提交 c5086c69 编写于 作者: NoSubject's avatar NoSubject

Merge branch 'feature/人员组织模块群组管理优化' into 'develop'

Merge of feature/[人员组织]群组管理优化 to develop

See merge request o2oa/o2oa!617
......@@ -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<String> expendGroupToIdentity(List<String> groupList) throws Exception {
List<Group> groups = new ArrayList<>();
List<Group> 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<String> set = new ListOrderedSet<String>();
for (Group g : groups) {
if (ListTools.isNotEmpty(g.getIdentityList())) {
set.addAll(g.getIdentityList());
}
}
return set.asList();
}
public Ehcache cache() {
return cache;
}
......
......@@ -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,6 +206,7 @@ public class GroupFactory extends AbstractFactory {
// @MethodDescribe("查找群组的直接群组成员.")
public List<String> listSubDirect(String id) throws Exception {
Group group = this.entityManagerContainer().find(id, Group.class, ExceptionWhen.none);
if(group!=null && ListTools.isNotEmpty(group.getGroupList())) {
EntityManager em = this.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
......@@ -212,6 +214,9 @@ public class GroupFactory extends AbstractFactory {
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<String> listSupDirectWithIdentity(String id) throws Exception {
EntityManager em = this.entityManagerContainer().get(Group.class);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<String> cq = cb.createQuery(String.class);
Root<Group> 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<Group> listSupDirectWithIdentityObject(String id) throws Exception {
List<String> ids = this.listSupDirectWithIdentity(id);
return this.entityManagerContainer().list(Group.class, ids);
}
}
\ No newline at end of file
......@@ -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<Group> groups = business.group().listSupDirectWithIdentityObject(identity.getId());
for(Group g : groups){
g.getIdentityList().remove(identity.getId());
}
}
}
\ No newline at end of file
......@@ -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<Wo>) element.getObjectValue());
......@@ -61,6 +63,8 @@ class ActionListLike extends BaseAction {
private List<String> unitList = new ArrayList<>();
@FieldDescribe("搜索职务范围,为空则不限定")
private List<String> unitDutyList = new ArrayList<>();
@FieldDescribe("搜索群组范围(仅限群组的身份成员),为空则不限定")
private List<String> groupList = new ArrayList<>();
public String getKey() {
return key;
......@@ -86,6 +90,13 @@ class ActionListLike extends BaseAction {
this.unitDutyList = unitDutyList;
}
public List<String> getGroupList() {
return groupList;
}
public void setGroupList(List<String> groupList) {
this.groupList = groupList;
}
}
public static class Wo extends Identity {
......@@ -107,11 +118,12 @@ class ActionListLike extends BaseAction {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
Root<Identity> 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<UnitDuty> unitDuties = business.unitDuty().pick(wi.getUnitDutyList());
List<String> unitDutyIdentities = new ArrayList<>();
......@@ -123,8 +135,16 @@ class ActionListLike extends BaseAction {
}
if (ListTools.isNotEmpty(wi.getUnitList())) {
List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
if(ListTools.isNotEmpty(identityIds)) {
p = cb.and(p, root.get(Identity_.id).in(identityIds));
}
}
if (ListTools.isNotEmpty(wi.getGroupList())) {
List<String> identityIds = business.expendGroupToIdentity(wi.getGroupList());
if(ListTools.isNotEmpty(identityIds)) {
p = cb.and(p, root.get(Identity_.id).in(identityIds));
}
}
List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
wos = Wo.copier.copy(os);
wos = business.identity().sort(wos);
......
......@@ -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<Wo>) element.getObjectValue());
......@@ -61,6 +63,8 @@ class ActionListLikePinyin extends BaseAction {
private List<String> unitList = new ArrayList<>();
@FieldDescribe("搜索职务范围,为空则不限定")
private List<String> unitDutyList = new ArrayList<>();
@FieldDescribe("搜索群组范围(仅限群组的身份成员),为空则不限定")
private List<String> groupList = new ArrayList<>();
public List<String> getUnitDutyList() {
return unitDutyList;
......@@ -86,6 +90,14 @@ class ActionListLikePinyin extends BaseAction {
this.unitList = unitList;
}
public List<String> getGroupList() {
return groupList;
}
public void setGroupList(List<String> groupList) {
this.groupList = groupList;
}
}
public static class Wo extends Identity {
......@@ -107,8 +119,9 @@ class ActionListLikePinyin extends BaseAction {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Identity> cq = cb.createQuery(Identity.class);
Root<Identity> 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<UnitDuty> unitDuties = business.unitDuty().pick(wi.getUnitDutyList());
List<String> unitDutyIdentities = new ArrayList<>();
......@@ -120,8 +133,16 @@ class ActionListLikePinyin extends BaseAction {
}
if (ListTools.isNotEmpty(wi.getUnitList())) {
List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
if(ListTools.isNotEmpty(identityIds)) {
p = cb.and(p, root.get(Identity_.id).in(identityIds));
}
}
if (ListTools.isNotEmpty(wi.getGroupList())) {
List<String> identityIds = business.expendGroupToIdentity(wi.getGroupList());
if(ListTools.isNotEmpty(identityIds)) {
p = cb.and(p, root.get(Identity_.id).in(identityIds));
}
}
List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
wos = Wo.copier.copy(os);
wos = business.identity().sort(wos);
......
......@@ -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<Wo>) element.getObjectValue());
......@@ -60,6 +62,8 @@ public class ActionListPinyinInitial extends BaseAction {
private List<String> unitList = new ArrayList<>();
@FieldDescribe("搜索职务范围,为空则不限定")
private List<String> unitDutyList = new ArrayList<>();
@FieldDescribe("搜索群组范围(仅限群组的身份成员),为空则不限定")
private List<String> groupList = new ArrayList<>();
public List<String> getUnitDutyList() {
return unitDutyList;
......@@ -85,6 +89,14 @@ public class ActionListPinyinInitial extends BaseAction {
this.unitList = unitList;
}
public List<String> getGroupList() {
return groupList;
}
public void setGroupList(List<String> groupList) {
this.groupList = groupList;
}
}
public static class Wo extends Identity {
......@@ -118,8 +130,16 @@ public class ActionListPinyinInitial extends BaseAction {
}
if (ListTools.isNotEmpty(wi.getUnitList())) {
List<String> identityIds = business.expendUnitToIdentity(wi.getUnitList());
if(ListTools.isNotEmpty(identityIds)) {
p = cb.and(p, root.get(Identity_.id).in(identityIds));
}
}
if (ListTools.isNotEmpty(wi.getGroupList())) {
List<String> identityIds = business.expendGroupToIdentity(wi.getGroupList());
if(ListTools.isNotEmpty(identityIds)) {
p = cb.and(p, root.get(Identity_.id).in(identityIds));
}
}
List<Identity> os = em.createQuery(cq.select(root).where(p)).getResultList();
wos = Wo.copier.copy(os);
wos = business.identity().sort(wos);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册