修改样品监控回放返回的结果格式
This commit is contained in:
parent
faddfbd223
commit
dcdea2e2f1
|
|
@ -14,6 +14,7 @@ import org.jeecg.modules.base.entity.original.GardsSampleData;
|
||||||
import org.jeecg.mapper.GardsSampleStatAnalysisMapper;
|
import org.jeecg.mapper.GardsSampleStatAnalysisMapper;
|
||||||
import org.jeecg.service.ISampleStatAnalysisService;
|
import org.jeecg.service.ISampleStatAnalysisService;
|
||||||
import org.jeecg.util.DistributionAnalysisToolkit;
|
import org.jeecg.util.DistributionAnalysisToolkit;
|
||||||
|
import org.jeecg.vo.StationInfoVO;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
@ -64,14 +65,79 @@ public class SampleStatAnalysisService extends ServiceImpl<GardsSampleStatAnalys
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
//时间段内有多少和台站
|
//获取台站信息
|
||||||
Map<String, List<StationInfoData>> groupedByMonth = StationInfoDataList.stream()
|
// Map<String, StationInfoVO> stationInfo =
|
||||||
.collect(Collectors.groupingBy(station ->
|
// 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()
|
station.getCollectStop().toInstant()
|
||||||
.atZone(ZoneId.of("UTC"))
|
.atZone(ZoneId.of("UTC"))
|
||||||
.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"))
|
.toLocalDate()
|
||||||
));
|
))
|
||||||
resultMap.put("SampleMonitorResultList", groupedByMonth);
|
.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.setSuccess(true);
|
||||||
result.setResult(resultMap);
|
result.setResult(resultMap);
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user