Browse Source

报警对象bug修改

xujiaheng 3 years ago
parent
commit
b9573b32ad

+ 11 - 20
src/main/java/com/persagy/apm/alarmservice/project/alarmruleobjrel/service/impl/ProjectAlarmRuleObjRelServiceImpl.java

@@ -361,8 +361,8 @@ public class ProjectAlarmRuleObjRelServiceImpl extends ServiceImpl<ProjectAlarmR
     @Override
     public List<ProjectAlarmRuleObjRelListItemVO> queryRuleObjRel(QueryRuleObjRelDTO queryRuleObjRelDTO) {
         List<ProjectAlarmRuleObjRel> resultList = new ArrayList<>();
-        if (StringUtils.isNotBlank(queryRuleObjRelDTO.getProjectAlarmRuleId())) {
-            //查询每条项目报警下的报警对象
+        if(StringUtils.isNotBlank(queryRuleObjRelDTO.getProjectAlarmRuleId())){
+            //1、查询项目报警下的未屏蔽的报警对象
             QueryWrapper<ProjectAlarmRuleObjRel> queryWrapper = new QueryWrapper<>();
             queryWrapper.eq(ProjectAlarmRuleObjRel.PROP_PROJECT_ALARM_RULE_ID, queryRuleObjRelDTO.getProjectAlarmRuleId());
             queryWrapper.eq(ProjectAlarmRuleObjRel.PROP_VALID, ValidEnum.TRUE.getType());
@@ -371,6 +371,7 @@ public class ProjectAlarmRuleObjRelServiceImpl extends ServiceImpl<ProjectAlarmR
             list.stream().map(ProjectAlarmRuleObjRel::getObjId).distinct().collect(Collectors.toList());
             resultList.addAll(list);
         }
+        //2、查询未绑定的报警对象(未屏蔽、未关联)
         //查询所有设备(报警对象)
         String projectId = queryRuleObjRelDTO.getProjectId();
         QueryEquipDTO queryEquipDTO = new QueryEquipDTO();
@@ -378,19 +379,16 @@ public class ProjectAlarmRuleObjRelServiceImpl extends ServiceImpl<ProjectAlarmR
         queryEquipDTO.setClassCode(queryRuleObjRelDTO.getClassCode());
         queryEquipDTO.setCondition(queryRuleObjRelDTO.getCondition());
         List<EquipItem> records = groupManagementService.getEquipList(queryEquipDTO);
-        //查询项目下所有已绑定的报警对象
+        //查询该报警类型下所有(可能有多个相同报警类型的项目报警)已绑定的报警对象
         List<String> projectAlarmRuleIdList = projectAlarmRuleService.queryAlarmRule(queryRuleObjRelDTO);
         Map<String, ProjectAlarmRuleObjRel> partitionMap = new HashMap<>();
-        if (projectAlarmRuleIdList.size() > 0){
-            QueryWrapper<ProjectAlarmRuleObjRel> queryWrapper = new QueryWrapper<>();
-            queryWrapper.eq(ProjectAlarmRuleObjRel.PROP_PROJECT_ID, projectId);
-            queryWrapper.in(ProjectAlarmRuleObjRel.PROP_PROJECT_ALARM_RULE_ID, projectAlarmRuleIdList);
-            queryWrapper.eq(ProjectAlarmRuleObjRel.PROP_VALID, ValidEnum.TRUE.getType());
-            //新增项目报警,要把屏蔽的查出来
-            if (StringUtils.isBlank(queryRuleObjRelDTO.getProjectAlarmRuleId()))
-                queryWrapper.eq(ProjectAlarmRuleObjRel.PROP_OPEN, 1);
-            List<ProjectAlarmRuleObjRel> list = list(queryWrapper);
-            partitionMap = list.stream().collect(Collectors.toMap(ProjectAlarmRuleObjRel::getObjId, equip -> equip, (k1, k2) -> k1));
+        if (projectAlarmRuleIdList.size() > 0) {
+            QueryWrapper<ProjectAlarmRuleObjRel> wrapper = new QueryWrapper<>();
+            wrapper.eq(ProjectAlarmRuleObjRel.PROP_PROJECT_ID, projectId);
+            wrapper.in(ProjectAlarmRuleObjRel.PROP_PROJECT_ALARM_RULE_ID, projectAlarmRuleIdList);
+            wrapper.eq(ProjectAlarmRuleObjRel.PROP_VALID, ValidEnum.TRUE.getType());
+            List<ProjectAlarmRuleObjRel> listRel = list(wrapper);
+            partitionMap = listRel.stream().collect(Collectors.toMap(ProjectAlarmRuleObjRel::getObjId, equip -> equip, (k1, k2) -> k1));
         }
         //筛选未绑定的报警对象
         for (EquipItem record : records) {
@@ -404,13 +402,6 @@ public class ProjectAlarmRuleObjRelServiceImpl extends ServiceImpl<ProjectAlarmR
                 resultList.add(projectAlarmRuleObjRelVO);
             }
         }
-        //去掉已屏蔽的对象
-        Iterator<ProjectAlarmRuleObjRel> iterator = resultList.iterator();
-        while (iterator.hasNext()) {
-            ProjectAlarmRuleObjRel next = iterator.next();
-            if (next.getOpen() == 0)
-                iterator.remove();
-        }
         return ConvertProjectAlarmRuleObjRelTool.INSTANCE.convert2List(resultList);
     }