| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.mapper.DeviceMapper; |
| | | import com.moral.api.mapper.MonitorPointMapper; |
| | | import com.moral.api.mapper.OrganizationMapper; |
| | | import com.moral.api.pojo.vo.device.DeviceVO; |
| | | import com.moral.api.pojo.vo.monitorPoint.MonitorPointVos; |
| | | import com.moral.api.service.DeviceService; |
| | | import com.moral.api.service.OrganizationService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.moral.constant.Constants; |
| | | import com.moral.util.TokenUtils; |
| | | import org.apache.commons.collections4.CollectionUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService { |
| | | |
| | | @Autowired |
| | | OrganizationMapper organizationMapper; |
| | | |
| | | @Autowired |
| | | MonitorPointMapper monitorPointMapper; |
| | | |
| | | |
| | | @Autowired |
| | | DeviceMapper deviceMapper; |
| | | |
| | | |
| | | |
| | | @Override |
| | | public List<Organization> getChildrenOrganizationsById(Integer id) { |
| | | List<Organization> childrenOrganization = new ArrayList<>(); |
| | | recursionQueryChildren(id,childrenOrganization); |
| | | return childrenOrganization; |
| | | } |
| | | |
| | | @Override |
| | | public Organization getOrganizationById(Integer id) { |
| | | return organizationMapper.selectById(id); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * @Description: 通过父组织查询下面所有的子组织放到children中 |
| | | * @Param: [parentId, children] |
| | | * @return: void |
| | | * @Author: 陈凯裕 |
| | | * @Date: 2021/7/1 |
| | | */ |
| | | private void recursionQueryChildren(Integer parentId, List<Organization> children) { |
| | | QueryWrapper<Organization> queryWrapper = new QueryWrapper(); |
| | | queryWrapper.select("id"); |
| | | queryWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | queryWrapper.eq("parent_id", parentId); |
| | | List<Organization> organizations = organizationMapper.selectList(queryWrapper); |
| | | if (!ObjectUtils.isEmpty(organizations)) { |
| | | children.addAll(organizations); |
| | | for (Organization organization : organizations) { |
| | | recursionQueryChildren(organization.getId(), children); |
| | | } |
| | | } else { |
| | | return; |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public List<Integer> orgIdList(Integer organizationId) { |
| | | return this.baseMapper.orgIdList(organizationId); |
| | | } |
| | | |
| | | /** |
| | | * 根据id获取组织信息 |
| | | * |
| | | * @param |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Organization> getOrganizationId() { |
| | | //获取用户信息 |
| | | Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo(); |
| | | Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization"); |
| | | Integer organizationId = (Integer) orgInfo.get("id"); |
| | | ArrayList<Organization> rsList = new ArrayList<>(); |
| | | if (organizationId==24){ |
| | | LambdaQueryWrapper<Organization> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.eq(Organization::getParentId,organizationId); |
| | | wrapper.eq(Organization::getIsDelete,Constants.NOT_DELETE); |
| | | wrapper.orderByDesc(Organization::getCreateTime); |
| | | List<Organization> organizations = organizationMapper.selectList(wrapper); |
| | | rsList.addAll(organizations); |
| | | }else { |
| | | Organization organizationById = this.getOrganizationById(organizationId); |
| | | rsList.add(organizationById); |
| | | } |
| | | return rsList; |
| | | } |
| | | |
| | | /** |
| | | * 查询组织信息 |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Organization> queryDevices() { |
| | | Map<String, Object> userInfo = (Map<String, Object>) TokenUtils.getUserInfo(); |
| | | Map<String, Object> orgInfo = (Map<String, Object>) userInfo.get("organization"); |
| | | Integer organizationId = (Integer) orgInfo.get("id"); |
| | | LambdaQueryWrapper<Organization> wrapper = new LambdaQueryWrapper<>(); |
| | | wrapper.select(Organization::getId,Organization::getAddress,Organization::getAreaName,Organization::getName); |
| | | wrapper.eq(Organization::getIsDelete,Constants.NOT_DELETE); |
| | | wrapper.orderByDesc(Organization::getCreateTime); |
| | | List<Organization> organizations; |
| | | if (organizationId==24){ |
| | | wrapper.eq(Organization::getParentId,organizationId); |
| | | organizations = organizationMapper.selectList(wrapper); |
| | | }else { |
| | | wrapper.eq(Organization::getId,organizationId); |
| | | organizations = organizationMapper.selectList(wrapper); |
| | | } |
| | | if (CollectionUtils.isNotEmpty(organizations)){ |
| | | organizations.forEach(it ->{ |
| | | //查询站点 |
| | | // QueryWrapper<MonitorPoint> queryMonitorPointsWrapper = new QueryWrapper<>(); |
| | | // queryMonitorPointsWrapper.eq("organization_id", it.getId()); |
| | | // queryMonitorPointsWrapper.eq("is_delete", Constants.NOT_DELETE); |
| | | // List<MonitorPoint> monitorPoints = monitorPointMapper.selectList(queryMonitorPointsWrapper); |
| | | List<MonitorPointVos> monitorPoints = monitorPointMapper.getMonitorPoint(it.getId()); |
| | | //查询站点对应的设备 |
| | | for (MonitorPointVos monitorPoint : monitorPoints) { |
| | | // List<Device> devices = deviceService.getDevicesByMonitorPointId(monitorPoint.getId()); |
| | | List<DeviceVO> listVo = deviceMapper.getListVo(monitorPoint.getId()); |
| | | monitorPoint.setMonitorPoint(listVo); |
| | | } |
| | | it.setMonitorPoint(monitorPoints); |
| | | } ); |
| | | } |
| | | return organizations; |
| | | } |
| | | } |