|
|
@@ -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());
|