DMZNewTask.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858
  1. package com.bfms.quartz.task;
  2. import java.io.UnsupportedEncodingException;
  3. import java.math.BigDecimal;
  4. import java.math.RoundingMode;
  5. import java.text.ParseException;
  6. import java.text.SimpleDateFormat;
  7. import java.time.LocalDateTime;
  8. import java.time.ZoneId;
  9. import java.time.ZonedDateTime;
  10. import java.time.format.DateTimeFormatter;
  11. import java.util.ArrayList;
  12. import java.util.Calendar;
  13. import java.util.Comparator;
  14. import java.util.Date;
  15. import java.util.HashMap;
  16. import java.util.LinkedHashMap;
  17. import java.util.List;
  18. import java.util.Map;
  19. import java.util.concurrent.TimeUnit;
  20. import com.alibaba.fastjson2.JSON;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.stereotype.Component;
  25. import org.springframework.web.bind.annotation.PostMapping;
  26. import org.springframework.web.bind.annotation.RequestBody;
  27. import org.springframework.web.util.UriComponents;
  28. import org.springframework.web.util.UriComponentsBuilder;
  29. import com.alibaba.fastjson2.JSONArray;
  30. import com.alibaba.fastjson2.JSONObject;
  31. import com.bfms.common.core.domain.AjaxResult;
  32. import com.bfms.common.core.redis.RedisCache;
  33. import com.bfms.common.utils.DateUtils;
  34. import com.bfms.common.utils.StringUtils;
  35. import com.bfms.common.utils.http.HttpUtils;
  36. import com.bfms.system.domain.QxtFileData;
  37. import com.bfms.system.mapper.QxtFileDataMapper;
  38. /**
  39. * 定时任务调度测试
  40. *
  41. * @author MET
  42. */
  43. @Component("DMZNewTask")
  44. public class DMZNewTask
  45. {
  46. protected final Logger logger = LoggerFactory.getLogger(DMZTask.class);
  47. @Autowired
  48. private RedisCache redisCache;
  49. @Autowired
  50. private QxtFileDataMapper qxtFileDataMapper;
  51. private final String NX_RANGE = "&maxLat=28.6&minLat=27.78&minLon=111.628&maxLon=112.958";
  52. public static void main(String[] args) {
  53. Calendar calendar = Calendar.getInstance();
  54. calendar.setTime(new Date());
  55. calendar.set(Calendar.HOUR_OF_DAY, 1);
  56. calendar.set(Calendar.MINUTE, 0);
  57. calendar.set(Calendar.SECOND, 0);
  58. calendar.add(Calendar.HOUR_OF_DAY, -8);
  59. // 当天0点时间
  60. Date date = calendar.getTime();
  61. System.out.print(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date));
  62. }
  63. public static List<String> getNowTimesStart() {
  64. Calendar calendar = Calendar.getInstance();
  65. calendar.setTime(new Date());
  66. calendar.set(Calendar.HOUR_OF_DAY, 1);
  67. calendar.set(Calendar.MINUTE, 0);
  68. calendar.set(Calendar.SECOND, 0);
  69. // 当天0点时间
  70. Date date = calendar.getTime();
  71. System.out.print(DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS, date));
  72. return null;
  73. }
  74. /**
  75. * 宁乡小时实况降水逐小时
  76. * @param params
  77. * @throws UnsupportedEncodingException
  78. * @throws ParseException
  79. */
  80. public void listByTimeDurationForAreaCode(String params) throws UnsupportedEncodingException, ParseException
  81. {
  82. //宁乡24小时气温
  83. JSONObject qiwenJson = new JSONObject();
  84. Date dt0 = new Date();
  85. Calendar rightNow0 = Calendar.getInstance();
  86. rightNow0.setTime(dt0);
  87. rightNow0.add(Calendar.HOUR, -(8));
  88. Date dt3=rightNow0.getTime();
  89. Date dt4=dt3;
  90. dt4.setTime(dt4.getTime()+8*60*60*1000);
  91. String nowstr = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4);
  92. dt4.setTime(dt4.getTime()-24*60*60*1000);
  93. String starStr = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4);
  94. JSONArray jsDesCol = new JSONArray();
  95. JSONObject e1 = new JSONObject();
  96. e1.put("prop", "time");
  97. e1.put("label", "时间");
  98. JSONObject e2 = new JSONObject();
  99. e2.put("prop", "temp");
  100. e2.put("label", "气温℃");
  101. jsDesCol.add(e1);
  102. jsDesCol.add(e2);
  103. qiwenJson.put("jsDesCol", jsDesCol);
  104. qiwenJson.put("title", starStr+"至"+nowstr+"宁乡市过去24小时气温时序");
  105. JSONArray jstableDataArr = new JSONArray();
  106. //宁乡24小时相对湿度
  107. JSONObject qiwenJson_xdsd = new JSONObject();
  108. Date dt0_xdsd = new Date();
  109. Calendar rightNow0_xdsd = Calendar.getInstance();
  110. rightNow0_xdsd.setTime(dt0_xdsd);
  111. rightNow0_xdsd.add(Calendar.HOUR, -(8));
  112. Date dt3_xdsd=rightNow0_xdsd.getTime();
  113. Date dt4_xdsd=dt3_xdsd;
  114. dt4_xdsd.setTime(dt4_xdsd.getTime()+8*60*60*1000);
  115. String nowstr_xdsd = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4_xdsd);
  116. dt4_xdsd.setTime(dt4_xdsd.getTime()-24*60*60*1000);
  117. String starStr_xdsd = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4_xdsd);
  118. JSONArray jsDesCol_xdsd = new JSONArray();
  119. JSONObject e1_xdsd = new JSONObject();
  120. e1_xdsd.put("prop", "time");
  121. e1_xdsd.put("label", "时间");
  122. JSONObject e2_xdsd = new JSONObject();
  123. e2_xdsd.put("prop", "temp");
  124. e2_xdsd.put("label", "土壤湿度(%)");
  125. jsDesCol_xdsd.add(e1_xdsd);
  126. jsDesCol_xdsd.add(e2_xdsd);
  127. qiwenJson_xdsd.put("jsDesCol", jsDesCol_xdsd);
  128. qiwenJson_xdsd.put("title", starStr_xdsd+"至"+nowstr_xdsd+"宁乡市近24小时10cm土壤相对湿度");
  129. JSONArray jstableDataArr_xdsd = new JSONArray();
  130. //宁乡24小时相对湿度
  131. JSONObject qiwenJson_zfl = new JSONObject();
  132. Date dt0_zfl = new Date();
  133. Calendar rightNow0_zfl = Calendar.getInstance();
  134. rightNow0_zfl.setTime(dt0_zfl);
  135. rightNow0_zfl.add(Calendar.HOUR, -(8));
  136. Date dt3_zfl=rightNow0_xdsd.getTime();
  137. Date dt4_zfl=dt3_xdsd;
  138. dt4_zfl.setTime(dt4_zfl.getTime()+8*60*60*1000);
  139. String nowstr_zfl = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4_zfl);
  140. dt4_xdsd.setTime(dt4_xdsd.getTime()-24*60*60*1000);
  141. String starStr_zfl = DateUtils.parseDateToStr("yyyy年MM月dd日HH", dt4_zfl);
  142. JSONArray jsDesCol_zfl = new JSONArray();
  143. JSONObject e1_zfl = new JSONObject();
  144. e1_zfl.put("prop", "time");
  145. e1_zfl.put("label", "时间");
  146. JSONObject e2_zfl = new JSONObject();
  147. e2_zfl.put("prop", "temp");
  148. e2_zfl.put("label", "蒸发量(mm)");
  149. jsDesCol_zfl.add(e1_zfl);
  150. jsDesCol_zfl.add(e2_zfl);
  151. qiwenJson_zfl.put("jsDesCol", jsDesCol_zfl);
  152. qiwenJson_zfl.put("title", starStr_zfl+"至"+nowstr_zfl+"宁乡市近24小时10cm平均蒸发量");
  153. JSONArray jstableDataArr_zfl = new JSONArray();
  154. //查询最近24小时数据
  155. List<String>timeLineArr = new ArrayList<String>();
  156. for(int i=0;i<24;i++) {
  157. Date dt = new Date();
  158. Calendar rightNow = Calendar.getInstance();
  159. rightNow.setTime(dt);
  160. rightNow.add(Calendar.HOUR, -(i+8));
  161. Date dt1=rightNow.getTime();
  162. String nowTimeQuery = DateUtils.parseDateToStr("yyyy-MM-dd+HH:mm:ss", dt1);
  163. Date dt2=dt1;
  164. dt2.setTime(dt2.getTime()+8*60*60*1000);
  165. String redisTimeKey = DateUtils.parseDateToStr("yyyyMMddHH", dt2);
  166. String redisTimeLine = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", dt1);
  167. String redisTimeLine1 = DateUtils.parseDateToStr("yyyy年MM月dd日 HH时", dt1);
  168. String sendGet = HttpUtils.sendGet( "http://113.247.231.105:40039/data/hourdata/listByTimeDurationForAreaRange?shichang=1"+NX_RANGE+"&nowtime="+nowTimeQuery, null);
  169. JSONObject resultObject = JSONObject.parseObject(sendGet);
  170. JSONArray jsonArray = resultObject.getJSONArray("data");
  171. //每个小时宁乡站点 平均气温
  172. BigDecimal pingjunQW = new BigDecimal(0);
  173. JSONObject jstableData = new JSONObject();
  174. //每个小时宁乡站点 平均相对湿度
  175. BigDecimal pingjunQW_xdsd = new BigDecimal(0);
  176. JSONObject jstableData_xdsd = new JSONObject();
  177. //每个小时宁乡站点 平均蒸发量
  178. BigDecimal pingjunQW_zfl = new BigDecimal(0);
  179. JSONObject jstableData_zfl = new JSONObject();
  180. if(jsonArray!=null) {
  181. JSONArray result = new JSONArray();
  182. JSONArray resultQWSK = new JSONArray();
  183. for (Object object : jsonArray) {
  184. JSONObject ob = (JSONObject) object;
  185. JSONObject newobj = new JSONObject();
  186. String xianid = ob.getString("xianid");
  187. newobj.put("stationIdC", ob.getString("dataid"));
  188. newobj.put("stationName",ob.getString("sname"));
  189. newobj.put("lon", ob.getString("lon"));
  190. newobj.put("lat", ob.getString("lat"));
  191. newobj.put("cnty", "431382".equals(xianid) ? "宁乡市" : "周边区县");
  192. String string = new BigDecimal(ob.getString("pre1")).compareTo(new BigDecimal(8888))>=0?"0":ob.getString("pre1");
  193. newobj.put("value", string);
  194. result.add(newobj);
  195. JSONObject newobj1 = new JSONObject();
  196. newobj1.put("stationIdC", ob.getString("dataid"));
  197. newobj1.put("stationName",ob.getString("sname"));
  198. newobj1.put("lon", ob.getString("lon"));
  199. newobj1.put("lat", ob.getString("lat"));
  200. newobj1.put("cnty", "431382".equals(xianid) ? "宁乡市" : "周边区县");
  201. String string1 = new BigDecimal(ob.getString("qw")).compareTo(new BigDecimal(8888))>=0?"0":ob.getString("qw");
  202. newobj1.put("value", string1);
  203. resultQWSK.add(newobj1);
  204. BigDecimal qw = new BigDecimal( ob.getString("qw"));
  205. if(qw.compareTo(new BigDecimal(100))<0)pingjunQW=pingjunQW.add(new BigDecimal( ob.getString("qw")));
  206. BigDecimal sdsd = new BigDecimal( ob.getString("sdsd"));
  207. if(sdsd.compareTo(new BigDecimal(100))<0)pingjunQW_xdsd = pingjunQW_xdsd.add(new BigDecimal( ob.getString("sdsd")));
  208. BigDecimal zfl = new BigDecimal( ob.getString("zf"));
  209. if(zfl.compareTo(new BigDecimal(100))<0)pingjunQW_zfl = pingjunQW_zfl.add(new BigDecimal( ob.getString("sdsd")));
  210. }
  211. redisCache.setCacheObject("NingXiang430182:rankOfStation1Hour:"+redisTimeKey, result);
  212. redisCache.setCacheObject("NingXiang430182:DMZQiWenSK:"+redisTimeKey, resultQWSK);
  213. timeLineArr.add(redisTimeLine);
  214. jstableData.put("temp", pingjunQW.divide(new BigDecimal(result.size()),3,RoundingMode.HALF_UP));
  215. jstableData.put("time", redisTimeLine1);
  216. jstableData_xdsd.put("temp", pingjunQW_xdsd.divide(new BigDecimal(result.size()),3,RoundingMode.HALF_UP));
  217. jstableData_xdsd.put("time", redisTimeLine1);
  218. jstableData_zfl.put("temp", pingjunQW_zfl.divide(new BigDecimal(result.size()),3,RoundingMode.HALF_UP));
  219. jstableData_zfl.put("time", redisTimeLine1);
  220. jstableDataArr.add(jstableData);
  221. jstableDataArr_xdsd.add(jstableData_xdsd);
  222. jstableDataArr_zfl.add(jstableData_zfl);
  223. }
  224. //timeLineArr.add(redisTimeLine);
  225. }
  226. //组装温度
  227. qiwenJson.put("jstableData", jstableDataArr);
  228. //组装相对湿度
  229. qiwenJson_xdsd.put("jstableData", jstableDataArr_xdsd);
  230. //组装蒸发量
  231. qiwenJson_zfl.put("jstableData", jstableDataArr_zfl);
  232. redisCache.setCacheObject("NingXiang430182:temperatureList", qiwenJson);
  233. redisCache.setCacheObject("NingXiang430182:humidityList", qiwenJson_xdsd);
  234. redisCache.setCacheObject("NingXiang430182:trsdList", qiwenJson_xdsd);
  235. redisCache.setCacheObject("NingXiang430182:zflList", qiwenJson_zfl);
  236. //组装气温通用时间轴
  237. JSONObject qiWenTimeLine = new JSONObject();
  238. qiWenTimeLine.put("mini", 0);
  239. qiWenTimeLine.put("step", 5);
  240. qiWenTimeLine.put("value", 0);
  241. Map<String,JSONObject> qiWenTimeLine_marks_map = new HashMap<String, JSONObject>();
  242. //逐小时雨量时间小时轴组装
  243. JSONObject RESULT = new JSONObject();
  244. JSONObject slider0 = new JSONObject();
  245. slider0.put("max", timeLineArr.size()-1);
  246. slider0.put("step", 2);
  247. slider0.put("value", 0);
  248. Map<String,JSONObject>marks = new HashMap<String, JSONObject>();
  249. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  250. int j = timeLineArr.size()-1;
  251. for(int i=0;i<timeLineArr.size();i++) {
  252. String timestring = timeLineArr.get(i);
  253. Date a = dateFormat.parse(timestring);
  254. String entd = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH1, a);
  255. String nm = DateUtils.parseDateToStr(DateUtils.DDHH, a);
  256. String rediskey = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, a);
  257. a.setTime(a.getTime() - 60*60*1000);
  258. String std = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH1, a);
  259. JSONObject jsonObj = new JSONObject();
  260. jsonObj.put("des", "逐小时降水实况:"+std+"-"+entd);
  261. jsonObj.put("ts", timestring);
  262. jsonObj.put("nm", nm);
  263. jsonObj.put("rediskey", "NingXiang430182:rankOfStation1Hour:"+rediskey);
  264. marks.put(j+"", jsonObj);
  265. JSONObject jsonObjQWSK = new JSONObject();
  266. jsonObjQWSK.put("des", "逐小时气温实况:"+std+"-"+entd);
  267. jsonObjQWSK.put("ts", timestring);
  268. jsonObjQWSK.put("nm", nm);
  269. jsonObjQWSK.put("rediskey", "NingXiang430182:DMZQiWenSK:"+rediskey);
  270. qiWenTimeLine_marks_map.put(j+"", jsonObjQWSK);
  271. j--;
  272. }
  273. slider0.put("marks", marks);
  274. RESULT.put("slider0", slider0);
  275. //存储小时降雨量时间轴
  276. redisCache.setCacheObject("NingXiang430182:rankOfStationLT_hour", slider0);
  277. qiWenTimeLine.put("marks", qiWenTimeLine_marks_map);
  278. qiWenTimeLine.put("max", timeLineArr.size()-1);
  279. qiWenTimeLine.put("sebiao", JSONObject.parse("{\"data\":[{\"title\":\"40\",\"colr\":\"rgb(109, 2, 22)\"},{\"title\":\"35\",\"colr\":\"rgb(169, 3, 17)\"},{\"title\":\"30\",\"colr\":\"rgb(208, 36, 13)\"},{\"title\":\"25\",\"colr\":\"rgb(214, 68, 18)\"},{\"title\":\"20\",\"colr\":\"rgb(238, 101, 23)\"},{\"title\":\"15\",\"colr\":\"rgb(241, 133, 9)\"},{\"title\":\"10\",\"colr\":\"rgb(247, 181, 45)\"},{\"title\":\"5\",\"colr\":\"rgb(233, 219, 112)\"},{\"title\":\"0\",\"colr\":\"rgb(153, 231, 174)\"},{\"title\":\"-2\",\"colr\":\"rgb(151, 214, 195)\"}],\"title\":\"气温(℃)\"}"));
  280. //存储小时气温时间轴
  281. redisCache.setCacheObject("NingXiang430182:DMZQiWenSK:LatestData", qiWenTimeLine);
  282. }
  283. /**
  284. * 宁乡小时实况降水逐3小时
  285. * @param params
  286. * @throws UnsupportedEncodingException
  287. * @throws ParseException
  288. */
  289. public void listByTimeDurationForAreaCode3(String params) throws UnsupportedEncodingException, ParseException
  290. {
  291. JSONArray jstableDataArr = new JSONArray();
  292. //查询最近24小时数据
  293. List<String>timeLineArr = new ArrayList<String>();
  294. for(int i=0;i<72;i++) {
  295. Date dt = new Date();
  296. Calendar rightNow = Calendar.getInstance();
  297. rightNow.setTime(dt);
  298. rightNow.add(Calendar.HOUR, -(i+8));
  299. Date dt1=rightNow.getTime();
  300. String nowTimeQuery = DateUtils.parseDateToStr("yyyy-MM-dd+HH:mm:ss", dt1);
  301. Date dt2=dt1;
  302. dt2.setTime(dt2.getTime()+8*60*60*1000);
  303. String redisTimeKey = DateUtils.parseDateToStr("yyyyMMddHH", dt2);
  304. String redisTimeLine = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", dt1);
  305. if(i%3==0) {
  306. String sendGet = HttpUtils.sendGet( "http://113.247.231.105:40039/data/hourdata/listByTimeDurationForAreaRange?shichang=1"+NX_RANGE+"&nowtime="+nowTimeQuery, null);
  307. JSONObject resultObject = JSONObject.parseObject(sendGet);
  308. JSONArray jsonArray = resultObject.getJSONArray("data");
  309. if(jsonArray!=null) {
  310. JSONArray result = new JSONArray();
  311. for (Object object : jsonArray) {
  312. JSONObject ob = (JSONObject) object;
  313. JSONObject newobj = new JSONObject();
  314. String xianid = ob.getString("xianid");
  315. newobj.put("stationIdC", ob.getString("dataid"));
  316. newobj.put("stationName",ob.getString("sname"));
  317. newobj.put("lon", ob.getString("lon"));
  318. newobj.put("lat", ob.getString("lat"));
  319. newobj.put("cnty", "431382".equals(xianid) ? "宁乡市" : "周边区县");
  320. String string = new BigDecimal(ob.getString("pre3")).compareTo(new BigDecimal(8888))>=0?"0":ob.getString("pre3");
  321. newobj.put("value",string);
  322. result.add(newobj);
  323. }
  324. redisCache.setCacheObject("NingXiang430182:rankOfStation3Hour:"+redisTimeKey, result);
  325. timeLineArr.add(redisTimeLine);
  326. }
  327. }
  328. }
  329. //逐小时雨量时间小时轴组装
  330. JSONObject RESULT = new JSONObject();
  331. JSONObject slider0 = new JSONObject();
  332. slider0.put("max", timeLineArr.size()-1);
  333. slider0.put("step", 2);
  334. slider0.put("value", 0);
  335. Map<String,JSONObject>marks = new HashMap<String, JSONObject>();
  336. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  337. int j = timeLineArr.size()-1;
  338. for(int i=0;i<timeLineArr.size();i++) {
  339. JSONObject jsonObj = new JSONObject();
  340. String timestring = timeLineArr.get(i);
  341. Date a = dateFormat.parse(timestring);
  342. String entd = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH1, a);
  343. String nm = DateUtils.parseDateToStr(DateUtils.DDHH, a);
  344. String rediskey = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, a);
  345. a.setTime(a.getTime() - 180*60*1000);
  346. String std = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH1, a);
  347. jsonObj.put("des", "逐3小时降水实况:"+std+"-"+entd);
  348. jsonObj.put("ts", timestring);
  349. jsonObj.put("nm", nm);
  350. jsonObj.put("rediskey", "NingXiang430182:rankOfStation3Hour:"+rediskey);
  351. marks.put(j+"", jsonObj);
  352. j--;
  353. }
  354. slider0.put("marks", marks);
  355. RESULT.put("slider0", slider0);
  356. //存储小时降雨量时间轴
  357. redisCache.setCacheObject("NingXiang430182:rankOfStationLT_3hour", slider0);
  358. }
  359. /**
  360. * 天气预报
  361. * @param params
  362. * @throws UnsupportedEncodingException
  363. * @throws ParseException
  364. */
  365. public void listAreaWeather(String params) throws UnsupportedEncodingException, ParseException
  366. {
  367. String sendGet = HttpUtils.sendGet( "http://113.247.231.105:40039/data/cityyb/listByAreaCodeForNew?adminCodes=430182000000", null);
  368. JSONObject resultObject = JSONObject.parseObject(sendGet);
  369. JSONArray jsonArray = resultObject.getJSONArray("data");
  370. JSONArray resultARR = new JSONArray();
  371. for(int i=0;i<jsonArray.size();i++) {
  372. JSONObject RES = new JSONObject();
  373. JSONObject OBJ = (JSONObject) jsonArray.get(i);
  374. Date ybtime = OBJ.getDate("ybtime");
  375. RES.put("temp", (OBJ.getString("temmin")+" ~ "+OBJ.getString("temmax")));
  376. RES.put("wind", (OBJ.getString("fengxiang")));
  377. RES.put("type", (OBJ.getString("tianqi1")));
  378. RES.put("day", (DateUtils.parseDateToStr(DateUtils.MM_DD, ybtime)));
  379. RES.put("code", StringUtils.getPinYin(OBJ.getString("tianqi1")));
  380. resultARR.add(RES);
  381. }
  382. JSONObject RESULT = new JSONObject();
  383. RESULT.put("area", "NingXiang");
  384. RESULT.put("today", "NingXiang");
  385. RESULT.put("barTitle", "NingXiang");
  386. RESULT.put("data", resultARR);
  387. //存储天气信息
  388. redisCache.setCacheObject("NingXiang430182:Weather", RESULT);
  389. }
  390. /**
  391. * 实况统计气温列表
  392. *
  393. * @param OBJ
  394. * @return
  395. */
  396. @PostMapping(value = "/temperatureList")
  397. public AjaxResult temperatureList(@RequestBody JSONObject OBJ) {
  398. try {
  399. String redisKey = "NingXiang430182:temperatureList";
  400. JSONObject resultJSONObject = redisCache.getCacheObject(redisKey);
  401. if (resultJSONObject == null) {
  402. resultJSONObject = JSONObject.parseObject("{\"jsDesCol\":[{\"prop\":\"time\",\"label\":\"时间\"},{\"prop\":\"temp\",\"label\":\"气温℃\"}],\"title\":\"过去24小时平均气温\",\"jstableData\":[]}");
  403. }
  404. return AjaxResult.success("实况统计气温列表数据加载成功!", resultJSONObject);
  405. } catch (Exception e) {
  406. return AjaxResult.error("暂无数据!");
  407. }
  408. }
  409. /**
  410. * 【实况统计】某地区气象站排名
  411. *
  412. * @param OBJ
  413. * @return
  414. * @throws ParseException
  415. */
  416. @PostMapping(value = "/rankOfStation")
  417. public AjaxResult rankOfStation(@RequestBody JSONObject OBJ) throws ParseException {
  418. JSONArray resultJSONObject = null;
  419. try {
  420. String redisKey = "NingXiang430182:rankOfStation:";
  421. String time = OBJ.getString("time");
  422. String ranktype = OBJ.getString("ranktype");
  423. if (ranktype.equals("0")) {
  424. redisKey += time;
  425. } else if (ranktype.equals("1")) {
  426. redisKey += time;
  427. } else if (ranktype.equals("2")) {
  428. redisKey += time;
  429. }
  430. resultJSONObject = redisCache.getCacheObject(time);
  431. if (resultJSONObject == null) {
  432. return AjaxResult.success("暂无数据!");
  433. /*
  434. * String res = HttpUtils.sendGet(OBJ.getString("uri"));
  435. * if(StringUtils.isEmpty(res))return AjaxResult.error(999," 某地区流域雨面量排名数据失败!");
  436. * resultJSONObject= JSONObject.parseObject(res);
  437. * redisCache.setCacheObject(redisKey,resultJSONObject);
  438. */
  439. }
  440. } catch (Exception e) {
  441. return AjaxResult.success("暂无数据!");
  442. }
  443. resultJSONObject.sort(Comparator.comparing(obj -> ((JSONObject) obj).getBigDecimal("value")).reversed());
  444. return AjaxResult.success("某地区气象站排名数据加载成功!", resultJSONObject);
  445. }
  446. /**
  447. * 获取水库降水预报
  448. */
  449. public void getRainfallVolumeForcast() throws ParseException {
  450. String redisKey = "NingXiang430182:reservoirListGIS";
  451. JSONArray resultJSONObject = redisCache.getCacheObject(redisKey);
  452. JSONArray jstableData = new JSONArray();
  453. for(int i=0;i<resultJSONObject.size();i++) {
  454. JSONObject sk = resultJSONObject.getJSONObject(i);
  455. JSONArray jsonArray = sk.getJSONArray("latlng");
  456. String url = "http://113.247.231.105:40039/data/grid/findGridYBListAll";
  457. JSONObject OBJ = new JSONObject();
  458. OBJ.put("skmc",sk.getString("nm"));
  459. OBJ.put("propId",sk.getString("id"));
  460. String sendGet = HttpUtils.sendGet(url, "lon="+jsonArray.getString(0)+"&lat="+jsonArray.getString(1)+"&count=240");
  461. JSONArray parse = JSONArray.parse(sendGet);
  462. //System.out.print(parse);
  463. for(int j=0;j<parse.size();j++) {
  464. JSONObject object = (JSONObject)parse.get(j);
  465. String time = object.getString("time").substring(0, 8);
  466. redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:SK:"+sk.getString("nm")+":"+time, object.getString("pre"));
  467. redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:SK:"+sk.getString("nm")+":"+object.getString("time"), object.getString("pre"));
  468. Date timeNow = new Date();
  469. SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
  470. Date dataTime = dateFormat.parse(object.getString("time"));
  471. long hour = this.getDiffMinutes(dataTime,timeNow);
  472. if(hour == 0 || hour == 1|| hour == 2){
  473. OBJ.put("hour1",object.getString("pre"));
  474. }
  475. if(hour == 3||hour == 4||hour == 5){
  476. OBJ.put("hour3",object.getString("pre"));
  477. }
  478. if(hour == 6||hour == 7||hour == 8||hour == 9||hour == 10||hour == 11){
  479. OBJ.put("hour6",object.getString("pre"));
  480. }
  481. if(hour == 12||hour == 13||hour == 14||hour == 15||hour == 16){
  482. OBJ.put("hour12",object.getString("pre"));
  483. }
  484. }
  485. jstableData.add(OBJ);
  486. }
  487. //拼装水库预报降水
  488. JSONArray jsDesCol = JSON.parseArray("[{\"prop\":\"skmc\",\"label\":\"水库名称\"},{\"prop\":\"hour1\",\"label\":\"未来1小时\"},{\"prop\":\"hour3\",\"label\":\"未来3小时\"},{\"prop\":\"hour6\",\"label\":\"未来6小时\"},{\"prop\":\"hour12\",\"label\":\"未来12小时\"}]");
  489. JSONObject RES = new JSONObject();
  490. RES.put("jsDesCol",jsDesCol);
  491. RES.put("jstableData",jstableData);
  492. RES.put("title",DateUtils.dateTimeNow(DateUtils.YYYYMMDDHH1)+"水库"+"未来1小时,3小时,6小时,12小时降水预报.单位(mm)");
  493. redisCache.setCacheObject("NingXiang430182:rainfallVolumeForcast:14",RES);
  494. }
  495. private long getDiffMinutes( Date date1, Date date2){
  496. long nd = 1000 * 24 * 60 * 60;//每天毫秒数
  497. long nh = 1000 * 60 * 60;//每小时毫秒数
  498. long nm = 1000 * 60;//每分钟毫秒数
  499. long diff = date1.getTime() - date2.getTime(); // 获得两个时间的毫秒时间差异
  500. long day = diff / nd; // 计算差多少天
  501. long hour = diff % nd / nh; // 计算差多少小时
  502. long min = diff % nd % nh / nm; // 计算差多少分钟
  503. return hour ;
  504. }
  505. /**
  506. * 分钟级降水
  507. *
  508. * @param params
  509. * @throws UnsupportedEncodingException
  510. * @throws ParseException
  511. */
  512. public void listYBMinutes(String params) throws UnsupportedEncodingException, ParseException {
  513. ZoneId ZONE_CTT = ZoneId.of("Asia/Shanghai");
  514. ZoneId ZONE_UTC = ZoneId.of("UTC");
  515. DateTimeFormatter YMDHMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
  516. DateTimeFormatter YMDHM_SLIM = DateTimeFormatter.ofPattern("yyyyMMddHHmm");
  517. LocalDateTime now = LocalDateTime.now();
  518. LocalDateTime ctt = now.minusMinutes(now.getMinute() % 5).withSecond(0).withNano(0);
  519. LocalDateTime utc = ZonedDateTime.of(ctt, ZONE_CTT).withZoneSameInstant(ZONE_UTC).toLocalDateTime();
  520. String apiUri = "http://113.247.231.105:40039/data/minpre/listByTimeRangeForAreaRange?startTime={sTime}&endTime={eTime}";
  521. Map<String, Object> vars = new HashMap<>();
  522. // 取数据,取最近两个时间点的数据,容错任务时间差
  523. for (int i = 0; i < 2; i++) {
  524. vars.put("sTime", utc.minusMinutes(i * 5 + 5).format(YMDHMS));
  525. vars.put("eTime", utc.minusMinutes(i * 5).format(YMDHMS));
  526. String url = UriComponentsBuilder.fromHttpUrl(apiUri).uriVariables(vars).encode().build().toString()
  527. + NX_RANGE;
  528. String sendGet = HttpUtils.sendGet(url, null);
  529. JSONObject parse = (JSONObject) JSONObject.parse(sendGet);
  530. JSONArray jsonArray = parse.getJSONArray("data");
  531. JSONArray stationList = new JSONArray();
  532. for (int j = 0; j < jsonArray.size(); j++) {
  533. JSONObject obj = (JSONObject) jsonArray.get(j);
  534. JSONObject stationData = new JSONObject();
  535. stationData.put("stationIdC", obj.getString("sid"));
  536. stationData.put("stationName", obj.getString("sname"));
  537. stationData.put("lon", obj.getString("lon"));
  538. stationData.put("lat", obj.getString("lat"));
  539. stationData.put("value", obj.getString("pre"));
  540. stationData.put("cnty", "宁乡市");
  541. stationList.add(stationData);
  542. }
  543. // 存储分钟级数据
  544. redisCache.setCacheObject(
  545. ("NingXiang430182:rankOfStationLT_minutes:" + ctt.minusMinutes(i * 5).format(YMDHM_SLIM)),
  546. stationList, 3, TimeUnit.HOURS);
  547. }
  548. // 拼接原前端需要的时间轴结构。5分钟间隔,最近2个小时,即24个点
  549. JSONObject timeline = new JSONObject();
  550. timeline.put("step", 3);
  551. timeline.put("value", 0);
  552. timeline.put("max", 23);
  553. timeline.put("min", 0);
  554. timeline.put("value", 0);
  555. DateTimeFormatter MDHM_ZHS = DateTimeFormatter.ofPattern("MM月dd日 HH:mm");
  556. Map<String, JSONObject> timeline_marks = new LinkedHashMap<>();
  557. int hour = 2, num = hour * 60 / 5;
  558. for (int i = num; i > 0; i--) {
  559. LocalDateTime sTime = ctt.minusMinutes(i * 5);
  560. LocalDateTime eTime = ctt.minusMinutes((i - 1) * 5);
  561. JSONObject markOBJ = new JSONObject();
  562. markOBJ.put("des", "分钟级降水实况: " + sTime.format(MDHM_ZHS) + "-" + eTime.format(MDHM_ZHS));
  563. markOBJ.put("rediskey", "NingXiang430182:rankOfStationLT_minutes:" + eTime.format(YMDHM_SLIM));
  564. markOBJ.put("ts", eTime.format(YMDHMS));
  565. markOBJ.put("nm", eTime.format(MDHM_ZHS));
  566. timeline_marks.put(String.valueOf(num - i), markOBJ);
  567. }
  568. timeline.put("marks", timeline_marks);
  569. redisCache.setCacheObject("NingXiang430182:rankOfStationLT_minutes", timeline);
  570. }
  571. /**
  572. * DMZ 查询省市县三级指导产品列表对外
  573. * @param params
  574. * @throws UnsupportedEncodingException
  575. * @throws ParseException
  576. */
  577. public void getWenjian(String params) throws UnsupportedEncodingException, ParseException
  578. {
  579. String url = "http://113.247.231.105:40039/data/zdcp/listForWxchat?adminCodes=430182000000";
  580. String sendGet = HttpUtils.sendGet(url, null);
  581. JSONObject parse = (JSONObject) JSONObject.parse(sendGet);
  582. JSONArray jsonArray = parse.getJSONArray("data");
  583. for(int i=0;i<jsonArray.size();i++) {
  584. JSONObject fileOBJ = (JSONObject) jsonArray.get(i);
  585. QxtFileData selectQxtFileDataById = qxtFileDataMapper.selectQxtFileDataById(fileOBJ.getString("fileId"));
  586. if(selectQxtFileDataById==null) {
  587. QxtFileData qxtFileData = new QxtFileData();
  588. qxtFileData.setId(fileOBJ.getString("fileId"));
  589. qxtFileData.setFilenmuri(fileOBJ.getString("filePdfurl"));
  590. qxtFileData.setFileip("http://113.247.231.105:40023/");
  591. qxtFileData.setDes(fileOBJ.getString("fileFname"));
  592. qxtFileData.setCreatedt(new Date());
  593. qxtFileData.setPublidt(fileOBJ.getDate("dDatatime"));
  594. String categoryids = "";
  595. if(fileOBJ.getString("groupName").indexOf("宁乡市")>=0) {
  596. if(fileOBJ.getString("fileQufen").indexOf("专题")>=0) {
  597. categoryids="NXQXZTBG";
  598. }else if(fileOBJ.getString("fileQufen").indexOf("决策")>=0) {
  599. categoryids="NXJCQXFWCP";
  600. }else if(fileOBJ.getString("fileQufen").indexOf("农")>=0) {
  601. categoryids="NXQXWNFWCP";
  602. }else if(fileOBJ.getString("fileQufen").indexOf("专业")>=0) {
  603. categoryids="NXZYQXFWCP";
  604. }else {
  605. categoryids="NXQXZTBG";
  606. }
  607. }else if(fileOBJ.getString("groupName").indexOf("湖南省")>=0) {
  608. if(fileOBJ.getString("fileQufen").indexOf("月")>=0) {
  609. categoryids="HNYB";
  610. }else if(fileOBJ.getString("fileQufen").indexOf("季")>=0) {
  611. categoryids="HNJB";
  612. }else if(fileOBJ.getString("fileQufen").indexOf("年")>=0) {
  613. categoryids="HNNB";
  614. }else if(fileOBJ.getString("fileQufen").indexOf("中期")>=0) {
  615. categoryids="HNZQTQYB";
  616. }else if(fileOBJ.getString("fileQufen").indexOf("延伸")>=0) {
  617. categoryids="QXYSYB";
  618. }else if(fileOBJ.getString("fileQufen").indexOf("重大")>=0) {
  619. categoryids="HNZDQXZB";
  620. }else {
  621. categoryids="HNYB";
  622. }
  623. }else if(fileOBJ.getString("groupName").indexOf("湖南省")>=0
  624. || fileOBJ.getString("groupName").indexOf("长沙市")>=0) {
  625. if(fileOBJ.getString("fileQufen").indexOf("专题")>=0) {
  626. categoryids="CSQXZTBG";
  627. }else if(fileOBJ.getString("fileQufen").indexOf("天气")>=0) {
  628. categoryids="CSYZTQFW";
  629. }else if(fileOBJ.getString("fileQufen").indexOf("年")>=0) {
  630. categoryids="HNNB";
  631. }else if(fileOBJ.getString("fileQufen").indexOf("重大")>=0) {
  632. categoryids="CSZDQXZB";
  633. }else if(fileOBJ.getString("fileQufen").indexOf("防汛")>=0) {
  634. categoryids="CSFXKHQXXX";
  635. } else {
  636. categoryids="CSQXZTBG";
  637. }
  638. }
  639. qxtFileData.setCategoryids(categoryids);
  640. qxtFileData.setCateid("word");
  641. qxtFileData.setSts(1);
  642. qxtFileData.setFilenm(fileOBJ.getString("fileFname"));
  643. qxtFileData.setIspdf(1);
  644. qxtFileData.setDownurl(fileOBJ.getString("fileFileurl"));
  645. qxtFileData.setAreacode(fileOBJ.getString("fileGroupid"));
  646. qxtFileDataMapper.insertQxtFileData(qxtFileData);
  647. }
  648. }
  649. }
  650. /**
  651. * 通过DMZ 经纬度查询雨量信息查询流域面雨量
  652. * @param params
  653. * @throws UnsupportedEncodingException
  654. * @throws ParseException
  655. */
  656. public void getLiuYuMianYuLiang(String params) throws UnsupportedEncodingException, ParseException
  657. {
  658. JSONObject rainArea = redisCache.getCacheObject("NingXiang430182:rankOfRainfallArea:data");
  659. if(rainArea!=null) {
  660. JSONArray jsonArr = rainArea.getJSONArray("forecastAreaRainOfBasinList");
  661. for(int i=0;i<jsonArr.size();i++) {
  662. JSONObject OBJ = (JSONObject) jsonArr.get(i);
  663. String url = "http://113.247.231.105:40039/data/grid/findGridYBListAll";
  664. String[] centerPoint = OBJ.getString("centerPoint").split(",");
  665. String sendGet = HttpUtils.sendGet(url, "lon="+centerPoint[0]+"&lat="+centerPoint[1]+"&count=240");
  666. JSONArray parse = JSONArray.parse(sendGet);
  667. //System.out.print(parse);
  668. for(int j=0;j<parse.size();j++) {
  669. JSONObject object = (JSONObject)parse.get(j);
  670. String time = object.getString("time").substring(0, 8);
  671. redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:LY:"+OBJ.getString("basinId")+":"+time, object.getString("pre"));
  672. redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:LY:"+OBJ.getString("basinId")+":"+object.getString("time"), object.getString("pre"));
  673. }
  674. }
  675. }
  676. //把几个水库的面雨量顺便爬取
  677. String redisKey = "NingXiang430182:reservoirListGIS";
  678. JSONArray resultJSONObject = redisCache.getCacheObject(redisKey);
  679. for(int i=0;i<resultJSONObject.size();i++) {
  680. JSONObject sk = resultJSONObject.getJSONObject(i);
  681. JSONArray jsonArray = sk.getJSONArray("latlng");
  682. String url = "http://113.247.231.105:40039/data/grid/findGridYBListAll";
  683. String sendGet = HttpUtils.sendGet(url, "lon="+jsonArray.getString(0)+"&lat="+jsonArray.getString(1)+"&count=240");
  684. JSONArray parse = JSONArray.parse(sendGet);
  685. //System.out.print(parse);
  686. for(int j=0;j<parse.size();j++) {
  687. JSONObject object = (JSONObject)parse.get(j);
  688. String time = object.getString("time").substring(0, 8);
  689. redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:SK:"+sk.getString("nm")+":"+time, object.getString("pre"));
  690. redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:SK:"+sk.getString("nm")+":"+object.getString("time"), object.getString("pre"));
  691. }
  692. }
  693. }
  694. }