表连接修复

master
cxw 2024-10-17 17:12:58 +08:00
parent 566e783c85
commit 957d07efb1
2 changed files with 103 additions and 23 deletions

View File

@ -165,27 +165,39 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
List<StPptnR> pptnRFutureList = new ArrayList<>();
QueryWrapper<StPptnR> qwExisted = new QueryWrapper<>();
Boolean isHaveFuturePPtn = true;
for(StStbprpB b : stbs){
String stcd = b.getStcd();
// 如果结束时间在当前时间之前,降雨序列从历史降雨表获取
if (endTime.compareTo(nowHourTime) <= 0) {
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", stcd).ge("tm", startTime).le("tm", endTime).orderBy(true, true, "tm");
} else {
qwExisted = new QueryWrapper<StPptnR>().eq("stcd", stcd).ge("tm", startTime).le("tm", nowHourTime).orderBy(true, true, "tm");
try {
// 获取预报数据
pptnRFutureList = getForecastDrpData(nowHourTime, stcd);
} catch (IllegalArgumentException e) {
if(stcd.equals(attResBase.getStcd())){
isHaveFuturePPtn = false;
}
log.error("该时间无预报数据");
}
}
List<StPptnR> pptnRExistedList = stPptnRService.list(qwExisted);
pptnRAllList.addAll(pptnRExistedList);
pptnRAllList.addAll(pptnRFutureList);
// 檀树岗修改实测降雨查询表数据预测降雨使用geom参数。最后按时间算数平均
// for(StStbprpB b : stbs){
// String stcd = b.getStcd();
// // 如果结束时间在当前时间之前,降雨序列从历史降雨表获取
// if (endTime.compareTo(nowHourTime) <= 0) {
// qwExisted = new QueryWrapper<StPptnR>().eq("stcd", stcd).ge("tm", startTime).le("tm", endTime).orderBy(true, true, "tm");
// } else {
// qwExisted = new QueryWrapper<StPptnR>().eq("stcd", stcd).ge("tm", startTime).le("tm", nowHourTime).orderBy(true, true, "tm");
// try {
// // 获取预报数据
// pptnRFutureList = getForecastDrpData(nowHourTime, stcd);
// } catch (IllegalArgumentException e) {
// if(stcd.equals(attResBase.getStcd())){
// isHaveFuturePPtn = false;
// }
// log.error("该时间无预报数据");
// }
// }
// List<StPptnR> pptnRExistedList = stPptnRService.list(qwExisted);
// pptnRAllList.addAll(pptnRExistedList);
// pptnRAllList.addAll(pptnRFutureList);
// }
if (endTime.compareTo(nowHourTime) <= 0) {
qwExisted = new QueryWrapper<StPptnR>().in("stcd", stbs.stream().map(StStbprpB::getStcd).toArray(String[]::new)).ge("tm", startTime).le("tm", endTime).orderBy(true, true, "tm");
} else {
qwExisted = new QueryWrapper<StPptnR>().in("stcd", stbs.stream().map(StStbprpB::getStcd).toArray(String[]::new)).ge("tm", startTime).le("tm", nowHourTime).orderBy(true, true, "tm");
// 获取预报数据
pptnRFutureList = getForecastDrpData(nowHourTime, "");
}
List<StPptnR> pptnRExistedList = stPptnRService.list(qwExisted);
pptnRAllList.addAll(pptnRExistedList);
pptnRAllList.addAll(pptnRFutureList);
if (CollectionUtils.isEmpty(pptnRAllList)) {
return voList;
}
@ -406,7 +418,8 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
// List<ForeRainTimeVo> data = forecastService.getData(vo, total, detail);
// 2024-10-14 改为获取水库整个面的降雨
ForeRainStatVo vo = new ForeRainStatVo();
vo.setGeom(forecastUseparam.getParamValue());
String[] paramValue = forecastUseparam.getParamValue().split(",");// x1,y1,x2,y2
vo.setGeom(buildRectangleGeoJson(Double.parseDouble(paramValue[0]), Double.parseDouble(paramValue[1]), Double.parseDouble(paramValue[2]), Double.parseDouble(paramValue[3])));
List<ForeRainTimeVo> data = forecastService.getAreaData(vo, total, detail);
if (CollectionUtils.isNotEmpty(data)) {
for (ForeRainTimeVo foreRainTimeVo : data) {
@ -669,4 +682,71 @@ public class ForecastResultsService extends ServiceImpl<ForecastResultsMapper, F
forecastProject.setYcSumFlood(ycSumFlood);
}
}
public static String buildRectangleGeoJson(double x1, double y1, double x2, double y2) {
// 校验数据是否在最大允许范围(预测降雨所划定区域)
Double x11 = ForecastService.x1;
Double y11 = ForecastService.y1;
Double x22 = ForecastService.x2;
Double y22 = ForecastService.y2;
/* y
* x22,y22
* x2,y2
*
* x1,y1
* x11,y11
* >>>>>>>>>>>> x
*/
// if(x11.compareTo(Double.valueOf(x1)) > 0 || y11.compareTo(Double.valueOf(y1)) > 0 || x22.compareTo(Double.valueOf(x2)) < 0 || y22.compareTo(Double.valueOf(y2)) < 0){
// throw new IllegalArgumentException("Geom参数超出预测降雨范围");
// }
if (!(x11.compareTo(Double.valueOf(x1)) <= 0 && x11.compareTo(Double.valueOf(x2)) <= 0 && x22.compareTo(Double.valueOf(x1)) >= 0 && x22.compareTo(Double.valueOf(x2)) >= 0
&& y11.compareTo(Double.valueOf(y1)) <= 0 && y11.compareTo(Double.valueOf(y2)) <= 0 && y22.compareTo(Double.valueOf(y1)) >= 0 && x22.compareTo(Double.valueOf(y2)) >= 0)) {
throw new IllegalArgumentException("Geom参数超出预测降雨范围");
}
double[] corner1 = {x1, y1};
double[] corner2 = {x2, y2};
// 构造矩形的四个顶点这里假设corner1是左下corner2是右上
double[][][] coordinates2D = {
{
{corner1[0], corner1[1]}, // 左下角
{corner2[0], corner1[1]}, // 右上角
{corner2[0], corner2[1]}, // 右下角
{corner1[0], corner2[1]}, // 左上角
{corner1[0], corner1[1]} // 回到左下角,闭合多边形
}
};
// 为了适应四层数组结构,我们添加一个额外的数组层
double[][][][] customCoordinates = {coordinates2D};
// 构建自定义的JSON字符串注意这不是标准的GeoJSON
StringBuilder jsonBuilder = new StringBuilder();
jsonBuilder.append("{");
jsonBuilder.append("\"type\": \"CustomPolygon\","); // 使用自定义类型
jsonBuilder.append("\"coordinates\": ");
jsonBuilder.append("[");
// 遍历并添加坐标到JSON字符串中
for (double[][][] ring : customCoordinates) {
jsonBuilder.append("[");
for (double[][] line : ring) {
jsonBuilder.append("[");
for (double[] point : line) {
jsonBuilder.append("[");
jsonBuilder.append(point[0]); // 经度
jsonBuilder.append(",");
jsonBuilder.append(point[1]); // 纬度
jsonBuilder.append("],");
}
jsonBuilder.append("]");
}
jsonBuilder.append("]");
}
jsonBuilder.append("]"); // 闭合最外层的坐标数组
jsonBuilder.append("}"); // 闭合JSON对象
return jsonBuilder.toString();
}
}

View File

@ -273,8 +273,8 @@ public class ForecastService {
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++){
for(int i = 0;i < nw;i++){
for(int j=0;j< nh;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)));