فهرست منبع

群组管理优化,1、增加身份成员;2、人员归属群组查询条件优化

o2sword 5 سال پیش
والد
کامیت
7bb4c802a0

+ 8 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/group/ActionAddMember.java

@@ -52,6 +52,14 @@ class ActionAddMember extends BaseAction {
 					group.setGroupList(ListTools.trim(ListUtils.sum(group.getGroupList(), group_add_ids), true, true));
 				}
 			}
+			if (ListTools.isNotEmpty(wi.getIdentityList())) {
+				List<String> identity_add_ids = ListTools.extractProperty(
+						business.identity().pick(ListTools.trim(wi.getIdentityList(), true, true)), JpaObject.id_FIELDNAME,
+						String.class, true, true);
+				if (ListTools.isNotEmpty(identity_add_ids)) {
+					group.setIdentityList(ListTools.trim(ListUtils.sum(group.getIdentityList(), identity_add_ids), true, true));
+				}
+			}
 			emc.check(group, CheckPersistType.all);
 			emc.commit();
 			ApplicationCache.notify(Group.class);

+ 3 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/group/ActionCreate.java

@@ -50,6 +50,9 @@ class ActionCreate extends BaseAction {
 			group.setGroupList(
 					ListTools.extractProperty(business.group().pick(ListTools.trim(group.getGroupList(), true, true)),
 							JpaObject.id_FIELDNAME, String.class, true, true));
+			group.setIdentityList(
+					ListTools.extractProperty(business.identity().pick(ListTools.trim(group.getIdentityList(), true, true)),
+							JpaObject.id_FIELDNAME, String.class, true, true));
 			emc.beginTransaction(Group.class);
 			emc.persist(group, CheckPersistType.all);
 			emc.commit();

+ 8 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/group/ActionDeleteMember.java

@@ -51,6 +51,14 @@ class ActionDeleteMember extends BaseAction {
 					group.setGroupList(ListUtils.union(group.getGroupList(), group_remove_ids));
 				}
 			}
+			if (ListTools.isNotEmpty(wi.getIdentityList())) {
+				List<String> identity_add_ids = ListTools.extractProperty(
+						business.identity().pick(ListTools.trim(wi.getIdentityList(), true, true)), JpaObject.id_FIELDNAME,
+						String.class, true, true);
+				if (ListTools.isNotEmpty(identity_add_ids)) {
+					group.setIdentityList(ListUtils.subtract(group.getIdentityList(), identity_add_ids));
+				}
+			}
 			emc.check(group, CheckPersistType.all);
 			emc.commit();
 			ApplicationCache.notify(Group.class);

+ 3 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/group/ActionEdit.java

@@ -60,6 +60,9 @@ class ActionEdit extends BaseAction {
 			group.setGroupList(
 					ListTools.extractProperty(business.group().pick(ListTools.trim(group.getGroupList(), true, true)),
 							JpaObject.id_FIELDNAME, String.class, true, true));
+			group.setIdentityList(
+					ListTools.extractProperty(business.identity().pick(ListTools.trim(group.getIdentityList(), true, true)),
+							JpaObject.id_FIELDNAME, String.class, true, true));
 			emc.check(group, CheckPersistType.all);
 			emc.commit();
 			ApplicationCache.notify(Group.class);

+ 31 - 10
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/group/ActionGet.java

@@ -17,6 +17,7 @@ import com.x.base.core.project.http.EffectivePerson;
 import com.x.base.core.project.tools.ListTools;
 import com.x.organization.assemble.control.Business;
 import com.x.organization.core.entity.Group;
+import com.x.organization.core.entity.Identity;
 import com.x.organization.core.entity.Person;
 import com.x.organization.core.entity.Unit;
 
@@ -51,6 +52,7 @@ class ActionGet extends BaseAction {
 		this.referenceGroup(business, wo);
 		this.referencePerson(business, wo);
 		this.referenceUnit(business, wo);
+		this.referenceIdentity(business, wo);
 		return wo;
 	}
 
@@ -73,11 +75,6 @@ class ActionGet extends BaseAction {
 			List<Person> os = business.person().pick(wo.getPersonList());
 			wos = WoPerson.copier.copy(os);
 		}
-		/*wos = wos.stream()
-				.sorted(Comparator.comparing(WoPerson::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
-						.thenComparing(
-								Comparator.comparing(WoPerson::getName, Comparator.nullsLast(String::compareTo))))
-				.collect(Collectors.toList());*/
 		wo.setWoPersonList(wos);
 	}
 
@@ -87,13 +84,18 @@ class ActionGet extends BaseAction {
 			List<Unit> os = business.unit().pick(wo.getUnitList());
 			wos = WoUnit.copier.copy(os);
 		}
-		/*wos = wos.stream()
-				.sorted(Comparator.comparing(WoUnit::getOrderNumber, Comparator.nullsLast(Integer::compareTo))
-						.thenComparing(Comparator.comparing(WoUnit::getName, Comparator.nullsLast(String::compareTo))))
-				.collect(Collectors.toList());*/
 		wo.setWoUnitList(wos);
 	}
 
+	private void referenceIdentity(Business business, Wo wo) throws Exception {
+		List<WoIdentity> wos = new ArrayList<>();
+		if (ListTools.isNotEmpty(wo.getIdentityList())) {
+			List<Identity> os = business.identity().pick(wo.getIdentityList());
+			wos = WoIdentity.copier.copy(os);
+		}
+		wo.setWoIdentityList(wos);
+	}
+
 	public static class Wo extends WoGroupAbstract {
 
 		private static final long serialVersionUID = -125007357898871894L;
@@ -107,6 +109,9 @@ class ActionGet extends BaseAction {
 		@FieldDescribe("成员组织对象")
 		private List<WoUnit> woUnitList = new ArrayList<>();
 
+		@FieldDescribe("成员身份对象")
+		private List<WoIdentity> woIdentityList = new ArrayList<>();
+
 		static WrapCopier<Group, Wo> copier = WrapCopierFactory.wo(Group.class, Wo.class, null,
 				ListTools.toList(JpaObject.FieldsInvisible));
 
@@ -134,6 +139,13 @@ class ActionGet extends BaseAction {
 			this.woUnitList = woUnitList;
 		}
 
+		public List<WoIdentity> getWoIdentityList() {
+			return woIdentityList;
+		}
+
+		public void setWoIdentityList(List<WoIdentity> woIdentityList) {
+			this.woIdentityList = woIdentityList;
+		}
 	}
 
 	public static class WoPerson extends Person {
@@ -147,11 +159,20 @@ class ActionGet extends BaseAction {
 
 	public static class WoUnit extends Unit {
 
-		private static final long serialVersionUID = -125007357898871894L;
+		private static final long serialVersionUID = -8142218653161885824L;
 
 		static WrapCopier<Unit, WoUnit> copier = WrapCopierFactory.wo(Unit.class, WoUnit.class, null,
 				JpaObject.FieldsInvisible);
 
 	}
 
+	public static class WoIdentity extends Identity {
+
+		private static final long serialVersionUID = 1217674471934438171L;
+
+		static WrapCopier<Identity, WoIdentity> copier = WrapCopierFactory.wo(Identity.class, WoIdentity.class, null,
+				JpaObject.FieldsInvisible);
+
+	}
+
 }

+ 22 - 0
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/factory/GroupFactory.java

@@ -172,6 +172,28 @@ public class GroupFactory extends AbstractFactory {
 		return em.createQuery(cq).getResultList();
 	}
 
+	// @MethodDescribe("获取指定身份直接所在的群组.")
+	public List<String> listSupDirectWithIdentity(String id) throws Exception {
+		EntityManager em = this.entityManagerContainer().get(Group.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<String> cq = cb.createQuery(String.class);
+		Root<Group> root = cq.from(Group.class);
+		Predicate p = cb.isMember(id, root.get(Group_.identityList));
+		cq.select(root.get(Group_.id)).where(p);
+		return em.createQuery(cq).getResultList();
+	}
+
+	// @MethodDescribe("获取指定组织直接所在的群组.")
+	public List<String> listSupDirectWithUnit(String id) throws Exception {
+		EntityManager em = this.entityManagerContainer().get(Group.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<String> cq = cb.createQuery(String.class);
+		Root<Group> root = cq.from(Group.class);
+		Predicate p = cb.isMember(id, root.get(Group_.unitList));
+		cq.select(root.get(Group_.id)).where(p);
+		return em.createQuery(cq).getResultList();
+	}
+
 	public List<Group> listSupNestedWithPersonObject(Person person) throws Exception {
 		List<String> ids = this.listSupNestedWithPerson(person.getId());
 		return this.entityManagerContainer().list(Group.class, ids);

+ 10 - 0
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/factory/IdentityFactory.java

@@ -105,6 +105,16 @@ public class IdentityFactory extends AbstractFactory {
 		return list;
 	}
 
+	public List<Identity> listByPerson(String personId) throws Exception{
+		EntityManager em = this.entityManagerContainer().get(Identity.class);
+		CriteriaBuilder cb = em.getCriteriaBuilder();
+		CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
+		Root<Identity> root = cq.from(Identity.class);
+		Predicate p = cb.equal(root.get(Identity_.person), personId);
+		List<Identity> is = em.createQuery(cq.select(root).where(p)).getResultList();
+		return is;
+	}
+
 	public <T extends Identity> List<T> sort(List<T> list) {
 		list = list.stream().sorted(
 				Comparator.comparing(Identity::getOrderNumber, Comparator.nullsLast(Integer::compareTo)).thenComparing(

+ 58 - 2
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/group/ActionListWithPerson.java

@@ -3,6 +3,8 @@ package com.x.organization.assemble.express.jaxrs.group;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.x.organization.core.entity.Identity;
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import com.google.gson.JsonElement;
@@ -27,7 +29,8 @@ class ActionListWithPerson extends BaseAction {
 			ActionResult<Wo> result = new ActionResult<>();
 			Business business = new Business(emc);
 			String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
-					StringUtils.join(wi.getPersonList(), ","));
+					StringUtils.join(wi.getPersonList(), ","),
+					wi.getRecursiveGroupFlag(), wi.getReferenceFlag(), wi.getRecursiveOrgFlag());
 			Element element = cache.get(cacheKey);
 			if (null != element && (null != element.getObjectValue())) {
 				result.setData((Wo) element.getObjectValue());
@@ -45,6 +48,15 @@ class ActionListWithPerson extends BaseAction {
 		@FieldDescribe("个人")
 		private List<String> personList = new ArrayList<>();
 
+		@FieldDescribe("是否递归查询上级群组,默认true")
+		private Boolean recursiveGroupFlag = true;
+
+		@FieldDescribe("是否包含查找人员身份成员、人员归属组织成员的所属群组,默认false")
+		private Boolean referenceFlag = false;
+
+		@FieldDescribe("是否递归人员归属组织的上级组织所属群组,前提referenceFlag为true,默认false")
+		private Boolean recursiveOrgFlag = false;
+
 		public List<String> getPersonList() {
 			return personList;
 		}
@@ -53,6 +65,29 @@ class ActionListWithPerson extends BaseAction {
 			this.personList = personList;
 		}
 
+		public Boolean getReferenceFlag() {
+			return referenceFlag;
+		}
+
+		public void setReferenceFlag(Boolean referenceFlag) {
+			this.referenceFlag = referenceFlag;
+		}
+
+		public Boolean getRecursiveGroupFlag() {
+			return recursiveGroupFlag;
+		}
+
+		public void setRecursiveGroupFlag(Boolean recursiveGroupFlag) {
+			this.recursiveGroupFlag = recursiveGroupFlag;
+		}
+
+		public Boolean getRecursiveOrgFlag() {
+			return recursiveOrgFlag;
+		}
+
+		public void setRecursiveOrgFlag(Boolean recursiveOrgFlag) {
+			this.recursiveOrgFlag = recursiveOrgFlag;
+		}
 	}
 
 	public static class Wo extends WoGroupAbstract {
@@ -64,9 +99,30 @@ class ActionListWithPerson extends BaseAction {
 		List<String> groupIds = new ArrayList<>();
 		for (Person person : os) {
 			groupIds.addAll(business.group().listSupDirectWithPerson(person.getId()));
+			if(BooleanUtils.isTrue(wi.getReferenceFlag())){
+				List<Identity> identityList = business.identity().listByPerson(person.getId());
+				for(Identity identity : identityList){
+					groupIds.addAll(business.group().listSupDirectWithIdentity(identity.getId()));
+					groupIds.addAll(business.group().listSupDirectWithUnit(identity.getUnit()));
+					if(BooleanUtils.isTrue(wi.getRecursiveOrgFlag())){
+						List<String> orgIds = business.unit().listSupNested(identity.getUnit());
+						for (String orgId : orgIds){
+							groupIds.addAll(business.group().listSupDirectWithUnit(orgId));
+						}
+					}
+				}
+			}
 		}
 		groupIds = ListTools.trim(groupIds, true, true);
-		List<String> values = business.group().listGroupDistinguishedNameSorted(groupIds);
+		List<String> groupIds2 = new ArrayList<>();
+		groupIds2.addAll(groupIds);
+		if(!BooleanUtils.isFalse(wi.getRecursiveGroupFlag())){
+			for(String groupId : groupIds){
+				groupIds2.addAll(business.group().listSupNested(groupId));
+			}
+			groupIds2 = ListTools.trim(groupIds2, true, true);
+		}
+		List<String> values = business.group().listGroupDistinguishedNameSorted(groupIds2);
 		Wo wo = new Wo();
 		wo.getGroupList().addAll(values);
 		return wo;

+ 60 - 3
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/group/ActionListWithPersonObject.java

@@ -3,6 +3,8 @@ package com.x.organization.assemble.express.jaxrs.group;
 import java.util.ArrayList;
 import java.util.List;
 
+import com.x.organization.core.entity.Identity;
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import com.google.gson.JsonElement;
@@ -28,7 +30,8 @@ class ActionListWithPersonObject extends BaseAction {
 			ActionResult<List<Wo>> result = new ActionResult<>();
 			Business business = new Business(emc);
 			String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(),
-					StringUtils.join(wi.getPersonList(), ","));
+					StringUtils.join(wi.getPersonList(), ","),
+					wi.getRecursiveGroupFlag(), wi.getReferenceFlag(), wi.getRecursiveOrgFlag());
 			Element element = cache.get(cacheKey);
 			if (null != element && (null != element.getObjectValue())) {
 				result.setData((List<Wo>) element.getObjectValue());
@@ -46,6 +49,15 @@ class ActionListWithPersonObject extends BaseAction {
 		@FieldDescribe("个人")
 		private List<String> personList = new ArrayList<>();
 
+		@FieldDescribe("是否递归查询上级群组,默认true")
+		private Boolean recursiveGroupFlag = true;
+
+		@FieldDescribe("是否包含查找人员身份成员、人员归属组织成员的所属群组,默认false")
+		private Boolean referenceFlag = false;
+
+		@FieldDescribe("是否递归人员归属组织的上级组织所属群组,前提referenceFlag为true,默认false")
+		private Boolean recursiveOrgFlag = false;
+
 		public List<String> getPersonList() {
 			return personList;
 		}
@@ -54,6 +66,29 @@ class ActionListWithPersonObject extends BaseAction {
 			this.personList = personList;
 		}
 
+		public Boolean getReferenceFlag() {
+			return referenceFlag;
+		}
+
+		public void setReferenceFlag(Boolean referenceFlag) {
+			this.referenceFlag = referenceFlag;
+		}
+
+		public Boolean getRecursiveGroupFlag() {
+			return recursiveGroupFlag;
+		}
+
+		public void setRecursiveGroupFlag(Boolean recursiveGroupFlag) {
+			this.recursiveGroupFlag = recursiveGroupFlag;
+		}
+
+		public Boolean getRecursiveOrgFlag() {
+			return recursiveOrgFlag;
+		}
+
+		public void setRecursiveOrgFlag(Boolean recursiveOrgFlag) {
+			this.recursiveOrgFlag = recursiveOrgFlag;
+		}
 	}
 
 	public static class Wo extends com.x.base.core.project.organization.Group {
@@ -65,10 +100,32 @@ class ActionListWithPersonObject extends BaseAction {
 		List<Person> os = business.person().pick(wi.getPersonList());
 		List<String> groupIds = new ArrayList<>();
 		for (Person person : os) {
-			groupIds.addAll(business.group().listSupNestedWithPerson(person.getId()));
+			groupIds.addAll(business.group().listSupDirectWithPerson(person.getId()));
+			if(BooleanUtils.isTrue(wi.getReferenceFlag())){
+				List<Identity> identityList = business.identity().listByPerson(person.getId());
+				for(Identity identity : identityList){
+					groupIds.addAll(business.group().listSupDirectWithIdentity(identity.getId()));
+					groupIds.addAll(business.group().listSupDirectWithUnit(identity.getUnit()));
+					if(BooleanUtils.isTrue(wi.getRecursiveOrgFlag())){
+						List<String> orgIds = business.unit().listSupNested(identity.getUnit());
+						for (String orgId : orgIds){
+							groupIds.addAll(business.group().listSupDirectWithUnit(orgId));
+						}
+					}
+				}
+			}
 		}
 		groupIds = ListTools.trim(groupIds, true, true);
-		List<Group> list = business.group().pick(groupIds);
+		List<String> groupIds2 = new ArrayList<>();
+		groupIds2.addAll(groupIds);
+		if(!BooleanUtils.isFalse(wi.getRecursiveGroupFlag())){
+			for(String groupId : groupIds){
+				groupIds2.addAll(business.group().listSupNested(groupId));
+			}
+			groupIds2 = ListTools.trim(groupIds2, true, true);
+		}
+
+		List<Group> list = business.group().pick(groupIds2);
 		list = business.group().sort(list);
 		for (Group o : list) {
 			wos.add(this.convert(business, o, Wo.class));

+ 19 - 0
o2server/x_organization_core_entity/src/main/java/com/x/organization/core/entity/Group.java

@@ -165,6 +165,17 @@ public class Group extends SliceJpaObject {
 	@CheckPersist(allowEmpty = true, citationExists = @CitationExist(type = Unit.class))
 	private List<String> unitList;
 
+	public static final String identityList_FIELDNAME = "identityList";
+	@FieldDescribe("群组存放身份成员,identity ID.")
+	@ContainerTable(name = TABLE + ContainerTableNameMiddle + identityList_FIELDNAME, joinIndex = @Index(name = TABLE
+			+ IndexNameMiddle + identityList_FIELDNAME + JoinIndexNameSuffix))
+	@ElementIndex(name = TABLE + IndexNameMiddle + identityList_FIELDNAME + ElementIndexNameSuffix)
+	@PersistentCollection(fetch = FetchType.EAGER)
+	@OrderColumn(name = ORDERCOLUMNCOLUMN)
+	@ElementColumn(length = JpaObject.length_id, name = ColumnNamePrefix + identityList_FIELDNAME)
+	@CheckPersist(allowEmpty = true, citationExists = @CitationExist(type = Unit.class))
+	private List<String> identityList;
+
 	public String getName() {
 		return name;
 	}
@@ -244,4 +255,12 @@ public class Group extends SliceJpaObject {
 	public void setUnitList(List<String> unitList) {
 		this.unitList = unitList;
 	}
+
+	public List<String> getIdentityList() {
+		return identityList;
+	}
+
+	public void setIdentityList(List<String> identityList) {
+		this.identityList = identityList;
+	}
 }