@@ -6,11 +6,13 @@ import cc.smtweb.system.bpm.web.common.BpmConst; | |||||
import cc.smtweb.system.bpm.web.sys.user.dataRightGroup.IDataRightTreeWorker; | import cc.smtweb.system.bpm.web.sys.user.dataRightGroup.IDataRightTreeWorker; | ||||
import cc.smtweb.system.bpm.web.sys.user.dept.Dept; | import cc.smtweb.system.bpm.web.sys.user.dept.Dept; | ||||
import cc.smtweb.system.bpm.web.sys.user.dept.DeptCache; | import cc.smtweb.system.bpm.web.sys.user.dept.DeptCache; | ||||
import cc.smtweb.system.bpm.web.sys.user.party.Party; | |||||
import cc.smtweb.system.bpm.web.sys.user.party.PartyCache; | import cc.smtweb.system.bpm.web.sys.user.party.PartyCache; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Collection; | |||||
import java.util.List; | import java.util.List; | ||||
import java.util.Set; | |||||
import java.util.stream.Collectors; | |||||
/** | /** | ||||
* @Author yaoq | * @Author yaoq | ||||
@@ -32,21 +34,41 @@ public class DeptDataRightTreeWork implements IDataRightTreeWorker { | |||||
List<SwMap> list = new ArrayList<>(); | List<SwMap> list = new ArrayList<>(); | ||||
list.add(buildExtraValue(BpmConst.DataRight.ALL_DEPT, "所有部门")); | list.add(buildExtraValue(BpmConst.DataRight.ALL_DEPT, "所有部门")); | ||||
list.add(buildExtraValue(BpmConst.DataRight.CUR_VALUE, "所属部门")); | list.add(buildExtraValue(BpmConst.DataRight.CUR_VALUE, "所属部门")); | ||||
Set<Party> partys = filterParty(PartyCache.getInstance().getTopSet()); | |||||
if (CommUtil.isEmpty(partys)) return list; | |||||
partys.forEach(party -> { | |||||
list.add(buildExtraValue(party.getId(), party.getName())); | |||||
}); | |||||
return list; | return list; | ||||
} | } | ||||
@Override | @Override | ||||
public List<SwMap> getChildren(long id) { | public List<SwMap> getChildren(long id) { | ||||
List<SwMap> list = new ArrayList<>(); | List<SwMap> list = new ArrayList<>(); | ||||
list.addAll(getExtraValues()); | |||||
Collection<Dept> depts = DeptCache.getInstance().getAll(); | |||||
if (CommUtil.isEmpty(depts)) return list; | |||||
depts.forEach(dept -> { | |||||
list.add(buildExtraValue(dept.getId(), dept.getName())); | |||||
if (id <= 0) { | |||||
list.addAll(getExtraValues()); | |||||
return list; | |||||
} | |||||
Set<Dept> depts = DeptCache.getInstance().getByP(String.valueOf(id)); | |||||
if (!CommUtil.isEmpty(depts)) { | |||||
depts.forEach(dept -> { | |||||
list.add(buildExtraValue(dept.getId(), dept.getName())); | |||||
}); | |||||
} | |||||
Set<Party> partys = filterParty(PartyCache.getInstance().getChildren(id)); | |||||
if (CommUtil.isEmpty(partys)) return list; | |||||
partys.forEach(party -> { | |||||
list.add(buildExtraValue(party.getId(), party.getName())); | |||||
}); | }); | ||||
return list; | return list; | ||||
} | } | ||||
private Set<Party> filterParty(Set<Party> partySet) { | |||||
if (CommUtil.isEmpty(partySet)) return partySet; | |||||
return partySet.stream().filter((party) -> | |||||
!CommUtil.isEmpty(DeptCache.getInstance().getAllByPartyEx(party.getId()))).collect(Collectors.toSet()); | |||||
} | |||||
@Override | @Override | ||||
public String getText(long value) { | public String getText(long value) { | ||||
if (BpmConst.DataRight.CUR_VALUE == value) return "所属部门"; | if (BpmConst.DataRight.CUR_VALUE == value) return "所属部门"; | ||||
@@ -35,11 +35,13 @@ public class PartyDataRightTreeWork implements IDataRightTreeWorker { | |||||
@Override | @Override | ||||
public List<SwMap> getChildren(long id) { | public List<SwMap> getChildren(long id) { | ||||
List<SwMap> list = new ArrayList<>(); | |||||
long key = id; | long key = id; | ||||
if (key <= 0) key = -1; | |||||
if (key <= 0) { | |||||
key = -1; | |||||
list.addAll(getExtraValues()); | |||||
} | |||||
Set<Party> partys = PartyCache.getInstance().getChildren(key); | Set<Party> partys = PartyCache.getInstance().getChildren(key); | ||||
List<SwMap> list = new ArrayList<>(); | |||||
list.addAll(getExtraValues()); | |||||
if (CommUtil.isEmpty(partys)) return list; | if (CommUtil.isEmpty(partys)) return list; | ||||
partys.forEach(party -> { | partys.forEach(party -> { | ||||
list.add(buildExtraValue(party.getId(), party.getName())); | list.add(buildExtraValue(party.getId(), party.getName())); | ||||
@@ -3,7 +3,11 @@ package cc.smtweb.system.bpm.web.sys.user.dept; | |||||
import cc.smtweb.framework.core.annotation.SwCache; | import cc.smtweb.framework.core.annotation.SwCache; | ||||
import cc.smtweb.framework.core.cache.AbstractEntityCache; | import cc.smtweb.framework.core.cache.AbstractEntityCache; | ||||
import cc.smtweb.framework.core.cache.CacheManager; | import cc.smtweb.framework.core.cache.CacheManager; | ||||
import cc.smtweb.framework.core.util.CommUtil; | |||||
import cc.smtweb.system.bpm.web.sys.user.party.Party; | |||||
import cc.smtweb.system.bpm.web.sys.user.party.PartyCache; | |||||
import java.util.HashSet; | |||||
import java.util.Set; | import java.util.Set; | ||||
/** | /** | ||||
@@ -37,4 +41,29 @@ public class DeptCache extends AbstractEntityCache<Dept> { | |||||
public final Set<Dept> getByP(String key) { | public final Set<Dept> getByP(String key) { | ||||
return getListByKey(mk_p, key); | return getListByKey(mk_p, key); | ||||
} | } | ||||
public final String getNameById(Long id) { | |||||
Dept dept = get(id); | |||||
if (dept == null) return ""; | |||||
return dept.getName(); | |||||
} | |||||
/** | |||||
* @Author yaoq | |||||
* @Date 2022/9/22 17:08 | |||||
* @Params | |||||
* @Return java.util.Set<cc.smtweb.system.bpm.web.sys.user.dept.Dept> | |||||
* @Description 根据单位获取,该单位级下级单位所有部门集合 | |||||
*/ | |||||
public final Set<Dept> getAllByPartyEx(long party_id) { | |||||
Set<Dept> set = getByP(String.valueOf(party_id)); | |||||
if (set == null) set = new HashSet<>(); | |||||
Set<Party> child = PartyCache.getInstance().getAllChildren(party_id); | |||||
for (Party party : child) { | |||||
Set<Dept> depts = getByP(String.valueOf(party.getId())); | |||||
if (CommUtil.isEmpty(depts)) continue; | |||||
set.addAll(depts); | |||||
} | |||||
return set; | |||||
} | |||||
} | } |
@@ -5,6 +5,7 @@ import cc.smtweb.framework.core.cache.AbstractEntityCache; | |||||
import cc.smtweb.framework.core.cache.CacheManager; | import cc.smtweb.framework.core.cache.CacheManager; | ||||
import cc.smtweb.framework.core.util.CommUtil; | import cc.smtweb.framework.core.util.CommUtil; | ||||
import java.util.HashSet; | |||||
import java.util.Set; | import java.util.Set; | ||||
/** | /** | ||||
@@ -32,6 +33,21 @@ public class PartyCache extends AbstractEntityCache<Party> { | |||||
return getListByKey(mk_pr, String.valueOf(key)); | return getListByKey(mk_pr, String.valueOf(key)); | ||||
} | } | ||||
public final Set<Party> getAllChildren(Long key) { | |||||
Set<Party> set = new HashSet<>(); | |||||
buildChildren(key, set); | |||||
return set; | |||||
} | |||||
private final void buildChildren(Long key, Set<Party> set) { | |||||
Set<Party> child = getChildren(key); | |||||
if (CommUtil.isEmpty(child)) return; | |||||
set.addAll(child); | |||||
for (Party party : child) { | |||||
buildChildren(party.getId(), set); | |||||
} | |||||
} | |||||
//获取顶级集合 | //获取顶级集合 | ||||
public final Set<Party> getTopSet() { | public final Set<Party> getTopSet() { | ||||
return getChildren(-1L); | return getChildren(-1L); | ||||