xufenglei
2017-12-01 b41f303340d8c21dad9e1b2fd798a0957e7fd7d1
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
package com.moral.service.impl;
 
import static com.moral.common.bean.Constants.IS_DELETE_FALSE;
 
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import com.moral.entity.Organization;
import com.moral.entity.OrganizationRelation;
import com.moral.entity.OrganizationRelationExample;
import com.moral.mapper.OrganizationMapper;
import com.moral.mapper.OrganizationRelationMapper;
import com.moral.service.OrganizationService;
 
@Service
public class OrganizationServiceImpl implements OrganizationService {
 
    @Autowired
    private OrganizationMapper organizationMapper;
 
    @Autowired
    private OrganizationRelationMapper organizationRelationMapper;
 
    @Override
    public Set<Integer> getChildOrganizationIds(Integer orgId){
        Set<Integer> orgIds = new HashSet<Integer>();
        orgIds.add(orgId);
        OrganizationRelationExample example = new OrganizationRelationExample();
        example.or().andParentIdEqualTo(orgId);
        Organization organization = organizationMapper.selectByPrimaryKey(orgId);
        if (IS_DELETE_FALSE.equals(organization.getIsDelete())) {
            List<OrganizationRelation> organizationRelations = organizationRelationMapper.selectByExample(example);
            for (OrganizationRelation organizationRelation : organizationRelations) {
                Set<Integer> organizationIds = getChildOrganizationIds(organizationRelation.getParentId());
                orgIds.addAll(organizationIds);
            }
        }
        return orgIds;
    }
 
}