kaiyu
2021-07-16 3b29244703787dda85386167dca4126b5b0f150c
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
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.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 = 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<>();
        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;
    }
 
    @Override
    public List<MonitorPoint> queryStateControlStationByRegionCode(Integer regionCode) {
        //获取国控站组织
        Organization stateControlStationOrganization = organizationService.getStateControlStation();
        //获取国控站组织下的所有站点
        QueryWrapper<MonitorPoint> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("is_delete",Constants.NOT_DELETE);
        queryWrapper.eq("organization_id",stateControlStationOrganization.getId());
        queryWrapper.eq(RegionCodeUtils.regionCodeConvertToName(regionCode),regionCode);
        return monitorPointMapper.selectList(queryWrapper);
    }
}