修复洪水预报错误

master
chenxiwang 2024-08-16 16:50:06 +08:00
parent 1e951e9e8a
commit 75968f74bc
3 changed files with 79 additions and 8 deletions

View File

@ -60,13 +60,14 @@ public class TaskGroupJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
Date nowDate = new Date();
JobDataMap jdMap = context.getJobDetail().getJobDataMap();
String jobId = (String) jdMap.get("jobId");
ForecastTask forecastTask = (ForecastTask) jdMap.get("forecastTask");
log.info("{}----TaskGroupJob-计划执行开始===>jobId:{}", sdf.format(LocalDateTime.now()), jobId);
log.info("{}----TaskGroupJob-计划执行开始===>jobId:{}", sdf.format(nowDate), jobId);
try {
// 根据执行时间、预热期、预见期获取对应的预报、开始、结束时间
Date nowTime = sdfMinute.parse(sdf.format(new Date()));
Date nowTime = sdfMinute.parse(sdf.format(nowDate));
Date forecastTime = nowTime;
Date startTime;
Date endTime;

View File

@ -200,15 +200,17 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
List<StRsvrR> resultList = reorganizeRsvrRData(rsvrRRealList, dt);
List<Date[]> periods = splitByDay8To8(startTime, endTime);
for (Date[] period : periods) {
Calendar calNew = Calendar.getInstance();
calNew.setTime(period[0]);
// 根据每段时间的开始时间如果在08点前则采用前一天的pa值计算
if (isBeforeEightAM(period[0])) {
cal.setTime(period[0]);
// 将日期往前推一天
cal.add(Calendar.DATE, -1);
calNew.add(Calendar.DATE, -1);
}
ForecastPa forecastPa = paMap.get(sdfDay.format(cal.getTime()));
ForecastPa forecastPa = paMap.get(sdfDay.format(calNew.getTime()));
if (ObjectUtils.isEmpty(forecastPa)) {
throw new IllegalArgumentException("温馨提示当前洪水预报所依赖的数据尚不完整请检查每日土壤含水量Pa、K值是否缺失。");
continue;
// throw new IllegalArgumentException("温馨提示当前洪水预报所依赖的数据尚不完整请检查每日土壤含水量Pa、K值是否缺失。");
}
// 根据降雨数据按照△t的颗粒度均分
// 筛选时间段内的降雨数据。不包前但包后
@ -290,7 +292,7 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
/**
*
*/
private List<StPptnR> getForecastDrpData(Date now, String stcd) {
public List<StPptnR> getForecastDrpData(Date now, String stcd) {
List<StPptnR> pptnRFutureList = new ArrayList<>();
StStbprpB stStbprpB = stStbprpBService.getOne(new QueryWrapper<StStbprpB>().eq("stcd", stcd));
String tm = "";// 时间格式应为YYYYMMDDHH其中HH只能为08或20例如2023062908

View File

@ -7,9 +7,11 @@ import com.gunshi.algorithm.RunoffService;
import com.gunshi.project.xyt.model.ForecastK;
import com.gunshi.project.xyt.model.ForecastPa;
import com.gunshi.project.xyt.model.ForecastUseparam;
import com.gunshi.project.xyt.model.StPptnR;
import com.gunshi.project.xyt.model.StStbprpB;
import com.gunshi.project.xyt.service.ForecastKService;
import com.gunshi.project.xyt.service.ForecastPaService;
import com.gunshi.project.xyt.service.ForecastResultsService;
import com.gunshi.project.xyt.service.ForecastUseparamService;
import com.gunshi.project.xyt.service.StPptnRService;
import com.gunshi.project.xyt.service.StStbprpBService;
@ -44,8 +46,12 @@ import java.util.stream.Collectors;
@Profile("prod")
public class PaDataTask {
private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private static SimpleDateFormat sdfDay = new SimpleDateFormat("yyyy-MM-dd");
private static SimpleDateFormat eightSdf = new SimpleDateFormat("yyyy-MM-dd 08:00:00");
@Autowired
private ForecastUseparamService forecastUseparamService;
@ -61,6 +67,9 @@ public class PaDataTask {
@Autowired
private StStbprpBService stStbprpBService;
@Autowired
private ForecastResultsService forecastResultsService;
/**
* @description: 830Pa
* @param
@ -81,6 +90,8 @@ public class PaDataTask {
// 查询所有需要统计pa值的站点
List<StStbprpB> stStbprpBList = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("source", "SK"));
if (CollectionUtils.isNotEmpty(stStbprpBList)) {
// 先删除站点当天的pa假如已经存在的话有另一任务提前算了第二天此处为当天
forecastPaService.remove(new QueryWrapper<ForecastPa>().eq("tm", sdfDay.format(nowTime)));
for (StStbprpB stb : stStbprpBList) {
String stcd = stb.getStcd();
// 获取最新pa
@ -105,7 +116,6 @@ public class PaDataTask {
// 第一次的pa0是最新一条的pa
List<ForecastPa> list = new ArrayList<>();
ForecastPa forecastPa = null;
int i = 0;
while (!lastTm.equals(sdfDay.format(nowTime))) {
double lastPa0 = forecastPaLast.getPa().doubleValue();
double lastPt0 = Double.valueOf(ObjectUtils.isEmpty(pptnrMap.get(lastTm)) ? "0.0" : pptnrMap.get(lastTm).toString());
@ -134,4 +144,62 @@ public class PaDataTask {
}
}
/**
* @description: 19245Pa
* @param
* @return: void
* @auther: cxw
* @date: 2024-08-16, , 15:42:13
*/
@Async
@Scheduled(cron ="0 0/5 20-23 * * ?")
@PostConstruct
public void PaNextDataCalc() throws ParseException {
Date nowTime = new Date();
// 查询所有需要统计pa值的站点
List<StStbprpB> stStbprpBList = stStbprpBService.list(new QueryWrapper<StStbprpB>().eq("source", "SK"));
if (CollectionUtils.isNotEmpty(stStbprpBList)) {
// 获取配置参数
List<ForecastUseparam> paramList = forecastUseparamService.list(new QueryWrapper<ForecastUseparam>().isNotNull("param_code").isNotNull("param_value"));
List<ForecastK> kList = forecastKService.list();
for (StStbprpB stb : stStbprpBList) {
String stcd = stb.getStcd();
// 查询第二天的是否已经生成了
Calendar calendarNext = Calendar.getInstance();
calendarNext.setTime(nowTime);
calendarNext.add(Calendar.DAY_OF_MONTH, 1);
String nextTimeStr = sdfDay.format(calendarNext.getTime());
ForecastPa hasPa = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", stcd).eq("tm", nextTimeStr));
if(ObjectUtils.isNotEmpty(hasPa)){
return;
}
// 获取最新pa当天
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", stcd).eq("tm", sdfDay.format(nowTime)).last("limit 1"));
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast)) {
// 获取当天大于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> pptnRFutureList = forecastResultsService.getForecastDrpData(nowTime, stcd);
qwExisted.addAll(pptnRFutureList);
Double totalDrp = qwExisted.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(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);
}
}
}
}
}