From d0e8848d43c1db767c01b7243430896a950b9094 Mon Sep 17 00:00:00 2001 From: duwenyuan <15600000461@163.com> Date: Wed, 31 Dec 2025 21:31:52 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=95=B0=E6=8D=AE=E5=88=86?= =?UTF-8?q?=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xml/GardsSampleStatAnalysisMapper.xml | 8 +- .../impl/SampleStatAnalysisService.java | 235 +++++++++++------- 2 files changed, 148 insertions(+), 95 deletions(-) diff --git a/jeecg-module-data-analyze/src/main/java/org/jeecg/mapper/xml/GardsSampleStatAnalysisMapper.xml b/jeecg-module-data-analyze/src/main/java/org/jeecg/mapper/xml/GardsSampleStatAnalysisMapper.xml index e673989..c8e6f1e 100644 --- a/jeecg-module-data-analyze/src/main/java/org/jeecg/mapper/xml/GardsSampleStatAnalysisMapper.xml +++ b/jeecg-module-data-analyze/src/main/java/org/jeecg/mapper/xml/GardsSampleStatAnalysisMapper.xml @@ -131,9 +131,9 @@ INNER JOIN RNAUTO.GARDS_XE_RESULTS b ON a.SAMPLE_ID = b.SAMPLE_ID - WHERE a.SAMPLE_TYPE = '#{sampleType}' + WHERE a.SAMPLE_TYPE = #{sampleType} AND a.STATION_ID = #{station} - AND b.NUCLIDENAME = #{nuclideName} + AND b.NUCLIDE_NAME = #{nuclideName} AND a.COLLECT_START BETWEEN TO_DATE(#{startTime}, 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(#{endTime}, 'YYYY-MM-DD HH24:MI:SS') @@ -155,9 +155,9 @@ INNER JOIN RNMAN.GARDS_NUCL_IDED b ON a.SAMPLE_ID = b.SAMPLE_ID - WHERE a.SAMPLE_TYPE = '#{sampleType}' + WHERE a.SAMPLE_TYPE = #{sampleType} AND a.STATION_ID = #{station} - AND b.NUCLIDENAME = #{nuclideName} + AND b.NUCLIDE_NAME = #{nuclideName} AND a.COLLECT_START BETWEEN TO_DATE(#{startTime}, 'YYYY-MM-DD HH24:MI:SS') AND TO_DATE(#{endTime}, 'YYYY-MM-DD HH24:MI:SS') 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 cb97958..826e6ab 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 @@ -6,11 +6,8 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.toolkit.StringUtils; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; -import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.PropertyNamingStrategies; import lombok.extern.slf4j.Slf4j; -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; @@ -27,7 +24,6 @@ import org.jeecg.vo.StationInfoVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; -import java.io.File; import java.text.SimpleDateFormat; import java.time.ZoneId; import java.time.format.DateTimeFormatter; @@ -37,7 +33,9 @@ import java.util.stream.Collectors; @Slf4j @Service @DS("ora") -public class SampleStatAnalysisService extends ServiceImpl implements ISampleStatAnalysisService { +public class SampleStatAnalysisService + extends ServiceImpl + implements ISampleStatAnalysisService { private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MM-dd"); // 动态颜色调色板(台站动态时自动循环) private static final String[] DETECTION_COLORS = { @@ -52,7 +50,8 @@ public class SampleStatAnalysisService extends ServiceImpl>> groupedByMonth = sortedList.stream() - .filter(station -> station.getCollectStop() != null) // 过滤 collectStop 为 null 的数据 - .filter(station -> station.getStationCode() != null) // 过滤 stationCode 为 null 的数据 - .filter(station -> station.getCategory() != null) // 过滤 category 为 null 的数据 + .filter(station -> station.getCollectStop() != + null) // 过滤 collectStop 为 null 的数据 + .filter(station -> station.getStationCode() != + null) // 过滤 stationCode 为 null 的数据 + .filter(station -> station.getCategory() != + null) // 过滤 category 为 null 的数据 .collect(Collectors.groupingBy( station -> station.getCollectStop().toInstant() .atZone(ZoneId.of("UTC")) @@ -132,28 +136,37 @@ public class SampleStatAnalysisService extends ServiceImpl { - List> resultList = new ArrayList<>(); - stationCodeToCategories.forEach((stationCode, categories) -> { - Map entry = new HashMap<>(); - entry.put("stationCode", stationCode); - //entry.put("categorys", new HashSet<>(categories)); // 去重后的集合 + List> resultList = + new ArrayList<>(); + stationCodeToCategories.forEach( + (stationCode, categories) -> { + Map entry = + new HashMap<>(); + entry.put("stationCode", stationCode); + //entry.put("categorys", new HashSet<>(categories)); // 去重后的集合 - // 统计 category 出现次数 - Map categoryCount = categories.stream() - .filter(Objects::nonNull) // 再次过滤 null(防御性编程) - .collect(Collectors.groupingBy( - category -> category, - Collectors.counting() - )); - Map levelCount = new HashMap<>(); - categoryCount.forEach((category, count) -> { - String levelKey = "level" + category; // 例如:1 → "level1" - levelCount.put(levelKey, count); - }); - entry.put("categoryCount", levelCount); + // 统计 category 出现次数 + Map categoryCount = + categories.stream() + .filter(Objects::nonNull) // 再次过滤 null(防御性编程) + .collect( + Collectors.groupingBy( + category -> category, + Collectors.counting() + )); + Map levelCount = + new HashMap<>(); + categoryCount.forEach( + (category, count) -> { + String levelKey = "level" + + category; // 例如:1 → "level1" + levelCount.put(levelKey, + count); + }); + entry.put("categoryCount", levelCount); - resultList.add(entry); - }); + resultList.add(entry); + }); return resultList; } ) @@ -178,7 +191,8 @@ public class SampleStatAnalysisService extends ServiceImpl resultMap = new HashMap<>(); List nuclideActConcIntvlList = new ArrayList<>(); @@ -209,34 +223,44 @@ public class SampleStatAnalysisService extends ServiceImpl> groupedByNuclideName = nuclideActConcIntvlList.stream() - .filter(p -> p.getNuclideName() != null) - .collect(Collectors.groupingBy(NuclideActConcIntvl::getNuclideName)); - Map> sortedByCount = groupedByNuclideName.entrySet().stream() - .sorted(Map.Entry.>comparingByValue( - Comparator.comparingInt(List::size) - ).reversed()) // .reversed() 表示从多到少 - .collect(Collectors.toMap( - Map.Entry::getKey, - Map.Entry::getValue, - (e1, e2) -> e1, - LinkedHashMap::new // 使用 LinkedHashMap - )); + Map> groupedByNuclideName = + nuclideActConcIntvlList.stream() + .filter(p -> p.getNuclideName() != null) + .collect(Collectors.groupingBy(NuclideActConcIntvl::getNuclideName)); + Map> sortedByCount = + groupedByNuclideName.entrySet().stream() + .sorted(Map.Entry.>comparingByValue( + Comparator.comparingInt(List::size) + ).reversed()) // .reversed() 表示从多到少 + .collect(Collectors.toMap( + Map.Entry::getKey, + Map.Entry::getValue, + (e1, e2) -> e1, + LinkedHashMap::new // 使用 LinkedHashMap + )); resultMap.put("nuclideActConcIntvlList", sortedByCount); result.setSuccess(true); result.setResult(resultMap); @@ -255,6 +279,7 @@ public class SampleStatAnalysisService extends ServiceImpl dataMap = new LinkedHashMap<>(); String schemaName = dataSource == 1 ? "RNAUTO" : "RNMAN"; // 1. 模拟从数据库获取该核素的原始数据 - List rawList = this.baseMapper.getIdentifiedNuclides(schemaName, nuclideName, stationCode, startTime, endTime); + List rawList = + this.baseMapper.getIdentifiedNuclides(schemaName, nuclideName, stationCode, + startTime, endTime); // 2. 排序(关键:X轴是时间轴,数据必须按时间升序) rawList.sort(Comparator.comparing(NuclideActConcIntvl::getCollectStop)); @@ -308,16 +337,17 @@ public class SampleStatAnalysisService extends ServiceImpl()); //double err = item.getConcErr() != null ? item.getConcErr() : 0; - double err =15; - levelGroup.get(categoryStr).add(new Object[]{timeStr, item.getConc(), err, err}); + //TODO 测试数据 + double err = 15; + levelGroup.get(categoryStr).add(new Object[] {timeStr, item.getConc(), err, err}); // if (cat == 3) { // // 3级: 携带误差维度 [时间, 活度, ConcErr , $Conc+ConcErr] // double err = item.getConcErr() != null ? item.getConcErr() : 0; @@ -347,7 +377,7 @@ public class SampleStatAnalysisService extends ServiceImpl> resultData = objectMapper.readValue(DataResult, new TypeReference<>() { - }); + Result> resultData = + objectMapper.readValue(DataResult, new TypeReference<>() { + }); result.setSuccess(true); result.setResult(resultData); @@ -3203,16 +3234,14 @@ public class SampleStatAnalysisService extends ServiceImpl resultMap = new HashMap<>(); @@ -3244,11 +3273,15 @@ public class SampleStatAnalysisService extends ServiceImpl resultMap = new HashMap<>(); List nuclideActConcIntvls = new ArrayList<>(); @@ -3317,21 +3350,30 @@ public class SampleStatAnalysisService extends ServiceImpl>() {}); //获取浓度出现的次数 //获取浓度值集合 - List data = DistributionAnalysisToolkit.convertConcToDoubleList(nuclideActConcIntvls); + List data = + DistributionAnalysisToolkit.convertConcToDoubleList(nuclideActConcIntvls); // 设置区间参数 double start = 0; // 区间起始值 double step = 200; // 区间步长(宽度) // 1. 区间统计 - List stats = DistributionAnalysisToolkit.calculateIntervalStats(nuclideActConcIntvls, start, step); + List stats = + DistributionAnalysisToolkit.calculateIntervalStats(nuclideActConcIntvls, start, + step); // 3. 累积分布函数 - List cdfPoints = DistributionAnalysisToolkit.calculateCDF(data); + List cdfPoints = + DistributionAnalysisToolkit.calculateCDF(data); // 4. 核密度估计 - List kdePoints = DistributionAnalysisToolkit.autoKDE(data, DistributionAnalysisToolkit.GAUSSIAN_KERNEL); + List kdePoints = + DistributionAnalysisToolkit.autoKDE(data, + DistributionAnalysisToolkit.GAUSSIAN_KERNEL); //获取所有浓度的累积 List cumulative = DistributionAnalysisToolkit.cumulativeSum(data); //获取95%累积线 @@ -3392,7 +3435,9 @@ public class SampleStatAnalysisService extends ServiceImpl resultMap = new HashMap<>(); @@ -3459,7 +3504,9 @@ public class SampleStatAnalysisService extends ServiceImpl sampleDatass = this.baseMapper.getNuclideTimeSeriesAnalysis(schemaName, station, nuclideName, startTime, endTime); + List sampleDatass = + this.baseMapper.getNuclideTimeSeriesAnalysis(schemaName, station, nuclideName, + startTime, endTime); // thresholdResultHisList = this.baseMapper.selectByCondition(schemaName, Arrays.asList(Integer.valueOf(station)) @@ -3490,7 +3537,9 @@ public class SampleStatAnalysisService extends ServiceImpl resultMap = new HashMap<>(); List nuclideActConcIntvls = new ArrayList<>(); @@ -3519,17 +3568,22 @@ public class SampleStatAnalysisService extends ServiceImpl nuclideActConcIntvls, Date startDate, Date endDate, String unit) { + private NuclideActConcIntvlVO convertToChartVO(List nuclideActConcIntvls, + Date startDate, Date endDate, String unit) { if (nuclideActConcIntvls == null || nuclideActConcIntvls.isEmpty()) { return new NuclideActConcIntvlVO(); } @@ -3568,7 +3623,8 @@ public class SampleStatAnalysisService extends ServiceImpl record.getStationId() != null ? record.getStationId().toString() : null) + .map(record -> record.getStationId() != null ? + record.getStationId().toString() : null) .orElse("UNKNOWN"); series.setStationCode(stationCode); series.setStationName(displayCode); // 可后续扩展 @@ -3651,9 +3707,6 @@ public class SampleStatAnalysisService extends ServiceImpl list) { if (list == null || list.isEmpty()) { // 处理空集合情况,返回一个默认值