UserManagerService.java 20.3 KB
Newer Older
R
roo00 已提交
1 2 3 4 5
package com.x.cms.assemble.control.service;

import com.x.base.core.container.EntityManagerContainer;
import com.x.base.core.container.factory.EntityManagerContainerFactory;
import com.x.base.core.project.http.EffectivePerson;
R
Ray 已提交
6 7
import com.x.base.core.project.logger.Logger;
import com.x.base.core.project.logger.LoggerFactory;
NoSubject's avatar
NoSubject 已提交
8
import com.x.base.core.project.organization.Identity;
O
o2sword 已提交
9
import com.x.base.core.project.organization.OrganizationDefinition;
R
roo00 已提交
10
import com.x.base.core.project.organization.Person;
R
roo00 已提交
11
import com.x.base.core.project.organization.Unit;
R
roo00 已提交
12
import com.x.base.core.project.tools.ListTools;
R
roo00 已提交
13
import com.x.cms.assemble.control.Business;
NoSubject's avatar
NoSubject 已提交
14
import com.x.cms.assemble.control.ThisApplication;
R
Ray 已提交
15 16
import com.x.cms.core.entity.AppInfo;
import com.x.organization.core.entity.PersistenceProperties;
O
o2sword 已提交
17 18 19 20 21 22
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
R
roo00 已提交
23 24 25

/**
 * 组织人员角色相关信息的服务类
O
o2sword 已提交
26
 *
R
roo00 已提交
27 28 29
 * @author O2LEE
 */
public class UserManagerService {
NoSubject's avatar
NoSubject 已提交
30

O
o2sword 已提交
31 32
	private static Logger logger = LoggerFactory.getLogger(UserManagerService.class);

R
roo00 已提交
33 34
	/**
	 * 根据人员名称获取人员
O
o2sword 已提交
35
	 *
R
roo00 已提交
36 37 38 39
	 * @param personName
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
40
	public Person getPerson(String personName) throws Exception {
O
o2sword 已提交
41 42 43 44 45 46
		if(StringUtils.isNotBlank(personName)){
			return null;
		}
		Business business = new Business(null);
		if(personName.split("@").length == 2){
			personName = personName.split("@")[0];
R
roo00 已提交
47
		}
O
o2sword 已提交
48
		return business.organization().person().getObject(personName);
R
roo00 已提交
49
	}
NoSubject's avatar
NoSubject 已提交
50

R
roo00 已提交
51
	/**
NoSubject's avatar
NoSubject 已提交
52
	 * 根据员工姓名获取组织名称 如果用户有多个身份,则取组织级别最大的组织名称
O
o2sword 已提交
53
	 *
R
update  
roo00 已提交
54
	 * @param personName
R
roo00 已提交
55 56 57
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
58 59
	public String getUnitNameWithPerson(String personName) throws Exception {
		List<String> unitNames = null;
R
roo00 已提交
60 61 62 63 64 65
		Business business = null;
		Integer level = 0;
		String result = null;
		Unit unit = null;
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			business = new Business(emc);
O
o2sword 已提交
66 67
			if(StringUtils.isNotBlank(personName) && personName.split("@").length == 2){
				personName = personName.split("@")[0];
68
			}
O
o2sword 已提交
69
			unitNames = business.organization().unit().listWithPerson(personName);
70
			if ( ListTools.isNotEmpty( unitNames )) {
NoSubject's avatar
NoSubject 已提交
71 72 73
				for (String unitName : unitNames) {
					unit = business.organization().unit().getObject(unitName);
					if (level < unit.getLevel()) {
R
roo00 已提交
74 75 76 77 78
						level = unit.getLevel();
						result = unitName;
					}
				}
			}
NoSubject's avatar
NoSubject 已提交
79
		} catch (Exception e) {
R
roo00 已提交
80 81 82 83 84 85 86
			throw e;
		}
		return result;
	}

	/**
	 * 根据身份名称获取身份所属的组织名称
O
o2sword 已提交
87
	 *
R
roo00 已提交
88 89 90 91
	 * @param identity
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
92
	public String getUnitNameByIdentity(String identity) throws Exception {
O
o2sword 已提交
93 94
		Business business = new Business(null);
		return business.organization().unit().getWithIdentity(identity);
R
roo00 已提交
95
	}
NoSubject's avatar
NoSubject 已提交
96

R
roo00 已提交
97 98
	/**
	 * 根据人员姓名获取人员所属的一级组织名称,如果人员有多个身份,则取组织等级最大的身份
O
o2sword 已提交
99
	 *
R
roo00 已提交
100 101 102 103
	 * @param personName
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
104
	public String getTopUnitNameWithPerson(String personName) throws Exception {
R
roo00 已提交
105 106 107 108 109
		String identity = null;
		String topUnitName = null;
		Business business = null;
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			business = new Business(emc);
O
o2sword 已提交
110 111 112
			if(!OrganizationDefinition.isPersonDistinguishedName(personName)){
				if(personName.split("@").length == 2){
					personName = personName.split("@")[0];
113
				}
O
o2sword 已提交
114
				personName = business.organization().person().get(personName);
115
			}
NoSubject's avatar
NoSubject 已提交
116
			identity = getMajorIdentityWithPerson(personName);
O
o2sword 已提交
117
			if (StringUtils.isNotBlank(identity)) {
NoSubject's avatar
NoSubject 已提交
118
				topUnitName = business.organization().unit().getWithIdentityWithLevel(identity, 1);
R
roo00 已提交
119 120
			}
			return topUnitName;
NoSubject's avatar
NoSubject 已提交
121
		} catch (Exception e) {
R
roo00 已提交
122 123 124
			throw e;
		}
	}
NoSubject's avatar
NoSubject 已提交
125

R
roo00 已提交
126 127
	/**
	 * 根据身份名称获取身份所属的顶层组织名称
O
o2sword 已提交
128
	 *
R
roo00 已提交
129 130 131 132
	 * @param identity
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
133
	public String getTopUnitNameByIdentity(String identity) throws Exception {
O
o2sword 已提交
134 135
		try {
			Business business = new Business(null);
NoSubject's avatar
NoSubject 已提交
136 137
			return business.organization().unit().getWithIdentityWithLevel(identity, 1);
		} catch (NullPointerException e) {
R
roo00 已提交
138 139 140 141 142 143 144
			return null;
		} catch (Exception e) {
			throw e;
		}
	}

	/**
NoSubject's avatar
NoSubject 已提交
145
	 * 根据个人姓名,根据个人姓名获取主身份
O
o2sword 已提交
146
	 *
R
roo00 已提交
147 148 149 150
	 * @param personName
	 * @return
	 * @throws Exception
	 */
151
	public String getMajorIdentityWithPerson( String personName ) throws Exception {
R
roo00 已提交
152 153 154 155
		List<String> identities = null;
		Business business = null;
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			business = new Business(emc);
O
o2sword 已提交
156 157
			if(!OrganizationDefinition.isPersonDistinguishedName(personName)){
				if (personName.endsWith("@P") && personName.split("@").length == 2) {
158 159 160 161 162
					personName = business.organization().person().get(personName.split("@")[0]);
				}else{
					personName = business.organization().person().get(personName);
				}
			}
NoSubject's avatar
NoSubject 已提交
163
			identities = business.organization().identity().listWithPerson(personName);
164
			if (ListTools.isNotEmpty( identities )) {
NoSubject's avatar
NoSubject 已提交
165 166
				if( identities.size() == 1 ) {
					return identities.get(0);
167 168 169
				}else{
					for (String identity : identities) {
						Identity obj = business.organization().identity().getObject(identity);
O
o2sword 已提交
170
						if (BooleanUtils.isTrue(obj.getMajor())) {
171 172
							return identity;
						}
R
roo00 已提交
173 174
					}
				}
175
				return identities.get(0);
R
roo00 已提交
176
			}
NoSubject's avatar
NoSubject 已提交
177 178
			return null;
		} catch (Exception e) {
R
roo00 已提交
179 180 181 182 183 184
			throw e;
		}
	}

	/**
	 * 根据用户的身份查询用户的姓名
O
o2sword 已提交
185
	 *
R
roo00 已提交
186 187 188 189
	 * @param identity
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
190 191
	public String getPersonNameWithIdentity(String identity) throws Exception {
		if (StringUtils.isEmpty(identity)) {
R
roo00 已提交
192 193 194 195 196
			throw new Exception("identity is null!");
		}
		Business business = null;
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			business = new Business(emc);
NoSubject's avatar
NoSubject 已提交
197 198
			return business.organization().person().getWithIdentity(identity);
		} catch (NullPointerException e) {
R
roo00 已提交
199 200 201 202 203 204 205 206
			return null;
		} catch (Exception e) {
			throw e;
		}
	}

	/**
	 * 获取人员所属的所有组织名称列表
O
o2sword 已提交
207
	 *
R
roo00 已提交
208 209 210 211
	 * @param personName
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
212
	public List<String> listUnitNamesWithPerson(String personName) throws Exception {
R
roo00 已提交
213 214
		List<String> unitNames = null;
		Business business = null;
NoSubject's avatar
NoSubject 已提交
215
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
R
roo00 已提交
216
			business = new Business(emc);
O
o2sword 已提交
217 218
			if( StringUtils.isNotEmpty( personName ) && personName.split("@").length == 2){
				personName = personName.split("@")[0];
219
			}
NoSubject's avatar
NoSubject 已提交
220 221 222
			unitNames = business.organization().unit().listWithPersonSupNested(personName);
			return unitNames == null ? new ArrayList<>() : unitNames;
		} catch (NullPointerException e) {
R
roo00 已提交
223 224 225 226 227
			return null;
		} catch (Exception e) {
			throw e;
		}
	}
NoSubject's avatar
NoSubject 已提交
228

R
roo00 已提交
229 230
	/**
	 * 根据用户姓名查询用户所有的身份信息
O
o2sword 已提交
231
	 *
232
	 * @param personName
R
roo00 已提交
233 234 235
	 * @return
	 * @throws Exception
	 */
236 237
	public List<String> listIdentitiesWithPerson(String personName) throws Exception {
		if (StringUtils.isEmpty(personName)) {
R
roo00 已提交
238 239 240
			throw new Exception("userName is null!");
		}
		Business business = null;
NoSubject's avatar
NoSubject 已提交
241
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
R
roo00 已提交
242
			business = new Business(emc);
O
o2sword 已提交
243 244
			if( StringUtils.isNotEmpty( personName ) && personName.split("@").length == 2){
				personName = personName.split("@")[0];
245 246
			}
			return business.organization().identity().listWithPerson(personName);
NoSubject's avatar
NoSubject 已提交
247
		} catch (NullPointerException e) {
R
roo00 已提交
248 249 250 251 252 253 254 255
			return null;
		} catch (Exception e) {
			throw e;
		}
	}

	/**
	 * 列示人员所拥有的所有角色信息
O
o2sword 已提交
256
	 *
R
update  
roo00 已提交
257
	 * @param personName
R
roo00 已提交
258 259 260
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
261
	public List<String> listRoleNamesByPerson(String personName) throws Exception {
R
roo00 已提交
262 263 264 265 266
		Business business = null;
		List<String> roleList = null;
		List<String> nameList = new ArrayList<String>();
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			business = new Business(emc);
267
			if( StringUtils.isNotEmpty( personName )){
O
o2sword 已提交
268
				if (personName.endsWith("@P") && personName.split("@").length == 2) {
269 270 271 272 273
					personName = business.organization().person().get(personName.split("@")[0]);
				}else{
					personName = business.organization().person().get(personName);
				}
			}
NoSubject's avatar
NoSubject 已提交
274
			roleList = business.organization().role().listWithPerson(personName);
R
roo00 已提交
275
			if (roleList != null && roleList.size() > 0) {
NoSubject's avatar
NoSubject 已提交
276
				roleList.stream().filter(r -> !nameList.contains(r)).distinct().forEach(r -> nameList.add(r));
R
roo00 已提交
277
			}
NoSubject's avatar
NoSubject 已提交
278
		} catch (NullPointerException e) {
R
roo00 已提交
279 280 281 282
			return null;
		} catch (Exception e) {
			throw e;
		}
NoSubject's avatar
NoSubject 已提交
283
		return nameList == null ? new ArrayList<>() : nameList;
R
roo00 已提交
284 285 286 287
	}

	/**
	 * 列示人员所拥有的所有群组信息
O
o2sword 已提交
288
	 *
R
roo00 已提交
289 290 291 292 293 294 295 296 297 298
	 * @param personName
	 * @return
	 * @throws Exception
	 */
	public List<String> listGroupNamesByPerson(String personName) throws Exception {
		Business business = null;
		List<String> groupList = null;
		List<String> nameList = new ArrayList<String>();
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			business = new Business(emc);
O
o2sword 已提交
299 300
			if( StringUtils.isNotEmpty( personName ) && personName.split("@").length == 2){
				personName = personName.split("@")[0];
301
			}
NoSubject's avatar
NoSubject 已提交
302
			groupList = business.organization().group().listWithPerson(personName);
R
roo00 已提交
303
			if (groupList != null && groupList.size() > 0) {
NoSubject's avatar
NoSubject 已提交
304
				groupList.stream().filter(g -> !nameList.contains(g)).distinct().forEach(g -> nameList.add(g));
R
roo00 已提交
305
			}
NoSubject's avatar
NoSubject 已提交
306
		} catch (NullPointerException e) {
R
roo00 已提交
307 308 309 310
			return null;
		} catch (Exception e) {
			throw e;
		}
NoSubject's avatar
NoSubject 已提交
311
		return nameList == null ? new ArrayList<>() : nameList;
R
roo00 已提交
312
	}
NoSubject's avatar
NoSubject 已提交
313

R
roo00 已提交
314 315
	/**
	 * 判断用户是否有指定的平台角色,比如CMS系统管理员
O
o2sword 已提交
316
	 *
R
update  
roo00 已提交
317 318
	 * @param personName
	 * @param roleName
R
roo00 已提交
319 320 321
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
322 323
	public boolean isHasPlatformRole(String personName, String roleName) throws Exception {
		if (StringUtils.isEmpty(personName)) {
R
roo00 已提交
324 325
			throw new Exception("personName is null!");
		}
NoSubject's avatar
NoSubject 已提交
326
		if (StringUtils.isEmpty(roleName)) {
R
roo00 已提交
327 328 329 330 331 332
			throw new Exception("roleName is null!");
		}
		List<String> roleList = null;
		Business business = null;
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			business = new Business(emc);
O
o2sword 已提交
333 334
			if( StringUtils.isNotEmpty( personName ) && personName.split("@").length == 2){
				personName = personName.split("@")[0];
335
			}
NoSubject's avatar
NoSubject 已提交
336
			roleList = business.organization().role().listWithPerson(personName);
R
roo00 已提交
337
			if (roleList != null && !roleList.isEmpty()) {
NoSubject's avatar
NoSubject 已提交
338
				if (roleList.stream().filter(r -> roleName.equalsIgnoreCase(r)).count() > 0) {
R
roo00 已提交
339 340 341 342 343
					return true;
				}
			} else {
				return false;
			}
NoSubject's avatar
NoSubject 已提交
344
		} catch (NullPointerException e) {
R
roo00 已提交
345 346 347 348 349 350 351
			return false;
		} catch (Exception e) {
			throw e;
		}
		return false;
	}

R
update  
roo00 已提交
352
	/**
NoSubject's avatar
NoSubject 已提交
353
	 * 判断指定人员是否是管理员 1、xadmin 2、拥有manager角色 3、拥有CMSManager@CMSManagerSystemRole@R角色
O
o2sword 已提交
354
	 *
R
update  
roo00 已提交
355 356 357 358
	 * @param effectivePerson
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
359
	public Boolean isManager(EffectivePerson effectivePerson) throws Exception {
R
update  
roo00 已提交
360
		if (effectivePerson == null) {
NoSubject's avatar
NoSubject 已提交
361
			throw new Exception("effectivePerson is null!");
R
roo00 已提交
362
		}
NoSubject's avatar
NoSubject 已提交
363
		if (effectivePerson.isManager()) {
R
update  
roo00 已提交
364 365
			return true;
		}
NoSubject's avatar
NoSubject 已提交
366
		if (this.isHasPlatformRole(effectivePerson.getDistinguishedName(), ThisApplication.ROLE_CMSManager)) {
R
update  
roo00 已提交
367 368 369
			return true;
		}
		return false;
R
roo00 已提交
370
	}
NoSubject's avatar
NoSubject 已提交
371 372

	public String getPersonIdentity(String personName, String identity) throws Exception {
R
roo00 已提交
373 374 375
		List<String> identityNames = null;
		String identityName = null;
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
NoSubject's avatar
NoSubject 已提交
376
			identityNames = listIdentitiesWithPerson(personName);
R
roo00 已提交
377
//			LogUtil.INFO("identityNames:", identityNames );
NoSubject's avatar
NoSubject 已提交
378 379 380 381
			if (StringUtils.isEmpty(identity)) {
				if (identityNames.size() == 0) {
					throw new Exception("perons has no identity. personName:" + personName);
				} else if (identityNames.size() > 0) {
R
roo00 已提交
382 383
					identityName = identityNames.get(0);
				}
NoSubject's avatar
NoSubject 已提交
384 385 386 387
			} else {
				// 判断传入的身份是否合法
				identityName = this.findIdentity(identityNames, identity);
				if (StringUtils.isEmpty(identity)) {
R
roo00 已提交
388 389 390 391 392 393 394 395
					identityName = identityNames.get(0);
				}
			}
		} catch (Exception e) {
			throw e;
		}
		return identityName;
	}
R
roo00 已提交
396

NoSubject's avatar
NoSubject 已提交
397 398 399 400 401
	private String findIdentity(List<String> identityNames, String identityName) throws Exception {
		if (identityName != null && !identityName.isEmpty() && !"null".equals(identityName)) {
			if (identityNames != null && !identityNames.isEmpty()) {
				for (String identity : identityNames) {
					if (identity.equalsIgnoreCase(identityName)) {
R
roo00 已提交
402 403 404 405
						return identity;
					}
				}
			}
NoSubject's avatar
NoSubject 已提交
406 407
		} else {
			if (identityNames != null && !identityNames.isEmpty()) {
R
roo00 已提交
408 409 410 411 412 413
				return identityNames.get(0);
			}
		}
		return null;
	}

O
o2sword 已提交
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
	/**
	 * 根据人员、组织、群组查询人员信息
	 * 参数name必须为xx@xx@x格式
	 * @param name
	 * @return
	 */
	public List<String> listPersonWithName(String name) {
		List<String> list = new ArrayList<>();
		if (StringUtils.isEmpty( name ) || name.indexOf("@") == -1) {
			return list;
		}
		Matcher matcher = PersistenceProperties.Person.distinguishedName_pattern.matcher(name);
		if(matcher.find()){
			list.add(name);
			return list;
		}
		matcher = PersistenceProperties.Unit.distinguishedName_pattern.matcher(name);
		if(matcher.find()) {
			try {
				Business business = new Business(null);
				return business.organization().person().listWithUnitSubNested(name);
			} catch (Exception e) {
				logger.warn("根据组织【{}】查询人员异常:{}", name,e.getMessage());
			}
		}
		matcher = PersistenceProperties.Identity.distinguishedName_pattern.matcher(name);
		if(matcher.find()){
			try {
				Business business = new Business(null);
				String person = business.organization().person().getWithIdentity(name);
				if(StringUtils.isNotBlank(person)){
					list.add(person);
				}
				return list;
			} catch (Exception e) {
				logger.warn("根据组织【{}】查询人员异常:{}", name,e.getMessage());
			}
		}
		matcher = PersistenceProperties.Group.distinguishedName_pattern.matcher(name);
		if(matcher.find()) {
			try {
				Business business = new Business(null);
				return business.organization().person().listWithGroup( name );
			} catch (Exception e) {
				logger.warn("根据组织【{}】查询人员异常:{}", name,e.getMessage());
			}
		}
		return list;
	}

R
roo00 已提交
464
	/**
465 466
	 * 根据组织名称,查询组织内所有的人员标识,包括下级组织<br/>
	 * 2020-06-12 改为使用唯一标识查询<br/>
R
roo00 已提交
467 468 469 470
	 * @param unitName
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
471
	public List<String> listPersonWithUnit(String unitName) throws Exception {
472
		if (StringUtils.isEmpty( unitName )) {
R
roo00 已提交
473 474
			throw new Exception("unitName is empty!");
		}
NoSubject's avatar
NoSubject 已提交
475 476
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			Business business = new Business(emc);
477 478 479 480 481

			//2020-06-12 unitName可能有3段,可能有2段,统一使用中间的唯一标识来进行查询
			String unique = getUniqueWithName( unitName );

			return business.organization().person().listWithUnitSubNested( unique );
R
roo00 已提交
482 483 484 485 486 487
		} catch (Exception e) {
			throw e;
		}
	}

	/**
488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
	 * 获取组织对象的唯一标识<br/>
	 *<br/>
	 * 组织对象标识一般会有3段,如 综合部@1304-73504398-13419-0347@U, 张三@293041-9305983-04258-0943@P<br/>
	 * 文档权限里也会存在2段,因为第一段经常会变,如组织:行政综合部@1304-73504398-13419-0347@U<br/>
	 * 所以查询的时候最好只用中间的唯一标识来查询<br/>
	 * @param orgObjectName
	 * @return
	 */
	private String getUniqueWithName(String orgObjectName ) {
		if( StringUtils.isNotEmpty( orgObjectName )){
			String[] array = orgObjectName.split("@");
			if( array.length == 3 ){
				return array[1];
			}else if( array.length == 2 ){
				return array[0];
			}else{
				return orgObjectName;
			}
		}
		return null;
	}

	/**
	 * 根据群组名称,查询群组内所有的人员标识<br/>
	 * 2020-06-12 改为使用唯一标识查询<br/>
	 *
R
roo00 已提交
514 515 516 517
	 * @param groupName
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
518 519
	public List<String> listPersonWithGroup(String groupName) throws Exception {
		if (StringUtils.isEmpty(groupName)) {
R
roo00 已提交
520 521
			throw new Exception("groupName is empty!");
		}
NoSubject's avatar
NoSubject 已提交
522 523
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			Business business = new Business(emc);
524 525 526 527 528

			//2020-06-12 unitName可能有3段,可能有2段,统一使用中间的唯一标识来进行查询
			String unique = getUniqueWithName( groupName );

			return business.organization().person().listWithGroup( unique );
R
roo00 已提交
529 530 531 532 533
		} catch (Exception e) {
			throw e;
		}
	}

534 535 536 537 538 539 540
	/**
	 * 根据角色名称,查询角色成员内所有的人员标识<br/>
	 * 2020-06-12 改为使用唯一标识查询<br/>
	 * @param role
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
541 542
	public List<String> listPersonWithRole(String role) throws Exception {
		if (StringUtils.isEmpty(role)) {
R
roo00 已提交
543 544
			throw new Exception("role is empty!");
		}
NoSubject's avatar
NoSubject 已提交
545 546
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			Business business = new Business(emc);
547 548 549 550 551

			//2020-06-12 unitName可能有3段,可能有2段,统一使用中间的唯一标识来进行查询
			String unique = getUniqueWithName( role );

			return business.organization().person().listWithRole( unique );
R
roo00 已提交
552 553 554 555 556 557 558
		} catch (Exception e) {
			throw e;
		}
	}

	/**
	 * 查询系统内所有顶级组织的数量
O
o2sword 已提交
559
	 *
R
roo00 已提交
560 561 562 563
	 * @return
	 * @throws Exception
	 */
	public int countTopUnit() throws Exception {
NoSubject's avatar
NoSubject 已提交
564 565
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			Business business = new Business(emc);
R
roo00 已提交
566
			List<String> unitNames = business.organization().unit().listWithLevel(1);
NoSubject's avatar
NoSubject 已提交
567
			if (ListTools.isNotEmpty(unitNames)) {
R
roo00 已提交
568 569 570 571 572 573 574 575 576 577
				return unitNames.size();
			}
		} catch (Exception e) {
			throw e;
		}
		return 0;
	}

	/**
	 * 判断指定组织是否是顶级组织
O
o2sword 已提交
578
	 *
R
roo00 已提交
579 580 581 582
	 * @param unitName
	 * @return
	 * @throws Exception
	 */
NoSubject's avatar
NoSubject 已提交
583 584
	public boolean isTopUnit(String unitName) throws Exception {
		if (StringUtils.isEmpty(unitName)) {
R
roo00 已提交
585 586
			throw new Exception("unitName is empty!");
		}
NoSubject's avatar
NoSubject 已提交
587 588
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			Business business = new Business(emc);
R
roo00 已提交
589
			List<String> unitNames = business.organization().unit().listWithLevel(1);
NoSubject's avatar
NoSubject 已提交
590
			if (ListTools.isNotEmpty(unitNames) && unitNames.contains(unitName)) {
R
roo00 已提交
591 592 593 594 595 596 597
				return true;
			}
		} catch (Exception e) {
			throw e;
		}
		return false;
	}
598 599

	public boolean hasCategoryManagerPermission( EffectivePerson person, String appId) throws Exception {
O
o2sword 已提交
600
		if( person.isManager()){
601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
			return true;
		}
		UserManagerService userManagerService = new UserManagerService();
		//Manager管理员
		if( userManagerService.isHasPlatformRole( person.getDistinguishedName(), ThisApplication.ROLE_Manager )){
			return true;
		}
		//CMS管理员
		if( userManagerService.isHasPlatformRole( person.getDistinguishedName(), ThisApplication.ROLE_CMSManager )){
			return true;
		}

		//查询用户是否为该栏目的管理者
		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
			AppInfo appInfo = emc.find( appId, AppInfo.class );
			//是管理员
			if( ListTools.isNotEmpty(appInfo.getManageablePersonList()) && ListTools.contains( appInfo.getManageablePersonList(), person.getDistinguishedName() )){
				return true;
			}
			if( ListTools.isNotEmpty( appInfo.getManageableUnitList() )){
				List<String> unitNames = userManagerService.listUnitNamesWithPerson( person.getDistinguishedName() );
				if( ListTools.isNotEmpty( unitNames )){
					unitNames.retainAll( appInfo.getManageableUnitList() );
					if( ListTools.isNotEmpty( unitNames )){
						return true;
					}
				}
			}
			if( ListTools.isNotEmpty( appInfo.getManageableGroupList() )){
				List<String> groupNames = userManagerService.listGroupNamesByPerson( person.getDistinguishedName() );
				if( ListTools.isNotEmpty( groupNames )){
					groupNames.retainAll( appInfo.getManageableGroupList() );
					if( ListTools.isNotEmpty( groupNames )){
						return true;
					}
				}
			}
		} catch (Exception e) {
			throw e;
		}

		return false;
	}

	public boolean hasAppInfoManagerPermission( EffectivePerson person ) throws Exception {
		//系统管理员
		if( person.isManager() || person.isCipher() ){
			return true;
		}
		if( StringUtils.equalsIgnoreCase("xadmin", person.getName() ) || StringUtils.equalsIgnoreCase("xadmin", person.getDistinguishedName() ) ){
			return true;
		}
		//CMS管理员
		UserManagerService userManagerService = new UserManagerService();
		if( userManagerService.isHasPlatformRole( person.getDistinguishedName(), ThisApplication.ROLE_CMSManager )){
			return true;
		}
		return false;
	}
O
o2sword 已提交
660
}