|
|
@@ -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; |
|
|
|
} |
|
|
|
} |