Просмотр исходного кода

群组身份成员关联查询优化

o2sword 5 лет назад
Родитель
Сommit
0191d39841

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

@@ -10,6 +10,7 @@ import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
 import org.apache.commons.collections.ListUtils;
+import org.apache.commons.collections4.set.ListOrderedSet;
 import org.apache.commons.lang3.StringUtils;
 
 import com.google.gson.JsonElement;
@@ -124,6 +125,7 @@ class ActionListLike extends BaseAction {
 				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)));
+		ListOrderedSet<String> set = new ListOrderedSet<>();
 		if (ListTools.isNotEmpty(wi.getUnitDutyList())) {
 			List<UnitDuty> unitDuties = business.unitDuty().pick(wi.getUnitDutyList());
 			List<String> unitDutyIdentities = new ArrayList<>();
@@ -131,19 +133,18 @@ class ActionListLike extends BaseAction {
 				unitDutyIdentities.addAll(o.getIdentityList());
 			}
 			unitDutyIdentities = ListTools.trim(unitDutyIdentities, true, true);
-			p = cb.and(p, root.get(Identity_.id).in(unitDutyIdentities));
+			set.addAll(unitDutyIdentities);
 		}
 		if (ListTools.isNotEmpty(wi.getUnitList())) {
 			List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
-			if(ListTools.isNotEmpty(identityIds)) {
-				p = cb.and(p, root.get(Identity_.id).in(identityIds));
-			}
+			set.addAll(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));
-			}
+			set.addAll(identityIds);
+		}
+		if(!set.isEmpty()){
+			p = cb.and(p, root.get(Identity_.id).in(set.asList()));
 		}
 		List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
 		wos = Wo.copier.copy(os);

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

@@ -10,6 +10,7 @@ import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
 import org.apache.commons.collections.ListUtils;
+import org.apache.commons.collections4.set.ListOrderedSet;
 import org.apache.commons.lang3.StringUtils;
 
 import com.google.gson.JsonElement;
@@ -122,6 +123,7 @@ class ActionListLikePinyin extends BaseAction {
 		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)));
+		ListOrderedSet<String> set = new ListOrderedSet<>();
 		if (ListTools.isNotEmpty(wi.getUnitDutyList())) {
 			List<UnitDuty> unitDuties = business.unitDuty().pick(wi.getUnitDutyList());
 			List<String> unitDutyIdentities = new ArrayList<>();
@@ -129,19 +131,18 @@ class ActionListLikePinyin extends BaseAction {
 				unitDutyIdentities.addAll(o.getIdentityList());
 			}
 			unitDutyIdentities = ListTools.trim(unitDutyIdentities, true, true);
-			p = cb.and(p, root.get(Identity_.id).in(unitDutyIdentities));
+			set.addAll(unitDutyIdentities);
 		}
 		if (ListTools.isNotEmpty(wi.getUnitList())) {
 			List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
-			if(ListTools.isNotEmpty(identityIds)) {
-				p = cb.and(p, root.get(Identity_.id).in(identityIds));
-			}
+			set.addAll(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));
-			}
+			set.addAll(identityIds);
+		}
+		if(!set.isEmpty()){
+			p = cb.and(p, root.get(Identity_.id).in(set.asList()));
 		}
 		List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
 		wos = Wo.copier.copy(os);

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

@@ -9,6 +9,7 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
+import org.apache.commons.collections4.set.ListOrderedSet;
 import org.apache.commons.lang3.StringUtils;
 
 import com.google.gson.JsonElement;
@@ -119,6 +120,8 @@ public class ActionListPinyinInitial extends BaseAction {
 		CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
 		Root<Identity> root = cq.from(Identity.class);
 		Predicate p = cb.like(root.get(Identity_.pinyinInitial), str + "%", StringTools.SQL_ESCAPE_CHAR);
+
+		ListOrderedSet<String> set = new ListOrderedSet<>();
 		if (ListTools.isNotEmpty(wi.getUnitDutyList())) {
 			List<UnitDuty> unitDuties = business.unitDuty().pick(wi.getUnitDutyList());
 			List<String> unitDutyIdentities = new ArrayList<>();
@@ -126,20 +129,20 @@ public class ActionListPinyinInitial extends BaseAction {
 				unitDutyIdentities.addAll(o.getIdentityList());
 			}
 			unitDutyIdentities = ListTools.trim(unitDutyIdentities, true, true);
-			p = cb.and(p, root.get(Identity_.id).in(unitDutyIdentities));
+			set.addAll(unitDutyIdentities);
 		}
 		if (ListTools.isNotEmpty(wi.getUnitList())) {
 			List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
-			if(ListTools.isNotEmpty(identityIds)) {
-				p = cb.and(p, root.get(Identity_.id).in(identityIds));
-			}
+			set.addAll(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));
-			}
+			set.addAll(identityIds);
 		}
+		if(!set.isEmpty()){
+			p = cb.and(p, root.get(Identity_.id).in(set.asList()));
+		}
+
 		List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
 		wos = Wo.copier.copy(os);
 		wos = business.identity().sort(wos);