From de69f94099f71fc52fae7618e575b3d2f3781d6c Mon Sep 17 00:00:00 2001 From: "446052889@qq.com" <446052889@qq.com> Date: Thu, 28 Mar 2024 14:16:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B5=81=E7=A8=8B=E5=85=A8=E6=99=AF=E6=BA=90?= =?UTF-8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../processmap/CoEProcessMapController.java | 83 ++++ .../constant/CoEProcessMapConstant.java | 24 ++ .../model/CoEProcessMapResponse.java | 64 +++ .../model/CoEProcessMapTreeModel.java | 182 +++++++++ .../coe/pal/processmap/plugins/Plugins.java | 40 ++ .../processmap/util/ProcessMapTreeUtil.java | 386 ++++++++++++++++++ .../pal/processmap/web/CoEProcessMapWeb.java | 265 ++++++++++++ 7 files changed, 1044 insertions(+) create mode 100644 com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/CoEProcessMapController.java create mode 100644 com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/constant/CoEProcessMapConstant.java create mode 100644 com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/model/CoEProcessMapResponse.java create mode 100644 com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/model/CoEProcessMapTreeModel.java create mode 100644 com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/plugins/Plugins.java create mode 100644 com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/util/ProcessMapTreeUtil.java create mode 100644 com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/web/CoEProcessMapWeb.java diff --git a/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/CoEProcessMapController.java b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/CoEProcessMapController.java new file mode 100644 index 00000000..ae6029d7 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/CoEProcessMapController.java @@ -0,0 +1,83 @@ +package com.actionsoft.apps.coe.pal.processmap; + +import com.actionsoft.apps.coe.pal.processmap.web.CoEProcessMapWeb; +import com.actionsoft.bpms.commons.htmlframework.HtmlPageTemplate; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.bpms.server.bind.annotation.Controller; +import com.actionsoft.bpms.server.bind.annotation.Mapping; +import com.alibaba.fastjson.JSON; + +import java.util.HashMap; +import java.util.Map; + +@Controller +public class CoEProcessMapController { + /** + * 架构全景展示 + * @param me + * @param wsid + * @return + */ + @Mapping("com.actionsoft.apps.coe.pal.processmap_home") + public String processReportHome(UserContext me, String wsid) { + CoEProcessMapWeb web = new CoEProcessMapWeb(me); + return web.getHome(wsid); + } + + /** + * 流程全景 home + * + * @param uc UserContext + */ + @Mapping("com.actionsoft.apps.coe.pal.processmap_panorama_home") + public String processPanoramaHome(UserContext uc, String wsId, String teamId) { + return new CoEProcessMapWeb(uc).getNewHome(wsId, teamId); + } + + /** + * 流程全景获取 + * + * @param uc UserContext + * @param wsId 资产库id + */ + @Mapping("com.actionsoft.apps.coe.pal.processmap_panorama_getProcessPanorama") + public String getProcessPanorama(UserContext uc, String wsId, String teamId) { + return new CoEProcessMapWeb(uc).getProcessPanorama(wsId, teamId); + } + + /** + * 获取流程全景通过id 局部数据组装 (鼠标点击返回的数据) + * + * @param uc UserContext + * @param wsId 资产库id + * @param id 节点返回的id + */ + @Mapping("com.actionsoft.apps.coe.pal.processmap_panorama_getPanoramaTreeById") + public String getPanoramaTreeById(UserContext uc, String wsId, String teamId, String id) { + return new CoEProcessMapWeb(uc).getPanoramaTreeById(wsId, teamId, id, true); + } + + /** + * 获取流程全景通过id 局部数据组装 (面包屑点击返回的数据) + * + * @param uc UserContext + * @param wsId 资产库id + * @param id 节点返回的id + */ + @Mapping("com.actionsoft.apps.coe.pal.processmap_panorama_getPanoramaTreeByIdToBread") + public String getPanoramaTreeByIdToBread(UserContext uc, String wsId, String teamId, String id) { + return new CoEProcessMapWeb(uc).getPanoramaTreeById(wsId, teamId, id, false); + } + + /** + * 获取流程全景 通过点击 侧边 + - 控制整体输出的 层级 + * + * @param uc UserContext + * @param wsId 资产库id + * @param level 层级 + */ + @Mapping("com.actionsoft.apps.coe.pal.processmap_panorama_getPanoramaTreeByLevel") + public String getPanoramaTreeByLevel(UserContext uc, String wsId, String teamId, Integer level) { + return new CoEProcessMapWeb(uc).getPanoramaTreeByLevel(wsId, teamId, level); + } +} diff --git a/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/constant/CoEProcessMapConstant.java b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/constant/CoEProcessMapConstant.java new file mode 100644 index 00000000..c2d4dbcf --- /dev/null +++ b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/constant/CoEProcessMapConstant.java @@ -0,0 +1,24 @@ +package com.actionsoft.apps.coe.pal.processmap.constant; + +/** + * 流程全景图常量定义 + * @author 作者: wangyh + * @version 创建时间:2014-3-4 + * + */ +public interface CoEProcessMapConstant { + /** + * 标题 + */ + public static final String PROCESSMAP_PAGE_TITLE ="流程全景图"; + + /** + * 流程查询时调用都流程pid + */ + String PROCESS_PID = "process"; + + /** + * 流程全景默认输出层级 + */ + Integer DEFAULT_LEVEL = 0; +} diff --git a/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/model/CoEProcessMapResponse.java b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/model/CoEProcessMapResponse.java new file mode 100644 index 00000000..0a89cba3 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/model/CoEProcessMapResponse.java @@ -0,0 +1,64 @@ +package com.actionsoft.apps.coe.pal.processmap.model; + +import java.util.List; + +/** + * pal 流程全景响应类 + * + * @author lipt + * @date 2022/12/6 + */ +public class CoEProcessMapResponse { + + /** + * 资产库id + */ + private String wsId; + + /** + * 资产库名称 + */ + private String wsName; + + /** + * 最大等级 + */ + private Integer maxLevel; + + /** + * 子响应类集合 + */ + private List coEProcessMapTreeModels; + + public Integer getMaxLevel() { + return maxLevel; + } + + public void setMaxLevel(Integer maxLevel) { + this.maxLevel = maxLevel; + } + + public String getWsId() { + return wsId; + } + + public void setWsId(String wsId) { + this.wsId = wsId; + } + + public String getWsName() { + return wsName; + } + + public void setWsName(String wsName) { + this.wsName = wsName; + } + + public List getCoEProcessMapTreeModels() { + return coEProcessMapTreeModels; + } + + public void setCoEProcessMapTreeModels(List coEProcessMapTreeModels) { + this.coEProcessMapTreeModels = coEProcessMapTreeModels; + } +} diff --git a/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/model/CoEProcessMapTreeModel.java b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/model/CoEProcessMapTreeModel.java new file mode 100644 index 00000000..eb6c6f53 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/model/CoEProcessMapTreeModel.java @@ -0,0 +1,182 @@ +package com.actionsoft.apps.coe.pal.processmap.model; + +import java.util.List; +import java.util.Map; + +/** + * pal 流程全景响应类 + * + * @author lipt + * @date 2022/12/6 + */ +public class CoEProcessMapTreeModel { + + /** + * 资产库文件表ID + */ + private String id; + + /** + * 节点名称 + */ + private String name; + + /** + * 节点值,为子响应类的数量 + */ + private Integer value; + + /** + * 节点路径 path + */ + private String path; + + /** + * 资产库文件父ID + */ + private String parentId; + + /** + * 版本Id,多个版本时一致,取自第一个版本的Id + */ + private String versionId; + + /** + * 流程等级编号 + */ + private String processLevelNo; + + /** + * 子响应类 + */ + private List children; + + /** + * 等级 + */ + private Integer level; + + /** + * 流程全景中节点颜色 + */ + private String color; + + /** + * 流程全景中节点颜色 透明度 + */ + private List colorAlpha; + + /** + * itemStyle 中的参数 colorAlpha + */ + private Map itemStyle; + + /** + * 颜色饱和度 + */ + private List colorSaturation; + + public String getVersionId() { + return versionId; + } + + public void setVersionId(String versionId) { + this.versionId = versionId; + } + + public List getColorAlpha() { + return colorAlpha; + } + + public void setColorAlpha(List colorAlpha) { + this.colorAlpha = colorAlpha; + } + + public Map getItemStyle() { + return itemStyle; + } + + public void setItemStyle(Map itemStyle) { + this.itemStyle = itemStyle; + } + + public List getColorSaturation() { + return colorSaturation; + } + + public void setColorSaturation(List colorSaturation) { + this.colorSaturation = colorSaturation; + } + + public Integer getLevel() { + return level; + } + + public void setLevel(Integer level) { + this.level = level; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public Integer getValue() { + return value; + } + + public void setValue(Integer value) { + this.value = value; + } + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getParentId() { + return parentId; + } + + public void setParentId(String parentId) { + this.parentId = parentId; + } + + public String getProcessLevelNo() { + return processLevelNo; + } + + public void setProcessLevelNo(String processLevelNo) { + this.processLevelNo = processLevelNo; + } + + public List getChildren() { + return children; + } + + public void setChildren(List children) { + this.children = children; + } + + public String getColor() { + return color; + } + + public void setColor(String color) { + this.color = color; + } +} diff --git a/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/plugins/Plugins.java b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/plugins/Plugins.java new file mode 100644 index 00000000..fa789a95 --- /dev/null +++ b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/plugins/Plugins.java @@ -0,0 +1,40 @@ +package com.actionsoft.apps.coe.pal.processmap.plugins; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import com.actionsoft.apps.coe.pal.processmap.web.CoEProcessMapWeb; +import com.actionsoft.apps.listener.PluginListener; +import com.actionsoft.apps.resource.AppContext; +import com.actionsoft.apps.resource.plugin.profile.AWSPluginProfile; +import com.actionsoft.apps.resource.plugin.profile.AppExtensionProfile; + +/** + * 注册插件 + * @author zhouxuan + */ +public class Plugins implements PluginListener { + public Plugins() { + } + public List register(AppContext context) { + List list = new ArrayList(); + // PAL应用扩展点 + Map params0 = new HashMap(); + params0.put("title", "流程全景"); + params0.put("icon", ""); + params0.put("desc", "流程全景"); + params0.put("mainClass", CoEProcessMapWeb.class.getName()); + params0.put("deletedClass", ""); + list.add(new AppExtensionProfile("PAL流程资产库->流程全景", "aslp://com.actionsoft.apps.coe.pal/registerExtendsApp", params0)); + + // 注册应用扩展点 + Map params1 = new HashMap(); + params1.put("title", "流程全景"); + params1.put("desc", "流程全景"); + list.add(new AppExtensionProfile("PAL小组->流程全景", "aslp://com.actionsoft.apps.coe.pal.cooperation/registerApp", params1)); + return list; + } + +} diff --git a/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/util/ProcessMapTreeUtil.java b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/util/ProcessMapTreeUtil.java new file mode 100644 index 00000000..5d62ae4b --- /dev/null +++ b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/util/ProcessMapTreeUtil.java @@ -0,0 +1,386 @@ +package com.actionsoft.apps.coe.pal.processmap.util; + +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.apps.coe.pal.pal.method.cache.PALMethodCache; +import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager; +import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.util.CoeProcessLevelUtil; +import com.actionsoft.apps.coe.pal.processmap.constant.CoEProcessMapConstant; +import com.actionsoft.apps.coe.pal.processmap.model.CoEProcessMapTreeModel; +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.i18n.I18nRes; +import org.springframework.beans.BeanUtils; +import org.springframework.util.CollectionUtils; + +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * 流程全景树组装工具,将组装树的调用方法提取到这个类中 + * + * @author lipt + * @date 2022/12/16 + */ +public class ProcessMapTreeUtil { + + /** + * 流程全景最大层级 + */ + private static Integer processMaxLevel = 0; + + /** + * 流程全景默认输出层级,随着 + - 的更改而更改 + */ + private static Integer defaultLevel = CoEProcessMapConstant.DEFAULT_LEVEL; + + /** + * treeModelsList 集合 + */ + private static List treeModelsList; + + /** + * 查询所有的数据 并组装到 tree 中,可以多次加载调用 + * + * @param wsId 资产库id + */ + public static void wrapperTreeModelList(String userId, String wsId, String teamId) { + // 所有子流程及其本身的集合 + List allProcessList = getAllRepositoryList(wsId); + + // 获取所有的权限 VersionId 集合 + Set permVerIds = CoeProcessLevelUtil.getPermRepositoryVersionIds(wsId, teamId, userId, null, null); + + // 基础树结构数据组装 集合对象转换 + List treeModels = processRepToTreeModel(allProcessList); + + // 从缓存中循环查询数据pal Method 的数据集合 + List palMethodList = getPalMethodPrem(wsId, teamId, userId); + + // 组装树结构的流程全景数据 + treeModelsList = wrapperPMTreePerm(palMethodList, treeModels, permVerIds); + } + + /** + * 根据权限获取 palMethod + * + * @param wsId 资产库Id + * @param teamId 小组Id + * @param userId 用户Id + * @return palMethod 集合 + */ + private static List getPalMethodPrem(String wsId, String teamId, String userId) { + // teamId 为空则 返回全部数据 + if (UtilString.isEmpty(teamId)) { + return PALMethodCache.getPALMethodList(true); + } + // 获取组权限下的 palMethod 的集合,过滤重复返回 + List permRepositoryList = CoeProcessLevelUtil.getPermRepositoryList(wsId, teamId, userId, null, null, true, false); + return permRepositoryList.stream().map(PALRepositoryModel::getMethodCategory).distinct().collect(Collectors.toList()); + } + + /** + * 对象转换 PALRepositoryModel 转化为定义的树类型 CoEProcessMapTreeModel + * + * @param allProcessList PALRepositoryModel集合 + * @return List + */ + public static List processRepToTreeModel(List allProcessList) { + return allProcessList.stream().map(a -> { + CoEProcessMapTreeModel model = new CoEProcessMapTreeModel(); + model.setParentId(a.getParentId()); + model.setId(a.getId()); + model.setName(a.getName()); + model.setPath(a.getName()); + model.setLevel(a.getLevel()); + model.setVersionId(a.getVersionId()); + return model; + }).collect(Collectors.toList()); + } + + /** + * 组装树结构 组装的为根节点数据 + * + * @param treeModels CoEProcessMapTreeModel集合 + * @return 返回树类型的集合 + */ + public static List wrapperPMTree(List treeModels, Boolean deepFlag) { + // 从缓存中循环查询数据pal Method 的数据集合 + List palMethodList = PALMethodCache.getPALMethodList(true); + Map mapTreeModelMap = treeModels.stream().collect(Collectors.toMap(CoEProcessMapTreeModel::getId, Function.identity())); + + List treeModelList = new ArrayList<>(); + for (String palMethod : palMethodList) { + CoEProcessMapTreeModel treeModel = new CoEProcessMapTreeModel(); + // 递归获取子节点的数据 + treeModel.setChildren(wrapperPMChildrenTree(treeModels, palMethod, 1)); + // 组装树中的数据 + wrapperCommonTreeData(treeModel); + treeModel.setId(palMethod); + if (deepFlag) { + treeModel.setValue(mapTreeModelMap.get(palMethod).getValue()); + } + treeModel.setName(I18nRes.findValue(CoEConstant.APP_ID, palMethod)); + treeModel.setLevel(0); + treeModelList.add(treeModel); + } + return treeModelList; + } + + /** + * 组装子节点数据 + * + * @param treeModels CoEProcessMapTreeModel集合数据 + * @param pid 父id + * @param level 当前节点所在等级 + * @return 返回组装好的树集合 + */ + public static List wrapperPMChildrenTree(List treeModels, String pid, Integer level) { + List treeModelList = new ArrayList<>(); + level++; + processMaxLevel = Math.max(processMaxLevel, level); + for (CoEProcessMapTreeModel treeModel : treeModels) { + if (pid.equals(treeModel.getParentId())) { + // 递归获取子节点的数据 + treeModel.setLevel(level); + treeModel.setChildren(wrapperPMChildrenTree(treeModels, treeModel.getId(), level)); + // 组装树中的数据 + wrapperCommonTreeData(treeModel); + + treeModelList.add(treeModel); + } + } + return treeModelList; + } + + /** + * 组装树中的公共数据提取的方法 + * + * @param treeModel 树 对象 + */ + private static void wrapperCommonTreeData(CoEProcessMapTreeModel treeModel) { + if (treeModel.getValue() == null) { + // 组装父节点数据 + int size = treeModel.getChildren().stream().mapToInt(CoEProcessMapTreeModel::getValue).sum(); + if (size == 0) { + // 美化样式,清楚边框的宽度 + Map map = new HashMap<>(); + map.put("borderWidth", 0); + treeModel.setItemStyle(map); + } + size = size == 0 ? 1 : size; + treeModel.setValue(size); + } + } + + /** + * 获取流程最大等级 + */ + public static Integer getProcessMaxLevel() { + return processMaxLevel; + } + + /** + * 查询所有的数据 并组装到 tree 中 默认不去刷新 treeModelsList + * + * @param wsId 资产库id + */ + public static List getTreeModelsList(String userId, String wsId, String teamId) { + return getTreeModelsList(userId, wsId, teamId, false); + } + + /** + * 查询所有的数据 并组装到 tree 中 + *

+ * 只有界面初始的时候去调用该方法,其余时候其余时候直接去获取已经有的数据 + * 接口去获取 getPanoramaTreePidList 和 getPanoramaTreeById 两个方法是不需要再次获取数据的。 + *

+ * + * @param userId 用户id + * @param wsId 资产库id + * @param teamId 小组id + * @param flushFlag 刷新标识 + */ + public static List getTreeModelsList(String userId, String wsId, String teamId, Boolean flushFlag) { + if (CollectionUtils.isEmpty(treeModelsList) || flushFlag) { + wrapperTreeModelList(userId, wsId, teamId); + } + return treeModelsList; + } + + /** + * 所有子流程及其本身的集合 + */ + public static List getAllRepositoryList(String wsId) { + // 从缓存中循环查询数据pal Method 的数据集合 存放到 + List palMethodList = PALMethodCache.getPALMethodList(true); + List palRepositoryModels = new ArrayList<>(); + // 获取当前所有流程的一级节点流程 + for (String palMethod : palMethodList) { + Iterator processIter = PALRepositoryCache.getByPid(wsId, palMethod); + processIter.forEachRemaining(palRepositoryModels::add); + // 排序 + palRepositoryModels.sort(Comparator.comparingInt(PALRepositoryModel::getOrderIndex).reversed()); + } + + // 所有子流程及其本身的集合 + List allProcessList = new ArrayList<>(); + palRepositoryModels.forEach(palRepositoryModel -> { + allProcessList.add(palRepositoryModel); + // 获取流程的所有使用中的子流程 + PALRepositoryQueryAPIManager.getInstance().getAllUsedPalRepositoryModelsByPid(wsId, palRepositoryModel.getId(), allProcessList); + }); + return allProcessList; + } + + /** + * 获取 treeModelList 集合 通过等级 + * + * @param treeModelList CoEProcessMapTreeModel集合 + * @return level 等级 + */ + public static List getTreeModelsByLevel(List treeModelList, int level) { + defaultLevel = level; + List treeModels = new ArrayList<>(); + for (CoEProcessMapTreeModel model : treeModelList) { + CoEProcessMapTreeModel treeModel; + treeModel = model; + if (treeModel.getLevel() >= level || CollectionUtils.isEmpty(treeModel.getChildren())) { + Map map = new HashMap<>(); + map.put("borderWidth", 0); + treeModel.setItemStyle(map); + treeModel.setChildren(null); + } else { + treeModel.setChildren(getTreeModelsByLevel(treeModel.getChildren(), level)); + } + treeModels.add(treeModel); + } + return treeModels; + } + + /** + * 树型转为基础list + */ + public static List treeModelToModelList(List treeModelList) { + List newTreeModel = new ArrayList<>(); + for (CoEProcessMapTreeModel model : treeModelList) { + newTreeModel.add(model); + List children = model.getChildren(); + if (!CollectionUtils.isEmpty(children)) { + List childrenList = treeModelToModelList(children); + newTreeModel.addAll(childrenList); + } + } + if (newTreeModel.size() > 0) { + for (CoEProcessMapTreeModel model : newTreeModel) { + model.setChildren(null); + } + } + return newTreeModel; + } + + /** + * 根据id查询树中的子节点 + * + * @param treeModelList 树型集合 + * @param id 要查询的id + */ + public static List findChildrenModelsById(List treeModelList, String id) { + for (CoEProcessMapTreeModel model : treeModelList) { + if (model.getId().equals(id)) { + return model.getChildren(); + } else { + if (!CollectionUtils.isEmpty(model.getChildren())) { + List childModels = findChildrenModelsById(model.getChildren(), id); + if (!CollectionUtils.isEmpty(childModels)) { + return childModels; + } + } + } + } + return null; + } + + /** + * 过滤树只包含一层数据,拷贝不影响原本的数据 + */ + public static List filterModelsOneLevel(List treeModels) { + if (CollectionUtils.isEmpty(treeModels)) { + return null; + } + return treeModels.stream().map(m -> { + CoEProcessMapTreeModel model = new CoEProcessMapTreeModel(); + BeanUtils.copyProperties(m, model); + if (!CollectionUtils.isEmpty(model.getChildren())) { + model.setChildren(null); + } + return model; + }).collect(Collectors.toList()); + } + + /** + * 组装树结构 组装的为根节点数据 + * + * @param treeModels CoEProcessMapTreeModel集合 + * @param permVerIds 获取所有的权限 VersionId 集合 + * @return 返回树类型的集合 + */ + public static List wrapperPMTreePerm(List palMethodList, List treeModels, Set permVerIds) { + Map mapTreeModelMap = treeModels.stream().collect(Collectors.toMap(CoEProcessMapTreeModel::getId, Function.identity())); + + // 当前的层级 + int curLevel = 0; + + List treeModelList = new ArrayList<>(); + for (String palMethod : palMethodList) { + CoEProcessMapTreeModel model = mapTreeModelMap.get(palMethod); + if (model != null && !permVerIds.contains(model.getVersionId())) { + // 父节点不在数据中,直接去添加子节点 level 也为当前节点的层级。 + List childTreePerm = wrapperPMChildrenTreePerm(treeModels, palMethod, permVerIds, curLevel); + treeModelList.addAll(childTreePerm); + } else { + CoEProcessMapTreeModel treeModel = new CoEProcessMapTreeModel(); + // 递归获取子节点的数据 + treeModel.setChildren(wrapperPMChildrenTreePerm(treeModels, palMethod, permVerIds, curLevel + 1)); + // 组装树中的数据 + wrapperCommonTreeData(treeModel); + treeModel.setId(palMethod); + treeModel.setName(I18nRes.findValue(CoEConstant.APP_ID, palMethod)); + treeModel.setLevel(curLevel); + treeModelList.add(treeModel); + } + } + return treeModelList; + } + + /** + * 组装子节点数据 + * + * @param treeModels CoEProcessMapTreeModel集合数据 + * @param pid 父id + * @param level 当前节点所在等级 + * @return 返回组装好的树集合 + */ + public static List wrapperPMChildrenTreePerm(List treeModels, String pid, Set permVerIds, Integer level) { + List treeModelList = new ArrayList<>(); + // 当前层级 + processMaxLevel = Math.max(processMaxLevel, level); + for (CoEProcessMapTreeModel treeModel : treeModels) { + if (pid.equals(treeModel.getParentId())) { + if (!permVerIds.contains(treeModel.getVersionId())) { + treeModelList.addAll(wrapperPMChildrenTreePerm(treeModels, treeModel.getId(), permVerIds, level)); + } else { + level++; + // 递归获取子节点的数据 + treeModel.setLevel(level); + treeModel.setChildren(wrapperPMChildrenTreePerm(treeModels, treeModel.getId(), permVerIds, level)); + // 组装树中的数据 + wrapperCommonTreeData(treeModel); + treeModelList.add(treeModel); + } + } + } + return treeModelList; + } +} diff --git a/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/web/CoEProcessMapWeb.java b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/web/CoEProcessMapWeb.java new file mode 100644 index 00000000..96a8387c --- /dev/null +++ b/com.actionsoft.apps.coe.pal.processmap/src/com/actionsoft/apps/coe/pal/processmap/web/CoEProcessMapWeb.java @@ -0,0 +1,265 @@ +package com.actionsoft.apps.coe.pal.processmap.web; + +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +import com.actionsoft.apps.coe.pal.constant.CoEConstant; +import com.actionsoft.apps.coe.pal.log.CoEOpLogAPI; +import com.actionsoft.apps.coe.pal.log.CoEOpLogConst; +import com.actionsoft.apps.coe.pal.pal.repository.PALRepositoryQueryAPIManager; +import com.actionsoft.apps.coe.pal.pal.repository.cache.PALRepositoryCache; +import com.actionsoft.apps.coe.pal.pal.repository.dao.CoeProcessLevelDaoFacotory; +import com.actionsoft.apps.coe.pal.pal.repository.model.CoeProcessLevelJsonModel; +import com.actionsoft.apps.coe.pal.pal.repository.model.PALRepositoryModel; +import com.actionsoft.apps.coe.pal.pal.repository.model.impl.PALRepositoryModelImpl; +import com.actionsoft.apps.coe.pal.pal.repository.util.CoeProcessLevelUtil; +import com.actionsoft.apps.coe.pal.pal.ws.dao.CoeWorkSpaceDaoFactory; +import com.actionsoft.apps.coe.pal.pal.ws.model.CoeWorkSpaceModel; +import com.actionsoft.apps.coe.pal.processmap.constant.CoEProcessMapConstant; +import com.actionsoft.apps.coe.pal.processmap.model.CoEProcessMapResponse; +import com.actionsoft.apps.coe.pal.processmap.model.CoEProcessMapTreeModel; +import com.actionsoft.apps.coe.pal.processmap.util.ProcessMapTreeUtil; +import com.actionsoft.bpms.commons.htmlframework.HtmlPageTemplate; +import com.actionsoft.bpms.commons.mvc.view.ActionWeb; +import com.actionsoft.bpms.commons.mvc.view.ResponseObject; +import com.actionsoft.bpms.server.UserContext; +import com.actionsoft.bpms.util.UtilString; +import com.actionsoft.i18n.I18nRes; +import com.actionsoft.sdk.local.SDK; +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import org.apache.commons.collections.CollectionUtils; + +import static com.actionsoft.apps.coe.pal.processmap.constant.CoEProcessMapConstant.DEFAULT_LEVEL; + +/** + * coe 流程全景 web 层 + * + * @date 2022/12/5 5:22 下午 + */ +public class CoEProcessMapWeb extends ActionWeb { + UserContext _uc; + + public CoEProcessMapWeb() { + } + + public CoEProcessMapWeb(UserContext uc) { + super(uc); + _uc = uc; + } + + public String mainPage(UserContext context, String wsId) { + _uc = context; + return getNewHome(wsId, ""); + } + + public String mainPage(UserContext context, String wsId, String teamId) { + _uc = context; + return getNewHome(wsId, teamId); + } + + @Deprecated + public String getHome(String wsId) { + CoeWorkSpaceModel coeWorkSpaceModel = (CoeWorkSpaceModel) CoeWorkSpaceDaoFactory.createCoeWorkSpace().getAllModel(wsId); + Iterator rootModels = PALRepositoryCache.getByPid(wsId, "process"); + List rootList = new ArrayList<>(); + while (rootModels.hasNext()) { + PALRepositoryModel rootModel = rootModels.next(); + if (rootModel.isUse()) { + rootList.add(rootModel); + } + } + Collections.sort(rootList, new Comparator() { + @Override + public int compare(PALRepositoryModel o1, PALRepositoryModel o2) { + return o1.getOrderIndex() - o2.getOrderIndex(); + } + }); + +// String rootId = ""; +// +// +// +// +// +// while(rootModels.hasNext()) { +// PALRepositoryModel rootModel = rootModels.next(); +// if (rootModel.isSystemFile()) { +// rootId = rootModel.getId(); +// break; +// } +// } +// + // list.add(PALRepositoryCache.getCache().get(rootId)); + List list = new ArrayList<>(); + for (PALRepositoryModel plModel : rootList) { + list.add(plModel); + PALRepositoryQueryAPIManager.getInstance().getAllUsedPalRepositoryModelsByPid(wsId, plModel.getId(), list); + } + + //用于架构全景的json数据传递 + List rlist = new ArrayList<>(); + int count = list.size(); + // 资产库文件集合 + for (int i = 0; i < count; i++) { + PALRepositoryModelImpl coeProcessLevelModel = (PALRepositoryModelImpl)list.get(i); + CoeProcessLevelJsonModel model = new CoeProcessLevelJsonModel(); + model.setPlLevel(coeProcessLevelModel.getLevel()); + model.setPlName(I18nRes.findValue(CoEConstant.APP_ID, + _uc.getLanguage(), coeProcessLevelModel.getName().trim())); + model.setPlNo(CoeProcessLevelUtil.getProcessLevelNoByUUId( + coeProcessLevelModel.getId(), + coeProcessLevelModel.getWsId()).replace(".", "")); + model.setUuid(coeProcessLevelModel.getId()); + model.setPlParentId(coeProcessLevelModel.getParentId()); + model.setColor(coeProcessLevelModel.getColor()); + model.setIndex(i); + model.setPlAllNo(CoeProcessLevelUtil.getProcessLevelNoByUUId( + coeProcessLevelModel.getId(), + coeProcessLevelModel.getWsId())); + + rlist.add(model); + } + Map macroLibraries = new HashMap(); + macroLibraries.put( + "maxLevel", + CoeProcessLevelDaoFacotory.createCoeProcessLevel().getMaxLevel( + coeWorkSpaceModel.getUUId()) + 1); + macroLibraries.put( + "wsName", + I18nRes.findValue(CoEConstant.APP_ID, + coeWorkSpaceModel.getWsName())); + macroLibraries.put("wsType", coeWorkSpaceModel.getWsTctype()); + macroLibraries.put("processLevelData", JSONArray + .parseArray(JSON.toJSONString(rlist)).toString()); + macroLibraries.put("uid", _uc.getUserModel().getUserName()); + macroLibraries.put("iframeTitle", CoEProcessMapConstant.PROCESSMAP_PAGE_TITLE); + // 操作行为日志记录 + if (SDK.getAppAPI().getPropertyBooleanValue(CoEConstant.APP_ID, "IS_RECORD_OP_LOG", false)) { + CoEOpLogAPI.auditOkOp(_uc, CoEOpLogConst.MODULE_CATEGORY_APPCENTER, CoEOpLogConst.OP_ACCESS, CoEOpLogConst.INFO_APPCENTER_ACCESS_PREFIX + SDK.getAppAPI().getAppContext("com.actionsoft.apps.coe.pal.processmap").getName() + CoEOpLogConst.INFO_APPCENTER_ACCESS_SUFFIX); + } + return HtmlPageTemplate.merge("com.actionsoft.apps.coe.pal.processmap", + "pal.ws.architecture.panoramic.htm", macroLibraries); + } + + + public String getNewHome(String wsId, String teamId) { + Map macroLibraries = new HashMap<>(); + macroLibraries.put("sessionId", _uc.getSessionId()); + macroLibraries.put("settingParam", JSON.toJSON(macroLibraries)); + macroLibraries.put("wsId", wsId); + macroLibraries.put("teamId", teamId); + return HtmlPageTemplate.merge("com.actionsoft.apps.coe.pal.processmap", "main.htm", macroLibraries); + } + + /** + * 获取流程全景 + * + * @param wsId 资产库id + * @param teamId 小组id + * @return 返回流程全景的数据 + */ + public String getProcessPanorama(String wsId, String teamId) { + if (UtilString.isEmpty(wsId)) { + return ResponseObject.newErrResponse("wsId不能为空").toString(); + } + ResponseObject ro = ResponseObject.newOkResponse(); + // 资产库实体类 + CoeWorkSpaceModel wsModel = CoeWorkSpaceDaoFactory.createCoeWorkSpace().getAllModel(wsId); + // 资产库名称 + String wsName = wsModel.getWsName(); + + // 组装基础返回的数据 + CoEProcessMapResponse coEProcessMapResponse = new CoEProcessMapResponse(); + coEProcessMapResponse.setWsName(wsName); + coEProcessMapResponse.setWsId(wsId); + + // 组装获取树model集合 + List treeModelList = ProcessMapTreeUtil.getTreeModelsList(_uc.getUID(), wsId, teamId, true); + coEProcessMapResponse.setCoEProcessMapTreeModels(treeModelList); + + // 默认输出1级数据 +// List treeModelsByLevel = ProcessMapTreeUtil.getTreeModelsByLevel(treeModelList, DEFAULT_LEVEL); +// coEProcessMapResponse.setCoEProcessMapTreeModels(treeModelsByLevel); + + coEProcessMapResponse.setMaxLevel(ProcessMapTreeUtil.getProcessMaxLevel()); + ro.put("processMap", coEProcessMapResponse); + return ro.toString(); + } + + /** + * 获取流程全景通过id 局部数据组装 (鼠标点击和面包屑点击返回的数据) + * + * @param wsId 资产库id + * @param id 节点返回的id + * @param deepFlag 下钻标识 点击面包屑时只显示当前层级,点击下钻时显示下一层级 + */ + public String getPanoramaTreeById(String wsId, String teamId, String id, Boolean deepFlag) { + if (UtilString.isEmpty(wsId)) { + return ResponseObject.newErrResponse("wsId不能为空").toString(); + } + if (UtilString.isEmpty(id)) { + return ResponseObject.newErrResponse("id不能为空").toString(); + } + // 组装获取树model集合 + List allRepositoryList = ProcessMapTreeUtil.getAllRepositoryList(wsId); + Map idAndModelMap = allRepositoryList.stream().collect(Collectors.toMap(PALRepositoryModel::getId, Function.identity())); + List idList = new ArrayList<>(); + idList.add(id); + String finalId = id; + while (idAndModelMap.get(id) != null) { + id = idAndModelMap.get(id).getParentId(); + idList.add(id); + } + // 反转 + Collections.reverse(idList); + + List treeModelList = ProcessMapTreeUtil.getTreeModelsList(_uc.getUID(), wsId, teamId, true); + + // 结果集合 + List treeModels; + if (deepFlag) { + List modelsById = ProcessMapTreeUtil.findChildrenModelsById(treeModelList, finalId); + treeModels = ProcessMapTreeUtil.filterModelsOneLevel(modelsById); + } else { + List allTreeModelList = ProcessMapTreeUtil.treeModelToModelList(treeModelList); + List deepIdList = new ArrayList<>(); + CollectionUtils.addAll(deepIdList, new Object[idList.size()]); + Collections.copy(deepIdList, idList); + deepIdList.remove(finalId); + List collect = allTreeModelList.stream() + // 过滤层级数据 + .filter(m -> (m.getLevel() <= DEFAULT_LEVEL) + // 是否为下钻的数据 + || deepIdList.contains(m.getParentId())) + .collect(Collectors.toList()); + treeModels = ProcessMapTreeUtil.wrapperPMTree(collect, true); + } + + ResponseObject ro = ResponseObject.newOkResponse(); + ro.put("treeModels", treeModels); + ro.put("idList", idList); + + return ro.toString(); + } + + /** + * 获取流程全景 通过点击 侧边 + - 控制整体输出的 层级 + * + * @param wsId 资产库id + * @param level 层级 + */ + public String getPanoramaTreeByLevel(String wsId, String teamId, Integer level) { + if (ProcessMapTreeUtil.getProcessMaxLevel() < level) { + return ResponseObject.newWarnResponse("层级超出最大值").toString(); + } + // 获取 存储的 treeModelList + List treeModelList = ProcessMapTreeUtil.getTreeModelsList(_uc.getUID(), wsId, teamId, true); + List treeModelsByLevel = ProcessMapTreeUtil.getTreeModelsByLevel(treeModelList, level); + + ResponseObject ro = ResponseObject.newOkResponse(); + ro.put("processMap", treeModelsByLevel); + return ro.toString(); + } +} \ No newline at end of file