|
|
@@ -4,10 +4,15 @@ import com.horizon.common.collect.Lists;
|
|
4
|
4
|
import com.horizon.core.HorizonCore;
|
|
5
|
5
|
import com.horizon.db.Access;
|
|
6
|
6
|
import com.horizon.third.adapter.OrganizationAdapter;
|
|
|
7
|
+import com.horizon.third.build.OrgDataBuilderHolder;
|
|
|
8
|
+import com.horizon.third.entity.OrgData;
|
|
|
9
|
+import com.horizon.third.entity.User;
|
|
7
|
10
|
import com.horizon.utils.StringUtil;
|
|
8
|
11
|
import org.slf4j.Logger;
|
|
9
|
12
|
import org.slf4j.LoggerFactory;
|
|
10
|
13
|
|
|
|
14
|
+import java.util.ArrayList;
|
|
|
15
|
+import java.util.Collections;
|
|
11
|
16
|
import java.util.List;
|
|
12
|
17
|
import java.util.Map;
|
|
13
|
18
|
|
|
|
@@ -44,13 +49,15 @@ public class GroupOrPositionUtil {
|
|
44
|
49
|
List<Map<String, String>> userByIDs = organization.getUserByIDs(orgUserIds.split(";"), HorizonCore.TENANT_IDENTIFIER.value());
|
|
45
|
50
|
// 根据userid获取用户信息
|
|
46
|
51
|
Map<String, String> userMap = organization.getUserById(userId, HorizonCore.TENANT_IDENTIFIER.value());
|
|
|
52
|
+ System.err.println("用户:" + userId);
|
|
47
|
53
|
String deptId = userMap.get("dept_id");
|
|
48
|
|
- String fDeptId = GroupOrPositionUtil.queryFDept(deptId);
|
|
49
|
|
- LOGGER.info("deptId:{}_fDeptId:{}", deptId, fDeptId);
|
|
|
54
|
+ System.err.println("用户部门:" + deptId);
|
|
|
55
|
+
|
|
|
56
|
+ String fDeptId = GroupOrPositionUtil.queryFDept(deptId);
|
|
|
57
|
+
|
|
50
|
58
|
// 对比用户所属部门,如果相同,则添加到userIds中
|
|
51
|
59
|
for (Map<String, String> user : userByIDs) {
|
|
52
|
|
- String fDeptIdTmp = GroupOrPositionUtil.queryFDept(user.get("dept_id"));
|
|
53
|
|
- LOGGER.info("deptId:{}_fDeptIdTmp:{}_fDeptIdTmp:{}", user.get("dept_id"), fDeptIdTmp, fDeptId);
|
|
|
60
|
+ String fDeptIdTmp = GroupOrPositionUtil.queryFDept(user.get("dept_id"));
|
|
54
|
61
|
if (fDeptIdTmp.equals(fDeptId)) {
|
|
55
|
62
|
userIds += user.get("id") + "/" + orgId + ";";
|
|
56
|
63
|
LOGGER.info("获取到{}里同步人员id:{}", orgId, user.get("id"));
|
|
|
@@ -60,8 +67,6 @@ public class GroupOrPositionUtil {
|
|
60
|
67
|
return userIds;
|
|
61
|
68
|
}
|
|
62
|
69
|
|
|
63
|
|
-
|
|
64
|
|
-
|
|
65
|
70
|
/**
|
|
66
|
71
|
* 获取userid所属部门,与设置的群组/岗位 下的人同部门的用户
|
|
67
|
72
|
*
|
|
|
@@ -72,7 +77,7 @@ public class GroupOrPositionUtil {
|
|
72
|
77
|
public static String getUserBySameDeptAndOrg(String orgIds[], String userId) {
|
|
73
|
78
|
OrganizationAdapter organization = new OrganizationAdapter();
|
|
74
|
79
|
// 最终办理人用户id
|
|
75
|
|
- String userIds = "";
|
|
|
80
|
+ StringBuilder userIds = new StringBuilder();
|
|
76
|
81
|
// 获取群组下的所有用户信息
|
|
77
|
82
|
if (orgIds.length < 1) return "";
|
|
78
|
83
|
for (String orgId : orgIds) {
|
|
|
@@ -84,20 +89,52 @@ public class GroupOrPositionUtil {
|
|
84
|
89
|
orgUserIds = organization.getAllUserFromPosition(orgId.replace("P_", ""), HorizonCore.TENANT_IDENTIFIER.value());
|
|
85
|
90
|
}
|
|
86
|
91
|
if (!StringUtil.hasValue(orgUserIds)) return "";
|
|
87
|
|
- // 根据多个用户id,获取用户信息
|
|
88
|
|
- List<Map<String, String>> userByIDs = organization.getUserByIDs(orgUserIds.split(";"), HorizonCore.TENANT_IDENTIFIER.value());
|
|
89
|
|
- // 根据userid获取用户信息
|
|
90
|
|
- Map<String, String> userMap = organization.getUserById(userId, HorizonCore.TENANT_IDENTIFIER.value());
|
|
91
|
|
- String deptId = userMap.get("dept_id");
|
|
92
|
|
- // 对比用户所属部门,如果相同,则添加到userIds中
|
|
93
|
|
- for (Map<String, String> user : userByIDs) {
|
|
94
|
|
- if (user.get("dept_id").equals(deptId)) {
|
|
95
|
|
- userIds += user.get("id") + "/" + orgId + ";";
|
|
96
|
|
- LOGGER.info("获取到{}里同步人员id:{}", orgId, user.get("id"));
|
|
|
92
|
+
|
|
|
93
|
+ List<User> userList = new ArrayList<>();
|
|
|
94
|
+ for (String userIdTmp : orgUserIds.split(";")) {
|
|
|
95
|
+ User user = OrgDataBuilderHolder.getBuilder().getUserById(userIdTmp);
|
|
|
96
|
+ userList.add(user);
|
|
|
97
|
+ }
|
|
|
98
|
+
|
|
|
99
|
+ User CurrentUser = OrgDataBuilderHolder.getBuilder().getUserById(userId);
|
|
|
100
|
+ List<String> deptIds = CurrentUser.getDepartment();
|
|
|
101
|
+
|
|
|
102
|
+ for (int i = 0; i < deptIds.size(); i++) {
|
|
|
103
|
+ if (!deptIds.get(i).startsWith("D_")) {
|
|
|
104
|
+ deptIds.set(i, "D_" + deptIds.get(i));
|
|
97
|
105
|
}
|
|
98
|
106
|
}
|
|
|
107
|
+
|
|
|
108
|
+
|
|
|
109
|
+// // 根据多个用户id,获取用户信息
|
|
|
110
|
+// List<Map<String, String>> userByIDs = organization.getUserByIDs(orgUserIds.split(";"), HorizonCore.TENANT_IDENTIFIER.value());
|
|
|
111
|
+// // 根据userid获取用户信息
|
|
|
112
|
+// Map<String, String> userMap = organization.getUserById(userId, HorizonCore.TENANT_IDENTIFIER.value());
|
|
|
113
|
+
|
|
|
114
|
+
|
|
|
115
|
+ for (User user : userList) {
|
|
|
116
|
+ List<String> deptList = user.getDepartment();
|
|
|
117
|
+
|
|
|
118
|
+ if (deptList == null) {
|
|
|
119
|
+ continue;
|
|
|
120
|
+ }
|
|
|
121
|
+ for (int i = 0; i < deptList.size(); i++) {
|
|
|
122
|
+ if (!deptList.get(i).startsWith("D_")) {
|
|
|
123
|
+ deptList.set(i, "D_" + deptList.get(i));
|
|
|
124
|
+ }
|
|
|
125
|
+ }
|
|
|
126
|
+
|
|
|
127
|
+ LOGGER.info("deptList:{},deptIds:{}", deptList.toString(), deptIds.toString());
|
|
|
128
|
+
|
|
|
129
|
+ boolean hasIntersection = !Collections.disjoint(deptList, deptIds);
|
|
|
130
|
+ if (hasIntersection) {
|
|
|
131
|
+ userIds.append(user.getId()).append("/").append(orgId).append(";");
|
|
|
132
|
+ LOGGER.info("获取到{}里同步人员id:{}", orgId, user.getId());
|
|
|
133
|
+ }
|
|
|
134
|
+ }
|
|
|
135
|
+
|
|
99
|
136
|
}
|
|
100
|
|
- return userIds;
|
|
|
137
|
+ return userIds.toString();
|
|
101
|
138
|
}
|
|
102
|
139
|
|
|
103
|
140
|
public static String queryFDept(String deptId){
|
|
|
@@ -126,4 +163,122 @@ public class GroupOrPositionUtil {
|
|
126
|
163
|
}
|
|
127
|
164
|
return fDeptId;
|
|
128
|
165
|
}
|
|
|
166
|
+
|
|
|
167
|
+
|
|
|
168
|
+ /**
|
|
|
169
|
+ * 获取userid所属部门,与设置的群组/岗位 下的人同部门的用户
|
|
|
170
|
+ *
|
|
|
171
|
+ * @param orgIds
|
|
|
172
|
+ * @param userId
|
|
|
173
|
+ * @return
|
|
|
174
|
+ */
|
|
|
175
|
+ public static String getUserBySameDeptAndOrgResolver(String orgIds[], String userId) {
|
|
|
176
|
+ OrganizationAdapter organization = new OrganizationAdapter();
|
|
|
177
|
+ // 最终办理人用户id
|
|
|
178
|
+ StringBuilder userIds = new StringBuilder();
|
|
|
179
|
+ int lenDiff = 0;
|
|
|
180
|
+ // 获取群组下的所有用户信息
|
|
|
181
|
+ if (orgIds.length < 1) return "";
|
|
|
182
|
+// for (String orgId : orgIds) {
|
|
|
183
|
+// String orgUserIds = "";
|
|
|
184
|
+// // 获取群组下的所有用户id
|
|
|
185
|
+// if (orgId.contains("G_")) {
|
|
|
186
|
+// orgUserIds = organization.getAllUserFromGroup(orgId.replace("G_", ""), HorizonCore.TENANT_IDENTIFIER.value());
|
|
|
187
|
+// } else if (orgId.contains("P_")) {
|
|
|
188
|
+// orgUserIds = organization.getAllUserFromPosition(orgId.replace("P_", ""), HorizonCore.TENANT_IDENTIFIER.value());
|
|
|
189
|
+// }
|
|
|
190
|
+// if (!StringUtil.hasValue(orgUserIds)) return "";
|
|
|
191
|
+//
|
|
|
192
|
+// List<User> userList = new ArrayList<>();
|
|
|
193
|
+// for (String userIdTmp : orgUserIds.split(";")) {
|
|
|
194
|
+// User user = OrgDataBuilderHolder.getBuilder().getUserById(userIdTmp);
|
|
|
195
|
+// userList.add(user);
|
|
|
196
|
+// }
|
|
|
197
|
+//
|
|
|
198
|
+// User CurrentUser = OrgDataBuilderHolder.getBuilder().getUserById(userId);
|
|
|
199
|
+// List<String> deptIds = CurrentUser.getDepartment();
|
|
|
200
|
+//
|
|
|
201
|
+// for (int i = 0; i < deptIds.size(); i++) {
|
|
|
202
|
+// if (!deptIds.get(i).startsWith("D_")) {
|
|
|
203
|
+// deptIds.set(i, "D_" + deptIds.get(i));
|
|
|
204
|
+// }
|
|
|
205
|
+// }
|
|
|
206
|
+//
|
|
|
207
|
+// for (User user : userList) {
|
|
|
208
|
+// List<String> deptList = user.getDepartment();
|
|
|
209
|
+// for (int i = 0; i < deptList.size(); i++) {
|
|
|
210
|
+// if (!deptList.get(i).startsWith("D_")) {
|
|
|
211
|
+// deptList.set(i, "D_" + deptList.get(i));
|
|
|
212
|
+// }
|
|
|
213
|
+// }
|
|
|
214
|
+//
|
|
|
215
|
+// boolean hasIntersection = !Collections.disjoint(deptList, deptIds);
|
|
|
216
|
+// if (hasIntersection) {
|
|
|
217
|
+// userIds.append(user.getId()).append("/").append(orgId).append(";");
|
|
|
218
|
+// LOGGER.info("获取到{}里同步人员id:{}", orgId, user.getId());
|
|
|
219
|
+// }
|
|
|
220
|
+// }
|
|
|
221
|
+//
|
|
|
222
|
+// }
|
|
|
223
|
+
|
|
|
224
|
+ do {
|
|
|
225
|
+ for (String orgId : orgIds) {
|
|
|
226
|
+ String orgUserIds = "";
|
|
|
227
|
+ // 获取群组下的所有用户id
|
|
|
228
|
+ if (orgId.contains("G_")) {
|
|
|
229
|
+ orgUserIds = organization.getAllUserFromGroup(orgId.replace("G_", ""), HorizonCore.TENANT_IDENTIFIER.value());
|
|
|
230
|
+ } else if (orgId.contains("P_")) {
|
|
|
231
|
+ orgUserIds = organization.getAllUserFromPosition(orgId.replace("P_", ""), HorizonCore.TENANT_IDENTIFIER.value());
|
|
|
232
|
+ }
|
|
|
233
|
+ if (!StringUtil.hasValue(orgUserIds)) return "";
|
|
|
234
|
+
|
|
|
235
|
+ List<User> userList = new ArrayList<>();
|
|
|
236
|
+ for (String userIdTmp : orgUserIds.split(";")) {
|
|
|
237
|
+ User user = OrgDataBuilderHolder.getBuilder().getUserById(userIdTmp);
|
|
|
238
|
+ userList.add(user);
|
|
|
239
|
+ }
|
|
|
240
|
+
|
|
|
241
|
+ User CurrentUser = OrgDataBuilderHolder.getBuilder().getUserById(userId);
|
|
|
242
|
+ List<String> deptIds = CurrentUser.getDepartment();
|
|
|
243
|
+
|
|
|
244
|
+ for (int i = 0; i < deptIds.size(); i++) {
|
|
|
245
|
+ OrgData orgData = null;
|
|
|
246
|
+ if (deptIds.get(i).startsWith("D_")) {
|
|
|
247
|
+ orgData = OrgDataBuilderHolder.getBuilder().getOrgDataById("D", deptIds.get(i).substring(2));
|
|
|
248
|
+ } else {
|
|
|
249
|
+ orgData = OrgDataBuilderHolder.getBuilder().getOrgDataById("D", deptIds.get(i));
|
|
|
250
|
+ }
|
|
|
251
|
+ if (orgData != null && orgData.getCode().length() > 4) {
|
|
|
252
|
+ deptIds.add(orgData.getCode().substring(0, Math.max(orgData.getCode().length() - lenDiff, 1)));
|
|
|
253
|
+ }
|
|
|
254
|
+ }
|
|
|
255
|
+
|
|
|
256
|
+
|
|
|
257
|
+ for (User user : userList) {
|
|
|
258
|
+ List<String> deptList = user.getDepartment();
|
|
|
259
|
+ for (int i = 0; i < deptList.size(); i++) {
|
|
|
260
|
+ OrgData orgData = null;
|
|
|
261
|
+ if (deptList.get(i).startsWith("D_")) {
|
|
|
262
|
+ orgData = OrgDataBuilderHolder.getBuilder().getOrgDataById("D", deptList.get(i).substring(2));
|
|
|
263
|
+ } else {
|
|
|
264
|
+ orgData = OrgDataBuilderHolder.getBuilder().getOrgDataById("D", deptList.get(i));
|
|
|
265
|
+ }
|
|
|
266
|
+ if (orgData != null && orgData.getCode().length() > 4) {
|
|
|
267
|
+ deptList.add(orgData.getCode().substring(0, Math.max(orgData.getCode().length() - lenDiff, 1)));
|
|
|
268
|
+ }
|
|
|
269
|
+ }
|
|
|
270
|
+
|
|
|
271
|
+ boolean hasIntersection = !Collections.disjoint(deptList, deptIds);
|
|
|
272
|
+ if (hasIntersection) {
|
|
|
273
|
+ userIds.append(user.getId()).append("/").append(orgId).append(";");
|
|
|
274
|
+ LOGGER.info("获取到{}里同步人员id:{}", orgId, user.getId());
|
|
|
275
|
+ }
|
|
|
276
|
+ }
|
|
|
277
|
+
|
|
|
278
|
+ }
|
|
|
279
|
+ lenDiff = lenDiff + 2;
|
|
|
280
|
+ } while (userIds.length() == 0 && lenDiff < 5);
|
|
|
281
|
+ return userIds.toString();
|
|
|
282
|
+ }
|
|
|
283
|
+
|
|
129
|
284
|
}
|