|
|
@@ -3,7 +3,6 @@ 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; |
|
|
@@ -11,7 +10,9 @@ 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.bean.entity.ProgressNode; |
|
|
|
import com.ningdatech.pmapi.todocenter.bean.vo.ProcessProgressDetailVo; |
|
|
|
import com.ningdatech.pmapi.todocenter.constant.HisProInsEndActId; |
|
|
|
import com.ningdatech.pmapi.todocenter.enums.ProcessStatusEnum; |
|
|
|
import com.ningdatech.pmapi.todocenter.extension.cmd.BackToHisApprovalNodeCmd; |
|
|
|
import com.ningdatech.pmapi.todocenter.model.dto.req.ReqProcessHandlerDTO; |
|
|
@@ -30,16 +31,13 @@ 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.TaskCommentVo; |
|
|
|
import com.wflow.workflow.bean.vo.ProcessTaskVo; |
|
|
|
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; |
|
|
@@ -116,7 +114,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()); |
|
|
|
ProcessTask processTask = ProcessTask.builder() |
|
|
|
ProcessTaskVo processTaskVo = ProcessTaskVo.builder() |
|
|
|
.taskId(task.getId()) |
|
|
|
.taskName(task.getName()) |
|
|
|
.taskDefKey(task.getTaskDefinitionKey()) |
|
|
@@ -133,7 +131,7 @@ public class TodoCenterManage { |
|
|
|
.createTime(processInstance.getStartTime()) |
|
|
|
.taskCreateTime(task.getCreateTime()) |
|
|
|
.build(); |
|
|
|
res.setProcessTaskInfo(processTask); |
|
|
|
res.setProcessTaskInfo(processTaskVo); |
|
|
|
String projectName = (String) formData.get(ProjectDeclareConstants.BasicInformation.PROJECT_NAME); |
|
|
|
res.setProjectName(projectName); |
|
|
|
res.setReportUnitId(owner.getOwnerDeptId()); |
|
|
@@ -195,15 +193,15 @@ public class TodoCenterManage { |
|
|
|
switch (param.getAction()) { |
|
|
|
// 通过 |
|
|
|
case pass: |
|
|
|
formData.put("audit_pass_opinion",param.getAuditApprovalOpinion()); |
|
|
|
formData.put("audit_pass_appendix",param.getAuditApprovalAppendix()); |
|
|
|
formData.put("audit_pass_opinion",param.getAuditPassOpinion()); |
|
|
|
formData.put("audit_pass_appendix",param.getAuditPassAppendix()); |
|
|
|
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()); |
|
|
|
formData.put("seal_pass_opinion",param.getSealPassOpinion()); |
|
|
|
formData.put("seal_pass_appendix",param.getSealPassAppendix()); |
|
|
|
Date sealPassTime = NdDateUtils.localDateTime2Date(LocalDateTime.now()); |
|
|
|
formData.put("seal_pass_time",sealPassTime); |
|
|
|
formService.updateInstanceFormData(param.getInstanceId(), formData); |
|
|
@@ -231,7 +229,6 @@ public class TodoCenterManage { |
|
|
|
default: |
|
|
|
throw new IllegalStateException("Unexpected value: " + param.getAction()); |
|
|
|
} |
|
|
|
Authentication.setAuthenticatedUserId(null); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -242,7 +239,7 @@ public class TodoCenterManage { |
|
|
|
*/ |
|
|
|
private void doReject(Task task, ReqProcessHandlerDTO param) { |
|
|
|
Map<String, Object> var = new HashMap<>(16); |
|
|
|
var.put("reject_" + task.getId(), param.getAction()); |
|
|
|
var.put("approve_" + task.getId(), param.getAction()); |
|
|
|
// TODO 中止流程并使项目进入对应状态 |
|
|
|
// TODO 给项目创建人、流程发起人发送浙政钉工作通知:【项目名称】的【流程名称】被驳回,请及时处理。 |
|
|
|
taskService.complete(param.getTaskId(), var); |
|
|
@@ -256,7 +253,7 @@ public class TodoCenterManage { |
|
|
|
*/ |
|
|
|
private void doSealPass(Task task, ReqProcessHandlerDTO param) { |
|
|
|
Map<String, Object> var = new HashMap<>(16); |
|
|
|
var.put("seal_pass_" + task.getId(), param.getAction()); |
|
|
|
var.put("approve_" + task.getId(), param.getAction()); |
|
|
|
// TODO 判断项目申报单位级别,区县单位申报有上级主管单位意见栏,市级单位没有 |
|
|
|
// TODO 市级单位:为大数据局;区县单位:为大数据中心(根据附件区分?) |
|
|
|
taskService.complete(param.getTaskId(), var); |
|
|
@@ -270,7 +267,7 @@ public class TodoCenterManage { |
|
|
|
*/ |
|
|
|
private void doPass(Task task, ReqProcessHandlerDTO param) { |
|
|
|
Map<String, Object> var = new HashMap<>(16); |
|
|
|
var.put("pass_" + task.getId(), param.getAction()); |
|
|
|
var.put("approve_" + task.getId(), param.getAction()); |
|
|
|
// TODO 获取流程下一个节点的审核人 |
|
|
|
|
|
|
|
// TODO 若有下一个审核人,向其发送浙政钉工作通知:标题:审核任务 内容:【单位名称】的【项目名称】需要您审核。 |
|
|
@@ -290,12 +287,12 @@ public class TodoCenterManage { |
|
|
|
List<Execution> executions = runtimeService.createExecutionQuery() |
|
|
|
.processInstanceId(task.getProcessInstanceId()) |
|
|
|
.onlyChildExecutions().list(); |
|
|
|
// 强制流程指向驳回 |
|
|
|
// 强制流程指向撤回 |
|
|
|
runtimeService.createChangeActivityStateBuilder() |
|
|
|
.processInstanceId(task.getProcessInstanceId()) |
|
|
|
.moveActivityIdTo(task.getTaskDefinitionKey(), "cancel-end") |
|
|
|
.moveActivityIdTo(task.getTaskDefinitionKey(), HisProInsEndActId.WITHDRAW) |
|
|
|
.moveExecutionsToSingleActivityId(executions.stream().map(Execution::getId) |
|
|
|
.collect(Collectors.toList()), "cancel-end") |
|
|
|
.collect(Collectors.toList()), HisProInsEndActId.WITHDRAW) |
|
|
|
.changeState(); |
|
|
|
} |
|
|
|
|
|
|
@@ -311,7 +308,7 @@ public class TodoCenterManage { |
|
|
|
// TODO 给项目创建人、流程发起人发送浙政钉工作通知:【项目名称】的【流程名称】被退回,请及时处理。 |
|
|
|
//执行自定义回退逻辑 |
|
|
|
managementService.executeCommand(new BackToHisApprovalNodeCmd(runtimeService, param.getTaskId(), param.getTargetNode())); |
|
|
|
runtimeService.setVariables(param.getInstanceId(), Maps.newHashMap("back_" + param.getTaskId(), param.getAction())); |
|
|
|
runtimeService.setVariables(param.getInstanceId(), Maps.newHashMap("approve_" + param.getTaskId(), param.getAction())); |
|
|
|
log.info("用户[{}] 退回流程[{}] [{} -> {}]", userId, param.getInstanceId(), current, param.getTargetNode()); |
|
|
|
} |
|
|
|
|
|
|
@@ -321,7 +318,7 @@ public class TodoCenterManage { |
|
|
|
* @param nodeId 当前获取流程人员关联的流程节点ID |
|
|
|
* @return 流程进度及表单详情 |
|
|
|
*/ |
|
|
|
public Object getProcessDetail(String nodeId, String instanceId) { |
|
|
|
public ProcessProgressDetailVo getProcessDetail(String nodeId, String instanceId) { |
|
|
|
HistoricProcessInstance instance = historyService.createHistoricProcessInstanceQuery().processInstanceId(instanceId).singleResult(); |
|
|
|
// 取表单及表单数据 |
|
|
|
HistoricVariableInstance forms = historyService.createHistoricVariableInstanceQuery() |
|
|
@@ -332,7 +329,6 @@ public class TodoCenterManage { |
|
|
|
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)) { |
|
|
|
// 搜索当前版本流程的配置 |
|
|
@@ -342,15 +338,17 @@ public class TodoCenterManage { |
|
|
|
} |
|
|
|
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); |
|
|
|
List<ProgressNode> taskRecords = getHisTaskRecords(instanceId, nodePropsValue); |
|
|
|
// 获取添加抄送任务 |
|
|
|
taskRecords.addAll(getCcTaskRecords(instanceId)); |
|
|
|
if (ObjectUtil.isNull(instance.getEndTime())) { |
|
|
|
taskRecords.addAll(processTaskService.getFutureTask(instanceId)); |
|
|
|
// TODO 下版实现 获取等待中且还未开始的任务,如果存在条件则需要直接解析条件 |
|
|
|
taskRecords.addAll(getFutureTask(instanceId)); |
|
|
|
} |
|
|
|
taskRecords = taskRecords.stream() |
|
|
|
.sorted(Comparator.comparing(ProcessProgressVo.ProgressNode::getStartTime)) |
|
|
|
.sorted(Comparator.comparing(ProgressNode::getStartTime)) |
|
|
|
.collect(Collectors.toList()); |
|
|
|
taskRecords.add(0, ProcessProgressVo.ProgressNode.builder() |
|
|
|
taskRecords.add(0, ProgressNode.builder() |
|
|
|
.nodeId("root") |
|
|
|
.name("提交申请") |
|
|
|
.user(startUser) |
|
|
@@ -358,14 +356,14 @@ public class TodoCenterManage { |
|
|
|
.startTime(instance.getStartTime()) |
|
|
|
.finishTime(instance.getStartTime()) |
|
|
|
.taskId("root") |
|
|
|
.result(ProcessHandlerParamsVo.Action.agree) |
|
|
|
.result(ReqProcessHandlerDTO.Action.pass) |
|
|
|
.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() |
|
|
|
ProcessProgressDetailVo res = ProcessProgressDetailVo.builder() |
|
|
|
.instanceId(instanceId) |
|
|
|
.version(instance.getProcessDefinitionVersion()) |
|
|
|
.formItems(formService.filterFormAndDataByPermConfig((List<Form>) forms.getValue(), formData, currentNode)) |
|
|
@@ -373,11 +371,20 @@ public class TodoCenterManage { |
|
|
|
.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(); |
|
|
|
if (Objects.isNull(instance.getEndActivityId())){ |
|
|
|
res.setStatus(ProcessStatusEnum.UNDER_REVIEW.name()); |
|
|
|
} else if (HisProInsEndActId.BACK.equals(instance.getEndActivityId())) { |
|
|
|
res.setStatus(ProcessStatusEnum.BE_BACKED.name()); |
|
|
|
} else if (HisProInsEndActId.REJECT.equals(instance.getEndActivityId())) { |
|
|
|
res.setStatus(ProcessStatusEnum.BE_REJECTED.name()); |
|
|
|
} else if (HisProInsEndActId.END.equals(instance.getEndActivityId())) { |
|
|
|
res.setStatus(ProcessStatusEnum.APPROVED.name()); |
|
|
|
} |
|
|
|
return res; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -386,16 +393,15 @@ public class TodoCenterManage { |
|
|
|
* @param instanceId 实例ID |
|
|
|
* @return 抄送我的流程 |
|
|
|
*/ |
|
|
|
private List<ProcessProgressVo.ProgressNode> getCcTaskRecords(String instanceId) { |
|
|
|
private List<ProgressNode> getCcTaskRecords(String instanceId) { |
|
|
|
Set<String> ccUsers = new HashSet<>(); |
|
|
|
List<ProcessProgressVo.ProgressNode> ccList = ccTasksMapper.selectList(new QueryWrapper<WflowCcTasks>() |
|
|
|
List<ProgressNode> ccList = ccTasksMapper.selectList(new QueryWrapper<WflowCcTasks>() |
|
|
|
.eq("instance_id", instanceId)).stream().map(task -> { |
|
|
|
ccUsers.add(task.getUserId()); |
|
|
|
return ProcessProgressVo.ProgressNode.builder() |
|
|
|
return 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()) |
|
|
@@ -415,46 +421,22 @@ public class TodoCenterManage { |
|
|
|
* @param nodeProps 节点设置 |
|
|
|
* @return 历史记录列表 |
|
|
|
*/ |
|
|
|
private List<ProcessProgressVo.ProgressNode> getHisTaskRecords(String instanceId, Map<String, Object> nodeProps) { |
|
|
|
private List<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() |
|
|
|
Map<String, ReqProcessHandlerDTO.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 -> { |
|
|
|
.collect(Collectors.toMap(HistoricVariableInstance::getVariableName, v -> (ReqProcessHandlerDTO.Action) v.getValue())); |
|
|
|
List<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() |
|
|
|
return ProgressNode.builder() |
|
|
|
.nodeId(his.getActivityId()) |
|
|
|
.name(his.getActivityName()) |
|
|
|
.nodeType(NodeTypeEnum.APPROVAL) |
|
|
@@ -463,34 +445,18 @@ public class TodoCenterManage { |
|
|
|
.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()))); |
|
|
|
} |
|
|
|
}); |
|
|
|
progressNodes.forEach(n -> n.setUser(map.get(n.getUser().getId()))); |
|
|
|
} |
|
|
|
return progressNodes; |
|
|
|
} |
|
|
|
|
|
|
|
private List<ProgressNode> getFutureTask(String instanceId) { |
|
|
|
//根据流程遍历后续节点,期间要穿越后续包含并行网关和条件网关的节点 |
|
|
|
return Collections.emptyList(); |
|
|
|
} |
|
|
|
} |