|
@@ -0,0 +1,99 @@
|
|
|
+package com.persagy.apm.diagnose.maintenance.controller;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.persagy.apm.diagnose.config.RabbitConfig;
|
|
|
+import com.persagy.apm.diagnose.maintenance.constant.EnumAlarmItem;
|
|
|
+import com.persagy.apm.diagnose.maintenance.constant.EnumMaintenanceIndicatorType;
|
|
|
+import com.persagy.apm.diagnose.utils.RedisLock;
|
|
|
+import com.persagy.apm.diagnose.utils.RedisUtil;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.validation.annotation.Validated;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import java.util.LinkedHashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Api(tags = "维保数据历史记录")
|
|
|
+@Validated
|
|
|
+@RestController
|
|
|
+@RequestMapping("monitorIndicatorRecords")
|
|
|
+public class MaintenanceController {
|
|
|
+ @Autowired
|
|
|
+ private RedisLock lockUtil;
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+ @Autowired
|
|
|
+ private RabbitConfig rabbitConfig;
|
|
|
+
|
|
|
+ @PostMapping("/sendData")
|
|
|
+ public void sendData() throws Exception {
|
|
|
+
|
|
|
+ Map<String, Boolean> iotDataMap = new LinkedHashMap<>();
|
|
|
+ iotDataMap.put("10", true);
|
|
|
+ iotDataMap.put("11", true);
|
|
|
+ iotDataMap.put("12", false);
|
|
|
+ iotDataMap.put("13", true);
|
|
|
+ iotDataMap.put("14", true);
|
|
|
+ iotDataMap.put("15", true);
|
|
|
+ iotDataMap.put("16", false);
|
|
|
+ iotDataMap.put("17", true);
|
|
|
+ iotDataMap.put("18", true);
|
|
|
+
|
|
|
+ String objId = "Eq1101060001f00f2ed121f9407783ac0f0a520a9616", alarmItemCode=EnumAlarmItem.EvapAbnormal.getCode();
|
|
|
+ String lockKey = objId+"-"+alarmItemCode;
|
|
|
+ Object isLock = redisUtil.get(lockKey);
|
|
|
+ if (null != isLock){
|
|
|
+ long time = System.currentTimeMillis() + (10 * 1000);
|
|
|
+ lockUtil.lock(lockKey, String.valueOf(time));
|
|
|
+ JSONArray array = getSendArray(iotDataMap,objId,alarmItemCode);
|
|
|
+ //推送
|
|
|
+ rabbitConfig.sendMsg(array);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONArray getSendArray(Map<String, Boolean> iotDataMap,String objId,String alarmItemCode) {
|
|
|
+ if (iotDataMap == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ JSONArray array = new JSONArray();
|
|
|
+ for (String time : iotDataMap.keySet()) {
|
|
|
+ if (iotDataMap.get(time)) {
|
|
|
+ array.add(getTriggerData(time,objId,alarmItemCode));
|
|
|
+ } else {
|
|
|
+ array.add(getNormalData(time,objId,alarmItemCode));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return array;
|
|
|
+ }
|
|
|
+
|
|
|
+ //触发报警
|
|
|
+ public JSONObject getTriggerData(String time,String objId,String alarmItemCode) {
|
|
|
+ return initJSONObject("202111"+time+"000000",objId,alarmItemCode,5.0,2.0);
|
|
|
+ }
|
|
|
+ //恢复
|
|
|
+ public JSONObject getNormalData(String time,String objId,String alarmItemCode) {
|
|
|
+ return initJSONObject("202111"+time+"000000",objId,alarmItemCode,1.0,0.0);
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject initJSONObject(String dataTime,String objId,String alarmItemCode,Double value1,Double value2){
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("dataTime",dataTime);
|
|
|
+ jsonObject.put("itemCode", alarmItemCode);
|
|
|
+ jsonObject.put("meterId",objId);
|
|
|
+ JSONArray funcIdArray = new JSONArray();
|
|
|
+ funcIdArray.add(EnumMaintenanceIndicatorType.ACCCCC_EvapHeatTransferDayAvg);//换热端差日维度平均值阈值
|
|
|
+ funcIdArray.add(EnumMaintenanceIndicatorType.ACCCCC_EvapContinuousOperation.getCode());//运行持续时间
|
|
|
+ JSONArray valueArray = new JSONArray();
|
|
|
+ valueArray.add(value1);
|
|
|
+ valueArray.add(value2);
|
|
|
+ jsonObject.put("funcId",funcIdArray);
|
|
|
+ jsonObject.put("value",valueArray);
|
|
|
+ return jsonObject;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|