| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | 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.OrganizationMapper; |
| | | import com.moral.api.pojo.vo.user.QxUser; |
| | | 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 org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.ObjectUtils; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Service |
| | | public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper, Organization> implements OrganizationService { |
| | | |
| | | @Autowired |
| | | OrganizationMapper organizationMapper; |
| | | |
| | | @Autowired |
| | | private DeviceService deviceService; |
| | | |
| | | |
| | | @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); |
| | | } |
| | | |
| | | /** |
| | | * 根据用户查询组织 |
| | | * |
| | | * @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; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @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; |
| | | } |
| | | } |
| | | } |