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 b05069da..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 @@ -27,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; @@ -189,7 +190,7 @@ public class ExportUtil { exportXls(response,template,target,dataSet,dataMap,"file.xls"); } - public static Workbook createWorkBook(List stationNameList, List columnNameList, List> dataList) { + public static Workbook createWorkBook(List stationNameList, List columnNameList, Map>> dataMap) { //创建工作簿 Workbook workbook = new HSSFWorkbook(); //遍历台站数量 @@ -208,8 +209,10 @@ public class ExportUtil { cell.setCellValue(columnName); } rowIndex+=1; + //根据台站名称获取数据 + List> dataList = dataMap.get(stationName); //遍历数据根据字段名称取值赋值 - for (int j=0; j 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 7fec78b1..be77cf20 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 @@ -27,6 +27,7 @@ import org.jeecg.modules.base.entity.postgre.SysDefaultNuclide; import org.jeecg.modules.base.enums.SystemType; 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; @@ -720,12 +721,8 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl listBySampleIds(Integer[] stationIds, - String startTime, - String endTime, - List sampleIds) { + public List listBySampleIds(Integer[] stationIds, String startTime, String endTime, List sampleIds) { Date startDate = DateUtil .parse(startTime + " 00:00:00","yyyy-MM-dd HH:mm:ss") .toJdkDate(); @@ -875,7 +869,10 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl resultMap = new HashMap<>(); + //从redis中获取台站信息 + Map stationMap = (Map)redisUtil.get("stationMap"); //判断开始时间是否为空 if (Objects.isNull(startDate)){ result.error500("The start time cannot be empty"); @@ -937,11 +934,135 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl> nuclideStatisticsMap = this.baseMapper.findNuclideStatistics(stationId, startTime, endTime, nuclideSql); //处理查询结果 handleNuclideData(nuclideStatisticsMap, systemType, nuclideNameList, 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); + 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 @@ -1116,4 +1237,6 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl