diff --git a/pigx-flow/pigx-flow-task/pigx-flow-task-biz/src/main/java/com/pig4cloud/pigx/flow/task/utils/NodeFormatUtil.java b/pigx-flow/pigx-flow-task/pigx-flow-task-biz/src/main/java/com/pig4cloud/pigx/flow/task/utils/NodeFormatUtil.java index d99547574..49d0c29e4 100644 --- a/pigx-flow/pigx-flow-task/pigx-flow-task-biz/src/main/java/com/pig4cloud/pigx/flow/task/utils/NodeFormatUtil.java +++ b/pigx-flow/pigx-flow-task/pigx-flow-task-biz/src/main/java/com/pig4cloud/pigx/flow/task/utils/NodeFormatUtil.java @@ -32,269 +32,271 @@ import java.util.stream.Collectors; */ public class NodeFormatUtil { - /** - * 格式化流程节点显示 - * @param node - * @param completeNodeSet - * @param continueNodeSet - * @param processInstanceId - * @param paramMap - */ - @SneakyThrows - public static List formatProcessNodeShow(Node node, Set completeNodeSet, - Set continueNodeSet, String processInstanceId, Map paramMap) { - List list = new ArrayList<>(); + /** + * 格式化流程节点显示 + * + * @param node + * @param completeNodeSet + * @param continueNodeSet + * @param processInstanceId + * @param paramMap + */ + @SneakyThrows + public static List formatProcessNodeShow(Node node, Set completeNodeSet, + Set continueNodeSet, String processInstanceId, Map paramMap) { + List list = new ArrayList<>(); - if (!NodeUtil.isNode(node)) { - return list; - } + if (!NodeUtil.isNode(node)) { + return list; + } - String name = node.getName(); - Integer type = node.getType(); + String name = node.getName(); + Integer type = node.getType(); - // SELF_SELECT + // SELF_SELECT - NodeVo nodeVo = new NodeVo(); - nodeVo.setId(node.getId()); - nodeVo.setName(name); - nodeVo.setType(type); - nodeVo.setStatus(NodeStatusEnum.WKS.getCode()); - if (completeNodeSet.contains(node.getId())) { - nodeVo.setStatus(NodeStatusEnum.YJS.getCode()); + NodeVo nodeVo = new NodeVo(); + nodeVo.setId(node.getId()); + nodeVo.setName(name); + nodeVo.setType(type); + nodeVo.setStatus(NodeStatusEnum.WKS.getCode()); + if (completeNodeSet.contains(node.getId())) { + nodeVo.setStatus(NodeStatusEnum.YJS.getCode()); - } - if (continueNodeSet.contains(node.getId())) { - nodeVo.setStatus(NodeStatusEnum.JXZ.getCode()); + } + if (continueNodeSet.contains(node.getId())) { + nodeVo.setStatus(NodeStatusEnum.JXZ.getCode()); - } + } - { + { + nodeVo.setPlaceholder(node.getPlaceHolder()); + } - nodeVo.setPlaceholder(node.getPlaceHolder()); + List userVoList = new ArrayList<>(); + if (type == NodeTypeEnum.APPROVAL.getValue().intValue()) { - } + Integer assignedType = node.getAssignedType(); - List userVoList = new ArrayList<>(); - if (type == NodeTypeEnum.APPROVAL.getValue().intValue()) { + boolean selfSelect = assignedType == ProcessInstanceConstant.AssignedTypeClass.SELF_SELECT; + nodeVo.setSelectUser(selfSelect); + if (selfSelect) { + nodeVo.setMultiple(node.getMultiple()); + } - Integer assignedType = node.getAssignedType(); + // 用户列表 + if (StrUtil.isNotBlank(processInstanceId)) { + IProcessNodeRecordAssignUserService processNodeRecordAssignUserService = SpringUtil + .getBean(IProcessNodeRecordAssignUserService.class); + List processNodeRecordAssignUserList = processNodeRecordAssignUserService + .lambdaQuery() + .eq(ProcessNodeRecordAssignUser::getNodeId, node.getId()) + .eq(ProcessNodeRecordAssignUser::getProcessInstanceId, processInstanceId) + .orderByAsc(ProcessNodeRecordAssignUser::getCreateTime) + .list(); + Map> map = processNodeRecordAssignUserList.stream() + .collect(Collectors.groupingBy(ProcessNodeRecordAssignUser::getTaskId)); - boolean selfSelect = assignedType == ProcessInstanceConstant.AssignedTypeClass.SELF_SELECT; - nodeVo.setSelectUser(selfSelect); - if (selfSelect) { - nodeVo.setMultiple(node.getMultiple()); - } + for (Map.Entry> entry : map.entrySet()) { + List value = entry.getValue(); + List collect = value.stream().map(w -> { + UserVo userVo = buildUser(Long.parseLong(w.getUserId())); + userVo.setShowTime(w.getEndTime()); + userVo.setApproveDesc(w.getApproveDesc()); + userVo.setStatus(w.getStatus()); + userVo.setOperType(w.getTaskType()); + return userVo; + }).collect(Collectors.toList()); + userVoList.addAll(collect); + } - // 用户列表 - if (StrUtil.isNotBlank(processInstanceId)) { - IProcessNodeRecordAssignUserService processNodeRecordAssignUserService = SpringUtil - .getBean(IProcessNodeRecordAssignUserService.class); - List processNodeRecordAssignUserList = processNodeRecordAssignUserService - .lambdaQuery().eq(ProcessNodeRecordAssignUser::getNodeId, node.getId()) - .eq(ProcessNodeRecordAssignUser::getProcessInstanceId, processInstanceId) - .orderByAsc(ProcessNodeRecordAssignUser::getCreateTime).list(); - Map> map = processNodeRecordAssignUserList.stream() - .collect(Collectors.groupingBy(ProcessNodeRecordAssignUser::getTaskId)); + if (processNodeRecordAssignUserList.isEmpty()) { + if (assignedType == ProcessInstanceConstant.AssignedTypeClass.SELF) { + // 发起人自己 + userVoList.addAll(CollUtil.newArrayList(buildRootUser(processInstanceId))); + } + if (assignedType == ProcessInstanceConstant.AssignedTypeClass.SELF_SELECT) { + // 发起人自选 + Object variable = paramMap.get(StrUtil.format("{}_assignee_select", node.getId())); - for (Map.Entry> entry : map.entrySet()) { - List value = entry.getValue(); - List collect = value.stream().map(w -> { - UserVo userVo = buildUser(Long.parseLong(w.getUserId())); - userVo.setShowTime(w.getEndTime()); - userVo.setApproveDesc(w.getApproveDesc()); - userVo.setStatus(w.getStatus()); - userVo.setOperType(w.getTaskType()); - return userVo; - }).collect(Collectors.toList()); - userVoList.addAll(collect); - } + ObjectMapper objectMapper = SpringUtil.getBean(ObjectMapper.class); + List nodeUserDtos = objectMapper.readValue(objectMapper.writeValueAsString(variable), + new TypeReference>() { + }); - if (processNodeRecordAssignUserList.isEmpty()) { - if (assignedType == ProcessInstanceConstant.AssignedTypeClass.SELF) { - // 发起人自己 - userVoList.addAll(CollUtil.newArrayList(buildRootUser(processInstanceId))); - } - if (assignedType == ProcessInstanceConstant.AssignedTypeClass.SELF_SELECT) { - // 发起人自选 - Object variable = paramMap.get(StrUtil.format("{}_assignee_select", node.getId())); + if (CollUtil.isNotEmpty(nodeUserDtos)) { + List collect = nodeUserDtos.stream().map(w -> Long.valueOf(w.getId())) + .collect(Collectors.toList()); + for (Long aLong : collect) { + UserVo userVo = buildUser(aLong); + userVoList.addAll(CollUtil.newArrayList(userVo)); + } + } - ObjectMapper objectMapper = SpringUtil.getBean(ObjectMapper.class); - List nodeUserDtos = objectMapper.readValue(objectMapper.writeValueAsString(variable), - new TypeReference>() { - }); + } + } - List collect = nodeUserDtos.stream().map(w -> Long.valueOf(w.getId())) - .collect(Collectors.toList()); - for (Long aLong : collect) { - UserVo userVo = buildUser(aLong); - userVoList.addAll(CollUtil.newArrayList(userVo)); - } - } - } + } else if (assignedType == ProcessInstanceConstant.AssignedTypeClass.USER) { + // 指定用户 - } - else if (assignedType == ProcessInstanceConstant.AssignedTypeClass.USER) { - // 指定用户 + List nodeUserList = node.getNodeUserList(); + List tempList = buildUser(nodeUserList); + userVoList.addAll(tempList); - List nodeUserList = node.getNodeUserList(); - List tempList = buildUser(nodeUserList); - userVoList.addAll(tempList); + } else if (assignedType == ProcessInstanceConstant.AssignedTypeClass.FORM_USER) { + // 表单人员 + String formUser = node.getFormUserId(); - } - else if (assignedType == ProcessInstanceConstant.AssignedTypeClass.FORM_USER) { - // 表单人员 - String formUser = node.getFormUserId(); + Object o = paramMap.get(formUser); + if (o != null) { + ObjectMapper objectMapper = SpringUtil.getBean(ObjectMapper.class); + String jsonString = objectMapper.writeValueAsString(o); + if (StrUtil.isNotBlank(jsonString)) { + List nodeUserDtoList = objectMapper.readValue(jsonString, new TypeReference>() { + }); + List userIdList = nodeUserDtoList.stream().map(NodeUser::getId).collect(Collectors.toList()); + for (Long aLong : userIdList) { + userVoList.addAll(CollUtil.newArrayList(buildUser(aLong))); + } + } + } - Object o = paramMap.get(formUser); - if (o != null) { - ObjectMapper objectMapper = SpringUtil.getBean(ObjectMapper.class); - String jsonString = objectMapper.writeValueAsString(o); - if (StrUtil.isNotBlank(jsonString)) { - List nodeUserDtoList = objectMapper.readValue(jsonString, - new TypeReference>() { - }); - List userIdList = nodeUserDtoList.stream().map(NodeUser::getId) - .collect(Collectors.toList()); - for (Long aLong : userIdList) { - userVoList.addAll(CollUtil.newArrayList(buildUser(aLong))); - } - } - } + } else if (assignedType == ProcessInstanceConstant.AssignedTypeClass.SELF) { + // 发起人自己 + userVoList.addAll(CollUtil.newArrayList(buildUser(SecurityUtils.getUser().getId()))); + } - } - else if (assignedType == ProcessInstanceConstant.AssignedTypeClass.SELF) { - // 发起人自己 - userVoList.addAll(CollUtil.newArrayList(buildUser(SecurityUtils.getUser().getId()))); - } + } else if (Objects.equals(node.getType(), NodeTypeEnum.ROOT.getValue())) { + // 发起节点 + if (StrUtil.isBlank(processInstanceId)) { + UserVo userVo = buildUser(SecurityUtils.getUser().getId()); + userVoList.addAll(CollUtil.newArrayList(userVo)); + } else { - } - else if (Objects.equals(node.getType(), NodeTypeEnum.ROOT.getValue())) { - // 发起节点 - if (StrUtil.isBlank(processInstanceId)) { - UserVo userVo = buildUser(SecurityUtils.getUser().getId()); - userVoList.addAll(CollUtil.newArrayList(userVo)); - } - else { + IProcessInstanceRecordService processInstanceRecordService = SpringUtil + .getBean(IProcessInstanceRecordService.class); + ProcessInstanceRecord processInstanceRecord = processInstanceRecordService.lambdaQuery() + .eq(ProcessInstanceRecord::getProcessInstanceId, processInstanceId) + .one(); - IProcessInstanceRecordService processInstanceRecordService = SpringUtil - .getBean(IProcessInstanceRecordService.class); - ProcessInstanceRecord processInstanceRecord = processInstanceRecordService.lambdaQuery() - .eq(ProcessInstanceRecord::getProcessInstanceId, processInstanceId).one(); + UserVo userVo = buildRootUser(processInstanceId); + userVo.setShowTime(processInstanceRecord.getCreateTime()); + userVo.setStatus(NodeStatusEnum.YJS.getCode()); + userVoList.addAll(CollUtil.newArrayList(userVo)); - UserVo userVo = buildRootUser(processInstanceId); - userVo.setShowTime(processInstanceRecord.getCreateTime()); - userVo.setStatus(NodeStatusEnum.YJS.getCode()); - userVoList.addAll(CollUtil.newArrayList(userVo)); + } + } else if (node.getType() == NodeTypeEnum.CC.getValue()) { + // 抄送节点 - } - } - else if (node.getType() == NodeTypeEnum.CC.getValue()) { - // 抄送节点 + List nodeUserList = node.getNodeUserList(); - List nodeUserList = node.getNodeUserList(); + List tempList = buildUser(nodeUserList); + userVoList.addAll(tempList); - List tempList = buildUser(nodeUserList); - userVoList.addAll(tempList); + } + nodeVo.setUserVoList(userVoList); - } - nodeVo.setUserVoList(userVoList); + List branchList = new ArrayList<>(); - List branchList = new ArrayList<>(); + if (type == NodeTypeEnum.EXCLUSIVE_GATEWAY.getValue().intValue() + || type == NodeTypeEnum.PARALLEL_GATEWAY.getValue().intValue()) { + // 条件分支 + List branchs = node.getConditionNodes(); - if (type == NodeTypeEnum.EXCLUSIVE_GATEWAY.getValue().intValue() - || type == NodeTypeEnum.PARALLEL_GATEWAY.getValue().intValue()) { - // 条件分支 - List branchs = node.getConditionNodes(); + for (Node branch : branchs) { + Node children = branch.getChildren(); + List processNodeShowDtos = formatProcessNodeShow(children, completeNodeSet, continueNodeSet, + processInstanceId, paramMap); - for (Node branch : branchs) { - Node children = branch.getChildren(); - List processNodeShowDtos = formatProcessNodeShow(children, completeNodeSet, continueNodeSet, - processInstanceId, paramMap); + NodeVo p = new NodeVo(); + p.setChildren(processNodeShowDtos); - NodeVo p = new NodeVo(); - p.setChildren(processNodeShowDtos); + p.setPlaceholder(branch.getPlaceHolder()); + branchList.add(p); + } + } + nodeVo.setBranch(branchList); - p.setPlaceholder(branch.getPlaceHolder()); - branchList.add(p); - } - } - nodeVo.setBranch(branchList); + list.add(nodeVo); - list.add(nodeVo); + List next = formatProcessNodeShow(node.getChildren(), completeNodeSet, continueNodeSet, + processInstanceId, paramMap); + list.addAll(next); - List next = formatProcessNodeShow(node.getChildren(), completeNodeSet, continueNodeSet, - processInstanceId, paramMap); - list.addAll(next); + return list; + } - return list; - } + /** + * 根据实例id + * + * @param processInstanceId + * @return + */ + private static UserVo buildRootUser(String processInstanceId) { - /** - * 根据实例id - * @param processInstanceId - * @return - */ - private static UserVo buildRootUser(String processInstanceId) { + IProcessInstanceRecordService processInstanceRecordService = SpringUtil + .getBean(IProcessInstanceRecordService.class); + ProcessInstanceRecord processInstanceRecord = processInstanceRecordService.lambdaQuery() + .eq(ProcessInstanceRecord::getProcessInstanceId, processInstanceId) + .one(); + Long userId = processInstanceRecord.getUserId(); + UserVo userVo = buildUser(userId); + return userVo; + } - IProcessInstanceRecordService processInstanceRecordService = SpringUtil - .getBean(IProcessInstanceRecordService.class); - ProcessInstanceRecord processInstanceRecord = processInstanceRecordService.lambdaQuery() - .eq(ProcessInstanceRecord::getProcessInstanceId, processInstanceId).one(); - Long userId = processInstanceRecord.getUserId(); - UserVo userVo = buildUser(userId); - return userVo; - } + /** + * 根据用户id + * + * @param userId + * @return + */ + private static UserVo buildUser(long userId) { + if (ProcessInstanceConstant.DEFAULT_EMPTY_ASSIGN == userId) { + return UserVo.builder().id(userId).build(); + } - /** - * 根据用户id - * @param userId - * @return - */ - private static UserVo buildUser(long userId) { - if (ProcessInstanceConstant.DEFAULT_EMPTY_ASSIGN == userId){ - return UserVo.builder().id(userId).build(); - } + RemoteUserService userService = SpringUtil.getBean(RemoteUserService.class); + SysUser user = userService.getUserById(userId).getData(); + if (user == null) { + return null; + } - RemoteUserService userService = SpringUtil.getBean(RemoteUserService.class); - SysUser user = userService.getUserById(userId).getData(); - if (user == null) { - return null; - } + return UserVo.builder().id(userId).name(user.getName()).avatar(user.getAvatar()).build(); + } - return UserVo.builder().id(userId).name(user.getName()).avatar(user.getAvatar()).build(); - } + private static List buildUser(List nodeUserList) { + List userVoList = new ArrayList<>(); + // 用户id + List userIdList = nodeUserList.stream() + .filter(w -> StrUtil.equals(w.getType(), NodeUserTypeEnum.USER.getKey())) + .map(w -> Convert.toLong(w.getId())) + .collect(Collectors.toList()); + // 部门id + List deptIdList = nodeUserList.stream() + .filter(w -> StrUtil.equals(w.getType(), NodeUserTypeEnum.DEPT.getKey())) + .map(w -> Convert.toLong(w.getId())) + .collect(Collectors.toList()); - private static List buildUser(List nodeUserList) { - List userVoList = new ArrayList<>(); - // 用户id - List userIdList = nodeUserList.stream() - .filter(w -> StrUtil.equals(w.getType(), NodeUserTypeEnum.USER.getKey())) - .map(w -> Convert.toLong(w.getId())).collect(Collectors.toList()); - // 部门id - List deptIdList = nodeUserList.stream() - .filter(w -> StrUtil.equals(w.getType(), NodeUserTypeEnum.DEPT.getKey())) - .map(w -> Convert.toLong(w.getId())).collect(Collectors.toList()); + if (CollUtil.isNotEmpty(deptIdList)) { - if (CollUtil.isNotEmpty(deptIdList)) { + IRemoteService iRemoteService = SpringUtil.getBean(IRemoteService.class); - IRemoteService iRemoteService = SpringUtil.getBean(IRemoteService.class); + List data = iRemoteService.queryUserIdListByDepIdList(deptIdList).getData(); - List data = iRemoteService.queryUserIdListByDepIdList(deptIdList).getData(); - - if (CollUtil.isNotEmpty(data)) { - for (long datum : data) { - if (!userIdList.contains(datum)) { - userIdList.add(datum); - } - } - } - } - { - for (Long aLong : userIdList) { - userVoList.addAll(CollUtil.newArrayList(buildUser(aLong))); - } - } - return userVoList; - } + if (CollUtil.isNotEmpty(data)) { + for (long datum : data) { + if (!userIdList.contains(datum)) { + userIdList.add(datum); + } + } + } + } + { + for (Long aLong : userIdList) { + userVoList.addAll(CollUtil.newArrayList(buildUser(aLong))); + } + } + return userVoList; + } }