Explorar o código

处理告警记录查询空指针异常bug

liuyaowen hai 9 meses
pai
achega
7f3b3dffe5

+ 13 - 6
src/main/java/com/yunfeiyun/agmp/iotm/web/service/impl/IotWarnlogServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
@@ -73,12 +74,18 @@ public class IotWarnlogServiceImpl implements IIotWarnlogService {
             devBids.add(iotWarnlogResVo.getDevBid());
             devTypeBids.add(iotWarnlogResVo.getDevtypeBid());
         }
-        // 查询告警设备信息
-        List<IotDevice> iotDeviceList = iotDeviceMapper.selectIotDeviceByDevBids(devBids, SecurityUtils.getTid());
-        Map<String,IotDevice> iotDeviceMap = iotDeviceList.stream().collect(Collectors.toMap(IotDevice::getDevBid,item->item));
-        // 查询告警设备类型信息
-        List<TosDevicetype> tosDevicetypes = tosDevicetypeMapper.selectTosDevicetypeByDevtypeBids(devTypeBids);
-        Map<String,String> tosDeviceTypeMap = tosDevicetypes.stream().collect(Collectors.toMap(TosDevicetype::getDevtypeBid,TosDevicetype::getDevtypeName));
+        Map<String,IotDevice> iotDeviceMap = new HashMap<>();
+        if(!devBids.isEmpty()){
+            // 查询告警设备信息
+            List<IotDevice> iotDeviceList = iotDeviceMapper.selectIotDeviceByDevBids(devBids, SecurityUtils.getTid());
+            iotDeviceMap = iotDeviceList.stream().collect(Collectors.toMap(IotDevice::getDevBid,item->item));
+        }
+        Map<String,String> tosDeviceTypeMap = new HashMap<>();
+        if(!devTypeBids.isEmpty()){
+            // 查询告警设备类型信息
+            List<TosDevicetype> tosDevicetypes = tosDevicetypeMapper.selectTosDevicetypeByDevtypeBids(devTypeBids);
+            tosDeviceTypeMap = tosDevicetypes.stream().collect(Collectors.toMap(TosDevicetype::getDevtypeBid,TosDevicetype::getDevtypeName));
+        }
         // 遍历结果进行赋值
         for(IotWarnlogResVo iotWarnlogResVo : iotWarnLogResVoList){
             IotDevice iotDevice = iotDeviceMap.get(iotWarnlogResVo.getDevBid());