浏览代码

挂墙终端告警页面后端接口修改

xujie 1 年之前
父节点
当前提交
5260b15529

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

@@ -16,5 +16,5 @@ import java.util.List;
  */
 public interface CoreNoticeRuleItemMapper extends BaseMapper<CoreNoticeRuleItem> {
 
-    List<String> getNoticeProductTypesByUser(@Param("roleIds") List<String> roleIds,@Param("orgId") Long orgId,@Param("userId") Long userId);
+    List<String> getNoticeProductTypesByUser(@Param("roleIds") List<Long> roleIds,@Param("orgId") Long orgId,@Param("userId") Long userId);
 }

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

@@ -20,4 +20,6 @@ public interface IotDeviceInfoMapper extends BaseMapper<IotDeviceInfo> {
     DeviceDetailInfoVo getDetailById(@Param("id") Serializable id);
 
     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);
 }

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

@@ -15,6 +15,6 @@ import java.util.List;
  */
 public interface ICoreNoticeRuleItemService extends IService<CoreNoticeRuleItem> {
 
-    List<String> getNoticeProductTypesByUser(List<String> roleIds,Long orgId,Long userId);
+    List<String> getNoticeProductTypesByUser(List<Long> roleIds,Long orgId,Long userId);
 
 }

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

@@ -8,6 +8,7 @@ import com.xunmei.iot.vo.deviceInfo.IotDeviceInfoPageVo;
 import com.xunmei.system.api.domain.iot.IotDeviceInfo;
 
 import java.io.Serializable;
+import java.util.List;
 
 public interface IIotDeviceInfoService extends IService<IotDeviceInfo> {
 
@@ -16,4 +17,6 @@ public interface IIotDeviceInfoService extends IService<IotDeviceInfo> {
     DeviceDetailInfoVo getDetail(Serializable id);
 
     DeviceDetailInfoVo getAlarmHostDetail(Serializable id);
+
+    List<DeviceDetailInfoVo> getByProductTypes(List<String> productTypes,String orgPath);
 }

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

@@ -21,7 +21,7 @@ public class CoreNoticeRuleItemServiceImpl extends ServiceImpl<CoreNoticeRuleIte
 
 
     @Override
-    public List<String> getNoticeProductTypesByUser(List<String> roleIds, Long orgId, Long userId) {
+    public List<String> getNoticeProductTypesByUser(List<Long> roleIds, Long orgId, Long userId) {
         return baseMapper.getNoticeProductTypesByUser(roleIds, orgId, userId);
     }
 }

+ 15 - 8
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/service/impl/IotBoardServiceImpl.java

@@ -29,8 +29,10 @@ import com.xunmei.iot.vo.alarmData.AppAlarmDataPageVo;
 import com.xunmei.iot.vo.board.IotBoardOverviewItemVo;
 import com.xunmei.iot.vo.board.IotBoardOverviewVo;
 import com.xunmei.iot.vo.board.IotBoardTotalData;
+import com.xunmei.iot.vo.deviceInfo.DeviceDetailInfoVo;
 import com.xunmei.system.api.RemoteOrgService;
 import com.xunmei.system.api.domain.SysOrg;
+import com.xunmei.system.api.domain.SysRole;
 import com.xunmei.system.api.domain.SysUser;
 import com.xunmei.system.api.model.LoginUser;
 import com.xunmei.system.api.vo.SysOrgVO;
@@ -78,6 +80,9 @@ public class IotBoardServiceImpl implements IotBoardService {
     @Resource
     ICoreNoticeRuleItemService coreNoticeRuleItemService;
 
+    @Resource
+    IIotDeviceInfoService deviceInfoService;
+
     private final Long TIMEOUT = 3L;
 
     @Override
@@ -176,6 +181,7 @@ 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");
         Map<String, Object> map = new HashMap<>();
         Map<String, Object> dataMap = new HashMap<>();
         List<Map<String, Object>> resultList = new ArrayList<>();
@@ -184,7 +190,8 @@ public class IotBoardServiceImpl implements IotBoardService {
             throw new ServiceException("当前机构信息不存在");
         }
         SysOrgVO org = optional.get();
-        List<IotSensor> list = sensorService.selectSensorListByOrgPath(org.getPath());
+        List<DeviceDetailInfoVo> list = deviceInfoService.getByProductTypes(productTypeList, org.getPath());
+        //List<IotSensor> list = sensorService.selectSensorListByOrgPath(org.getPath());
         dataMap.put("sensor", map);
         dataMap.put("resultData", resultList);
         map.put("key", "传感器设备");
@@ -195,7 +202,7 @@ public class IotBoardServiceImpl implements IotBoardService {
             buildEmptyData(resultList, alarmTypeList);
             return dataMap;
         }
-        Map<Integer, Long> collect = list.stream().collect(Collectors.groupingBy(IotSensor::getState, Collectors.counting()));
+        Map<Integer, Long> collect = list.stream().collect(Collectors.groupingBy(DeviceDetailInfoVo::getState, Collectors.counting()));
         collect.forEach((k, v) -> {
             if (ObjectUtil.equal(0, k)) {
                 map.put("normal", v.intValue());
@@ -216,10 +223,10 @@ public class IotBoardServiceImpl implements IotBoardService {
 
         //查询当前登录用户需要通知的告警类型
         LoginUser loginUser = SecurityUtils.getLoginUser();
-        List<String> roleIds = null;
-        Set<String> roles = loginUser.getRoles();
-        if (roles != null && !roles.isEmpty()){
-            roleIds = new ArrayList<>(roles);
+        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());
 
@@ -236,7 +243,7 @@ public class IotBoardServiceImpl implements IotBoardService {
             hashMap.put("currentAlarm", (int) currentAlarm);
             hashMap.put("unDealAlarm", (int) unDealAlarm);
             hashMap.put("needAlarm", (int) needAlarm);
-            hashMap.put("currentAlarmData", getAlarmDataList(value, Integer.parseInt(listEntry.getKey().toString()), cacheList));
+            hashMap.put("currentAlarmData", getAlarmDataList(value, listEntry.getKey().toString(), cacheList));
             hashMap.put("needNotice", productTypes.contains(value.get(0).getSourceType()) ? 1 : 0);
 
             resultList.add(hashMap);
@@ -260,7 +267,7 @@ public class IotBoardServiceImpl implements IotBoardService {
         return dataMap;
     }
 
-    private List<AppAlarmDataPageVo> getAlarmDataList(List<IotAlarmData> dataList, Integer sourceType, List<SysOrgVO> cacheList) {
+    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()))

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

@@ -81,4 +81,9 @@ public class IotDeviceInfoServiceImpl extends ServiceImpl<IotDeviceInfoMapper, I
         }
         return detailInfoVo;
     }
+
+    @Override
+    public List<DeviceDetailInfoVo> getByProductTypes(List<String> productTypes, String orgPath) {
+        return baseMapper.getByProductTypes(productTypes, orgPath);
+    }
 }

+ 3 - 0
soc-modules/soc-modules-iot/src/main/java/com/xunmei/iot/vo/deviceInfo/DeviceDetailInfoVo.java

@@ -21,4 +21,7 @@ public class DeviceDetailInfoVo extends IotDeviceInfoPageVo implements Serializa
 
     //子设备
     private List<DeviceDetailInfoVo> childrenInfos;
+
+    //告警状态,0:正常,1:告警,2:未知
+    private Integer state;
 }

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

@@ -68,4 +68,25 @@
                 and d.device_product = #{deviceProduct}
             </if>
     </select>
+    <select id="getByProductTypes" 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_path like concat(#{orgPath},'%')
+            <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>