123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858 |
- 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<String> 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小时数据
- List<String>timeLineArr = new ArrayList<String>();
- 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<String,JSONObject> qiWenTimeLine_marks_map = new HashMap<String, JSONObject>();
-
-
-
- //逐小时雨量时间小时轴组装
- JSONObject RESULT = new JSONObject();
- JSONObject slider0 = new JSONObject();
- slider0.put("max", timeLineArr.size()-1);
- slider0.put("step", 2);
- slider0.put("value", 0);
- Map<String,JSONObject>marks = new HashMap<String, JSONObject>();
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- int j = timeLineArr.size()-1;
- for(int i=0;i<timeLineArr.size();i++) {
-
-
- String timestring = timeLineArr.get(i);
- Date a = dateFormat.parse(timestring);
- String entd = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH1, a);
- String nm = DateUtils.parseDateToStr(DateUtils.DDHH, a);
- String rediskey = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, a);
-
- a.setTime(a.getTime() - 60*60*1000);
- String std = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH1, a);
- JSONObject jsonObj = new JSONObject();
- jsonObj.put("des", "逐小时降水实况:"+std+"-"+entd);
- jsonObj.put("ts", timestring);
- jsonObj.put("nm", nm);
- jsonObj.put("rediskey", "NingXiang430182:rankOfStation1Hour:"+rediskey);
- marks.put(j+"", jsonObj);
-
-
-
-
-
- JSONObject jsonObjQWSK = new JSONObject();
- jsonObjQWSK.put("des", "逐小时气温实况:"+std+"-"+entd);
- jsonObjQWSK.put("ts", timestring);
- jsonObjQWSK.put("nm", nm);
- jsonObjQWSK.put("rediskey", "NingXiang430182:DMZQiWenSK:"+rediskey);
- qiWenTimeLine_marks_map.put(j+"", jsonObjQWSK);
-
-
- j--;
- }
- slider0.put("marks", marks);
- RESULT.put("slider0", slider0);
- //存储小时降雨量时间轴
- redisCache.setCacheObject("NingXiang430182:rankOfStationLT_hour", slider0);
-
-
-
- qiWenTimeLine.put("marks", qiWenTimeLine_marks_map);
- qiWenTimeLine.put("max", timeLineArr.size()-1);
-
- 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\":\"气温(℃)\"}"));
- //存储小时气温时间轴
- redisCache.setCacheObject("NingXiang430182:DMZQiWenSK:LatestData", qiWenTimeLine);
-
-
-
-
- }
-
-
-
-
-
- /**
- * 宁乡小时实况降水逐3小时
- * @param params
- * @throws UnsupportedEncodingException
- * @throws ParseException
- */
- public void listByTimeDurationForAreaCode3(String params) throws UnsupportedEncodingException, ParseException
- {
-
- JSONArray jstableDataArr = new JSONArray();
- //查询最近24小时数据
- List<String>timeLineArr = new ArrayList<String>();
- 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);
- Map<String,JSONObject>marks = new HashMap<String, JSONObject>();
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- int j = timeLineArr.size()-1;
- for(int i=0;i<timeLineArr.size();i++) {
-
- JSONObject jsonObj = new JSONObject();
- String timestring = timeLineArr.get(i);
- Date a = dateFormat.parse(timestring);
- String entd = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH1, a);
- String nm = DateUtils.parseDateToStr(DateUtils.DDHH, a);
- String rediskey = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH, a);
-
- a.setTime(a.getTime() - 180*60*1000);
- String std = DateUtils.parseDateToStr(DateUtils.YYYYMMDDHH1, a);
- jsonObj.put("des", "逐3小时降水实况:"+std+"-"+entd);
- jsonObj.put("ts", timestring);
- jsonObj.put("nm", nm);
- jsonObj.put("rediskey", "NingXiang430182:rankOfStation3Hour:"+rediskey);
- marks.put(j+"", jsonObj);
- j--;
- }
- slider0.put("marks", marks);
- RESULT.put("slider0", slider0);
- //存储小时降雨量时间轴
- redisCache.setCacheObject("NingXiang430182:rankOfStationLT_3hour", slider0);
-
- }
-
-
-
- /**
- * 天气预报
- * @param params
- * @throws UnsupportedEncodingException
- * @throws ParseException
- */
- public void listAreaWeather(String params) throws UnsupportedEncodingException, ParseException
- {
-
- String sendGet = HttpUtils.sendGet( "http://113.247.231.105:40039/data/cityyb/listByAreaCodeForNew?adminCodes=430182000000", null);
- JSONObject resultObject = JSONObject.parseObject(sendGet);
- JSONArray jsonArray = resultObject.getJSONArray("data");
- JSONArray resultARR = new JSONArray();
- for(int i=0;i<jsonArray.size();i++) {
- JSONObject RES = new JSONObject();
- JSONObject OBJ = (JSONObject) jsonArray.get(i);
- Date ybtime = OBJ.getDate("ybtime");
- RES.put("temp", (OBJ.getString("temmin")+" ~ "+OBJ.getString("temmax")));
- RES.put("wind", (OBJ.getString("fengxiang")));
- RES.put("type", (OBJ.getString("tianqi1")));
- RES.put("day", (DateUtils.parseDateToStr(DateUtils.MM_DD, ybtime)));
-
- RES.put("code", StringUtils.getPinYin(OBJ.getString("tianqi1")));
-
- resultARR.add(RES);
-
- }
- JSONObject RESULT = new JSONObject();
- RESULT.put("area", "NingXiang");
- RESULT.put("today", "NingXiang");
- RESULT.put("barTitle", "NingXiang");
- RESULT.put("data", resultARR);
- //存储天气信息
- redisCache.setCacheObject("NingXiang430182:Weather", RESULT);
-
-
-
- }
-
-
- /**
- * 实况统计气温列表
- *
- * @param OBJ
- * @return
- */
- @PostMapping(value = "/temperatureList")
- public AjaxResult temperatureList(@RequestBody JSONObject OBJ) {
- try {
- String redisKey = "NingXiang430182:temperatureList";
- JSONObject resultJSONObject = redisCache.getCacheObject(redisKey);
- if (resultJSONObject == null) {
- resultJSONObject = JSONObject.parseObject("{\"jsDesCol\":[{\"prop\":\"time\",\"label\":\"时间\"},{\"prop\":\"temp\",\"label\":\"气温℃\"}],\"title\":\"过去24小时平均气温\",\"jstableData\":[]}");
- }
- return AjaxResult.success("实况统计气温列表数据加载成功!", resultJSONObject);
- } catch (Exception e) {
- return AjaxResult.error("暂无数据!");
- }
- }
-
-
-
- /**
- * 【实况统计】某地区气象站排名
- *
- * @param OBJ
- * @return
- * @throws ParseException
- */
- @PostMapping(value = "/rankOfStation")
- public AjaxResult rankOfStation(@RequestBody JSONObject OBJ) throws ParseException {
- JSONArray resultJSONObject = null;
- try {
- String redisKey = "NingXiang430182:rankOfStation:";
- String time = OBJ.getString("time");
- String ranktype = OBJ.getString("ranktype");
- if (ranktype.equals("0")) {
- redisKey += time;
- } else if (ranktype.equals("1")) {
- redisKey += time;
- } else if (ranktype.equals("2")) {
- redisKey += time;
- }
- resultJSONObject = redisCache.getCacheObject(time);
- if (resultJSONObject == null) {
- return AjaxResult.success("暂无数据!");
- /*
- * String res = HttpUtils.sendGet(OBJ.getString("uri"));
- * if(StringUtils.isEmpty(res))return AjaxResult.error(999," 某地区流域雨面量排名数据失败!");
- * resultJSONObject= JSONObject.parseObject(res);
- * redisCache.setCacheObject(redisKey,resultJSONObject);
- */
- }
- } catch (Exception e) {
- return AjaxResult.success("暂无数据!");
- }
- resultJSONObject.sort(Comparator.comparing(obj -> ((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<resultJSONObject.size();i++) {
- JSONObject sk = resultJSONObject.getJSONObject(i);
- JSONArray jsonArray = sk.getJSONArray("latlng");
- String url = "http://113.247.231.105:40039/data/grid/findGridYBListAll";
- JSONObject OBJ = new JSONObject();
- OBJ.put("skmc",sk.getString("nm"));
- OBJ.put("propId",sk.getString("id"));
- String sendGet = HttpUtils.sendGet(url, "lon="+jsonArray.getString(0)+"&lat="+jsonArray.getString(1)+"&count=240");
- JSONArray parse = JSONArray.parse(sendGet);
- //System.out.print(parse);
- for(int j=0;j<parse.size();j++) {
- JSONObject object = (JSONObject)parse.get(j);
- String time = object.getString("time").substring(0, 8);
- redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:SK:"+sk.getString("nm")+":"+time, object.getString("pre"));
- redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:SK:"+sk.getString("nm")+":"+object.getString("time"), object.getString("pre"));
- Date timeNow = new Date();
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmm");
- Date dataTime = dateFormat.parse(object.getString("time"));
- long hour = this.getDiffMinutes(dataTime,timeNow);
- if(hour == 0 || hour == 1|| hour == 2){
- OBJ.put("hour1",object.getString("pre"));
- }
- if(hour == 3||hour == 4||hour == 5){
- OBJ.put("hour3",object.getString("pre"));
- }
- if(hour == 6||hour == 7||hour == 8||hour == 9||hour == 10||hour == 11){
- OBJ.put("hour6",object.getString("pre"));
- }
- if(hour == 12||hour == 13||hour == 14||hour == 15||hour == 16){
- OBJ.put("hour12",object.getString("pre"));
- }
- }
- jstableData.add(OBJ);
- }
- //拼装水库预报降水
- JSONArray jsDesCol = JSON.parseArray("[{\"prop\":\"skmc\",\"label\":\"水库名称\"},{\"prop\":\"hour1\",\"label\":\"未来1小时\"},{\"prop\":\"hour3\",\"label\":\"未来3小时\"},{\"prop\":\"hour6\",\"label\":\"未来6小时\"},{\"prop\":\"hour12\",\"label\":\"未来12小时\"}]");
- JSONObject RES = new JSONObject();
- RES.put("jsDesCol",jsDesCol);
- RES.put("jstableData",jstableData);
- RES.put("title",DateUtils.dateTimeNow(DateUtils.YYYYMMDDHH1)+"水库"+"未来1小时,3小时,6小时,12小时降水预报.单位(mm)");
- redisCache.setCacheObject("NingXiang430182:rainfallVolumeForcast:14",RES);
- }
- private long getDiffMinutes( Date date1, Date date2){
- long nd = 1000 * 24 * 60 * 60;//每天毫秒数
- long nh = 1000 * 60 * 60;//每小时毫秒数
- long nm = 1000 * 60;//每分钟毫秒数
- long diff = date1.getTime() - date2.getTime(); // 获得两个时间的毫秒时间差异
- long day = diff / nd; // 计算差多少天
- long hour = diff % nd / nh; // 计算差多少小时
- long min = diff % nd % nh / nm; // 计算差多少分钟
- return hour ;
- }
- /**
- * 分钟级降水
- *
- * @param params
- * @throws UnsupportedEncodingException
- * @throws ParseException
- */
- public void listYBMinutes(String params) throws UnsupportedEncodingException, ParseException {
- ZoneId ZONE_CTT = ZoneId.of("Asia/Shanghai");
- ZoneId ZONE_UTC = ZoneId.of("UTC");
- DateTimeFormatter YMDHMS = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
- DateTimeFormatter YMDHM_SLIM = DateTimeFormatter.ofPattern("yyyyMMddHHmm");
- LocalDateTime now = LocalDateTime.now();
- LocalDateTime ctt = now.minusMinutes(now.getMinute() % 5).withSecond(0).withNano(0);
- LocalDateTime utc = ZonedDateTime.of(ctt, ZONE_CTT).withZoneSameInstant(ZONE_UTC).toLocalDateTime();
- String apiUri = "http://113.247.231.105:40039/data/minpre/listByTimeRangeForAreaRange?startTime={sTime}&endTime={eTime}";
- Map<String, Object> 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<String, JSONObject> 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<jsonArray.size();i++) {
- JSONObject fileOBJ = (JSONObject) jsonArray.get(i);
- QxtFileData selectQxtFileDataById = qxtFileDataMapper.selectQxtFileDataById(fileOBJ.getString("fileId"));
- if(selectQxtFileDataById==null) {
- QxtFileData qxtFileData = new QxtFileData();
- qxtFileData.setId(fileOBJ.getString("fileId"));
- qxtFileData.setFilenmuri(fileOBJ.getString("filePdfurl"));
- qxtFileData.setFileip("http://113.247.231.105:40023/");
- qxtFileData.setDes(fileOBJ.getString("fileFname"));
- qxtFileData.setCreatedt(new Date());
- qxtFileData.setPublidt(fileOBJ.getDate("dDatatime"));
- String categoryids = "";
- if(fileOBJ.getString("groupName").indexOf("宁乡市")>=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<jsonArr.size();i++) {
- JSONObject OBJ = (JSONObject) jsonArr.get(i);
- String url = "http://113.247.231.105:40039/data/grid/findGridYBListAll";
- String[] centerPoint = OBJ.getString("centerPoint").split(",");
- String sendGet = HttpUtils.sendGet(url, "lon="+centerPoint[0]+"&lat="+centerPoint[1]+"&count=240");
- JSONArray parse = JSONArray.parse(sendGet);
- //System.out.print(parse);
- for(int j=0;j<parse.size();j++) {
- JSONObject object = (JSONObject)parse.get(j);
- String time = object.getString("time").substring(0, 8);
- redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:LY:"+OBJ.getString("basinId")+":"+time, object.getString("pre"));
- redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:LY:"+OBJ.getString("basinId")+":"+object.getString("time"), object.getString("pre"));
- }
- }
-
- }
- //把几个水库的面雨量顺便爬取
- String redisKey = "NingXiang430182:reservoirListGIS";
- JSONArray resultJSONObject = redisCache.getCacheObject(redisKey);
-
- for(int i=0;i<resultJSONObject.size();i++) {
- JSONObject sk = resultJSONObject.getJSONObject(i);
- JSONArray jsonArray = sk.getJSONArray("latlng");
-
- String url = "http://113.247.231.105:40039/data/grid/findGridYBListAll";
-
- String sendGet = HttpUtils.sendGet(url, "lon="+jsonArray.getString(0)+"&lat="+jsonArray.getString(1)+"&count=240");
- JSONArray parse = JSONArray.parse(sendGet);
- //System.out.print(parse);
- for(int j=0;j<parse.size();j++) {
- JSONObject object = (JSONObject)parse.get(j);
- String time = object.getString("time").substring(0, 8);
- redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:SK:"+sk.getString("nm")+":"+time, object.getString("pre"));
- redisCache.setCacheObject("NingXiang430182:rankOfRainfallArea:SK:"+sk.getString("nm")+":"+object.getString("time"), object.getString("pre"));
- }
- }
-
- }
-
-
- }
|