|
@@ -4,7 +4,12 @@ import com.alibaba.fastjson.JSON;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.persagy.apm.energyalarmstarter.alarmdata.mq.model.DmpMessage;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmengine.constants.RedisConstants;
|
|
|
import com.persagy.apm.energyalarmstarter.alarmengine.feign.AlarmCondition;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmengine.feign.ObjConditionRel;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmengine.jms.model.ItemCodeCondition;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmengine.jms.model.ObjConditionInfo;
|
|
|
+import com.persagy.apm.energyalarmstarter.alarmengine.redis.RedisUtil;
|
|
|
import com.persagy.apm.energyalarmstarter.alarmengine.service.AlarmRecordMsgHandler;
|
|
|
import io.netty.channel.ChannelHandler;
|
|
|
import lombok.SneakyThrows;
|
|
@@ -15,6 +20,7 @@ import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import javax.annotation.Resource;
|
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -33,6 +39,9 @@ public class AlarmEngineMsgHandler {
|
|
|
@Resource(name = "alarmRedisTemplate")
|
|
|
private RedisTemplate<String, String> alarmRedisTemplate;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private RedisUtil redisUtil;
|
|
|
+
|
|
|
@SneakyThrows
|
|
|
public String getAlarmCategory(DmpMessage dmpMessage) {
|
|
|
JSONObject data = dmpMessage.getExts();
|
|
@@ -136,8 +145,63 @@ public class AlarmEngineMsgHandler {
|
|
|
* @version V1.0 2021/10/26 7:51 下午
|
|
|
*/
|
|
|
public void syncNewObjConditionRelList(DmpMessage msg) {
|
|
|
- JSONArray createdRelList = JSONObject.parseArray(msg.getStr1());
|
|
|
- // TODO: 2021/11/16 更新redis
|
|
|
+ List<ObjConditionRel> createdRelList = JSONObject.parseArray(msg.getStr1(), ObjConditionRel.class);
|
|
|
+ syncCreatedObjConditionRelList2Redis(createdRelList);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 新的设备与报警条件关联关系同步至redis
|
|
|
+ *
|
|
|
+ * @param createdRelList 新增的关联关系
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/11/20 5:29 下午
|
|
|
+ */
|
|
|
+ private void syncCreatedObjConditionRelList2Redis(List<ObjConditionRel> createdRelList) {
|
|
|
+ if (CollectionUtils.isEmpty(createdRelList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (ObjConditionRel objConditionRel : createdRelList) {
|
|
|
+ // 报警对象id
|
|
|
+ String objId = objConditionRel.getObjId();
|
|
|
+ // 报警对象和报警条件的关联信息
|
|
|
+ ObjConditionInfo objConditionInfo = redisUtil.get(RedisConstants.OBJ_CONDITION_REL, objId, ObjConditionInfo.class);
|
|
|
+ if (objConditionInfo == null) {
|
|
|
+ objConditionInfo = new ObjConditionInfo(objConditionRel.getProjectId());
|
|
|
+ }
|
|
|
+ ItemCodeCondition condition = new ItemCodeCondition();
|
|
|
+ condition.setConditionId(objConditionRel.getConditionId());
|
|
|
+ condition.setItemCode(objConditionRel.getItemCode());
|
|
|
+ // 对象内部自己做去重操作
|
|
|
+ objConditionInfo.addCondition(condition);
|
|
|
+ redisUtil.put(RedisConstants.OBJ_CONDITION_REL, objId, JSON.toJSONString(objConditionInfo));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除的设备与报警条件关联关系同步至redis
|
|
|
+ *
|
|
|
+ * @param deletedRelList 删除的关联关系
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/11/20 5:29 下午
|
|
|
+ */
|
|
|
+ private void syncDeletedObjConditionRelList2Redis(List<ObjConditionRel> deletedRelList) {
|
|
|
+ if (CollectionUtils.isEmpty(deletedRelList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ for (ObjConditionRel objConditionRel : deletedRelList) {
|
|
|
+ // 报警对象id
|
|
|
+ String objId = objConditionRel.getObjId();
|
|
|
+ ObjConditionInfo objConditionInfo = redisUtil.get(RedisConstants.OBJ_CONDITION_REL, objId, ObjConditionInfo.class);
|
|
|
+ ItemCodeCondition condition = new ItemCodeCondition();
|
|
|
+ condition.setConditionId(objConditionRel.getConditionId());
|
|
|
+ condition.setItemCode(objConditionRel.getItemCode());
|
|
|
+ objConditionInfo.removeCondition(condition);
|
|
|
+ if (CollectionUtils.isEmpty(objConditionInfo.getConditions())) {
|
|
|
+ redisUtil.delete(RedisConstants.OBJ_CONDITION_REL, objId);
|
|
|
+ } else {
|
|
|
+ redisUtil.put(RedisConstants.OBJ_CONDITION_REL, objId, JSON.toJSONString(objConditionInfo));
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -148,15 +212,16 @@ public class AlarmEngineMsgHandler {
|
|
|
* @version V1.0 2021/10/26 7:51 下午
|
|
|
*/
|
|
|
public void syncDeletedObjConditionRelList(DmpMessage msg) {
|
|
|
- JSONArray deletedRelList = JSONObject.parseArray(msg.getStr1());
|
|
|
- // TODO: 2021/11/16 更新redis
|
|
|
+ List<ObjConditionRel> deletedRelList = JSONObject.parseArray(msg.getStr1(), ObjConditionRel.class);
|
|
|
+ syncDeletedObjConditionRelList2Redis(deletedRelList);
|
|
|
}
|
|
|
|
|
|
public void syncUpdateObjConditionRelList(DmpMessage msg) {
|
|
|
- JSONArray deletedRelList = JSONObject.parseArray(msg.getStr1());
|
|
|
- JSONArray createdRelList = JSONObject.parseArray(msg.getStr2());
|
|
|
+ List<ObjConditionRel> deletedRelList = JSONObject.parseArray(msg.getStr1(), ObjConditionRel.class);
|
|
|
+ List<ObjConditionRel> createdRelList = JSONObject.parseArray(msg.getStr2(), ObjConditionRel.class);
|
|
|
// 先删除,再创建
|
|
|
- // TODO: 2021/11/16 更新redis
|
|
|
+ syncDeletedObjConditionRelList2Redis(deletedRelList);
|
|
|
+ syncCreatedObjConditionRelList2Redis(createdRelList);
|
|
|
}
|
|
|
|
|
|
/**
|