统计分析导出核素对比统计数据功能实现

This commit is contained in:
qiaoqinzheng 2024-01-22 13:47:12 +08:00
parent 680c263033
commit d8e980fdb2
4 changed files with 152 additions and 14 deletions

View File

@ -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<String> stationNameList, List<String> columnNameList, List<Map<String, Object>> dataList) {
public static Workbook createWorkBook(List<String> stationNameList, List<String> columnNameList, Map<String, List<Map<String, Object>>> dataMap) {
//创建工作簿
Workbook workbook = new HSSFWorkbook();
//遍历台站数量
@ -208,8 +209,10 @@ public class ExportUtil {
cell.setCellValue(columnName);
}
rowIndex+=1;
//根据台站名称获取数据
List<Map<String, Object>> dataList = dataMap.get(stationName);
//遍历数据根据字段名称取值赋值
for (int j=0; j<dataList.size(); j++) {
for (int j=0; j<dataList.size(); j++,rowIndex++) {
//创建存储数据的行
Row dataRow = sheet.createRow(rowIndex);
//数据数组中读取下标对应的数据
@ -220,7 +223,11 @@ public class ExportUtil {
String columnName = columnNameList.get(k);
//根据列名读取对应数据的信息
Object value = data.get(StringUtils.upperCase(columnName));
cell.setCellValue(value.toString());
if (Objects.nonNull(value)) {
cell.setCellValue(value.toString());
} else {
cell.setCellValue("");
}
}
}
}

View File

@ -212,7 +212,13 @@ public class WebStatisticsController {
return gardsSampleDataWebService.findNuclideStatistics(stationId, systemType, dbName, nuclideNames, startDate, endDate);
}
@GetMapping("exportNuclideStatistics")
@ApiOperation(value = "导出核素统计结果", notes = "导出核素统计结果")
public void exportNuclideStatistics(String[] stationIds, String systemType, String dbName, String[] nuclideNames,
@DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate, @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate,
HttpServletResponse response) {
gardsSampleDataWebService.exportNuclideStatistics(stationIds, systemType, dbName, nuclideNames, startDate, endDate, response);
}

View File

@ -56,4 +56,6 @@ public interface IGardsSampleDataWebService extends IService<GardsSampleDataWeb>
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);
}

View File

@ -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<GardsSampleDataWe
}
@Override
public void radionuclideExport(Integer[] stationIds,
String dataType,
String pageType,
String spectralQualifie,
String startTime,
String endTime,
public void radionuclideExport(Integer[] stationIds, String dataType, String pageType,
String spectralQualifie, String startTime, String endTime,
HttpServletResponse response) {
Date startDate = DateUtil
@ -812,10 +809,7 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
}
@Override
public List<GardsSampleDataWeb> listBySampleIds(Integer[] stationIds,
String startTime,
String endTime,
List<Integer> sampleIds) {
public List<GardsSampleDataWeb> listBySampleIds(Integer[] stationIds, String startTime, String endTime, List<Integer> 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<GardsSampleDataWe
@Override
public Result findNuclideStatistics(String stationId, String systemType, String dbName, String[] nuclideNames, Date startDate, Date endDate) {
Result result = new Result();
//存储结果
Map<String, Object> resultMap = new HashMap<>();
//从redis中获取台站信息
Map<String, String> stationMap = (Map<String, String>)redisUtil.get("stationMap");
//判断开始时间是否为空
if (Objects.isNull(startDate)){
result.error500("The start time cannot be empty");
@ -937,11 +934,135 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
List<Map<String, Object>> 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<String, List<Map<String, Object>>> resultMap = new HashMap<>();
//从redis中获取台站信息
Map<String, String> stationMap = (Map<String, String>)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<String> 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<String> 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<String> stationNameList = new LinkedList<>();
for (String stationId:stationIds) {
//返回台站名称
String stationName = stationMap.get(stationId);
//拼接sql查询结果
List<Map<String, Object>> 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<String> nuclideNames) {
String sql = "";
//存储每个核素对应的sql
@ -1116,4 +1237,6 @@ public class GardsSampleDataWebServiceImpl extends ServiceImpl<GardsSampleDataWe
resultMap.put("AcqLiveSec", acqLiveSecList);
}
}