package com.moral.service.impl;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Service;
|
|
import com.moral.mapper.OrganizationRelationMapper;
|
import com.moral.service.OrganizationRelationService;
|
|
@Service
|
public class OrganizationRelationServiceImpl implements OrganizationRelationService {
|
|
@Resource
|
private OrganizationRelationMapper organizationRelationMapper;
|
|
@Override
|
public List<Object> getChildIdByParentId(List<Integer> parentIdList) {
|
|
List<Object> organizationIdList = new ArrayList<>();
|
for (Integer parentId : parentIdList) {
|
organizationIdList.add(parentId);
|
}
|
//进行循环
|
for (int i = 0; i < 10; i++) {
|
if (!parentIdList.isEmpty()) {
|
//或去该组织下的子组织
|
List<Map<String, Integer>> childIdList = organizationRelationMapper.getChildIdByParentId(parentIdList);
|
//清空父组织id集合
|
parentIdList.clear();
|
//将子组织id放入到集合中
|
for (Map<String, Integer> map : childIdList) {
|
organizationIdList.add(map.get("child_id"));
|
parentIdList.add(map.get("child_id"));
|
}
|
} else {
|
break;
|
}
|
}
|
return organizationIdList;
|
}
|
|
@Override
|
public Integer getParentIdByChildId(Integer childId) {
|
Integer parentId = organizationRelationMapper.getParentIdByChildId(childId);
|
if (parentId != null) {
|
childId = parentId;
|
return getParentIdByChildId(childId);
|
}
|
return childId;
|
}
|
|
@Override
|
public List<Integer> getParentIdListByChildId(Integer childId) {
|
List<Integer> organizationIdList = new ArrayList<>();
|
organizationIdList.add(childId);
|
for (int i = 0; i < 10; i++) {
|
if (childId != null) {
|
Integer parentId = organizationRelationMapper.getParentIdByChildId(childId);
|
childId = parentId;
|
if (childId != null) {
|
organizationIdList.add(childId);
|
}
|
} else {
|
break;
|
}
|
}
|
return organizationIdList;
|
}
|
|
}
|