洪水预测相关优化
parent
5a59239d75
commit
fab8bfec9c
|
|
@ -33,4 +33,6 @@ public interface StPptnRMapper extends BaseMapper<StPptnR> {
|
||||||
List<StPptnR> getStcdLastPptnData();
|
List<StPptnR> getStcdLastPptnData();
|
||||||
|
|
||||||
List<Map<String, Object>> getPptnRDataList(@Param("stcd") String stcd, @Param("tm") String tm);
|
List<Map<String, Object>> getPptnRDataList(@Param("stcd") String stcd, @Param("tm") String tm);
|
||||||
|
|
||||||
|
List<Map<String, Object>> getPptnRDataListByTask(@Param("resCode") String resCode, @Param("stcd") String stcd, @Param("tm") String tm);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
package com.gunshi.project.xyt.model;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
|
import com.gunshi.core.dateformat.DateFormatString;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 描述: 降水量表-面雨量
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class StPptnRAverage extends StPptnR {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时段降水量
|
||||||
|
*/
|
||||||
|
@Schema(description="时段降水量")
|
||||||
|
private String drp;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时间
|
||||||
|
*/
|
||||||
|
@Schema(description="时间")
|
||||||
|
@JsonFormat(pattern = DateFormatString.YYYY_MM_DD_HH_MM_SS, timezone = "GMT+8")
|
||||||
|
private Date tm;
|
||||||
|
|
||||||
|
public StPptnRAverage(Date tm, String drp) {
|
||||||
|
this.tm = tm;
|
||||||
|
this.drp = drp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -21,6 +21,7 @@ import com.gunshi.project.xyt.model.ForecastTask;
|
||||||
import com.gunshi.project.xyt.model.ForecastU;
|
import com.gunshi.project.xyt.model.ForecastU;
|
||||||
import com.gunshi.project.xyt.model.ForecastUseparam;
|
import com.gunshi.project.xyt.model.ForecastUseparam;
|
||||||
import com.gunshi.project.xyt.model.StPptnR;
|
import com.gunshi.project.xyt.model.StPptnR;
|
||||||
|
import com.gunshi.project.xyt.model.StPptnRAverage;
|
||||||
import com.gunshi.project.xyt.model.StRsvrR;
|
import com.gunshi.project.xyt.model.StRsvrR;
|
||||||
import com.gunshi.project.xyt.model.StStbprpB;
|
import com.gunshi.project.xyt.model.StStbprpB;
|
||||||
import com.gunshi.project.xyt.model.StZqrlB;
|
import com.gunshi.project.xyt.model.StZqrlB;
|
||||||
|
|
@ -125,7 +126,8 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
||||||
voList = excuteForecast(forecastTask);
|
voList = excuteForecast(forecastTask);
|
||||||
voList.sort(Comparator.comparing(ForecastResultVo::getTm));
|
voList.sort(Comparator.comparing(ForecastResultVo::getTm));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("数据异常!");
|
e.printStackTrace();
|
||||||
|
throw new IllegalArgumentException(e.getMessage());
|
||||||
}
|
}
|
||||||
return voList;
|
return voList;
|
||||||
}
|
}
|
||||||
|
|
@ -138,9 +140,19 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
||||||
* @date: 2024-08-05, 周一, 17:14:52
|
* @date: 2024-08-05, 周一, 17:14:52
|
||||||
*/
|
*/
|
||||||
private List<ForecastResultVo> excuteForecast(ForecastTask forecastTask) throws Exception {
|
private List<ForecastResultVo> excuteForecast(ForecastTask forecastTask) throws Exception {
|
||||||
|
List<ForecastResultVo> voList = new ArrayList<>();
|
||||||
|
// 获取配置参数
|
||||||
|
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
|
||||||
|
if (CollectionUtils.isEmpty(paramList)) {
|
||||||
|
throw new IllegalArgumentException("温馨提示:当前洪水预报所依赖的数据尚不完整,请检查入参是否缺失。");
|
||||||
|
}
|
||||||
// 获取系统当前的水库站编码、汛限水位
|
// 获取系统当前的水库站编码、汛限水位
|
||||||
AttResBase attResBase = attResBaseService.getOne(new QueryWrapper<>());
|
AttResBase attResBase = attResBaseService.getOne(new QueryWrapper<>());
|
||||||
List<ForecastResultVo> voList = new ArrayList<>();
|
// 多站点水库面雨量
|
||||||
|
List<StStbprpB> stbs = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("res_code", attResBase.getResCode()));
|
||||||
|
if (CollectionUtils.isEmpty(stbs)) {
|
||||||
|
return voList;
|
||||||
|
}
|
||||||
Date nowHourTime = forecastTask.getNowTime();
|
Date nowHourTime = forecastTask.getNowTime();
|
||||||
Date startTime = forecastTask.getStartTime();
|
Date startTime = forecastTask.getStartTime();
|
||||||
Date endTime = forecastTask.getEndTime();
|
Date endTime = forecastTask.getEndTime();
|
||||||
|
|
@ -149,30 +161,43 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
||||||
List<StPptnR> pptnRFutureList = new ArrayList<>();
|
List<StPptnR> pptnRFutureList = new ArrayList<>();
|
||||||
QueryWrapper<StPptnR> qwExisted = new QueryWrapper<>();
|
QueryWrapper<StPptnR> qwExisted = new QueryWrapper<>();
|
||||||
Boolean isHaveFuturePPtn = true;
|
Boolean isHaveFuturePPtn = true;
|
||||||
// 如果结束时间在当前时间之前,降雨序列从历史降雨表获取
|
for(StStbprpB b : stbs){
|
||||||
if (endTime.compareTo(nowHourTime) <= 0) {
|
String stcd = b.getStcd();
|
||||||
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", attResBase.getStcd()).ge("tm", startTime).le("tm", endTime).orderBy(true, true, "tm");
|
// 如果结束时间在当前时间之前,降雨序列从历史降雨表获取
|
||||||
} else {
|
if (endTime.compareTo(nowHourTime) <= 0) {
|
||||||
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", attResBase.getStcd()).ge("tm", startTime).le("tm", nowHourTime).orderBy(true, true, "tm");
|
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", stcd).ge("tm", startTime).le("tm", endTime).orderBy(true, true, "tm");
|
||||||
try {
|
} else {
|
||||||
// 获取预报数据
|
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", stcd).ge("tm", startTime).le("tm", nowHourTime).orderBy(true, true, "tm");
|
||||||
pptnRFutureList = getForecastDrpData(nowHourTime, attResBase.getStcd());
|
try {
|
||||||
} catch (IllegalArgumentException e) {
|
// 获取预报数据
|
||||||
isHaveFuturePPtn = false;
|
pptnRFutureList = getForecastDrpData(nowHourTime, stcd);
|
||||||
log.error("该时间无预报数据");
|
} catch (IllegalArgumentException e) {
|
||||||
|
if(stcd.equals(attResBase.getStcd())){
|
||||||
|
isHaveFuturePPtn = false;
|
||||||
|
}
|
||||||
|
log.error("该时间无预报数据");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
List<StPptnR> pptnRExistedList = stPptnRService.list(qwExisted);
|
||||||
|
pptnRAllList.addAll(pptnRExistedList);
|
||||||
|
pptnRAllList.addAll(pptnRFutureList);
|
||||||
}
|
}
|
||||||
List<StPptnR> pptnRExistedList = stPptnRService.list(qwExisted);
|
|
||||||
pptnRAllList.addAll(pptnRExistedList);
|
|
||||||
pptnRAllList.addAll(pptnRFutureList);
|
|
||||||
if (CollectionUtils.isEmpty(pptnRAllList)) {
|
if (CollectionUtils.isEmpty(pptnRAllList)) {
|
||||||
return voList;
|
return voList;
|
||||||
}
|
}
|
||||||
// 获取配置参数
|
// 多站点面雨量结果list
|
||||||
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
|
List<StPptnR> polyPptnRList = pptnRAllList.stream()
|
||||||
if (CollectionUtils.isEmpty(paramList)) {
|
.collect(Collectors.groupingBy(
|
||||||
throw new IllegalArgumentException("温馨提示:当前洪水预报所依赖的数据尚不完整,请检查入参是否缺失。");
|
StPptnR::getTm,
|
||||||
}
|
Collectors.mapping(
|
||||||
|
pptn -> Double.parseDouble(pptn.getDrp()), // 将String转换为double
|
||||||
|
Collectors.averagingDouble(d -> d) // 计算平均值
|
||||||
|
)
|
||||||
|
))
|
||||||
|
.entrySet().stream()
|
||||||
|
.map(entry -> new StPptnRAverage(entry.getKey(), String.valueOf(entry.getValue())))
|
||||||
|
.sorted(Comparator.comparing(StPptnRAverage::getTm))
|
||||||
|
.collect(Collectors.toList());
|
||||||
double dt = 0.0;
|
double dt = 0.0;
|
||||||
double Wm = 0.0;
|
double Wm = 0.0;
|
||||||
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
|
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
|
||||||
|
|
@ -228,7 +253,7 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
||||||
}
|
}
|
||||||
// 根据降雨数据,按照△t的颗粒度,均分
|
// 根据降雨数据,按照△t的颗粒度,均分
|
||||||
// 筛选时间段内的降雨数据。不包前但包后
|
// 筛选时间段内的降雨数据。不包前但包后
|
||||||
List<StPptnR> filterList = pptnRAllList.stream().filter(e -> e.getTm().compareTo(period[0]) >= 0).filter(e -> e.getTm().compareTo(period[1]) <= 0).collect(Collectors.toList());
|
List<StPptnR> filterList = polyPptnRList.stream().filter(e -> e.getTm().compareTo(period[0]) >= 0).filter(e -> e.getTm().compareTo(period[1]) <= 0).collect(Collectors.toList());
|
||||||
Map<String, List<StPptnR>> retMap = new HashMap<>();
|
Map<String, List<StPptnR>> retMap = new HashMap<>();
|
||||||
if (CollectionUtils.isNotEmpty(filterList)) {
|
if (CollectionUtils.isNotEmpty(filterList)) {
|
||||||
retMap = reorganizePptnRData(filterList, dt, period[0], period[1], nowHourTime, isHaveFuturePPtn);
|
retMap = reorganizePptnRData(filterList, dt, period[0], period[1], nowHourTime, isHaveFuturePPtn);
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,10 @@ public class StPptnRService extends ServiceImpl<StPptnRMapper, StPptnR>
|
||||||
public List<Map<String, Object>> getPptnRDataList(String stcd, String tm) {
|
public List<Map<String, Object>> getPptnRDataList(String stcd, String tm) {
|
||||||
return baseMapper.getPptnRDataList(stcd, tm);
|
return baseMapper.getPptnRDataList(stcd, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<Map<String, Object>> getPptnRDataListByTask(String resCode, String stcd, String tm) {
|
||||||
|
return baseMapper.getPptnRDataListByTask(resCode, stcd, tm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,18 +4,19 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||||
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
||||||
import com.gunshi.algorithm.RunoffService;
|
import com.gunshi.algorithm.RunoffService;
|
||||||
|
import com.gunshi.project.xyt.model.AttResBase;
|
||||||
import com.gunshi.project.xyt.model.ForecastK;
|
import com.gunshi.project.xyt.model.ForecastK;
|
||||||
import com.gunshi.project.xyt.model.ForecastPa;
|
import com.gunshi.project.xyt.model.ForecastPa;
|
||||||
import com.gunshi.project.xyt.model.ForecastUseparam;
|
import com.gunshi.project.xyt.model.ForecastUseparam;
|
||||||
import com.gunshi.project.xyt.model.StPptnR;
|
import com.gunshi.project.xyt.model.StPptnR;
|
||||||
import com.gunshi.project.xyt.model.StStbprpB;
|
import com.gunshi.project.xyt.model.StStbprpB;
|
||||||
|
import com.gunshi.project.xyt.service.AttResBaseService;
|
||||||
import com.gunshi.project.xyt.service.ForecastKService;
|
import com.gunshi.project.xyt.service.ForecastKService;
|
||||||
import com.gunshi.project.xyt.service.ForecastPaService;
|
import com.gunshi.project.xyt.service.ForecastPaService;
|
||||||
import com.gunshi.project.xyt.service.ForecastResultsService;
|
import com.gunshi.project.xyt.service.ForecastResultsService;
|
||||||
import com.gunshi.project.xyt.service.ForecastUseparamService;
|
import com.gunshi.project.xyt.service.ForecastUseparamService;
|
||||||
import com.gunshi.project.xyt.service.StPptnRService;
|
import com.gunshi.project.xyt.service.StPptnRService;
|
||||||
import com.gunshi.project.xyt.service.StStbprpBService;
|
import com.gunshi.project.xyt.service.StStbprpBService;
|
||||||
import jakarta.annotation.PostConstruct;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
|
|
@ -70,6 +71,9 @@ public class PaDataTask {
|
||||||
@Autowired
|
@Autowired
|
||||||
private ForecastResultsService forecastResultsService;
|
private ForecastResultsService forecastResultsService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private AttResBaseService attResBaseService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @description: 每天8点30计算的Pa
|
* @description: 每天8点30计算的Pa
|
||||||
* @param
|
* @param
|
||||||
|
|
@ -79,7 +83,6 @@ public class PaDataTask {
|
||||||
*/
|
*/
|
||||||
@Async
|
@Async
|
||||||
@Scheduled(cron ="0 30 8 * * ?")
|
@Scheduled(cron ="0 30 8 * * ?")
|
||||||
// @PostConstruct
|
|
||||||
public void PaDataCalc() throws ParseException {
|
public void PaDataCalc() throws ParseException {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
calendar.setTime(new Date());
|
calendar.setTime(new Date());
|
||||||
|
|
@ -87,58 +90,60 @@ public class PaDataTask {
|
||||||
// 获取配置参数
|
// 获取配置参数
|
||||||
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
|
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
|
||||||
List<ForecastK> kList = forecastKService.list();
|
List<ForecastK> kList = forecastKService.list();
|
||||||
// 查询所有需要统计pa值的站点
|
if (CollectionUtils.isEmpty(paramList) || CollectionUtils.isEmpty(kList)) {
|
||||||
List<StStbprpB> stStbprpBList = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("source", "SK"));
|
return;
|
||||||
if (CollectionUtils.isNotEmpty(stStbprpBList)) {
|
}
|
||||||
// 先删除站点当天的pa,假如已经存在的话(有另一任务,提前算了第二天(此处为当天)的)
|
// 檀树岗使用多个站点的均值作为水库的降雨
|
||||||
forecastPaService.remove(new QueryWrapper<ForecastPa>().eq("tm", sdfDay.format(nowTime)));
|
AttResBase attResBase = attResBaseService.getOne(new QueryWrapper<>());
|
||||||
for (StStbprpB stb : stStbprpBList) {
|
if (ObjectUtils.isNotEmpty(attResBase)) {
|
||||||
String stcd = stb.getStcd();
|
String resCode = attResBase.getResCode();
|
||||||
// 获取最新pa
|
String skStcd = attResBase.getStcd();
|
||||||
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", stcd).orderBy(true, false, "tm").last("limit 1"));
|
// 先删除水库当天的pa,假如已经存在的话(有另一任务,提前算了第二天(此处为当天)的)
|
||||||
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast) && !forecastPaLast.getTm().equals(sdfDay.format(nowTime))) {
|
forecastPaService.remove(new QueryWrapper<ForecastPa>().eq("tm", sdfDay.format(nowTime)).eq("stcd", attResBase.getResCode()));
|
||||||
Calendar calendar2 = Calendar.getInstance();
|
// 获取最新pa
|
||||||
calendar2.setTime(sdfDay.parse(forecastPaLast.getTm()));
|
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", skStcd).orderBy(true, false, "tm").last("limit 1"));
|
||||||
calendar2.add(Calendar.DAY_OF_MONTH, -3);
|
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast) && !forecastPaLast.getTm().equals(sdfDay.format(nowTime))) {
|
||||||
String searchTm = sdfDay.format(calendar2.getTime());
|
Calendar calendar2 = Calendar.getInstance();
|
||||||
String lastTm = forecastPaLast.getTm();
|
calendar2.setTime(sdfDay.parse(forecastPaLast.getTm()));
|
||||||
// 获取空缺时间的所有降雨,当天8点到第二天8点间的drp和
|
calendar2.add(Calendar.DAY_OF_MONTH, -3);
|
||||||
List<Map<String, Object>> mapList = stPptnRService.getPptnRDataList(stcd, searchTm);
|
String searchTm = sdfDay.format(calendar2.getTime());
|
||||||
Map<String, Object> pptnrMap;
|
String lastTm = forecastPaLast.getTm();
|
||||||
if (CollectionUtils.isNotEmpty(mapList)) {
|
// 获取空缺时间的所有降雨,当天8点到第二天8点间的drp和
|
||||||
pptnrMap = mapList.stream().collect(Collectors.toMap(map -> (String) map.get("tm"), map -> map.get("drp")));
|
List<Map<String, Object>> mapList = stPptnRService.getPptnRDataListByTask(resCode, skStcd, searchTm);
|
||||||
} else {
|
Map<String, Object> pptnrMap;
|
||||||
return;
|
if (CollectionUtils.isNotEmpty(mapList)) {
|
||||||
}
|
pptnrMap = mapList.stream().collect(Collectors.toMap(map -> (String) map.get("tm"), map -> map.get("drp")));
|
||||||
Map<Integer, BigDecimal> kMap = kList.stream().collect(Collectors.toMap(ForecastK::getMonth, ForecastK::getKValue));
|
} else {
|
||||||
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
|
return;
|
||||||
double Im = Double.parseDouble(paramMap.get("Im"));// 土壤含水量最大值(最大初损值)Im
|
}
|
||||||
// 第一次的pa0是最新一条的pa
|
Map<Integer, BigDecimal> kMap = kList.stream().collect(Collectors.toMap(ForecastK::getMonth, ForecastK::getKValue));
|
||||||
List<ForecastPa> list = new ArrayList<>();
|
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
|
||||||
ForecastPa forecastPa = null;
|
double Im = Double.parseDouble(paramMap.get("Im"));// 土壤含水量最大值(最大初损值)Im
|
||||||
while (!lastTm.equals(sdfDay.format(nowTime))) {
|
// 第一次的pa0是最新一条的pa
|
||||||
double lastPa0 = forecastPaLast.getPa().doubleValue();
|
List<ForecastPa> list = new ArrayList<>();
|
||||||
double lastPt0 = Double.valueOf(ObjectUtils.isEmpty(pptnrMap.get(lastTm)) ? "0.0" : pptnrMap.get(lastTm).toString());
|
ForecastPa forecastPa = null;
|
||||||
forecastPa = new ForecastPa();
|
while (!lastTm.equals(sdfDay.format(nowTime))) {
|
||||||
// 最新加1天
|
double lastPa0 = forecastPaLast.getPa().doubleValue();
|
||||||
calendar.setTime(sdfDay.parse(lastTm));
|
double lastPt0 = Double.valueOf(ObjectUtils.isEmpty(pptnrMap.get(lastTm)) ? "0.0" : pptnrMap.get(lastTm).toString());
|
||||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
forecastPa = new ForecastPa();
|
||||||
lastTm = sdfDay.format(calendar.getTime());
|
// 最新加1天
|
||||||
double k = kMap.get(Integer.valueOf(lastTm.substring(5, 7))).doubleValue();
|
calendar.setTime(sdfDay.parse(lastTm));
|
||||||
double pa = RunoffService.PaCaculate(k, lastPa0, lastPt0, Im);
|
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||||
forecastPa.setStcd(stcd);
|
lastTm = sdfDay.format(calendar.getTime());
|
||||||
forecastPa.setTm(lastTm);
|
double k = kMap.get(Integer.valueOf(lastTm.substring(5, 7))).doubleValue();
|
||||||
forecastPa.setK(new BigDecimal(k).setScale(2, BigDecimal.ROUND_HALF_UP));
|
double pa = RunoffService.PaCaculate(k, lastPa0, lastPt0, Im);
|
||||||
forecastPa.setPa0(new BigDecimal(lastPa0));
|
forecastPa.setStcd(skStcd);
|
||||||
forecastPa.setIm(new BigDecimal(Im));
|
forecastPa.setTm(lastTm);
|
||||||
forecastPa.setPt0(new BigDecimal(lastPt0).setScale(2, BigDecimal.ROUND_HALF_UP));
|
forecastPa.setK(new BigDecimal(k).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||||
forecastPa.setPa(new BigDecimal(pa));
|
forecastPa.setPa0(new BigDecimal(lastPa0));
|
||||||
list.add(forecastPa);
|
forecastPa.setIm(new BigDecimal(Im));
|
||||||
forecastPaLast = forecastPa;
|
forecastPa.setPt0(new BigDecimal(lastPt0).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||||
}
|
forecastPa.setPa(new BigDecimal(pa));
|
||||||
if (CollectionUtils.isNotEmpty(list)) {
|
list.add(forecastPa);
|
||||||
forecastPaService.saveBatch(list);
|
forecastPaLast = forecastPa;
|
||||||
}
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
|
forecastPaService.saveBatch(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -155,48 +160,58 @@ public class PaDataTask {
|
||||||
@Scheduled(cron ="0 0/5 20-23 * * ?")
|
@Scheduled(cron ="0 0/5 20-23 * * ?")
|
||||||
public void PaNextDataCalc() throws ParseException {
|
public void PaNextDataCalc() throws ParseException {
|
||||||
Date nowTime = new Date();
|
Date nowTime = new Date();
|
||||||
// 查询所有需要统计pa值的站点
|
// 檀树岗使用多个站点的均值作为水库的降雨
|
||||||
List<StStbprpB> stStbprpBList = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("source", "SK"));
|
AttResBase attResBase = attResBaseService.getOne(new QueryWrapper<>());
|
||||||
if (CollectionUtils.isNotEmpty(stStbprpBList)) {
|
if (ObjectUtils.isNotEmpty(attResBase)) {
|
||||||
|
// 查询所有需要统计pa值的站点
|
||||||
|
List<StStbprpB> stStbprpBList = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("res_code", attResBase.getResCode()));
|
||||||
|
if(CollectionUtils.isEmpty(stStbprpBList)){
|
||||||
|
return;
|
||||||
|
}
|
||||||
// 获取配置参数
|
// 获取配置参数
|
||||||
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
|
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
|
||||||
List<ForecastK> kList = forecastKService.list();
|
List<ForecastK> kList = forecastKService.list();
|
||||||
|
if (CollectionUtils.isEmpty(paramList) || CollectionUtils.isEmpty(kList)) {
|
||||||
for (StStbprpB stb : stStbprpBList) {
|
return;
|
||||||
String stcd = stb.getStcd();
|
}
|
||||||
// 查询第二天的是否已经生成了
|
String skStcd = attResBase.getResCode();
|
||||||
Calendar calendarNext = Calendar.getInstance();
|
// 查询第二天的是否已经生成了
|
||||||
calendarNext.setTime(nowTime);
|
Calendar calendarNext = Calendar.getInstance();
|
||||||
calendarNext.add(Calendar.DAY_OF_MONTH, 1);
|
calendarNext.setTime(nowTime);
|
||||||
String nextTimeStr = sdfDay.format(calendarNext.getTime());
|
calendarNext.add(Calendar.DAY_OF_MONTH, 1);
|
||||||
ForecastPa hasPa = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", stcd).eq("tm", nextTimeStr));
|
String nextTimeStr = sdfDay.format(calendarNext.getTime());
|
||||||
if(ObjectUtils.isNotEmpty(hasPa)){
|
ForecastPa hasPa = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", skStcd).eq("tm", nextTimeStr));
|
||||||
return;
|
if (ObjectUtils.isNotEmpty(hasPa)) {
|
||||||
}
|
return;
|
||||||
// 获取最新pa(当天)
|
}
|
||||||
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", stcd).eq("tm", sdfDay.format(nowTime)).last("limit 1"));
|
// 获取最新pa(当天)
|
||||||
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast)) {
|
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", skStcd).eq("tm", sdfDay.format(nowTime)).last("limit 1"));
|
||||||
|
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast)) {
|
||||||
|
List<StPptnR> listAll = new ArrayList<>();
|
||||||
|
for (StStbprpB stb : stStbprpBList) {
|
||||||
|
String stcd = stb.getStcd();
|
||||||
// 获取当天大于08点到执行时间的真实降雨
|
// 获取当天大于08点到执行时间的真实降雨
|
||||||
List<StPptnR> qwExisted = stPptnRService.list(new QueryWrapper<StPptnR>().eq("stcd", stcd).gt("tm", sdf.parse(eightSdf.format(nowTime))).le("tm", nowTime).orderBy(true, true, "tm"));
|
List<StPptnR> qwExistedStcd = stPptnRService.list(new QueryWrapper<StPptnR>().eq("stcd", stcd).gt("tm", sdf.parse(eightSdf.format(nowTime))).le("tm", nowTime).orderBy(true, true, "tm"));
|
||||||
// 获取当天的预测降雨
|
// 获取当天的预测降雨
|
||||||
List<StPptnR> pptnRFutureList = forecastResultsService.getForecastDrpData(nowTime, stcd);
|
List<StPptnR> pptnRFutureListStcd = forecastResultsService.getForecastDrpData(nowTime, stcd);
|
||||||
qwExisted.addAll(pptnRFutureList);
|
listAll.addAll(qwExistedStcd);
|
||||||
Double totalDrp = qwExisted.stream().mapToDouble(x -> Double.valueOf(x.getDrp())).sum();
|
listAll.addAll(pptnRFutureListStcd);
|
||||||
ForecastPa forecastPa = new ForecastPa();
|
|
||||||
Map<Integer, BigDecimal> kMap = kList.stream().collect(Collectors.toMap(ForecastK::getMonth, ForecastK::getKValue));
|
|
||||||
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
|
|
||||||
double Im = Double.parseDouble(paramMap.get("Im"));// 土壤含水量最大值(最大初损值)Im
|
|
||||||
double k = kMap.get(Integer.valueOf(nextTimeStr.substring(5, 7))).doubleValue();
|
|
||||||
double pa = RunoffService.PaCaculate(k, Double.parseDouble(forecastPaLast.getPa().toString()), totalDrp, Im);
|
|
||||||
forecastPa.setStcd(stcd);
|
|
||||||
forecastPa.setTm(nextTimeStr);
|
|
||||||
forecastPa.setK(new BigDecimal(k).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
||||||
forecastPa.setPa0(forecastPaLast.getPa());
|
|
||||||
forecastPa.setIm(new BigDecimal(Im));
|
|
||||||
forecastPa.setPt0(new BigDecimal(totalDrp).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
||||||
forecastPa.setPa(new BigDecimal(pa));
|
|
||||||
forecastPaService.save(forecastPa);
|
|
||||||
}
|
}
|
||||||
|
Double totalDrp = listAll.stream().mapToDouble(x -> Double.valueOf(x.getDrp())).sum();
|
||||||
|
ForecastPa forecastPa = new ForecastPa();
|
||||||
|
Map<Integer, BigDecimal> kMap = kList.stream().collect(Collectors.toMap(ForecastK::getMonth, ForecastK::getKValue));
|
||||||
|
Map<String, String> paramMap = paramList.stream().collect(Collectors.toMap(ForecastUseparam::getParamCode, ForecastUseparam::getParamValue));
|
||||||
|
double Im = Double.parseDouble(paramMap.get("Im"));// 土壤含水量最大值(最大初损值)Im
|
||||||
|
double k = kMap.get(Integer.valueOf(nextTimeStr.substring(5, 7))).doubleValue();
|
||||||
|
double pa = RunoffService.PaCaculate(k, Double.parseDouble(forecastPaLast.getPa().toString()), totalDrp, Im);
|
||||||
|
forecastPa.setStcd(skStcd);
|
||||||
|
forecastPa.setTm(nextTimeStr);
|
||||||
|
forecastPa.setK(new BigDecimal(k).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||||
|
forecastPa.setPa0(forecastPaLast.getPa());
|
||||||
|
forecastPa.setIm(new BigDecimal(Im));
|
||||||
|
forecastPa.setPt0(new BigDecimal(totalDrp).setScale(2, BigDecimal.ROUND_HALF_UP));
|
||||||
|
forecastPa.setPa(new BigDecimal(pa));
|
||||||
|
forecastPaService.save(forecastPa);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,22 +15,29 @@
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
<select id="getPptnRDataList" resultType="java.util.Map">
|
<select id="getPptnRDataList" resultType="java.util.Map">
|
||||||
SELECT
|
SELECT to_char(tm_start, 'YYYY-MM-DD') tm,
|
||||||
to_char( tm_start, 'YYYY-MM-DD' ) tm,
|
drp
|
||||||
drp
|
FROM (SELECT date_trunc('day', tm :: TIMESTAMP - INTERVAL '8 hours' - INTERVAL '1 second') + INTERVAL '8 hours' AS tm_start, SUM ( drp ) AS drp
|
||||||
FROM
|
FROM
|
||||||
(
|
st_pptn_r
|
||||||
SELECT
|
WHERE
|
||||||
date_trunc( 'day', tm :: TIMESTAMP - INTERVAL '9 hours' ) + INTERVAL '9 hours' AS tm_start,
|
stcd = #{stcd}
|
||||||
SUM ( drp ) AS drp
|
AND tm >= #{tm}
|
||||||
FROM
|
GROUP BY
|
||||||
st_pptn_r
|
date_trunc( 'day', tm :: TIMESTAMP - INTERVAL '8 hours' - INTERVAL '1 second') + INTERVAL '8 hours'
|
||||||
WHERE
|
ORDER BY
|
||||||
stcd = #{stcd} AND tm >= #{tm}
|
tm_start ASC) t
|
||||||
GROUP BY
|
</select>
|
||||||
date_trunc( 'day', tm :: TIMESTAMP - INTERVAL '9 hours' ) + INTERVAL '9 hours'
|
|
||||||
ORDER BY
|
<select id="getPptnRDataListByTask" resultType="java.util.Map">
|
||||||
tm_start ASC
|
SELECT to_char(tm_start, 'YYYY-MM-DD') tm,
|
||||||
) t
|
drp
|
||||||
|
FROM (SELECT date_trunc('day', tm :: TIMESTAMP - INTERVAL '8 hours' - INTERVAL '1 second') + INTERVAL '8 hours' AS tm_start, SUM ( drp ) AS drp
|
||||||
|
FROM
|
||||||
|
(SELECT tm, ROUND(AVG (drp), 1) drp FROM st_pptn_r WHERE tm >= #{tm} AND stcd IN (SELECT stcd FROM st_stbprp_b WHERE res_code = #{resCode}) GROUP BY tm) a
|
||||||
|
GROUP BY
|
||||||
|
date_trunc( 'day', tm :: TIMESTAMP - INTERVAL '8 hours' - INTERVAL '1 second') + INTERVAL '8 hours'
|
||||||
|
ORDER BY
|
||||||
|
tm_start ASC) T
|
||||||
</select>
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<select id="getStcdLastRsvrData" resultType="com.gunshi.project.xyt.model.StRsvrR">
|
<select id="getStcdLastRsvrData" resultType="com.gunshi.project.xyt.model.StRsvrR">
|
||||||
SELECT stb.stcd,
|
SELECT stb.stcd,
|
||||||
case UPPER(stb.sttp) when 'RR' then r2.tm when 'ZZ' then r.tm end stm,
|
case UPPER(stb.sttp) when 'RR' then r.tm when 'ZZ' then r2.tm end stm,
|
||||||
stb.source,
|
stb.source,
|
||||||
stb.sttp
|
stb.sttp
|
||||||
FROM public.st_stbprp_b stb
|
FROM public.st_stbprp_b stb
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue