From dcdea2e2f105fac1e400e632bf8fd9972422f7e3 Mon Sep 17 00:00:00 2001 From: duwenyuan <1351851645@qq.com> Date: Sat, 25 Oct 2025 18:04:29 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A0=B7=E5=93=81=E7=9B=91?= =?UTF-8?q?=E6=8E=A7=E5=9B=9E=E6=94=BE=E8=BF=94=E5=9B=9E=E7=9A=84=E7=BB=93?= =?UTF-8?q?=E6=9E=9C=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/SampleStatAnalysisService.java | 78 +++++++++++++++++-- .../main/java/org/jeecg/vo/StationInfoVO.java | 19 +++++ 2 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 jeecg-module-data-analyze/src/main/java/org/jeecg/vo/StationInfoVO.java 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 bdcebba..ffe7c10 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 @@ -14,6 +14,7 @@ import org.jeecg.modules.base.entity.original.GardsSampleData; import org.jeecg.mapper.GardsSampleStatAnalysisMapper; import org.jeecg.service.ISampleStatAnalysisService; import org.jeecg.util.DistributionAnalysisToolkit; +import org.jeecg.vo.StationInfoVO; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; @@ -64,14 +65,79 @@ public class SampleStatAnalysisService extends ServiceImpl> groupedByMonth = StationInfoDataList.stream() - .collect(Collectors.groupingBy(station -> + //获取台站信息 +// Map stationInfo = +// StationInfoDataList.stream().collect( +// Collectors.toMap(StationInfoData::getStationCode, +// station -> +// new StationInfoVO(station.getStationCode(), station.getLon(),station.getLat()), +// (existing, replacement) -> existing) +// +// ); + Set stationInfoSet = StationInfoDataList.stream() + .map(station -> new StationInfoVO( + station.getStationCode(), + station.getLon(), + station.getLat() + )) + .collect(Collectors.toSet()); + + + List sortedList = StationInfoDataList.stream() + .sorted(Comparator.comparing(station -> station.getCollectStop().toInstant() .atZone(ZoneId.of("UTC")) - .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) - )); - resultMap.put("SampleMonitorResultList", groupedByMonth); + .toLocalDate() + )) + .collect(Collectors.toList()); + //时间段内有多少和台站 + Map>> groupedByMonth = + sortedList.stream() + .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")) + .format(DateTimeFormatter.ofPattern("yyyy-MM-dd")), + TreeMap::new, + Collectors.collectingAndThen( + Collectors.groupingBy( + StationInfoData::getStationCode, + Collectors.mapping( + StationInfoData::getCategory, + Collectors.toList() + ) + ), + stationCodeToCategories -> { + 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); + + resultList.add(entry); + }); + return resultList; + } + ) + )); + resultMap.put("stationInfo", stationInfoSet); + resultMap.put("sampleMonitorResultList", groupedByMonth); result.setSuccess(true); result.setResult(resultMap); return result; diff --git a/jeecg-module-data-analyze/src/main/java/org/jeecg/vo/StationInfoVO.java b/jeecg-module-data-analyze/src/main/java/org/jeecg/vo/StationInfoVO.java new file mode 100644 index 0000000..2f4cea6 --- /dev/null +++ b/jeecg-module-data-analyze/src/main/java/org/jeecg/vo/StationInfoVO.java @@ -0,0 +1,19 @@ +package org.jeecg.vo; + +import lombok.Data; + +@Data +public class StationInfoVO { + + + private String stationCode; + private String lon; + + private String lat; + + public StationInfoVO(String stationCode, String lon, String lat) { + this.stationCode = stationCode; + this.lon = lon; + this.lat = lat; + } +}