|
@@ -1,6 +1,14 @@
|
|
|
package com.jiayue.client.service;
|
|
|
|
|
|
+import cn.hutool.core.codec.Base64;
|
|
|
+import cn.hutool.core.util.CharsetUtil;
|
|
|
+import cn.hutool.core.util.ZipUtil;
|
|
|
+import cn.hutool.http.HttpUtil;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
import com.jiayue.client.IpfcstClientApplication;
|
|
|
+import com.jiayue.client.util.Constants;
|
|
|
+import com.jiayue.client.util.MD5Util;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
import org.junit.Test;
|
|
|
import org.junit.runner.RunWith;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -8,9 +16,9 @@ import org.springframework.boot.test.context.SpringBootTest;
|
|
|
import org.springframework.jdbc.core.JdbcTemplate;
|
|
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.*;
|
|
|
|
|
|
+@Slf4j
|
|
|
@RunWith(SpringJUnit4ClassRunner.class)
|
|
|
@SpringBootTest(classes = IpfcstClientApplication.class, properties = "spring.config.location=classpath:/application.yml")
|
|
|
public class QueryDataServiceTest {
|
|
@@ -20,18 +28,60 @@ public class QueryDataServiceTest {
|
|
|
@Autowired
|
|
|
private QueryDataService queryDataService;
|
|
|
|
|
|
+ /*
|
|
|
+ * 将时间戳转换为时间
|
|
|
+ * @param s
|
|
|
+ */
|
|
|
+ public static String stampToDateStr(String s) {
|
|
|
+ String res;
|
|
|
+ long lt = new Long(s);
|
|
|
+ Date date = new Date(lt);
|
|
|
+ res = Constants.formatter.format(date);
|
|
|
+ return res;
|
|
|
+ }
|
|
|
+
|
|
|
@Test
|
|
|
public void test() {
|
|
|
- String starTime = "2021-01-01 12:00:21";
|
|
|
- String endTime = "2022-01-01 12:00:21";
|
|
|
- //List<Map<String, Object>> testList = queryDataService.getRps(starTime, endTime, "T00003");
|
|
|
- // List<Map<String, Object>> testList = queryDataService.getDqs(starTime, endTime, "T00003");
|
|
|
- //List<Map<String, Object>> testList = queryDataService.getCdqs(starTime, endTime, "1");
|
|
|
- //List<Map<String, Object>> testList = queryDataService.getCfts(starTime, endTime, "6");
|
|
|
- // List<Map<String, Object>> testList = queryDataService.getFjs(starTime, endTime, "1");
|
|
|
- List<Map<String, Object>> testList = queryDataService.getWeatherds(starTime, endTime, "7");
|
|
|
-
|
|
|
- System.out.println(testList.size());
|
|
|
+ log.info("时间 {} 公众号推送异常消息", System.currentTimeMillis());
|
|
|
+ List<Map<String, Object>> testList = queryDataService.getWarnigMsg();
|
|
|
+ List<Map<String, Object>> valueList = new ArrayList<>();
|
|
|
+ for (Map<String, Object> strInfo : testList) {
|
|
|
+ Map<String, Object> valueMap = new HashMap<>();
|
|
|
+ valueMap.put("info", strInfo.get("C_NAME"));
|
|
|
+ valueMap.put("stationCode", strInfo.get("C_STATION_CODE"));
|
|
|
+ // valueMap.put("createTime", WechatMsgUtils.stampToDateStr(Convert.toDate(strInfo.get("C_CREATE_TIME")).getTime() + ""));
|
|
|
+ valueList.add(valueMap);
|
|
|
+ }
|
|
|
+ String reqBodyStr = JSONUtil.toJsonStr(valueList);
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ resultMap.put("type", "warningMsg");
|
|
|
+ resultMap.put("body", reqBodyStr);
|
|
|
+ String sign = MD5Util.encode(reqBodyStr + "Syjy*3377", "MD5");
|
|
|
+ resultMap.put("sign", sign);
|
|
|
+
|
|
|
+ String reqStr = JSONUtil.toJsonStr(resultMap);
|
|
|
+ log.debug("回传数据给数据中心,请求原报文:{}", reqStr);
|
|
|
+
|
|
|
+ Map<String, Object> reqMap = new HashMap<>();
|
|
|
+ reqMap.put("reqMsg", Base64.encode(ZipUtil.gzip(reqStr, CharsetUtil.CHARSET_UTF_8.name())));
|
|
|
+ log.debug("回传数据给数据中心,压缩加密后报文:{}", reqMap);
|
|
|
+ String resp = HttpUtil.post("http://127.0.0.1:9001/qinghaiComeBackApi/datas", reqMap);
|
|
|
+ if (resp.length() > 0 && (0 == JSONUtil.parseObj(resp).getInt("code"))) {
|
|
|
+ log.info("回传警告数据给数据中心成功,获得响应报文:{}", resp);
|
|
|
+ } else {
|
|
|
+ log.error("回传警告数据给数据中心错误:{}", resp);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取当前时间
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getCurentTime() {
|
|
|
+ Calendar date = Calendar.getInstance();
|
|
|
+ date.setTime(new Date());
|
|
|
+ return Constants.formatter.format(date.getTime());
|
|
|
}
|
|
|
|
|
|
public List<Map<String, Object>> getRp(String startTime, String endTime, String stationCode) {
|