|
@@ -5,11 +5,16 @@ 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;
|
|
@@ -21,6 +26,8 @@ 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;
|
|
@@ -32,7 +39,7 @@ import com.bfms.common.utils.http.HttpUtils;
|
|
|
import com.bfms.system.domain.QxtFileData;
|
|
|
import com.bfms.system.mapper.QxtFileDataMapper;
|
|
|
/**
|
|
|
- * 定时任务调度测试
|
|
|
+ * 定时任务调度测试
|
|
|
*
|
|
|
* @author MET
|
|
|
*/
|
|
@@ -45,6 +52,7 @@ public class DMZNewTask
|
|
|
@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();
|
|
@@ -191,7 +199,7 @@ public class DMZNewTask
|
|
|
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/listByTimeDurationForAreaCode?adminCodes=430182000000&shichang=1&nowtime="+nowTimeQuery, null);
|
|
|
+ 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");
|
|
|
//每个小时宁乡站点 平均气温
|
|
@@ -213,11 +221,13 @@ public class DMZNewTask
|
|
|
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", "宁乡市");
|
|
|
+ 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);
|
|
@@ -229,7 +239,7 @@ public class DMZNewTask
|
|
|
newobj1.put("stationName",ob.getString("sname"));
|
|
|
newobj1.put("lon", ob.getString("lon"));
|
|
|
newobj1.put("lat", ob.getString("lat"));
|
|
|
- newobj1.put("cnty", "宁乡市");
|
|
|
+ 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);
|
|
@@ -244,7 +254,7 @@ public class DMZNewTask
|
|
|
|
|
|
|
|
|
}
|
|
|
- redisCache.setCacheObject("NingXiang430182:rankOfStation:"+redisTimeKey, result);
|
|
|
+ redisCache.setCacheObject("NingXiang430182:rankOfStation1Hour:"+redisTimeKey, result);
|
|
|
|
|
|
|
|
|
|
|
@@ -323,7 +333,7 @@ public class DMZNewTask
|
|
|
jsonObj.put("des", "逐小时降水实况:"+std+"-"+entd);
|
|
|
jsonObj.put("ts", timestring);
|
|
|
jsonObj.put("nm", nm);
|
|
|
- jsonObj.put("rediskey", "NingXiang430182:rankOfStation:"+rediskey);
|
|
|
+ jsonObj.put("rediskey", "NingXiang430182:rankOfStation1Hour:"+rediskey);
|
|
|
marks.put(j+"", jsonObj);
|
|
|
|
|
|
|
|
@@ -388,7 +398,7 @@ public class DMZNewTask
|
|
|
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/listByTimeDurationForAreaCode?adminCodes=430182000000&shichang=1&nowtime="+nowTimeQuery, null);
|
|
|
+ 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");
|
|
|
|
|
@@ -397,17 +407,18 @@ public class DMZNewTask
|
|
|
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", "宁乡市");
|
|
|
+ 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:rankOfStation:"+redisTimeKey, result);
|
|
|
+ redisCache.setCacheObject("NingXiang430182:rankOfStation3Hour:"+redisTimeKey, result);
|
|
|
timeLineArr.add(redisTimeLine);
|
|
|
|
|
|
}
|
|
@@ -439,7 +450,7 @@ public class DMZNewTask
|
|
|
jsonObj.put("des", "逐3小时降水实况:"+std+"-"+entd);
|
|
|
jsonObj.put("ts", timestring);
|
|
|
jsonObj.put("nm", nm);
|
|
|
- jsonObj.put("rediskey", "NingXiang430182:rankOfStation:"+rediskey);
|
|
|
+ jsonObj.put("rediskey", "NingXiang430182:rankOfStation3Hour:"+rediskey);
|
|
|
marks.put(j+"", jsonObj);
|
|
|
j--;
|
|
|
}
|
|
@@ -575,7 +586,7 @@ public class DMZNewTask
|
|
|
|
|
|
String sendGet = HttpUtils.sendGet(url, "lon="+jsonArray.getString(0)+"&lat="+jsonArray.getString(1)+"&count=240");
|
|
|
JSONArray parse = JSONArray.parse(sendGet);
|
|
|
- //System.out.print(parse);NingXiang430182:warningnews
|
|
|
+ //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);
|
|
@@ -633,98 +644,82 @@ public class DMZNewTask
|
|
|
|
|
|
return hour ;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 分钟级降水
|
|
|
- * @param params
|
|
|
- * @throws UnsupportedEncodingException
|
|
|
- * @throws ParseException
|
|
|
- */
|
|
|
- public void listYBMinutes(String params) throws UnsupportedEncodingException, ParseException
|
|
|
- {
|
|
|
-
|
|
|
- JSONObject minuteTimeLine = new JSONObject();
|
|
|
-
|
|
|
- JSONObject minuteTimeLine_slider0 = new JSONObject();
|
|
|
- minuteTimeLine_slider0.put("step",3);
|
|
|
- minuteTimeLine_slider0.put("value",0);
|
|
|
- SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
|
- Map<String,JSONObject>minuteTimeLine_marks = new HashMap<String, JSONObject>();
|
|
|
- Date dt1 = new Date();
|
|
|
- for(int i=20;i>=0;i--) {
|
|
|
-
|
|
|
- Date dt4=dt1;
|
|
|
- String redisTimeLine4 = DateUtils.parseDateToStr("MM月dd日 HH:mm", dt4);
|
|
|
- String redisTimeLine1_BJ4 = DateUtils.parseDateToStr("yyyyMMddHHmm", dt4);
|
|
|
- String redisTimeLinets_4 = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", dt4);
|
|
|
- String redisTimeLine1nm_BJ4 = DateUtils.parseDateToStr("MM月dd日 HH:mm", dt4);
|
|
|
-
|
|
|
- Date dt2=dt1;
|
|
|
- dt2.setTime(dt2.getTime()-15*60*1000);
|
|
|
- String redisTimeLine1_BJ1 = DateUtils.parseDateToStr("MM月dd日 HH:mm", dt2);
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- JSONObject markOBJ = new JSONObject();
|
|
|
- markOBJ.put("des", "分钟级降水实况: "+redisTimeLine1_BJ1+"-"+redisTimeLine4);
|
|
|
- markOBJ.put("rediskey", "NingXiang430182:rankOfStationLT_minutes:"+redisTimeLine1_BJ4);
|
|
|
- markOBJ.put("ts", redisTimeLinets_4);
|
|
|
- markOBJ.put("nm", redisTimeLine1nm_BJ4);
|
|
|
-
|
|
|
-
|
|
|
- Date nowTime1 = dateFormat.parse(redisTimeLinets_4);
|
|
|
- nowTime1.setTime(nowTime1.getTime()-8*60*60*1000);
|
|
|
- String nowTime = DateUtils.parseDateToStr("yyyy-MM-dd+HH:mm:ss", nowTime1);
|
|
|
-
|
|
|
- //请求数据
|
|
|
- String url = "http://113.247.231.105:40039/data/minpre/listByTimeDurationForAreaCodeBySUM?adminCodes=430182000000&nowtime="+nowTime+"&shichang=15";
|
|
|
- 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 objecta = (JSONObject) jsonArray.get(j);
|
|
|
-
|
|
|
- JSONObject station = new JSONObject();
|
|
|
- station.put("stationIdC", objecta.getString("sid"));
|
|
|
- station.put("stationName", objecta.getString("sname"));
|
|
|
- station.put("lon", objecta.getString("lon"));
|
|
|
- station.put("lat", objecta.getString("lat"));
|
|
|
- station.put("cnty", "宁乡市");
|
|
|
- station.put("value", objecta.getString("pre"));
|
|
|
-
|
|
|
- stationList.add(station);
|
|
|
-
|
|
|
- }
|
|
|
- //存储分钟级数据
|
|
|
- redisCache.setCacheObject(("NingXiang430182:rankOfStationLT_minutes:"+redisTimeLine1_BJ4), stationList,2,TimeUnit.HOURS);
|
|
|
- minuteTimeLine_marks.put(i+"", markOBJ);
|
|
|
-
|
|
|
-
|
|
|
- dt1=dt2;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- minuteTimeLine_slider0.put("marks", minuteTimeLine_marks);
|
|
|
- minuteTimeLine_slider0.put("max", 20);
|
|
|
- minuteTimeLine_slider0.put("min", 0);
|
|
|
- minuteTimeLine_slider0.put("value", 0);
|
|
|
|
|
|
- minuteTimeLine.put("slider0", minuteTimeLine_slider0);
|
|
|
|
|
|
- //System.out.println(minuteTimeLine);
|
|
|
- //存储分钟级时间轴
|
|
|
- redisCache.setCacheObject("NingXiang430182:rankOfStationLT_minutes", minuteTimeLine_slider0);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 分钟级降水
|
|
|
+ *
|
|
|
+ * @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
|