| | |
| | | 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.config.Interceptor.UserHelper; |
| | | 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.user.QxUser; |
| | | 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> |
| | |
| | | OrganizationMapper organizationMapper; |
| | | |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | MonitorPointMapper monitorPointMapper; |
| | | |
| | | |
| | | @Autowired |
| | | DeviceMapper deviceMapper; |
| | | |
| | | |
| | | |
| | | @Override |
| | |
| | | return organizationMapper.selectById(id); |
| | | } |
| | | |
| | | /** |
| | | * 根据用户查询组织 |
| | | * |
| | | * @return |
| | | */ |
| | | @Override |
| | | public List<Organization> getOrganizations() { |
| | | QueryWrapper<Organization> wrapper = new QueryWrapper<>(); |
| | | wrapper.select("id","name"); |
| | | QxUser user = UserHelper.getCurrentUser(); |
| | | Integer organizationId = user.getOrganizationId(); |
| | | if (organizationId!=24){ |
| | | wrapper.eq("id",user.getOrganizationId()); |
| | | } |
| | | wrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | List<Organization> organizations = organizationMapper.selectList(wrapper); |
| | | for (int i=0; i<organizations.size(); i++) { |
| | | List<String> macs = deviceService.getMacsByOrganizationId(organizations.get(i).getId()); |
| | | if (ObjectUtils.isEmpty(macs)){ |
| | | organizations.remove(i); |
| | | i--; |
| | | } |
| | | } |
| | | return organizations; |
| | | } |
| | | |
| | | |
| | | /** |
| | |
| | | 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; |
| | | } |
| | | } |