jinpengyong
2023-10-10 f0837ee21f7650d4413830d4ee90da02bcdd6d36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
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>
 *  服务实现类
 * </p>
 *
 * @author moral
 * @since 2022-01-17
 */
@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;
    }
}