diff --git a/jeecg-module-data-analyze/src/main/java/org/jeecg/service/impl/SampleStatAnalysisService.java b/jeecg-module-data-analyze/src/main/java/org/jeecg/service/impl/SampleStatAnalysisService.java index 0ab8cb7..bdcebba 100644 --- a/jeecg-module-data-analyze/src/main/java/org/jeecg/service/impl/SampleStatAnalysisService.java +++ b/jeecg-module-data-analyze/src/main/java/org/jeecg/service/impl/SampleStatAnalysisService.java @@ -4,6 +4,7 @@ import com.baomidou.dynamic.datasource.annotation.DS; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; +import org.apache.commons.collections.CollectionUtils; import org.jeecg.common.api.vo.Result; import org.jeecg.common.constant.CommonConstant; import org.jeecg.common.util.DateUtils; @@ -30,53 +31,54 @@ public class SampleStatAnalysisService extends ServiceImpl resultMap = new HashMap<>(); - List StationInfoDataList = new ArrayList<>(); + try { + result.setCode(CommonConstant.SC_OK_200); + //声明返回用的结果map + Map resultMap = new HashMap<>(); + List StationInfoDataList = new ArrayList<>(); - //region 局部变量 - if (StringUtils.isBlank(sampleType)) { - result.error500("SampleType Code cannot be null"); + //region 局部变量 + if (StringUtils.isBlank(sampleType)) { + result.error500("SampleType Code cannot be null"); + return result; + } + 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"; + //endregion + + switch (dataSource) { + case 1: + StationInfoDataList = this.baseMapper.getRnAutoSampleResult(sampleType, startTime, endTime); + + break; + case 2: + StationInfoDataList = this.baseMapper.getRnManSampleResult(sampleType, startTime, endTime); + + break; + } + //时间段内有多少和台站 + Map> groupedByMonth = StationInfoDataList.stream() + .collect(Collectors.groupingBy(station -> + station.getCollectStop().toInstant() + .atZone(ZoneId.of("UTC")) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + )); + resultMap.put("SampleMonitorResultList", groupedByMonth); + result.setSuccess(true); + result.setResult(resultMap); + return result; + } catch (Exception e) { + result.error500("样品监测回放错误:" + e.getMessage()); return result; } - 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"; - //endregion - - switch (dataSource) { - case 1: - StationInfoDataList = this.baseMapper.getRnAutoSampleResult(sampleType, startTime, endTime); - - break; - case 2: - StationInfoDataList = this.baseMapper.getRnManSampleResult(sampleType, startTime, endTime); - - break; - } - //时间段内有多少和台站 - - Map> groupedByMonth = StationInfoDataList.stream() - .collect(Collectors.groupingBy(station -> - station.getCollectStop().toInstant() - .atZone(ZoneId.of("UTC")) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) - )); - - - resultMap.put("SampleMonitorResultList", groupedByMonth); - - result.setSuccess(true); - result.setResult(resultMap); - return result; } @@ -98,56 +100,62 @@ public class SampleStatAnalysisService extends ServiceImpl> groupedByNuclideName = nuclideActConcIntvlList.stream() + .filter(p -> p.getNuclideName() != null) + .collect(Collectors.groupingBy(NuclideActConcIntvl::getNuclideName)); + //查询级别 getSample + List nuclideNames = new ArrayList<>(groupedByNuclideName.keySet()); + if (CollectionUtils.isNotEmpty(nuclideNames)) { + //通过台站ID、核素名称查找阈值 + thresholdResultHisDataList = this.baseMapper.selectByStationAndNuclides(schemaName, Integer.valueOf(stationCode), nuclideNames, startTime, endTime); + } + resultMap.put("nuclideActConcIntvlList", groupedByNuclideName); + resultMap.put("sampleLevelDataList", sampleLevelDataList); + resultMap.put("thresholdResultHisDataList", thresholdResultHisDataList); + result.setSuccess(true); + result.setResult(resultMap); + return result; + } catch (Exception e) { + result.error500("样品统计分析错误:" + e.getMessage()); return result; } - 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"; - //endregion - switch (dataSource) { - //RNAUTO - case 1: - //获取样品中识别到的核素集合 - nuclideActConcIntvlList = this.baseMapper.getRnAutoIdentifiedNuclides(stationCode, startTime, endTime); - //核素等级时序分析 - sampleLevelDataList = this.baseMapper.getRnAutoNuclideTimeSeriesAnalysis(stationCode, startTime, endTime); - break; - //RNMAN - case 2: - //获取样品中识别到的核素集合 - nuclideActConcIntvlList = this.baseMapper.getRnManIdentifiedNuclides(stationCode, startTime, endTime); - - //核素等级时序分析 - sampleLevelDataList = this.baseMapper.getRnManNuclideTimeSeriesAnalysis(stationCode, startTime, endTime); - break; - } - //key=核素名称,value=获取样品中识别到的核素集合 - Map> groupedByNuclideName = nuclideActConcIntvlList.stream() - .filter(p -> p.getNuclideName() != null) - .collect(Collectors.groupingBy(NuclideActConcIntvl::getNuclideName)); - //查询级别 getSample - List nuclideNames = new ArrayList<>(groupedByNuclideName.keySet()); - //通过台站ID、核素名称查找阈值 - thresholdResultHisDataList = this.baseMapper.selectByStationAndNuclides(schemaName, Integer.valueOf(stationCode), nuclideNames, startTime, endTime); - - resultMap.put("nuclideActConcIntvlList", groupedByNuclideName); - resultMap.put("sampleLevelDataList", sampleLevelDataList); - resultMap.put("thresholdResultHisDataList", thresholdResultHisDataList); - result.setSuccess(true); - result.setResult(resultMap); - - return result; } /** @@ -163,43 +171,46 @@ public class SampleStatAnalysisService extends ServiceImpl sampleDataList = new ArrayList<>(); //region 局部变量 Result result = new Result(); - result.setCode(CommonConstant.SC_OK_200); - if (StringUtils.isBlank(sampleType)) { - result.error500("SampleType Code cannot be null"); + try { + result.setCode(CommonConstant.SC_OK_200); + if (StringUtils.isBlank(sampleType)) { + result.error500("SampleType Code cannot be null"); + return result; + } + if (StringUtils.isBlank(station)) { + result.error500("Station Code cannot be null"); + return result; + } + 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"; + //endregion + switch (dataSource) { + case 1: + sampleDataList = this.baseMapper.getRnAutoSampleGradeAnalysis(sampleType, station, startTime, endTime); + + break; + case 2: + sampleDataList = this.baseMapper.getRnManSampleGradeAnalysis(sampleType, station, startTime, endTime); + break; + + } + + resultMap.put("sampleDataList", sampleDataList); + result.setSuccess(true); + result.setResult(resultMap); + return result; + } catch (Exception e) { + result.error500("样品统计分析错误:" + e.getMessage()); return result; } - if (StringUtils.isBlank(station)) { - result.error500("Station Code cannot be null"); - return result; - } - 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"; - //endregion - switch (dataSource) { - case 1: - sampleDataList = this.baseMapper.getRnAutoSampleGradeAnalysis(sampleType, station, startTime, endTime); - - break; - case 2: - sampleDataList = this.baseMapper.getRnManSampleGradeAnalysis(sampleType, station, startTime, endTime); - break; - - } - - resultMap.put("sampleDataList", sampleDataList); - result.setSuccess(true); - result.setResult(resultMap); - - - return result; } /*** 样品活度浓度区间频率分析 @@ -219,86 +230,92 @@ public class SampleStatAnalysisService extends ServiceImpl nuclideActConcIntvls = new ArrayList<>(); //region 局部变量 Result result = new Result(); - result.setCode(CommonConstant.SC_OK_200); - if (StringUtils.isBlank(sampleType)) { - result.error500("SampleType Code cannot be null"); + try { + result.setCode(CommonConstant.SC_OK_200); + if (StringUtils.isBlank(sampleType)) { + result.error500("SampleType Code cannot be null"); + return result; + } + if (StringUtils.isBlank(nuclideName)) { + result.error500("nuclideName Code cannot be null"); + return result; + } + if (StringUtils.isBlank(station)) { + result.error500("Station Code cannot be null"); + return result; + } + 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"; + //endregion + + //根据数据源、样品类型查询样品的浓度 + switch (sampleType) { + case "P": + switch (dataSource) { + //RNAUTO + case 1: + nuclideActConcIntvls = this.baseMapper.getRnautoPNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); + break; + //RNMAN + case 2: + nuclideActConcIntvls = this.baseMapper.getRnautoNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); + break; + } + break; + case "B": + switch (dataSource) { + case 1: + nuclideActConcIntvls = this.baseMapper.getRnmanPNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); + break; + case 2: + nuclideActConcIntvls = this.baseMapper.getRnmanNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); + break; + + } + break; + + } + + //获取浓度出现的次数 + //获取浓度值集合 + List data = DistributionAnalysisToolkit.convertConcToDoubleList(nuclideActConcIntvls); + // 设置区间参数 + double start = 0; // 区间起始值 + double step = 200; // 区间步长(宽度) + + + // 1. 区间统计 + List stats = DistributionAnalysisToolkit.calculateIntervalStats(nuclideActConcIntvls, start, step); + // 3. 累积分布函数 + List cdfPoints = DistributionAnalysisToolkit.calculateCDF(data); + // 4. 核密度估计 + List kdePoints = DistributionAnalysisToolkit.autoKDE(data, DistributionAnalysisToolkit.GAUSSIAN_KERNEL); + //获取所有浓度的累积 + List cumulative = DistributionAnalysisToolkit.cumulativeSum(data); + //获取95%累积线 + double percentile95 = DistributionAnalysisToolkit.calculate95thPercentile(data); + + resultMap.put("stats", stats); + resultMap.put("cdfPoints", cdfPoints); + resultMap.put("kdePoints", kdePoints); + resultMap.put("cumulative", cumulative); + resultMap.put("percentile95", percentile95); + result.setSuccess(true); + result.setResult(resultMap); + return result; + } catch (Exception e) { + result.error500("样品活度浓度区间频率分析错误:" + e.getMessage()); return result; } - if (StringUtils.isBlank(nuclideName)) { - result.error500("nuclideName Code cannot be null"); - return result; - } - if (StringUtils.isBlank(station)) { - result.error500("Station Code cannot be null"); - return result; - } - 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"; - //endregion - //根据数据源、样品类型查询样品的浓度 - switch (sampleType) { - case "P": - switch (dataSource) { - //RNAUTO - case 1: - nuclideActConcIntvls = this.baseMapper.getRnautoPNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); - break; - //RNMAN - case 2: - nuclideActConcIntvls = this.baseMapper.getRnautoNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); - break; - } - break; - case "B": - switch (dataSource) { - case 1: - nuclideActConcIntvls = this.baseMapper.getRnmanPNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); - break; - case 2: - nuclideActConcIntvls = this.baseMapper.getRnmanNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); - break; - - } - break; - - } - - //获取浓度出现的次数 - //获取浓度值集合 - List data = DistributionAnalysisToolkit.convertConcToDoubleList(nuclideActConcIntvls); - // 设置区间参数 - double start = 0; // 区间起始值 - double step = 200; // 区间步长(宽度) - - - // 1. 区间统计 - List stats = DistributionAnalysisToolkit.calculateIntervalStats(nuclideActConcIntvls, start, step); - // 3. 累积分布函数 - List cdfPoints = DistributionAnalysisToolkit.calculateCDF(data); - // 4. 核密度估计 - List kdePoints = DistributionAnalysisToolkit.autoKDE(data, DistributionAnalysisToolkit.GAUSSIAN_KERNEL); - //获取所有浓度的累积 - List cumulative = DistributionAnalysisToolkit.cumulativeSum(data); - //获取95%累积线 - double percentile95 = DistributionAnalysisToolkit.calculate95thPercentile(data); - - resultMap.put("stats", stats); - resultMap.put("cdfPoints", cdfPoints); - resultMap.put("kdePoints", kdePoints); - resultMap.put("cumulative", cumulative); - resultMap.put("percentile95", percentile95); - result.setSuccess(true); - result.setResult(resultMap); - return result; } /*** 核素活度浓度时序分析 @@ -314,75 +331,82 @@ public class SampleStatAnalysisService extends ServiceImpl resultMap = new HashMap<>(); - //region 局部变量 + try { + result.setCode(CommonConstant.SC_OK_200); - if (StringUtils.isBlank(sampleType)) { - result.error500("SampleType Code cannot be null"); - return result; - } - if (StringUtils.isBlank(nuclideName)) { - result.error500("nuclideName Code cannot be null"); - return result; - } - if (StringUtils.isBlank(station)) { - result.error500("Station Code cannot be null"); - return result; - } - 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"; - //endregion - //获取样品阈值级别和阈值 - List sampleDatas = new ArrayList<>(); - //核素的阈值 - List thresholdResultHisList = new ArrayList<>(); - List nuclideActConcIntvls = new ArrayList<>(); - nuclideActConcIntvls = switch (sampleType) { - case "P" -> { - sampleDatas = this.baseMapper.getRnAutoSampleLevel(station, startTime, endTime); - yield switch (dataSource) { - //RNAUTO - case 1 -> - this.baseMapper.getRnautoPNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); - //RNMAN - case 2 -> - this.baseMapper.getRnautoNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); - default -> nuclideActConcIntvls; - }; + //region 局部变量 + + if (StringUtils.isBlank(sampleType)) { + result.error500("SampleType Code cannot be null"); + return result; } - case "B" -> { - sampleDatas = this.baseMapper.getRnManSampleLevel(station, startTime, endTime); - yield switch (dataSource) { - case 1 -> - this.baseMapper.getRnmanPNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); - case 2 -> - this.baseMapper.getRnmanNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); - default -> nuclideActConcIntvls; - }; + if (StringUtils.isBlank(nuclideName)) { + result.error500("nuclideName Code cannot be null"); + return result; } - default -> nuclideActConcIntvls; - }; - String schemaName = dataSource == 1 ? "RNAUTO" : "RNMAN"; + if (StringUtils.isBlank(station)) { + result.error500("Station Code cannot be null"); + return result; + } + 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"; + //endregion + //获取样品阈值级别和阈值 + List sampleDatas = new ArrayList<>(); + //核素的阈值 + List thresholdResultHisList = new ArrayList<>(); + List nuclideActConcIntvls = new ArrayList<>(); + nuclideActConcIntvls = switch (sampleType) { + case "P" -> { + sampleDatas = this.baseMapper.getRnAutoSampleLevel(station, startTime, endTime); + yield switch (dataSource) { + //RNAUTO + case 1 -> + this.baseMapper.getRnautoPNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); + //RNMAN + case 2 -> + this.baseMapper.getRnautoNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); + default -> nuclideActConcIntvls; + }; + } + case "B" -> { + sampleDatas = this.baseMapper.getRnManSampleLevel(station, startTime, endTime); + yield switch (dataSource) { + case 1 -> + this.baseMapper.getRnmanPNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); + case 2 -> + this.baseMapper.getRnmanNuclideActConcIntvl(sampleType, station, nuclideName, startTime, endTime); + default -> nuclideActConcIntvls; + }; + } + default -> nuclideActConcIntvls; + }; + String schemaName = dataSource == 1 ? "RNAUTO" : "RNMAN"; - thresholdResultHisList = this.baseMapper.selectByCondition(schemaName, Arrays.asList(Integer.valueOf(station)) - , Arrays.asList(nuclideName), startTime, endTime); - resultMap.put("sampleDataList", sampleDatas); - resultMap.put("nuclideInfoList", nuclideActConcIntvls); - resultMap.put("thresholdResultHisList", thresholdResultHisList); + thresholdResultHisList = this.baseMapper.selectByCondition(schemaName, Arrays.asList(Integer.valueOf(station)) + , Arrays.asList(nuclideName), startTime, endTime); + resultMap.put("sampleDataList", sampleDatas); + resultMap.put("nuclideInfoList", nuclideActConcIntvls); + resultMap.put("thresholdResultHisList", thresholdResultHisList); + + result.setSuccess(true); + result.setResult(resultMap); + return result; + } catch (Exception e) { + result.error500("核素活度浓度时序分析错误:" + e.getMessage()); + return result; + } - result.setSuccess(true); - result.setResult(resultMap); - return result; } /*** 核素活度浓度对比分析 @@ -396,43 +420,48 @@ public class SampleStatAnalysisService extends ServiceImpl resultMap = new HashMap<>(); List nuclideActConcIntvls = new ArrayList<>(); - //region 局部变量 - 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"; - if (Objects.isNull(stationIds)) { + Result result = new Result(); + try { + result.setCode(CommonConstant.SC_OK_200); + + //region 局部变量 + 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"; + + if (Objects.isNull(stationIds)) { + result.setSuccess(true); + result.setResult(Collections.emptyList()); + return result; + } + //endregion + switch (dataSource) { + case 1: + nuclideActConcIntvls = this.baseMapper.getRnAutoAnalyzeNuclideActivityConc(sampleType, nuclideName, stationIds, startTime, endTime); + break; + case 2: + nuclideActConcIntvls = this.baseMapper.getRnManAnalyzeNuclideActivityConc(sampleType, nuclideName, stationIds, startTime, endTime); + break; + + } + resultMap.put("nuclideInfoList", nuclideActConcIntvls); result.setSuccess(true); - result.setResult(Collections.emptyList()); + result.setResult(resultMap); + return result; + } catch (Exception e) { + result.error500("核素活度浓度对比分析错误:" + e.getMessage()); return result; } - //endregion - switch (dataSource) { - case 1: - nuclideActConcIntvls = this.baseMapper.getRnAutoAnalyzeNuclideActivityConc(sampleType, nuclideName, stationIds, startTime, endTime); - break; - case 2: - nuclideActConcIntvls = this.baseMapper.getRnManAnalyzeNuclideActivityConc(sampleType, nuclideName, stationIds, startTime, endTime); - break; - - } - resultMap.put("nuclideInfoList", nuclideActConcIntvls); - result.setSuccess(true); - result.setResult(resultMap); - - return result; } @Override