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; /** *

* 服务实现类 *

* * @author moral * @since 2021-07-01 */ @Service public class MonitorPointServiceImpl extends ServiceImpl implements MonitorPointService { @Autowired MonitorPointMapper monitorPointMapper; @Autowired OrganizationService organizationService; @Autowired DeviceService deviceService; @Override public List queryByOrgIdAndRegionCode(MonitorPointQueryForm form) { //取参 Integer organizationId = form.getOrganizationId(); Integer regionCode = form.getRegionCode(); String region = RegionCodeUtils.regionCodeConvertToName(regionCode); //查询子组织 List childrenOrganization = organizationService.getChildrenOrganizationsById(organizationId); List organizationIds = new ArrayList<>(); for (Organization organization : childrenOrganization) { organizationIds.add(organization.getId()); } organizationIds.add(organizationId); //查询站点 QueryWrapper queryMonitorPointsWrapper = new QueryWrapper<>(); queryMonitorPointsWrapper.eq(region,regionCode); queryMonitorPointsWrapper.in("organization_id",organizationIds); queryMonitorPointsWrapper.eq("is_delete", Constants.NOT_DELETE); List monitorPoints = monitorPointMapper.selectList(queryMonitorPointsWrapper); //查询站点对应的设备 for (MonitorPoint monitorPoint : monitorPoints) { List devices = deviceService.getDevicesByMonitorPointId(monitorPoint.getId()); monitorPoint.setDevices(devices); } return monitorPoints; } @Override public List queryStateControlStationByRegionCode(Integer regionCode) { //获取国控站组织 Organization stateControlStationOrganization = organizationService.getStateControlStation(); //获取国控站组织下的所有站点 QueryWrapper 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); } }