lizijie
2021-11-29 d8310f6bc609440fa352c0e5a9436c7c78caa287
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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;
    }
 
}