add -- 添加"委派"和"转办"操作,修改流转记录显示方式
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
package com.ruoyi.workflow.domain.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @author konbai
|
||||
* @createTime 2022/4/4 02:03
|
||||
*/
|
||||
@Data
|
||||
@ApiModel("流程批复视图对象")
|
||||
public class WfCommentVo {
|
||||
|
||||
/**
|
||||
* 审批类别
|
||||
*/
|
||||
private String type;
|
||||
|
||||
/**
|
||||
* 批复内容
|
||||
*/
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 批复时间
|
||||
*/
|
||||
private Date time;
|
||||
|
||||
|
||||
}
|
||||
@@ -6,9 +6,11 @@ import com.ruoyi.workflow.domain.dto.WfCommentDto;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.Data;
|
||||
import org.flowable.engine.task.Comment;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 工作流任务视图对象
|
||||
@@ -84,6 +86,9 @@ public class WfTaskVo implements Serializable {
|
||||
@ApiModelProperty("任务意见")
|
||||
private WfCommentDto comment;
|
||||
|
||||
@ApiModelProperty("任务意见")
|
||||
private List<Comment> commentList;
|
||||
|
||||
@ApiModelProperty("候选执行人")
|
||||
private String candidate;
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public interface IWfTaskService {
|
||||
*
|
||||
* @param bo 请求实体参数
|
||||
*/
|
||||
void assignTask(WfTaskBo bo);
|
||||
void transferTask(WfTaskBo bo);
|
||||
|
||||
/**
|
||||
* 我发起的流程
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.ruoyi.workflow.service.impl;
|
||||
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.date.BetweenFormatter;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
@@ -13,7 +14,6 @@ import com.ruoyi.flowable.factory.FlowServiceFactory;
|
||||
import com.ruoyi.system.service.ISysRoleService;
|
||||
import com.ruoyi.system.service.ISysUserService;
|
||||
import com.ruoyi.workflow.domain.bo.WfTaskBo;
|
||||
import com.ruoyi.workflow.domain.dto.WfCommentDto;
|
||||
import com.ruoyi.workflow.domain.vo.WfFormVo;
|
||||
import com.ruoyi.workflow.domain.vo.WfTaskVo;
|
||||
import com.ruoyi.workflow.service.IWfDeployFormService;
|
||||
@@ -21,11 +21,11 @@ import com.ruoyi.workflow.service.IWfInstanceService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.flowable.common.engine.api.FlowableObjectNotFoundException;
|
||||
import org.flowable.engine.history.HistoricActivityInstance;
|
||||
import org.flowable.engine.history.HistoricProcessInstance;
|
||||
import org.flowable.engine.task.Comment;
|
||||
import org.flowable.identitylink.api.history.HistoricIdentityLink;
|
||||
import org.flowable.task.api.Task;
|
||||
import org.flowable.task.api.history.HistoricTaskInstance;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -130,58 +130,61 @@ public class WfInstanceServiceImpl extends FlowServiceFactory implements IWfInst
|
||||
public Map<String, Object> queryDetailProcess(String procInsId, String deployId) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
if (StringUtils.isNotBlank(procInsId)) {
|
||||
List<HistoricActivityInstance> list = historyService
|
||||
.createHistoricActivityInstanceQuery()
|
||||
List<HistoricTaskInstance> taskInstanceList = historyService.createHistoricTaskInstanceQuery()
|
||||
.processInstanceId(procInsId)
|
||||
.orderByHistoricActivityInstanceStartTime()
|
||||
.desc().list();
|
||||
List<WfTaskVo> hisFlowList = new ArrayList<>();
|
||||
for (HistoricActivityInstance histIns : list) {
|
||||
if (StringUtils.isNotBlank(histIns.getTaskId())) {
|
||||
WfTaskVo flowTask = new WfTaskVo();
|
||||
flowTask.setProcDefId(histIns.getProcessDefinitionId());
|
||||
flowTask.setTaskId(histIns.getTaskId());
|
||||
flowTask.setTaskName(histIns.getActivityName());
|
||||
flowTask.setCreateTime(histIns.getStartTime());
|
||||
flowTask.setFinishTime(histIns.getEndTime());
|
||||
if (StringUtils.isNotBlank(histIns.getAssignee())) {
|
||||
SysUser user = userService.selectUserById(Long.parseLong(histIns.getAssignee()));
|
||||
flowTask.setAssigneeId(user.getUserId());
|
||||
flowTask.setAssigneeName(user.getNickName());
|
||||
flowTask.setDeptName(user.getDept().getDeptName());
|
||||
}
|
||||
// 展示审批人员
|
||||
List<HistoricIdentityLink> linksForTask = historyService.getHistoricIdentityLinksForTask(histIns.getTaskId());
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (HistoricIdentityLink identityLink : linksForTask) {
|
||||
if ("candidate".equals(identityLink.getType())) {
|
||||
if (StringUtils.isNotBlank(identityLink.getUserId())) {
|
||||
SysUser user = userService.selectUserById(Long.parseLong(identityLink.getUserId()));
|
||||
stringBuilder.append(user.getNickName()).append(",");
|
||||
}
|
||||
if (StringUtils.isNotBlank(identityLink.getGroupId())) {
|
||||
SysRole role = roleService.selectRoleById(Long.parseLong(identityLink.getGroupId()));
|
||||
stringBuilder.append(role.getRoleName()).append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(stringBuilder)) {
|
||||
flowTask.setCandidate(stringBuilder.substring(0, stringBuilder.length() - 1));
|
||||
}
|
||||
if (ObjectUtil.isNotNull(histIns.getDurationInMillis())) {
|
||||
flowTask.setDuration(DateUtil.formatBetween(histIns.getDurationInMillis(), BetweenFormatter.Level.SECOND));
|
||||
}
|
||||
// 获取意见评论内容
|
||||
List<Comment> commentList = taskService.getProcessInstanceComments(histIns.getProcessInstanceId());
|
||||
commentList.forEach(comment -> {
|
||||
if (histIns.getTaskId().equals(comment.getTaskId())) {
|
||||
flowTask.setComment(WfCommentDto.builder().type(comment.getType()).comment(comment.getFullMessage()).build());
|
||||
}
|
||||
});
|
||||
hisFlowList.add(flowTask);
|
||||
.orderByHistoricTaskInstanceStartTime().desc()
|
||||
.list();
|
||||
List<Comment> commentList = taskService.getProcessInstanceComments(procInsId);
|
||||
List<WfTaskVo> taskVoList = new ArrayList<>(taskInstanceList.size());
|
||||
taskInstanceList.forEach(taskInstance -> {
|
||||
WfTaskVo taskVo = new WfTaskVo();
|
||||
taskVo.setProcDefId(taskInstance.getProcessDefinitionId());
|
||||
taskVo.setTaskId(taskInstance.getId());
|
||||
taskVo.setTaskName(taskInstance.getName());
|
||||
taskVo.setCreateTime(taskInstance.getStartTime());
|
||||
taskVo.setFinishTime(taskInstance.getEndTime());
|
||||
if (StringUtils.isNotBlank(taskInstance.getAssignee())) {
|
||||
SysUser user = userService.selectUserById(Long.parseLong(taskInstance.getAssignee()));
|
||||
taskVo.setAssigneeId(user.getUserId());
|
||||
taskVo.setAssigneeName(user.getNickName());
|
||||
taskVo.setDeptName(user.getDept().getDeptName());
|
||||
}
|
||||
}
|
||||
map.put("flowList", hisFlowList);
|
||||
// 展示审批人员
|
||||
List<HistoricIdentityLink> linksForTask = historyService.getHistoricIdentityLinksForTask(taskInstance.getId());
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (HistoricIdentityLink identityLink : linksForTask) {
|
||||
if ("candidate".equals(identityLink.getType())) {
|
||||
if (StringUtils.isNotBlank(identityLink.getUserId())) {
|
||||
SysUser user = userService.selectUserById(Long.parseLong(identityLink.getUserId()));
|
||||
stringBuilder.append(user.getNickName()).append(",");
|
||||
}
|
||||
if (StringUtils.isNotBlank(identityLink.getGroupId())) {
|
||||
SysRole role = roleService.selectRoleById(Long.parseLong(identityLink.getGroupId()));
|
||||
stringBuilder.append(role.getRoleName()).append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(stringBuilder)) {
|
||||
taskVo.setCandidate(stringBuilder.substring(0, stringBuilder.length() - 1));
|
||||
}
|
||||
if (ObjectUtil.isNotNull(taskInstance.getDurationInMillis())) {
|
||||
taskVo.setDuration(DateUtil.formatBetween(taskInstance.getDurationInMillis(), BetweenFormatter.Level.SECOND));
|
||||
}
|
||||
// 获取意见评论内容
|
||||
if (CollUtil.isNotEmpty(commentList)) {
|
||||
List<Comment> comments = new ArrayList<>();
|
||||
// commentList.stream().filter(comment -> taskInstance.getId().equals(comment.getTaskId())).collect(Collectors.toList());
|
||||
for (Comment comment : commentList) {
|
||||
if (comment.getTaskId().equals(taskInstance.getId())) {
|
||||
comments.add(comment);
|
||||
// taskVo.setComment(WfCommentDto.builder().type(comment.getType()).comment(comment.getFullMessage()).build());
|
||||
}
|
||||
}
|
||||
taskVo.setCommentList(comments);
|
||||
}
|
||||
taskVoList.add(taskVo);
|
||||
});
|
||||
map.put("flowList", taskVoList);
|
||||
// // 查询当前任务是否完成
|
||||
// List<Task> taskList = taskService.createTaskQuery().processInstanceId(procInsId).list();
|
||||
// if (CollectionUtils.isNotEmpty(taskList)) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
|
||||
import com.ruoyi.common.exception.ServiceException;
|
||||
import com.ruoyi.common.helper.LoginHelper;
|
||||
import com.ruoyi.common.utils.JsonUtils;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import com.ruoyi.flowable.common.constant.ProcessConstants;
|
||||
import com.ruoyi.flowable.common.enums.FlowComment;
|
||||
import com.ruoyi.flowable.factory.FlowServiceFactory;
|
||||
@@ -33,7 +34,6 @@ import com.ruoyi.workflow.service.IWfTaskService;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.flowable.bpmn.model.Process;
|
||||
import org.flowable.bpmn.model.*;
|
||||
import org.flowable.common.engine.api.FlowableException;
|
||||
@@ -84,26 +84,26 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
|
||||
/**
|
||||
* 完成任务
|
||||
*
|
||||
* @param taskVo 请求实体参数
|
||||
* @param taskBo 请求实体参数
|
||||
*/
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void complete(WfTaskBo taskVo) {
|
||||
Task task = taskService.createTaskQuery().taskId(taskVo.getTaskId()).singleResult();
|
||||
public void complete(WfTaskBo taskBo) {
|
||||
Task task = taskService.createTaskQuery().taskId(taskBo.getTaskId()).singleResult();
|
||||
if (Objects.isNull(task)) {
|
||||
throw new ServiceException("任务不存在");
|
||||
}
|
||||
if (DelegationState.PENDING.equals(task.getDelegationState())) {
|
||||
taskService.addComment(taskVo.getTaskId(), taskVo.getInstanceId(), FlowComment.DELEGATE.getType(), taskVo.getComment());
|
||||
taskService.resolveTask(taskVo.getTaskId(), taskVo.getValues());
|
||||
taskService.addComment(taskBo.getTaskId(), taskBo.getInstanceId(), FlowComment.DELEGATE.getType(), taskBo.getComment());
|
||||
taskService.resolveTask(taskBo.getTaskId(), taskBo.getValues());
|
||||
} else {
|
||||
taskService.addComment(taskVo.getTaskId(), taskVo.getInstanceId(), FlowComment.NORMAL.getType(), taskVo.getComment());
|
||||
taskService.addComment(taskBo.getTaskId(), taskBo.getInstanceId(), FlowComment.NORMAL.getType(), taskBo.getComment());
|
||||
Long userId = LoginHelper.getUserId();
|
||||
taskService.setAssignee(taskVo.getTaskId(), userId.toString());
|
||||
if (ObjectUtil.isNotEmpty(taskVo.getValues())) {
|
||||
taskService.complete(taskVo.getTaskId(), taskVo.getValues());
|
||||
taskService.setAssignee(taskBo.getTaskId(), userId.toString());
|
||||
if (ObjectUtil.isNotEmpty(taskBo.getValues())) {
|
||||
taskService.complete(taskBo.getTaskId(), taskBo.getValues());
|
||||
} else {
|
||||
taskService.complete(taskVo.getTaskId());
|
||||
taskService.complete(taskBo.getTaskId());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,11 +115,14 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
|
||||
*/
|
||||
@Override
|
||||
public void taskReject(WfTaskBo bo) {
|
||||
if (taskService.createTaskQuery().taskId(bo.getTaskId()).singleResult().isSuspended()) {
|
||||
throw new RuntimeException("任务处于挂起状态");
|
||||
}
|
||||
// 当前任务 task
|
||||
Task task = taskService.createTaskQuery().taskId(bo.getTaskId()).singleResult();
|
||||
if (ObjectUtil.isNull(task)) {
|
||||
throw new RuntimeException("获取任务信息异常!");
|
||||
}
|
||||
if (task.isSuspended()) {
|
||||
throw new RuntimeException("任务处于挂起状态");
|
||||
}
|
||||
// 获取流程定义信息
|
||||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
|
||||
// 获取所有节点信息
|
||||
@@ -240,11 +243,14 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
@Override
|
||||
public void taskReturn(WfTaskBo bo) {
|
||||
if (taskService.createTaskQuery().taskId(bo.getTaskId()).singleResult().isSuspended()) {
|
||||
throw new RuntimeException("任务处于挂起状态");
|
||||
}
|
||||
// 当前任务 task
|
||||
Task task = taskService.createTaskQuery().taskId(bo.getTaskId()).singleResult();
|
||||
if (ObjectUtil.isNull(task)) {
|
||||
throw new RuntimeException("获取任务信息异常!");
|
||||
}
|
||||
if (task.isSuspended()) {
|
||||
throw new RuntimeException("任务处于挂起状态");
|
||||
}
|
||||
// 获取流程定义信息
|
||||
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(task.getProcessDefinitionId()).singleResult();
|
||||
// 获取所有节点信息
|
||||
@@ -394,7 +400,28 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void delegateTask(WfTaskBo bo) {
|
||||
taskService.delegateTask(bo.getTaskId(), bo.getAssignee());
|
||||
// 当前任务 task
|
||||
Task task = taskService.createTaskQuery().taskId(bo.getTaskId()).singleResult();
|
||||
if (ObjectUtil.isEmpty(task)) {
|
||||
throw new ServiceException("获取任务失败!");
|
||||
}
|
||||
StringBuilder commentBuilder = new StringBuilder(LoginHelper.getNickName())
|
||||
.append("->");
|
||||
SysUser user = sysUserService.selectUserById(Long.parseLong(bo.getUserId()));
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
commentBuilder.append(user.getNickName());
|
||||
} else {
|
||||
commentBuilder.append(bo.getUserId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(bo.getComment())) {
|
||||
commentBuilder.append(": ").append(bo.getComment());
|
||||
}
|
||||
// 添加审批意见
|
||||
taskService.addComment(bo.getTaskId(), task.getProcessInstanceId(), FlowComment.DELEGATE.getType(), commentBuilder.toString());
|
||||
// 设置办理人为当前登录人
|
||||
taskService.setOwner(bo.getTaskId(), LoginHelper.getUserId().toString());
|
||||
// 执行委派
|
||||
taskService.delegateTask(bo.getTaskId(), bo.getUserId());
|
||||
}
|
||||
|
||||
|
||||
@@ -405,8 +432,29 @@ public class WfTaskServiceImpl extends FlowServiceFactory implements IWfTaskServ
|
||||
*/
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void assignTask(WfTaskBo bo) {
|
||||
taskService.setAssignee(bo.getTaskId(), bo.getComment());
|
||||
public void transferTask(WfTaskBo bo) {
|
||||
// 当前任务 task
|
||||
Task task = taskService.createTaskQuery().taskId(bo.getTaskId()).singleResult();
|
||||
if (ObjectUtil.isEmpty(task)) {
|
||||
throw new ServiceException("获取任务失败!");
|
||||
}
|
||||
StringBuilder commentBuilder = new StringBuilder(LoginHelper.getNickName())
|
||||
.append("->");
|
||||
SysUser user = sysUserService.selectUserById(Long.parseLong(bo.getUserId()));
|
||||
if (ObjectUtil.isNotNull(user)) {
|
||||
commentBuilder.append(user.getNickName());
|
||||
} else {
|
||||
commentBuilder.append(bo.getUserId());
|
||||
}
|
||||
if (StringUtils.isNotBlank(bo.getComment())) {
|
||||
commentBuilder.append(": ").append(bo.getComment());
|
||||
}
|
||||
// 添加审批意见
|
||||
taskService.addComment(bo.getTaskId(), task.getProcessInstanceId(), FlowComment.TRANSFER.getType(), commentBuilder.toString());
|
||||
// 设置拥有者为当前登录人
|
||||
taskService.setOwner(bo.getTaskId(), LoginHelper.getUserId().toString());
|
||||
// 转办任务
|
||||
taskService.setAssignee(bo.getTaskId(), bo.getUserId());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user