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 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); + } + nuclides = nuclides.stream().distinct().collect(Collectors.toList()); + String nuclideStr = ""; + 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); + } + } } @Override @@ -4036,5 +4155,4 @@ public class GammaServiceImpl implements IGammaService { private String rowFormat(String source, String... args){ return String.format(source,args); } - }