From 88bab3545af45656661d232989d48a1bfeaf22ad Mon Sep 17 00:00:00 2001 From: cxw <1520264117@qq.com> Date: Mon, 23 Sep 2024 13:53:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E9=87=8A=E5=B0=8F=E7=8E=89=E6=BD=AD?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gunshi/project/xyt/timetask/DataTask.java | 1318 ++++++++--------- 1 file changed, 659 insertions(+), 659 deletions(-) diff --git a/src/main/java/com/gunshi/project/xyt/timetask/DataTask.java b/src/main/java/com/gunshi/project/xyt/timetask/DataTask.java index 6d92e3c..5d8f830 100644 --- a/src/main/java/com/gunshi/project/xyt/timetask/DataTask.java +++ b/src/main/java/com/gunshi/project/xyt/timetask/DataTask.java @@ -1,665 +1,665 @@ -package com.gunshi.project.xyt.timetask; - -import com.alibaba.fastjson2.JSONArray; -import com.alibaba.fastjson2.JSONObject; -import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; -import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; -import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; -import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.gunshi.project.xyt.entity.SkSyncData; -import com.gunshi.project.xyt.entity.SkSyncResp; -import com.gunshi.project.xyt.entity.SyncDataReq; -import com.gunshi.project.xyt.model.*; -import com.gunshi.project.xyt.service.*; -import com.gunshi.project.xyt.util.OkHttpUtil; -import lombok.extern.slf4j.Slf4j; -import okhttp3.*; -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.*; -import java.util.concurrent.TimeUnit; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * @author cxw - * @description: 数据定时任务 - * @classname DataTask.java - * @create 2024-07-11, 星期四, 14:19:22 - */ -@EnableScheduling//开启定时任务 -@Component -@Slf4j -@Profile("prod") -public class DataTask { - private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - private static SimpleDateFormat sdfD = new SimpleDateFormat("yyyy-MM-dd"); - private static SimpleDateFormat sdfH = new SimpleDateFormat("yyyy-MM-dd HH"); - - @Value("${owrsvrPath}") - private String owrsvrPath;// 获取水雨情、图像接口 http://owrsvr.cloudowr.cn/ - - @Value("${apiPath}") - private String apiPath;// 获取雨情按天接口 - - @Value("${jcskPath}") - private String jcskPath;// 荆楚水库同步地址 - - @Value("${jcskToken}") - private String jcskToken;// 荆楚水库同步接口token - - @Value("${reloadCache}") - private String reloadCache;// 清除ip白名单缓存 - - public static String jcskPathPptnRoute = "/xfdbaj/st_pptn_r";// 雨情接口 - public static String jcskPathRiverRoute = "/xfdbaj/st_rsvr_r";// 水位接口 - - public static String hbskpprealstsRoute = "pubapi/hbsk/pprealsts";// 站点实时雨情 - - public static String hbskpphisRoute = "pubapi/hbsk/pphis";// 站点历史雨情 - - public static String hbskzzrealstsRoute = "pubapi/hbsk/zzrealsts";// 站点实时水情 - - public static String hbskzzhisRoute = "pubapi/hbsk/zzhis";// 站点历史水情 - - public static String hbskpicrealstsRoute = "pubapi/hbsk/picrealsts";// 站点实时图像 - - public static String hbskpichisRoute = "pubapi/hbsk/pichis";// 站点历史图像 - - - // 水库站点 - @Autowired - private StStbprpBService stStbprpBService; - - // 实时雨情 - @Autowired - private StPptnRRealService stPptnRRealService; - - // 历史雨情 - @Autowired - private StPptnRService stPptnRService; - - // 小时雨情 - @Autowired - private StPptnRHService stPptnRHService; - - // 按天雨情 - @Autowired - private StPptnRDService stPptnRDService; - - // 实时水情 - @Autowired - private StRsvrRRealService stRsvrRRealService; - - // 历史水情 - @Autowired - private StRsvrRService stRsvrRService; - - // 实时图像 - @Autowired - private StImgRRealService stImgRRealService; - - // 历史图像 - @Autowired - private StImgRService stImgRService; - - @Autowired - private MessageCenterService messageCenterService; - - - /** - * @description: 定时获取水库雨情数据(实时) - * @param - * @return: void - * @auther: cxw - * @date: 2024-07-11, 周四, 14:21:35 - */ -// @Async -// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) - public void getSkYqRealData() { - Date now = new Date(); - System.out.println("雨情实时定时任务,执行时间:" + sdf.format(now)); - // 获取水库站点编码 - String sts = "[" + stStbprpBService.list(new QueryWrapper().eq("source", "SK")).stream().map(StStbprpB::getStcd).collect(Collectors.joining(",")) + "]"; - OkHttpClient client = OkHttpUtil.build(); - try { - Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskpprealstsRoute) - .post(new FormBody.Builder().add("sts", sts).build()) - .build()).execute(); - String respStr = resp.body().string(); - ObjectMapper om = new ObjectMapper(); - Map map = om.readValue(respStr, Map.class); - List list = (List)map.get("data"); - if(CollectionUtils.isNotEmpty(list)){ - for (Map map1 : list) { - StPptnRReal stPptnRReal = new ObjectMapper().convertValue(map1, StPptnRReal.class); - if(ObjectUtils.isEmpty(stPptnRReal.getChtm())){ - stPptnRReal.setChtm(new Date()); - } - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.eq("stcd", stPptnRReal.getStcd()); - stPptnRRealService.saveOrUpdate(stPptnRReal, updateWrapper); - } - } - } - catch (IOException e) - { - log.error("雨情实时定时任务错误:", e.getMessage()); - } - } - - /** - * @description: 定时获取水库雨情数据(历史) - * @param - * @return: void - * @auther: cxw - * @date: 2024-07-11, 周四, 14:21:35 - */ -// @Async -// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) - public void getSkYqHisData() { - Date now = new Date(); - System.out.println("雨情历史定时任务,执行时间:" + sdf.format(now)); - // 获取水库站点编码历史雨情表中站点最新数据时间 - List stcdLast = stPptnRService.getStcdLastPptnData(); - OkHttpClient client = OkHttpUtil.build(); - try { - if(CollectionUtils.isNotEmpty(stcdLast)){ - for(StPptnR stPptnR : stcdLast){ - Date stm = stPptnR.getStm(); - Calendar calendar = Calendar.getInstance(); - // 默认40天前(接口最多40天),存在则加1小时(接口是按小时算且大于等于开始时间) - if(ObjectUtils.isEmpty(stm)){ - calendar.add(Calendar.DATE, -40); - } else { - calendar.setTime(stm); - calendar.add(Calendar.HOUR_OF_DAY, 1); - } - stm = calendar.getTime(); - Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskpphisRoute) - .post(new FormBody.Builder().add("stcd", stPptnR.getStcd()) - .add("stm", sdfH.format(stm)) - .add("etm", sdfH.format(now)) - .build()) - .build()).execute(); - String respStr = resp.body().string(); - ObjectMapper om = new ObjectMapper(); - Map map = om.readValue(respStr, Map.class); - if("400".equals(map.get("code").toString())){ - continue; - } - List list = (List)map.get("data"); - if(CollectionUtils.isNotEmpty(list)){ - List rlist = JSONArray.parseArray(JSONObject.toJSONString(list)).toJavaList(StPptnR.class); - stPptnRService.saveBatch(rlist); - } - } - } - } - catch (IOException e) - { - log.error("雨情历史定时任务错误:", e.getMessage()); - } - } - - - /** - * @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 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); +//package com.gunshi.project.xyt.timetask; +// +//import com.alibaba.fastjson2.JSONArray; +//import com.alibaba.fastjson2.JSONObject; +//import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; +//import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper; +//import com.baomidou.mybatisplus.core.toolkit.CollectionUtils; +//import com.baomidou.mybatisplus.core.toolkit.ObjectUtils; +//import com.fasterxml.jackson.databind.DeserializationFeature; +//import com.fasterxml.jackson.databind.ObjectMapper; +//import com.gunshi.project.xyt.entity.SkSyncData; +//import com.gunshi.project.xyt.entity.SkSyncResp; +//import com.gunshi.project.xyt.entity.SyncDataReq; +//import com.gunshi.project.xyt.model.*; +//import com.gunshi.project.xyt.service.*; +//import com.gunshi.project.xyt.util.OkHttpUtil; +//import lombok.extern.slf4j.Slf4j; +//import okhttp3.*; +//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.*; +//import java.util.concurrent.TimeUnit; +//import java.util.function.Function; +//import java.util.stream.Collectors; +// +///** +// * @author cxw +// * @description: 数据定时任务 +// * @classname DataTask.java +// * @create 2024-07-11, 星期四, 14:19:22 +// */ +//@EnableScheduling//开启定时任务 +//@Component +//@Slf4j +//@Profile("prod") +//public class DataTask { +// private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); +// private static SimpleDateFormat sdfD = new SimpleDateFormat("yyyy-MM-dd"); +// private static SimpleDateFormat sdfH = new SimpleDateFormat("yyyy-MM-dd HH"); +// +// @Value("${owrsvrPath}") +// private String owrsvrPath;// 获取水雨情、图像接口 http://owrsvr.cloudowr.cn/ +// +// @Value("${apiPath}") +// private String apiPath;// 获取雨情按天接口 +// +// @Value("${jcskPath}") +// private String jcskPath;// 荆楚水库同步地址 +// +// @Value("${jcskToken}") +// private String jcskToken;// 荆楚水库同步接口token +// +// @Value("${reloadCache}") +// private String reloadCache;// 清除ip白名单缓存 +// +// public static String jcskPathPptnRoute = "/xfdbaj/st_pptn_r";// 雨情接口 +// public static String jcskPathRiverRoute = "/xfdbaj/st_rsvr_r";// 水位接口 +// +// public static String hbskpprealstsRoute = "pubapi/hbsk/pprealsts";// 站点实时雨情 +// +// public static String hbskpphisRoute = "pubapi/hbsk/pphis";// 站点历史雨情 +// +// public static String hbskzzrealstsRoute = "pubapi/hbsk/zzrealsts";// 站点实时水情 +// +// public static String hbskzzhisRoute = "pubapi/hbsk/zzhis";// 站点历史水情 +// +// public static String hbskpicrealstsRoute = "pubapi/hbsk/picrealsts";// 站点实时图像 +// +// public static String hbskpichisRoute = "pubapi/hbsk/pichis";// 站点历史图像 +// +// +// // 水库站点 +// @Autowired +// private StStbprpBService stStbprpBService; +// +// // 实时雨情 +// @Autowired +// private StPptnRRealService stPptnRRealService; +// +// // 历史雨情 +// @Autowired +// private StPptnRService stPptnRService; +// +// // 小时雨情 +// @Autowired +// private StPptnRHService stPptnRHService; +// +// // 按天雨情 +// @Autowired +// private StPptnRDService stPptnRDService; +// +// // 实时水情 +// @Autowired +// private StRsvrRRealService stRsvrRRealService; +// +// // 历史水情 +// @Autowired +// private StRsvrRService stRsvrRService; +// +// // 实时图像 +// @Autowired +// private StImgRRealService stImgRRealService; +// +// // 历史图像 +// @Autowired +// private StImgRService stImgRService; +// +// @Autowired +// private MessageCenterService messageCenterService; +// +// +// /** +// * @description: 定时获取水库雨情数据(实时) +// * @param +// * @return: void +// * @auther: cxw +// * @date: 2024-07-11, 周四, 14:21:35 +// */ +//// @Async +//// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) +// public void getSkYqRealData() { +// Date now = new Date(); +// System.out.println("雨情实时定时任务,执行时间:" + sdf.format(now)); +// // 获取水库站点编码 +// String sts = "[" + stStbprpBService.list(new QueryWrapper().eq("source", "SK")).stream().map(StStbprpB::getStcd).collect(Collectors.joining(",")) + "]"; +// OkHttpClient client = OkHttpUtil.build(); +// try { +// Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskpprealstsRoute) +// .post(new FormBody.Builder().add("sts", sts).build()) +// .build()).execute(); +// String respStr = resp.body().string(); +// ObjectMapper om = new ObjectMapper(); +// Map map = om.readValue(respStr, Map.class); +// List list = (List)map.get("data"); +// if(CollectionUtils.isNotEmpty(list)){ +// for (Map map1 : list) { +// StPptnRReal stPptnRReal = new ObjectMapper().convertValue(map1, StPptnRReal.class); +// if(ObjectUtils.isEmpty(stPptnRReal.getChtm())){ +// stPptnRReal.setChtm(new Date()); +// } +// UpdateWrapper updateWrapper = new UpdateWrapper<>(); +// updateWrapper.eq("stcd", stPptnRReal.getStcd()); +// stPptnRRealService.saveOrUpdate(stPptnRReal, updateWrapper); +// } +// } +// } +// catch (IOException e) +// { +// log.error("雨情实时定时任务错误:", e.getMessage()); +// } +// } +// +// /** +// * @description: 定时获取水库雨情数据(历史) +// * @param +// * @return: void +// * @auther: cxw +// * @date: 2024-07-11, 周四, 14:21:35 +// */ +//// @Async +//// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) +// public void getSkYqHisData() { +// Date now = new Date(); +// System.out.println("雨情历史定时任务,执行时间:" + sdf.format(now)); +// // 获取水库站点编码历史雨情表中站点最新数据时间 +// List stcdLast = stPptnRService.getStcdLastPptnData(); +// OkHttpClient client = OkHttpUtil.build(); +// try { +// if(CollectionUtils.isNotEmpty(stcdLast)){ +// for(StPptnR stPptnR : stcdLast){ +// Date stm = stPptnR.getStm(); +// Calendar calendar = Calendar.getInstance(); +// // 默认40天前(接口最多40天),存在则加1小时(接口是按小时算且大于等于开始时间) +// if(ObjectUtils.isEmpty(stm)){ +// calendar.add(Calendar.DATE, -40); +// } 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()); - String code = jsonObject.get("code").toString(); - // 清除同步平台的ip白名单缓存 - if (!"200".equals(code)) { - 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 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); - // 更新到实时数据表 - stPptnRRealService.updatePptnRReal(stPptnR.getStcd()); - // 整编降雨量小时表数据 - StPptnRH maxData = stPptnRHService.getMaxData(stPptnR.getStcd()); - List list = stPptnRHService.reorganizePptnRHData(stPptnR.getStcd(), maxData); - if(CollectionUtils.isNotEmpty(list)){ - StPptnRH LastData = list.get(0); - if(LastData.getTm().equals(maxData.getTm())){ - list.remove(0); - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.eq("stcd", LastData.getStcd()).eq("tm", LastData.getTm()); - LastData.setDrp(LastData.getDrp()); - LastData.setChtm(maxData.getChtm()); - stPptnRHService.saveOrUpdate(LastData, updateWrapper); - } - if(list.size() > 0){ - stPptnRHService.saveBatch(list); - } - } - } - } - } - } - } - catch (IOException e) - { - log.error("荆楚水库雨情定时任务:", e.getMessage()); - } - } - - /** - * @description: 定时获取水库雨情数据(按天) - * @param - * @return: void - * @auther: cxw - * @date: 2024-07-11, 周四, 14:21:35 - */ -// @Async -// @Scheduled(cron = "0 30 8 * * ?") - public void getSkYqDayData() { - Date now = new Date(); - System.out.println("雨情按天定时任务,执行时间:" + sdf.format(now)); - // 获取水库站点编码按天雨情表中站点最新数据时间 - List stcdLast = stPptnRDService.getStcdLastPptnDayData(); - OkHttpClient client = OkHttpUtil.build(); - try { - if(CollectionUtils.isNotEmpty(stcdLast)){ - for(StPptnRD stPptnRD : stcdLast){ - String stcd = stPptnRD.getStcd(); - Date stm = stPptnRD.getStm(); - Calendar calendar = Calendar.getInstance(); - // 默认两周前的时间(接口只提供addvcd的条件,数据量较大),如果存在,需要加一天(接口是按天算且大于等于开始时间) - if(ObjectUtils.isEmpty(stm)){ - calendar.add(Calendar.DATE, -14); - } else { - calendar.setTime(stm); - calendar.add(Calendar.DATE, 1); - } - stm = calendar.getTime(); - MediaType mediaType = MediaType.parse("application/json"); - SyncDataReq syncDataReq = new SyncDataReq(); - syncDataReq.setAdcd(stPptnRD.getAdcd()); - syncDataReq.setType("SK"); - syncDataReq.setStartDate(sdfD.format(stm)); - syncDataReq.setEndDate(sdfD.format(now)); - RequestBody body = RequestBody.create(JacksonUtils.writeValue(syncDataReq), mediaType); - Response resp = client.newCall(new Request.Builder().url(apiPath) - .post(body) - .build()).execute(); - String respStr = resp.body().string(); - ObjectMapper objectMapper = new ObjectMapper(); - objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); - SkSyncResp resq = objectMapper.readValue(respStr, SkSyncResp.class); - SkSyncData data = resq.getData(); - List stPptnRDList = data.getStPptnRD(); - if(CollectionUtils.isNotEmpty(stPptnRDList)) { - Iterator iterator = stPptnRDList.iterator(); - while (iterator.hasNext()) { - StPptnRD stPptnRD1 = iterator.next(); - if (!stcd.equals(stPptnRD1.getStcd())) { - iterator.remove(); - continue; - } - stPptnRD1.setYear(Integer.valueOf(sdfD.format(stPptnRD1.getTm()).substring(0, 4))); - } - stPptnRDService.saveBatch(stPptnRDList); - } - } - } - } - catch (IOException e) - { - log.error("雨情按天定时任务错误:", e.getMessage()); - } - } - - - /** - * @description: 定时获取水库水情数据(实时) - * @param - * @return: void - * @auther: cxw - * @date: 2024-07-11, 周四, 14:21:35 - */ +// } +// stm = calendar.getTime(); +// Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskpphisRoute) +// .post(new FormBody.Builder().add("stcd", stPptnR.getStcd()) +// .add("stm", sdfH.format(stm)) +// .add("etm", sdfH.format(now)) +// .build()) +// .build()).execute(); +// String respStr = resp.body().string(); +// ObjectMapper om = new ObjectMapper(); +// Map map = om.readValue(respStr, Map.class); +// if("400".equals(map.get("code").toString())){ +// continue; +// } +// List list = (List)map.get("data"); +// if(CollectionUtils.isNotEmpty(list)){ +// List rlist = JSONArray.parseArray(JSONObject.toJSONString(list)).toJavaList(StPptnR.class); +// stPptnRService.saveBatch(rlist); +// } +// } +// } +// } +// catch (IOException e) +// { +// log.error("雨情历史定时任务错误:", e.getMessage()); +// } +// } +// +// +// /** +// * @description: 同步荆楚水库雨量数据 +// * @param +// * @return: void +// * @auther: cxw +// * @date: 2024-08-19, 周一, 13:41:50 +// */ // @Async // @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) - public void getSkSqRealData() { - Date now = new Date(); - System.out.println("水情实时定时任务,执行时间:" + sdf.format(now)); - // 获取水库站点编码 - String sts = "[" + stStbprpBService.list(new QueryWrapper().eq("source", "SK")).stream().map(StStbprpB::getStcd).collect(Collectors.joining(",")) + "]"; - OkHttpClient client = OkHttpUtil.build(); - try { - Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskzzrealstsRoute) - .post(new FormBody.Builder().add("sts", sts).build()) - .build()).execute(); - String respStr = resp.body().string(); - ObjectMapper om = new ObjectMapper(); - Map map = om.readValue(respStr, Map.class); - List list = (List)map.get("data"); - if(CollectionUtils.isNotEmpty(list)){ - for (Map map1 : list) { - StRsvrRReal stRsvrRReal = new ObjectMapper().convertValue(map1, StRsvrRReal.class); - if(ObjectUtils.isEmpty(stRsvrRReal.getChtm())){ - stRsvrRReal.setChtm(new Date()); - } - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.eq("stcd", stRsvrRReal.getStcd()); - stRsvrRRealService.saveOrUpdate(stRsvrRReal, updateWrapper); - } - } - } - catch (IOException e) - { - log.error("水情实时定时任务错误:", e.getMessage()); - } - } - - /** - * @description: 定时获取水库水情数据(历史) - * @param - * @return: void - * @auther: cxw - * @date: 2024-07-11, 周四, 14:21:35 - */ -// @Async -// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) - public void getSkSqHisData() { - Date now = new Date(); - System.out.println("水情历史定时任务,执行时间:" + sdf.format(now)); - // 获取水库站点编码历史水情表中站点最新数据时间 - List stcdLast = stRsvrRService.getStcdLastRsvrData(); - OkHttpClient client = OkHttpUtil.build(); - try { - if(CollectionUtils.isNotEmpty(stcdLast)){ - for(StRsvrR stRsvrR : stcdLast){ - Date stm = stRsvrR.getStm(); - Calendar calendar = Calendar.getInstance(); - // 默认40天前(接口最多40天),存在则加1小时(接口是按小时算且大于等于开始时间) - if(ObjectUtils.isEmpty(stm)){ - calendar.add(Calendar.DATE, -40); - } else { - calendar.setTime(stm); - calendar.add(Calendar.HOUR_OF_DAY, 1); - } - stm = calendar.getTime(); - Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskzzhisRoute) - .post(new FormBody.Builder().add("stcd", stRsvrR.getStcd()) - .add("stm", sdfH.format(stm)) - .add("etm", sdfH.format(now)) - .build()) - .build()).execute(); - String respStr = resp.body().string(); - ObjectMapper om = new ObjectMapper(); - Map map = om.readValue(respStr, Map.class); - if("400".equals(map.get("code").toString())){ - continue; - } - List list = (List)map.get("data"); - if(CollectionUtils.isNotEmpty(list)){ - List rlist = JSONArray.parseArray(JSONObject.toJSONString(list)).toJavaList(StRsvrR.class); - stRsvrRService.saveBatch(rlist); - } - } - } - } - catch (IOException e) - { - log.error("水情历史定时任务错误:", e.getMessage()); - } - } - - - /** - * @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 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); +//// @PostConstruct +// public void getSkYqHisDataJcsk() { +// Date now = new Date(); +// System.out.println("荆楚水库雨情定时任务,执行时间:" + sdf.format(now)); +// // 获取水库站点编码历史雨情表中站点最新数据时间 +// List 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()); +// String code = jsonObject.get("code").toString(); +// // 清除同步平台的ip白名单缓存 +// if (!"200".equals(code)) { +// 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 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); +// // 更新到实时数据表 +// stPptnRRealService.updatePptnRReal(stPptnR.getStcd()); +// // 整编降雨量小时表数据 +// StPptnRH maxData = stPptnRHService.getMaxData(stPptnR.getStcd()); +// List list = stPptnRHService.reorganizePptnRHData(stPptnR.getStcd(), maxData); +// if(CollectionUtils.isNotEmpty(list)){ +// StPptnRH LastData = list.get(0); +// if(LastData.getTm().equals(maxData.getTm())){ +// list.remove(0); +// UpdateWrapper updateWrapper = new UpdateWrapper<>(); +// updateWrapper.eq("stcd", LastData.getStcd()).eq("tm", LastData.getTm()); +// LastData.setDrp(LastData.getDrp()); +// LastData.setChtm(maxData.getChtm()); +// stPptnRHService.saveOrUpdate(LastData, updateWrapper); +// } +// if(list.size() > 0){ +// stPptnRHService.saveBatch(list); +// } +// } +// } +// } +// } +// } +// } +// catch (IOException e) +// { +// log.error("荆楚水库雨情定时任务:", e.getMessage()); +// } +// } +// +// /** +// * @description: 定时获取水库雨情数据(按天) +// * @param +// * @return: void +// * @auther: cxw +// * @date: 2024-07-11, 周四, 14:21:35 +// */ +//// @Async +//// @Scheduled(cron = "0 30 8 * * ?") +// public void getSkYqDayData() { +// Date now = new Date(); +// System.out.println("雨情按天定时任务,执行时间:" + sdf.format(now)); +// // 获取水库站点编码按天雨情表中站点最新数据时间 +// List stcdLast = stPptnRDService.getStcdLastPptnDayData(); +// OkHttpClient client = OkHttpUtil.build(); +// try { +// if(CollectionUtils.isNotEmpty(stcdLast)){ +// for(StPptnRD stPptnRD : stcdLast){ +// String stcd = stPptnRD.getStcd(); +// Date stm = stPptnRD.getStm(); +// Calendar calendar = Calendar.getInstance(); +// // 默认两周前的时间(接口只提供addvcd的条件,数据量较大),如果存在,需要加一天(接口是按天算且大于等于开始时间) +// if(ObjectUtils.isEmpty(stm)){ +// calendar.add(Calendar.DATE, -14); +// } else { +// calendar.setTime(stm); +// calendar.add(Calendar.DATE, 1); +// } +// stm = calendar.getTime(); +// MediaType mediaType = MediaType.parse("application/json"); +// SyncDataReq syncDataReq = new SyncDataReq(); +// syncDataReq.setAdcd(stPptnRD.getAdcd()); +// syncDataReq.setType("SK"); +// syncDataReq.setStartDate(sdfD.format(stm)); +// syncDataReq.setEndDate(sdfD.format(now)); +// RequestBody body = RequestBody.create(JacksonUtils.writeValue(syncDataReq), mediaType); +// Response resp = client.newCall(new Request.Builder().url(apiPath) +// .post(body) +// .build()).execute(); +// String respStr = resp.body().string(); +// ObjectMapper objectMapper = new ObjectMapper(); +// objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); +// SkSyncResp resq = objectMapper.readValue(respStr, SkSyncResp.class); +// SkSyncData data = resq.getData(); +// List stPptnRDList = data.getStPptnRD(); +// if(CollectionUtils.isNotEmpty(stPptnRDList)) { +// Iterator iterator = stPptnRDList.iterator(); +// while (iterator.hasNext()) { +// StPptnRD stPptnRD1 = iterator.next(); +// if (!stcd.equals(stPptnRD1.getStcd())) { +// iterator.remove(); +// continue; +// } +// stPptnRD1.setYear(Integer.valueOf(sdfD.format(stPptnRD1.getTm()).substring(0, 4))); +// } +// stPptnRDService.saveBatch(stPptnRDList); +// } +// } +// } +// } +// catch (IOException e) +// { +// log.error("雨情按天定时任务错误:", e.getMessage()); +// } +// } +// +// +// /** +// * @description: 定时获取水库水情数据(实时) +// * @param +// * @return: void +// * @auther: cxw +// * @date: 2024-07-11, 周四, 14:21:35 +// */ +//// @Async +//// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) +// public void getSkSqRealData() { +// Date now = new Date(); +// System.out.println("水情实时定时任务,执行时间:" + sdf.format(now)); +// // 获取水库站点编码 +// String sts = "[" + stStbprpBService.list(new QueryWrapper().eq("source", "SK")).stream().map(StStbprpB::getStcd).collect(Collectors.joining(",")) + "]"; +// OkHttpClient client = OkHttpUtil.build(); +// try { +// Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskzzrealstsRoute) +// .post(new FormBody.Builder().add("sts", sts).build()) +// .build()).execute(); +// String respStr = resp.body().string(); +// ObjectMapper om = new ObjectMapper(); +// Map map = om.readValue(respStr, Map.class); +// List list = (List)map.get("data"); +// if(CollectionUtils.isNotEmpty(list)){ +// for (Map map1 : list) { +// StRsvrRReal stRsvrRReal = new ObjectMapper().convertValue(map1, StRsvrRReal.class); +// if(ObjectUtils.isEmpty(stRsvrRReal.getChtm())){ +// stRsvrRReal.setChtm(new Date()); +// } +// UpdateWrapper updateWrapper = new UpdateWrapper<>(); +// updateWrapper.eq("stcd", stRsvrRReal.getStcd()); +// stRsvrRRealService.saveOrUpdate(stRsvrRReal, updateWrapper); +// } +// } +// } +// catch (IOException e) +// { +// log.error("水情实时定时任务错误:", e.getMessage()); +// } +// } +// +// /** +// * @description: 定时获取水库水情数据(历史) +// * @param +// * @return: void +// * @auther: cxw +// * @date: 2024-07-11, 周四, 14:21:35 +// */ +//// @Async +//// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) +// public void getSkSqHisData() { +// Date now = new Date(); +// System.out.println("水情历史定时任务,执行时间:" + sdf.format(now)); +// // 获取水库站点编码历史水情表中站点最新数据时间 +// List stcdLast = stRsvrRService.getStcdLastRsvrData(); +// OkHttpClient client = OkHttpUtil.build(); +// try { +// if(CollectionUtils.isNotEmpty(stcdLast)){ +// for(StRsvrR stRsvrR : stcdLast){ +// Date stm = stRsvrR.getStm(); +// Calendar calendar = Calendar.getInstance(); +// // 默认40天前(接口最多40天),存在则加1小时(接口是按小时算且大于等于开始时间) +// if(ObjectUtils.isEmpty(stm)){ +// calendar.add(Calendar.DATE, -40); +// } 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 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.stream().max(Comparator.comparing(StRsvrR::getTm)).get(); - StRsvrRReal stRsvrRReal = new StRsvrRReal(); - stRsvrRReal.setStcd(STRsvrR1.getStcd()); - stRsvrRReal.setTm(STRsvrR1.getTm()); - stRsvrRReal.setRz(STRsvrR1.getRz()); - stRsvrRReal.setChtm(new Date()); - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.eq("stcd", stRsvrRReal.getStcd()); - stRsvrRRealService.saveOrUpdate(stRsvrRReal, updateWrapper); - messageCenterService.rzWarnMes(rlist); - } - } - } - } - } - catch (IOException e) - { - log.error("荆楚水库水位定时任务:", e.getMessage()); - } - } - - /** - * @description: 定时获取水库图像数据(实时) - * @param - * @return: void - * @auther: cxw - * @date: 2024-07-22, 周一, 13:54:08 - */ +// } +// stm = calendar.getTime(); +// Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskzzhisRoute) +// .post(new FormBody.Builder().add("stcd", stRsvrR.getStcd()) +// .add("stm", sdfH.format(stm)) +// .add("etm", sdfH.format(now)) +// .build()) +// .build()).execute(); +// String respStr = resp.body().string(); +// ObjectMapper om = new ObjectMapper(); +// Map map = om.readValue(respStr, Map.class); +// if("400".equals(map.get("code").toString())){ +// continue; +// } +// List list = (List)map.get("data"); +// if(CollectionUtils.isNotEmpty(list)){ +// List rlist = JSONArray.parseArray(JSONObject.toJSONString(list)).toJavaList(StRsvrR.class); +// stRsvrRService.saveBatch(rlist); +// } +// } +// } +// } +// catch (IOException e) +// { +// log.error("水情历史定时任务错误:", e.getMessage()); +// } +// } +// +// +// /** +// * @description: 同步荆楚水库雨量数据 +// * @param +// * @return: void +// * @auther: cxw +// * @date: 2024-08-19, 周一, 13:41:50 +// */ // @Async // @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) - public void getSkImgRealData() { - Date now = new Date(); - System.out.println("图像实时图像定时任务,执行时间:" + sdf.format(now)); - // 获取水库站点编码 - String sts = "[" + stStbprpBService.list(new QueryWrapper().eq("source", "SK")).stream().map(StStbprpB::getStcd).collect(Collectors.joining(",")) + "]"; - OkHttpClient client = OkHttpUtil.build(); - try { - Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskpicrealstsRoute) - .post(new FormBody.Builder().add("sts", sts).build()) - .build()).execute(); - String respStr = resp.body().string(); - ObjectMapper om = new ObjectMapper(); - Map map = om.readValue(respStr, Map.class); - List list = (List)map.get("data"); - if(CollectionUtils.isNotEmpty(list)){ - for (Map map1 : list) { - StImgRReal stImgRReal = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setDateFormat(sdf).convertValue(map1, StImgRReal.class); - if(ObjectUtils.isEmpty(stImgRReal.getChtm())){ - stImgRReal.setChtm(new Date()); - } - if(ObjectUtils.isEmpty(stImgRReal.getChid())){ - stImgRReal.setChid(map1.get("machineid").toString()); - } - if(ObjectUtils.isEmpty(stImgRReal.getImgPath())){ - stImgRReal.setImgPath(map1.get("url").toString()); - } - UpdateWrapper updateWrapper = new UpdateWrapper<>(); - updateWrapper.eq("stcd", stImgRReal.getStcd()).eq("chid", stImgRReal.getChid()); - stImgRRealService.saveOrUpdate(stImgRReal, updateWrapper); - } - } - } - catch (IOException e) - { - log.error("图像实时定时任务错误:", e.getMessage()); - } - } - - /** - * @description: 定时获取水库图像数据(历史) - * @param - * @return: void - * @auther: cxw - * @date: 2024-07-22, 周一, 13:55:45 - */ -// @Async -// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) - public void getSkImgHisData() { - Date now = new Date(); - System.out.println("图像历史定时任务,执行时间:" + sdf.format(now)); - // 获取水库站点编码历史图像表中站点最新数据时间 - List stcdLast = stImgRService.getStcdLastImgData(); - OkHttpClient client = OkHttpUtil.build(); - try { - if(CollectionUtils.isNotEmpty(stcdLast)){ - for (StImgR stImgR : stcdLast) { - Date stm = stImgR.getStm(); - Calendar calendar = Calendar.getInstance(); - // 默认40天前(接口最多40天),存在则加1小时(接口是按小时算且大于等于开始时间) - if(ObjectUtils.isEmpty(stm)){ - calendar.add(Calendar.DATE, -40); - } else { - calendar.setTime(stm); - calendar.add(Calendar.HOUR_OF_DAY, 1); - } - stm = calendar.getTime(); - Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskpichisRoute) - .post(new FormBody.Builder().add("stcd", stImgR.getStcd()) - .add("stm", sdfH.format(stm)) - .add("etm", sdfH.format(now)) - .build()) - .build()).execute(); - String respStr = resp.body().string(); - ObjectMapper om = new ObjectMapper(); - Map map = om.readValue(respStr, Map.class); - if ("400".equals(map.get("code").toString())) { - continue; - } - List list = (List)map.get("data"); - if (CollectionUtils.isNotEmpty(list)) { - List rlist = list.stream().map(map1 -> { - StImgR stImgRNew = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setDateFormat(sdf).convertValue(map1, StImgR.class); - // 手动设置对应属性 - if(ObjectUtils.isEmpty(stImgRNew.getChtm())){ - stImgRNew.setChtm(new Date()); - } - if(ObjectUtils.isEmpty(stImgRNew.getChid())){ - stImgRNew.setChid(map1.get("machineid").toString()); - } - if(ObjectUtils.isEmpty(stImgRNew.getImgPath())){ - stImgRNew.setImgPath(map1.get("url").toString()); - } - return stImgRNew; - }).collect(Collectors.toList()); - stImgRService.saveBatch(rlist); - } - } - } - } - catch (IOException e) - { - log.error("图像历史定时任务错误:", e.getMessage()); - } - } - -} +//// @PostConstruct +// public void getSkSqHisDataJcsk() { +// Date now = new Date(); +// System.out.println("荆楚水库水位定时任务,执行时间:" + sdf.format(now)); +// // 获取水库站点编码历史水情表中站点最新数据时间 +// List 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 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.stream().max(Comparator.comparing(StRsvrR::getTm)).get(); +// StRsvrRReal stRsvrRReal = new StRsvrRReal(); +// stRsvrRReal.setStcd(STRsvrR1.getStcd()); +// stRsvrRReal.setTm(STRsvrR1.getTm()); +// stRsvrRReal.setRz(STRsvrR1.getRz()); +// stRsvrRReal.setChtm(new Date()); +// UpdateWrapper updateWrapper = new UpdateWrapper<>(); +// updateWrapper.eq("stcd", stRsvrRReal.getStcd()); +// stRsvrRRealService.saveOrUpdate(stRsvrRReal, updateWrapper); +// messageCenterService.rzWarnMes(rlist); +// } +// } +// } +// } +// } +// catch (IOException e) +// { +// log.error("荆楚水库水位定时任务:", e.getMessage()); +// } +// } +// +// /** +// * @description: 定时获取水库图像数据(实时) +// * @param +// * @return: void +// * @auther: cxw +// * @date: 2024-07-22, 周一, 13:54:08 +// */ +//// @Async +//// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) +// public void getSkImgRealData() { +// Date now = new Date(); +// System.out.println("图像实时图像定时任务,执行时间:" + sdf.format(now)); +// // 获取水库站点编码 +// String sts = "[" + stStbprpBService.list(new QueryWrapper().eq("source", "SK")).stream().map(StStbprpB::getStcd).collect(Collectors.joining(",")) + "]"; +// OkHttpClient client = OkHttpUtil.build(); +// try { +// Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskpicrealstsRoute) +// .post(new FormBody.Builder().add("sts", sts).build()) +// .build()).execute(); +// String respStr = resp.body().string(); +// ObjectMapper om = new ObjectMapper(); +// Map map = om.readValue(respStr, Map.class); +// List list = (List)map.get("data"); +// if(CollectionUtils.isNotEmpty(list)){ +// for (Map map1 : list) { +// StImgRReal stImgRReal = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setDateFormat(sdf).convertValue(map1, StImgRReal.class); +// if(ObjectUtils.isEmpty(stImgRReal.getChtm())){ +// stImgRReal.setChtm(new Date()); +// } +// if(ObjectUtils.isEmpty(stImgRReal.getChid())){ +// stImgRReal.setChid(map1.get("machineid").toString()); +// } +// if(ObjectUtils.isEmpty(stImgRReal.getImgPath())){ +// stImgRReal.setImgPath(map1.get("url").toString()); +// } +// UpdateWrapper updateWrapper = new UpdateWrapper<>(); +// updateWrapper.eq("stcd", stImgRReal.getStcd()).eq("chid", stImgRReal.getChid()); +// stImgRRealService.saveOrUpdate(stImgRReal, updateWrapper); +// } +// } +// } +// catch (IOException e) +// { +// log.error("图像实时定时任务错误:", e.getMessage()); +// } +// } +// +// /** +// * @description: 定时获取水库图像数据(历史) +// * @param +// * @return: void +// * @auther: cxw +// * @date: 2024-07-22, 周一, 13:55:45 +// */ +//// @Async +//// @Scheduled(fixedRate = 5, timeUnit = TimeUnit.MINUTES) +// public void getSkImgHisData() { +// Date now = new Date(); +// System.out.println("图像历史定时任务,执行时间:" + sdf.format(now)); +// // 获取水库站点编码历史图像表中站点最新数据时间 +// List stcdLast = stImgRService.getStcdLastImgData(); +// OkHttpClient client = OkHttpUtil.build(); +// try { +// if(CollectionUtils.isNotEmpty(stcdLast)){ +// for (StImgR stImgR : stcdLast) { +// Date stm = stImgR.getStm(); +// Calendar calendar = Calendar.getInstance(); +// // 默认40天前(接口最多40天),存在则加1小时(接口是按小时算且大于等于开始时间) +// if(ObjectUtils.isEmpty(stm)){ +// calendar.add(Calendar.DATE, -40); +// } else { +// calendar.setTime(stm); +// calendar.add(Calendar.HOUR_OF_DAY, 1); +// } +// stm = calendar.getTime(); +// Response resp = client.newCall(new Request.Builder().url(owrsvrPath + hbskpichisRoute) +// .post(new FormBody.Builder().add("stcd", stImgR.getStcd()) +// .add("stm", sdfH.format(stm)) +// .add("etm", sdfH.format(now)) +// .build()) +// .build()).execute(); +// String respStr = resp.body().string(); +// ObjectMapper om = new ObjectMapper(); +// Map map = om.readValue(respStr, Map.class); +// if ("400".equals(map.get("code").toString())) { +// continue; +// } +// List list = (List)map.get("data"); +// if (CollectionUtils.isNotEmpty(list)) { +// List rlist = list.stream().map(map1 -> { +// StImgR stImgRNew = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false).setDateFormat(sdf).convertValue(map1, StImgR.class); +// // 手动设置对应属性 +// if(ObjectUtils.isEmpty(stImgRNew.getChtm())){ +// stImgRNew.setChtm(new Date()); +// } +// if(ObjectUtils.isEmpty(stImgRNew.getChid())){ +// stImgRNew.setChid(map1.get("machineid").toString()); +// } +// if(ObjectUtils.isEmpty(stImgRNew.getImgPath())){ +// stImgRNew.setImgPath(map1.get("url").toString()); +// } +// return stImgRNew; +// }).collect(Collectors.toList()); +// stImgRService.saveBatch(rlist); +// } +// } +// } +// } +// catch (IOException e) +// { +// log.error("图像历史定时任务错误:", e.getMessage()); +// } +// } +// +//}