雨情水位数据同步切换源
parent
f3d3ff04f6
commit
6c737846af
|
|
@ -1,25 +1,6 @@
|
|||
package com.gunshi.project.xyt.timetask;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
||||
|
|
@ -47,7 +28,7 @@ import com.gunshi.project.xyt.service.StRsvrRRealService;
|
|||
import com.gunshi.project.xyt.service.StRsvrRService;
|
||||
import com.gunshi.project.xyt.service.StStbprpBService;
|
||||
import com.gunshi.project.xyt.util.OkHttpUtil;
|
||||
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.FormBody;
|
||||
import okhttp3.MediaType;
|
||||
|
|
@ -55,8 +36,27 @@ import okhttp3.OkHttpClient;
|
|||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
import ru.olegcherednik.jackson_utils.JacksonUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author cxw
|
||||
* @description: 数据定时任务
|
||||
|
|
@ -78,6 +78,15 @@ public class DataTask {
|
|||
@Value("${apiPath}")
|
||||
private String apiPath;// 获取雨情按天接口
|
||||
|
||||
@Value("${jcskPath}")
|
||||
private String jcskPath;// 荆楚水库同步地址
|
||||
|
||||
@Value("${jcskToken}")
|
||||
private String jcskToken;// 荆楚水库同步接口token
|
||||
|
||||
public static String jcskPathPptnRoute = "/st_pptn_r";// 雨情接口
|
||||
public static String jcskPathRiverRoute = "/st_rsvr_r";// 水位接口
|
||||
|
||||
public static String hbskpprealstsRoute = "pubapi/hbsk/pprealsts";// 站点实时雨情
|
||||
|
||||
public static String hbskpphisRoute = "pubapi/hbsk/pphis";// 站点历史雨情
|
||||
|
|
@ -219,6 +228,84 @@ public class DataTask {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 同步荆楚水库雨量数据
|
||||
* @param
|
||||
* @return: void
|
||||
* @auther: cxw
|
||||
* @date: 2024-08-19, 周一, 13:41:50
|
||||
*/
|
||||
@Async
|
||||
@Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES)
|
||||
// @PostConstruct
|
||||
public void getSkYqHisDataJcsk() {
|
||||
Date now = new Date();
|
||||
System.out.println("荆楚水库雨情定时任务,执行时间:" + sdf.format(now));
|
||||
// 获取水库站点编码历史雨情表中站点最新数据时间
|
||||
List<StPptnR> stcdLast = stPptnRService.getStcdLastPptnData();
|
||||
OkHttpClient client = OkHttpUtil.build();
|
||||
try {
|
||||
if(CollectionUtils.isNotEmpty(stcdLast)){
|
||||
for(StPptnR stPptnR : stcdLast){
|
||||
String stcd = stPptnR.getStcd();
|
||||
if(!"716164061".equals(stcd)){
|
||||
continue;
|
||||
} else {
|
||||
stcd = "3610";
|
||||
}
|
||||
Date stm = stPptnR.getStm();
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
// 默认40天前(接口最多40天),存在则不加,接口是大于开始时间
|
||||
if(ObjectUtils.isEmpty(stm)){
|
||||
calendar.add(Calendar.DATE, -60);
|
||||
} else {
|
||||
calendar.setTime(stm);
|
||||
// calendar.add(Calendar.HOUR_OF_DAY, 1);
|
||||
}
|
||||
stm = calendar.getTime();
|
||||
Response resp = client.newCall(new Request.Builder().url(jcskPath + jcskPathPptnRoute)
|
||||
.post(new FormBody.Builder().add("stcd", stcd)
|
||||
.add("stm", sdf.format(stm))
|
||||
.add("etm", sdf.format(now))
|
||||
.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());
|
||||
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() + "_" + e.getTm(), // 使用属性组合作为键
|
||||
Function.identity(),
|
||||
(existing, replacement) -> existing // 如果有冲突,保留现有的
|
||||
)).values().stream().collect(Collectors.toList());
|
||||
stPptnRService.saveBatch(rlist);
|
||||
// 使用最后一条更新到实时数据表
|
||||
StPptnR stPptnR1 = rlist.get(rlist.size() - 1);
|
||||
StPptnRReal stPptnRReal = new StPptnRReal();
|
||||
stPptnRReal.setStcd(stPptnR1.getStcd());
|
||||
stPptnRReal.setTm(stPptnR1.getTm());
|
||||
stPptnRReal.setDrp(stPptnR1.getDrp());
|
||||
stPptnRReal.setChtm(new Date());
|
||||
UpdateWrapper<StPptnRReal> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("stcd", stPptnRReal.getStcd());
|
||||
stPptnRRealService.saveOrUpdate(stPptnRReal, updateWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.error("荆楚水库雨情定时任务:", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 定时获取水库雨情数据(按天)
|
||||
* @param
|
||||
|
|
@ -381,6 +468,84 @@ public class DataTask {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @description: 同步荆楚水库雨量数据
|
||||
* @param
|
||||
* @return: void
|
||||
* @auther: cxw
|
||||
* @date: 2024-08-19, 周一, 13:41:50
|
||||
*/
|
||||
@Async
|
||||
@Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES)
|
||||
// @PostConstruct
|
||||
public void getSkSqHisDataJcsk() {
|
||||
Date now = new Date();
|
||||
System.out.println("荆楚水库水位定时任务,执行时间:" + sdf.format(now));
|
||||
// 获取水库站点编码历史水情表中站点最新数据时间
|
||||
List<StRsvrR> stcdLast = stRsvrRService.getStcdLastRsvrData();
|
||||
OkHttpClient client = OkHttpUtil.build();
|
||||
try {
|
||||
if(CollectionUtils.isNotEmpty(stcdLast)){
|
||||
for(StRsvrR stRsvrR : stcdLast){
|
||||
Date stm = stRsvrR.getStm();
|
||||
String stcd = stRsvrR.getStcd();
|
||||
if(!"716164061".equals(stcd)){
|
||||
continue;
|
||||
} else {
|
||||
stcd = "3610";
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
// 默认40天前(接口最多40天),存在则不加,接口是大于开始时间
|
||||
if(ObjectUtils.isEmpty(stm)){
|
||||
calendar.add(Calendar.DATE, -60);
|
||||
} else {
|
||||
calendar.setTime(stm);
|
||||
// calendar.add(Calendar.HOUR_OF_DAY, 1);
|
||||
}
|
||||
stm = calendar.getTime();
|
||||
Response resp = client.newCall(new Request.Builder().url(jcskPath + jcskPathRiverRoute)
|
||||
.post(new FormBody.Builder().add("stcd", stcd)
|
||||
.add("stm", sdf.format(stm))
|
||||
.add("etm", sdf.format(now))
|
||||
.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());
|
||||
JSONArray data = jsonObject.getJSONArray("data");
|
||||
if(ObjectUtils.isNotEmpty(data)){
|
||||
List<StRsvrR> rlist = data.toJavaList(StRsvrR.class);
|
||||
if(CollectionUtils.isNotEmpty(rlist)){
|
||||
// 全部替换为stcd,并去重
|
||||
rlist = rlist.stream().peek(entity -> entity.setStcd(stRsvrR.getStcd())).collect(Collectors.toMap(
|
||||
e -> e.getStcd() + "_" + e.getTm(), // 使用属性组合作为键
|
||||
Function.identity(),
|
||||
(existing, replacement) -> existing // 如果有冲突,保留现有的
|
||||
)).values().stream().collect(Collectors.toList());
|
||||
stRsvrRService.saveBatch(rlist);
|
||||
// 使用最后一条更新到实时数据表
|
||||
StRsvrR STRsvrR1 = rlist.get(rlist.size() - 1);
|
||||
StRsvrRReal stRsvrRReal = new StRsvrRReal();
|
||||
stRsvrRReal.setStcd(STRsvrR1.getStcd());
|
||||
stRsvrRReal.setTm(STRsvrR1.getTm());
|
||||
stRsvrRReal.setRz(STRsvrR1.getRz());
|
||||
stRsvrRReal.setChtm(new Date());
|
||||
UpdateWrapper<StRsvrRReal> updateWrapper = new UpdateWrapper<>();
|
||||
updateWrapper.eq("stcd", stRsvrRReal.getStcd());
|
||||
stRsvrRRealService.saveOrUpdate(stRsvrRReal, updateWrapper);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.error("荆楚水库水位定时任务:", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @description: 定时获取水库图像数据(实时)
|
||||
* @param
|
||||
|
|
|
|||
|
|
@ -30,6 +30,9 @@ shqxjsCloudowrCnPath: http://shqxjs.cloudowr.cn/service/
|
|||
|
||||
owrsvrPath: http://owrsvr.cloudowr.cn/
|
||||
|
||||
jcskPath: http://223.75.53.124:8002/shareddata/api/v1/monitdata/xfdbaj
|
||||
jcskToken: 65E30623C28021BDC9400E2552FF88EB345FC5091BBE53C0650C489709C44075B13DD33924FEE38B7DFE9633B68E941126AB16D8BE875B480193141D9B8B8EB8
|
||||
|
||||
apiPath: http://223.75.53.141:8000/shzh/monitdata/datasync/getData
|
||||
|
||||
shqxjsWarnPath: http://223.75.53.141:8000/shzh/met/zyqxfw/api/warning/getGroupWarning
|
||||
|
|
|
|||
Loading…
Reference in New Issue