diff --git a/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/CooperationQueryAPIManager.java b/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/CooperationQueryAPIManager.java index 20e9cd96..d4bfd9c3 100644 --- a/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/CooperationQueryAPIManager.java +++ b/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/CooperationQueryAPIManager.java @@ -141,126 +141,6 @@ public class CooperationQueryAPIManager { } } - public List getAllTeamInfo(){ - List list = new ArrayList<>(); - - List allTeam = new CoeCooperationTeamDao().getAllTeam(); - for (CoeCooperationTeamModel teamModel : allTeam) { - TeamInfo teamInfo = new TeamInfo(); - teamInfo.setTeamId(teamModel.getId()); - List userInfos = this.getUserInfoByTeamId(teamModel.getId()); - teamInfo.setUsers(userInfos); - - List permVerIds = new CoeCooperationTeamPermDao().getCooperationTeamPermVerIds(teamModel.getId()); - teamInfo.getVersionIds().addAll(permVerIds); - - list.add(teamInfo); - } - return list; - } - - public List getUserInfoByTeamId(String teamId){ - List list = new ArrayList<>(); - - Map userMap = new HashMap<>(); - List memberModels = new CoeCooperationMemberDao().queryUserListByTeam(teamId); - for (CoeCooperationMemberModel memberModel : memberModels) { - UserInfo userInfo = userMap.get(memberModel.getUserId()); - if (null == userInfo){ - userInfo = new UserInfo(); - userInfo.setUserid(memberModel.getUserId()); - userInfo.getRoleIds().add(memberModel.getRoleId()); - }else { - userInfo.getRoleIds().add(memberModel.getRoleId()); - } - userMap.put(memberModel.getUserId(),userInfo); - } - - for (UserInfo userInfo : userMap.values()) { - List roleIds = userInfo.getRoleIds(); - Set appPerm = this.getAppPerm(roleIds); - userInfo.setAppPermission(appPerm); - - Set actionPerm = this.getActionPerm(roleIds); - userInfo.setOperatePermission(actionPerm); - - boolean allDataPerm = this.isAllDataPerm(roleIds); - userInfo.setIsAllDataPermission(allDataPerm); - - if (!allDataPerm){ - Map> dataPerm = this.getDataPerm(teamId, roleIds); - userInfo.setDataPermission(dataPerm); - } - } - - list.addAll(userMap.values()); - return list; - } - - private Set getAppPerm(List roleIds){ - Set set = new HashSet<>(); - for (String roleId : roleIds) { - CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId); - if (null == roleModel){ - continue; - } - //设置全局app权限 - List appPerm = Arrays.stream(roleModel.getAppPerm().split(",")).collect(Collectors.toList()); - set.addAll(appPerm); - } - return set; - } - - private Set getActionPerm(List roleIds){ - Set set = new HashSet<>(); - for (String roleId : roleIds) { - CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId); - if (null == roleModel){ - continue; - } - //设置全局操作权限 - List actionPermList = Arrays.stream(roleModel.getActionPerm().split(",")).collect(Collectors.toList()); - set.addAll(actionPermList); - } - return set; - } - - private boolean isAllDataPerm(List roleIds){ - for (String roleId : roleIds) { - CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId); - if (null == roleModel){ - continue; - } - if (roleModel.getDataPerm().equals("all")){ - return true; - } - } - return false; - } - - private Map> getDataPerm(String teamId,List roleIds){ - Map> map = new HashMap<>(); - for (String roleId : roleIds) { - CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId); - if (null == roleModel) { - continue; - } - //获取角色下数据权限,设置数据权限 - List rolePerms = new CoeCooperationRolePermDao().getRolePermByTeamIdAndRoleId(teamId, roleId); - for (CoeCooperationRolePermModel rolePerm : rolePerms) { - Set dataPerm = map.get(rolePerm.getPalVersionId()); - if (null == dataPerm){ - dataPerm = new HashSet<>(); - } - if (StringUtils.isNotEmpty(rolePerm.getActionPerm())){ - dataPerm.addAll(Arrays.asList(rolePerm.getActionPerm().split(",").clone())); - } - map.put(rolePerm.getPalVersionId(), dataPerm); - } - } - return map; - } - /** * 根据父节点获取权限范围内的子流程(小组权限范围内) * @param wsId diff --git a/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/plugins/Plugins.java b/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/plugins/Plugins.java index 6daa8b83..5eb06033 100644 --- a/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/plugins/Plugins.java +++ b/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/plugins/Plugins.java @@ -32,8 +32,6 @@ 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; } } diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/CoeCooperationAPIManager.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/CoeCooperationAPIManager.java index 096a38aa..1d2e0624 100644 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/CoeCooperationAPIManager.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/CoeCooperationAPIManager.java @@ -2,6 +2,9 @@ package com.actionsoft.apps.coe.pal.cooperation; import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.apps.coe.pal.cooperation.cache.CooperationCache; +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.CoeCooperationConst; import com.actionsoft.apps.coe.pal.cooperation.dao.*; import com.actionsoft.apps.coe.pal.cooperation.model.*; @@ -24,10 +27,12 @@ import com.actionsoft.bpms.util.UtilString; import com.actionsoft.sdk.local.SDK; import com.actionsoft.sdk.local.api.AppAPI; import com.alibaba.fastjson.JSONArray; +import org.apache.commons.lang.StringUtils; import javax.servlet.RequestDispatcher; import java.sql.Timestamp; import java.util.*; +import java.util.stream.Collectors; /** * @Created by sunlh @@ -580,28 +585,43 @@ public class CoeCooperationAPIManager { * @param ro havingWritePerm、havingRemovePerm、havingVersionManagePerm 返回true false */ public void queryCooperationMemberActionPerm(String teamId, String userId, ResponseObject ro) { - // 权限获取 - boolean havingWritePerm = true; - boolean havingRemovePerm = true; - boolean havingVersionManagePerm = true; - int validUserPermDataCount = 0;// 当前小组成员有效(流程表中存在)的数据权限数量 - if (!UtilString.isEmpty(teamId) && isInstall()) { - CoeCooperationRoleModel role = queryCooperationRoleByUser(teamId, userId); - if (role != null) { - if (role.getActionPerm() == null) { - role.setActionPerm(""); - }; - havingWritePerm = role.getActionPerm().contains(CoeCooperationConst.ACTION_WRITE);// 新增、修改权限 - havingRemovePerm = role.getActionPerm().contains(CoeCooperationConst.ACTION_DELETE);// 删除权限 - havingVersionManagePerm = role.getActionPerm().contains(CoeCooperationConst.ACTION_VERSION);// 版本管理权限 + boolean isOlderVersion = SDK.getAppAPI().getPropertyBooleanValue("com.actionsoft.apps.coe.pal", "IsOlderVersion", true); + if (isOlderVersion){ + // 权限获取 + boolean havingWritePerm = true; + boolean havingRemovePerm = true; + boolean havingVersionManagePerm = true; + int validUserPermDataCount = 0;// 当前小组成员有效(流程表中存在)的数据权限数量 + if (!UtilString.isEmpty(teamId) && isInstall()) { + Set userOperatePermission = CooperationCache.getUserOperatePermission(teamId, userId); + havingWritePerm = userOperatePermission.contains(CoeCooperationConst.ACTION_WRITE);// 新增、修改权限 + havingRemovePerm = userOperatePermission.contains(CoeCooperationConst.ACTION_DELETE);// 删除权限 + havingVersionManagePerm = userOperatePermission.contains(CoeCooperationConst.ACTION_VERSION);// 版本管理权限 } + ro.put("isOlderVersion", isOlderVersion); + ro.put("havingWritePerm", havingWritePerm);// 新增、修改权限 + ro.put("havingRemovePerm", havingRemovePerm);// 删除权限 + ro.put("havingVersionManagePerm", havingVersionManagePerm);// 版本管理权限 + Set permDataVerIdList = CooperationCache.getUserDataVisitablePermission(teamId, userId,true); + validUserPermDataCount = permDataVerIdList != null ? permDataVerIdList.size() : 0; + ro.put("validUserPermDataCount", validUserPermDataCount); + }else { + boolean havingCreatePerm = true; + boolean havingBatchPerm = true; + int validUserPermDataCount = 0; + if (!UtilString.isEmpty(teamId) && isInstall()) { + Set userOperatePermission = CooperationCache.getUserOperatePermission(teamId, userId); + havingCreatePerm = userOperatePermission.contains(CoeCooperationConst.ACTION_CREATE_PROCESS); + havingBatchPerm = userOperatePermission.contains(CoeCooperationConst.ACTION_BATCH); + } + + ro.put("isOlderVersion", !isOlderVersion);// 新增、修改权限 + ro.put("havingCreatePerm", havingCreatePerm);// 新增、修改权限 + ro.put("havingBatchPerm", havingBatchPerm);// 删除权限 + Set dataVisitablePermission = CooperationCache.getUserDataVisitablePermission(teamId, userId,true); + validUserPermDataCount = dataVisitablePermission != null ? dataVisitablePermission.size() : 0; + ro.put("validUserPermDataCount", validUserPermDataCount); } - ro.put("havingWritePerm", havingWritePerm);// 新增、修改权限 - ro.put("havingRemovePerm", havingRemovePerm);// 删除权限 - ro.put("havingVersionManagePerm", havingVersionManagePerm);// 版本管理权限 - List permDataVerIdList = queryCooperationRoleDataPermByTeamUser(teamId, userId, true); - validUserPermDataCount = permDataVerIdList != null ? permDataVerIdList.size() : 0; - ro.put("validUserPermDataCount", validUserPermDataCount); } /** @@ -735,4 +755,125 @@ public class CoeCooperationAPIManager { return false; } + + public List getAllTeamInfo(){ + List list = new ArrayList<>(); + + List allTeam = new CoeCooperationTeamDao().getAllTeam(); + for (CoeCooperationTeamModel teamModel : allTeam) { + TeamInfo teamInfo = new TeamInfo(); + teamInfo.setTeamId(teamModel.getId()); + List userInfos = this.getUserInfoByTeamId(teamModel.getId()); + teamInfo.setUsers(userInfos); + + List permVerIds = new CoeCooperationTeamPermDao().getCooperationTeamPermVerIds(teamModel.getId()); + teamInfo.getVersionIds().addAll(permVerIds); + + list.add(teamInfo); + } + return list; + } + + public List getUserInfoByTeamId(String teamId){ + List list = new ArrayList<>(); + + Map userMap = new HashMap<>(); + List memberModels = new CoeCooperationMemberDao().queryUserListByTeam(teamId); + for (CoeCooperationMemberModel memberModel : memberModels) { + UserInfo userInfo = userMap.get(memberModel.getUserId()); + if (null == userInfo){ + userInfo = new UserInfo(); + userInfo.setUserid(memberModel.getUserId()); + userInfo.getRoleIds().add(memberModel.getRoleId()); + }else { + userInfo.getRoleIds().add(memberModel.getRoleId()); + } + userMap.put(memberModel.getUserId(),userInfo); + } + + for (UserInfo userInfo : userMap.values()) { + List roleIds = userInfo.getRoleIds(); + Set appPerm = this.getAppPerm(roleIds); + userInfo.setAppPermission(appPerm); + + Set actionPerm = this.getActionPerm(roleIds); + userInfo.setOperatePermission(actionPerm); + + boolean allDataPerm = this.isAllDataPerm(roleIds); + userInfo.setIsAllDataPermission(allDataPerm); + + if (!allDataPerm){ + Map> dataPerm = this.getDataPerm(teamId, roleIds); + userInfo.setDataPermission(dataPerm); + } + } + + list.addAll(userMap.values()); + return list; + } + + private Set getAppPerm(List roleIds){ + Set set = new HashSet<>(); + for (String roleId : roleIds) { + CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId); + if (null == roleModel){ + continue; + } + //设置全局app权限 + List appPerm = Arrays.stream(roleModel.getAppPerm().split(",")).collect(Collectors.toList()); + set.addAll(appPerm); + } + return set; + } + + private Set getActionPerm(List roleIds){ + Set set = new HashSet<>(); + for (String roleId : roleIds) { + CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId); + if (null == roleModel){ + continue; + } + //设置全局操作权限 + List actionPermList = Arrays.stream(roleModel.getActionPerm().split(",")).collect(Collectors.toList()); + set.addAll(actionPermList); + } + return set; + } + + private boolean isAllDataPerm(List roleIds){ + for (String roleId : roleIds) { + CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId); + if (null == roleModel){ + continue; + } + if (roleModel.getDataPerm().equals("all")){ + return true; + } + } + return false; + } + + private Map> getDataPerm(String teamId,List roleIds){ + Map> map = new HashMap<>(); + for (String roleId : roleIds) { + CoeCooperationRoleModel roleModel = new CoeCooperationRoleDao().queryById(roleId); + if (null == roleModel) { + continue; + } + //获取角色下数据权限,设置数据权限 + List rolePerms = new CoeCooperationRolePermDao().getRolePermByTeamIdAndRoleId(teamId, roleId); + for (CoeCooperationRolePermModel rolePerm : rolePerms) { + Set dataPerm = map.get(rolePerm.getPalVersionId()); + if (null == dataPerm){ + dataPerm = new HashSet<>(); + } + if (StringUtils.isNotEmpty(rolePerm.getActionPerm())){ + dataPerm.addAll(Arrays.asList(rolePerm.getActionPerm().split(",").clone())); + } + map.put(rolePerm.getPalVersionId(), dataPerm); + } + } + return map; + } + } diff --git a/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/cache/CooperationCache.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/cache/CooperationCache.java similarity index 84% rename from com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/cache/CooperationCache.java rename to com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/cache/CooperationCache.java index 122234fb..cda73bc6 100644 --- a/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/cache/CooperationCache.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/cache/CooperationCache.java @@ -1,19 +1,21 @@ package com.actionsoft.apps.coe.pal.cooperation.cache; -import com.actionsoft.apps.coe.pal.cooperation.CooperationQueryAPIManager; + +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.apps.coe.pal.cooperation.CoeCooperationAPIManager; 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.CoeCooperationConst; -import com.actionsoft.apps.coe.pal.cooperation.constant.Constant; -import com.actionsoft.apps.coe.pal.cooperation.extend.CooperationAppManager; -import com.actionsoft.apps.coe.pal.cooperation.extend.CooperationAppProfile; import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; 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.commons.mvc.view.ResponseObject; import com.actionsoft.bpms.util.ConsolePrinter; import com.actionsoft.sdk.local.SDK; +import com.actionsoft.sdk.local.api.AppAPI; +import com.alibaba.fastjson.JSONArray; import java.util.*; import java.util.stream.Collectors; @@ -25,13 +27,13 @@ public class CooperationCache extends Cache { @Override protected void load() { - List allTeamInfo = CooperationQueryAPIManager.getInstance().getAllTeamInfo(); + List allTeamInfo = CoeCooperationAPIManager.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()) + "个]"); + ConsolePrinter.info("[" + SDK.getAppAPI().getAppContext(CoEConstant.APP_ID).getNameI18N() + "]Cache加载pal 小组用户角色权限信息 [" + (( allTeamInfo == null) ? 0 : allTeamInfo.size()) + "个]"); } @@ -129,9 +131,15 @@ public class CooperationCache extends Cache { Set appPermission = userInfo.getAppPermission(); if (appPermission.contains("all")){ Set set = new HashSet<>(); - List appProfiles = CooperationAppManager.getList(); - for (CooperationAppProfile profile : appProfiles) { - set.add(profile.getId()); + // aslp服务地址 + String aslp = "aslp://com.actionsoft.apps.coe.pal.cooperation/listApps"; + //列出已注册的流程团队扩展App + ResponseObject ro = SDK.getAppAPI().callASLP(SDK.getAppAPI().getAppContext(CoEConstant.APP_ID), aslp, new HashMap()); + if (ro.isOk()) { + JSONArray appArr = (JSONArray)((Map)ro.getData()).get("apps"); + for (int i = 0; i < appArr.size(); i++) { + set.add(appArr.getJSONObject(i).getString("id")); + } } return set; } diff --git a/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/cache/model/TeamInfo.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/cache/model/TeamInfo.java similarity index 100% rename from com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/cache/model/TeamInfo.java rename to com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/cache/model/TeamInfo.java diff --git a/com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/cache/model/UserInfo.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/cache/model/UserInfo.java similarity index 100% rename from com.actionsoft.apps.coe.pal.cooperation/src/com/actionsoft/apps/coe/pal/cooperation/cache/model/UserInfo.java rename to com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/cooperation/cache/model/UserInfo.java diff --git a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/plugin/Plugins.java b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/plugin/Plugins.java index 90ccaa9f..f9e37732 100755 --- a/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/plugin/Plugins.java +++ b/com.actionsoft.apps.coe.pal/src/com/actionsoft/apps/coe/pal/plugin/Plugins.java @@ -14,6 +14,7 @@ import com.actionsoft.apps.coe.pal.aslp.MethodAPI.QueryMethodListByMethod; import com.actionsoft.apps.coe.pal.aslp.PermAPI.*; import com.actionsoft.apps.coe.pal.aslp.PublishAPI.PublishPALRepository; import com.actionsoft.apps.coe.pal.aslp.RepositoryAPI.*; +import com.actionsoft.apps.coe.pal.cooperation.cache.CooperationCache; import com.actionsoft.apps.coe.pal.pal.home.aslp.RegisterExtendsApp; import com.actionsoft.apps.coe.pal.pal.method.aslp.RegisterMethodApp; import com.actionsoft.apps.coe.pal.pal.repository.addons.RepositoryDiagramExistMark; @@ -165,6 +166,9 @@ public class Plugins implements PluginListener { list.add(new ASLPPluginProfile("queryAllPublishedPALRepositoryModelsByPid", QueryAllPublishedPALRepositoryModelsByPid.class.getName(), "获取流程资产库下所有已发布的子流程,请直接调用SDK.getPALRepositoryQueryAPI.getAllPublishedPalRepositoryModelsByPid()方法", new HttpASLP(HttpASLP.AUTH_AWS_SID, null))); list.add(new AddOnsPluginProfile(RepositoryDiagramExistMark.class.getName(), "PAL初始化模型图标记", null)); + + //小组用户权限信息cache + list.add(new CachePluginProfile(CooperationCache.class)); return list; }