| | |
| | | package com.moral.api.service.impl; |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
| | | import com.moral.api.entity.Organization; |
| | | import com.moral.api.mapper.OrganizationMapper; |
| | | 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; |
| | | |
| | | @Override |
| | | public List<Organization> getChildrenOrganizationsById(Integer id) { |
| | | List<Organization> childrenOrganization = new ArrayList<>(); |
| | | recursionQueryChildren(id,childrenOrganization); |
| | | return childrenOrganization; |
| | | } |
| | | |
| | | @Override |
| | | public Organization getStateControlStation() { |
| | | QueryWrapper<Organization> wrapper = new QueryWrapper<>(); |
| | | wrapper.select("id"); |
| | | wrapper.eq("name","国控站"); |
| | | wrapper.eq("is_delete",Constants.NOT_DELETE); |
| | | Organization organization = organizationMapper.selectOne(wrapper); |
| | | return organization; |
| | | } |
| | | |
| | | /** |
| | | * @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; |
| | | } |
| | | } |
| | | } |