补水雨情数据;初步优化洪水预报
parent
bce0e56891
commit
9027fee40c
5
pom.xml
5
pom.xml
|
|
@ -211,6 +211,11 @@
|
||||||
</exclusion>
|
</exclusion>
|
||||||
</exclusions>
|
</exclusions>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.locationtech.jts</groupId>
|
||||||
|
<artifactId>jts-core</artifactId>
|
||||||
|
<version>1.18.1</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,43 @@
|
||||||
|
package com.gunshi.project.xyt.entity.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 天气预报-流域统计
|
||||||
|
* Created by wanyan on 2024/3/13
|
||||||
|
*
|
||||||
|
* @author wanyan
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ForeRainStatVo {
|
||||||
|
|
||||||
|
@Schema(description = "id")
|
||||||
|
private String id;
|
||||||
|
|
||||||
|
@Schema(description = "名称")
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@Schema(description = "雨量")
|
||||||
|
private Double drp;
|
||||||
|
|
||||||
|
@Schema(description="经度")
|
||||||
|
private BigDecimal lgtd;
|
||||||
|
|
||||||
|
@Schema(description="纬度")
|
||||||
|
private BigDecimal lttd;
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private List<MeshrainVo> meshrainVos;
|
||||||
|
|
||||||
|
@Schema(description = "逐小时雨量")
|
||||||
|
private List<ForeRainTimeVo> timeRainVos;
|
||||||
|
|
||||||
|
@JsonIgnore
|
||||||
|
private String geom;
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
package com.gunshi.project.xyt.entity.vo;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Description:
|
||||||
|
* Created by wanyan on 2024/3/13
|
||||||
|
*
|
||||||
|
* @author wanyan
|
||||||
|
* @version 1.0
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class MeshrainVo {
|
||||||
|
|
||||||
|
@Schema(description = "水库/河流/行政区划编码")
|
||||||
|
private String code;
|
||||||
|
|
||||||
|
@Schema(description = "行号")
|
||||||
|
private Integer rownum;
|
||||||
|
|
||||||
|
@Schema(description = "列号")
|
||||||
|
private Integer colnum;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -35,4 +35,6 @@ public interface StPptnRMapper extends BaseMapper<StPptnR> {
|
||||||
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);
|
List<Map<String, Object>> getPptnRDataListByTask(@Param("resCode") String resCode, @Param("stcd") String stcd, @Param("tm") String tm);
|
||||||
|
|
||||||
|
List<StPptnR> getStcdFirstPptnData();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,4 +15,6 @@ import java.util.List;
|
||||||
public interface StRsvrRMapper extends BaseMapper<StRsvrR> {
|
public interface StRsvrRMapper extends BaseMapper<StRsvrR> {
|
||||||
|
|
||||||
List<StRsvrR> getStcdLastRsvrData();
|
List<StRsvrR> getStcdLastRsvrData();
|
||||||
|
|
||||||
|
List<StRsvrR> getStcdFirstRsvrData();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
import com.gunshi.algorithm.RrainfallForecast;
|
import com.gunshi.algorithm.RrainfallForecast;
|
||||||
import com.gunshi.algorithm.RunoffService;
|
import com.gunshi.algorithm.RunoffService;
|
||||||
import com.gunshi.model.vo.FloodAlgorithemVo;
|
import com.gunshi.model.vo.FloodAlgorithemVo;
|
||||||
|
import com.gunshi.project.xyt.entity.vo.ForeRainStatVo;
|
||||||
import com.gunshi.project.xyt.entity.vo.ForeRainTimeVo;
|
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.entity.vo.ForecastResultVo;
|
||||||
import com.gunshi.project.xyt.grb.RainGrib2Layer;
|
import com.gunshi.project.xyt.grb.RainGrib2Layer;
|
||||||
import com.gunshi.project.xyt.mapper.ForecastResultsMapper;
|
import com.gunshi.project.xyt.mapper.ForecastResultsMapper;
|
||||||
|
|
@ -385,7 +385,8 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
||||||
*/
|
*/
|
||||||
public List<StPptnR> getForecastDrpData(Date now, String stcd) {
|
public List<StPptnR> getForecastDrpData(Date now, String stcd) {
|
||||||
List<StPptnR> pptnRFutureList = new ArrayList<>();
|
List<StPptnR> pptnRFutureList = new ArrayList<>();
|
||||||
StStbprpB stStbprpB = stStbprpBService.getOne(new QueryWrapper<StStbprpB>().eq("stcd", stcd));
|
// StStbprpB stStbprpB = stStbprpBService.getOne(new QueryWrapper<StStbprpB>().eq("stcd", stcd));
|
||||||
|
ForecastUseparam forecastUseparam = forecastUseparamService.getOne(new QueryWrapper<ForecastUseparam>().eq("param_code", "geom"));
|
||||||
String tm = "";// 时间格式应为:YYYYMMDDHH其中HH只能为08或20,例如2023062908
|
String tm = "";// 时间格式应为:YYYYMMDDHH其中HH只能为08或20,例如2023062908
|
||||||
if (isBeforeEightAM(now)) {
|
if (isBeforeEightAM(now)) {
|
||||||
tm = sixteenSdf.format(now);
|
tm = sixteenSdf.format(now);
|
||||||
|
|
@ -398,11 +399,15 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
|
||||||
List<RainGrib2Layer> total = gribList.stream().filter(o -> o.getTmRange().getInterval() == 24).collect(Collectors.toList());
|
List<RainGrib2Layer> total = gribList.stream().filter(o -> o.getTmRange().getInterval() == 24).collect(Collectors.toList());
|
||||||
//24小时每个网格的逐小时雨量
|
//24小时每个网格的逐小时雨量
|
||||||
List<RainGrib2Layer> detail = gribList.stream().filter(o -> o.getTmRange().getInterval() == 1).collect(Collectors.toList());
|
List<RainGrib2Layer> detail = gribList.stream().filter(o -> o.getTmRange().getInterval() == 1).collect(Collectors.toList());
|
||||||
ForeRainVo vo = new ForeRainVo();
|
// ForeRainVo vo = new ForeRainVo();
|
||||||
vo.setStcd(stcd);
|
// vo.setStcd(stcd);
|
||||||
vo.setLgtd(stStbprpB.getLgtd());
|
// vo.setLgtd(stStbprpB.getLgtd());
|
||||||
vo.setLttd(stStbprpB.getLttd());
|
// vo.setLttd(stStbprpB.getLttd());
|
||||||
List<ForeRainTimeVo> data = forecastService.getData(vo, total, detail);
|
// List<ForeRainTimeVo> data = forecastService.getData(vo, total, detail);
|
||||||
|
// 2024-10-14 改为获取水库整个面的降雨
|
||||||
|
ForeRainStatVo vo = new ForeRainStatVo();
|
||||||
|
vo.setGeom(forecastUseparam.getParamValue());
|
||||||
|
List<ForeRainTimeVo> data = forecastService.getAreaData(vo, total, detail);
|
||||||
if (CollectionUtils.isNotEmpty(data)) {
|
if (CollectionUtils.isNotEmpty(data)) {
|
||||||
for (ForeRainTimeVo foreRainTimeVo : data) {
|
for (ForeRainTimeVo foreRainTimeVo : data) {
|
||||||
// 只取当前时间之后的数据
|
// 只取当前时间之后的数据
|
||||||
|
|
|
||||||
|
|
@ -5,8 +5,10 @@ import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.gunshi.project.xyt.entity.so.ShortWeatherSo;
|
import com.gunshi.project.xyt.entity.so.ShortWeatherSo;
|
||||||
import com.gunshi.project.xyt.entity.so.WeatherSo;
|
import com.gunshi.project.xyt.entity.so.WeatherSo;
|
||||||
|
import com.gunshi.project.xyt.entity.vo.ForeRainStatVo;
|
||||||
import com.gunshi.project.xyt.entity.vo.ForeRainTimeVo;
|
import com.gunshi.project.xyt.entity.vo.ForeRainTimeVo;
|
||||||
import com.gunshi.project.xyt.entity.vo.ForeRainVo;
|
import com.gunshi.project.xyt.entity.vo.ForeRainVo;
|
||||||
|
import com.gunshi.project.xyt.entity.vo.MeshrainVo;
|
||||||
import com.gunshi.project.xyt.grb.RainGrib2Layer;
|
import com.gunshi.project.xyt.grb.RainGrib2Layer;
|
||||||
import com.gunshi.project.xyt.mapper.RealRainMapper;
|
import com.gunshi.project.xyt.mapper.RealRainMapper;
|
||||||
import jakarta.annotation.Resource;
|
import jakarta.annotation.Resource;
|
||||||
|
|
@ -19,6 +21,10 @@ import org.apache.http.client.HttpClient;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.HttpClientBuilder;
|
import org.apache.http.impl.client.HttpClientBuilder;
|
||||||
import org.apache.http.util.EntityUtils;
|
import org.apache.http.util.EntityUtils;
|
||||||
|
import org.locationtech.jts.geom.Coordinate;
|
||||||
|
import org.locationtech.jts.geom.GeometryFactory;
|
||||||
|
import org.locationtech.jts.geom.Polygon;
|
||||||
|
import org.locationtech.jts.geom.impl.CoordinateArraySequence;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
|
@ -43,6 +49,7 @@ public class ForecastService {
|
||||||
@Value("${shqxjsCloudowrCnPath}")
|
@Value("${shqxjsCloudowrCnPath}")
|
||||||
private String shqxjsCloudowrCnPath;//获取气象预报文件名接口 http://shqxjs.cloudowr.cn/service/
|
private String shqxjsCloudowrCnPath;//获取气象预报文件名接口 http://shqxjs.cloudowr.cn/service/
|
||||||
|
|
||||||
|
public static GeometryFactory factory = new GeometryFactory();
|
||||||
|
|
||||||
public static String grbgetName = "grb/get";
|
public static String grbgetName = "grb/get";
|
||||||
|
|
||||||
|
|
@ -244,4 +251,89 @@ public class ForecastService {
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
return resultList;
|
return resultList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 计算面降雨量
|
||||||
|
* @param vo
|
||||||
|
* @param total
|
||||||
|
* @param detail
|
||||||
|
* @return: java.util.List<com.gunshi.project.xyt.entity.vo.ForeRainTimeVo>
|
||||||
|
* @date: 2024-10-14, 周一, 17:52:27
|
||||||
|
*/
|
||||||
|
public List<ForeRainTimeVo> getAreaData(ForeRainStatVo vo, List<RainGrib2Layer> total, List<RainGrib2Layer> detail) {
|
||||||
|
String geom = vo.getGeom();
|
||||||
|
//处理面
|
||||||
|
Polygon areaPolygon = handlePolygon(geom);
|
||||||
|
RainGrib2Layer layer = total.get(0);
|
||||||
|
BigDecimal dh = layer.getDh();
|
||||||
|
BigDecimal dw = layer.getDw();
|
||||||
|
int nh = layer.getNh();//横向格子数
|
||||||
|
int nw = layer.getNw();//纵向格子数
|
||||||
|
//网格左下角经纬度
|
||||||
|
BigDecimal x11 = layer.getX1();
|
||||||
|
BigDecimal y11 = layer.getY1();
|
||||||
|
List<MeshrainVo> meshrainVos = new ArrayList<>();
|
||||||
|
for(int i = 0;i < nh;i++){
|
||||||
|
for(int j=0;j< nw;j++){
|
||||||
|
BigDecimal xMin = x11.add(dh.multiply(BigDecimal.valueOf(i)));
|
||||||
|
BigDecimal xMax = x11.add(dh.multiply(BigDecimal.valueOf(i+1)));
|
||||||
|
BigDecimal yMin = y11.add(dw.multiply(BigDecimal.valueOf(j)));
|
||||||
|
BigDecimal yMax = y11.add(dw.multiply(BigDecimal.valueOf(j+1)));
|
||||||
|
Coordinate[] c2 = {
|
||||||
|
new Coordinate(xMin.doubleValue(), yMin.doubleValue()),
|
||||||
|
new Coordinate(xMin.doubleValue(), yMax.doubleValue()),
|
||||||
|
new Coordinate(xMax.doubleValue(), yMax.doubleValue()),
|
||||||
|
new Coordinate(xMax.doubleValue(), yMin.doubleValue()),
|
||||||
|
new Coordinate(xMin.doubleValue(), yMin.doubleValue())
|
||||||
|
};
|
||||||
|
Polygon p2 = factory.createPolygon(new CoordinateArraySequence(c2));
|
||||||
|
boolean intersects = areaPolygon.intersects(p2);
|
||||||
|
if(intersects){
|
||||||
|
MeshrainVo meshrainVo = new MeshrainVo();
|
||||||
|
meshrainVo.setColnum(i);
|
||||||
|
meshrainVo.setRownum(j);
|
||||||
|
meshrainVos.add(meshrainVo);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<ForeRainTimeVo> result = new ArrayList<>();
|
||||||
|
BigDecimal size = new BigDecimal(meshrainVos.size());
|
||||||
|
for(MeshrainVo mesVo : meshrainVos){
|
||||||
|
result.addAll(detail.stream().map(lay->
|
||||||
|
ForeRainTimeVo.builder().tm(lay.getTmRange().getTm2()).drp(lay.data[mesVo.getRownum()][mesVo.getColnum()]).build()
|
||||||
|
).collect(Collectors.toList()));
|
||||||
|
}
|
||||||
|
Map<Date, BigDecimal> sumByGroup = result.stream()
|
||||||
|
.collect(Collectors.groupingBy(ForeRainTimeVo::getTm, Collectors.mapping(ForeRainTimeVo::getDrp, Collectors.reducing(BigDecimal.ZERO, BigDecimal::add))));
|
||||||
|
List<ForeRainTimeVo> resultList = sumByGroup.entrySet().stream()
|
||||||
|
.map(entry -> ForeRainTimeVo.builder().tm(entry.getKey()).drp(entry.getValue().divide(size,1, RoundingMode.UP)).build())
|
||||||
|
.sorted(Comparator.comparing(ForeRainTimeVo::getTm))
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
vo.setDrp(calcSumDrp(meshrainVos,total));
|
||||||
|
return resultList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Polygon handlePolygon(String geom) {
|
||||||
|
JSONObject jsonObject = new JSONObject(geom);
|
||||||
|
JSONArray data = jsonObject.getJSONArray("coordinates");
|
||||||
|
JSONArray data1 = data.getJSONArray(0);
|
||||||
|
JSONArray jsonArray = data1.getJSONArray(0);
|
||||||
|
Coordinate[] coords = new Coordinate[jsonArray.size()];
|
||||||
|
for (int c = 0; c < jsonArray.size(); c++) {
|
||||||
|
BigDecimal x = (BigDecimal) jsonArray.getJSONArray(c).get(0);
|
||||||
|
BigDecimal y = (BigDecimal) jsonArray.getJSONArray(c).get(1);
|
||||||
|
coords[c] = new Coordinate(x.doubleValue(), y.doubleValue());
|
||||||
|
}
|
||||||
|
return factory.createPolygon(new CoordinateArraySequence(coords));
|
||||||
|
}
|
||||||
|
|
||||||
|
private Double calcSumDrp(List<MeshrainVo> meshrainVos, List<RainGrib2Layer> total) {
|
||||||
|
BigDecimal size = new BigDecimal(meshrainVos.size());
|
||||||
|
BigDecimal sumDrp = new BigDecimal(0);
|
||||||
|
for (MeshrainVo vo : meshrainVos){
|
||||||
|
List<BigDecimal> drp = total.stream().map(o -> (o.getData()[vo.getRownum()][vo.getColnum()])).collect(Collectors.toList());
|
||||||
|
sumDrp = drp.stream().reduce(sumDrp,BigDecimal::add);
|
||||||
|
}
|
||||||
|
return sumDrp.divide(size,1,RoundingMode.UP).doubleValue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,10 @@ public class StPptnRService extends ServiceImpl<StPptnRMapper, StPptnR>
|
||||||
public List<Map<String, Object>> getPptnRDataListByTask(String resCode, String stcd, String tm) {
|
public List<Map<String, Object>> getPptnRDataListByTask(String resCode, String stcd, String tm) {
|
||||||
return baseMapper.getPptnRDataListByTask(resCode, stcd, tm);
|
return baseMapper.getPptnRDataListByTask(resCode, stcd, tm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<StPptnR> getStcdFirstPptnData() {
|
||||||
|
return baseMapper.getStcdFirstPptnData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,10 @@ public class StRsvrRService extends ServiceImpl<StRsvrRMapper, StRsvrR>
|
||||||
public List<StRsvrR> getStcdLastRsvrData() {
|
public List<StRsvrR> getStcdLastRsvrData() {
|
||||||
return baseMapper.getStcdLastRsvrData();
|
return baseMapper.getStcdLastRsvrData();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<StRsvrR> getStcdFirstRsvrData() {
|
||||||
|
return baseMapper.getStcdFirstRsvrData();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import com.gunshi.project.xyt.service.StRiverRService;
|
||||||
import com.gunshi.project.xyt.service.StRsvrRRealService;
|
import com.gunshi.project.xyt.service.StRsvrRRealService;
|
||||||
import com.gunshi.project.xyt.service.StRsvrRService;
|
import com.gunshi.project.xyt.service.StRsvrRService;
|
||||||
import com.gunshi.project.xyt.util.OkHttpUtil;
|
import com.gunshi.project.xyt.util.OkHttpUtil;
|
||||||
|
import jakarta.annotation.PostConstruct;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import okhttp3.FormBody;
|
import okhttp3.FormBody;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
|
@ -323,4 +324,245 @@ public class DataTaskTSG {
|
||||||
log.error("水情历史定时任务错误:", e.getMessage());
|
log.error("水情历史定时任务错误:", e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 补雨量数据
|
||||||
|
* @param
|
||||||
|
* @return: void
|
||||||
|
* @auther: cxw
|
||||||
|
* @date: 2024-10-16, 周三, 16:24:29
|
||||||
|
*/
|
||||||
|
// @PostConstruct
|
||||||
|
public void supplementPptnData() {
|
||||||
|
Date now = new Date();
|
||||||
|
System.out.println("补雨量数据任务,执行时间:" + sdf.format(now));
|
||||||
|
List<StPptnR> stcdLastPptnDatas = stPptnRService.getStcdFirstPptnData();
|
||||||
|
OkHttpClient client = OkHttpUtil.build();
|
||||||
|
try {
|
||||||
|
if (CollectionUtils.isNotEmpty(stcdLastPptnDatas)) {
|
||||||
|
for (StPptnR stPptnR : stcdLastPptnDatas) {
|
||||||
|
String stm = "2024-06-01 00:00:00";// 补数据的开始时间
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
String url = jcskPath + jcskPathPptnRoute + stPptnR.getSource().toLowerCase();
|
||||||
|
String stcd = stPptnR.getStcd();
|
||||||
|
Date etmD = null;
|
||||||
|
if (ObjectUtils.isEmpty(stPptnR.getEtm())) {
|
||||||
|
etmD = now;
|
||||||
|
} else {
|
||||||
|
etmD = stPptnR.getEtm();
|
||||||
|
}
|
||||||
|
String etm = sdf.format(etmD);// 补数据的结束时间
|
||||||
|
if (stmIsBeforeEtm(etm, stm, "yyyy-MM-dd HH:mm:ss")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// 开始时间往后推3天,不超过结束日期
|
||||||
|
while (stmIsBeforeEtm(stm, etm, "yyyy-MM-dd HH:mm:ss")) {
|
||||||
|
String newEtm = dateManipulation(stm, 3, "yyyy-MM-dd HH:mm:ss");
|
||||||
|
Response resp = client.newCall(new Request.Builder().url(url).post(new FormBody.Builder().add("stcd", stcd).add("stm", stm).add("etm", newEtm).build()).header("Token", jcskToken).addHeader("Content-Type", "application/x-www" +
|
||||||
|
"-form-urlencoded").build()).execute();
|
||||||
|
String respStr = resp.body().string();
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(respStr.toLowerCase());
|
||||||
|
// 清除同步平台的ip白名单缓存
|
||||||
|
if ("401".equals(jsonObject.get("code").toString())) {
|
||||||
|
OkHttpClient clientCache = new OkHttpClient();
|
||||||
|
Request request = new Request.Builder().url(reloadCache).build();
|
||||||
|
clientCache.newCall(request).execute();
|
||||||
|
}
|
||||||
|
JSONArray data = jsonObject.getJSONArray("data");
|
||||||
|
if (ObjectUtils.isNotEmpty(data)) {
|
||||||
|
List<StPptnR> rlist = data.toJavaList(StPptnR.class);
|
||||||
|
if (CollectionUtils.isNotEmpty(rlist)) {
|
||||||
|
// 全部替换为stcd,并去重
|
||||||
|
rlist = rlist.stream().peek(entity -> entity.setStcd(stPptnR.getStcd())).collect(Collectors.toMap(e -> e.getStcd().toUpperCase() + "_" + e.getTm(), // 使用属性组合作为键
|
||||||
|
Function.identity(), (existing, replacement) -> existing // 如果有冲突,保留现有的
|
||||||
|
)).values().stream().collect(Collectors.toList());
|
||||||
|
stPptnRService.saveBatch(rlist);
|
||||||
|
// 更新到实时数据表
|
||||||
|
stPptnRRealService.updatePptnRReal(rlist.get(0).getStcd());
|
||||||
|
// 整编降雨量天表数据
|
||||||
|
StPptnRD maxDataD = stPptnRDService.getMaxData(stPptnR.getStcd());
|
||||||
|
Date tmMax = maxDataD.getTm();
|
||||||
|
maxDataD.setTm(sdf.parse(sdfEight.format(tmMax)));
|
||||||
|
List<StPptnRD> listD = stPptnRDService.reorganizePptnRDData(stPptnR.getStcd(), maxDataD);
|
||||||
|
if (CollectionUtils.isNotEmpty(listD)) {
|
||||||
|
if (listD.size() > 0) {
|
||||||
|
listD = listD.stream().map(user -> {
|
||||||
|
user.setYear(Integer.valueOf(sdfD.format(user.getTm()).substring(0, 4))); // 修改属性值
|
||||||
|
return user;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
QueryWrapper<StPptnRD> deleteWrapper = new QueryWrapper<>();
|
||||||
|
deleteWrapper.eq("stcd", stcd).ge("tm", tmMax);
|
||||||
|
stPptnRDService.remove(deleteWrapper);
|
||||||
|
stPptnRDService.saveBatch(listD);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// 整编降雨量小时表数据
|
||||||
|
StPptnRH maxDataH = stPptnRHService.getMaxData(stPptnR.getStcd());
|
||||||
|
List<StPptnRH> listH = stPptnRHService.reorganizePptnRHData(stPptnR.getStcd(), maxDataH);
|
||||||
|
if (CollectionUtils.isNotEmpty(listH)) {
|
||||||
|
StPptnRH LastData = listH.get(0);
|
||||||
|
if (LastData.getTm().equals(maxDataH.getTm())) {
|
||||||
|
listH.remove(0);
|
||||||
|
UpdateWrapper<StPptnRH> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.eq("stcd", LastData.getStcd()).eq("tm", LastData.getTm());
|
||||||
|
LastData.setDrp(LastData.getDrp());
|
||||||
|
LastData.setChtm(maxDataH.getChtm());
|
||||||
|
stPptnRHService.saveOrUpdate(LastData, updateWrapper);
|
||||||
|
}
|
||||||
|
if (listH.size() > 0) {
|
||||||
|
stPptnRHService.saveBatch(listH);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stmIsBeforeEtm(etm, newEtm, "yyyy-MM-dd HH:mm:ss")) {
|
||||||
|
stm = etm;
|
||||||
|
} else {
|
||||||
|
stm = newEtm;
|
||||||
|
}
|
||||||
|
calendar.setTime(sdf.parse(stm));
|
||||||
|
calendar.add(Calendar.MINUTE, 5);
|
||||||
|
stm = sdf.format(calendar.getTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("补雨量数据任务失败:", e.getMessage());
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description: 补水位数据
|
||||||
|
* @param
|
||||||
|
* @return: void
|
||||||
|
* @auther: cxw
|
||||||
|
* @date: 2024-10-16, 周三, 17:13:33
|
||||||
|
*/
|
||||||
|
// @PostConstruct
|
||||||
|
public void supplementRsvrData() {
|
||||||
|
Date now = new Date();
|
||||||
|
System.out.println("补水位数据任务,执行时间:" + sdf.format(now));
|
||||||
|
List<StRsvrR> stcdLast = stRsvrRService.getStcdFirstRsvrData();
|
||||||
|
OkHttpClient client = OkHttpUtil.build();
|
||||||
|
try {
|
||||||
|
if (CollectionUtils.isNotEmpty(stcdLast)) {
|
||||||
|
for (StRsvrR stRsvrR : stcdLast) {
|
||||||
|
String sttp = stRsvrR.getSttp().toLowerCase();
|
||||||
|
String source = stRsvrR.getSource().toLowerCase();
|
||||||
|
String stm = "2024-06-01 00:00:00";// 补数据的开始时间
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
Date etmD = null;
|
||||||
|
if (ObjectUtils.isEmpty(stRsvrR.getEtm())) {
|
||||||
|
etmD = now;
|
||||||
|
} else {
|
||||||
|
etmD = stRsvrR.getEtm();
|
||||||
|
}
|
||||||
|
String etm = sdf.format(etmD);// 补数据的结束时间
|
||||||
|
if (stmIsBeforeEtm(etm, stm, "yyyy-MM-dd HH:mm:ss")) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String url = jcskPath;
|
||||||
|
if ("rr".equals(sttp)) {
|
||||||
|
url += jcskPathZzRsvrRoute + source;
|
||||||
|
} else if ("zz".equals(sttp)) {
|
||||||
|
url += jcskPathRrRiverRoute + source;
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
while (stmIsBeforeEtm(stm, etm, "yyyy-MM-dd HH:mm:ss")) {
|
||||||
|
String newEtm = dateManipulation(stm, 3, "yyyy-MM-dd HH:mm:ss");
|
||||||
|
Response resp = client.newCall(new Request.Builder().url(url)
|
||||||
|
.post(new FormBody.Builder().add("stcd", stRsvrR.getStcd())
|
||||||
|
.add("stm", stm)
|
||||||
|
.add("etm", newEtm)
|
||||||
|
.build())
|
||||||
|
.header("Token", jcskToken)
|
||||||
|
.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||||
|
.build()).execute();
|
||||||
|
String respStr = resp.body().string();
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(respStr.toLowerCase());
|
||||||
|
if (!"200".equals(jsonObject.get("code").toString())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
JSONArray data = jsonObject.getJSONArray("data");
|
||||||
|
if (CollectionUtils.isNotEmpty(data)) {
|
||||||
|
if ("zz".equals(sttp)) {
|
||||||
|
List<StRiverR> rlist = data.toJavaList(StRiverR.class);
|
||||||
|
stRiverRService.saveBatch(rlist);
|
||||||
|
// 更新实时表数据
|
||||||
|
StRiverR stRiverRLast = rlist.get(rlist.size() - 1);
|
||||||
|
StRiverRReal stRiverRReal = new StRiverRReal();
|
||||||
|
UpdateWrapper<StRiverRReal> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.eq("stcd", stRiverRLast.getStcd()).eq("tm", stRiverRLast.getTm());
|
||||||
|
BeanUtils.copyProperties(stRiverRLast, stRiverRReal);
|
||||||
|
stRiverRReal.setChtm(new Date());
|
||||||
|
stRiverRRealService.saveOrUpdate(stRiverRReal, updateWrapper);
|
||||||
|
} else if ("rr".equals(sttp)) {
|
||||||
|
List<StRsvrR> rlist = data.toJavaList(StRsvrR.class);
|
||||||
|
stRsvrRService.saveBatch(rlist);
|
||||||
|
// 更新实时表数据
|
||||||
|
StRsvrR stRsvrRLast = rlist.get(rlist.size() - 1);
|
||||||
|
StRsvrRReal stRsvrRReal = new StRsvrRReal();
|
||||||
|
UpdateWrapper<StRsvrRReal> updateWrapper = new UpdateWrapper<>();
|
||||||
|
updateWrapper.eq("stcd", stRsvrRLast.getStcd()).eq("tm", stRsvrRLast.getTm());
|
||||||
|
BeanUtils.copyProperties(stRsvrRLast, stRsvrRReal);
|
||||||
|
stRsvrRReal.setChtm(new Date());
|
||||||
|
stRsvrRRealService.saveOrUpdate(stRsvrRReal, updateWrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (stmIsBeforeEtm(etm, newEtm, "yyyy-MM-dd HH:mm:ss")) {
|
||||||
|
stm = etm;
|
||||||
|
} else {
|
||||||
|
stm = newEtm;
|
||||||
|
}
|
||||||
|
calendar.setTime(sdf.parse(stm));
|
||||||
|
calendar.add(Calendar.MINUTE, 5);
|
||||||
|
stm = sdf.format(calendar.getTime());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("补水位数据任务错误:", e.getMessage());
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new IllegalArgumentException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private Boolean stmIsBeforeEtm(String stm, String etm, String fmt) {
|
||||||
|
Boolean ret = false;
|
||||||
|
try {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(fmt);
|
||||||
|
Date date1 = sdf.parse(stm);
|
||||||
|
Date date2 = sdf.parse(etm);
|
||||||
|
if (date1.equals(date2)) {
|
||||||
|
ret = true;
|
||||||
|
} else if (date1.before(date2)) {
|
||||||
|
ret = true;
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
throw new RuntimeException("时间大小不正确!");
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String dateManipulation(String tm, int daysToSubtract, String fmt) {
|
||||||
|
String newDateString = "";
|
||||||
|
try {
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat(fmt);
|
||||||
|
Date parsedDate = dateFormat.parse(tm);
|
||||||
|
|
||||||
|
Calendar calendar = Calendar.getInstance();
|
||||||
|
calendar.setTime(parsedDate);
|
||||||
|
calendar.add(Calendar.DATE, daysToSubtract);
|
||||||
|
|
||||||
|
newDateString = dateFormat.format(calendar.getTime());
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return newDateString;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ 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;
|
||||||
|
|
@ -83,6 +84,7 @@ 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());
|
||||||
|
|
@ -102,6 +104,19 @@ public class PaDataTask {
|
||||||
forecastPaService.remove(new QueryWrapper<ForecastPa>().eq("tm", sdfDay.format(nowTime)).eq("stcd", attResBase.getResCode()));
|
forecastPaService.remove(new QueryWrapper<ForecastPa>().eq("tm", sdfDay.format(nowTime)).eq("stcd", attResBase.getResCode()));
|
||||||
// 获取最新pa
|
// 获取最新pa
|
||||||
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", skStcd).orderBy(true, false, "tm").last("limit 1"));
|
ForecastPa forecastPaLast = forecastPaService.getOne(new QueryWrapper<ForecastPa>().eq("stcd", skStcd).orderBy(true, false, "tm").last("limit 1"));
|
||||||
|
// 补数据时解开
|
||||||
|
// if(ObjectUtils.isEmpty(forecastPaLast)){
|
||||||
|
// forecastPaLast = new ForecastPa();
|
||||||
|
// forecastPaLast.setStcd(skStcd);
|
||||||
|
// forecastPaLast.setTm("2024-06-01");
|
||||||
|
// forecastPaLast.setK(new BigDecimal(0.92));
|
||||||
|
// forecastPaLast.setPa0(BigDecimal.ZERO);
|
||||||
|
// forecastPaLast.setIm(new BigDecimal(120));
|
||||||
|
// forecastPaLast.setPt0(BigDecimal.ZERO);
|
||||||
|
// forecastPaLast.setPa(BigDecimal.ZERO);
|
||||||
|
// forecastPaLast.setChtm(new Date());
|
||||||
|
//
|
||||||
|
// }
|
||||||
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast) && !forecastPaLast.getTm().equals(sdfDay.format(nowTime))) {
|
if (CollectionUtils.isNotEmpty(paramList) && CollectionUtils.isNotEmpty(kList) && ObjectUtils.isNotEmpty(forecastPaLast) && !forecastPaLast.getTm().equals(sdfDay.format(nowTime))) {
|
||||||
Calendar calendar2 = Calendar.getInstance();
|
Calendar calendar2 = Calendar.getInstance();
|
||||||
calendar2.setTime(sdfDay.parse(forecastPaLast.getTm()));
|
calendar2.setTime(sdfDay.parse(forecastPaLast.getTm()));
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,18 @@
|
||||||
WHERE stb.source in ('QX', 'SW', 'SH')
|
WHERE stb.source in ('QX', 'SW', 'SH')
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="getStcdFirstPptnData" resultType="com.gunshi.project.xyt.model.StPptnR">
|
||||||
|
SELECT stb.stcd,
|
||||||
|
r.tm etm,
|
||||||
|
stb.source,
|
||||||
|
stb.sttp
|
||||||
|
FROM public.st_stbprp_b stb
|
||||||
|
LEFT JOIN (SELECT *
|
||||||
|
FROM (SELECT *, ROW_NUMBER() OVER ( PARTITION BY stcd ORDER BY tm ASC ) AS rn FROM public.st_pptn_r) subquery
|
||||||
|
WHERE subquery.rn = 1) r ON stb.stcd = r.stcd
|
||||||
|
WHERE stb.source in ('QX', 'SW', 'SH')
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="getPptnRDataList" resultType="java.util.Map">
|
<select id="getPptnRDataList" resultType="java.util.Map">
|
||||||
SELECT to_char(tm_start, 'YYYY-MM-DD') tm,
|
SELECT to_char(tm_start, 'YYYY-MM-DD') tm,
|
||||||
drp
|
drp
|
||||||
|
|
|
||||||
|
|
@ -16,4 +16,18 @@
|
||||||
WHERE subquery2.rn = 1) r2 ON stb.stcd = r.stcd
|
WHERE subquery2.rn = 1) r2 ON stb.stcd = r.stcd
|
||||||
WHERE stb.source in ('SW', 'SH')
|
WHERE stb.source in ('SW', 'SH')
|
||||||
</select>
|
</select>
|
||||||
|
<select id="getStcdFirstRsvrData" resultType="com.gunshi.project.xyt.model.StRsvrR">
|
||||||
|
SELECT stb.stcd,
|
||||||
|
case UPPER(stb.sttp) when 'RR' then r.tm when 'ZZ' then r2.tm end stm,
|
||||||
|
stb.source,
|
||||||
|
stb.sttp
|
||||||
|
FROM public.st_stbprp_b stb
|
||||||
|
LEFT JOIN (SELECT *
|
||||||
|
FROM (SELECT *, ROW_NUMBER() OVER ( PARTITION BY stcd ORDER BY tm ASC ) AS rn FROM public.st_rsvr_r) subquery
|
||||||
|
WHERE subquery.rn = 1) r ON stb.stcd = r.stcd
|
||||||
|
LEFT JOIN (SELECT *
|
||||||
|
FROM (SELECT *, ROW_NUMBER() OVER ( PARTITION BY stcd ORDER BY tm ASC ) AS rn FROM public.st_river_r) subquery2
|
||||||
|
WHERE subquery2.rn = 1) r2 ON stb.stcd = r.stcd
|
||||||
|
WHERE stb.source in ('SW', 'SH')
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue