diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ClassUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ClassUtil.java index a5569856..eb650c0e 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ClassUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ClassUtil.java @@ -2,7 +2,12 @@ package org.jeecg.common.util; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.StrUtil; +import org.jeecgframework.poi.excel.entity.TemplateExportParams; +import org.springframework.core.io.DefaultResourceLoader; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; +import java.io.IOException; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.HashMap; @@ -47,4 +52,17 @@ public class ClassUtil { } return objsStr; } + + public static String classPath(String path){ + try { + String pathPrefix = "classpath:"; + ResourceLoader loader = new DefaultResourceLoader(); + String templatePath = pathPrefix + path; + Resource resource = loader.getResource(templatePath); + return resource.getFile().getAbsolutePath(); + } catch (IOException e) { + e.printStackTrace(); + return ""; + } + } } diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ExportUtil.java b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ExportUtil.java index d901e1b1..c8e72adb 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ExportUtil.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/common/util/ExportUtil.java @@ -14,6 +14,7 @@ import org.springframework.core.io.ResourceLoader; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.OutputStream; +import java.io.PrintWriter; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -47,6 +48,13 @@ public class ExportUtil { response.setHeader("Content-disposition", "attachment;filename=" + name); return response.getOutputStream(); } + public static PrintWriter streamWriter(HttpServletResponse response, String fileName) throws IOException { + response.setCharacterEncoding(UTF_8); + response.setContentType("application/octet-stream"); + String name = URLEncoder.encode(fileName, UTF_8); + response.setHeader("Content-disposition", "attachment;filename=" + name); + return response.getWriter(); + } public static void exportXls(HttpServletResponse response, Class target, List data, String fileName){ @@ -77,18 +85,11 @@ public class ExportUtil { exportXls(response, target, data, "file.xls"); } - public static TemplateExportParams excelTemplate(String name){ - try { - String pathPrefix = "classpath:excelTemplate/"; - ResourceLoader loader = new DefaultResourceLoader(); - String templatePath = pathPrefix + name; - Resource resource = loader.getResource(templatePath); - String path = resource.getFile().getAbsolutePath(); - return new TemplateExportParams(path); - } catch (IOException e) { - e.printStackTrace(); - return null; - } + public static TemplateExportParams excelTemplate(String template){ + String pathPrefix = "excelTemplate/"; + String path = pathPrefix + template; + String templatePath = ClassUtil.classPath(path); + return new TemplateExportParams(templatePath); } public static void exportXls(HttpServletResponse response, String template, diff --git a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/ExportTemplate.java b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/ExportTemplate.java index 1a2375ea..23b2e163 100644 --- a/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/ExportTemplate.java +++ b/jeecg-boot-base-core/src/main/java/org/jeecg/modules/base/enums/ExportTemplate.java @@ -12,7 +12,8 @@ public enum ExportTemplate { SampleInfo_G("SampleInformation-G.xls"), RadionuclideActivity_G("RadionuclideActivity-G.xls"), SampleInfo_B("SampleInformation-B.xls"), - QcResult_B("QcResult-B.xls"); + QcResult_B("QcResult-B.xls"), + RLR_B("RLR-B.xls"),RLR_G("Gamma.RLR"); ExportTemplate(String name) { this.name = name; diff --git a/jeecg-boot-base-core/src/main/resources/excelTemplate/Gamma.RLR b/jeecg-boot-base-core/src/main/resources/excelTemplate/Gamma.RLR new file mode 100644 index 00000000..c6c127bf --- /dev/null +++ b/jeecg-boot-base-core/src/main/resources/excelTemplate/Gamma.RLR @@ -0,0 +1,76 @@ +BEGIN IMS2.0 +MSG_TYPE DATA +MSG_ID ${header_msg_id} ${header_station_code} +DATA_TYPE MINIRLR +#Header +${header_priority_level} +${header_station_code} ${header_srid} +${header_lab_code} ${header_lab_detector} +${header_report_type} ${header_report_number} +${header_sample_category} +${header_transmission} +#Objective +~AnalysisPurpose +${Obj_purpose} +~TestsAuthorized +${Obj_authorized} +~SpecialInstructions +${Obj_instruction} +#Collection +${collect_start} ${collect_stop} ${collect_airVolume} +#SampleReceipt +${Receipt_srid} +${Receipt_sealNum} +${Receipt_sample_dateTime} +~PackageCondition +${Receipt_package} +~SealCondition +${Receipt_seal} +~SampleCondition +${Receipt_sample} +#Test +${Test_type} +${Test_completion} +${Test_person} +${Test_purpose} +#PeaksMethod +${PeakMethod_software} +${PeakMethod_location} +#PeakFit +${peakFit} +#g_AnalysisMethods +${AnalyMethod_software} +~NuclidesMethod +${AnalyMethod_nuclide} +~BaselineMethod +${AnalyMethod_baseline} +~LCMethod +${AnalyMethod_lc} +~CalibrationMethod +${AnalyMethod_calib} +#PeakAssociation +${Association} +#References +~SAMPLEPHD +${Reference_samplePHD} +~CALIBPHD +${Reference_CalibPHD} +~PhysicalConstants +${Reference_physical} +#Results +${Result_act_ref} ${Result_conc_ref} +${Result} +#NuclideRatios +#g_CoincidenceCorrection +#MDA +#Conclusions +${conclusion_person} +~IDCSummary +${Conclusion_IDC} +~Labsummary +${Conclusion_Lab} +~ResultComparison +${Conclusion_Res} +#Comment +${Comment} +STOP \ No newline at end of file diff --git a/jeecg-boot-base-core/src/main/resources/excelTemplate/RLR-B.xls b/jeecg-boot-base-core/src/main/resources/excelTemplate/RLR-B.xls new file mode 100644 index 00000000..747c0bbc Binary files /dev/null and b/jeecg-boot-base-core/src/main/resources/excelTemplate/RLR-B.xls differ 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 cfb6e0c8..d2ed282b 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 @@ -3,13 +3,16 @@ package org.jeecg.modules.controller; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.ListUtil; import cn.hutool.core.io.FileUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.ReUtil; import cn.hutool.core.util.StrUtil; import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; import org.jeecg.common.api.vo.Result; import org.jeecg.common.util.ClassUtil; +import org.jeecg.common.util.ExportUtil; import org.jeecg.modules.base.bizVo.GammaRLR; +import org.jeecg.modules.base.enums.ExportTemplate; import org.jeecg.modules.entity.vo.*; import org.jeecg.modules.service.IGammaService; import org.springframework.beans.factory.annotation.Autowired; @@ -18,6 +21,9 @@ import org.springframework.web.bind.annotation.*; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; @@ -25,6 +31,9 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import static org.jeecg.modules.base.enums.ExportTemplate.RLR_B; +import static org.jeecg.modules.base.enums.ExportTemplate.RLR_G; + @RestController @RequestMapping("gamma") @Api(value = "gamma人工分析",tags = "gamma人工分析") @@ -316,57 +325,10 @@ public class GammaController { return gammaService.viewRLR(sampleId, fileName); } - @GetMapping("exportRLR") + @PostMapping ("exportRLR") @ApiOperation(value = "导出RLR页面数据", notes = "导出RLR页面数据") - public void exportRLR(Integer sampleId, String fileName, HttpServletResponse response) { - - } - - public static void main(String[] args) { - String template = "D:\\Share\\Gamma\\Gamma.RLR"; - GammaRLR gammaRLR = new GammaRLR(); - gammaRLR.setAnalyMethod_lc("我是测试数据"); - List lines = FileUtil.readUtf8Lines(template); - // 正则表达式,匹配${}中的内容 - String regex = "\\$\\{([^}]+)}"; - List newLines = new ArrayList<>(); - List list = ListUtil.toList("peakFit","Association","Result"); - for (String line : lines) { - if (StrUtil.isBlank(line)) continue; - List fieldNames = ReUtil.findAllGroup1(regex, line); - if (CollUtil.isEmpty(fieldNames)){ - newLines.add(line); - continue; - } - Map fieldValue = ClassUtil.fieldValue(gammaRLR, fieldNames); - for (Map.Entry entry : fieldValue.entrySet()) { - String fieldName = entry.getKey(); - Object value = entry.getValue(); - if (list.contains(fieldName)){ - List lineList = new ArrayList<>(); - switch (fieldName){ - case "peakFit": - lineList = ClassUtil.objsStr((List)value); - break; - case "Association": - lineList = ClassUtil.objsStr((List)value); - break; - case "Result": - lineList = ClassUtil.objsStr((List)value); - break; - default: - break; - } - newLines.addAll(lineList); - }else { - String search = "${" + fieldName + "}"; - String newLine = StrUtil.replace(line, search, value.toString()); - newLines.add(newLine); - } - } - } - - String output = "C:\\Users\\a\\Desktop\\"; + public void exportRLR(@RequestBody GammaRLR gammaRLR, HttpServletResponse response) { + gammaService.exportRLR(gammaRLR, response); } @GetMapping("viewAutomaticAnalysisLog") diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java index ed097a43..dfe1e77d 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/controller/SpectrumAnalysesController.java @@ -128,6 +128,12 @@ public class SpectrumAnalysesController { return spectrumAnalysisService.viewRLR(sampleId); } + @GetMapping("exportRLR") + @ApiOperation(value = "导出RLR数据", notes = "导出RLR数据") + public void exportRLR(Integer sampleId, HttpServletResponse response) { + spectrumAnalysisService.exportRLR(sampleId, response); + } + @GetMapping("viewGammaDetectorCalibration") @ApiOperation(value = "查询GammaDetectorCalibration数据", notes = "查询GammaDetectorCalibration数据") public Result viewGammaDetectorCalibration(Integer sampleId) { 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 58544e57..0dc4930e 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 @@ -1,6 +1,7 @@ package org.jeecg.modules.service; import org.jeecg.common.api.vo.Result; +import org.jeecg.modules.base.bizVo.GammaRLR; import org.jeecg.modules.entity.vo.*; import javax.servlet.http.HttpServletRequest; @@ -107,7 +108,7 @@ public interface IGammaService{ Result viewRLR(Integer sampleId, String fileName); - void exportRLR(Integer sampleId, String fileName, HttpServletResponse response); + void exportRLR(GammaRLR gammaRLR, HttpServletResponse response); void viewAutomaticAnalysisLog(Integer sampleId, HttpServletResponse response); diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java index e13a01a3..e2c56c37 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/ISpectrumAnalysisService.java @@ -45,6 +45,8 @@ public interface ISpectrumAnalysisService { Result viewRLR(Integer sampleId); + void exportRLR(Integer sampleId, HttpServletResponse response); + Result viewGammaDetectorCalibration(Integer sampleId); Result viewBetaDetectorCalibration(Integer sampleId); 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 89c6b0fa..c751402c 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 @@ -1,10 +1,13 @@ package org.jeecg.modules.service.impl; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.collection.ListUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.io.FileUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; +import cn.hutool.core.util.ReUtil; +import cn.hutool.core.util.StrUtil; import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.StringPool; @@ -19,6 +22,7 @@ import org.jeecg.common.constant.DateConstant; import org.jeecg.common.properties.SpectrumPathProperties; import org.jeecg.common.system.util.JwtUtil; import org.jeecg.common.util.*; +import org.jeecg.modules.base.bizVo.GammaRLR; import org.jeecg.modules.base.entity.configuration.GardsNuclLinesLib; import org.jeecg.modules.base.enums.ExportTemplate; import org.jeecg.modules.base.enums.RoleType; @@ -48,6 +52,7 @@ import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; +import static org.jeecg.modules.base.enums.ExportTemplate.RLR_G; import static org.jeecg.modules.base.enums.ExportTemplate.SampleInfo_G; @Service(value = "gammaService") @@ -2046,12 +2051,69 @@ public class GammaServiceImpl implements IGammaService { result.setResult(map); return result; } - @Override - public void exportRLR(Integer sampleId, String fileName, HttpServletResponse response) { - + public void exportRLR(GammaRLR gammaRLR, HttpServletResponse response) { + String pathPrefix = "excelTemplate/"; + String path = pathPrefix + RLR_G.getName(); + String template = ClassUtil.classPath(path); + List lines = FileUtil.readUtf8Lines(template); + // 正则表达式,匹配${}中的内容 + String regex = "\\$\\{([^}]+)}"; + List newLines = new ArrayList<>(); + List list = ListUtil.toList("peakFit","Association","Result"); + List skip = ListUtil.toList("${peakFit}","${Association}","${Result}"); + for (String line : lines) { + if (StrUtil.isBlank(line)) continue; + List fieldNames = ReUtil.findAllGroup1(regex, line); + if (CollUtil.isEmpty(fieldNames)){ + newLines.add(line); + continue; + } + Map fieldValue = ClassUtil.fieldValue(gammaRLR, fieldNames); + String newLine = line; + for (Map.Entry entry : fieldValue.entrySet()) { + String fieldName = entry.getKey(); + Object value = entry.getValue(); + if (list.contains(fieldName)){ + List lineList = new ArrayList<>(); + switch (fieldName){ + case "peakFit": + lineList = ClassUtil.objsStr((List)value); + break; + case "Association": + lineList = ClassUtil.objsStr((List)value); + break; + case "Result": + lineList = ClassUtil.objsStr((List)value); + break; + default: + break; + } + newLines.addAll(lineList); + }else { + String search = "${" + fieldName + "}"; + String replacement = StrUtil.toString(value); + replacement = StrUtil.isBlank(replacement) ? "null" : replacement; + newLine = StrUtil.replace(newLine, search, replacement); + } + } + if (!CollUtil.contains(skip, newLine)) + newLines.add(newLine); + } + PrintWriter writer = null; + try { + String export = "Gamma.RLR"; + writer = ExportUtil.streamWriter(response, export); + for (String newLine : newLines) { + writer.println(newLine); + } + } catch (IOException e) { + e.printStackTrace(); + }finally { + if (ObjectUtil.isNotNull(writer)) + writer.close(); + } } - @Override public void viewAutomaticAnalysisLog(Integer sampleId, HttpServletResponse response) { if (Objects.isNull(sampleId)){ diff --git a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java index 9b474f44..d335357c 100644 --- a/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java +++ b/jeecg-module-spectrum-analysis/src/main/java/org/jeecg/modules/service/impl/SpectrumAnalysisServiceImpl.java @@ -45,8 +45,7 @@ import java.util.*; import java.util.regex.Pattern; import java.util.stream.Collectors; -import static org.jeecg.modules.base.enums.ExportTemplate.QcResult_B; -import static org.jeecg.modules.base.enums.ExportTemplate.SampleInfo_B; +import static org.jeecg.modules.base.enums.ExportTemplate.*; @Service("spectrumAnalysisService") @DS("ora") @@ -1455,6 +1454,18 @@ public class SpectrumAnalysisServiceImpl implements ISpectrumAnalysisService { return result; } + @Override + public void exportRLR(Integer sampleId, HttpServletResponse response) { + Result result = viewRLR(sampleId); + RlrDataValues rlrDataValues = (RlrDataValues)result.getResult(); + Map dataMap = BeanUtil.beanToMap(rlrDataValues); + // 将Null值替换为"",避免空指针异常(或者在模板中进行判断) + dataMap.replaceAll((key, value) -> ObjectUtil.isNull(value) ? "" : value); + String export = "RLR-Beta.xls"; + String template = RLR_B.getName(); + ExportUtil.exportXls(response, template, dataMap,export); + } + @Override public Result viewGammaDetectorCalibration(Integer sampleId) { Result result = new Result();