Pārlūkot izejas kodu

1、群组身份成员关联查询优化;2、身份删除同时删除群组中的身份成员;

o2sword 5 gadi atpakaļ
vecāks
revīzija
16a81dbffe

+ 28 - 0
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/Business.java

@@ -46,6 +46,7 @@ import com.x.organization.core.entity.UnitAttribute;
 import com.x.organization.core.entity.UnitDuty;
 import com.x.organization.core.entity.UnitDuty;
 
 
 import net.sf.ehcache.Ehcache;
 import net.sf.ehcache.Ehcache;
+import org.apache.commons.collections4.set.ListOrderedSet;
 
 
 public class Business {
 public class Business {
 
 
@@ -473,6 +474,33 @@ public class Business {
 		return os;
 		return os;
 	}
 	}
 
 
+	public List<String> expendGroupToIdentity(List<String> groupList) throws Exception {
+		List<Group> groups = new ArrayList<>();
+		List<Group> expendGroups = new ArrayList<>();
+		if (ListTools.isNotEmpty(groupList)) {
+			groupList = ListTools.trim(groupList, true, true);
+			for (String s : groupList) {
+				Group g = this.group().pick(s);
+				if (null != g) {
+					groups.add(g);
+				}
+			}
+		}
+		if (ListTools.isNotEmpty(groups)) {
+			for (Group g : groups) {
+				expendGroups.add(g);
+				expendGroups.addAll(this.group().listSubNestedObject(g));
+			}
+		}
+		ListOrderedSet<String> set = new ListOrderedSet<String>();
+		for (Group g : groups) {
+			if (ListTools.isNotEmpty(g.getIdentityList())) {
+				set.addAll(g.getIdentityList());
+			}
+		}
+		return set.asList();
+	}
+
 	public Ehcache cache() {
 	public Ehcache cache() {
 		return cache;
 		return cache;
 	}
 	}

+ 29 - 7
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/factory/GroupFactory.java

@@ -12,6 +12,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import javax.persistence.criteria.Root;
 
 
+import com.x.base.core.project.tools.ListTools;
 import org.apache.commons.collections4.set.ListOrderedSet;
 import org.apache.commons.collections4.set.ListOrderedSet;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 
 
@@ -205,13 +206,17 @@ public class GroupFactory extends AbstractFactory {
 	// @MethodDescribe("查找群组的直接群组成员.")
 	// @MethodDescribe("查找群组的直接群组成员.")
 	public List<String> listSubDirect(String id) throws Exception {
 	public List<String> listSubDirect(String id) throws Exception {
 		Group group = this.entityManagerContainer().find(id, Group.class, ExceptionWhen.none);
 		Group group = this.entityManagerContainer().find(id, Group.class, ExceptionWhen.none);
-		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 = root.get(Group_.id).in(group.getGroupList());
-		cq.select(root.get(Group_.id)).where(p);
-		return em.createQuery(cq).getResultList();
+		if(group!=null && ListTools.isNotEmpty(group.getGroupList())) {
+			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 = root.get(Group_.id).in(group.getGroupList());
+			cq.select(root.get(Group_.id)).where(p);
+			return em.createQuery(cq).getResultList();
+		}else{
+			return new ArrayList<>();
+		}
 	}
 	}
 
 
 	// @MethodDescribe("查找群组的全部群组成员,包括嵌套的群组成员.")
 	// @MethodDescribe("查找群组的全部群组成员,包括嵌套的群组成员.")
@@ -237,4 +242,21 @@ public class GroupFactory extends AbstractFactory {
 		}
 		}
 	}
 	}
 
 
+	// @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<Group> listSupDirectWithIdentityObject(String id) throws Exception {
+		List<String> ids = this.listSupDirectWithIdentity(id);
+		return this.entityManagerContainer().list(Group.class, ids);
+	}
+
 }
 }

+ 12 - 4
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionDelete.java

@@ -11,6 +11,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 import javax.persistence.criteria.Root;
 
 
+import com.x.organization.core.entity.*;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.commons.lang3.StringUtils;
 
 
 import com.x.base.core.container.EntityManagerContainer;
 import com.x.base.core.container.EntityManagerContainer;
@@ -24,10 +25,6 @@ import com.x.base.core.project.http.EffectivePerson;
 import com.x.base.core.project.jaxrs.WoId;
 import com.x.base.core.project.jaxrs.WoId;
 import com.x.organization.assemble.control.Business;
 import com.x.organization.assemble.control.Business;
 import com.x.organization.assemble.control.message.OrgMessageFactory;
 import com.x.organization.assemble.control.message.OrgMessageFactory;
-import com.x.organization.core.entity.Identity;
-import com.x.organization.core.entity.Unit;
-import com.x.organization.core.entity.UnitDuty;
-import com.x.organization.core.entity.UnitDuty_;
 
 
 public class ActionDelete extends BaseAction {
 public class ActionDelete extends BaseAction {
 
 
@@ -52,6 +49,10 @@ public class ActionDelete extends BaseAction {
 				this.removeMemberOfUnitDuty(business, identity);
 				this.removeMemberOfUnitDuty(business, identity);
 				emc.commit();
 				emc.commit();
 			}
 			}
+			/** group的身份成员删除。*/
+			emc.beginTransaction(Group.class);
+			this.removeMemberOfGroup(business, identity);
+			emc.commit();
 			/** 由于前面pick出来的需要重新取出 */
 			/** 由于前面pick出来的需要重新取出 */
 			identity = emc.find(identity.getId(), Identity.class);
 			identity = emc.find(identity.getId(), Identity.class);
 			// /** 删除下属身份 */
 			// /** 删除下属身份 */
@@ -118,4 +119,11 @@ public class ActionDelete extends BaseAction {
 			o.getIdentityList().remove(identity.getId());
 			o.getIdentityList().remove(identity.getId());
 		}
 		}
 	}
 	}
+
+	private void removeMemberOfGroup(Business business, Identity identity) throws Exception {
+		List<Group> groups = business.group().listSupDirectWithIdentityObject(identity.getId());
+		for(Group g : groups){
+			g.getIdentityList().remove(identity.getId());
+		}
+	}
 }
 }

+ 27 - 7
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLike.java

@@ -40,7 +40,9 @@ class ActionListLike extends BaseAction {
 			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 			Business business = new Business(emc);
 			Business business = new Business(emc);
 			String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(),
 			String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(),
-					StringUtils.join(wi.getUnitList(), ","));
+					StringUtils.join(wi.getUnitList(), ","),
+					StringUtils.join(wi.getUnitDutyList(), ","),
+					StringUtils.join(wi.getGroupList(), ","));
 			Element element = business.cache().get(cacheKey);
 			Element element = business.cache().get(cacheKey);
 			if (null != element && (null != element.getObjectValue())) {
 			if (null != element && (null != element.getObjectValue())) {
 				result.setData((List<Wo>) element.getObjectValue());
 				result.setData((List<Wo>) element.getObjectValue());
@@ -61,6 +63,8 @@ class ActionListLike extends BaseAction {
 		private List<String> unitList = new ArrayList<>();
 		private List<String> unitList = new ArrayList<>();
 		@FieldDescribe("搜索职务范围,为空则不限定")
 		@FieldDescribe("搜索职务范围,为空则不限定")
 		private List<String> unitDutyList = new ArrayList<>();
 		private List<String> unitDutyList = new ArrayList<>();
+		@FieldDescribe("搜索群组范围(仅限群组的身份成员),为空则不限定")
+		private List<String> groupList = new ArrayList<>();
 
 
 		public String getKey() {
 		public String getKey() {
 			return key;
 			return key;
@@ -86,6 +90,13 @@ class ActionListLike extends BaseAction {
 			this.unitDutyList = unitDutyList;
 			this.unitDutyList = unitDutyList;
 		}
 		}
 
 
+		public List<String> getGroupList() {
+			return groupList;
+		}
+
+		public void setGroupList(List<String> groupList) {
+			this.groupList = groupList;
+		}
 	}
 	}
 
 
 	public static class Wo extends Identity {
 	public static class Wo extends Identity {
@@ -107,11 +118,12 @@ class ActionListLike extends BaseAction {
 		CriteriaBuilder cb = em.getCriteriaBuilder();
 		CriteriaBuilder cb = em.getCriteriaBuilder();
 		CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
 		CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
 		Root<Identity> root = cq.from(Identity.class);
 		Root<Identity> root = cq.from(Identity.class);
-		Predicate p = cb.like(cb.lower(root.get(Identity_.name)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR);
-		p = cb.or(p, cb.like(cb.lower(root.get(Identity_.unique)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR));
-		p = cb.or(p, cb.like(cb.lower(root.get(Identity_.pinyin)), str + "%", StringTools.SQL_ESCAPE_CHAR));
-		p = cb.or(p, cb.like(cb.lower(root.get(Identity_.pinyinInitial)), str + "%", StringTools.SQL_ESCAPE_CHAR));
-		p = cb.or(p, cb.like(cb.lower(root.get(Identity_.distinguishedName)), str + "%", StringTools.SQL_ESCAPE_CHAR));
+		Predicate p = cb.conjunction();
+		p = cb.and(p, cb.or(cb.like(cb.lower(root.get(Identity_.name)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR),
+				cb.like(cb.lower(root.get(Identity_.unique)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR),
+				cb.like(cb.lower(root.get(Identity_.pinyin)), str + "%", StringTools.SQL_ESCAPE_CHAR),
+				cb.like(cb.lower(root.get(Identity_.pinyinInitial)), str + "%", StringTools.SQL_ESCAPE_CHAR),
+				cb.like(cb.lower(root.get(Identity_.distinguishedName)), str + "%", StringTools.SQL_ESCAPE_CHAR)));
 		if (ListTools.isNotEmpty(wi.getUnitDutyList())) {
 		if (ListTools.isNotEmpty(wi.getUnitDutyList())) {
 			List<UnitDuty> unitDuties = business.unitDuty().pick(wi.getUnitDutyList());
 			List<UnitDuty> unitDuties = business.unitDuty().pick(wi.getUnitDutyList());
 			List<String> unitDutyIdentities = new ArrayList<>();
 			List<String> unitDutyIdentities = new ArrayList<>();
@@ -123,7 +135,15 @@ class ActionListLike extends BaseAction {
 		}
 		}
 		if (ListTools.isNotEmpty(wi.getUnitList())) {
 		if (ListTools.isNotEmpty(wi.getUnitList())) {
 			List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
 			List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
-			p = cb.and(p, root.get(Identity_.id).in(identityIds));
+			if(ListTools.isNotEmpty(identityIds)) {
+				p = cb.and(p, root.get(Identity_.id).in(identityIds));
+			}
+		}
+		if (ListTools.isNotEmpty(wi.getGroupList())) {
+			List<String> identityIds = business.expendGroupToIdentity(wi.getGroupList());
+			if(ListTools.isNotEmpty(identityIds)) {
+				p = cb.and(p, root.get(Identity_.id).in(identityIds));
+			}
 		}
 		}
 		List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
 		List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
 		wos = Wo.copier.copy(os);
 		wos = Wo.copier.copy(os);

+ 25 - 4
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLikePinyin.java

@@ -40,7 +40,9 @@ class ActionListLikePinyin extends BaseAction {
 			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 			Business business = new Business(emc);
 			Business business = new Business(emc);
 			String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(),
 			String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(),
-					StringUtils.join(wi.getUnitList(), ","));
+					StringUtils.join(wi.getUnitList(), ","),
+					StringUtils.join(wi.getUnitDutyList(), ","),
+					StringUtils.join(wi.getGroupList(), ","));
 			Element element = business.cache().get(cacheKey);
 			Element element = business.cache().get(cacheKey);
 			if (null != element && (null != element.getObjectValue())) {
 			if (null != element && (null != element.getObjectValue())) {
 				result.setData((List<Wo>) element.getObjectValue());
 				result.setData((List<Wo>) element.getObjectValue());
@@ -61,6 +63,8 @@ class ActionListLikePinyin extends BaseAction {
 		private List<String> unitList = new ArrayList<>();
 		private List<String> unitList = new ArrayList<>();
 		@FieldDescribe("搜索职务范围,为空则不限定")
 		@FieldDescribe("搜索职务范围,为空则不限定")
 		private List<String> unitDutyList = new ArrayList<>();
 		private List<String> unitDutyList = new ArrayList<>();
+		@FieldDescribe("搜索群组范围(仅限群组的身份成员),为空则不限定")
+		private List<String> groupList = new ArrayList<>();
 
 
 		public List<String> getUnitDutyList() {
 		public List<String> getUnitDutyList() {
 			return unitDutyList;
 			return unitDutyList;
@@ -86,6 +90,14 @@ class ActionListLikePinyin extends BaseAction {
 			this.unitList = unitList;
 			this.unitList = unitList;
 		}
 		}
 
 
+		public List<String> getGroupList() {
+			return groupList;
+		}
+
+		public void setGroupList(List<String> groupList) {
+			this.groupList = groupList;
+		}
+
 	}
 	}
 
 
 	public static class Wo extends Identity {
 	public static class Wo extends Identity {
@@ -107,8 +119,9 @@ class ActionListLikePinyin extends BaseAction {
 		CriteriaBuilder cb = em.getCriteriaBuilder();
 		CriteriaBuilder cb = em.getCriteriaBuilder();
 		CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
 		CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
 		Root<Identity> root = cq.from(Identity.class);
 		Root<Identity> root = cq.from(Identity.class);
-		Predicate p = cb.like(root.get(Identity_.pinyin), str + "%");
-		p = cb.or(p, cb.like(root.get(Identity_.pinyinInitial), str + "%"));
+		Predicate p = cb.conjunction();
+		p = cb.and(p, cb.or(cb.like(cb.lower(root.get(Identity_.pinyin)), str + "%", StringTools.SQL_ESCAPE_CHAR),
+				cb.like(cb.lower(root.get(Identity_.pinyinInitial)), str + "%", StringTools.SQL_ESCAPE_CHAR)));
 		if (ListTools.isNotEmpty(wi.getUnitDutyList())) {
 		if (ListTools.isNotEmpty(wi.getUnitDutyList())) {
 			List<UnitDuty> unitDuties = business.unitDuty().pick(wi.getUnitDutyList());
 			List<UnitDuty> unitDuties = business.unitDuty().pick(wi.getUnitDutyList());
 			List<String> unitDutyIdentities = new ArrayList<>();
 			List<String> unitDutyIdentities = new ArrayList<>();
@@ -120,7 +133,15 @@ class ActionListLikePinyin extends BaseAction {
 		}
 		}
 		if (ListTools.isNotEmpty(wi.getUnitList())) {
 		if (ListTools.isNotEmpty(wi.getUnitList())) {
 			List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
 			List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
-			p = cb.and(p, root.get(Identity_.id).in(identityIds));
+			if(ListTools.isNotEmpty(identityIds)) {
+				p = cb.and(p, root.get(Identity_.id).in(identityIds));
+			}
+		}
+		if (ListTools.isNotEmpty(wi.getGroupList())) {
+			List<String> identityIds = business.expendGroupToIdentity(wi.getGroupList());
+			if(ListTools.isNotEmpty(identityIds)) {
+				p = cb.and(p, root.get(Identity_.id).in(identityIds));
+			}
 		}
 		}
 		List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
 		List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
 		wos = Wo.copier.copy(os);
 		wos = Wo.copier.copy(os);

+ 22 - 2
o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListPinyinInitial.java

@@ -39,7 +39,9 @@ public class ActionListPinyinInitial extends BaseAction {
 			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
 			Business business = new Business(emc);
 			Business business = new Business(emc);
 			String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(),
 			String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(),
-					StringUtils.join(wi.getUnitList(), ","));
+					StringUtils.join(wi.getUnitList(), ","),
+					StringUtils.join(wi.getUnitDutyList(), ","),
+					StringUtils.join(wi.getGroupList(), ","));
 			Element element = business.cache().get(cacheKey);
 			Element element = business.cache().get(cacheKey);
 			if (null != element && (null != element.getObjectValue())) {
 			if (null != element && (null != element.getObjectValue())) {
 				result.setData((List<Wo>) element.getObjectValue());
 				result.setData((List<Wo>) element.getObjectValue());
@@ -60,6 +62,8 @@ public class ActionListPinyinInitial extends BaseAction {
 		private List<String> unitList = new ArrayList<>();
 		private List<String> unitList = new ArrayList<>();
 		@FieldDescribe("搜索职务范围,为空则不限定")
 		@FieldDescribe("搜索职务范围,为空则不限定")
 		private List<String> unitDutyList = new ArrayList<>();
 		private List<String> unitDutyList = new ArrayList<>();
+		@FieldDescribe("搜索群组范围(仅限群组的身份成员),为空则不限定")
+		private List<String> groupList = new ArrayList<>();
 
 
 		public List<String> getUnitDutyList() {
 		public List<String> getUnitDutyList() {
 			return unitDutyList;
 			return unitDutyList;
@@ -85,6 +89,14 @@ public class ActionListPinyinInitial extends BaseAction {
 			this.unitList = unitList;
 			this.unitList = unitList;
 		}
 		}
 
 
+		public List<String> getGroupList() {
+			return groupList;
+		}
+
+		public void setGroupList(List<String> groupList) {
+			this.groupList = groupList;
+		}
+
 	}
 	}
 
 
 	public static class Wo extends Identity {
 	public static class Wo extends Identity {
@@ -118,7 +130,15 @@ public class ActionListPinyinInitial extends BaseAction {
 		}
 		}
 		if (ListTools.isNotEmpty(wi.getUnitList())) {
 		if (ListTools.isNotEmpty(wi.getUnitList())) {
 			List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
 			List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
-			p = cb.and(p, root.get(Identity_.id).in(identityIds));
+			if(ListTools.isNotEmpty(identityIds)) {
+				p = cb.and(p, root.get(Identity_.id).in(identityIds));
+			}
+		}
+		if (ListTools.isNotEmpty(wi.getGroupList())) {
+			List<String> identityIds = business.expendGroupToIdentity(wi.getGroupList());
+			if(ListTools.isNotEmpty(identityIds)) {
+				p = cb.and(p, root.get(Identity_.id).in(identityIds));
+			}
 		}
 		}
 		List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
 		List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
 		wos = Wo.copier.copy(os);
 		wos = Wo.copier.copy(os);