|
|
@@ -0,0 +1,441 @@
|
|
|
+package com.gbd.demp.data.exchange.task;
|
|
|
+
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+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 lombok.extern.slf4j.Slf4j;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
+import org.springframework.scheduling.annotation.AsyncResult;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+import java.util.concurrent.Future;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 实时数据异步处理
|
|
|
+ * 1.告警规则判断
|
|
|
+ * 2.存储数据到数据库
|
|
|
+ * 3.如有告警,推送告警并且存入告警事件表
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Component
|
|
|
+@Async("taskExecutor")
|
|
|
+public class LiveDataTask {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private IDeviceThresholdService deviceThresholdService;
|
|
|
+ @Autowired
|
|
|
+ private ILiveDataService liveDataService;
|
|
|
+ @Autowired
|
|
|
+ private IHistoryDataService historyDataService;
|
|
|
+ @Autowired
|
|
|
+ private IDeviceInfoService deviceInfoService;
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+ @Autowired
|
|
|
+ private IAlarmEventService alarmEventService;
|
|
|
+ @Autowired
|
|
|
+ private ISensorInfoService sensorInfoService;
|
|
|
+
|
|
|
+
|
|
|
+ //获取异步结果
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Future<String> alarmTask(String liveData) {
|
|
|
+ try {
|
|
|
+ String reportTime = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
|
|
|
+ Date nowDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(reportTime);
|
|
|
+ String token = "8a81e3166b379ce3016b37bab1bc000d";
|
|
|
+ byte bb[] = CommonUtils.getHexBytes(liveData);
|
|
|
+ String[] oldData = new String[bb.length];
|
|
|
+ for (int i = 0; i < bb.length; i++) {
|
|
|
+ String stmp = Integer.toHexString(bb[i] & 0xFF);
|
|
|
+ stmp = stmp.length() == 1 ? "0" + stmp : stmp;
|
|
|
+ oldData[i] = stmp.toUpperCase();
|
|
|
+ }
|
|
|
+ // 处理数据
|
|
|
+// String reportTime = "20" + oldData[5] + "-" + oldData[6] + "-" + oldData[7] + " " + oldData[8] + ":"
|
|
|
+// + oldData[9] + ":" + oldData[10];// 上报时间
|
|
|
+ String deviceId = oldData[4];//设备编号
|
|
|
+ int len = Integer.parseInt(oldData[11]);
|
|
|
+ //根据设备id获取设备信息
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getDeviceInfoById(deviceId);
|
|
|
+ String startTime = deviceInfo.getWorkTimeFrom();
|
|
|
+ String endTime = deviceInfo.getWorkTimeTo();
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
|
|
|
+ String now = sf.format(new Date());//获取当前时间
|
|
|
+ //如果未设置时间或者当前时间在工作范围内
|
|
|
+ if (CommonUtils.isEffectiveDate(sf.parse(now), sf.parse(startTime), sf.parse(endTime))) {
|
|
|
+ for (int i = 0; i < len; i++) {
|
|
|
+ String seq = oldData[12 + 6 * i] + oldData[13 + 6 * i];// 设备类型+编号(传感器编号)
|
|
|
+ String str = oldData[14 + 6 * i];// 03 第一位0正数 1负数;第二位表示有几位小数
|
|
|
+ String num = str.substring(0, 1);
|
|
|
+ String num2 = str.substring(1, 2);
|
|
|
+ String value = oldData[15 + 6 * i] + oldData[16 + 6 * i] + oldData[17 + 6 * i];// 对应参数值 00 00 68
|
|
|
+ double val = Double.parseDouble(value.substring(0, (value.length() - Integer.parseInt(num2))) + "."
|
|
|
+ + value.substring((value.length() - Integer.parseInt(num2)), value.length()));
|
|
|
+ if ("1".equals(num)) {
|
|
|
+ val = -val;
|
|
|
+ }
|
|
|
+ LiveData data = new LiveData();
|
|
|
+ data.setDeviceId(deviceId);
|
|
|
+ data.setReportTime(reportTime);
|
|
|
+ data.setSensorId(seq);
|
|
|
+ data.setDataValue(val);
|
|
|
+ HistoryData data1 = new HistoryData();
|
|
|
+ data1.setDeviceId(deviceId);
|
|
|
+ data1.setReportTime(reportTime);
|
|
|
+ data1.setSensorId(seq);
|
|
|
+ data1.setDataValue(val);
|
|
|
+ List<DeviceThreshold> thresholds = deviceThresholdService.getThresholdsBySensorID(seq);//根据传感器编号获取传感器阈值信息
|
|
|
+ SensorInfo sensorInfo = sensorInfoService.getBySensorId(seq, deviceId);//获取传感器信息
|
|
|
+ if (thresholds.size() > 0) {
|
|
|
+ //code:0
|
|
|
+ DeviceThreshold thresholds_0 = thresholds.get(0);
|
|
|
+ double low_0 = thresholds_0.getLowValue();
|
|
|
+ double high_0 = thresholds_0.getHighValue();
|
|
|
+ //code:1
|
|
|
+ DeviceThreshold thresholds_1 = thresholds.get(1);
|
|
|
+ double low_1 = thresholds_1.getLowValue();
|
|
|
+ double high_1 = thresholds_1.getHighValue();
|
|
|
+ //code:2
|
|
|
+ DeviceThreshold thresholds_2 = thresholds.get(2);
|
|
|
+ double low_2 = thresholds_2.getLowValue();
|
|
|
+ double high_2 = thresholds_2.getHighValue();
|
|
|
+ //code:3
|
|
|
+ DeviceThreshold thresholds_3 = thresholds.get(3);
|
|
|
+ double low_3 = thresholds_3.getLowValue();
|
|
|
+ double high_3 = thresholds_3.getHighValue();
|
|
|
+ //code:4
|
|
|
+ DeviceThreshold thresholds_4 = thresholds.get(4);
|
|
|
+ double low_4 = thresholds_4.getLowValue();
|
|
|
+ double high_4 = thresholds_4.getHighValue();
|
|
|
+ if (val >= low_0 && val <= high_0) {//状态0
|
|
|
+ data.setStatus(0);
|
|
|
+ data1.setStatus(0);
|
|
|
+ }
|
|
|
+ if ((val < low_0 && val >= low_1) || (val > high_0 && val <= high_1)) {//状态1
|
|
|
+// ServerAlarm alarm = new ServerAlarm();
|
|
|
+// alarm.setToken(token);
|
|
|
+// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
+// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
+// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
+// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
+// alarm.setAlarmData(val + "");
|
|
|
+// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
+// alarm.setDataLevel(1 + "");
|
|
|
+// alarm.setAlarmTime(reportTime);
|
|
|
+// String thirdPartyId = alarmPost(alarm);
|
|
|
+// AlarmEvent event = new AlarmEvent();
|
|
|
+// event.setDeviceId(deviceId);
|
|
|
+// event.setSensorId(seq);
|
|
|
+// event.setAlarmTime(nowDate);
|
|
|
+// event.setAlarmLevel(1 + "");
|
|
|
+// event.setEventStatus(1);
|
|
|
+// event.setIsreport(1);
|
|
|
+// event.setThirdPartyId(thirdPartyId);
|
|
|
+// alarmEventService.save(event);
|
|
|
+ data.setStatus(1);
|
|
|
+ data1.setStatus(1);
|
|
|
+ }
|
|
|
+ if ((val < low_1 && val >= low_2) || (val > high_1 && val <= high_2)) {//状态2
|
|
|
+// ServerAlarm alarm = new ServerAlarm();
|
|
|
+// alarm.setToken(token);
|
|
|
+// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
+// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
+// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
+// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
+// alarm.setAlarmData(val + "");
|
|
|
+// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
+// alarm.setDataLevel(2 + "");
|
|
|
+// alarm.setAlarmTime(reportTime);
|
|
|
+// String thirdPartyId = alarmPost(alarm);
|
|
|
+// AlarmEvent event = new AlarmEvent();
|
|
|
+// event.setDeviceId(deviceId);
|
|
|
+// event.setSensorId(seq);
|
|
|
+// event.setAlarmTime(nowDate);
|
|
|
+// event.setAlarmLevel(2 + "");
|
|
|
+// event.setEventStatus(1);
|
|
|
+// event.setIsreport(1);
|
|
|
+// event.setThirdPartyId(thirdPartyId);
|
|
|
+// alarmEventService.save(event);
|
|
|
+ data.setStatus(2);
|
|
|
+ data1.setStatus(2);
|
|
|
+ }
|
|
|
+ if ((val < low_2 && val >= low_3) || (val > high_2 && val <= high_3)) {//状态3
|
|
|
+// ServerAlarm alarm = new ServerAlarm();
|
|
|
+// alarm.setToken(token);
|
|
|
+// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
+// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
+// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
+// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
+// alarm.setAlarmData(val + "");
|
|
|
+// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
+// alarm.setDataLevel(3 + "");
|
|
|
+// alarm.setAlarmTime(reportTime);
|
|
|
+// String thirdPartyId = alarmPost(alarm);
|
|
|
+// AlarmEvent event = new AlarmEvent();
|
|
|
+// event.setDeviceId(deviceId);
|
|
|
+// event.setSensorId(seq);
|
|
|
+// event.setAlarmTime(nowDate);
|
|
|
+// event.setAlarmLevel(3 + "");
|
|
|
+// event.setEventStatus(1);
|
|
|
+// event.setIsreport(1);
|
|
|
+// event.setThirdPartyId(thirdPartyId);
|
|
|
+// alarmEventService.save(event);
|
|
|
+ data.setStatus(3);
|
|
|
+ data1.setStatus(3);
|
|
|
+ }
|
|
|
+ if ((val < low_3 && val >= low_4) || (val > high_3 && val <= high_4)) {//状态4
|
|
|
+// ServerAlarm alarm = new ServerAlarm();
|
|
|
+// alarm.setToken(token);
|
|
|
+// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
+// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
+// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
+// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
+// alarm.setAlarmData(val + "");
|
|
|
+// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
+// alarm.setDataLevel(4 + "");
|
|
|
+// alarm.setAlarmTime(reportTime);
|
|
|
+// String thirdPartyId = alarmPost(alarm);
|
|
|
+// AlarmEvent event = new AlarmEvent();
|
|
|
+// event.setDeviceId(deviceId);
|
|
|
+// event.setSensorId(seq);
|
|
|
+// event.setAlarmTime(nowDate);
|
|
|
+// event.setAlarmLevel(4 + "");
|
|
|
+// event.setEventStatus(1);
|
|
|
+// event.setIsreport(1);
|
|
|
+// event.setThirdPartyId(thirdPartyId);
|
|
|
+// alarmEventService.save(event);
|
|
|
+ data.setStatus(4);
|
|
|
+ data1.setStatus(4);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data.setStatus(0);
|
|
|
+ data1.setStatus(0);
|
|
|
+ }
|
|
|
+ liveDataService.acceptLiveData(data);
|
|
|
+ historyDataService.save(data1);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error(e.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ return new AsyncResult<String>("完成");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public Future<String> liveTask(Map<String, Object> liveData) {
|
|
|
+ try {
|
|
|
+ String token = "8a81e3166b379ce3016b37bab1bc000d";
|
|
|
+ String reportTime = (String) liveData.get("CreateDataTime");
|
|
|
+ String deviceId = String.valueOf(liveData.get("deviceId"));//获取设备编号
|
|
|
+ DeviceInfo deviceInfo = deviceInfoService.getDeviceInfoById(deviceId);
|
|
|
+ if (deviceInfo != null) {
|
|
|
+ String startTime = deviceInfo.getWorkTimeFrom();
|
|
|
+ String endTime = deviceInfo.getWorkTimeTo();
|
|
|
+ SimpleDateFormat sf = new SimpleDateFormat("HH:mm:ss");
|
|
|
+ String now = sf.format(new Date());//获取当前时间
|
|
|
+ Date nowDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(reportTime);
|
|
|
+ //如果未设置时间或者当前时间在工作范围内
|
|
|
+ if (CommonUtils.isEffectiveDate(sf.parse(now), sf.parse(startTime), sf.parse(endTime))) {
|
|
|
+ int count = sensorInfoService.getSensorCount(deviceId);//获取该设备下的传感器数量
|
|
|
+ if (count > 0) {
|
|
|
+ for (int i = 0; i < count; i++) {//循环插入数据库
|
|
|
+ String seq = "m" + (i + 1);//传感器编号
|
|
|
+ double val = Double.valueOf(liveData.get(seq) + "");
|
|
|
+ LiveData data = new LiveData();
|
|
|
+ data.setDeviceId(deviceId);
|
|
|
+ data.setReportTime(reportTime);
|
|
|
+ data.setSensorId(seq);
|
|
|
+ data.setDataValue(val);
|
|
|
+ HistoryData data1 = new HistoryData();
|
|
|
+ data1.setDeviceId(deviceId);
|
|
|
+ data1.setReportTime(reportTime);
|
|
|
+ data1.setSensorId(seq);
|
|
|
+ data1.setDataValue(val);
|
|
|
+// String dateTime = (String) liveData.get("CreateDataTime");
|
|
|
+ List<DeviceThreshold> thresholds = deviceThresholdService.getThresholdsBySensorID(seq);//根据传感器编号获取传感器阈值信息
|
|
|
+ SensorInfo sensorInfo = sensorInfoService.getBySensorId(seq, deviceId);//获取传感器信息
|
|
|
+ if (thresholds.size() > 0) {
|
|
|
+ //code:0
|
|
|
+ DeviceThreshold thresholds_0 = thresholds.get(0);
|
|
|
+ double low_0 = thresholds_0.getLowValue();
|
|
|
+ double high_0 = thresholds_0.getHighValue();
|
|
|
+ //code:1
|
|
|
+ DeviceThreshold thresholds_1 = thresholds.get(1);
|
|
|
+ double low_1 = thresholds_1.getLowValue();
|
|
|
+ double high_1 = thresholds_1.getHighValue();
|
|
|
+ //code:2
|
|
|
+ DeviceThreshold thresholds_2 = thresholds.get(2);
|
|
|
+ double low_2 = thresholds_2.getLowValue();
|
|
|
+ double high_2 = thresholds_2.getHighValue();
|
|
|
+ //code:3
|
|
|
+ DeviceThreshold thresholds_3 = thresholds.get(3);
|
|
|
+ double low_3 = thresholds_3.getLowValue();
|
|
|
+ double high_3 = thresholds_3.getHighValue();
|
|
|
+ //code:4
|
|
|
+ DeviceThreshold thresholds_4 = thresholds.get(4);
|
|
|
+ double low_4 = thresholds_4.getLowValue();
|
|
|
+ double high_4 = thresholds_4.getHighValue();
|
|
|
+ if (val >= low_0 && val <= high_0) {//状态0
|
|
|
+ data.setStatus(0);
|
|
|
+ data1.setStatus(0);
|
|
|
+ }
|
|
|
+ if ((val < low_0 && val >= low_1) || (val > high_0 && val <= high_1)) {//状态1
|
|
|
+// ServerAlarm alarm = new ServerAlarm();
|
|
|
+// alarm.setToken(token);
|
|
|
+// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
+// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
+// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
+// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
+// alarm.setAlarmData(val + "");
|
|
|
+// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
+// alarm.setDataLevel(1 + "");
|
|
|
+// alarm.setAlarmTime(reportTime);
|
|
|
+// String thirdPartyId = alarmPost(alarm);
|
|
|
+// AlarmEvent event = new AlarmEvent();
|
|
|
+// event.setDeviceId(deviceId);
|
|
|
+// event.setSensorId(seq);
|
|
|
+// event.setAlarmTime(nowDate);
|
|
|
+// event.setAlarmLevel(1 + "");
|
|
|
+// event.setEventStatus(1);
|
|
|
+// event.setIsreport(1);
|
|
|
+// event.setThirdPartyId(thirdPartyId);
|
|
|
+// alarmEventService.save(event);
|
|
|
+ data.setStatus(1);
|
|
|
+ data1.setStatus(1);
|
|
|
+ }
|
|
|
+ if ((val < low_1 && val >= low_2) || (val > high_1 && val <= high_2)) {//状态2
|
|
|
+// ServerAlarm alarm = new ServerAlarm();
|
|
|
+// alarm.setToken(token);
|
|
|
+// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
+// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
+// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
+// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
+// alarm.setAlarmData(val + "");
|
|
|
+// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
+// alarm.setDataLevel(2 + "");
|
|
|
+// alarm.setAlarmTime(reportTime);
|
|
|
+// String thirdPartyId = alarmPost(alarm);
|
|
|
+// AlarmEvent event = new AlarmEvent();
|
|
|
+// event.setDeviceId(deviceId);
|
|
|
+// event.setSensorId(seq);
|
|
|
+// event.setAlarmTime(nowDate);
|
|
|
+// event.setAlarmLevel(2 + "");
|
|
|
+// event.setEventStatus(1);
|
|
|
+// event.setIsreport(1);
|
|
|
+// event.setThirdPartyId(thirdPartyId);
|
|
|
+// alarmEventService.save(event);
|
|
|
+ data.setStatus(2);
|
|
|
+ data1.setStatus(2);
|
|
|
+ }
|
|
|
+ if ((val < low_2 && val >= low_3) || (val > high_2 && val <= high_3)) {//状态3
|
|
|
+// ServerAlarm alarm = new ServerAlarm();
|
|
|
+// alarm.setToken(token);
|
|
|
+// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
+// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
+// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
+// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
+// alarm.setAlarmData(val + "");
|
|
|
+// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
+// alarm.setDataLevel(3 + "");
|
|
|
+// alarm.setAlarmTime(reportTime);
|
|
|
+// String thirdPartyId = alarmPost(alarm);
|
|
|
+// AlarmEvent event = new AlarmEvent();
|
|
|
+// event.setDeviceId(deviceId);
|
|
|
+// event.setSensorId(seq);
|
|
|
+// event.setAlarmTime(nowDate);
|
|
|
+// event.setAlarmLevel(3 + "");
|
|
|
+// event.setEventStatus(1);
|
|
|
+// event.setIsreport(1);
|
|
|
+// event.setThirdPartyId(thirdPartyId);
|
|
|
+// alarmEventService.save(event);
|
|
|
+ data.setStatus(3);
|
|
|
+ data1.setStatus(3);
|
|
|
+ }
|
|
|
+ if ((val < low_3 && val >= low_4) || (val > high_3 && val <= high_4)) {//状态4
|
|
|
+// ServerAlarm alarm = new ServerAlarm();
|
|
|
+// alarm.setToken(token);
|
|
|
+// alarm.setCompanyId(deviceInfo.getCompanyId());
|
|
|
+// alarm.setCompanyName(deviceInfo.getCompanyName());
|
|
|
+// alarm.setAlarmType(sensorInfo.getSensorName() + "超限");
|
|
|
+// alarm.setAlarmDevice(deviceInfo.getDeviceName());
|
|
|
+// alarm.setAlarmData(val + "");
|
|
|
+// alarm.setDataUnit(sensorInfo.getSensorUnit());
|
|
|
+// alarm.setDataLevel(4 + "");
|
|
|
+// alarm.setAlarmTime(reportTime);
|
|
|
+// String thirdPartyId = alarmPost(alarm);
|
|
|
+// AlarmEvent event = new AlarmEvent();
|
|
|
+// event.setDeviceId(deviceId);
|
|
|
+// event.setSensorId(seq);
|
|
|
+// event.setAlarmTime(nowDate);
|
|
|
+// event.setAlarmLevel(4 + "");
|
|
|
+// event.setEventStatus(1);
|
|
|
+// event.setIsreport(1);
|
|
|
+// event.setThirdPartyId(thirdPartyId);
|
|
|
+// alarmEventService.save(event);
|
|
|
+ data.setStatus(4);
|
|
|
+ data1.setStatus(4);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ data.setStatus(0);
|
|
|
+ data1.setStatus(0);
|
|
|
+ }
|
|
|
+ liveDataService.acceptLiveData(data);
|
|
|
+ historyDataService.save(data1);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } 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");
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 返回uuid
|
|
|
+ *
|
|
|
+ * @param alarm
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String alarmPost(ServerAlarm alarm) {
|
|
|
+ String url = "http://zhzf.sipac.gov.cn/szyqaj/app/common/alarmSave";
|
|
|
+ String json = JSON.toJSONString(alarm);
|
|
|
+ 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");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|