zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package com.changhong.epc.rely.api.tool;
 
import com.changhong.epc.rely.api.bean.Organization;
import com.iemsoft.framework.cloud.core.tools.ObjectUtil;
 
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
 
/**
 * 组织机构数据处理
 * @author liush
 *
 */
public class OrgUtil {
    
    /**
     * 格式化组织机构树(去掉user position)
     * @param list
     */
    public static void organizationFormat(List<Organization> list) {
        if(list != null)
        for(Organization organization:list) {
            if(organization.getUsers() != null)
                organization.getUsers().clear();
            if(organization.getPositions() != null)
                organization.getPositions().clear();
            organizationFormat(organization.getChildren());
        }
    }
    
    /**
     * 转换数组为集合
     * @param strArrays
     * @return
     */
    public static List<String> getCodeList(String[] strArrays) {
        List<String> strList = new ArrayList<String>();
        for(String str : strArrays) {
            strList.add(str);
        }
        return strList;
    }
    
    /**
     * 获取组织机构code对应的name生成Map
     * @param strCodeList
     * @param organizationList
     * @return
     */
    public static Map<String, String> getMap(List<String> strCodeList, List<Organization> organizationList) {
        Map<String, String> map = new HashMap<>();
        if(ObjectUtil.empty(strCodeList)){
            return map;
        }
        for(String str : strCodeList) {
            List<String> getNameList = new ArrayList<>();
            getOrgName(str, organizationList, getNameList);
            if(getNameList.size() == 1) {
                for(String strValue : getNameList) {
                    map.put(str, strValue);
                }
            } else {
                map.put(str, getNameList.toString());
            }
            
            
        }
        return map;
    }
    
    
    /**
     * 依据组织机构code获取对应的name
     * @param list
     * @return
     */
    public static String getOrgName(String orgCode, List<Organization> list ,List<String> orgName){
        if(list != null)
            for(Organization organization:list) {
                if(organization.getCode().equals(orgCode)) {
                    orgName.add(organization.getName());
                }
                if(ObjectUtil.notEmpty(orgName)){
                    return null;
                }
                getOrgName(orgCode, organization.getChildren(), orgName);
            }
        return null;
    }
    
    
    /**
     * 依据组织机构code数组查询对应的name并格式化为,分隔的形式
     * @param map
     * @param orgCodes
     * @return
     */
    public static String stringFormat(Map<String, String> map, String[] orgCodes) {
        StringBuilder ids = new StringBuilder();
        List<String> strList = new ArrayList<>();
        for(String str : orgCodes) {
            strList.add(map.get(str));
        }
        if(ObjectUtil.empty(strList)){
            return null;
        } else {
             for (int i = 0; i < strList.size(); i++) {
                if (i != 0) {
                    ids.append(",");
                }
                ids.append(strList.get(i));
            }
        }
        return ids.toString();
    }
    
    /**
     * 依据组织机构code查询name
     * @param list
     * @param organization
     * @return
     */
    public static String getOrg(String orgCode, List<Organization> list, Organization organization){
        if(list != null)
            for(Organization org:list) {
                if(org.getCode().equals(orgCode)) {
                    organization.setName(org.getName());
                }
                getOrg(orgCode, org.getChildren(), organization);
            }
        return null;
    }
    
    /**
     * 依据组织机构code查询父机构code
     * @param list
     * @param organization
     * @return
     */
    public static String getParentId(String orgCode, List<Organization> list, Organization organization){
        if(list != null)
            for(Organization org:list) {
                if(org.getCode().equals(orgCode)) {
                    // System.err.println(org);
                    organization.setId(org.getParentId());
                }
                getParentId(orgCode, org.getChildren(), organization);
            }
        return null;
    }
    
    /**
     * 依据组织机构id查询code和name
     * @param list
     * @param organization
     * @return
     */
    public static String getParentOrg(String id, List<Organization> list, Organization organization){
        if(list != null)
            for(Organization org:list) {
                // System.out.println("org"+org.getId()+"id"+id);
                if(org.getId().equals(id)) {
                    organization.setName(org.getName());
                    organization.setCode(org.getCode());
                }
                getParentOrg(id, org.getChildren(), organization);
            }
        return null;
    }
 
}