Просмотр исходного кода

告警列表接口添加设备信息

liuyaowen 9 месяцев назад
Родитель
Сommit
639f022fae

+ 7 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/domain/resvo/IotWarnconfigResVo.java

@@ -1,12 +1,19 @@
 package com.yunfeiyun.agmp.iotm.web.domain.resvo;
 
+import com.yunfeiyun.agmp.common.core.domain.entity.SysUser;
+import com.yunfeiyun.agmp.iot.common.domain.IotDevice;
 import com.yunfeiyun.agmp.iot.common.domain.IotWarnconfig;
 import lombok.Data;
 
+import java.util.List;
+
 @Data
 public class IotWarnconfigResVo extends IotWarnconfig {
     private String devtypeName;
     private String wpChannel;
     private String wcTouchtypeName;
     private String wcLevelName;
+
+    private List<IotDevice> iotDeviceList;
+    private List<SysUser> sysUserList;
 }

+ 2 - 0
src/main/java/com/yunfeiyun/agmp/iotm/web/mapper/IotWarnobjectMapper.java

@@ -63,4 +63,6 @@ public interface IotWarnobjectMapper {
     public int deleteIotWarnobjectByWoBids(@Param("array") String[] ids, @Param("tid") String tid);
 
     List<IotWarnobjectResVo> selectIotWarnobjectResVoList(IotWarnobject iotWarnobject);
+
+    List<IotWarnobject> selectIotWarnobjectListByWcBids(@Param("list") List<String> wcBids,@Param("tid") String tid);
 }

+ 32 - 4
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarnconfigServiceImpl.java

@@ -26,9 +26,8 @@ import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.List;
+import java.util.*;
+import java.util.stream.Collectors;
 
 /**
  * 告警配置Service业务层处理
@@ -76,11 +75,40 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
     @Override
     public List<IotWarnconfigResVo> selectIotWarnconfigResVoList(IotWarnconfig iotWarnconfig) {
         List<IotWarnconfigResVo> iotWarnconfigResVoList = iotWarnconfigMapper.selectIotWarnconfigResVoList(iotWarnconfig);
+        List<String> wcBids = new ArrayList<>();
+        Map<String,IotWarnconfigResVo> map = new HashMap<>();
         for(IotWarnconfigResVo iotWarnconfigResVo : iotWarnconfigResVoList){
             iotWarnconfigResVo.setDevtypeName(IotDeviceDictEnum.getNameByCode(iotWarnconfigResVo.getDevtypeBid()));
             iotWarnconfigResVo.setWcTouchtypeName(IotWarnTouchTypeEnum.findByCode(iotWarnconfigResVo.getWcTouchtype()).getContent());
             iotWarnconfigResVo.setWcLevelName(IotWarnlevelEnum.findByCode(iotWarnconfigResVo.getWcLevel()).getContent());
+            iotWarnconfigResVo.setIotDeviceList(new ArrayList<>());
+            iotWarnconfigResVo.setSysUserList(new ArrayList<>());
+            wcBids.add(iotWarnconfigResVo.getWcBid());
+            map.put(iotWarnconfigResVo.getWcBid(),iotWarnconfigResVo);
         }
+        if(!wcBids.isEmpty()){
+            // 填充设备信息
+            List<IotWarnobject> iotWarnobjectList = iotWarnobjectMapper.selectIotWarnobjectListByWcBids(wcBids,SecurityUtils.getTid());
+            Map<String,List<IotWarnobject>> iotWarnobjectMap = iotWarnobjectList.stream().collect(Collectors.groupingBy(IotWarnobject::getDevBid));
+            if(!iotWarnobjectMap.isEmpty()){
+                List<IotDevice> iotDeviceList = iotDeviceMapper.selectIotDeviceByDevBids(new ArrayList<>(iotWarnobjectMap.keySet()),SecurityUtils.getTid());
+                for(IotDevice iotDevice : iotDeviceList){
+                    List<IotWarnobject> devWarnObjectList = iotWarnobjectMap.get(iotDevice.getDevBid());
+                    if(null == devWarnObjectList){
+                        continue;
+                    }
+                    for(IotWarnobject iotWarnobject : devWarnObjectList){
+                        IotWarnconfigResVo iotWarnconfigResVo = map.get(iotWarnobject.getWcBid());
+                        if(null != iotWarnconfigResVo){
+                            iotWarnconfigResVo.getIotDeviceList().add(iotDevice);
+                        }
+                    }
+                }
+            }
+            // 填充通知人信息,暂不实现
+        }
+
+
         return iotWarnconfigResVoList;
     }
 
@@ -229,8 +257,8 @@ public class IotWarnconfigServiceImpl implements IIotWarnconfigService {
         return null;
     }
 
-    @Transactional(rollbackFor = Exception.class)
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public IotWarnconfig copy(String wcBid) {
         // 查询告警规则
         IotWarnconfig iotWarnconfig = iotWarnconfigMapper.selectIotWarnconfigByWcBid(wcBid,SecurityUtils.getTid());

+ 12 - 0
src/main/resources/mapper/IotWarnobjectMapper.xml

@@ -79,4 +79,16 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
             <if test="tid != null  and tid != ''"> and tid = #{tid}</if>
         </where>
     </select>
+
+    <select id="selectIotWarnobjectListByWcBids"
+            resultType="com.yunfeiyun.agmp.iot.common.domain.IotWarnobject">
+        <include refid="selectIotWarnobjectVo"/>
+        <where>
+            wcBid in
+            <foreach item="item" collection="list" open="(" separator="," close=")">
+                #{item}
+            </foreach>
+            and tid = #{tid}
+        </where>
+    </select>
 </mapper>