Browse Source

待办中心待我处理处理功能

master
CMM 1 year ago
parent
commit
4047abc7d3
9 changed files with 815 additions and 22 deletions
  1. +27
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/common/model/FileBasicInfo.java
  2. +62
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/bean/entity/ProcessTask.java
  3. +69
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/bean/vo/ProcessProgressVo.java
  4. +27
    -5
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/controller/TodoCenterController.java
  5. +188
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/extension/cmd/BackToHisApprovalNodeCmd.java
  6. +358
    -14
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java
  7. +82
    -0
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/dto/req/ReqProcessHandlerDTO.java
  8. +2
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/dto/res/ResToBeProcessedDTO.java
  9. +0
    -2
      pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/dto/res/ResToBeProjectListExportDTO.java

+ 27
- 0
pmapi/src/main/java/com/ningdatech/pmapi/common/model/FileBasicInfo.java View File

@@ -0,0 +1,27 @@
package com.ningdatech.pmapi.common.model;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

/**
* @author liuxinxin
* @date 2022/7/25 下午1:55
* 用于包装使用
*/
@Data
@ApiModel("文件信息基类")
public class FileBasicInfo {

@ApiModelProperty("文件id")
private Long fileId;

@ApiModelProperty("文件名")
private String fileName;

@ApiModelProperty("文件类型")
private Integer fileType;

@ApiModelProperty("文件路径")
private String filePath;
}

+ 62
- 0
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/bean/entity/ProcessTask.java View File

@@ -0,0 +1,62 @@
package com.ningdatech.pmapi.todocenter.bean.entity;

import com.wflow.workflow.bean.process.OrgUser;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
* 流程任务实体
*
* @author CMM
* @since 2023/01/30 16:57
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ProcessTask {
//任务ID
private String taskId;
//任务定义key
private String taskDefKey;
//流程定义ID
private String processDefId;
//流程执行ID
private String executionId;
//任务名称
private String taskName;
//任务归属节点
private String nodeId;

//任务处理结果
private String taskResult;

//部署ID
private String deployId;
//流程定义名称
private String processDefName;
//版本
private Integer version;
//实例ID
private String instanceId;


//流程发起人
private String ownerId;
private OrgUser owner;
//流程发起人部门ID
private String ownerDeptId;
//流程发起人部门名称
private String ownerDeptName;

//流程实例创建时间
private Date createTime;
//task创建时间
private Date taskCreateTime;
//task完成时间
private Date taskEndTime;
}

+ 69
- 0
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/bean/vo/ProcessProgressVo.java View File

@@ -0,0 +1,69 @@
package com.ningdatech.pmapi.todocenter.bean.vo;

import com.wflow.workflow.bean.process.OrgUser;
import com.wflow.workflow.bean.process.form.Form;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* 流程进展详情实体
*
* @author CMM
* @since 2023/01/30 17:21
*/
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class ProcessProgressVo {
/**
* 审批实例ID
*/
private String instanceId;
/**
* 表单配置项
*/
private List<Form> formItems;
/**
* 表单值
*/
private Map<String, Object> formData;
/**
* 流程进度步骤
*/
private List<ProgressNode> progress;
/**
* 流程定义名称
*/
private String processDefName;
/**
* 版本
*/
private Integer version;
/**
* 流程状态
*/
private String status;
/**
* 流程结果
*/
private String result;
/**
* 发起人
*/
private OrgUser staterUser;
/**
* 发起人部门
*/
private String starterDept;
/**
* 发起时间
*/
private Date startTime;
}

+ 27
- 5
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/controller/TodoCenterController.java View File

@@ -5,10 +5,10 @@ import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import com.ningdatech.pmapi.common.util.ExcelDownUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ningdatech.pmapi.todocenter.model.dto.req.ReqProcessHandlerDTO;
import com.wflow.utils.R;
import com.wflow.workflow.bean.vo.ProcessHandlerParamsVo;
import org.springframework.web.bind.annotation.*;

import com.ningdatech.basic.model.ApiResponse;
import com.ningdatech.basic.model.PageVo;
@@ -40,7 +40,7 @@ public class TodoCenterController {
* @param param
* @return
*/
@GetMapping("/NotAppendProjectList")
@GetMapping("/query-project-list")
public ApiResponse<PageVo<ResToBeProcessedDTO>> queryProjectList(@Valid @ModelAttribute ReqToBeProcessedDTO param){
PageVo<ResToBeProcessedDTO> result = todoCenterManage.queryProjectList(param);
return ApiResponse.ofSuccess(result);
@@ -58,4 +58,26 @@ public class TodoCenterController {
ExcelDownUtil.downXlsx(response,param,todoCenterManage::exportProjectList);
}

/**
* 查询流程表单数据及审批的进度步骤
* @param instanceId 流程实例ID
* @param nodeId 当前获取流程人员关联的流程节点ID
* @return 流程进度及表单详情
*/
@GetMapping("progress/{instanceId}/{nodeId}")
public ApiResponse<Object> getProcessDetail(@PathVariable String instanceId,
@PathVariable(required = false) String nodeId) {
return ApiResponse.ofSuccess(todoCenterManage.getProcessDetail(nodeId, instanceId));
}

/**
* 审核通过,盖章并通过、退回、撤回、驳回等操作
* @param param 操作参数
* @return 操作结果
*/
@PostMapping("/handler")
public ApiResponse<Object> handler(@Valid @RequestBody ReqProcessHandlerDTO param) {
todoCenterManage.handler(param);
return ApiResponse.ofSuccess();
}
}

+ 188
- 0
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/extension/cmd/BackToHisApprovalNodeCmd.java View File

@@ -0,0 +1,188 @@
package com.ningdatech.pmapi.todocenter.extension.cmd;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;

import org.assertj.core.util.Sets;
import org.flowable.bpmn.model.FlowNode;
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.UserTask;
import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.impl.delegate.ActivityBehavior;
import org.flowable.engine.impl.persistence.entity.ExecutionEntity;
import org.flowable.engine.impl.persistence.entity.ExecutionEntityManager;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.impl.util.ExecutionGraphUtil;
import org.flowable.engine.impl.util.ProcessDefinitionUtil;
import org.flowable.task.api.Task;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;

import com.wflow.workflow.utils.FlowableUtils;

/**
* @author : willian fu
* @date : 2022/10/14
*/
public class BackToHisApprovalNodeCmd implements Command<String>, Serializable {

private static final long serialVersionUID = -80075781855060928L;

protected RuntimeService runtimeService;
protected String taskId;
protected String targetNodeId;

public BackToHisApprovalNodeCmd(RuntimeService runtimeService, String taskId, String targetNodeId) {
this.runtimeService = runtimeService;
this.taskId = taskId;
this.targetNodeId = targetNodeId;
}

@Override
public String execute(CommandContext commandContext) {
if (targetNodeId == null || targetNodeId.length() == 0) {
throw new FlowableException("退回的目标节点不能为空");
}
TaskEntity task = CommandContextUtil.getProcessEngineConfiguration().getTaskServiceConfiguration().getTaskService().getTask(taskId);
if (task == null) {
throw new FlowableObjectNotFoundException(taskId + " 任务不能为空", Task.class);
}
String sourceNodeId = task.getTaskDefinitionKey();
String processInstanceId = task.getProcessInstanceId();
String processDefinitionId = task.getProcessDefinitionId();
//获取流程定义
Process process = ProcessDefinitionUtil.getProcess(processDefinitionId);
FlowNode sourceFlowElement = (FlowNode) process.getFlowElement(sourceNodeId, true);
// 只支持从用户任务退回
if (!(sourceFlowElement instanceof UserTask)) {
throw new FlowableException("只能从审批节点进行回退");
}
FlowNode targetFlowElement = (FlowNode) process.getFlowElement(targetNodeId, true);
// 退回节点到当前节点不可达到,不允许退回
if (!ExecutionGraphUtil.isReachable(processDefinitionId, targetNodeId, sourceNodeId)) {
throw new FlowableException("无法回退到目标节点");
}
//目标节点如果相对当前节点是在子流程内部,则无法直接退回,目前处理是只能退回到子流程开始节点
String[] sourceAndTargetRealActivityId = FlowableUtils.getSourceAndTargetRealActivityId(sourceFlowElement, targetFlowElement);
// 实际应操作的当前节点ID
String sourceRealActivityId = sourceAndTargetRealActivityId[0];
// 实际应操作的目标节点ID
String targetRealActivityId = sourceAndTargetRealActivityId[1];

Map<String, Set<String>> specialGatewayNodes = FlowableUtils.getSpecialGatewayElements(process);
// 当前节点处在的并行网关list
List<String> sourceInSpecialGatewayList = new ArrayList<>();
// 目标节点处在的并行网关list
List<String> targetInSpecialGatewayList = new ArrayList<>();
setSpecialGatewayList(sourceRealActivityId, targetRealActivityId, specialGatewayNodes, sourceInSpecialGatewayList, targetInSpecialGatewayList);
// 实际应筛选的节点ID
Set<String> sourceRealAcitivtyIds = null;
// 若退回目标节点相对当前节点在并行网关中,则要找到相对当前节点最近的这个并行网关,后续做特殊处理
String targetRealSpecialGateway = null;

// 1.目标节点和当前节点都不在并行网关中
if (targetInSpecialGatewayList.isEmpty() && sourceInSpecialGatewayList.isEmpty()) {
sourceRealAcitivtyIds = Sets.newLinkedHashSet(sourceRealActivityId);
}
// 2.目标节点不在并行网关中、当前节点在并行网关中
else if (targetInSpecialGatewayList.isEmpty()) {
sourceRealAcitivtyIds = specialGatewayNodes.get(sourceInSpecialGatewayList.get(0));
}
// 3.目标节点在并行网关中、当前节点不在并行网关中
else if (sourceInSpecialGatewayList.isEmpty()) {
sourceRealAcitivtyIds = Sets.newLinkedHashSet(sourceRealActivityId);
targetRealSpecialGateway = targetInSpecialGatewayList.get(0);
}
// 4.目标节点和当前节点都在并行网关中
else {
int diffSpecialGatewayLevel = FlowableUtils.getDiffLevel(sourceInSpecialGatewayList, targetInSpecialGatewayList);
// 在并行网关同一层且在同一分支
if (diffSpecialGatewayLevel == -1) {
sourceRealAcitivtyIds = Sets.newLinkedHashSet(sourceRealActivityId);
} else {
// 当前节点最内层并行网关不被目标节点最内层并行网关包含
// 或理解为当前节点相对目标节点在并行网关外
// 只筛选当前节点的execution
if (sourceInSpecialGatewayList.size() == diffSpecialGatewayLevel) {
sourceRealAcitivtyIds = Sets.newLinkedHashSet(sourceRealActivityId);
}
// 当前节点相对目标节点在并行网关内,应筛选相对目标节点最近的并行网关的所有节点的execution
else {
sourceRealAcitivtyIds = specialGatewayNodes.get(sourceInSpecialGatewayList.get(diffSpecialGatewayLevel));
}
// 目标节点最内层并行网关包含当前节点最内层并行网关
// 或理解为目标节点相对当前节点在并行网关外
// 不做处理
if (targetInSpecialGatewayList.size() == diffSpecialGatewayLevel) {
}
// 目标节点相对当前节点在并行网关内
else {
targetRealSpecialGateway = targetInSpecialGatewayList.get(diffSpecialGatewayLevel);
}
}
}

// 筛选需要处理的execution
List<ExecutionEntity> realExecutions = this.getRealExecutions(commandContext, processInstanceId,
task.getExecutionId(), sourceRealActivityId, sourceRealAcitivtyIds);
// 执行退回,直接跳转到实际的 targetRealActivityId
List<String> realExecutionIds = realExecutions.stream().map(ExecutionEntity::getId).collect(Collectors.toList());
runtimeService.createChangeActivityStateBuilder().processInstanceId(processInstanceId).moveExecutionsToSingleActivityId(realExecutionIds, targetRealActivityId).changeState();
// 目标节点相对当前节点处于并行网关内,需要特殊处理,需要手动生成并行网关汇聚节点(_end)的execution数据
if (targetRealSpecialGateway != null) {
createTargetInSpecialGatewayEndExecutions(commandContext, realExecutions, process, targetInSpecialGatewayList, targetRealSpecialGateway);
}
return targetRealActivityId;
}

private void setSpecialGatewayList(String sourceNodeId, String targetNodeId, Map<String, Set<String>> specialGatewayNodes,
List<String> sourceInSpecialGatewayList, List<String> targetInSpecialGatewayList) {
for (Map.Entry<String, Set<String>> entry : specialGatewayNodes.entrySet()) {
if (entry.getValue().contains(sourceNodeId)) {
sourceInSpecialGatewayList.add(entry.getKey());
}
if (entry.getValue().contains(targetNodeId)) {
targetInSpecialGatewayList.add(entry.getKey());
}
}
}

private void createTargetInSpecialGatewayEndExecutions(CommandContext commandContext, List<ExecutionEntity> excutionEntitys, Process process,
List<String> targetInSpecialGatewayList, String targetRealSpecialGateway) {
// 目标节点相对当前节点处于并行网关,需要手动生成并行网关汇聚节点(_end)的execution数据
String parentExecutionId = excutionEntitys.iterator().next().getParentId();
ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
ExecutionEntity parentExecutionEntity = executionEntityManager.findById(parentExecutionId);

int index = targetInSpecialGatewayList.indexOf(targetRealSpecialGateway);
for (; index < targetInSpecialGatewayList.size(); index++) {
String targetInSpecialGateway = targetInSpecialGatewayList.get(index);
FlowNode targetInSpecialGatewayEnd = (FlowNode) process.getFlowElement(targetInSpecialGateway + "_end", true);
int nbrOfExecutionsToJoin = targetInSpecialGatewayEnd.getIncomingFlows().size();
// 处理目标节点所处的分支以外的分支,即 总分枝数-1 = nbrOfExecutionsToJoin - 1
for (int i = 0; i < nbrOfExecutionsToJoin - 1; i++) {
ExecutionEntity childExecution = executionEntityManager.createChildExecution(parentExecutionEntity);
childExecution.setCurrentFlowElement(targetInSpecialGatewayEnd);
ActivityBehavior activityBehavior = (ActivityBehavior) targetInSpecialGatewayEnd.getBehavior();
activityBehavior.execute(childExecution);
}
}
}

private List<ExecutionEntity> getRealExecutions(CommandContext commandContext, String processInstanceId,
String taskExecutionId, String sourceRealActivityId, Set<String> activityIds) {
ExecutionEntityManager executionEntityManager = CommandContextUtil.getExecutionEntityManager(commandContext);
ExecutionEntity taskExecution = executionEntityManager.findById(taskExecutionId);
List<ExecutionEntity> executions = executionEntityManager.findChildExecutionsByProcessInstanceId(processInstanceId);
Set<String> parentExecutionIds = FlowableUtils.getParentExecutionIdsByActivityId(executions, sourceRealActivityId);
String realParentExecutionId = FlowableUtils.getParentExecutionIdFromParentIds(taskExecution, parentExecutionIds);
return executionEntityManager.findExecutionsByParentExecutionAndActivityIds(realParentExecutionId, activityIds);
}
}

+ 358
- 14
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/manage/TodoCenterManage.java View File

@@ -1,28 +1,55 @@
package com.ningdatech.pmapi.todocenter.manage;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.excel.EasyExcel;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ningdatech.basic.exception.BizException;
import com.ningdatech.basic.util.NdDateUtils;
import com.ningdatech.pmapi.common.constant.ProjectDeclareConstants;
import com.ningdatech.pmapi.common.util.ExcelDownUtil;
import com.ningdatech.pmapi.common.util.ExcelExportStyle;
import com.ningdatech.pmapi.todocenter.bean.entity.ProcessTask;
import com.ningdatech.pmapi.todocenter.enums.ProcessStatusEnum;
import com.ningdatech.pmapi.todocenter.extension.cmd.BackToHisApprovalNodeCmd;
import com.ningdatech.pmapi.todocenter.model.dto.req.ReqProcessHandlerDTO;
import com.ningdatech.pmapi.todocenter.model.dto.res.ResToBeProjectListExportDTO;
import com.ningdatech.pmapi.user.util.LoginUserUtil;
import com.wflow.bean.do_.UserDo;
import com.wflow.bean.entity.WflowCcTasks;
import com.wflow.bean.entity.WflowModelHistorys;
import com.wflow.mapper.WflowCcTasksMapper;
import com.wflow.mapper.WflowModelHistorysMapper;
import com.wflow.service.OrgRepositoryService;
import com.wflow.workflow.bean.dto.ProcessInstanceOwnerDto;
import com.wflow.workflow.bean.process.OrgUser;
import com.wflow.workflow.bean.process.ProcessNode;
import com.wflow.workflow.bean.process.enums.ApprovalModeEnum;
import com.wflow.workflow.bean.process.enums.NodeTypeEnum;
import com.wflow.workflow.bean.process.form.Form;
import com.wflow.workflow.bean.process.props.ApprovalProps;
import com.wflow.workflow.bean.vo.ProcessHandlerParamsVo;
import com.wflow.workflow.bean.vo.ProcessProgressVo;
import com.wflow.workflow.bean.vo.ProcessTaskVo;
import com.wflow.workflow.service.ProcessInstanceService;
import com.wflow.workflow.service.UserDeptOrLeaderService;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import com.wflow.workflow.bean.vo.TaskCommentVo;
import com.wflow.workflow.config.WflowGlobalVarDef;
import com.wflow.workflow.service.*;
import com.wflow.workflow.service.FormService;
import lombok.extern.slf4j.Slf4j;
import org.assertj.core.util.Lists;
import org.assertj.core.util.Maps;
import org.flowable.common.engine.impl.identity.Authentication;
import org.flowable.engine.*;
import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.history.HistoricProcessInstance;
import org.flowable.engine.repository.ProcessDefinition;
import org.flowable.engine.runtime.Execution;
import org.flowable.engine.runtime.ProcessInstance;
import org.flowable.task.api.Task;
import org.flowable.task.api.TaskQuery;

import org.flowable.variable.api.history.HistoricVariableInstance;
import org.springframework.stereotype.Component;
import com.ningdatech.basic.model.PageVo;

@@ -33,10 +60,8 @@ import lombok.RequiredArgsConstructor;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;

/**
@@ -45,6 +70,7 @@ import java.util.stream.Collectors;
*/
@Component
@RequiredArgsConstructor
@Slf4j
public class TodoCenterManage {

private final TaskService taskService;
@@ -52,6 +78,14 @@ public class TodoCenterManage {
private final RuntimeService runtimeService;
private final UserDeptOrLeaderService userDeptOrLeaderService;
private final ProcessInstanceService processService;
private final FormService formService;
private final ManagementService managementService;
private final HistoryService historyService;
private final WflowModelHistorysMapper modelHistorysMapper;
private final ProcessNodeCatchService nodeCatchService;
private final OrgRepositoryService orgRepositoryService;
private final ProcessTaskService processTaskService;
private final WflowCcTasksMapper ccTasksMapper;
public PageVo<ResToBeProcessedDTO> queryProjectList(ReqToBeProcessedDTO param) {
// 获取登录用户ID
Long userId = LoginUserUtil.getUserId();
@@ -82,7 +116,7 @@ public class TodoCenterManage {
ProcessInstanceOwnerDto owner = runtimeService.getVariable(task.getExecutionId(), "owner", ProcessInstanceOwnerDto.class);
ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
staterUsers.add(owner.getOwner());
ProcessTaskVo processTaskVo = ProcessTaskVo.builder()
ProcessTask processTask = ProcessTask.builder()
.taskId(task.getId())
.taskName(task.getName())
.taskDefKey(task.getTaskDefinitionKey())
@@ -99,7 +133,7 @@ public class TodoCenterManage {
.createTime(processInstance.getStartTime())
.taskCreateTime(task.getCreateTime())
.build();
res.setProcessTaskVo(processTaskVo);
res.setProcessTaskInfo(processTask);
String projectName = (String) formData.get(ProjectDeclareConstants.BasicInformation.PROJECT_NAME);
res.setProjectName(projectName);
res.setReportUnitId(owner.getOwnerDeptId());
@@ -121,12 +155,11 @@ public class TodoCenterManage {
//取用户信息,减少数据库查询,一次构建
if (CollectionUtil.isNotEmpty(staterUsers)) {
Map<String, OrgUser> userMap = userDeptOrLeaderService.getUserMapByIds(staterUsers);
page.setRecords(result.stream().peek(v -> v.getProcessTaskVo().setOwner(userMap.get(v.getProcessTaskVo().getOwnerId()))).collect(Collectors.toList()));
page.setRecords(result.stream().peek(v -> v.getProcessTaskInfo().setOwner(userMap.get(v.getProcessTaskInfo().getOwnerId()))).collect(Collectors.toList()));
}
return PageVo.of(resVos,page.getTotal());
}


public void exportProjectList(HttpServletResponse response, ReqToBeProcessedDTO param) {
PageVo<ResToBeProcessedDTO> page =
queryProjectList(param);
@@ -149,4 +182,315 @@ public class TodoCenterManage {
throw new RuntimeException(e);
}
}

public void handler(ReqProcessHandlerDTO param) {
Long userId = LoginUserUtil.getUserId();
Task task = taskService.createTaskQuery().taskId(param.getTaskId()).active().singleResult();
HashMap<String, Object> formData = new HashMap<>(32);
String format = NdDateUtils.format(LocalDateTime.now(), "yyyy-MM-dd HH:mm");
LocalDateTime auditTime = LocalDateTime.parse(format);
if (Objects.isNull(task)) {
throw new BizException("任务不存在");
}
switch (param.getAction()) {
// 通过
case pass:
formData.put("audit_pass_opinion",param.getAuditApprovalOpinion());
formData.put("audit_pass_appendix",param.getAuditApprovalAppendix());
formData.put("audit_pass_time", auditTime);
formService.updateInstanceFormData(param.getInstanceId(), formData);
doPass(task, param);
// 盖章并通过
case seal_pass:
formData.put("seal_pass_opinion",param.getSealApprovalOpinion());
formData.put("seal_pass_appendix",param.getSealApprovalAppendix());
Date sealPassTime = NdDateUtils.localDateTime2Date(LocalDateTime.now());
formData.put("seal_pass_time",sealPassTime);
formService.updateInstanceFormData(param.getInstanceId(), formData);
doSealPass(task, param);
// 驳回
case reject:
formData.put("audit_reject_opinion",param.getAuditRejectOpinion());
formData.put("audit_reject_appendix",param.getAuditRejectAppendix());
formData.put("audit_reject_time", auditTime);
formService.updateInstanceFormData(param.getInstanceId(), formData);
doReject(task, param);
break;
// 退回
case back:
formData.put("audit_back_opinion",param.getAuditBackOpinion());
formData.put("audit_back_appendix",param.getAuditBackAppendix());
formData.put("audit_back_time", auditTime);
formService.updateInstanceFormData(param.getInstanceId(), formData);
doBackTask(task.getTaskDefinitionKey(), userId, param);
break;
// 撤回
case withdraw:
doWithDrawProcess(task);
break;
default:
throw new IllegalStateException("Unexpected value: " + param.getAction());
}
Authentication.setAuthenticatedUserId(null);
}

/**
* 审批任务:驳回
*
* @param task 当前任务
* @param param 参数
*/
private void doReject(Task task, ReqProcessHandlerDTO param) {
Map<String, Object> var = new HashMap<>(16);
var.put("reject_" + task.getId(), param.getAction());
// TODO 中止流程并使项目进入对应状态
// TODO 给项目创建人、流程发起人发送浙政钉工作通知:【项目名称】的【流程名称】被驳回,请及时处理。
taskService.complete(param.getTaskId(), var);
}

/**
* 审批任务:盖章并通过
*
* @param task 当前任务
* @param param 参数
*/
private void doSealPass(Task task, ReqProcessHandlerDTO param) {
Map<String, Object> var = new HashMap<>(16);
var.put("seal_pass_" + task.getId(), param.getAction());
// TODO 判断项目申报单位级别,区县单位申报有上级主管单位意见栏,市级单位没有
// TODO 市级单位:为大数据局;区县单位:为大数据中心(根据附件区分?)
taskService.complete(param.getTaskId(), var);
}

/**
* 审批任务:通过
*
* @param task 当前任务
* @param param 参数
*/
private void doPass(Task task, ReqProcessHandlerDTO param) {
Map<String, Object> var = new HashMap<>(16);
var.put("pass_" + task.getId(), param.getAction());
// TODO 获取流程下一个节点的审核人

// TODO 若有下一个审核人,向其发送浙政钉工作通知:标题:审核任务 内容:【单位名称】的【项目名称】需要您审核。

// TODO 若没有,向发起人发送浙政钉工作通知:【项目名称】已通过【流程名称】,请及时开始下一步操作。
taskService.complete(param.getTaskId(), var);
}

/**
* 撤销流程处理
*
* @param task 当前任务
*/
private void doWithDrawProcess(Task task) {
// TODO 若是流程发起人点击撤回,项目回到上一个状态,并删除当前审核人对应的待办记录
// TODO 若是前一个审核人点击撤回,在审核记录中移除自己提交过的审核意见、待我处理中移除当前审核人的待办记录、待我处理中增加自己的待办记录、我已处理中去掉自己之前处理的记录
List<Execution> executions = runtimeService.createExecutionQuery()
.processInstanceId(task.getProcessInstanceId())
.onlyChildExecutions().list();
// 强制流程指向驳回
runtimeService.createChangeActivityStateBuilder()
.processInstanceId(task.getProcessInstanceId())
.moveActivityIdTo(task.getTaskDefinitionKey(), "cancel-end")
.moveExecutionsToSingleActivityId(executions.stream().map(Execution::getId)
.collect(Collectors.toList()), "cancel-end")
.changeState();
}

/**
* 退回流程处理
* @param current 当前流程定义key
* @param userId 当前登录用户ID
* @param param 参数
*/
private void doBackTask(String current, Long userId, ReqProcessHandlerDTO param) {
// TODO 流程变成【被退回】状态
// TODO 待我处理中,为流程发起人增加一条待办记录
// TODO 给项目创建人、流程发起人发送浙政钉工作通知:【项目名称】的【流程名称】被退回,请及时处理。
//执行自定义回退逻辑
managementService.executeCommand(new BackToHisApprovalNodeCmd(runtimeService, param.getTaskId(), param.getTargetNode()));
runtimeService.setVariables(param.getInstanceId(), Maps.newHashMap("back_" + param.getTaskId(), param.getAction()));
log.info("用户[{}] 退回流程[{}] [{} -> {}]", userId, param.getInstanceId(), current, param.getTargetNode());
}

/**
* 查询流程表单数据及审批的进度步骤
* @param instanceId 流程实例ID
* @param nodeId 当前获取流程人员关联的流程节点ID
* @return 流程进度及表单详情
*/
public Object getProcessDetail(String nodeId, String instanceId) {
HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery().processInstanceId(instanceId).singleResult();
// 取表单及表单数据
HistoricVariableInstance forms = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(instanceId).variableName(WflowGlobalVarDef.WFLOW_FORMS).singleResult();
List<HistoricVariableInstance> formDatas = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(instanceId).variableNameLike("field%").list();
// 取节点设置
HistoricVariableInstance nodeProps = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(instanceId).variableName(WflowGlobalVarDef.WFLOW_NODE_PROPS).singleResult();
Map<String, Object> nodePropsValue = (Map<String, Object>) nodeProps.getValue();

ProcessNode<?> currentNode = null;
if (StrUtil.isNotBlank(nodeId)) {
// 搜索当前版本流程的配置
WflowModelHistorys modelHistory = modelHistorysMapper.selectOne(new QueryWrapper<>(WflowModelHistorys.builder()
.processDefId(instance.getProcessDefinitionId()).version(instance.getProcessDefinitionVersion()).build()));
currentNode = nodeCatchService.reloadProcessByStr(modelHistory.getProcess()).get(nodeId);
}
UserDo users = orgRepositoryService.getUserById(instance.getStartUserId());
OrgUser startUser = OrgUser.builder().id(users.getUserId()).name(users.getUserName()).avatar(users.getAvatar()).build();
List<ProcessProgressVo.ProgressNode> taskRecords = getHisTaskRecords(instanceId, nodePropsValue);
taskRecords.addAll(getCcTaskRecords(instanceId));
if (ObjectUtil.isNull(instance.getEndTime())) {
taskRecords.addAll(processTaskService.getFutureTask(instanceId));
}
taskRecords = taskRecords.stream()
.sorted(Comparator.comparing(ProcessProgressVo.ProgressNode::getStartTime))
.collect(Collectors.toList());
taskRecords.add(0, ProcessProgressVo.ProgressNode.builder()
.nodeId("root")
.name("提交申请")
.user(startUser)
.nodeType(NodeTypeEnum.ROOT)
.startTime(instance.getStartTime())
.finishTime(instance.getStartTime())
.taskId("root")
.result(ProcessHandlerParamsVo.Action.agree)
.build());
// 提取全量表单数据
Map<String, Object> formData = formDatas.stream().collect(Collectors.toMap(HistoricVariableInstance::getVariableName, HistoricVariableInstance::getValue));
HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(instanceId).variableName("owner").singleResult();
ProcessInstanceOwnerDto owner = (ProcessInstanceOwnerDto) variableInstance.getValue();
return ProcessProgressVo.builder()
.instanceId(instanceId)
.version(instance.getProcessDefinitionVersion())
.formItems(formService.filterFormAndDataByPermConfig((List<Form>) forms.getValue(), formData, currentNode))
.formData(formData)
.processDefName(instance.getProcessDefinitionName())
.staterUser(startUser)
.starterDept(null == owner ? null : owner.getOwnerDeptName())
.status(ObjectUtil.isNull(instance.getEndActivityId()) ? "RUNNING" : "COMPLETE")
.result(instance.getEndActivityId())
.startTime(instance.getStartTime())
.progress(taskRecords)
.build();
}

/**
* 获取抄送的流程实例信息
*
* @param instanceId 实例ID
* @return 抄送我的流程
*/
private List<ProcessProgressVo.ProgressNode> getCcTaskRecords(String instanceId) {
Set<String> ccUsers = new HashSet<>();
List<ProcessProgressVo.ProgressNode> ccList = ccTasksMapper.selectList(new QueryWrapper<WflowCcTasks>()
.eq("instance_id", instanceId)).stream().map(task -> {
ccUsers.add(task.getUserId());
return ProcessProgressVo.ProgressNode.builder()
.nodeId(task.getNodeId())
.nodeType(NodeTypeEnum.CC)
.name(task.getNodeName())
.comment(Collections.emptyList())
.user(OrgUser.builder().id(task.getUserId()).build())
.startTime(task.getCreateTime())
.finishTime(task.getCreateTime())
.build();
}).collect(Collectors.toList());
if (CollectionUtil.isNotEmpty(ccUsers)) {
Map<String, OrgUser> userMap = userDeptOrLeaderService.getUserMapByIds(ccUsers);
ccList.stream().peek(v -> v.setUser(userMap.get(v.getUser().getId()))).collect(Collectors.toList());
}
return ccList;
}

/**
* 获取流程的审批历史记录
*
* @param instanceId 审批实例ID
* @param nodeProps 节点设置
* @return 历史记录列表
*/
private List<ProcessProgressVo.ProgressNode> getHisTaskRecords(String instanceId, Map<String, Object> nodeProps) {
List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery()
.processInstanceId(instanceId).orderByHistoricActivityInstanceStartTime().asc().list();
Set<String> userSet = new HashSet<>();
//获取节点处理结果
Map<String, ProcessHandlerParamsVo.Action> varMap = historyService.createHistoricVariableInstanceQuery()
.processInstanceId(instanceId).variableNameLike("approve_%").list().stream()
.collect(Collectors.toMap(HistoricVariableInstance::getVariableName, v -> (ProcessHandlerParamsVo.Action) v.getValue()));
Map<String, List<TaskCommentVo>> commentMap = new HashMap<>();
//统一处理所有评论数据,省的多次查询
List<TaskCommentVo> cmvos = taskService.getProcessInstanceComments(instanceId).stream().map(comment -> {
userSet.add(comment.getUserId());
TaskCommentVo commentVo = TaskCommentVo.builder()
.id(comment.getId())
.taskId(comment.getTaskId())
.commentType(comment.getType())
.type("COMMENT")
.createTime(comment.getTime())
.user(OrgUser.builder().id(comment.getUserId()).build())
.build();
ProcessHandlerParamsVo.ProcessComment processComment = JSONObject.parseObject(comment.getFullMessage(), ProcessHandlerParamsVo.ProcessComment.class);
commentVo.setText(processComment.getText());
commentVo.setAttachments(processComment.getAttachments());
return commentVo;
}).collect(Collectors.toList());
cmvos.forEach(cm -> {
//把评论数据按照task进行归类
String taskId = Optional.ofNullable(cm.getTaskId()).orElse(instanceId);
List<TaskCommentVo> vos = commentMap.computeIfAbsent(taskId, k -> new ArrayList<>());
vos.add(cm);
});
List<ProcessProgressVo.ProgressNode> progressNodes = list.stream().filter(his -> ObjectUtil.isNotNull(his.getTaskId())).map(his -> {
Object props = nodeProps.get(his.getActivityId());
ApprovalModeEnum approvalMode = null;
if (props instanceof ApprovalProps) {
approvalMode = ((ApprovalProps) props).getMode();
}
userSet.add(his.getAssignee());
List<TaskCommentVo> commentVos = commentMap.getOrDefault(his.getTaskId(), Collections.emptyList());
return ProcessProgressVo.ProgressNode.builder()
.nodeId(his.getActivityId())
.name(his.getActivityName())
.nodeType(NodeTypeEnum.APPROVAL)
.user(OrgUser.builder().id(his.getAssignee()).build())
.startTime(his.getStartTime())
.finishTime(his.getEndTime())
.taskId(his.getTaskId())
.approvalMode(approvalMode)
.comment(commentVos)
.result(varMap.get("approve_" + his.getTaskId()))
.build();
}).collect(Collectors.toList());
//将非任务类的评论转换成流程节点
progressNodes.addAll(commentMap.getOrDefault(instanceId, Collections.emptyList()).stream().map(cm ->
ProcessProgressVo.ProgressNode.builder()
.nodeId(cm.getId())
.name("参与评论")
.user(cm.getUser())
.startTime(cm.getCreateTime())
.finishTime(cm.getCreateTime())
.taskId(cm.getId())
.comment(Lists.list(cm))
.result(ProcessHandlerParamsVo.Action.comment)
.build()).collect(Collectors.toList()));
if (CollectionUtil.isNotEmpty(userSet)) {
Map<String, OrgUser> map = userDeptOrLeaderService.getUserMapByIds(userSet);
progressNodes.forEach(n -> {
if (WflowGlobalVarDef.WFLOW_TASK_AGRRE.equals(n.getUser().getId())
|| WflowGlobalVarDef.WFLOW_TASK_REFUSE.equals(n.getUser().getId())) {
n.setUser(WflowGlobalVarDef.SYS);
} else {
n.setUser(map.get(n.getUser().getId()));
n.getComment().forEach(c -> c.setUser(map.get(c.getUser().getId())));
}
});
}
return progressNodes;
}
}

+ 82
- 0
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/dto/req/ReqProcessHandlerDTO.java View File

@@ -0,0 +1,82 @@
package com.ningdatech.pmapi.todocenter.model.dto.req;
import com.ningdatech.pmapi.common.model.FileBasicInfo;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.time.LocalDateTime;

/**
* 流程处理操作参数实体
*
* @author CMM
* @since 2023/01/30 09:09
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ReqProcessHandlerDTO {

/**
* 实例ID
*/
private String instanceId;
/**
* 任务ID
*/
private String taskId;
/**
* 签名图片地址
*/
private String signature;
/**
* 操作类型
*/
private Action action;
/**
* 目标用户
*/
private String targetUser;
/**
* 目标节点
*/
private String targetNode;
/**
* 审核通过意见
*/
private String auditApprovalOpinion;

/**
* 审核通过附件
*/
private FileBasicInfo auditApprovalAppendix;
/**
* 盖章通过意见
*/
private String sealApprovalOpinion;

/**
* 盖章通过附件
*/
private FileBasicInfo sealApprovalAppendix;
/**
* 审核退回意见
*/
private String auditBackOpinion;
/**
* 审核退回附件
*/
private FileBasicInfo auditBackAppendix;
/**
* 审核驳回意见
*/
private String auditRejectOpinion;

/**
* 审核驳回附件
*/
private FileBasicInfo auditRejectAppendix;
public enum Action{
//通过、盖章并通过、退回、撤回、驳回
pass, seal_pass ,back, withdraw, reject;
}
}

+ 2
- 1
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/dto/res/ResToBeProcessedDTO.java View File

@@ -3,6 +3,7 @@ package com.ningdatech.pmapi.todocenter.model.dto.res;
import java.io.Serializable;
import java.time.LocalDateTime;

import com.ningdatech.pmapi.todocenter.bean.entity.ProcessTask;
import com.wflow.workflow.bean.vo.ProcessTaskVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
@@ -49,5 +50,5 @@ public class ResToBeProcessedDTO implements Serializable {
private LocalDateTime processLaunchTime;

@ApiModelProperty("流程任务信息")
private ProcessTaskVo processTaskVo;
private ProcessTask processTaskInfo;
}

+ 0
- 2
pmapi/src/main/java/com/ningdatech/pmapi/todocenter/model/dto/res/ResToBeProjectListExportDTO.java View File

@@ -1,8 +1,6 @@
package com.ningdatech.pmapi.todocenter.model.dto.res;

import com.alibaba.excel.annotation.ExcelProperty;
import com.wflow.workflow.bean.vo.ProcessTaskVo;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;


Loading…
Cancel
Save