Bladeren bron

Merge branch 'fix/修改根据组织和职务名称查询身份信息接口' into 'wrdp'

[人员组织]修改根据组织和职务名称查询身份信息接口

See merge request o2oa/o2oa!2077
o2null 5 jaren geleden
bovenliggende
commit
25505212b3

+ 51 - 19
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/unitduty/ActionListIdentityWithUnitWithName.java

@@ -10,6 +10,10 @@ import javax.persistence.criteria.CriteriaQuery;
 import javax.persistence.criteria.Predicate;
 import javax.persistence.criteria.Root;
 
+import com.x.base.core.entity.JpaObject;
+import com.x.base.core.project.logger.Logger;
+import com.x.base.core.project.logger.LoggerFactory;
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import com.google.gson.JsonElement;
@@ -28,7 +32,7 @@ import com.x.organization.core.entity.UnitDuty;
 import com.x.organization.core.entity.UnitDuty_;
 
 class ActionListIdentityWithUnitWithName extends BaseAction {
-
+	private static Logger logger = LoggerFactory.getLogger(ActionListIdentityWithUnitWithName.class);
 	ActionResult<Wo> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
 		try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
 			Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
@@ -50,12 +54,12 @@ class ActionListIdentityWithUnitWithName extends BaseAction {
 			}
 			names = ListTools.trim(names, true, true);
 			units = ListTools.trim(units, true, true);
-			CacheKey cacheKey = new CacheKey(this.getClass(), names, units);
+			CacheKey cacheKey = new CacheKey(this.getClass(), names, units, wi.getRecursiveUnit());
 			Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
 			if (optional.isPresent()) {
 				result.setData((Wo) optional.get());
 			} else {
-				Wo wo = this.list(business, names, units);
+				Wo wo = this.list(business, names, units, wi.getRecursiveUnit());
 				CacheManager.put(cacheCategory, cacheKey, wo);
 				result.setData(wo);
 			}
@@ -65,17 +69,21 @@ class ActionListIdentityWithUnitWithName extends BaseAction {
 
 	public static class Wi extends GsonPropertyObject {
 
-		@FieldDescribe("组织属性名称")
+		@FieldDescribe("组织职务名称")
 		private String name;
+
 		@FieldDescribe("组织")
 		private String unit;
 
-		@FieldDescribe("组织属性名称(多值)")
+		@FieldDescribe("组织职务名称(多值)")
 		private List<String> nameList;
 
 		@FieldDescribe("组织(多值)")
 		private List<String> unitList;
 
+		@FieldDescribe("是否递归下级组织(默认false)")
+		private Boolean recursiveUnit;
+
 		public String getName() {
 			return name;
 		}
@@ -108,6 +116,13 @@ class ActionListIdentityWithUnitWithName extends BaseAction {
 			this.unitList = unitList;
 		}
 
+		public Boolean getRecursiveUnit() {
+			return recursiveUnit;
+		}
+
+		public void setRecursiveUnit(Boolean recursiveUnit) {
+			this.recursiveUnit = recursiveUnit;
+		}
 	}
 
 	public static class Wo extends GsonPropertyObject {
@@ -125,27 +140,44 @@ class ActionListIdentityWithUnitWithName extends BaseAction {
 
 	}
 
-	private Wo list(Business business, List<String> names, List<String> units) throws Exception {
+	private Wo list(Business business, List<String> names, List<String> units, Boolean recursiveUnit) throws Exception {
 		Wo wo = new Wo();
-		List<String> identityIds = new ArrayList<>();
-		for (String str : units) {
-			Unit unit = business.unit().pick(str);
-			if (null != unit) {
+		List<UnitDuty> os = new ArrayList<>();
+		if(units.isEmpty()){
+			EntityManager em = business.entityManagerContainer().get(UnitDuty.class);
+			CriteriaBuilder cb = em.getCriteriaBuilder();
+			CriteriaQuery<UnitDuty> cq = cb.createQuery(UnitDuty.class);
+			Root<UnitDuty> root = cq.from(UnitDuty.class);
+			Predicate p = root.get(UnitDuty_.name).in(names);
+			os = em.createQuery(cq.select(root).where(p)).getResultList();
+		}else{
+			List<Unit> unitList = business.unit().pick(units);
+			if(!unitList.isEmpty()){
+				units.clear();
+				for(Unit unit : unitList){
+					units.add(unit.getId());
+					if(BooleanUtils.isTrue(recursiveUnit)){
+						units.addAll(business.unit().listSubNested(unit.getId()));
+					}
+				}
+				units = ListTools.trim(units, true, true);
 				EntityManager em = business.entityManagerContainer().get(UnitDuty.class);
 				CriteriaBuilder cb = em.getCriteriaBuilder();
 				CriteriaQuery<UnitDuty> cq = cb.createQuery(UnitDuty.class);
 				Root<UnitDuty> root = cq.from(UnitDuty.class);
-				Predicate p = cb.equal(root.get(UnitDuty_.unit), unit.getId());
-				p = cb.and(p, root.get(UnitDuty_.name).in(names));
-				List<UnitDuty> os = em.createQuery(cq.select(root).where(p)).getResultList();
-				if (!os.isEmpty()) {
-					for (UnitDuty o : os) {
-						identityIds.addAll(o.getIdentityList());
-					}
-				}
+				Predicate p = root.get(UnitDuty_.name).in(names);
+				p = cb.and(p, root.get(UnitDuty_.unit).in(units));
+				os = em.createQuery(cq.select(root).where(p)).getResultList();
+			}
+		}
+
+		List<String> identityIds = new ArrayList<>();
+		if (!os.isEmpty()) {
+			for (UnitDuty o : os) {
+				identityIds.addAll(o.getIdentityList());
 			}
+			identityIds = ListTools.trim(identityIds, true, true);
 		}
-		identityIds = ListTools.trim(identityIds, true, true);
 		List<String> list = business.identity().listIdentityDistinguishedNameSorted(identityIds);
 		wo.getIdentityList().addAll(list);
 		return wo;

+ 79 - 23
o2server/x_organization_assemble_express/src/main/java/com/x/organization/assemble/express/jaxrs/unitduty/ActionListIdentityWithUnitWithNameObject.java

@@ -1,9 +1,9 @@
 package com.x.organization.assemble.express.jaxrs.unitduty;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
+import java.util.*;
 
+import com.x.organization.core.entity.*;
+import org.apache.commons.lang3.BooleanUtils;
 import org.apache.commons.lang3.StringUtils;
 
 import com.google.gson.JsonElement;
@@ -17,10 +17,12 @@ import com.x.base.core.project.http.ActionResult;
 import com.x.base.core.project.http.EffectivePerson;
 import com.x.base.core.project.tools.ListTools;
 import com.x.organization.assemble.express.Business;
-import com.x.organization.core.entity.Identity;
-import com.x.organization.core.entity.Person;
-import com.x.organization.core.entity.Unit;
-import com.x.organization.core.entity.UnitDuty;
+
+import javax.persistence.EntityManager;
+import javax.persistence.criteria.CriteriaBuilder;
+import javax.persistence.criteria.CriteriaQuery;
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
 
 class ActionListIdentityWithUnitWithNameObject extends BaseAction {
 
@@ -46,12 +48,12 @@ class ActionListIdentityWithUnitWithNameObject extends BaseAction {
 			}
 			names = ListTools.trim(names, true, true);
 			units = ListTools.trim(units, true, true);
-			CacheKey cacheKey = new CacheKey(this.getClass(), names, units);
+			CacheKey cacheKey = new CacheKey(this.getClass(), names, units, wi.getRecursiveUnit());
 			Optional<?> optional = CacheManager.get(cacheCategory, cacheKey);
 			if (optional.isPresent()) {
 				result.setData((List<Wo>) optional.get());
 			} else {
-				List<Wo> wos = this.list(business, names, units);
+				List<Wo> wos = this.list(business, names, units, wi.getRecursiveUnit());
 				CacheManager.put(cacheCategory, cacheKey, wos);
 				result.setData(wos);
 			}
@@ -61,17 +63,21 @@ class ActionListIdentityWithUnitWithNameObject extends BaseAction {
 
 	public static class Wi extends GsonPropertyObject {
 
-		@FieldDescribe("组织属性名称")
+		@FieldDescribe("组织职务名称")
 		private String name;
+
 		@FieldDescribe("组织")
 		private String unit;
 
-		@FieldDescribe("组织属性名称(多值)")
+		@FieldDescribe("组织职务名称(多值)")
 		private List<String> nameList;
 
 		@FieldDescribe("组织(多值)")
 		private List<String> unitList;
 
+		@FieldDescribe("是否递归下级组织(默认false)")
+		private Boolean recursiveUnit;
+
 		public String getName() {
 			return name;
 		}
@@ -104,6 +110,14 @@ class ActionListIdentityWithUnitWithNameObject extends BaseAction {
 			this.unitList = unitList;
 		}
 
+		public Boolean getRecursiveUnit() {
+			return recursiveUnit;
+		}
+
+		public void setRecursiveUnit(Boolean recursiveUnit) {
+			this.recursiveUnit = recursiveUnit;
+		}
+
 	}
 
 	public static class Wo extends com.x.base.core.project.organization.Identity {
@@ -138,21 +152,59 @@ class ActionListIdentityWithUnitWithNameObject extends BaseAction {
 
 	}
 
-	private List<Wo> list(Business business, List<String> names, List<String> units) throws Exception {
+	private List<Wo> list(Business business, List<String> names, List<String> units, Boolean recursiveUnit) throws Exception {
 		List<Wo> wos = new ArrayList<>();
-		for (String str : units) {
-			Unit matchUnit = business.unit().pick(str);
-			if (null != matchUnit) {
-				List<UnitDuty> os = business.entityManagerContainer().listEqualAndIn(UnitDuty.class,
-						UnitDuty.unit_FIELDNAME, matchUnit.getId(), UnitDuty.name_FIELDNAME, names);
-				for (UnitDuty o : os) {
-					for (Identity identity : business.identity().pick(o.getIdentityList())) {
-						Unit unit = business.unit().pick(identity.getUnit());
-						Person person = business.person().pick(identity.getPerson());
-						Wo wo = this.convertToIdentity(matchUnit, unit, person, identity);
-						wos.add(wo);
+		List<UnitDuty> os = new ArrayList<>();
+		Map<String, Unit> unitMap = new HashMap<>();
+		if(units.isEmpty()){
+			EntityManager em = business.entityManagerContainer().get(UnitDuty.class);
+			CriteriaBuilder cb = em.getCriteriaBuilder();
+			CriteriaQuery<UnitDuty> cq = cb.createQuery(UnitDuty.class);
+			Root<UnitDuty> root = cq.from(UnitDuty.class);
+			Predicate p = root.get(UnitDuty_.name).in(names);
+			os = em.createQuery(cq.select(root).where(p)).getResultList();
+		}else{
+			List<Unit> unitList = business.unit().pick(units);
+			if(!unitList.isEmpty()){
+				units.clear();
+				for(Unit unit : unitList){
+					units.add(unit.getId());
+					unitMap.put(unit.getId(), unit);
+					if(BooleanUtils.isTrue(recursiveUnit)){
+						List<Unit> subUnitList = business.unit().listSubNestedObject(unit);
+						for (Unit subunit:subUnitList) {
+							unitMap.put(subunit.getId(), subunit);
+							units.add(subunit.getId());
+						}
 					}
 				}
+				units = ListTools.trim(units, true, true);
+				EntityManager em = business.entityManagerContainer().get(UnitDuty.class);
+				CriteriaBuilder cb = em.getCriteriaBuilder();
+				CriteriaQuery<UnitDuty> cq = cb.createQuery(UnitDuty.class);
+				Root<UnitDuty> root = cq.from(UnitDuty.class);
+				Predicate p = root.get(UnitDuty_.name).in(names);
+				p = cb.and(p, root.get(UnitDuty_.unit).in(units));
+				os = em.createQuery(cq.select(root).where(p)).getResultList();
+			}
+		}
+
+		for (UnitDuty o : os) {
+			for (Identity identity : business.identity().pick(o.getIdentityList())) {
+				Unit matchUnit = unitMap.get(o.getUnit());
+				if(matchUnit == null){
+					matchUnit = business.unit().pick(o.getUnit());
+					unitMap.put(matchUnit.getId(), matchUnit);
+				}
+				/*Unit unit = unitMap.get(identity.getUnit());
+				if(unit == null){
+					unit = business.unit().pick(identity.getUnit());
+					unitMap.put(unit.getId(), unit);
+				}
+				Person person = business.person().pick(identity.getPerson());
+				 */
+				Wo wo = this.convertToIdentity(matchUnit, null, null, identity);
+				wos.add(wo);
 			}
 		}
 		return wos;
@@ -167,9 +219,13 @@ class ActionListIdentityWithUnitWithNameObject extends BaseAction {
 		}
 		if (null != unit) {
 			wo.setUnit(unit.getDistinguishedName());
+		}else{
+			wo.setUnit(identity.getUnit());
 		}
 		if (null != person) {
 			wo.setPerson(person.getDistinguishedName());
+		}else{
+			wo.setPerson(identity.getPerson());
 		}
 		if (null != identity) {
 			wo.setDescription(identity.getDescription());