kaiyu
2021-09-24 8e9a6b3013b877faa78bff87954dabe873e4eac7
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
package com.moral.api.service.impl;
 
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.moral.api.entity.Device;
import com.moral.api.entity.MonitorPoint;
import com.moral.api.entity.Organization;
import com.moral.api.mapper.MonitorPointMapper;
import com.moral.api.pojo.form.device.MonitorPointQueryForm;
import com.moral.api.service.DeviceService;
import com.moral.api.service.MonitorPointService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.moral.api.service.OrganizationService;
import com.moral.constant.Constants;
import com.moral.util.RegionCodeUtils;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
 
/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author moral
 * @since 2021-07-01
 */
@Service
public class MonitorPointServiceImpl extends ServiceImpl<MonitorPointMapper, MonitorPoint> implements MonitorPointService {
 
    @Autowired
    MonitorPointMapper monitorPointMapper;
    @Autowired
    OrganizationService organizationService;
    @Autowired
    DeviceService deviceService;
 
    @Override
    public List<MonitorPoint> queryByOrgIdAndRegionCode(MonitorPointQueryForm form) {
        //取参
        Integer organizationId = form.getOrganizationId();
        Integer regionCode = form.getRegionCode();
        String region = null;
        if (regionCode != null) {
            region = RegionCodeUtils.regionCodeConvertToName(regionCode);
        }
 
        //查询子组织
        List<Organization> childrenOrganization = organizationService.getChildrenOrganizationsById(organizationId);
        List<Integer> organizationIds = new ArrayList<>();
        for (Organization organization : childrenOrganization) {
            organizationIds.add(organization.getId());
        }
        organizationIds.add(organizationId);
        //查询站点
        QueryWrapper<MonitorPoint> queryMonitorPointsWrapper = new QueryWrapper<>();
 
        //如果region不为空,就查询当前组织,所选城市下所有站点及设备信息
        //如果region为空,则查询当前组织下所有的站点和设备
        if (region != null){
            queryMonitorPointsWrapper.eq(region, regionCode);
        }
        queryMonitorPointsWrapper.in("organization_id", organizationIds);
        queryMonitorPointsWrapper.eq("is_delete", Constants.NOT_DELETE);
        List<MonitorPoint> monitorPoints = monitorPointMapper.selectList(queryMonitorPointsWrapper);
        //查询站点对应的设备
        for (MonitorPoint monitorPoint : monitorPoints) {
            List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPoint.getId());
            monitorPoint.setDevices(devices);
        }
        return monitorPoints;
    }
 
 
}