Merge remote-tracking branch 'origin/station' into station
# Conflicts: # jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java
This commit is contained in:
commit
571502cc36
|
@ -0,0 +1,42 @@
|
|||
package org.jeecg.modules.base.abstracts;
|
||||
|
||||
/**
|
||||
* 日志/报告格式化抽象类
|
||||
*/
|
||||
public abstract class AbstractLogOrReport {
|
||||
|
||||
/**
|
||||
* 行日志格式化
|
||||
* @param source 需要格式化的字符串
|
||||
* @param symbolNum 格式化的符号数量
|
||||
* @param args 格式化替换参数数组
|
||||
* @return
|
||||
*/
|
||||
public String titleFormat(String source, Integer symbolNum, String... args){
|
||||
StringBuilder firstParam = new StringBuilder();
|
||||
for (int i=0;i<symbolNum;i++){
|
||||
firstParam.append(args[0]);
|
||||
}
|
||||
args[0] = firstParam.toString();
|
||||
|
||||
StringBuilder lastParam = new StringBuilder();
|
||||
for (int i=0;i<symbolNum;i++){
|
||||
lastParam.append(args[args.length-1]);
|
||||
}
|
||||
args[args.length-1] = lastParam.toString();
|
||||
|
||||
return String.format(source,args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 行格式化
|
||||
* @param source
|
||||
* @param args
|
||||
* @return
|
||||
*/
|
||||
public String rowFormat(String source, String... args){
|
||||
return String.format(source,args);
|
||||
}
|
||||
|
||||
}
|
|
@ -476,9 +476,9 @@ public class GammaController {
|
|||
return gammaService.saveToDB(fileName, request);
|
||||
}
|
||||
|
||||
@GetMapping("saveTxt")
|
||||
public Result saveTxt(String fileName, HttpServletRequest request) {
|
||||
return gammaService.saveTxt(fileName, request);
|
||||
@GetMapping("saveToTxt")
|
||||
public void saveToTxt(String fileName, HttpServletRequest request, HttpServletResponse response) {
|
||||
gammaService.saveToTxt(fileName, request, response);
|
||||
}
|
||||
|
||||
@GetMapping("saveToExcel")
|
||||
|
|
|
@ -160,7 +160,7 @@ public interface IGammaService{
|
|||
|
||||
Result saveToDB(String fileName, HttpServletRequest request);
|
||||
|
||||
Result saveTxt(String fileName, HttpServletRequest request);
|
||||
void saveToTxt(String fileName, HttpServletRequest request, HttpServletResponse response);
|
||||
|
||||
void saveToExcel(String fileName, HttpServletResponse response);
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.jeecg.common.properties.SpectrumPathProperties;
|
|||
import org.jeecg.common.system.util.JwtUtil;
|
||||
import org.jeecg.common.system.vo.LoginUser;
|
||||
import org.jeecg.common.util.*;
|
||||
import org.jeecg.modules.base.abstracts.AbstractLogOrReport;
|
||||
import org.jeecg.modules.base.bizVo.GammaRLR;
|
||||
import org.jeecg.modules.base.dto.PeakInfoDto;
|
||||
import org.jeecg.modules.base.entity.configuration.GardsNuclLib;
|
||||
|
@ -72,7 +73,7 @@ import static org.jeecg.modules.base.enums.ExportTemplate.*;
|
|||
|
||||
@Service(value = "gammaService")
|
||||
@DS("ora")
|
||||
public class GammaServiceImpl implements IGammaService {
|
||||
public class GammaServiceImpl extends AbstractLogOrReport implements IGammaService {
|
||||
|
||||
@Autowired
|
||||
private LocalCache localCache;
|
||||
|
@ -3923,30 +3924,35 @@ public class GammaServiceImpl implements IGammaService {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Result saveTxt(String fileName, HttpServletRequest request) {
|
||||
Result result = new Result();
|
||||
public void saveToTxt(String fileName, HttpServletRequest request, HttpServletResponse response) {
|
||||
String userName = JwtUtil.getUserNameByToken(request);
|
||||
Cache<String, PHDFile> phdCache = localCache.getPHDCache();
|
||||
PHDFile phd = phdCache.getIfPresent(fileName+"-"+userName);
|
||||
StringBuilder strBuild = new StringBuilder();
|
||||
//txt文本内容
|
||||
//文本内容第一块内容匹配格式
|
||||
//文本内容第一块头部信息
|
||||
String title1 = " %s The Results of Peak Searching %s";
|
||||
//文本内容第一块内容匹配
|
||||
strBuild.append(titleFormat(title1, 51, StringPool.ASTERISK));
|
||||
//文本内容第一块头部信息匹配
|
||||
strBuild.append(titleFormat(title1, 51, StringPool.ASTERISK, StringPool.ASTERISK));
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//文本内容第二块
|
||||
//文本内容第二块匹配格式
|
||||
String title2 = "%-12s %-12s %-12s %-12s %-12s %-12s %-12s %-12s %-12s %-12s";
|
||||
//文本内容第二块第一部分数据信息
|
||||
//文本内容第二块头部信息
|
||||
String[] titleArgs2 = new String[]{"PeakID", "Energy(keV)", "Centroid", "Multiplet", "FWHM(keV)", "NetArea", "NAErr%", "Signif", "Sensit", "Nuclide"};
|
||||
//文本内容第二块第一部分数据匹配
|
||||
//文本内容第二块头部信息匹配
|
||||
strBuild.append(rowFormat(title2, titleArgs2));
|
||||
//遍历数组进行文本内容第二块第二部分数据匹配
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//遍历数组进行文本内容第二块数据匹配
|
||||
for (int i=0; i<phd.getVPeak().size(); i++) {
|
||||
PeakInfo peakInfo = phd.getVPeak().get(i);
|
||||
String peakId = String.valueOf(peakInfo.index);
|
||||
String peakId = String.valueOf(i+1);
|
||||
String energy = NumberFormatUtil.numberFormat(String.valueOf(peakInfo.energy));
|
||||
String peakCentroid = NumberFormatUtil.numberFormat(String.valueOf(peakInfo.peakCentroid));
|
||||
String multiIndex = String.valueOf(peakInfo.multiIndex);
|
||||
|
@ -3957,15 +3963,128 @@ public class GammaServiceImpl implements IGammaService {
|
|||
String sensit = NumberFormatUtil.numberFormat(String.valueOf(peakInfo.sensitivity));
|
||||
String nuclide = StringUtils.join(peakInfo.nuclides, StringPool.SEMICOLON);
|
||||
strBuild.append(rowFormat(title2, peakId, energy, peakCentroid, multiIndex, fwhm, area, areaErr, signif, sensit, nuclide));
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
}
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//文本内容第三块
|
||||
|
||||
|
||||
result.setSuccess(true);
|
||||
result.setResult(strBuild.toString());
|
||||
return result;
|
||||
//文本内容第三块头部信息
|
||||
String title3 = " %s The Results of Nuclide Identify %s";
|
||||
strBuild.append(titleFormat(title3, 12, StringPool.ASTERISK, StringPool.ASTERISK));
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//文本内容第三块数据
|
||||
List<List<String>> peakNuclides = phd.getVPeak().stream().map(item -> item.nuclides).collect(Collectors.toList());
|
||||
List<String> nuclides = new LinkedList<>();
|
||||
for (int i=0; i<peakNuclides.size(); i++) {
|
||||
List<String> peakNuclide = peakNuclides.get(i);
|
||||
nuclides.addAll(peakNuclide);
|
||||
}
|
||||
nuclides = nuclides.stream().distinct().collect(Collectors.toList());
|
||||
String nuclideStr = "";
|
||||
for (int i=0; i<nuclides.size(); i++) {
|
||||
nuclideStr+=" "+nuclides.get(i);
|
||||
}
|
||||
strBuild.append(nuclideStr);
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//文本内容第四块
|
||||
//文本内容第四块头部信息
|
||||
String title4 = " %s Nuclide's Activity and Concentration %s";
|
||||
//文本内容第四块头部信息匹配
|
||||
strBuild.append(titleFormat(title4, 28, StringPool.ASTERISK, StringPool.ASTERISK));
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//文本内容第四块第一部分数据
|
||||
String data1 = "Activity Reference Time: %s";
|
||||
String actRefTime = DateUtils.formatDate(phd.getUsedSetting().getRefTime_act(), "yyyy/MM/dd HH:mm:ss");
|
||||
strBuild.append(rowFormat(data1, actRefTime));
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//文本内容第四块第二部分数据
|
||||
String data2 = "Concentration Reference Time: %s";
|
||||
String concRefTime = DateUtils.formatDate(phd.getUsedSetting().getRefTime_conc(), "yyyy/MM/dd HH:mm:ss");
|
||||
strBuild.append(rowFormat(data2, concRefTime));
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//文本内容第五块
|
||||
//文本内容第五块头部信息
|
||||
String title5 = "%-12s %-12s %-12s %-12s %-12s %-12s %-12s %-12s %-12s %-12s";
|
||||
String[] titleArgs5 = new String[]{"Nuclide", "Halflife", "Yield%", "Energy(keV)", "Efficiency", "Activity(Bq)", "ActErr%", "MDA(Bq)", "Conc(uBq/m^3)", "MDC(uBq/m^3)"};
|
||||
strBuild.append(rowFormat(title5, titleArgs5));
|
||||
//换行
|
||||
strBuild.append(System.lineSeparator());
|
||||
//文本内容第五块数据
|
||||
Map<String, NuclideActMda> mapNucActMda = phd.getMapNucActMda();
|
||||
for (Map.Entry<String, NuclideActMda> entry:mapNucActMda.entrySet()) {
|
||||
String key = entry.getKey();
|
||||
NuclideActMda nuc = entry.getValue();
|
||||
String halflifeValue = "";
|
||||
if(nuc.isBCalculateMDA()) {
|
||||
String units = "S";
|
||||
double halflife = nuc.getHalflife();
|
||||
if(halflife >= 31556736) {// 1年 = 365.24 * 24 * 60 * 60 = 31556736s
|
||||
halflife /= 31556736;
|
||||
units = "A";
|
||||
} else if(halflife >= 86400) {// 1天 = 24 * 60 * 60 = 86400s
|
||||
halflife /= 86400;
|
||||
units = "D";
|
||||
} else if(halflife >= 3600) {
|
||||
halflife /= 3600;
|
||||
units = "H";
|
||||
}
|
||||
halflifeValue = NumberFormatUtil.numberFormat(String.valueOf(halflife)) + units;
|
||||
}
|
||||
String efficiency = NumberFormatUtil.numberFormat(String.valueOf(nuc.getEfficiency()));
|
||||
String activity = NumberFormatUtil.numberFormat(String.valueOf(nuc.getActivity()));
|
||||
String actErr = NumberFormatUtil.numberFormat(String.valueOf(nuc.getAct_err()/nuc.getActivity()*100));
|
||||
String mda = NumberFormatUtil.numberFormat(String.valueOf(nuc.getMda()));
|
||||
String conc = NumberFormatUtil.numberFormat(String.valueOf(nuc.getConcentration()));
|
||||
String mdc = NumberFormatUtil.numberFormat(String.valueOf(nuc.getMdc()));
|
||||
if(nuc.getCalculateIdx() >= 0 && nuc.getCalculateIdx() < nuc.getVEnergy().size()) {
|
||||
String yield = NumberFormatUtil.numberFormat(String.valueOf(nuc.getVYield().get(nuc.getCalculateIdx())*100));
|
||||
String energy = NumberFormatUtil.numberFormat(String.valueOf(nuc.getVEnergy().get(nuc.getCalculateIdx())));
|
||||
strBuild.append(rowFormat(title5, key, halflifeValue, yield, energy, efficiency, activity, actErr, mda, conc, mdc));
|
||||
strBuild.append(System.lineSeparator());
|
||||
} else {
|
||||
strBuild.append(rowFormat(title5, key, halflifeValue, "NULL", "NULL", efficiency, activity, actErr, mda, conc, mdc));
|
||||
strBuild.append(System.lineSeparator());
|
||||
}
|
||||
}
|
||||
strBuild.append(System.lineSeparator());
|
||||
String detectorCode = phd.getHeader().getDetector_code();
|
||||
String date = phd.getAcq().getAcquisition_start_date().replace("/", "");
|
||||
String time = phd.getAcq().getAcquisition_start_time().replace(":", "").substring(0, 4);
|
||||
String dataType = phd.getMsgInfo().getData_type().substring(0, 1);
|
||||
String format = ".txt";
|
||||
String txtFileName = String.format("%s-%s_%s_%s_RESULT%s", detectorCode, date, time, dataType, format);
|
||||
//导出数据内容到txt文本
|
||||
OutputStream fos = null;
|
||||
try {
|
||||
//设置响应类型
|
||||
response.setContentType("application/octet-stream");
|
||||
//解决中文不能生成文件
|
||||
response.setHeader("Content-Disposition", "attachment; fileName=" + URLEncoder.encode(txtFileName,"UTF-8"));
|
||||
fos = response.getOutputStream();
|
||||
fos.write(strBuild.toString().getBytes());
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
} finally {
|
||||
try {
|
||||
if (Objects.nonNull(fos)) {
|
||||
fos.close();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -4036,5 +4155,4 @@ public class GammaServiceImpl implements IGammaService {
|
|||
private String rowFormat(String source, String... args){
|
||||
return String.format(source,args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user