|
|
@@ -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>("完成");
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|