|  |  | 
 |  |  | package com.moral.api.service.impl; | 
 |  |  |  | 
 |  |  | import com.alibaba.fastjson.JSON; | 
 |  |  | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | 
 |  |  | import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper; | 
 |  |  | import com.moral.api.entity.Device; | 
 |  |  | import com.moral.api.entity.MonitorPoint; | 
 |  |  | import com.moral.api.entity.ServicesScopeDevice; | 
 |  |  | import com.moral.api.mapper.DeviceMapper; | 
 |  |  | import com.moral.api.mapper.MonitorPointMapper; | 
 |  |  | import com.moral.api.mapper.ServicesScopeDeviceMapper; | 
 |  |  | import com.moral.api.service.ServicesScopeDeviceService; | 
 |  |  | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; | 
 |  |  | import com.moral.constant.Constants; | 
 |  |  | import org.springframework.beans.factory.annotation.Autowired; | 
 |  |  | import org.springframework.stereotype.Service; | 
 |  |  |  | 
 |  |  | import java.util.ArrayList; | 
 |  |  | import java.util.List; | 
 |  |  | import java.util.Map; | 
 |  |  | import java.util.stream.Collectors; | 
 |  |  |  | 
 |  |  | /** | 
 |  |  |  * <p> | 
 |  |  | 
 |  |  | @Service | 
 |  |  | public class ServicesScopeDeviceServiceImpl extends ServiceImpl<ServicesScopeDeviceMapper, ServicesScopeDevice> implements ServicesScopeDeviceService { | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private ServicesScopeDeviceMapper servicesScopeDeviceMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private DeviceMapper deviceMapper; | 
 |  |  |  | 
 |  |  |     @Autowired | 
 |  |  |     private MonitorPointMapper monitorPointMapper; | 
 |  |  |  | 
 |  |  |     @Override | 
 |  |  |     public List<Map<String, Object>> getDevicesAndMonitorPoint(Map<String, Object> map) { | 
 |  |  |         int servicesScopeId = Integer.parseInt(map.get("servicesScopeId").toString()); | 
 |  |  |         QueryWrapper<ServicesScopeDevice> servicesScopeDeviceQueryWrapper = new QueryWrapper<>(); | 
 |  |  |         servicesScopeDeviceQueryWrapper.eq("is_delete",Constants.NOT_DELETE); | 
 |  |  |         servicesScopeDeviceQueryWrapper.eq("services_scope_id",servicesScopeId); | 
 |  |  |         List<ServicesScopeDevice> servicesScopeDevices = servicesScopeDeviceMapper.selectList(servicesScopeDeviceQueryWrapper); | 
 |  |  |         if (servicesScopeDevices.size() == 0){ | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         List<Integer> deviceIds = servicesScopeDevices.stream().map(p -> p.getDeviceId()).collect(Collectors.toList()); | 
 |  |  |         QueryWrapper<Device> deviceQueryWrapper = new QueryWrapper<>(); | 
 |  |  |         deviceQueryWrapper.eq("is_delete",Constants.NOT_DELETE); | 
 |  |  |         deviceQueryWrapper.in("id",deviceIds); | 
 |  |  |         List<Device> devices = deviceMapper.selectList(deviceQueryWrapper); | 
 |  |  |         if (devices.size() == 0){ | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         List<Integer> monitorPointIds = devices.stream().map(p -> p.getMonitorPointId()).collect(Collectors.toList()); | 
 |  |  |         QueryWrapper<MonitorPoint> monitorPointQueryWrapper = new QueryWrapper<>(); | 
 |  |  |         monitorPointQueryWrapper.eq("is_delete",Constants.NOT_DELETE); | 
 |  |  |         monitorPointQueryWrapper.in("id",monitorPointIds); | 
 |  |  |         List<MonitorPoint> monitorPointList = monitorPointMapper.selectList(monitorPointQueryWrapper); | 
 |  |  |         if (monitorPointList.size() == 0){ | 
 |  |  |             return null; | 
 |  |  |         } | 
 |  |  |         List resultList = new ArrayList(); | 
 |  |  |         for (MonitorPoint monitorPoint:monitorPointList) { | 
 |  |  |             Map monitorPointMap = JSON.parseObject(JSON.toJSONString(monitorPoint), Map.class); | 
 |  |  |             List deviceList = new ArrayList(); | 
 |  |  |             for (Device device:devices) { | 
 |  |  |                 if (device.getMonitorPointId().equals(monitorPoint.getId())){ | 
 |  |  |                     deviceList.add(device); | 
 |  |  |                 } | 
 |  |  |             } | 
 |  |  |             monitorPointMap.put("devices",deviceList); | 
 |  |  |             resultList.add(monitorPointMap); | 
 |  |  |         } | 
 |  |  |         return resultList; | 
 |  |  |     } | 
 |  |  | } |