Ver Fonte

挂墙终端接口返回数据修改

xujie há 1 ano atrás
pai
commit
062b7cf929

+ 31 - 113
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotBoardServiceImpl.java

@@ -181,8 +181,10 @@ public class IotBoardServiceImpl implements IotBoardService {
     public Map<String, Object> iotOverview(Long orgId) {
         List<SysOrgVO> cacheList = RedisUtils.getCacheList(CacheConstants.ORG_CACHE_LIST_KEY);
 
-        List<String> alarmTypeList = Lists.newArrayList("水浸告警", "温湿度告警", "烟感告警", "燃气告警", "门磁告警", "防盗告警","8小时回路告警","24小时回路告警");
-        List<String> productTypeList = Lists.newArrayList("FSU_Water", "FSU_TemperatureAndHumidity", "FSU_Smoke", "FSU_Gas", "FSU_DoorMagnetic", "FSU_Theft","FSU_DoPowerCollection8Hour","FSU_DoPowerCollection24Hour");
+        Map<String, String> alarmTypeAndDesc = getAlarmTypeAndDesc();
+        List<String> productTypeList = new ArrayList<>(alarmTypeAndDesc.keySet());
+        //8小时回路和24小时回路的product_type都是FSU_DoPowerCollection
+        productTypeList.add("FSU_DoPowerCollection");
 
         Map<String, Object> map = new HashMap<>();
         Map<String, Object> dataMap = new HashMap<>();
@@ -201,7 +203,7 @@ public class IotBoardServiceImpl implements IotBoardService {
         map.put("normal", 0);
         map.put("alarm", 0);
         if (ObjectUtil.isEmpty(list)) {
-            buildEmptyData(resultList, alarmTypeList);
+            //buildEmptyData(resultList, alarmTypeList);
             return dataMap;
         }
         Map<Integer, Long> collect = list.stream().collect(Collectors.groupingBy(DeviceDetailInfoVo::getState, Collectors.counting()));
@@ -213,6 +215,15 @@ public class IotBoardServiceImpl implements IotBoardService {
                 map.put("alarm", v.intValue());
             }
         });
+        Set<String> keySet = list.stream().collect(Collectors.groupingBy(DeviceDetailInfoVo::getDeviceProduct)).keySet();
+        List<String> deviceProductTypes = new ArrayList<>(keySet);
+        List<String> alarmTypeList = deviceProductTypes.stream().filter(alarmTypeAndDesc::containsKey).map(alarmTypeAndDesc::get).collect(Collectors.toList());
+        if (deviceProductTypes.contains("FSU_DoPowerCollection")){
+            alarmTypeList.add("8小时回路告警");
+            alarmTypeList.add("24小时回路告警");
+        }
+
+
         List<IotAlarmData> alarmDataList = alarmDataService.selectAlarmDataListByOrgPath(org.getPath(), 0);
         if (ObjectUtil.isEmpty(alarmDataList)) {
             buildEmptyData(resultList, alarmTypeList);
@@ -221,37 +232,19 @@ public class IotBoardServiceImpl implements IotBoardService {
         //屏蔽红外
         alarmDataList.removeIf(d -> ObjectUtil.equal(METER_ATTRIBUTES_4.getText(), d.getSourceTypeDes()));
         Map<Object, List<IotAlarmData>> dataList = alarmDataList.stream().collect(Collectors.groupingBy(IotAlarmData::getSourceType));
-
-
-        //查询当前登录用户需要通知的告警类型
-        LoginUser loginUser = SecurityUtils.getLoginUser();
-        List<Long> roleIds = null;
-        List<SysRole> sysRoles = loginUser.getSysUser().getRoles();
-        if (sysRoles != null && !sysRoles.isEmpty()) {
-            roleIds = sysRoles.stream().map(SysRole::getId).collect(Collectors.toList());
-        }
-        List<String> productTypes = coreNoticeRuleItemService.getNoticeProductTypesByUser(roleIds, orgId, loginUser.getUserid());
-
-
         for (Map.Entry<Object, List<IotAlarmData>> listEntry : dataList.entrySet()) {
             List<IotAlarmData> value = listEntry.getValue();
             Map<String, Object> hashMap = new HashMap<>();
             long currentAlarm = value.stream().filter(d -> ObjectUtil.isNull(d.getEndTime())).count();
             long unDealAlarm = value.stream().filter(d -> ObjectUtil.isNull(d.getDoTime())).count();
-            int needAlarm = value.stream().anyMatch(d -> ObjectUtil.isNull(d.getEndTime()) && ObjectUtil.isNull(d.getDoTime())) ? 1 : 0;
-            needAlarm = (needAlarm == 1 && productTypes.contains(value.get(0).getSourceType())) ? 1 : 0;
+            long needAlarm = value.stream().anyMatch(d -> ObjectUtil.isNull(d.getEndTime()) && ObjectUtil.isNull(d.getDoTime())) ? 1 : 0;
 
             hashMap.put("key", value.get(0).getSourceTypeDes());
             hashMap.put("historyAlarm", value.size());
             hashMap.put("currentAlarm", (int) currentAlarm);
             hashMap.put("unDealAlarm", (int) unDealAlarm);
-
-            List<AppAlarmDataPageVo> pageVos = getAlarmDataList(value, listEntry.getKey().toString(), cacheList, needAlarm);
-            hashMap.put("currentAlarmData", pageVos);
-
-            needAlarm = pageVos.stream().anyMatch(d -> ObjectUtil.equal(d.getNeedAlarm(), 1)) ? 1 : 0;
-            hashMap.put("needAlarm", needAlarm);
-
+            hashMap.put("needAlarm", (int) needAlarm);
+            hashMap.put("currentAlarmData", getAlarmDataList(value, listEntry.getKey().toString(), cacheList));
             resultList.add(hashMap);
         }
         List<String> keyList = resultList.stream().map(m -> m.get("key")).distinct().map(String::valueOf).collect(Collectors.toList());
@@ -269,16 +262,10 @@ public class IotBoardServiceImpl implements IotBoardService {
             }
         }
 
-        //查询通知规则中通知机构为当前机构的数据
-        List<Long> orgIdList = coreNoticeRuleItemService.getOrgIdsByNoticeOrgId(orgId);
-        if (orgIdList != null && orgIdList.size() > 0) {
-            handleOtherData(orgIdList,dataMap,roleIds,loginUser,cacheList);
-        }
-
         return dataMap;
     }
 
-    private List<AppAlarmDataPageVo> getAlarmDataList(List<IotAlarmData> dataList, String sourceType, List<SysOrgVO> cacheList,Integer needAlarm) {
+    private List<AppAlarmDataPageVo> getAlarmDataList(List<IotAlarmData> dataList, String sourceType, List<SysOrgVO> cacheList) {
         List<IotAlarmData> list = dataList.stream()
                 .filter(d -> ObjectUtil.equal(d.getSourceType(), sourceType))
                 .filter(d -> ObjectUtil.isNull(d.getEndTime()))
@@ -305,7 +292,6 @@ public class IotBoardServiceImpl implements IotBoardService {
             vo.setDoByUser(alarmData.getDoByUser());
             vo.setDoType(alarmData.getDoType());
             vo.setDoContent(alarmData.getDoContent());
-            vo.setNeedAlarm(needAlarm);
             arrayList.add(vo);
 
         }
@@ -510,86 +496,18 @@ public class IotBoardServiceImpl implements IotBoardService {
         }
     }
 
-    /**
-     * @param orgIdList
-     * @param dataMap
-     * @param roleIds
-     * @param loginUser
-     */
-    private void handleOtherData(List<Long> orgIdList, Map<String, Object> dataMap,List<Long> roleIds,LoginUser loginUser,List<SysOrgVO> cacheList) {
-        //查询其他机构的数据
-        for (Long orgId : orgIdList) {
-            //根据用户ID和角色查询其他机构需要通知的类型
-            List<String> productTypes = coreNoticeRuleItemService.getNoticeProductTypesByNoticeUser(roleIds, orgId, loginUser.getOrgId(),loginUser.getUserid());
-            if (!(productTypes != null && productTypes.size() > 0)) {
-                continue;
-            }
-            List<DeviceDetailInfoVo> list = deviceInfoService.getByProductTypesAndOrgId(productTypes, orgId);
-            if (!(list != null && list.size() > 0)) {
-                continue;
-            }
-            Map<Integer, Long> otherCollect = list.stream().collect(Collectors.groupingBy(DeviceDetailInfoVo::getState, Collectors.counting()));
-            int normalCount = otherCollect.getOrDefault(0, 0L).intValue();
-            int alarmCount = otherCollect.getOrDefault(1, 0L).intValue();
-
-            Map<String,Object> sensorMap = (Map<String, Object>) dataMap.get("sensor");
-            sensorMap.put("sensorNums",(int)sensorMap.get("sensorNums") + list.size());
-            sensorMap.put("normal",(int)sensorMap.get("normal") + normalCount);
-            sensorMap.put("alarm",(int)sensorMap.get("alarm") + alarmCount);
-            dataMap.put("sensor", sensorMap);
-
-            List<IotAlarmData> alarmDataList = alarmDataService.getByProductTypesAndOrgId(productTypes,orgId, 0);
-            if (!(alarmDataList != null && alarmDataList.size() > 0)) {
-                continue;
-            }
-
-            List<Map<String, Object>> resultList = (List<Map<String, Object>>) dataMap.get("resultData");
-
-            //屏蔽红外
-            alarmDataList.removeIf(d -> ObjectUtil.equal(METER_ATTRIBUTES_4.getText(), d.getSourceTypeDes()));
-            Map<Object, List<IotAlarmData>> otherDataList = alarmDataList.stream().collect(Collectors.groupingBy(IotAlarmData::getSourceType));
-            for (Map.Entry<Object, List<IotAlarmData>> listEntry : otherDataList.entrySet()) {
-                List<IotAlarmData> value = listEntry.getValue();
-                long unDealAlarm = value.stream().filter(d -> ObjectUtil.isNull(d.getDoTime())).count();
-                long currentAlarm = value.stream().filter(d -> ObjectUtil.isNull(d.getEndTime())).count();
-                int needAlarm = value.stream().anyMatch(d -> ObjectUtil.isNull(d.getEndTime()) && ObjectUtil.isNull(d.getDoTime())) ? 1 : 0;
-                needAlarm = (needAlarm == 1 && productTypes.contains(value.get(0).getSourceType())) ? 1 : 0;
-
-
-                Optional<Map<String, Object>> optional = resultList.stream().filter(d -> d.get("key").equals(listEntry.getValue().get(0).getSourceTypeDes())).findFirst();
-                if (!optional.isPresent()){
-                    Map<String, Object> hashMap = new HashMap<>();
-                    hashMap.put("key", value.get(0).getSourceTypeDes());
-                    hashMap.put("currentAlarm", (int) currentAlarm);
-                    hashMap.put("unDealAlarm", (int) unDealAlarm);
-                    hashMap.put("historyAlarm", value.size());
-
-                    List<AppAlarmDataPageVo> pageVos = getAlarmDataList(value, listEntry.getKey().toString(), cacheList, needAlarm);
-                    hashMap.put("currentAlarmData", pageVos);
-
-                    needAlarm = pageVos.stream().anyMatch(d -> ObjectUtil.equal(d.getNeedAlarm(), 1)) ? 1 : 0;
-                    hashMap.put("needAlarm", needAlarm);
-
-                    resultList.add(hashMap);
-                }else {
-                    Map<String, Object> objectMap = optional.get();
-                    int index = resultList.indexOf(objectMap);
-                    objectMap.put("historyAlarm", (int) objectMap.get("historyAlarm") + value.size());
-                    objectMap.put("currentAlarm", (int) objectMap.get("currentAlarm") + (int) currentAlarm);
-                    objectMap.put("unDealAlarm", (int) objectMap.get("unDealAlarm") + (int) unDealAlarm);
-
-                    List<AppAlarmDataPageVo> dataList = (List<AppAlarmDataPageVo>) objectMap.get("currentAlarmData");
-                    dataList.addAll(getAlarmDataList(value, listEntry.getKey().toString(), cacheList, needAlarm));
-                    objectMap.put("currentAlarmData", dataList);
-
-                    needAlarm = dataList.stream().anyMatch(d -> ObjectUtil.equal(d.getNeedAlarm(), 1)) ? 1 : 0;
-                    objectMap.put("needAlarm", needAlarm);
-
-                    resultList.set(index,objectMap);
-                }
-            }
-
-            dataMap.put("resultData", resultList);
-        }
+    private Map<String,String> getAlarmTypeAndDesc(){
+        HashMap<String, String> hashMap = new HashMap<>();
+        hashMap.put("FSU_Water","水浸告警");
+        hashMap.put("FSU_TemperatureAndHumidity","温湿度告警");
+        hashMap.put("FSU_Smoke","烟感告警");
+        hashMap.put("FSU_Gas","燃气告警");
+        hashMap.put("FSU_DoorMagnetic","门磁告警");
+        hashMap.put("FSU_Theft","防盗告警");
+        hashMap.put("FSU_DoPowerCollection8Hour","8小时回路告警");
+        hashMap.put("FSU_DoPowerCollection24Hour","24小时回路告警");
+        hashMap.put("FSU_Ups","UPS告警");
+
+        return hashMap;
     }
 }

+ 1 - 0
soc-modules/soc-modules-iot/src/main/resources/mapper/CoreNoticeRuleItemMapper.xml

@@ -33,6 +33,7 @@
                 LEFT JOIN core_notice_rule_item r ON c.id = r.rule_id
         WHERE
             r.org_id = #{orgId}
+            AND c.org_id != #{orgId}
             AND c.`enable` = 1
         GROUP BY
             c.org_id

+ 13 - 5
soc-modules/soc-modules-iot/src/main/resources/mapper/IotAlarmDataMapper.xml

@@ -121,11 +121,19 @@
     </select>
 
     <select id="selectAlarmDataListByOrgPath" resultType="com.xunmei.common.core.domain.mediator.domain.IotAlarmData">
-        select d.* from iot_alarm_data d inner join sys_org o on d.org_id = o.id where o.path like
-        concat(#{orgPath},'%') and o.deleted = 0
-        <if test="dataType != null">
-            and d.data_type = #{dataType}
-        </if>
+        SELECT
+            d.*
+        FROM
+            iot_alarm_data d
+            INNER JOIN sys_org o ON d.org_id = o.id
+            LEFT JOIN iot_device_info i ON d.device_id = i.id
+        where
+            o.path like concat(#{orgPath},'%')
+            and o.deleted = 0
+            and i.deleted = 0
+            <if test="dataType != null">
+                and d.data_type = #{dataType}
+            </if>
     </select>
 
     <select id="selectDeviceTypeCount" resultType="com.xunmei.iot.vo.alarmData.DeviceTypeCountVo">