Browse Source

更新需求

usts 5 years ago
parent
commit
cb20365b62

+ 28 - 8
febs-server/gbd-demp-data-exchange/src/main/java/com/gbd/demp/data/exchange/task/LiveDataTask.java

@@ -7,6 +7,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.gbd.demp.data.exchange.entity.*;
 import com.gbd.demp.data.exchange.service.*;
 import com.gbd.demp.data.exchange.utils.CommonUtils;
+import com.gbd.demp.data.exchange.vo.Ioc;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.http.HttpEntity;
@@ -389,6 +390,7 @@ public class LiveDataTask {
      * <p>
      * 1.现在系统中新增设备信息、传感器编号
      * 2.现根据设备编号从数据库里获取传感器编号,然后根据传感器编号存数据、判断阈值
+     * 3.解析完数据,往IOC推送
      *
      * @param liveData
      * @return
@@ -412,6 +414,7 @@ public class LiveDataTask {
 //                    if (count > 0) {
 //                        for (int i = 0; i < count; i++) {//循环插入数据库
 //                            String seq = "m" + (i + 1);//传感器编号
+                List<Ioc> iocList = new ArrayList<>();
                 for (String seq : sensorIds) {//遍历传感器
                     double val = Double.valueOf(deviceData.get(seq));
                     LiveData data = new LiveData();
@@ -427,6 +430,14 @@ public class LiveDataTask {
                     List<DeviceThreshold> thresholds = deviceThresholdService.getThresholdsBySensorID(seq);//根据传感器编号获取传感器阈值信息
                     SensorInfo sensorInfo = sensorInfoService.getBySensorId(seq, deviceId);//获取传感器信息
                     AlarmEvent alarmEvent = alarmEventService.checkExist(deviceId, seq);//8小时内是否有告警信息,如果有,只更新,不推送
+                    Ioc ioc = new Ioc();
+                    ioc.setDetectorId(deviceId + "-" + seq);
+                    ioc.setPrecision(3);
+                    ioc.setUnit(sensorInfo.getSensorUnit());
+                    ioc.setValue(val);
+                    ioc.setStatus(1);
+                    ioc.setExpired(false);
+                    iocList.add(ioc);
                     if (thresholds.size() > 0) {
                         //code:0
                         DeviceThreshold thresholds_0 = thresholds.get(0);
@@ -624,20 +635,29 @@ public class LiveDataTask {
                         historyDataService.save(data1);
                     }
                 }
+                if (iocList.size() > 0)
+                    postToIOC(iocList);
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
         return new AsyncResult<String>("完成");
     }
-//
-//    public Future<String> task6() throws InterruptedException {
-//        long begin = System.currentTimeMillis();
-//        Thread.sleep(1000L);
-//        long end = System.currentTimeMillis();
-//        System.out.println("任务6耗时=" + (end - begin));
-//        return new AsyncResult<String>("任务6");
-//    }
+
+    public Future<String> postToIOC(List<Ioc> iocList) throws InterruptedException {
+        String url = "http://121.239.102.59:8083/nata/device/data";
+        String json = JSON.toJSONString(iocList);
+        HttpHeaders headers = new HttpHeaders();
+        MediaType type = MediaType.parseMediaType("application/json; charset=UTF-8");
+        headers.add("User-Agent", "Chrome/69.0.3497.81 Safari/537.36");
+        headers.setContentType(type);
+        headers.add("Accept", MediaType.APPLICATION_JSON.toString());
+        HttpEntity<String> formEntity = new HttpEntity<String>(json.toString(), headers);
+        String s = restTemplate.postForEntity(url, formEntity, String.class).getBody();
+//        JSONObject jsonObject = JSONObject.parseObject(s);
+//        return jsonObject.getString("id");
+        return new AsyncResult<String>("完成");
+    }
 
 
     /**

+ 24 - 0
febs-server/gbd-demp-data-exchange/src/main/java/com/gbd/demp/data/exchange/vo/Ioc.java

@@ -0,0 +1,24 @@
+package com.gbd.demp.data.exchange.vo;
+
+import lombok.Data;
+
+@Data
+public class Ioc {
+    private String detectorId;//探头ID
+    private int precision;//探头精度,类型枚举 X1 = 1 X0_1 = 2 X0_01 = 3 X0_001 = 4
+    private String unit;//探头单位
+    private Double value;//探头返回的数值
+    /**
+     * 探头状态,类型枚举
+     * 离线 Offline = 0
+     * 正常 Normal = 1
+     * 报警(低报) LowAlert = 2
+     * 报警(高报) HighAlert = 3
+     * 故障 Broken = 4
+     * 屏蔽 Sheild = 5
+     */
+    private int status;
+    private boolean expired;//是否过期,类型布尔
+
+
+}

+ 5 - 3
febs-server/gbd-demp-info/src/main/java/com/gbd/demp/info/utils/ThirdPartyUtils.java

@@ -14,6 +14,7 @@ public class ThirdPartyUtils {
 
     /**
      * 获取第三方平台用户信息
+     *
      * @param token
      * @return
      */
@@ -23,7 +24,7 @@ public class ThirdPartyUtils {
         MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
         paramMap.add("token", token);
         HttpHeaders headers = new HttpHeaders();
-        headers.add("User-Agent", "Chrome/69.0.3497.81 Safari/537.36");
+        headers.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.54");
         HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap, headers);
         ResponseEntity<String> response = template.postForEntity(url, httpEntity, String.class);
         ThirdPartyUser user = JSONObject.parseObject(response.getBody(), ThirdPartyUser.class);
@@ -33,16 +34,17 @@ public class ThirdPartyUtils {
 
     /**
      * 向第三方平台请求数据
+     *
      * @param url
      * @param token
      * @return
      */
-    public static ResponseEntity getThirdPartyInfo(String url,String token) {
+    public static ResponseEntity getThirdPartyInfo(String url, String token) {
         RestTemplate template = new RestTemplate();
         MultiValueMap<String, Object> paramMap = new LinkedMultiValueMap<String, Object>();
         paramMap.add("token", token);
         HttpHeaders headers = new HttpHeaders();
-        headers.add("User-Agent", "Chrome/69.0.3497.81 Safari/537.36");
+        headers.add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.90 Safari/537.36 Edg/89.0.774.54");
         HttpEntity<MultiValueMap<String, Object>> httpEntity = new HttpEntity<MultiValueMap<String, Object>>(paramMap, headers);
         ResponseEntity<String> response = template.postForEntity(url, httpEntity, String.class);
 //        ThirdPartyUser user = JSONObject.parseObject(response.getBody(), ThirdPartyUser.class);