From c5d3ca5de6982a7cdf7615fcebe8b880801afd18 Mon Sep 17 00:00:00 2001 From: chenxiwang <1520264117@qq.com> Date: Tue, 20 Aug 2024 10:19:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B4=AA=E6=B0=B4=E9=A2=84?= =?UTF-8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ForecastProjectController.java | 26 +++++++++++++++++-- .../xyt/entity/vo/ForecastResultVo.java | 6 +++++ .../xyt/service/ForecastResultsService.java | 16 ++++++++++-- 3 files changed, 44 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/gunshi/project/xyt/controller/ForecastProjectController.java b/src/main/java/com/gunshi/project/xyt/controller/ForecastProjectController.java index 80aec2c..37cb8ca 100644 --- a/src/main/java/com/gunshi/project/xyt/controller/ForecastProjectController.java +++ b/src/main/java/com/gunshi/project/xyt/controller/ForecastProjectController.java @@ -1,6 +1,5 @@ package com.gunshi.project.xyt.controller; -import com.alibaba.fastjson2.JSON; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; import com.baomidou.mybatisplus.core.toolkit.IdWorker; @@ -30,8 +29,10 @@ import org.springframework.web.bind.annotation.RestController; import java.io.Serializable; import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; /** * 描述: 预报_预测方案管理表 @@ -43,6 +44,8 @@ import java.util.Objects; @RequestMapping(value="/forecastProject") public class ForecastProjectController { + private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + @Autowired private ForecastProjectService service; @@ -129,7 +132,26 @@ public class ForecastProjectController { } List resultList = forecastResultsService.list(new QueryWrapper().eq("project_id", projectId).orderBy(true, true, "tm")); if (CollectionUtils.isNotEmpty(resultList)) { - forecastProject.setVoList(JSON.parseArray(JSON.toJSONString(resultList), ForecastResultVo.class)); + List vos = resultList.stream() + .map(result -> { + ForecastResultVo vo = new ForecastResultVo(); + vo.setTm(sdf.format(result.getTm())); + vo.setYcRkQValue(result.getYcRkQValue()); + vo.setRealRkQValue(result.getRealRkQValue()); + vo.setYcCkQValue(result.getYcCkQValue()); + vo.setRealCkQValue(result.getRealCkQValue()); + vo.setYcSwHValue(result.getYcSwHValue()); + vo.setRealSwHValue(result.getRealSwHValue()); + vo.setSwHDValue(result.getYcSwHValue().subtract(result.getRealSwHValue()));// 处理预测与实测水位差 + vo.setDrp(result.getDrp()); + vo.setIspreDrp(result.getIspreDrp()); + vo.setR(result.getR()); + vo.setFlLowLimLev(result.getFlLowLimLev()); + vo.setCurrentYdgdyjz(result.getCurrentYdgdyjz()); + vo.setPa(result.getPa()); + return vo; + }).collect(Collectors.toList()); + forecastProject.setVoList(vos); forecastResultsService.handleVoList(forecastProject); } return R.ok(forecastProject); diff --git a/src/main/java/com/gunshi/project/xyt/entity/vo/ForecastResultVo.java b/src/main/java/com/gunshi/project/xyt/entity/vo/ForecastResultVo.java index 4c4aab7..ca9ef7e 100644 --- a/src/main/java/com/gunshi/project/xyt/entity/vo/ForecastResultVo.java +++ b/src/main/java/com/gunshi/project/xyt/entity/vo/ForecastResultVo.java @@ -58,6 +58,12 @@ public class ForecastResultVo { @Schema(description="实际水库水位") private BigDecimal realSwHValue; + /** + * 水位:预测-实测 + */ + @Schema(description="水位:预测-实测") + private BigDecimal swHDValue; + /** * 降雨 */ diff --git a/src/main/java/com/gunshi/project/xyt/service/ForecastResultsService.java b/src/main/java/com/gunshi/project/xyt/service/ForecastResultsService.java index c9b19ce..137d4ff 100644 --- a/src/main/java/com/gunshi/project/xyt/service/ForecastResultsService.java +++ b/src/main/java/com/gunshi/project/xyt/service/ForecastResultsService.java @@ -40,6 +40,7 @@ import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; import java.util.stream.Collectors; /** @@ -252,6 +253,7 @@ public class ForecastResultsService extends ServiceImpl { Date date = entity.getTm(); return date.getMinutes() == 0 && date.getSeconds() == 0; - }).collect(Collectors.toList()); + }).collect(Collectors.toMap( + e -> e.getStcd() + "_" + e.getTm(), // 使用属性组合作为键 + Function.identity(), + (existing, replacement) -> existing // 如果有冲突,保留现有的 + )).values().stream().collect(Collectors.toList()); + rsvrRRealList.sort(Comparator.comparing(StRsvrR::getTm)); // 每次加0小时30分钟,根据dt设置,此时dt=0.5小时 int totalMinutes = (int) Math.round(dt * 60); // 计算小时数 @@ -400,7 +407,12 @@ public class ForecastResultsService extends ServiceImpl { Date date = entity.getTm(); return date.getMinutes() == 0 && date.getSeconds() == 0; - }).collect(Collectors.toList()); + }).collect(Collectors.toMap( + e -> e.getStcd() + "_" + e.getTm(), // 使用属性组合作为键 + Function.identity(), + (existing, replacement) -> existing // 如果有冲突,保留现有的 + )).values().stream().collect(Collectors.toList()); + filterList.sort(Comparator.comparing(StPptnR::getTm)); Map> retMap = new HashMap<>(); Map tmDrpMap = filterList.stream().collect(Collectors.toMap(pptnR -> sdfMinute.format(pptnR.getTm()), StPptnR::getDrp)); List listForForecast = new ArrayList<>();// 传给预测程序使用,缺失的数据为0