修改样品监控回放返回的结果格式

This commit is contained in:
duwenyuan 2025-10-25 18:04:29 +08:00
parent faddfbd223
commit dcdea2e2f1
2 changed files with 91 additions and 6 deletions

View File

@ -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<GardsSampleStatAnalys
break;
}
//时间段内有多少和台站
Map<String, List<StationInfoData>> groupedByMonth = StationInfoDataList.stream()
.collect(Collectors.groupingBy(station ->
//获取台站信息
// Map<String, StationInfoVO> stationInfo =
// StationInfoDataList.stream().collect(
// Collectors.toMap(StationInfoData::getStationCode,
// station ->
// new StationInfoVO(station.getStationCode(), station.getLon(),station.getLat()),
// (existing, replacement) -> existing)
//
// );
Set<StationInfoVO> stationInfoSet = StationInfoDataList.stream()
.map(station -> new StationInfoVO(
station.getStationCode(),
station.getLon(),
station.getLat()
))
.collect(Collectors.toSet());
List<StationInfoData> 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<String, List<Map<String, Object>>> 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<Map<String, Object>> resultList = new ArrayList<>();
stationCodeToCategories.forEach((stationCode, categories) -> {
Map<String, Object> entry = new HashMap<>();
entry.put("stationCode", stationCode);
//entry.put("categorys", new HashSet<>(categories)); // 去重后的集合
// 统计 category 出现次数
Map<Integer, Long> categoryCount = categories.stream()
.filter(Objects::nonNull) // 再次过滤 null防御性编程
.collect(Collectors.groupingBy(
category -> category,
Collectors.counting()
));
Map<String, Long> 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;

View File

@ -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;
}
}