package com.bfms.quartz.task; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.math.RoundingMode; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.LocalDateTime; import java.time.ZoneId; import java.time.ZonedDateTime; import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.Calendar; import java.util.Comparator; import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; import com.alibaba.fastjson2.JSON; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.util.UriComponents; import org.springframework.web.util.UriComponentsBuilder; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.bfms.common.core.domain.AjaxResult; import com.bfms.common.core.redis.RedisCache; import com.bfms.common.utils.DateUtils; import com.bfms.common.utils.StringUtils; import com.bfms.common.utils.http.HttpUtils; import com.bfms.system.domain.QxtFileData; import com.bfms.system.mapper.QxtFileDataMapper; /** * 定时任务调度测试 * * @author MET */ @Component("DMZNewTask") public class DMZNewTask { protected final Logger logger = LoggerFactory.getLogger(DMZTask.class); @Autowired private RedisCache redisCache; @Autowired private QxtFileDataMapper qxtFileDataMapper; private final String NX_RANGE = "&maxLat=28.6&minLat=27.78&minLon=111.628&maxLon=112.958"; public static void main(String[] args) { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.HOUR_OF_DAY, 1); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); calendar.add(Calendar.HOUR_OF_DAY, -8); // 当天0点时间 Date date = calendar.getTime(); System.out.print(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date)); } public static List getNowTimesStart() { Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); calendar.set(Calendar.HOUR_OF_DAY, 1); calendar.set(Calendar.MINUTE, 0); calendar.set(Calendar.SECOND, 0); // 当天0点时间 Date date = calendar.getTime(); System.out.print(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date)); return null; } /** * 宁乡小时实况降水逐小时 * @param params * @throws UnsupportedEncodingException * @throws ParseException */ public void listByTimeDurationForAreaCode(String params) throws UnsupportedEncodingException, ParseException { //宁乡24小时气温 JSONObject qiwenJson = new JSONObject(); Date dt0 = new Date(); Calendar rightNow0 = Calendar.getInstance(); rightNow0.setTime(dt0); rightNow0.add(Calendar.HOUR, -(8)); Date dt3=rightNow0.getTime(); Date dt4=dt3; dt4.setTime(dt4.getTime()+8*60*60*1000); String nowstr = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4); dt4.setTime(dt4.getTime()-24*60*60*1000); String starStr = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4); JSONArray jsDesCol = new JSONArray(); JSONObject e1 = new JSONObject(); e1.put("prop", "time"); e1.put("label", "时间"); JSONObject e2 = new JSONObject(); e2.put("prop", "temp"); e2.put("label", "气温℃"); jsDesCol.add(e1); jsDesCol.add(e2); qiwenJson.put("jsDesCol", jsDesCol); qiwenJson.put("title", starStr+"至"+nowstr+"宁乡市过去24小时气温时序"); JSONArray jstableDataArr = new JSONArray(); //宁乡24小时相对湿度 JSONObject qiwenJson_xdsd = new JSONObject(); Date dt0_xdsd = new Date(); Calendar rightNow0_xdsd = Calendar.getInstance(); rightNow0_xdsd.setTime(dt0_xdsd); rightNow0_xdsd.add(Calendar.HOUR, -(8)); Date dt3_xdsd=rightNow0_xdsd.getTime(); Date dt4_xdsd=dt3_xdsd; dt4_xdsd.setTime(dt4_xdsd.getTime()+8*60*60*1000); String nowstr_xdsd = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4_xdsd); dt4_xdsd.setTime(dt4_xdsd.getTime()-24*60*60*1000); String starStr_xdsd = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4_xdsd); JSONArray jsDesCol_xdsd = new JSONArray(); JSONObject e1_xdsd = new JSONObject(); e1_xdsd.put("prop", "time"); e1_xdsd.put("label", "时间"); JSONObject e2_xdsd = new JSONObject(); e2_xdsd.put("prop", "temp"); e2_xdsd.put("label", "土壤湿度(%)"); jsDesCol_xdsd.add(e1_xdsd); jsDesCol_xdsd.add(e2_xdsd); qiwenJson_xdsd.put("jsDesCol", jsDesCol_xdsd); qiwenJson_xdsd.put("title", starStr_xdsd+"至"+nowstr_xdsd+"宁乡市近24小时10cm土壤相对湿度"); JSONArray jstableDataArr_xdsd = new JSONArray(); //宁乡24小时相对湿度 JSONObject qiwenJson_zfl = new JSONObject(); Date dt0_zfl = new Date(); Calendar rightNow0_zfl = Calendar.getInstance(); rightNow0_zfl.setTime(dt0_zfl); rightNow0_zfl.add(Calendar.HOUR, -(8)); Date dt3_zfl=rightNow0_xdsd.getTime(); Date dt4_zfl=dt3_xdsd; dt4_zfl.setTime(dt4_zfl.getTime()+8*60*60*1000); String nowstr_zfl = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4_zfl); dt4_xdsd.setTime(dt4_xdsd.getTime()-24*60*60*1000); String starStr_zfl = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4_zfl); JSONArray jsDesCol_zfl = new JSONArray(); JSONObject e1_zfl = new JSONObject(); e1_zfl.put("prop", "time"); e1_zfl.put("label", "时间"); JSONObject e2_zfl = new JSONObject(); e2_zfl.put("prop", "temp"); e2_zfl.put("label", "蒸发量(mm)"); jsDesCol_zfl.add(e1_zfl); jsDesCol_zfl.add(e2_zfl); qiwenJson_zfl.put("jsDesCol", jsDesCol_zfl); qiwenJson_zfl.put("title", starStr_zfl+"至"+nowstr_zfl+"宁乡市近24小时10cm平均蒸发量"); JSONArray jstableDataArr_zfl = new JSONArray(); //查询最近24小时数据 ListtimeLineArr = new ArrayList(); for(int i=0;i<24;i++) { Date dt = new Date(); Calendar rightNow = Calendar.getInstance(); rightNow.setTime(dt); rightNow.add(Calendar.HOUR, -(i+8)); Date dt1=rightNow.getTime(); String nowTimeQuery = DateUtils.parseDateToStr("yyyy-MM-dd+HH:mm:ss", dt1); Date dt2=dt1; dt2.setTime(dt2.getTime()+8*60*60*1000); String redisTimeKey = DateUtils.parseDateToStr("yyyyMMddHH", dt2); String redisTimeLine = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", dt1); String redisTimeLine1 = DateUtils.parseDateToStr("yyyy年MM月dd日 HH时", dt1); String sendGet = HttpUtils.sendGet( "http://113.247.231.105:40039/data/hourdata/listByTimeDurationForAreaRange?shichang=1"+NX_RANGE+"&nowtime="+nowTimeQuery, null); JSONObject resultObject = JSONObject.parseObject(sendGet); JSONArray jsonArray = resultObject.getJSONArray("data"); //每个小时宁乡站点 平均气温 BigDecimal pingjunQW = new BigDecimal(0); JSONObject jstableData = new JSONObject(); //每个小时宁乡站点 平均相对湿度 BigDecimal pingjunQW_xdsd = new BigDecimal(0); JSONObject jstableData_xdsd = new JSONObject(); //每个小时宁乡站点 平均蒸发量 BigDecimal pingjunQW_zfl = new BigDecimal(0); JSONObject jstableData_zfl = new JSONObject(); if(jsonArray!=null) { JSONArray result = new JSONArray(); JSONArray resultQWSK = new JSONArray(); for (Object object : jsonArray) { JSONObject ob = (JSONObject) object; JSONObject newobj = new JSONObject(); String xianid = ob.getString("xianid"); newobj.put("stationIdC", ob.getString("dataid")); newobj.put("stationName",ob.getString("sname")); newobj.put("lon", ob.getString("lon")); newobj.put("lat", ob.getString("lat")); newobj.put("cnty", "431382".equals(xianid) ? "宁乡市" : "周边区县"); String string = new BigDecimal(ob.getString("pre1")).compareTo(new BigDecimal(8888))>=0?"0":ob.getString("pre1"); newobj.put("value", string); result.add(newobj); JSONObject newobj1 = new JSONObject(); newobj1.put("stationIdC", ob.getString("dataid")); newobj1.put("stationName",ob.getString("sname")); newobj1.put("lon", ob.getString("lon")); newobj1.put("lat", ob.getString("lat")); newobj1.put("cnty", "431382".equals(xianid) ? "宁乡市" : "周边区县"); String string1 = new BigDecimal(ob.getString("qw")).compareTo(new BigDecimal(8888))>=0?"0":ob.getString("qw"); newobj1.put("value", string1); resultQWSK.add(newobj1); BigDecimal qw = new BigDecimal( ob.getString("qw")); if(qw.compareTo(new BigDecimal(100))<0)pingjunQW=pingjunQW.add(new BigDecimal( ob.getString("qw"))); BigDecimal sdsd = new BigDecimal( ob.getString("sdsd")); if(sdsd.compareTo(new BigDecimal(100))<0)pingjunQW_xdsd = pingjunQW_xdsd.add(new BigDecimal( ob.getString("sdsd"))); BigDecimal zfl = new BigDecimal( ob.getString("zf")); if(zfl.compareTo(new BigDecimal(100))<0)pingjunQW_zfl = pingjunQW_zfl.add(new BigDecimal( ob.getString("sdsd"))); } redisCache.setCacheObject("NingXiang430182:rankOfStation1Hour:"+redisTimeKey, result); redisCache.setCacheObject("NingXiang430182:DMZQiWenSK:"+redisTimeKey, resultQWSK); timeLineArr.add(redisTimeLine); jstableData.put("temp", pingjunQW.divide(new BigDecimal(result.size()),3,RoundingMode.HALF_UP)); jstableData.put("time", redisTimeLine1); jstableData_xdsd.put("temp", pingjunQW_xdsd.divide(new BigDecimal(result.size()),3,RoundingMode.HALF_UP)); jstableData_xdsd.put("time", redisTimeLine1); jstableData_zfl.put("temp", pingjunQW_zfl.divide(new BigDecimal(result.size()),3,RoundingMode.HALF_UP)); jstableData_zfl.put("time", redisTimeLine1); jstableDataArr.add(jstableData); jstableDataArr_xdsd.add(jstableData_xdsd); jstableDataArr_zfl.add(jstableData_zfl); } //timeLineArr.add(redisTimeLine); } //组装温度 qiwenJson.put("jstableData", jstableDataArr); //组装相对湿度 qiwenJson_xdsd.put("jstableData", jstableDataArr_xdsd); //组装蒸发量 qiwenJson_zfl.put("jstableData", jstableDataArr_zfl); redisCache.setCacheObject("NingXiang430182:temperatureList", qiwenJson); redisCache.setCacheObject("NingXiang430182:humidityList", qiwenJson_xdsd); redisCache.setCacheObject("NingXiang430182:trsdList", qiwenJson_xdsd); redisCache.setCacheObject("NingXiang430182:zflList", qiwenJson_zfl); //组装气温通用时间轴 JSONObject qiWenTimeLine = new JSONObject(); qiWenTimeLine.put("mini", 0); qiWenTimeLine.put("step", 5); qiWenTimeLine.put("value", 0); Map qiWenTimeLine_marks_map = new HashMap(); //逐小时雨量时间小时轴组装 JSONObject RESULT = new JSONObject(); JSONObject slider0 = new JSONObject(); slider0.put("max", timeLineArr.size()-1); slider0.put("step", 2); slider0.put("value", 0); Mapmarks = new HashMap(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); int j = timeLineArr.size()-1; for(int i=0;itimeLineArr = new ArrayList(); for(int i=0;i<72;i++) { Date dt = new Date(); Calendar rightNow = Calendar.getInstance(); rightNow.setTime(dt); rightNow.add(Calendar.HOUR, -(i+8)); Date dt1=rightNow.getTime(); String nowTimeQuery = DateUtils.parseDateToStr("yyyy-MM-dd+HH:mm:ss", dt1); Date dt2=dt1; dt2.setTime(dt2.getTime()+8*60*60*1000); String redisTimeKey = DateUtils.parseDateToStr("yyyyMMddHH", dt2); String redisTimeLine = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", dt1); if(i%3==0) { String sendGet = HttpUtils.sendGet( "http://113.247.231.105:40039/data/hourdata/listByTimeDurationForAreaRange?shichang=1"+NX_RANGE+"&nowtime="+nowTimeQuery, null); JSONObject resultObject = JSONObject.parseObject(sendGet); JSONArray jsonArray = resultObject.getJSONArray("data"); if(jsonArray!=null) { JSONArray result = new JSONArray(); for (Object object : jsonArray) { JSONObject ob = (JSONObject) object; JSONObject newobj = new JSONObject(); String xianid = ob.getString("xianid"); newobj.put("stationIdC", ob.getString("dataid")); newobj.put("stationName",ob.getString("sname")); newobj.put("lon", ob.getString("lon")); newobj.put("lat", ob.getString("lat")); newobj.put("cnty", "431382".equals(xianid) ? "宁乡市" : "周边区县"); String string = new BigDecimal(ob.getString("pre3")).compareTo(new BigDecimal(8888))>=0?"0":ob.getString("pre3"); newobj.put("value",string); result.add(newobj); } redisCache.setCacheObject("NingXiang430182:rankOfStation3Hour:"+redisTimeKey, result); timeLineArr.add(redisTimeLine); } } } //逐小时雨量时间小时轴组装 JSONObject RESULT = new JSONObject(); JSONObject slider0 = new JSONObject(); slider0.put("max", timeLineArr.size()-1); slider0.put("step", 2); slider0.put("value", 0); Mapmarks = new HashMap(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); int j = timeLineArr.size()-1; for(int i=0;i ((JSONObject) obj).getBigDecimal("value")).reversed()); return AjaxResult.success("某地区气象站排名数据加载成功!", resultJSONObject); } /** * 获取水库降水预报 */ public void getRainfallVolumeForcast() throws ParseException { String redisKey = "NingXiang430182:reservoirListGIS"; JSONArray resultJSONObject = redisCache.getCacheObject(redisKey); JSONArray jstableData = new JSONArray(); for(int i=0;i vars = new HashMap<>(); // 取数据,取最近两个时间点的数据,容错任务时间差 for (int i = 0; i < 2; i++) { vars.put("sTime", utc.minusMinutes(i * 5 + 5).format(YMDHMS)); vars.put("eTime", utc.minusMinutes(i * 5).format(YMDHMS)); String url = UriComponentsBuilder.fromHttpUrl(apiUri).uriVariables(vars).encode().build().toString() + NX_RANGE; String sendGet = HttpUtils.sendGet(url, null); JSONObject parse = (JSONObject) JSONObject.parse(sendGet); JSONArray jsonArray = parse.getJSONArray("data"); JSONArray stationList = new JSONArray(); for (int j = 0; j < jsonArray.size(); j++) { JSONObject obj = (JSONObject) jsonArray.get(j); JSONObject stationData = new JSONObject(); stationData.put("stationIdC", obj.getString("sid")); stationData.put("stationName", obj.getString("sname")); stationData.put("lon", obj.getString("lon")); stationData.put("lat", obj.getString("lat")); stationData.put("value", obj.getString("pre")); stationData.put("cnty", "宁乡市"); stationList.add(stationData); } // 存储分钟级数据 redisCache.setCacheObject( ("NingXiang430182:rankOfStationLT_minutes:" + ctt.minusMinutes(i * 5).format(YMDHM_SLIM)), stationList, 3, TimeUnit.HOURS); } // 拼接原前端需要的时间轴结构。5分钟间隔,最近2个小时,即24个点 JSONObject timeline = new JSONObject(); timeline.put("step", 3); timeline.put("value", 0); timeline.put("max", 23); timeline.put("min", 0); timeline.put("value", 0); DateTimeFormatter MDHM_ZHS = DateTimeFormatter.ofPattern("MM月dd日 HH:mm"); Map timeline_marks = new LinkedHashMap<>(); int hour = 2, num = hour * 60 / 5; for (int i = num; i > 0; i--) { LocalDateTime sTime = ctt.minusMinutes(i * 5); LocalDateTime eTime = ctt.minusMinutes((i - 1) * 5); JSONObject markOBJ = new JSONObject(); markOBJ.put("des", "分钟级降水实况: " + sTime.format(MDHM_ZHS) + "-" + eTime.format(MDHM_ZHS)); markOBJ.put("rediskey", "NingXiang430182:rankOfStationLT_minutes:" + eTime.format(YMDHM_SLIM)); markOBJ.put("ts", eTime.format(YMDHMS)); markOBJ.put("nm", eTime.format(MDHM_ZHS)); timeline_marks.put(String.valueOf(num - i), markOBJ); } timeline.put("marks", timeline_marks); redisCache.setCacheObject("NingXiang430182:rankOfStationLT_minutes", timeline); } /** * DMZ 查询省市县三级指导产品列表对外 * @param params * @throws UnsupportedEncodingException * @throws ParseException */ public void getWenjian(String params) throws UnsupportedEncodingException, ParseException { String url = "http://113.247.231.105:40039/data/zdcp/listForWxchat?adminCodes=430182000000"; String sendGet = HttpUtils.sendGet(url, null); JSONObject parse = (JSONObject) JSONObject.parse(sendGet); JSONArray jsonArray = parse.getJSONArray("data"); for(int i=0;i=0) { if(fileOBJ.getString("fileQufen").indexOf("专题")>=0) { categoryids="NXQXZTBG"; }else if(fileOBJ.getString("fileQufen").indexOf("决策")>=0) { categoryids="NXJCQXFWCP"; }else if(fileOBJ.getString("fileQufen").indexOf("农")>=0) { categoryids="NXQXWNFWCP"; }else if(fileOBJ.getString("fileQufen").indexOf("专业")>=0) { categoryids="NXZYQXFWCP"; }else { categoryids="NXQXZTBG"; } }else if(fileOBJ.getString("groupName").indexOf("湖南省")>=0) { if(fileOBJ.getString("fileQufen").indexOf("月")>=0) { categoryids="HNYB"; }else if(fileOBJ.getString("fileQufen").indexOf("季")>=0) { categoryids="HNJB"; }else if(fileOBJ.getString("fileQufen").indexOf("年")>=0) { categoryids="HNNB"; }else if(fileOBJ.getString("fileQufen").indexOf("中期")>=0) { categoryids="HNZQTQYB"; }else if(fileOBJ.getString("fileQufen").indexOf("延伸")>=0) { categoryids="QXYSYB"; }else if(fileOBJ.getString("fileQufen").indexOf("重大")>=0) { categoryids="HNZDQXZB"; }else { categoryids="HNYB"; } }else if(fileOBJ.getString("groupName").indexOf("湖南省")>=0 || fileOBJ.getString("groupName").indexOf("长沙市")>=0) { if(fileOBJ.getString("fileQufen").indexOf("专题")>=0) { categoryids="CSQXZTBG"; }else if(fileOBJ.getString("fileQufen").indexOf("天气")>=0) { categoryids="CSYZTQFW"; }else if(fileOBJ.getString("fileQufen").indexOf("年")>=0) { categoryids="HNNB"; }else if(fileOBJ.getString("fileQufen").indexOf("重大")>=0) { categoryids="CSZDQXZB"; }else if(fileOBJ.getString("fileQufen").indexOf("防汛")>=0) { categoryids="CSFXKHQXXX"; } else { categoryids="CSQXZTBG"; } } qxtFileData.setCategoryids(categoryids); qxtFileData.setCateid("word"); qxtFileData.setSts(1); qxtFileData.setFilenm(fileOBJ.getString("fileFname")); qxtFileData.setIspdf(1); qxtFileData.setDownurl(fileOBJ.getString("fileFileurl")); qxtFileData.setAreacode(fileOBJ.getString("fileGroupid")); qxtFileDataMapper.insertQxtFileData(qxtFileData); } } } /** * 通过DMZ 经纬度查询雨量信息查询流域面雨量 * @param params * @throws UnsupportedEncodingException * @throws ParseException */ public void getLiuYuMianYuLiang(String params) throws UnsupportedEncodingException, ParseException { JSONObject rainArea = redisCache.getCacheObject("NingXiang430182:rankOfRainfallArea:data"); if(rainArea!=null) { JSONArray jsonArr = rainArea.getJSONArray("forecastAreaRainOfBasinList"); for(int i=0;i