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 3640f577..1dbe6319 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 @@ -4,6 +4,11 @@ import cn.hutool.core.io.FileUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.ss.usermodel.Cell; +import org.apache.poi.ss.usermodel.Row; +import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.jeecgframework.poi.excel.ExcelExportUtil; import org.jeecgframework.poi.excel.entity.ExportParams; @@ -22,6 +27,7 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.Objects; import static org.jeecg.common.util.ClassUtil.classPathStream; @@ -183,4 +189,50 @@ public class ExportUtil { Map dataMap){ exportXls(response,template,target,dataSet,dataMap,"file.xls"); } + + public static Workbook createWorkBook(List stationNameList, List columnNameList, Map>> dataMap) { + //创建工作簿 + Workbook workbook = new HSSFWorkbook(); + //遍历台站数量 + for (int i=0; i> dataList = dataMap.get(stationName); + //遍历数据根据字段名称取值赋值 + for (int j=0; j data = dataList.get(j); + for (int k=0; k Integer getSampleId(@Param(value = "filePathName") String filePathName); + List> findNuclideStatistics(@Param(value = "stationId") String stationId, @Param(value = "startTime") String startTime, @Param(value = "endTime") String endTime, @Param(value = "nuclideSql") String nuclideSql); + } diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/mapper/SysDefaultNuclideMapper.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/mapper/SysDefaultNuclideMapper.java new file mode 100644 index 00000000..5f2ce650 --- /dev/null +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/mapper/SysDefaultNuclideMapper.java @@ -0,0 +1,9 @@ +package org.jeecg.modules.mapper; + +import com.baomidou.mybatisplus.core.mapper.BaseMapper; +import org.apache.ibatis.annotations.Mapper; +import org.jeecg.modules.base.entity.postgre.SysDefaultNuclide; + +@Mapper +public interface SysDefaultNuclideMapper extends BaseMapper { +} diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/mapper/xml/GardsSampleDataWebMapper.xml b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/mapper/xml/GardsSampleDataWebMapper.xml index aea22575..3f302d6e 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/mapper/xml/GardsSampleDataWebMapper.xml +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/mapper/xml/GardsSampleDataWebMapper.xml @@ -178,4 +178,48 @@ SELECT SAMPLE_ID FROM ORIGINAL.GARDS_SAMPLE_DATA WHERE INPUT_FILE_NAME = #{filePathName} + + \ No newline at end of file diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/IGardsSampleDataWebService.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/IGardsSampleDataWebService.java index 52ca749c..0af52bac 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/IGardsSampleDataWebService.java +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/IGardsSampleDataWebService.java @@ -51,4 +51,11 @@ public interface IGardsSampleDataWebService extends IService List sampleIds); List queryByModDate(Date startTime, Date endTime); + + Result findNuclideList(String systemType); + + Result findNuclideStatistics(String stationId, String systemType, String dbName, String[] nuclideNames, Date startDate, Date endDate); + + void exportNuclideStatistics(String[] stationIds, String systemType, String dbName, String[] nuclideNames, Date startDate, Date endDate, HttpServletResponse response); + } diff --git a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java index b862dc6e..c64a1e1b 100644 --- a/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java +++ b/jeecg-module-web-statistics/src/main/java/org/jeecg/modules/service/impl/GardsSampleDataWebServiceImpl.java @@ -23,8 +23,12 @@ import org.jeecg.common.util.*; import org.jeecg.modules.base.entity.original.GardsSampleAux; import org.jeecg.modules.base.entity.original.GardsSampleData; import org.jeecg.modules.base.entity.original.GardsSampleDescription; +import org.jeecg.modules.base.entity.postgre.SysDefaultNuclide; +import org.jeecg.modules.base.enums.SystemType; +import org.jeecg.modules.base.enums.XeNuclideName; import org.jeecg.modules.entity.GardsSampleDataWeb; import org.jeecg.modules.entity.data.*; +import org.jeecg.modules.entity.dto.SampleDataDto; import org.jeecg.modules.entity.vo.SpectrumFileRecord; import org.jeecg.modules.mapper.*; import org.jeecg.modules.native_jni.EnergySpectrumHandler; @@ -52,26 +56,10 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl queryWrapper = new LambdaQueryWrapper<>(); + queryWrapper.eq(SysDefaultNuclide::getUseType, 4); + if (systemType.equals("beta")) { + queryWrapper.eq(SysDefaultNuclide::getNuclideType, SystemType.BETA.getType()); + } else if (systemType.equals("gamma")) { + queryWrapper.eq(SysDefaultNuclide::getNuclideType, SystemType.GAMMA.getType()); + } else if (systemType.equals("Particulate")) { + queryWrapper.eq(SysDefaultNuclide::getNuclideType, SystemType.PARTICULATE.getType()); + } + List defaultNuclides = defaultNuclideMapper.selectList(queryWrapper); + result.setSuccess(true); + result.setResult(defaultNuclides); + return result; + } + + @Override + public Result findNuclideStatistics(String stationId, String systemType, String dbName, String[] nuclideNames, Date startDate, Date endDate) { + Result result = new Result(); + //存储结果 + Map resultMap = new HashMap<>(); + //从redis中获取台站信息 + Map stationMap = (Map)redisUtil.get("stationMap"); + //判断开始时间是否为空 + if (Objects.isNull(startDate)){ + result.error500("The start time cannot be empty"); + return result; + } + String startTime = DateUtils.formatDate(startDate, "yyyy-MM-dd") + " 00:00:00"; + //判断结束时间是否为空 + if (Objects.isNull(endDate)) { + result.error500("The end time cannot be empty"); + return result; + } + String endTime = DateUtils.formatDate(endDate, "yyyy-MM-dd") + " 23:59:59"; + List allDayTime = DateUtils.getAllDay(DateUtils.formatDate(startDate, "yyyy-MM-dd"), DateUtils.formatDate(endDate, "yyyy-MM-dd")); + //判断查询的核素内容是否为空 + List nuclideNameList = new LinkedList<>(); + if (nuclideNames != null && nuclideNames.length > 0) { + nuclideNameList = Arrays.asList(nuclideNames); + } + //判断要查询的数据库类型 + if (dbName.equals("auto")) { + dbName = "RNAUTO"; + } else if (dbName.equals("man")) { + dbName = "RNMAN"; + } + //判断系统类型查询对应匹配的核素信息 + String nuclideSql = ""; + if (systemType.equals("beta")) { + nuclideSql = betaNuclideSql(dbName, nuclideNameList); + for (int i=0; i< nuclideNameList.size(); i++) { + String nuclideName = nuclideNameList.get(i); + if (StringUtils.isNotBlank(nuclideName)) { + List concList = new LinkedList<>(); + List mdcList = new LinkedList<>(); + resultMap.put(nuclideName+"Conc", concList); + resultMap.put(nuclideName+"MDC", mdcList); + } + } + } else if (systemType.equals("gamma")) { + nuclideSql = gammaNuclideSql(dbName, nuclideNameList); + for (int i=0; i< nuclideNameList.size(); i++) { + String nuclideName = nuclideNameList.get(i); + if (StringUtils.isNotBlank(nuclideName)) { + List concList = new LinkedList<>(); + List mdcList = new LinkedList<>(); + resultMap.put(nuclideName+"Conc", concList); + resultMap.put(nuclideName+"MDC", mdcList); + } + } + } else if (systemType.equals("Particulate")) { + nuclideSql = particulateSql(dbName, nuclideNameList); + for (int i=0; i< nuclideNameList.size(); i++) { + String nuclideName = nuclideNameList.get(i); + if (StringUtils.isNotBlank(nuclideName)) { + List concList = new LinkedList<>(); + resultMap.put(nuclideName+"Conc", concList); + } + } + } + //拼接sql查询结果 + List> nuclideStatisticsMap = this.baseMapper.findNuclideStatistics(stationId, startTime, endTime, nuclideSql); + //处理查询结果 + handleNuclideData(nuclideStatisticsMap, systemType, nuclideNameList, allDayTime, resultMap); + //返回台站名称 + String stationName = stationMap.get(stationId); + resultMap.put("STATION_NAME", stationName); + result.setSuccess(true); + result.setResult(resultMap); + return result; + } + + @Override + public void exportNuclideStatistics(String[] stationIds, String systemType, String dbName, String[] nuclideNames, Date startDate, Date endDate, HttpServletResponse response) { + Map>> resultMap = new HashMap<>(); + //从redis中获取台站信息 + Map stationMap = (Map)redisUtil.get("stationMap"); + //判断开始时间是否为空 + if (Objects.isNull(startDate)){ + return; + } + String startTime = DateUtils.formatDate(startDate, "yyyy-MM-dd") + " 00:00:00"; + //判断结束时间是否为空 + if (Objects.isNull(endDate)) { + return; + } + String endTime = DateUtils.formatDate(endDate, "yyyy-MM-dd") + " 23:59:59"; + //判断查询的核素内容是否为空 + List nuclideNameList = new LinkedList<>(); + if (nuclideNames != null && nuclideNames.length > 0) { + nuclideNameList = Arrays.asList(nuclideNames); + } + //判断要查询的数据库类型 + if (dbName.equals("auto")) { + dbName = "RNAUTO"; + } else if (dbName.equals("man")) { + dbName = "RNMAN"; + } + //列名数组 + List columnNameList = new LinkedList<>(); + //判断系统类型查询对应匹配的核素信息 + String nuclideSql = ""; + if (systemType.equals("beta")) { + //存储基础列名 + columnNameList.add("STATION_ID"); + columnNameList.add("SAMPLE_ID"); + columnNameList.add("SPECTRAL_QUALIFIE"); + columnNameList.add("COLLECT_START"); + columnNameList.add("QUANTITY"); + columnNameList.add("XE_VOLUME"); + columnNameList.add("ACQUISITION_START"); + columnNameList.add("ACQUISITION_LIVE_SEC"); + columnNameList.add("SITE_DET_CODE"); + nuclideSql = betaNuclideSql(dbName, nuclideNameList); + for (int i=0; i< nuclideNameList.size(); i++) { + String nuclideName = nuclideNameList.get(i); + String upperNuclideName = nuclideName.toUpperCase(); + if (upperNuclideName.equals(XeNuclideName.XE_131m.getType().toUpperCase())) { + nuclideName = XeNuclideName.XE_131m.getType(); + } else if (upperNuclideName.equals(XeNuclideName.XE_133m.getType().toUpperCase())) { + nuclideName = XeNuclideName.XE_133m.getType(); + } + nuclideNameList.set(i, nuclideName); + if (StringUtils.isNotBlank(nuclideName)) { + columnNameList.add(StringUtils.upperCase(nuclideName)); + columnNameList.add(StringUtils.upperCase(nuclideName+"MDC")); + } + } + } else if (systemType.equals("gamma")) { + //存储基础列名 + columnNameList.add("STATION_ID"); + columnNameList.add("SAMPLE_ID"); + columnNameList.add("SAMPLE_REF_ID"); + columnNameList.add("COLLECT_START"); + columnNameList.add("COLLECT_STOP"); + columnNameList.add("QUANTITY"); + columnNameList.add("ACQUISITION_START"); + columnNameList.add("ACQUISITION_STOP"); + columnNameList.add("ACQUISITION_LIVE_SEC"); + columnNameList.add("SITE_DET_CODE"); + nuclideSql = gammaNuclideSql(dbName, nuclideNameList); + for (int i=0; i< nuclideNameList.size(); i++) { + String nuclideName = nuclideNameList.get(i); + if (StringUtils.isNotBlank(nuclideName)) { + columnNameList.add(StringUtils.upperCase(nuclideName)); + columnNameList.add(StringUtils.upperCase(nuclideName+"MDC")); + } + } + } else if (systemType.equals("Particulate")) { + //存储基础列名 + columnNameList.add("STATION_ID"); + columnNameList.add("SAMPLE_ID"); + columnNameList.add("SAMPLE_REF_ID"); + columnNameList.add("COLLECT_START"); + columnNameList.add("COLLECT_STOP"); + columnNameList.add("QUANTITY"); + columnNameList.add("ACQUISITION_START"); + columnNameList.add("ACQUISITION_STOP"); + columnNameList.add("ACQUISITION_LIVE_SEC"); + columnNameList.add("SITE_DET_CODE"); + nuclideSql = particulateSql(dbName, nuclideNameList); + for (int i=0; i< nuclideNameList.size(); i++) { + String nuclideName = nuclideNameList.get(i); + if (StringUtils.isNotBlank(nuclideName)) { + columnNameList.add(StringUtils.upperCase(nuclideName)); + } + } + } + //台站名称数组 + List stationNameList = new LinkedList<>(); + for (String stationId:stationIds) { + //返回台站名称 + String stationName = stationMap.get(stationId); + //拼接sql查询结果 + List> nuclideStatisticsMap = this.baseMapper.findNuclideStatistics(stationId, startTime, endTime, nuclideSql); + resultMap.put(stationName, nuclideStatisticsMap); + //添加台站名称到集合 + stationNameList.add(stationName); + } + Workbook workbook = null; + OutputStream outputStream = null; + try { + // 设置文件名、Excel类型(xls|xlsx) + outputStream = ExportUtil.xls(response,"nuclide.xls"); + workbook = ExportUtil.createWorkBook(stationNameList, columnNameList, resultMap); + workbook.write(outputStream); + } catch (IOException e) { + e.printStackTrace(); + }finally { + try { + if (ObjectUtil.isNotNull(outputStream)) + outputStream.close(); + if (ObjectUtil.isNotNull(workbook)) + workbook.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + private String betaNuclideSql(String dbName, List nuclideNames) { + String sql = ""; + //存储每个核素对应的sql + List nuclideSqls = new LinkedList<>(); + //遍历核素名称拼接sql语句 + for (int i=0; i nuclideNames) { + String sql = ""; + //存储每个核素对应的sql + List nuclideSqls = new LinkedList<>(); + //遍历核素名称 + for (int i=0; i nuclideNames) { + String sql = ""; + //存储核素sql + List nuclideSqls = new LinkedList<>(); + //遍历核素信息 + for (int i=0; i> nuclideStatisticsMap, String systemType, List nuclideNameList, List allDateTime, Map resultMap) { + //存储横坐标采集开始时间 + List collectStartList = new LinkedList<>(); + //存储横坐标对应体积 + List quantityList = new LinkedList<>(); + //存储横坐标对应acq活时间 + List acqLiveSecList = new LinkedList<>(); + //遍历日期时间 + for (int i=0; i< allDateTime.size(); i++) { + //根据下标获取日期时间 + String dayTime = allDateTime.get(i); + //新增标识判断是否包含 可能存在一天有多条数据的情况 + boolean isHave = false; + //遍历查询结果数组 + for (int j=0; j< nuclideStatisticsMap.size(); j++) { + //根据下标获取核素查询结果 + Map nuclideStatistics = nuclideStatisticsMap.get(j); + //获取采集开始时间 + Object collectStart = nuclideStatistics.get("COLLECT_START"); + //采集开始时间转为字符串 + String collectStartStr = collectStart.toString(); + //截取采集开始时间的年月日 + collectStartStr = collectStartStr.substring(0, 10); + //如果采集时间包含当前日期 则正常的读取数据并存入数组 + if (dayTime.equals(collectStartStr)) { + collectStartList.add(collectStart.toString()); + //获取体积 + Object quantity = nuclideStatistics.get("QUANTITY"); + //判断体积数值是否有 如果有 正常存储 + if (Objects.nonNull(quantity)) { + quantityList.add(Double.valueOf(quantity.toString())); + } else { + quantityList.add(null); + } + //获取acq活时间 + Object acquisitionLiveSec = nuclideStatistics.get("ACQUISITION_LIVE_SEC"); + //判断活时间是否为空 如果不为空 正常存储 + if (Objects.nonNull(acquisitionLiveSec)) { + acqLiveSecList.add(Double.valueOf(acquisitionLiveSec.toString())); + } else { + acqLiveSecList.add(null); + } + //判断系统类型决定读取核素的信息 + if (systemType.equals("beta") || systemType.equals("gamma")) { + for (String nuclideName: nuclideNameList) { + List concList = (List) resultMap.get(nuclideName + "Conc"); + List mdcList = (List) resultMap.get(nuclideName + "MDC"); + //将核素名称转为全部大写 + String columnName = StringUtils.upperCase(nuclideName); + //读取查询出的浓度 + Object conc = nuclideStatistics.get(columnName); + //判断如果浓度不为空 正常存储 + if (Objects.nonNull(conc)) { + if (conc.toString().toLowerCase().contains("inf") || conc.toString().toLowerCase().contains("nan")) { + concList.add(null); + } else { + concList.add(Double.valueOf(conc.toString())); + } + } else { + concList.add(null); + } + //读取查询出的mdc结果 + Object mdc = nuclideStatistics.get(columnName + "MDC"); + //判断如果mdc结果不为空 正常存储 + if (Objects.nonNull(mdc)) { + if (mdc.toString().toLowerCase().contains("inf") || mdc.toString().toLowerCase().contains("nan")) { + mdcList.add(null); + } else { + mdcList.add(Double.valueOf(mdc.toString())); + } + } else { + mdcList.add(null); + } + } + } else if (systemType.equals("Particulate")) { + for (String nuclideName: nuclideNameList) { + List concList = (List) resultMap.get(nuclideName + "Conc"); + //将核素名称转为全部大写 + String columnName = StringUtils.upperCase(nuclideName); + //读取查询出的浓度 + Object conc = nuclideStatistics.get(columnName); + //判断如果浓度不为空 正常存储 + if (Objects.nonNull(conc)) { + if (conc.toString().toLowerCase().contains("inf") || conc.toString().toLowerCase().contains("nan")) { + concList.add(null); + } else { + concList.add(Double.valueOf(conc.toString())); + } + } else { + concList.add(null); + } + } + } + isHave = true; + } else { //如果采集时间不包含当前日期 各数组填补null + //如果全数组遍历后都没有 就填充空数据 + if (j == nuclideStatisticsMap.size()-1 && !isHave) { + collectStartList.add(dayTime+" 00:00:00"); + quantityList.add(null); + acqLiveSecList.add(null); + //判断系统类型决定读取核素的信息 + if (systemType.equals("beta") || systemType.equals("gamma")) { + for (String nuclideName: nuclideNameList) { + List concList = (List) resultMap.get(nuclideName + "Conc"); + List mdcList = (List) resultMap.get(nuclideName + "MDC"); + concList.add(null); + mdcList.add(null); + } + } else if (systemType.equals("Particulate")) { + for (String nuclideName: nuclideNameList) { + List concList = (List) resultMap.get(nuclideName + "Conc"); + concList.add(null); + } + } + } + } + } + } + resultMap.put("CollectStart", collectStartList); + resultMap.put("Quantity", quantityList); + resultMap.put("AcqLiveSec", acqLiveSecList); + } + + + }