小组应用小组用户权限缓存搭建
This commit is contained in:
parent
c0eac15c0b
commit
c8478e1bcd
@ -2,6 +2,16 @@ package com.actionsoft.apps.coe.pal.cooperation;
|
||||
|
||||
|
||||
import com.actionsoft.apps.coe.pal.constant.CoEConstant;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.cache.model.TeamInfo;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.cache.model.UserInfo;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.dao.CoeCooperationMemberDao;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.dao.CoeCooperationRoleDao;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.dao.CoeCooperationRolePermDao;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.dao.CoeCooperationTeamDao;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.model.CoeCooperationMemberModel;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.model.CoeCooperationRoleModel;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.model.CoeCooperationRolePermModel;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.model.CoeCooperationTeamModel;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.util.CooperationUtil;
|
||||
import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache;
|
||||
import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager;
|
||||
@ -12,8 +22,11 @@ import com.actionsoft.bpms.util.UtilString;
|
||||
import com.actionsoft.i18n.I18nRes;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public class CooperationQueryAPIManager {
|
||||
|
||||
@ -125,6 +138,60 @@ public class CooperationQueryAPIManager {
|
||||
}
|
||||
}
|
||||
|
||||
public List<TeamInfo> getAllTeamInfo(){
|
||||
List<TeamInfo> list = new ArrayList<>();
|
||||
|
||||
List<CoeCooperationTeamModel> allTeam = new CoeCooperationTeamDao().getAllTeam();
|
||||
for (CoeCooperationTeamModel teamModel : allTeam) {
|
||||
TeamInfo teamInfo = new TeamInfo();
|
||||
teamInfo.setTeamId(teamModel.getId());
|
||||
List<UserInfo> userInfos = this.getUserInfoByTeamId(teamModel.getId());
|
||||
teamInfo.setUsers(userInfos);
|
||||
list.add(teamInfo);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public List<UserInfo> getUserInfoByTeamId(String teamId){
|
||||
List<UserInfo> list = new ArrayList<>();
|
||||
|
||||
List<CoeCooperationMemberModel> memberModels = new CoeCooperationMemberDao().queryUserListByTeam(teamId);
|
||||
for (CoeCooperationMemberModel memberModel : memberModels) {
|
||||
UserInfo userInfo = new UserInfo();
|
||||
userInfo.setUserid(memberModel.getUserId());
|
||||
userInfo.getRoleIds().add(memberModel.getRoleId());
|
||||
|
||||
//获取角色信息,设置全局权限
|
||||
CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(memberModel.getRoleId());
|
||||
List<String> appPermList = Arrays.stream(roleModel.getAppPerm().split(",")).collect(Collectors.toList());
|
||||
userInfo.getAppPermission().addAll(appPermList);
|
||||
List<String> actionPermList = Arrays.stream(roleModel.getActionPerm().split(",")).collect(Collectors.toList());
|
||||
userInfo.getOperatePermission().addAll(actionPermList);
|
||||
//设置全部数据权限
|
||||
userInfo.setIsAllDataPermission(roleModel.getDataPerm().equals("all"));
|
||||
|
||||
if (!userInfo.getIsAllDataPermission()){
|
||||
//获取角色下数据权限,设置数据权限
|
||||
List<CoeCooperationRolePermModel> rolePerms = new CoeCooperationRolePermDao().getRolePermByTeamIdAndRoleId(teamId, memberModel.getRoleId());
|
||||
for (CoeCooperationRolePermModel rolePerm : rolePerms) {
|
||||
Set<String> dataPerm = userInfo.getDataPermission().get(rolePerm.getPalVersionId());
|
||||
if (null == dataPerm){
|
||||
dataPerm = new HashSet<>();
|
||||
}
|
||||
if (StringUtils.isNotEmpty(rolePerm.getActionPerm())){
|
||||
dataPerm.addAll(Arrays.asList(rolePerm.getActionPerm().split(",").clone()));
|
||||
}
|
||||
userInfo.getDataPermission().put(rolePerm.getPalVersionId(), dataPerm);
|
||||
}
|
||||
}
|
||||
|
||||
list.add(userInfo);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 根据父节点获取权限范围内的子流程(小组权限范围内)
|
||||
* @param wsId
|
||||
|
||||
@ -0,0 +1,159 @@
|
||||
package com.actionsoft.apps.coe.pal.cooperation.cache;
|
||||
|
||||
import com.actionsoft.apps.coe.pal.cooperation.CooperationQueryAPIManager;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.cache.model.TeamInfo;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.cache.model.UserInfo;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.constant.Constant;
|
||||
import com.actionsoft.apps.resource.plugin.profile.CachePluginProfile;
|
||||
import com.actionsoft.bpms.commons.cache.Cache;
|
||||
import com.actionsoft.bpms.commons.cache.CacheManager;
|
||||
import com.actionsoft.bpms.util.ConsolePrinter;
|
||||
import com.actionsoft.sdk.local.SDK;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class CooperationCache extends Cache<String, TeamInfo> {
|
||||
public CooperationCache(CachePluginProfile profile){
|
||||
super(profile);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void load() {
|
||||
List<TeamInfo> allTeamInfo = CooperationQueryAPIManager.getInstance().getAllTeamInfo();
|
||||
for (TeamInfo teamInfo : allTeamInfo) {
|
||||
put(teamInfo.getTeamId(),teamInfo);
|
||||
}
|
||||
|
||||
//平台console打印
|
||||
ConsolePrinter.info("[" + SDK.getAppAPI().getAppContext(Constant.APP_ID).getNameI18N() + "]Cache加载pal 小组用户角色权限信息 [" + (( allTeamInfo == null) ? 0 : allTeamInfo.size()) + "个]");
|
||||
|
||||
}
|
||||
|
||||
public static CooperationCache getCache(){
|
||||
return CacheManager.getCache(CooperationCache.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部小组权限info
|
||||
* @return
|
||||
*/
|
||||
public static List<TeamInfo> getAllTeamInfo(){
|
||||
List<TeamInfo> collect = getCache().stream().collect(Collectors.toList());
|
||||
if (collect.isEmpty()){
|
||||
getCache().load();
|
||||
}
|
||||
return collect;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定小组的权限info
|
||||
* @param teamId
|
||||
* @return
|
||||
*/
|
||||
public static TeamInfo getTeamInfo(String teamId){
|
||||
return getCache().get(teamId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小组下用户权限列表数据
|
||||
* @param teamId
|
||||
* @return
|
||||
*/
|
||||
public static List<UserInfo> getUserInfo(String teamId){
|
||||
TeamInfo teamInfo = getCache().get(teamId);
|
||||
return teamInfo.getUsers();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取小组下用户权限列表数据
|
||||
* @param teamId
|
||||
* @return
|
||||
*/
|
||||
public static UserInfo getUserInfo(String teamId,String userid){
|
||||
TeamInfo teamInfo = getCache().get(teamId);
|
||||
for (UserInfo user : teamInfo.getUsers()) {
|
||||
if (user.getUserid().equals(userid)){
|
||||
return user;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小组id与用户id获取用户的角色ids
|
||||
* @param teamId
|
||||
* @param userid
|
||||
* @return
|
||||
*/
|
||||
public static List<String> getUserRoles(String teamId,String userid){
|
||||
UserInfo userInfo = CooperationCache.getUserInfo(teamId, userid);
|
||||
if (null == userInfo){
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return userInfo.getRoleIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小组id与用户id获取用户的操作权限
|
||||
* @param teamId
|
||||
* @param userid
|
||||
* @return
|
||||
*/
|
||||
public static Set<String> getUserOperatePermission(String teamId,String userid){
|
||||
UserInfo userInfo = CooperationCache.getUserInfo(teamId, userid);
|
||||
if (null == userInfo){
|
||||
return new HashSet<>();
|
||||
}
|
||||
return userInfo.getOperatePermission();
|
||||
}
|
||||
/**
|
||||
* 根据小组id与用户id获取用户的应用权限
|
||||
* @param teamId
|
||||
* @param userid
|
||||
* @return
|
||||
*/
|
||||
public static Set<String> getUserAPPPermission(String teamId,String userid){
|
||||
UserInfo userInfo = CooperationCache.getUserInfo(teamId, userid);
|
||||
if (null == userInfo){
|
||||
return new HashSet<>();
|
||||
}
|
||||
return userInfo.getAppPermission();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小组与用户id获取用户数据访问权限
|
||||
* @param teamId
|
||||
* @param userid
|
||||
* @return
|
||||
*/
|
||||
public static Set<String> getUserDataVisitablePermission(String teamId,String userid){
|
||||
UserInfo userInfo = CooperationCache.getUserInfo(teamId, userid);
|
||||
if (null == userInfo){
|
||||
return new HashSet<>();
|
||||
}
|
||||
return userInfo.getDataPermission().keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小组与用户id获取用户数据控制权限
|
||||
* @param teamId
|
||||
* @param userid
|
||||
* @param versionId
|
||||
* @return
|
||||
*/
|
||||
public static Set<String> getUserDataOperatePermission(String teamId,String userid,String versionId){
|
||||
UserInfo userInfo = CooperationCache.getUserInfo(teamId, userid);
|
||||
if (null == userInfo){
|
||||
return new HashSet<>();
|
||||
}
|
||||
return userInfo.getDataPermission().get(versionId);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.actionsoft.apps.coe.pal.cooperation.cache.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
public class TeamInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String teamId;
|
||||
|
||||
private List<UserInfo> users;
|
||||
|
||||
public TeamInfo() {}
|
||||
|
||||
public String getTeamId() {
|
||||
return teamId;
|
||||
}
|
||||
|
||||
public void setTeamId(String teamId) {
|
||||
this.teamId = teamId;
|
||||
}
|
||||
|
||||
public List<UserInfo> getUsers() {
|
||||
return users;
|
||||
}
|
||||
|
||||
public void setUsers(List<UserInfo> users) {
|
||||
this.users = users;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
package com.actionsoft.apps.coe.pal.cooperation.cache.model;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.*;
|
||||
|
||||
public class UserInfo implements Serializable {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private String userid;
|
||||
private List<String> roleIds = new ArrayList<>();
|
||||
private Set<String> operatePermission = new HashSet<>();
|
||||
private Set<String> appPermission = new HashSet<>();
|
||||
private Map<String,Set<String>> dataPermission = new HashMap<>();
|
||||
private boolean isAllDataPermission;
|
||||
|
||||
public UserInfo() { }
|
||||
|
||||
|
||||
public String getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(String userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public List<String> getRoleIds() {
|
||||
return roleIds;
|
||||
}
|
||||
|
||||
public void setRoleIds(List<String> roleIds) {
|
||||
this.roleIds = roleIds;
|
||||
}
|
||||
|
||||
public Set<String> getOperatePermission() {
|
||||
return operatePermission;
|
||||
}
|
||||
|
||||
public void setOperatePermission(Set<String> operatePermission) {
|
||||
this.operatePermission = operatePermission;
|
||||
}
|
||||
|
||||
public Set<String> getAppPermission() {
|
||||
return appPermission;
|
||||
}
|
||||
|
||||
public void setAppPermission(Set<String> appPermission) {
|
||||
this.appPermission = appPermission;
|
||||
}
|
||||
|
||||
public Map<String, Set<String>> getDataPermission() {
|
||||
return dataPermission;
|
||||
}
|
||||
|
||||
public void setIsDataPermission(Map<String, Set<String>> dataPermission) {
|
||||
this.dataPermission = dataPermission;
|
||||
}
|
||||
|
||||
public boolean getIsAllDataPermission() {
|
||||
return isAllDataPermission;
|
||||
}
|
||||
|
||||
public void setIsAllDataPermission(boolean allDataPermission) {
|
||||
isAllDataPermission = allDataPermission;
|
||||
}
|
||||
|
||||
}
|
||||
@ -2,13 +2,11 @@ package com.actionsoft.apps.coe.pal.cooperation.plugins;
|
||||
|
||||
import com.actionsoft.apps.coe.pal.cooperation.aslp.ListApps;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.aslp.RegisterApp;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.cache.CooperationCache;
|
||||
import com.actionsoft.apps.coe.pal.cooperation.dc.FileProcessor;
|
||||
import com.actionsoft.apps.listener.PluginListener;
|
||||
import com.actionsoft.apps.resource.AppContext;
|
||||
import com.actionsoft.apps.resource.plugin.profile.ASLPPluginProfile;
|
||||
import com.actionsoft.apps.resource.plugin.profile.AWSPluginProfile;
|
||||
import com.actionsoft.apps.resource.plugin.profile.AppExtensionProfile;
|
||||
import com.actionsoft.apps.resource.plugin.profile.DCPluginProfile;
|
||||
import com.actionsoft.apps.resource.plugin.profile.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@ -34,6 +32,8 @@ public class Plugins implements PluginListener {
|
||||
params2.put("deletedClass", "");
|
||||
list.add(new AppExtensionProfile("PAL小组->回收站", "aslp://com.actionsoft.apps.coe.pal.cooperation/registerApp", params2));
|
||||
|
||||
//小组用户权限信息cache
|
||||
list.add(new CachePluginProfile(CooperationCache.class));
|
||||
return list;
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,6 +83,17 @@ public class CoeCooperationRolePermDao extends DaoObject<CoeCooperationRolePermM
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小组与角色id获取数据权限模型
|
||||
* @param teamId
|
||||
* @param roleId
|
||||
* @return
|
||||
*/
|
||||
public List<CoeCooperationRolePermModel> getRolePermByTeamIdAndRoleId(String teamId,String roleId){
|
||||
String where = CoeCooperationRolePermModel.TEAMID + " =? AND "+ CoeCooperationRolePermModel.ROLEID +" =?";
|
||||
return query(where,teamId,roleId).list();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据小组删除相关数据
|
||||
* @param teamId
|
||||
@ -175,6 +186,7 @@ public class CoeCooperationRolePermDao extends DaoObject<CoeCooperationRolePermM
|
||||
model.setTeamId(rset.getString(CoeCooperationRolePermModel.TEAMID));
|
||||
model.setRoleId(rset.getString(CoeCooperationRolePermModel.ROLEID));
|
||||
model.setPalVersionId(rset.getString(CoeCooperationRolePermModel.PALVERSIONID));
|
||||
model.setActionPerm(rset.getString(CoeCooperationRolePermModel.ACTIONPERM));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
@ -182,6 +182,14 @@ public class CoeCooperationTeamDao extends DaoObject<CoeCooperationTeamModel> {
|
||||
DBSql.update(sql);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取全部小组数据
|
||||
* @return
|
||||
*/
|
||||
public List<CoeCooperationTeamModel> getAllTeam(){
|
||||
return query().orderBy(CoeCooperationTeamModel.CREATETIME).desc().list();
|
||||
}
|
||||
|
||||
private class Mapper implements RowMapper<CoeCooperationTeamModel> {
|
||||
public CoeCooperationTeamModel mapRow(ResultSet rset, int rowNum) throws SQLException {
|
||||
CoeCooperationTeamModel model = new CoeCooperationTeamModel();
|
||||
|
||||
@ -16,11 +16,13 @@ public final class CoeCooperationRolePermModel extends ModelBean {
|
||||
public static final String TEAMID = "TEAMID";
|
||||
public static final String ROLEID = "ROLEID";
|
||||
public static final String PALVERSIONID = "PALVERSIONID";
|
||||
public static final String ACTIONPERM = "ACTIONPERM";
|
||||
|
||||
private String id;
|
||||
private String teamId;
|
||||
private String roleId;
|
||||
private String palVersionId;
|
||||
private String actionPerm;
|
||||
|
||||
public CoeCooperationRolePermModel() {
|
||||
}
|
||||
@ -32,6 +34,14 @@ public final class CoeCooperationRolePermModel extends ModelBean {
|
||||
this.palVersionId = palVersionId;
|
||||
}
|
||||
|
||||
public CoeCooperationRolePermModel(String id, String teamId, String roleId, String palVersionId, String actionPerm) {
|
||||
this.id = id;
|
||||
this.teamId = teamId;
|
||||
this.roleId = roleId;
|
||||
this.palVersionId = palVersionId;
|
||||
this.actionPerm = actionPerm;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
@ -63,4 +73,12 @@ public final class CoeCooperationRolePermModel extends ModelBean {
|
||||
public void setPalVersionId(String palVersionId) {
|
||||
this.palVersionId = palVersionId;
|
||||
}
|
||||
|
||||
public String getActionPerm() {
|
||||
return actionPerm;
|
||||
}
|
||||
|
||||
public void setActionPerm(String actionPerm) {
|
||||
this.actionPerm = actionPerm;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user