diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java index 0d1a9103..1256ad63 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/GammaController.java @@ -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); } } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java index 50b665b5..360c28bc 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/IGammaService.java @@ -160,6 +160,6 @@ public interface IGammaService{ Result saveToDB(String fileName, HttpServletRequest request); - Result saveTxt(String fileName, HttpServletRequest request); + void saveToTxt(String fileName, HttpServletRequest request, HttpServletResponse response); } diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java index 4ca17e1f..ee8521d4 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/GammaServiceImpl.java @@ -25,6 +25,7 @@ import org.jeecg.common.properties.ParameterProperties; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.util.*; +import org.jeecg.modules.base.abstracts.AbstractLogOrReport; import org.jeecg.modules.base.bizVo.GammaRLR; import org.jeecg.modules.base.entity.configuration.GardsNuclLib; import org.jeecg.modules.base.entity.configuration.GardsNuclLinesLib; @@ -69,7 +70,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; @@ -3920,30 +3921,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 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> peakNuclides = phd.getVPeak().stream().map(item -> item.nuclides).collect(Collectors.toList()); + List nuclides = new LinkedList<>(); + for (int i=0; i peakNuclide = peakNuclides.get(i); + nuclides.addAll(peakNuclide); } - args[0] = firstParam.toString(); - - StringBuilder lastParam = new StringBuilder(); - for (int i=0;i mapNucActMda = phd.getMapNucActMda(); + for (Map.Entry 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); + } } - args[args.length-1] = lastParam.toString(); - - return String.format(source,args); - } - - /** - * 行格式化 - * @param source - * @param args - * @return - */ - private String rowFormat(String source, String... args){ - return String.format(source,args); } }