|  |  |  | 
|---|
|  |  |  | 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> | 
|---|
|  |  |  | 
|---|
|  |  |  | Organization organization = organizationMapper.selectOne(wrapper_organization); | 
|---|
|  |  |  | return organization; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 根据父组织获取所有子组织 | 
|---|
|  |  |  | * @Param: [] | 
|---|
|  |  |  | * @return: java.util.List<com.moral.api.entity.Organization> | 
|---|
|  |  |  | * @Author: 陈凯裕 | 
|---|
|  |  |  | * @Date: 2021/4/14 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | @Override | 
|---|
|  |  |  | public List<Organization> getAllChildrenOrganization(Integer parentId) { | 
|---|
|  |  |  | List<Organization> children = new ArrayList<>(); | 
|---|
|  |  |  | recursionQueryChildren(parentId, children); | 
|---|
|  |  |  | return children; | 
|---|
|  |  |  | } | 
|---|
|  |  |  |  | 
|---|
|  |  |  | /** | 
|---|
|  |  |  | * @Description: 通过父组织查询下面所有的子组织放到children中 | 
|---|
|  |  |  | * @Param: [parent, children] | 
|---|
|  |  |  | * @return: void | 
|---|
|  |  |  | * @Author: 陈凯裕 | 
|---|
|  |  |  | * @Date: 2021/4/14 | 
|---|
|  |  |  | */ | 
|---|
|  |  |  | private void recursionQueryChildren(Integer parentId, List<Organization> children) { | 
|---|
|  |  |  | QueryWrapper<Organization> queryWrapper = new QueryWrapper(); | 
|---|
|  |  |  | 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; | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|
|  |  |  | } | 
|---|