同步优化;洪水预测接口
parent
8d8d1a802e
commit
2fb4cbcd3a
|
|
@ -6,6 +6,7 @@ import com.baomidou.mybatisplus.core.toolkit.StringUtils;
|
|||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.gunshi.core.result.R;
|
||||
import com.gunshi.project.xyt.model.ForecastPlan;
|
||||
import com.gunshi.project.xyt.schedule.TaskGroupHandler;
|
||||
import com.gunshi.project.xyt.service.ForecastPlanService;
|
||||
import com.gunshi.project.xyt.validate.markers.Insert;
|
||||
import com.gunshi.project.xyt.validate.markers.Update;
|
||||
|
|
@ -36,11 +37,17 @@ public class ForecastPlanController {
|
|||
@Autowired
|
||||
private ForecastPlanService service;
|
||||
|
||||
@Autowired
|
||||
private TaskGroupHandler taskGroupHandler;
|
||||
|
||||
|
||||
@Operation(summary = "新增")
|
||||
@PostMapping("/insert")
|
||||
public R<ForecastPlan> insert(@Validated(Insert.class) @RequestBody ForecastPlan dto) {
|
||||
boolean result = service.save(dto);
|
||||
if(result){
|
||||
taskGroupHandler.addCronJob(String.valueOf(dto.getId()), dto);
|
||||
}
|
||||
return R.ok(result ? dto : null);
|
||||
}
|
||||
|
||||
|
|
@ -48,13 +55,22 @@ public class ForecastPlanController {
|
|||
@PostMapping("/update")
|
||||
public R<ForecastPlan> update(@Validated(Update.class) @RequestBody ForecastPlan dto) {
|
||||
boolean result = service.updateById(dto);
|
||||
if(result){
|
||||
// 先删除,再重新添加
|
||||
taskGroupHandler.removeCronJob(String.valueOf(dto.getId()));
|
||||
taskGroupHandler.addCronJob(String.valueOf(dto.getId()), dto);
|
||||
}
|
||||
return R.ok(result ? dto : null);
|
||||
}
|
||||
|
||||
@Operation(summary = "删除")
|
||||
@GetMapping("/del/{id}")
|
||||
public R<Boolean> del(@Schema(name = "id") @PathVariable("id") Serializable id) {
|
||||
return R.ok(service.removeById(id));
|
||||
boolean b = service.removeById(id);
|
||||
if (b) {
|
||||
taskGroupHandler.removeCronJob((String) id);
|
||||
}
|
||||
return R.ok(b);
|
||||
}
|
||||
|
||||
@Operation(summary = "列表")
|
||||
|
|
|
|||
|
|
@ -7,8 +7,10 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||
import com.gunshi.algorithm.RrainfallForecast;
|
||||
import com.gunshi.core.result.R;
|
||||
import com.gunshi.model.vo.FloodAlgorithemVo;
|
||||
import com.gunshi.project.xyt.entity.vo.ForecastResultVo;
|
||||
import com.gunshi.project.xyt.model.ForecastPlan;
|
||||
import com.gunshi.project.xyt.model.ForecastResults;
|
||||
import com.gunshi.project.xyt.service.ForecastPlanService;
|
||||
import com.gunshi.project.xyt.service.ForecastResultsService;
|
||||
import com.gunshi.project.xyt.validate.markers.Insert;
|
||||
import com.gunshi.project.xyt.validate.markers.Update;
|
||||
|
|
@ -22,6 +24,7 @@ import org.springframework.web.bind.annotation.PathVariable;
|
|||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
|
@ -38,9 +41,14 @@ import java.util.List;
|
|||
@RequestMapping(value="/forecastResults")
|
||||
public class ForecastResultsController {
|
||||
|
||||
private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
|
||||
@Autowired
|
||||
private ForecastResultsService service;
|
||||
|
||||
@Autowired
|
||||
private ForecastPlanService forecastPlanService;
|
||||
|
||||
|
||||
@Operation(summary = "新增")
|
||||
@PostMapping("/insert")
|
||||
|
|
@ -82,6 +90,27 @@ public class ForecastResultsController {
|
|||
return R.ok(service.page(forecastResults.getPageSo().toPage(), wrapper));
|
||||
}
|
||||
|
||||
@Operation(summary = "获取人工交互洪水预报结果")
|
||||
@PostMapping("/getHumanForecastResult")
|
||||
public R<List<ForecastResultVo>> getHumanForecastResult(@Schema(name = "forecastTm", description = "预报时间") @RequestParam("forecastTm") String forecastTm,
|
||||
@Schema(name = "startTm", description = "开始时间") @RequestParam("startTm") String startTm,
|
||||
@Schema(name = "endTm", description = "结束时间") @RequestParam("endTm") String endTm) throws Exception {
|
||||
ForecastPlan forecastPlan = new ForecastPlan();
|
||||
forecastPlan.setForecastTm(dateFormat.parse(forecastTm));
|
||||
forecastPlan.setStartTm(dateFormat.parse(startTm));
|
||||
forecastPlan.setEndTm(dateFormat.parse(endTm));
|
||||
List<ForecastResultVo> voList = service.getHumanForecastResult(forecastPlan);
|
||||
return R.ok(voList);
|
||||
}
|
||||
|
||||
// @Operation(summary = "查看方案洪水预报结果")
|
||||
// @PostMapping("/getForecastPlanResult")
|
||||
// public R<List<ForecastResultVo>> getForecastPlanResult(@Schema(name = "planId", description = "预测方案id") @RequestParam("planId") String planId) throws Exception {
|
||||
// ForecastPlan forecastPlan = forecastPlanService.getById(planId);
|
||||
// List<ForecastResultVo> voList = service.getForecastPlanResult(forecastPlan);
|
||||
// return R.ok(voList);
|
||||
// }
|
||||
|
||||
|
||||
@Operation(summary = "洪水预报测试")
|
||||
@PostMapping("/forecastTest")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,72 @@
|
|||
package com.gunshi.project.xyt.entity.vo;
|
||||
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
*@description 预测结果VO
|
||||
*@author cxw
|
||||
*@classname ForecastResultVo.java
|
||||
*@create 2024-07-31, 周三, 11:05:04
|
||||
*/
|
||||
@Schema(description="预测结果VO")
|
||||
@Data
|
||||
public class ForecastResultVo {
|
||||
|
||||
/**
|
||||
* 时间
|
||||
*/
|
||||
@Schema(description="时间")
|
||||
private String tm;
|
||||
|
||||
/**
|
||||
* 预测入库流量
|
||||
*/
|
||||
@Schema(description="预测入库流量")
|
||||
private BigDecimal ycRkQValue;
|
||||
|
||||
/**
|
||||
* 实际入库流量
|
||||
*/
|
||||
@Schema(description="实际入库流量")
|
||||
private BigDecimal realRkQValue;
|
||||
|
||||
/**
|
||||
* 预测出库流量
|
||||
*/
|
||||
@Schema(description="预测出库流量")
|
||||
private BigDecimal ycCkQValue;
|
||||
|
||||
/**
|
||||
* 实际出库流量
|
||||
*/
|
||||
@Schema(description="实际出库流量")
|
||||
private BigDecimal realCkQValue;
|
||||
|
||||
/**
|
||||
* 预测水库水位
|
||||
*/
|
||||
@Schema(description="预测水库水位")
|
||||
private BigDecimal ycSwHValue;
|
||||
|
||||
/**
|
||||
* 实际水库水位
|
||||
*/
|
||||
@Schema(description="实际水库水位")
|
||||
private BigDecimal realSwHValue;
|
||||
|
||||
/**
|
||||
* 预测降雨
|
||||
*/
|
||||
@Schema(description="预测降雨")
|
||||
private BigDecimal ycDrp;
|
||||
|
||||
/**
|
||||
* 实际水库水位
|
||||
*/
|
||||
@Schema(description="实际降雨")
|
||||
private BigDecimal realDrp;
|
||||
}
|
||||
|
|
@ -65,6 +65,13 @@ public class ForecastResults extends GenericPageParams implements Serializable {
|
|||
@Schema(description="水库水位")
|
||||
private BigDecimal swHValue;
|
||||
|
||||
/**
|
||||
* 降雨
|
||||
*/
|
||||
@TableField(value="drp_value")
|
||||
@Schema(description="降雨")
|
||||
private BigDecimal drpValue;
|
||||
|
||||
/**
|
||||
* 入库时间
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@ import org.quartz.Scheduler;
|
|||
import org.quartz.SchedulerException;
|
||||
import org.quartz.TriggerBuilder;
|
||||
import org.quartz.TriggerKey;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
|
|
@ -26,7 +25,6 @@ import org.springframework.web.bind.annotation.GetMapping;
|
|||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@Profile("prod")
|
||||
public class TaskGroupHandler {
|
||||
|
||||
@Resource
|
||||
|
|
|
|||
|
|
@ -9,7 +9,6 @@ import org.quartz.JobDataMap;
|
|||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobExecutionException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
|
@ -24,7 +23,6 @@ import java.util.List;
|
|||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
@Profile("prod")
|
||||
public class TaskGroupJob implements Job {
|
||||
|
||||
private static DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
|
|
|
|||
|
|
@ -4,9 +4,11 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.gunshi.algorithm.RrainfallForecast;
|
||||
import com.gunshi.model.vo.FloodAlgorithemVo;
|
||||
import com.gunshi.project.xyt.entity.vo.ForeRainTimeVo;
|
||||
import com.gunshi.project.xyt.entity.vo.ForeRainVo;
|
||||
import com.gunshi.project.xyt.entity.vo.ForecastResultVo;
|
||||
import com.gunshi.project.xyt.grb.RainGrib2Layer;
|
||||
import com.gunshi.project.xyt.mapper.ForecastResultsMapper;
|
||||
import com.gunshi.project.xyt.model.ForecastK;
|
||||
|
|
@ -17,6 +19,7 @@ import com.gunshi.project.xyt.model.ForecastUseparam;
|
|||
import com.gunshi.project.xyt.model.StPptnR;
|
||||
import com.gunshi.project.xyt.model.StRsvrR;
|
||||
import com.gunshi.project.xyt.model.StStbprpB;
|
||||
import com.gunshi.project.xyt.model.StWaterR;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
|
@ -27,6 +30,7 @@ import java.text.SimpleDateFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
|
@ -67,6 +71,9 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
|||
@Autowired
|
||||
private StStbprpBService stStbprpBService;
|
||||
|
||||
@Autowired
|
||||
private StWaterRService stWaterRService;
|
||||
|
||||
|
||||
/**
|
||||
* @description: 洪水预测
|
||||
|
|
@ -78,7 +85,7 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
|||
public List<FloodAlgorithemVo> floodForecast(ForecastPlan forecastPlan) {
|
||||
List<FloodAlgorithemVo> voList = new ArrayList<>();
|
||||
Date now = new Date();
|
||||
String dateStr = sdf.format(forecastPlan.getForecastTm());
|
||||
Date forecastTm = forecastPlan.getForecastTm();
|
||||
Date startTm = forecastPlan.getStartTm();
|
||||
Date endTm = forecastPlan.getEndTm();
|
||||
// 获取配置参数
|
||||
|
|
@ -90,7 +97,7 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
|||
double[] u = uList.stream().mapToDouble(forecastU -> forecastU.getUValue().doubleValue()).toArray();
|
||||
// 蒸发率
|
||||
Map<Integer, BigDecimal> kMap = kList.stream().collect(Collectors.toMap(ForecastK::getMonth, ForecastK::getKValue));
|
||||
double k = kMap.get(Integer.valueOf(dateStr.substring(5, 7))).doubleValue();
|
||||
double k = kMap.get(Integer.valueOf(sdf.format(forecastTm).substring(5, 7))).doubleValue();
|
||||
// 其它配置参数
|
||||
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode,
|
||||
ForecastUseparam::getParamValue));
|
||||
|
|
@ -102,9 +109,8 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
|||
double H1 = 0.0;// 初始水库水位,可以根据H1->V1,H1->q1得到初始的水库库容和下泄流量
|
||||
double PaT1 = 0.0;// 根据昨天的降雨值求今天早上的土壤含水量,这个每天早上8点,根据昨天的降雨值要重新计算。
|
||||
try {
|
||||
// 获取预测时间前的最后水库水位
|
||||
StRsvrR rsvrR = stRsvrRService.getOne(new QueryWrapper<StRsvrR>().eq("stcd", "716153201").le("tm", forecastPlan.getForecastTm()).orderBy(true, false,
|
||||
"tm").last("limit 1"));
|
||||
// 获取预测开始时间前的最后水库水位
|
||||
StRsvrR rsvrR = stRsvrRService.getOne(new QueryWrapper<StRsvrR>().eq("stcd", "716153201").le("tm", startTm).orderBy(true, false, "tm").last("limit 1"));
|
||||
if (ObjectUtils.isNotEmpty(rsvrR)) {
|
||||
H1 = Double.parseDouble(rsvrR.getRz());
|
||||
} else {
|
||||
|
|
@ -149,10 +155,16 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
|||
}
|
||||
}
|
||||
}
|
||||
System.out.println(pResultList);
|
||||
double[] PList = pResultList.stream().mapToDouble(Double::parseDouble).toArray();
|
||||
// 预测执行
|
||||
// voList = RrainfallForecast.getData(dateStr, k, PaT0, Wm, pt, H1, dt, PaT1, PList, u);
|
||||
voList = RrainfallForecast.getData(sdf.format(startTm), k, PaT0, Wm, pt, H1, dt, PaT1, PList, u);
|
||||
// 预测程序返回的时间会比想要的长,截取
|
||||
if(CollectionUtils.isNotEmpty(voList)){
|
||||
voList.subList(0, PList.length);
|
||||
for (int j = 0; j < voList.size(); j++){
|
||||
voList.get(j).setDrp(new BigDecimal(PList[j]));
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
|
@ -222,4 +234,64 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
|||
calendar.set(Calendar.MILLISECOND, 0);
|
||||
return date.before(calendar.getTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 获取人工交互洪水预报结果
|
||||
* @param forecastPlan
|
||||
* @return: java.util.List<com.gunshi.project.xyt.entity.vo.ForecastResultVo>
|
||||
* @auther: cxw
|
||||
* @date: 2024-07-31, 周三, 11:09:24
|
||||
*/
|
||||
public List<ForecastResultVo> getHumanForecastResult(ForecastPlan forecastPlan) {
|
||||
List<ForecastResultVo> resultList = new ArrayList<>();
|
||||
// 获取时间范围内的真实降雨
|
||||
List<StPptnR> pptnRList = stPptnRService.list(new QueryWrapper<StPptnR>().eq("stcd", "716153201").ge("tm", forecastPlan.getStartTm()).le("tm", forecastPlan.getForecastTm()));
|
||||
// 获取时间范围内的真实水位
|
||||
List<StRsvrR> rsvrRList = stRsvrRService.list(new QueryWrapper<StRsvrR>().eq("stcd", "716153201").ge("tm", forecastPlan.getStartTm()).le("tm", forecastPlan.getForecastTm()));
|
||||
// 获取时间范围内的真实入库流量
|
||||
List<StWaterR> waterRkList = stWaterRService.list(new QueryWrapper<StWaterR>().eq("stcd", "1111111").ge("tm", forecastPlan.getStartTm()).le("tm", forecastPlan.getForecastTm()));
|
||||
// 获取时间范围内的真实出库流量
|
||||
List<StWaterR> waterCkList = stWaterRService.list(new QueryWrapper<StWaterR>().eq("stcd", "2222222").ge("tm", forecastPlan.getStartTm()).le("tm", forecastPlan.getForecastTm()));
|
||||
List<FloodAlgorithemVo> floodAlgorithemVos = floodForecast(forecastPlan);
|
||||
if (CollectionUtils.isNotEmpty(floodAlgorithemVos)) {
|
||||
Map<Date, String> pptnRMap = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(pptnRList)) {
|
||||
pptnRMap = pptnRList.stream().collect(Collectors.toMap(StPptnR::getTm, StPptnR::getDrp));
|
||||
}
|
||||
Map<Date, String> rsvrRMap = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(rsvrRList)) {
|
||||
rsvrRMap = rsvrRList.stream().collect(Collectors.toMap(StRsvrR::getTm, StRsvrR::getRz));
|
||||
}
|
||||
Map<Date, String> waterRkMap = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(waterRkList)) {
|
||||
waterRkMap = waterRkList.stream().collect(Collectors.toMap(StWaterR::getTm, StWaterR::getQ));
|
||||
}
|
||||
Map<Date, String> waterCkMap = new HashMap<>();
|
||||
if (CollectionUtils.isNotEmpty(waterCkList)) {
|
||||
waterCkMap = waterRkList.stream().collect(Collectors.toMap(StWaterR::getTm, StWaterR::getQ));
|
||||
}
|
||||
// 组装
|
||||
for (FloodAlgorithemVo floodVo : floodAlgorithemVos) {
|
||||
ForecastResultVo vo = new ForecastResultVo();
|
||||
vo.setTm(floodVo.getDateStr());
|
||||
vo.setYcRkQValue(floodVo.getRq());
|
||||
vo.setYcCkQValue(floodVo.getCq());
|
||||
vo.setYcSwHValue(floodVo.getKh());
|
||||
vo.setYcDrp(floodVo.getDrp());
|
||||
if (pptnRMap.containsKey(floodVo.getDateStr())) {
|
||||
vo.setRealDrp(new BigDecimal(pptnRMap.get(floodVo.getDateStr())));
|
||||
}
|
||||
if (rsvrRMap.containsKey(floodVo.getDateStr())) {
|
||||
vo.setRealSwHValue(new BigDecimal(rsvrRMap.get(floodVo.getDateStr())));
|
||||
}
|
||||
if (waterRkMap.containsKey(floodVo.getDateStr())) {
|
||||
vo.setRealRkQValue(new BigDecimal(waterRkMap.get(floodVo.getDateStr())));
|
||||
}
|
||||
if (waterCkMap.containsKey(floodVo.getDateStr())) {
|
||||
vo.setRealCkQValue(new BigDecimal(waterCkMap.get(floodVo.getDateStr())));
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultList;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -188,6 +188,7 @@ public class DataTask {
|
|||
if(ObjectUtils.isEmpty(stm)){
|
||||
calendar.add(Calendar.DATE, -40);
|
||||
} else {
|
||||
calendar.setTime(stm);
|
||||
calendar.add(Calendar.HOUR, 1);
|
||||
}
|
||||
stm = calendar.getTime();
|
||||
|
|
@ -242,6 +243,7 @@ public class DataTask {
|
|||
if(ObjectUtils.isEmpty(stm)){
|
||||
calendar.add(Calendar.DATE, -14);
|
||||
} else {
|
||||
calendar.setTime(stm);
|
||||
calendar.add(Calendar.DATE, 1);
|
||||
}
|
||||
stm = calendar.getTime();
|
||||
|
|
@ -348,6 +350,7 @@ public class DataTask {
|
|||
if(ObjectUtils.isEmpty(stm)){
|
||||
calendar.add(Calendar.DATE, -40);
|
||||
} else {
|
||||
calendar.setTime(stm);
|
||||
calendar.add(Calendar.HOUR, 1);
|
||||
}
|
||||
stm = calendar.getTime();
|
||||
|
|
@ -448,6 +451,7 @@ public class DataTask {
|
|||
if(ObjectUtils.isEmpty(stm)){
|
||||
calendar.add(Calendar.DATE, -40);
|
||||
} else {
|
||||
calendar.setTime(stm);
|
||||
calendar.add(Calendar.HOUR, 1);
|
||||
}
|
||||
stm = calendar.getTime();
|
||||
|
|
|
|||
Loading…
Reference in New Issue