|
|
@@ -7,19 +7,36 @@ import java.util.Optional;
|
|
|
import com.google.gson.JsonElement;
|
|
|
import com.x.base.core.container.EntityManagerContainer;
|
|
|
import com.x.base.core.container.factory.EntityManagerContainerFactory;
|
|
|
+import com.x.base.core.entity.JpaObject;
|
|
|
import com.x.base.core.project.annotation.FieldDescribe;
|
|
|
+import com.x.base.core.project.bean.WrapCopier;
|
|
|
+import com.x.base.core.project.bean.WrapCopierFactory;
|
|
|
import com.x.base.core.project.cache.Cache.CacheKey;
|
|
|
import com.x.base.core.project.cache.CacheManager;
|
|
|
import com.x.base.core.project.gson.GsonPropertyObject;
|
|
|
import com.x.base.core.project.http.ActionResult;
|
|
|
import com.x.base.core.project.http.EffectivePerson;
|
|
|
+import com.x.base.core.project.logger.Logger;
|
|
|
+import com.x.base.core.project.logger.LoggerFactory;
|
|
|
+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.Identity_;
|
|
|
import com.x.organization.core.entity.Unit;
|
|
|
+import com.x.organization.core.entity.Unit_;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
|
|
-class ActionListObject extends BaseAction {
|
|
|
+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 ActionListObject extends BaseAction {
|
|
|
+ private static Logger logger = LoggerFactory.getLogger(ActionListObject.class);
|
|
|
@SuppressWarnings("unchecked")
|
|
|
ActionResult<List<Wo>> execute(EffectivePerson effectivePerson, JsonElement jsonElement) throws Exception {
|
|
|
+
|
|
|
try (EntityManagerContainer emc = EntityManagerContainerFactory.instance().create()) {
|
|
|
Wi wi = this.convertToWrapIn(jsonElement, Wi.class);
|
|
|
ActionResult<List<Wo>> result = new ActionResult<>();
|
|
|
@@ -52,17 +69,71 @@ class ActionListObject extends BaseAction {
|
|
|
|
|
|
}
|
|
|
|
|
|
- public static class Wo extends com.x.base.core.project.organization.Unit {
|
|
|
+ public static class Wo extends Unit {
|
|
|
+ private static final long serialVersionUID = -7913547275132005308L;
|
|
|
+
|
|
|
+ @FieldDescribe("直接下级组织数量")
|
|
|
+ private Long subDirectUnitCount = 0L;
|
|
|
+
|
|
|
+ @FieldDescribe("直接下级身份数量")
|
|
|
+ private Long subDirectIdentityCount = 0L;
|
|
|
+
|
|
|
+ static WrapCopier<Unit, Wo> copier = WrapCopierFactory.wo(Unit.class, Wo.class, null,
|
|
|
+ ListTools.toList(JpaObject.FieldsInvisible,Unit.controllerList_FIELDNAME,Unit.inheritedControllerList_FIELDNAME));
|
|
|
+
|
|
|
+ public Long getSubDirectUnitCount() {
|
|
|
+ return subDirectUnitCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setSubDirectUnitCount(Long subDirectUnitCount) {
|
|
|
+ this.subDirectUnitCount = subDirectUnitCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public Long getSubDirectIdentityCount() {
|
|
|
+ return subDirectIdentityCount;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setSubDirectIdentityCount(Long subDirectIdentityCount) {
|
|
|
+ this.subDirectIdentityCount = subDirectIdentityCount;
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
|
private List<Wo> list(Business business, Wi wi) throws Exception {
|
|
|
List<Unit> os = business.unit().pick(wi.getUnitList());
|
|
|
- List<Wo> wos = new ArrayList<>();
|
|
|
- for (Unit o : os) {
|
|
|
- wos.add(this.convert(business, o, Wo.class));
|
|
|
+ List<Wo> wos = Wo.copier.copy(os);
|
|
|
+
|
|
|
+ for (Wo wo : wos) {
|
|
|
+ if (StringUtils.isNotEmpty(wo.getSuperior())) {
|
|
|
+ Unit superior = business.unit().pick(wo.getSuperior());
|
|
|
+ if (null != superior) {
|
|
|
+ wo.setSuperior(superior.getDistinguishedName());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ wo.setSubDirectIdentityCount(this.countSubDirectIdentity(business, wo));
|
|
|
+ wo.setSubDirectUnitCount(this.countSubDirectUnit(business, wo));
|
|
|
}
|
|
|
return wos;
|
|
|
}
|
|
|
|
|
|
+ private Long countSubDirectUnit(Business business, Wo wo) throws Exception {
|
|
|
+ EntityManager em = business.entityManagerContainer().get(Unit.class);
|
|
|
+ CriteriaBuilder cb = em.getCriteriaBuilder();
|
|
|
+ CriteriaQuery<Long> cq = cb.createQuery(Long.class);
|
|
|
+ Root<Unit> root = cq.from(Unit.class);
|
|
|
+ Predicate p = cb.equal(root.get(Unit_.superior), wo.getId());
|
|
|
+ Long count = em.createQuery(cq.select(cb.count(root)).where(p)).getSingleResult();
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
+ private Long countSubDirectIdentity(Business business, Wo wo) throws Exception {
|
|
|
+ EntityManager em = business.entityManagerContainer().get(Identity.class);
|
|
|
+ CriteriaBuilder cb = em.getCriteriaBuilder();
|
|
|
+ CriteriaQuery<Long> cq = cb.createQuery(Long.class);
|
|
|
+ Root<Identity> root = cq.from(Identity.class);
|
|
|
+ Predicate p = cb.equal(root.get(Identity_.unit), wo.getId());
|
|
|
+ Long count = em.createQuery(cq.select(cb.count(root)).where(p)).getSingleResult();
|
|
|
+ return count;
|
|
|
+ }
|
|
|
+
|
|
|
}
|