kaiyu
2021-07-01 49875151be4b427935fcb3d60696e99ba9d2e1ad
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
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> query(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;
    }
}