diff --git a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/Business.java b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/Business.java index 42cd33ce5925756f7e14830e3faaff34f1ee5467..07c215bfa4cd9554c2655a896c7295842bc7d342 100644 --- a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/Business.java +++ b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/Business.java @@ -45,6 +45,7 @@ import com.x.organization.core.entity.UnitDuty; import org.apache.commons.collections4.CollectionUtils; import net.sf.ehcache.Ehcache; +import org.apache.commons.collections4.set.ListOrderedSet; public class Business { @@ -464,6 +465,33 @@ public class Business { return os; } + public List expendGroupToIdentity(List groupList) throws Exception { + List groups = new ArrayList<>(); + List expendGroups = new ArrayList<>(); + if (ListTools.isNotEmpty(groupList)) { + groupList = ListTools.trim(groupList, true, true); + for (String s : groupList) { + Group g = this.group().pick(s); + if (null != g) { + groups.add(g); + } + } + } + if (ListTools.isNotEmpty(groups)) { + for (Group g : groups) { + expendGroups.add(g); + expendGroups.addAll(this.group().listSubNestedObject(g)); + } + } + ListOrderedSet set = new ListOrderedSet(); + for (Group g : groups) { + if (ListTools.isNotEmpty(g.getIdentityList())) { + set.addAll(g.getIdentityList()); + } + } + return set.asList(); + } + public Ehcache cache() { return cache; } diff --git a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/factory/GroupFactory.java b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/factory/GroupFactory.java index 6143aa6cc332569a71af869e9c34fc94538b8a1c..48412475c0d00fd67315e67742059a28335e3871 100644 --- a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/factory/GroupFactory.java +++ b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/factory/GroupFactory.java @@ -12,6 +12,7 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import com.x.base.core.project.tools.ListTools; import org.apache.commons.collections4.set.ListOrderedSet; import org.apache.commons.lang3.StringUtils; @@ -205,13 +206,17 @@ public class GroupFactory extends AbstractFactory { // @MethodDescribe("查找群组的直接群组成员.") public List listSubDirect(String id) throws Exception { Group group = this.entityManagerContainer().find(id, Group.class, ExceptionWhen.none); - EntityManager em = this.entityManagerContainer().get(Group.class); - CriteriaBuilder cb = em.getCriteriaBuilder(); - CriteriaQuery cq = cb.createQuery(String.class); - Root root = cq.from(Group.class); - Predicate p = root.get(Group_.id).in(group.getGroupList()); - cq.select(root.get(Group_.id)).where(p); - return em.createQuery(cq).getResultList(); + if(group!=null && ListTools.isNotEmpty(group.getGroupList())) { + EntityManager em = this.entityManagerContainer().get(Group.class); + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(String.class); + Root root = cq.from(Group.class); + Predicate p = root.get(Group_.id).in(group.getGroupList()); + cq.select(root.get(Group_.id)).where(p); + return em.createQuery(cq).getResultList(); + }else{ + return new ArrayList<>(); + } } // @MethodDescribe("查找群组的全部群组成员,包括嵌套的群组成员.") @@ -237,4 +242,21 @@ public class GroupFactory extends AbstractFactory { } } + // @MethodDescribe("获取指定身份直接所在的群组.") + public List listSupDirectWithIdentity(String id) throws Exception { + EntityManager em = this.entityManagerContainer().get(Group.class); + CriteriaBuilder cb = em.getCriteriaBuilder(); + CriteriaQuery cq = cb.createQuery(String.class); + Root root = cq.from(Group.class); + Predicate p = cb.isMember(id, root.get(Group_.identityList)); + cq.select(root.get(Group_.id)).where(p); + return em.createQuery(cq).getResultList(); + } + + // @MethodDescribe("获取指定身份直接所在的群组.") + public List listSupDirectWithIdentityObject(String id) throws Exception { + List ids = this.listSupDirectWithIdentity(id); + return this.entityManagerContainer().list(Group.class, ids); + } + } \ No newline at end of file diff --git a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionDelete.java b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionDelete.java index 404609bcde2bc3aa01fcc67caa41b0648852225a..a30a5a3bbe6f636ea4e0b4e8bb55183d093518a4 100644 --- a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionDelete.java +++ b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionDelete.java @@ -11,6 +11,7 @@ import javax.persistence.criteria.CriteriaQuery; import javax.persistence.criteria.Predicate; import javax.persistence.criteria.Root; +import com.x.organization.core.entity.*; import org.apache.commons.lang3.StringUtils; import com.x.base.core.container.EntityManagerContainer; @@ -24,10 +25,6 @@ import com.x.base.core.project.http.EffectivePerson; import com.x.base.core.project.jaxrs.WoId; import com.x.organization.assemble.control.Business; import com.x.organization.assemble.control.message.OrgMessageFactory; -import com.x.organization.core.entity.Identity; -import com.x.organization.core.entity.Unit; -import com.x.organization.core.entity.UnitDuty; -import com.x.organization.core.entity.UnitDuty_; public class ActionDelete extends BaseAction { @@ -52,6 +49,10 @@ public class ActionDelete extends BaseAction { this.removeMemberOfUnitDuty(business, identity); emc.commit(); } + /** group的身份成员删除。*/ + emc.beginTransaction(Group.class); + this.removeMemberOfGroup(business, identity); + emc.commit(); /** 由于前面pick出来的需要重新取出 */ identity = emc.find(identity.getId(), Identity.class); // /** 删除下属身份 */ @@ -118,4 +119,11 @@ public class ActionDelete extends BaseAction { o.getIdentityList().remove(identity.getId()); } } + + private void removeMemberOfGroup(Business business, Identity identity) throws Exception { + List groups = business.group().listSupDirectWithIdentityObject(identity.getId()); + for(Group g : groups){ + g.getIdentityList().remove(identity.getId()); + } + } } \ No newline at end of file diff --git a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLike.java b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLike.java index c0f25f4b52248ac30dca24972e1adb1b95107383..871f9998f720479406f10f9af8d45b015b67b743 100644 --- a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLike.java +++ b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLike.java @@ -40,7 +40,9 @@ class ActionListLike extends BaseAction { Wi wi = this.convertToWrapIn(jsonElement, Wi.class); Business business = new Business(emc); String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(), - StringUtils.join(wi.getUnitList(), ",")); + StringUtils.join(wi.getUnitList(), ","), + StringUtils.join(wi.getUnitDutyList(), ","), + StringUtils.join(wi.getGroupList(), ",")); Element element = business.cache().get(cacheKey); if (null != element && (null != element.getObjectValue())) { result.setData((List) element.getObjectValue()); @@ -61,6 +63,8 @@ class ActionListLike extends BaseAction { private List unitList = new ArrayList<>(); @FieldDescribe("搜索职务范围,为空则不限定") private List unitDutyList = new ArrayList<>(); + @FieldDescribe("搜索群组范围(仅限群组的身份成员),为空则不限定") + private List groupList = new ArrayList<>(); public String getKey() { return key; @@ -86,6 +90,13 @@ class ActionListLike extends BaseAction { this.unitDutyList = unitDutyList; } + public List getGroupList() { + return groupList; + } + + public void setGroupList(List groupList) { + this.groupList = groupList; + } } public static class Wo extends Identity { @@ -107,11 +118,12 @@ class ActionListLike extends BaseAction { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Identity.class); Root root = cq.from(Identity.class); - Predicate p = cb.like(cb.lower(root.get(Identity_.name)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR); - p = cb.or(p, cb.like(cb.lower(root.get(Identity_.unique)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR)); - p = cb.or(p, cb.like(cb.lower(root.get(Identity_.pinyin)), str + "%", StringTools.SQL_ESCAPE_CHAR)); - p = cb.or(p, cb.like(cb.lower(root.get(Identity_.pinyinInitial)), str + "%", StringTools.SQL_ESCAPE_CHAR)); - p = cb.or(p, cb.like(cb.lower(root.get(Identity_.distinguishedName)), str + "%", StringTools.SQL_ESCAPE_CHAR)); + Predicate p = cb.conjunction(); + p = cb.and(p, cb.or(cb.like(cb.lower(root.get(Identity_.name)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR), + cb.like(cb.lower(root.get(Identity_.unique)), "%" + str + "%", StringTools.SQL_ESCAPE_CHAR), + 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))); if (ListTools.isNotEmpty(wi.getUnitDutyList())) { List unitDuties = business.unitDuty().pick(wi.getUnitDutyList()); List unitDutyIdentities = new ArrayList<>(); @@ -123,7 +135,15 @@ class ActionListLike extends BaseAction { } if (ListTools.isNotEmpty(wi.getUnitList())) { List identityIds = business.expendUnitToIdentity(wi.getUnitList()); - p = cb.and(p, root.get(Identity_.id).in(identityIds)); + if(ListTools.isNotEmpty(identityIds)) { + p = cb.and(p, root.get(Identity_.id).in(identityIds)); + } + } + if (ListTools.isNotEmpty(wi.getGroupList())) { + List identityIds = business.expendGroupToIdentity(wi.getGroupList()); + if(ListTools.isNotEmpty(identityIds)) { + p = cb.and(p, root.get(Identity_.id).in(identityIds)); + } } List os = em.createQuery(cq.select(root).where(p)).getResultList(); wos = Wo.copier.copy(os); diff --git a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLikePinyin.java b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLikePinyin.java index 4c04694a2511e5b6cedc1dbc03a4a044c162387a..b890e593c5610d947c09855d4902e3f1490bff5b 100644 --- a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLikePinyin.java +++ b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListLikePinyin.java @@ -40,7 +40,9 @@ class ActionListLikePinyin extends BaseAction { Wi wi = this.convertToWrapIn(jsonElement, Wi.class); Business business = new Business(emc); String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(), - StringUtils.join(wi.getUnitList(), ",")); + StringUtils.join(wi.getUnitList(), ","), + StringUtils.join(wi.getUnitDutyList(), ","), + StringUtils.join(wi.getGroupList(), ",")); Element element = business.cache().get(cacheKey); if (null != element && (null != element.getObjectValue())) { result.setData((List) element.getObjectValue()); @@ -61,6 +63,8 @@ class ActionListLikePinyin extends BaseAction { private List unitList = new ArrayList<>(); @FieldDescribe("搜索职务范围,为空则不限定") private List unitDutyList = new ArrayList<>(); + @FieldDescribe("搜索群组范围(仅限群组的身份成员),为空则不限定") + private List groupList = new ArrayList<>(); public List getUnitDutyList() { return unitDutyList; @@ -86,6 +90,14 @@ class ActionListLikePinyin extends BaseAction { this.unitList = unitList; } + public List getGroupList() { + return groupList; + } + + public void setGroupList(List groupList) { + this.groupList = groupList; + } + } public static class Wo extends Identity { @@ -107,8 +119,9 @@ class ActionListLikePinyin extends BaseAction { CriteriaBuilder cb = em.getCriteriaBuilder(); CriteriaQuery cq = cb.createQuery(Identity.class); Root root = cq.from(Identity.class); - Predicate p = cb.like(root.get(Identity_.pinyin), str + "%"); - p = cb.or(p, cb.like(root.get(Identity_.pinyinInitial), str + "%")); + 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))); if (ListTools.isNotEmpty(wi.getUnitDutyList())) { List unitDuties = business.unitDuty().pick(wi.getUnitDutyList()); List unitDutyIdentities = new ArrayList<>(); @@ -120,7 +133,15 @@ class ActionListLikePinyin extends BaseAction { } if (ListTools.isNotEmpty(wi.getUnitList())) { List identityIds = business.expendUnitToIdentity(wi.getUnitList()); - p = cb.and(p, root.get(Identity_.id).in(identityIds)); + if(ListTools.isNotEmpty(identityIds)) { + p = cb.and(p, root.get(Identity_.id).in(identityIds)); + } + } + if (ListTools.isNotEmpty(wi.getGroupList())) { + List identityIds = business.expendGroupToIdentity(wi.getGroupList()); + if(ListTools.isNotEmpty(identityIds)) { + p = cb.and(p, root.get(Identity_.id).in(identityIds)); + } } List os = em.createQuery(cq.select(root).where(p)).getResultList(); wos = Wo.copier.copy(os); diff --git a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListPinyinInitial.java b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListPinyinInitial.java index 2b917c98b4b47efbb1dd8165fb6e9ada58d1f51c..4175d713fdaa9750f63825182f7a24ec94f9bc79 100644 --- a/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListPinyinInitial.java +++ b/o2server/x_organization_assemble_control/src/main/java/com/x/organization/assemble/control/jaxrs/identity/ActionListPinyinInitial.java @@ -39,7 +39,9 @@ public class ActionListPinyinInitial extends BaseAction { Wi wi = this.convertToWrapIn(jsonElement, Wi.class); Business business = new Business(emc); String cacheKey = ApplicationCache.concreteCacheKey(this.getClass(), wi.getKey(), - StringUtils.join(wi.getUnitList(), ",")); + StringUtils.join(wi.getUnitList(), ","), + StringUtils.join(wi.getUnitDutyList(), ","), + StringUtils.join(wi.getGroupList(), ",")); Element element = business.cache().get(cacheKey); if (null != element && (null != element.getObjectValue())) { result.setData((List) element.getObjectValue()); @@ -60,6 +62,8 @@ public class ActionListPinyinInitial extends BaseAction { private List unitList = new ArrayList<>(); @FieldDescribe("搜索职务范围,为空则不限定") private List unitDutyList = new ArrayList<>(); + @FieldDescribe("搜索群组范围(仅限群组的身份成员),为空则不限定") + private List groupList = new ArrayList<>(); public List getUnitDutyList() { return unitDutyList; @@ -85,6 +89,14 @@ public class ActionListPinyinInitial extends BaseAction { this.unitList = unitList; } + public List getGroupList() { + return groupList; + } + + public void setGroupList(List groupList) { + this.groupList = groupList; + } + } public static class Wo extends Identity { @@ -118,7 +130,15 @@ public class ActionListPinyinInitial extends BaseAction { } if (ListTools.isNotEmpty(wi.getUnitList())) { List identityIds = business.expendUnitToIdentity(wi.getUnitList()); - p = cb.and(p, root.get(Identity_.id).in(identityIds)); + if(ListTools.isNotEmpty(identityIds)) { + p = cb.and(p, root.get(Identity_.id).in(identityIds)); + } + } + if (ListTools.isNotEmpty(wi.getGroupList())) { + List identityIds = business.expendGroupToIdentity(wi.getGroupList()); + if(ListTools.isNotEmpty(identityIds)) { + p = cb.and(p, root.get(Identity_.id).in(identityIds)); + } } List os = em.createQuery(cq.select(root).where(p)).getResultList(); wos = Wo.copier.copy(os);