From b3e0a4fc73dc06150db3689fe58c05b360f3a6c0 Mon Sep 17 00:00:00 2001 From: panbaolin <123456> Date: Wed, 11 Oct 2023 16:26:55 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix:1.=E6=8F=90=E4=BA=A4=E6=97=A5=E5=BF=97/?= =?UTF-8?q?=E6=8A=A5=E5=91=8A=E6=8A=BD=E8=B1=A1=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/abstracts/AbstractLogOrReport.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/abstracts/AbstractLogOrReport.java diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/abstracts/AbstractLogOrReport.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/abstracts/AbstractLogOrReport.java new file mode 100644 index 00000000..a30176d5 --- /dev/null +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/abstracts/AbstractLogOrReport.java @@ -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 Date: Wed, 11 Oct 2023 18:47:52 +0800 Subject: [PATCH 2/2] =?UTF-8?q?gamma=E6=A8=A1=E5=9D=97saveToTXT=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/controller/GammaController.java | 6 +- .../jeecg/modules/service/IGammaService.java | 2 +- .../service/impl/GammaServiceImpl.java | 178 +++++++++++++----- 3 files changed, 136 insertions(+), 50 deletions(-) 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); } }