Prechádzať zdrojové kódy

挂墙终端报警修改

xujie 1 rok pred
rodič
commit
866d278da9
15 zmenil súbory, kde vykonal 207 pridanie a 8 odobranie
  1. 2 3
      soc-common/soc-common-websocket/src/main/java/com/xunmei/common/websocket/handler/PlusWebSocketHandler.java
  2. 4 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/CoreNoticeRuleItemMapper.java
  3. 1 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotAlarmDataMapper.java
  4. 2 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotDeviceInfoMapper.java
  5. 4 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/ICoreNoticeRuleItemService.java
  6. 2 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IIotDeviceInfoService.java
  7. 2 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IotAlarmDataService.java
  8. 10 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/CoreNoticeRuleItemServiceImpl.java
  9. 5 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotAlarmDataServiceImpl.java
  10. 92 5
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotBoardServiceImpl.java
  11. 5 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotDeviceInfoServiceImpl.java
  12. 2 0
      soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/alarmData/AppAlarmDataPageVo.java
  13. 35 0
      soc-modules/soc-modules-iot/src/main/resources/mapper/CoreNoticeRuleItemMapper.xml
  14. 20 0
      soc-modules/soc-modules-iot/src/main/resources/mapper/IotAlarmDataMapper.xml
  15. 21 0
      soc-modules/soc-modules-iot/src/main/resources/mapper/IotDeviceInfoMapper.xml

+ 2 - 3
soc-common/soc-common-websocket/src/main/java/com/xunmei/common/websocket/handler/PlusWebSocketHandler.java

@@ -1,12 +1,10 @@
 package com.xunmei.common.websocket.handler;
 
-import com.xunmei.common.security.utils.SecurityUtils;
 import com.xunmei.common.websocket.dto.WebSocketMessageDto;
 import com.xunmei.common.websocket.holder.WebSocketSessionHolder;
 import com.xunmei.common.websocket.utils.WebSocketUtils;
 import com.xunmei.system.api.model.LoginUser;
 import lombok.extern.slf4j.Slf4j;
-
 import org.springframework.web.socket.*;
 import org.springframework.web.socket.handler.AbstractWebSocketHandler;
 
@@ -42,10 +40,11 @@ public class PlusWebSocketHandler extends AbstractWebSocketHandler {
      */
     @Override
     protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
+        LoginUser loginUser = (LoginUser) session.getAttributes().get(LOGIN_USER_KEY);
         if (message.getPayload().equals("ping")){
+            log.info("收到心跳检测sessionId:{},userId:{},userName:{}", session.getId(), loginUser.getUserid(), loginUser.getUsername());
             return;
         }
-        LoginUser loginUser = (LoginUser) session.getAttributes().get(LOGIN_USER_KEY);
         List<Long> userIds = new ArrayList<>();
         userIds.add(loginUser.getUserid());
         WebSocketMessageDto webSocketMessageDto = new WebSocketMessageDto();

+ 4 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/CoreNoticeRuleItemMapper.java

@@ -17,4 +17,8 @@ import java.util.List;
 public interface CoreNoticeRuleItemMapper extends BaseMapper<CoreNoticeRuleItem> {
 
     List<String> getNoticeProductTypesByUser(@Param("roleIds") List<Long> roleIds,@Param("orgId") Long orgId,@Param("userId") Long userId);
+
+    List<String> getNoticeProductTypesByNoticeUser(@Param("roleIds") List<Long> roleIds,@Param("orgId") Long orgId,@Param("noticeOrgId")Long noticeOrgId,@Param("userId")Long userId);
+
+    List<Long> getOrgIdsByNoticeOrgId(@Param("orgId") Long orgId);
 }

+ 1 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotAlarmDataMapper.java

@@ -26,6 +26,7 @@ public interface IotAlarmDataMapper extends BaseMapper<IotAlarmData> {
     Integer appBadge(Long orgId);
 
     List<IotAlarmData> selectAlarmDataListByOrgPath(@Param("orgPath") String orgPath, @Param("dataType") Integer dataType);
+    List<IotAlarmData> getByProductTypesAndOrgId(@Param("productTypes") List<String> productTypes, @Param("orgId") Long orgId, @Param("dataType") Integer dataType);
 
     List<DeviceTypeCountVo> selectDeviceTypeCount(@Param("query")AppAlarmPageDto requestDto);
 

+ 2 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/mapper/IotDeviceInfoMapper.java

@@ -22,4 +22,6 @@ public interface IotDeviceInfoMapper extends BaseMapper<IotDeviceInfo> {
     List<DeviceDetailInfoVo> getChildrenInfoList(@Param("deviceProduct") String deviceProduct,@Param("iotToken") String iotToken,@Param("hostCode") String hostCode);
 
     List<DeviceDetailInfoVo> getByProductTypes(@Param("productTypes") List<String> productTypes,@Param("orgPath") String orgPath);
+
+    List<DeviceDetailInfoVo> getByProductTypesAndOrgId(@Param("productTypes") List<String> productTypes,@Param("orgId") Long orgId);
 }

+ 4 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/ICoreNoticeRuleItemService.java

@@ -17,4 +17,8 @@ public interface ICoreNoticeRuleItemService extends IService<CoreNoticeRuleItem>
 
     List<String> getNoticeProductTypesByUser(List<Long> roleIds,Long orgId,Long userId);
 
+    List<String> getNoticeProductTypesByNoticeUser(List<Long> roleIds,Long orgId,Long noticeOrgId,Long userId);
+
+    List<Long> getOrgIdsByNoticeOrgId(Long orgId);
+
 }

+ 2 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IIotDeviceInfoService.java

@@ -21,4 +21,6 @@ public interface IIotDeviceInfoService extends IService<IotDeviceInfo> {
     List<DeviceDetailInfoVo> getByProductTypes(List<String> productTypes,String orgPath);
 
     IotDeviceInfo selectDevice(String iotCode, String deviceProduct, String deviceCode);
+
+    List<DeviceDetailInfoVo> getByProductTypesAndOrgId(List<String> productTypes,Long orgId);
 }

+ 2 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/IotAlarmDataService.java

@@ -46,4 +46,6 @@ public interface IotAlarmDataService extends IService<IotAlarmData> {
     List<AlarmTypeSelectedVO> getDeviceTypeList(String type);
 
     Integer selectUpsAlarmCount(String orgPath);
+
+    List<IotAlarmData> getByProductTypesAndOrgId(List<String> productTypes,Long orgId,Integer dataType);
 }

+ 10 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/CoreNoticeRuleItemServiceImpl.java

@@ -24,4 +24,14 @@ public class CoreNoticeRuleItemServiceImpl extends ServiceImpl<CoreNoticeRuleIte
     public List<String> getNoticeProductTypesByUser(List<Long> roleIds, Long orgId, Long userId) {
         return baseMapper.getNoticeProductTypesByUser(roleIds, orgId, userId);
     }
+
+    @Override
+    public List<String> getNoticeProductTypesByNoticeUser(List<Long> roleIds, Long orgId, Long noticeOrgId, Long userId) {
+        return baseMapper.getNoticeProductTypesByNoticeUser(roleIds,orgId,noticeOrgId,userId);
+    }
+
+    @Override
+    public List<Long> getOrgIdsByNoticeOrgId(Long orgId) {
+        return baseMapper.getOrgIdsByNoticeOrgId(orgId);
+    }
 }

+ 5 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotAlarmDataServiceImpl.java

@@ -193,6 +193,11 @@ public class IotAlarmDataServiceImpl extends ServiceImpl<IotAlarmDataMapper, Iot
     }
 
     @Override
+    public List<IotAlarmData> getByProductTypesAndOrgId(List<String> productTypes, Long orgId, Integer dataType) {
+        return baseMapper.getByProductTypesAndOrgId(productTypes, orgId, dataType);
+    }
+
+    @Override
     public SensorAlarmCountVo selectDeviceTypeCount(AppAlarmPageDto requestDto) {
         SensorAlarmCountVo sensorAlarmCountVo = new SensorAlarmCountVo();
         if (requestDto.getCheckSub() && ObjectUtil.isNotEmpty(requestDto.getOrgId())) {

+ 92 - 5
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotBoardServiceImpl.java

@@ -181,8 +181,8 @@ 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("水浸告警", "温湿度告警", "烟感告警", "燃气告警", "门磁告警", "防盗告警");
-        List<String> productTypeList = Lists.newArrayList("FSU_Water", "FSU_TemperatureAndHumidity", "FSU_Smoke", "FSU_Gas", "FSU_DoorMagnetic", "FSU_Theft");
+        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, Object> map = new HashMap<>();
         Map<String, Object> dataMap = new HashMap<>();
@@ -239,13 +239,14 @@ public class IotBoardServiceImpl implements IotBoardService {
             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;
 
             hashMap.put("key", value.get(0).getSourceTypeDes());
             hashMap.put("historyAlarm", value.size());
             hashMap.put("currentAlarm", (int) currentAlarm);
             hashMap.put("unDealAlarm", (int) unDealAlarm);
-            hashMap.put("needAlarm", (needAlarm == 1 && productTypes.contains(value.get(0).getSourceType())) ? 1 : 0);
-            hashMap.put("currentAlarmData", getAlarmDataList(value, listEntry.getKey().toString(), cacheList));
+            hashMap.put("needAlarm", needAlarm);
+            hashMap.put("currentAlarmData", getAlarmDataList(value, listEntry.getKey().toString(), cacheList,needAlarm));
 
             resultList.add(hashMap);
         }
@@ -264,10 +265,16 @@ 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) {
+    private List<AppAlarmDataPageVo> getAlarmDataList(List<IotAlarmData> dataList, String sourceType, List<SysOrgVO> cacheList,Integer needAlarm) {
         List<IotAlarmData> list = dataList.stream()
                 .filter(d -> ObjectUtil.equal(d.getSourceType(), sourceType))
                 .filter(d -> ObjectUtil.isNull(d.getEndTime()))
@@ -294,6 +301,7 @@ public class IotBoardServiceImpl implements IotBoardService {
             vo.setDoByUser(alarmData.getDoByUser());
             vo.setDoType(alarmData.getDoType());
             vo.setDoContent(alarmData.getDoContent());
+            vo.setNeedAlarm(needAlarm);
             arrayList.add(vo);
 
         }
@@ -497,4 +505,83 @@ public class IotBoardServiceImpl implements IotBoardService {
             videoInspection.setHardDiskExceptionRate(String.format("%.2f", ((dvrDiskList.size() - count1) * 100.0 / dvrDiskList.size())) + "%");
         }
     }
+
+    /**
+     * @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("historyAlarm", value.size());
+                    hashMap.put("unDealAlarm", (int) unDealAlarm);
+                    hashMap.put("currentAlarm", (int) currentAlarm);
+                    hashMap.put("needAlarm", needAlarm);
+                    hashMap.put("currentAlarmData", getAlarmDataList(value, listEntry.getKey().toString(), cacheList,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") + currentAlarm);
+                    objectMap.put("unDealAlarm", (int) objectMap.get("unDealAlarm") + unDealAlarm);
+
+                    List<AppAlarmDataPageVo> dataList = (List<AppAlarmDataPageVo>) objectMap.get("currentAlarmData");
+                    dataList.addAll(getAlarmDataList(value, listEntry.getKey().toString(), cacheList, needAlarm));
+                    objectMap.put("currentAlarmData", dataList);
+
+                    needAlarm = ((int) objectMap.get("needAlarm") == 1 && needAlarm == 1) ? 1 : 0;
+                    objectMap.put("needAlarm", needAlarm);
+
+                    resultList.set(index,objectMap);
+                }
+            }
+
+            dataMap.put("resultData", resultList);
+        }
+    }
 }

+ 5 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotDeviceInfoServiceImpl.java

@@ -98,4 +98,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         wrapper.last(Constants.LIMIT1);
         return baseMapper.selectOne(wrapper);
     }
+
+    @Override
+    public List<DeviceDetailInfoVo> getByProductTypesAndOrgId(List<String> productTypes, Long orgId) {
+        return baseMapper.getByProductTypesAndOrgId(productTypes,orgId);
+    }
 }

+ 2 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/alarmData/AppAlarmDataPageVo.java

@@ -45,5 +45,7 @@ public class AppAlarmDataPageVo {
     @ApiModelProperty(value = "告警处置内容")
     private String doContent;
 
+    @ApiModelProperty(value = "该条告警是否需要播报语音 0:不需要 1:需要")
+    private Integer needAlarm;
 
 }

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

@@ -11,6 +11,7 @@
             LEFT JOIN core_notice_rule c ON r.rule_id = c.id
         WHERE
             c.`enable` = 1
+            AND c.org_id = #{orgId}
             AND r.org_id = #{orgId}
             AND (
                     r.user_ids LIKE concat( '%', #{userId}, '%' )
@@ -24,4 +25,38 @@
         GROUP BY
             r.product_type
     </select>
+    <select id="getOrgIdsByNoticeOrgId" resultType="java.lang.Long">
+        SELECT
+            c.org_id
+        FROM
+            core_notice_rule c
+                LEFT JOIN core_notice_rule_item r ON c.id = r.rule_id
+        WHERE
+            r.org_id = #{orgId}
+            AND c.`enable` = 1
+        GROUP BY
+            c.org_id
+    </select>
+    <select id="getNoticeProductTypesByNoticeUser" resultType="java.lang.String">
+        SELECT
+            r.product_type
+        FROM
+            core_notice_rule_item r
+            LEFT JOIN core_notice_rule c ON r.rule_id = c.id
+        WHERE
+            c.`enable` = 1
+            AND c.org_id = #{orgId}
+            AND r.org_id = #{noticeOrgId}
+            AND (
+            r.user_ids LIKE concat( '%', #{userId}, '%' )
+            <if test="roleIds != null and roleIds.size() > 0">
+                OR r.role_id IN
+                <foreach collection="roleIds" index="index" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+            )
+        GROUP BY
+            r.product_type
+    </select>
 </mapper>

+ 20 - 0
soc-modules/soc-modules-iot/src/main/resources/mapper/IotAlarmDataMapper.xml

@@ -269,4 +269,24 @@
           and o.path like concat(#{orgPath}, '%')
           and d.source_type = 'FSU_Ups'
     </select>
+    <select id="getByProductTypesAndOrgId"
+            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.id = #{orgId}
+            AND o.deleted = 0
+            <if test="dataType != null">
+                and d.data_type = #{dataType}
+            </if>
+            <if test="productTypes !=null and productTypes.size()>0">
+                and d.source_type in
+                <foreach collection="productTypes" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+    </select>
 </mapper>

+ 21 - 0
soc-modules/soc-modules-iot/src/main/resources/mapper/IotDeviceInfoMapper.xml

@@ -89,4 +89,25 @@
                 </foreach>
             </if>
     </select>
+    <select id="getByProductTypesAndOrgId" resultType="com.xunmei.iot.vo.deviceInfo.DeviceDetailInfoVo">
+        SELECT
+            d.id,
+            d.device_type,
+            d.device_product,
+            d.device_code,
+            d.device_name,
+            ifnull( s.state, 0 ) AS state
+        FROM
+            iot_device_info d
+            LEFT JOIN iot_device_status s ON d.id = s.device_id
+        WHERE
+            d.deleted = 0
+            and d.org_id = #{orgId}
+            <if test="productTypes !=null and productTypes.size()>0">
+                and d.device_product in
+                <foreach collection="productTypes" item="item" open="(" separator="," close=")">
+                    #{item}
+                </foreach>
+            </if>
+    </select>
 </mapper>