|
|
@@ -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 {
|
|
|
|
|
|
@@ -152,19 +154,57 @@ class ActionListIdentityWithUnitWithNameObject extends BaseAction {
|
|
|
|
|
|
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;
|
|
|
@@ -179,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());
|