|
@@ -474,4 +474,90 @@ public class GroupAlarmRuleServiceImpl extends ServiceImpl<GroupAlarmRuleMapper,
|
|
|
queryWrapper.eq(GroupAlarmRule.PROP_VALID, ValidEnum.TRUE.getType());
|
|
|
return list(queryWrapper);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 创建集团报警规则
|
|
|
+ *
|
|
|
+ * @return 集团报警规则主键
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021-09-08 22:35:45
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public String createGroupAlarmRulePM(AddGroupAlarmRuleDTO addGroupAlarmRuleDTO) throws Exception {
|
|
|
+ //1、给某个设备分组创建集团报警
|
|
|
+ GroupAlarmRule groupAlarmRule = ConvertGroupAlarmRuleTool.INSTANCE.convertAddDto2Entity(addGroupAlarmRuleDTO);
|
|
|
+ AddAlarmConditionDTO alarmCondition = addGroupAlarmRuleDTO.getAlarmCondition();
|
|
|
+ Map<String, Object> conditionMap = alarmConditionService.createAlarmCondition(alarmCondition);
|
|
|
+ //创建集团报警
|
|
|
+ groupAlarmRule.setAlarmConditionId((String) conditionMap.get("id"));
|
|
|
+ setDefaultValue(groupAlarmRule);
|
|
|
+ save(groupAlarmRule);
|
|
|
+ //2、异步创建项目报警
|
|
|
+ String userId = PoemsContext.getContext().getUserId();
|
|
|
+ String groupCode = PoemsContext.getContext().getGroupCode();
|
|
|
+ String projectId = PoemsContext.getContext().getProjectId();
|
|
|
+ String pd = PoemsContext.getContext().getPd();
|
|
|
+ String loginDevice = PoemsContext.getContext().getLoginDevice();
|
|
|
+ executor.execute(() -> {
|
|
|
+ // 切换线程需要重新设置线程中的通用变量
|
|
|
+ PoemsContext.setContext(userId, loginDevice, pd, groupCode, projectId);
|
|
|
+ projectAlarmRuleService.addProjectAlarmRulesPM(addGroupAlarmRuleDTO);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 勿删,后续有可能恢复 lixing
|
|
|
+// List<ProjectVO> projects = projectAlarmRuleService.getProject();
|
|
|
+// if (projects.size() == 0) {
|
|
|
+// throw new Exception("获取项目为空");
|
|
|
+// }
|
|
|
+// //3、同步创建设备报警条件
|
|
|
+// List<AddAlarmConfigDTO> alarmConfigs = new ArrayList<>();
|
|
|
+// String condition = addGroupAlarmRuleDTO.getCondition();
|
|
|
+// String classCode = addGroupAlarmRuleDTO.getClassCode();
|
|
|
+// for (ProjectVO project : projects) {
|
|
|
+// QueryEquipDTO queryEquipDTO = new QueryEquipDTO();
|
|
|
+// queryEquipDTO.setProjectId(projectId);
|
|
|
+// queryEquipDTO.setClassCode(classCode);
|
|
|
+// queryEquipDTO.setCondition(condition);
|
|
|
+// List<EquipItem> record = groupManagementService.getEquipList(queryEquipDTO);
|
|
|
+// for (EquipItem rec : record) {
|
|
|
+// AddAlarmConfigDTO addAlarmConfigDTO = new AddAlarmConfigDTO();
|
|
|
+// String equipId = rec.getId();
|
|
|
+// addAlarmConfigDTO.setObjId(equipId);
|
|
|
+// addAlarmConfigDTO.setItemCode(addGroupAlarmRuleDTO.getAlarmItemCode());
|
|
|
+// addAlarmConfigDTO.setClassCode(addGroupAlarmRuleDTO.getClassCode());
|
|
|
+// addAlarmConfigDTO.setLevel(alarmCondition.getAlarmLevel());
|
|
|
+// addAlarmConfigDTO.setCategory("Eqdx");
|
|
|
+// addAlarmConfigDTO.setOpen(1);
|
|
|
+// AlarmCondition cond = new AlarmCondition();
|
|
|
+// List<String> infoCodeList = (List<String>) conditionMap.get("infoCode");
|
|
|
+// List<String> infoCodeNew = new ArrayList<>();
|
|
|
+// for (String infoCode : infoCodeList) {
|
|
|
+// String replacement = equipId + "_" + infoCode;
|
|
|
+// infoCodeNew.add(infoCode.replaceAll(infoCode, replacement));
|
|
|
+// }
|
|
|
+// cond.setInfoCode(infoCodeNew);
|
|
|
+// String backend = (String) conditionMap.get("backend");
|
|
|
+// for (String infoCode : infoCodeList) {
|
|
|
+// String replacement = equipId + "_" + infoCode;
|
|
|
+// backend = backend.replaceAll(infoCode, replacement);
|
|
|
+// }
|
|
|
+// cond.setEnd("!" + backend);
|
|
|
+// cond.setEndUphold(0);
|
|
|
+// cond.setTrigger(backend);
|
|
|
+// cond.setTriggerUphold(alarmCondition.getTriggerUphold() * 60);
|
|
|
+// cond.setRules((List<String>) conditionMap.get("displayFormula"));
|
|
|
+// JSONArray configs = JSONArray.parseArray(JSON.toJSONString(alarmCondition.getFrontend()));
|
|
|
+// cond.setConfigs(configs);
|
|
|
+// AlarmEffectTime effectTime = new AlarmEffectTime();
|
|
|
+// effectTime.setType("always");
|
|
|
+// cond.setEffectTime(effectTime);
|
|
|
+// addAlarmConfigDTO.setCondition(cond);
|
|
|
+// alarmConfigs.add(addAlarmConfigDTO);
|
|
|
+// }
|
|
|
+// projectAlarmRuleService.sendBatchCreateAlarmConfigMsg(alarmConfigs, projectId);
|
|
|
+// }
|
|
|
+ return groupAlarmRule.getId();
|
|
|
+ }
|
|
|
+
|
|
|
}
|