实现 bpm 已办任务的后端接口

This commit is contained in:
YunaiV 2022-01-08 20:49:11 +08:00
parent 77f06e79c4
commit 2017b03169
8 changed files with 182 additions and 18 deletions

View File

@ -2,3 +2,8 @@
GET {{baseUrl}}/bpm/task/todo-page
tenant-id: 1
Authorization: Bearer {{token}}
### 请求 /bpm/task/done-page 接口 => 成功
GET {{baseUrl}}/bpm/task/done-page
tenant-id: 1
Authorization: Bearer {{token}}

View File

@ -31,11 +31,17 @@ public class BpmTaskController {
// TODO 芋艿权限validation
@GetMapping("todo-page")
@ApiOperation("获取 TODO 待办任务分页")
@ApiOperation("获取 Todo 待办任务分页")
public CommonResult<PageResult<BpmTaskTodoPageItemRespVO>> getTodoTaskPage(@Valid BpmTaskTodoPageReqVO pageVO) {
return success(taskService.getTodoTaskPage(getLoginUserId(), pageVO));
}
@GetMapping("done-page")
@ApiOperation("获取 Done 已办任务分页")
public CommonResult<PageResult<BpmTaskDonePageItemRespVO>> getTodoTaskPage(@Valid BpmTaskDonePageReqVO pageVO) {
return success(taskService.getDoneTaskPage(getLoginUserId(), pageVO));
}
@PostMapping("/task-steps")
public CommonResult<TaskHandleVO> getTaskSteps(@RequestBody TaskQueryReqVO taskQuery) {
return success(taskService.getTaskSteps(taskQuery));

View File

@ -0,0 +1,63 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.Date;
@ApiModel("流程任务的 Done 已完成的分页项 Response VO")
@Data
public class BpmTaskDonePageItemRespVO {
@ApiModelProperty(value = "任务编号", required = true, example = "1024")
private String id;
@ApiModelProperty(value = "任务名字", required = true, example = "芋道")
private String name;
@ApiModelProperty(value = "接收时间", required = true)
private Date claimTime;
@ApiModelProperty(value = "创建时间", required = true)
private Date createTime;
@ApiModelProperty(value = "结束时间", required = true)
private Date endTime;
@ApiModelProperty(value = "持续时间", required = true, example = "1000")
private Long durationInMillis;
/**
* 所属流程实例
*/
private ProcessInstance processInstance;
@Data
@ApiModel("流程实例")
public static class ProcessInstance {
@ApiModelProperty(value = "流程实例编号", required = true, example = "1024")
private String id;
@ApiModelProperty(value = "流程实例名称", required = true, example = "芋道")
private String name;
@ApiModelProperty(value = "发起人的用户编号", required = true, example = "1024")
private Long startUserId;
@ApiModelProperty(value = "发起人的用户昵称", required = true, example = "芋艿")
private String startUserNickname;
@ApiModelProperty(value = "流程定义的编号", required = true, example = "2048")
private String processDefinitionId;
}
// 任务编号流程名称任务节点流程发起人接收时间审批时间耗时名称开始时间流程记录撤回
// 任务编号任务名称所属流程委托代办人流程发起人优先级审批操作审批意见耗时创建时间名称开始时间申请详情
// 任务编号任务名称流程名称流程发起人接收时间审批时间耗时名称接收时间详情TODO 撤回
}

View File

@ -0,0 +1,32 @@
package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.springframework.format.annotation.DateTimeFormat;
import java.util.Date;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@ApiModel("流程任务的 Done 已办的分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class BpmTaskDonePageReqVO extends PageParam {
@ApiModelProperty(value = "流程任务名", example = "芋道")
private String name;
@ApiModelProperty(value = "开始的创建收间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date beginCreateTime;
@ApiModelProperty(value = "结束的创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private Date endCreateTime;
}

View File

@ -6,7 +6,7 @@ import lombok.Data;
import java.util.Date;
@ApiModel(value = "流程任务的 Running 进行中的分页项 Response VO", description = "待办任务")
@ApiModel("流程任务的 Running 进行中的分页项 Response VO")
@Data
public class BpmTaskTodoPageItemRespVO {
@ -51,8 +51,4 @@ public class BpmTaskTodoPageItemRespVO {
}
// 任务编号任务名称任务节点流程版本流程发起人接收时间名称开始时间处理
// 任务编号任务名称所属流程委托代办人流程发起人优先级状态创建时间名称开始时间申请详情通过驳回转办历史
// 任务编号任务名称流程名称流程发起人接收时间状态名称接收时间处理委托
}

View File

@ -1,10 +1,12 @@
package cn.iocoder.yudao.adminserver.modules.bpm.convert.task;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.BpmTaskDonePageItemRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.BpmTaskTodoPageItemRespVO;
import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.TaskStepVO;
import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.impl.persistence.entity.SuspensionState;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;
@ -61,4 +63,28 @@ public interface BpmTaskConvert {
SuspensionState.ACTIVE.getStateCode();
}
default List<BpmTaskDonePageItemRespVO> convertList2(List<HistoricTaskInstance> tasks,
Map<String, ProcessInstance> processInstanceMap,
Map<Long, SysUserDO> userMap) {
return CollectionUtils.convertList(tasks, task -> {
ProcessInstance processInstance = processInstanceMap.get(task.getProcessInstanceId());
return convert(task, processInstance, userMap.get(Long.valueOf(processInstance.getStartUserId())));
});
}
@Mappings({
@Mapping(source = "task.id", target = "id"),
@Mapping(source = "task.name", target = "name"),
@Mapping(source = "task.claimTime", target = "claimTime"),
@Mapping(source = "task.createTime", target = "createTime"),
@Mapping(source = "task.endTime", target = "endTime"),
@Mapping(source = "task.durationInMillis", target = "durationInMillis"),
@Mapping(source = "processInstance.id", target = "processInstance.id"),
@Mapping(source = "processInstance.name", target = "processInstance.name"),
@Mapping(source = "processInstance.startUserId", target = "processInstance.startUserId"),
@Mapping(source = "processInstance.processDefinitionId", target = "processInstance.processDefinitionId"),
@Mapping(source = "user.nickname", target = "processInstance.startUserNickname")
})
BpmTaskDonePageItemRespVO convert(HistoricTaskInstance task, ProcessInstance processInstance, SysUserDO user);
}

View File

@ -44,7 +44,7 @@ public interface BpmTaskService {
}
/**
* 获得流程任务分页
* 获得待办的流程任务分页
*
* @param userId 用户编号
* @param pageReqVO 分页请求
@ -52,6 +52,15 @@ public interface BpmTaskService {
*/
PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageReqVO);
/**
* 获得已办的流程任务分页
*
* @param userId 用户编号
* @param pageReqVO 分页请求
* @return 流程任务分页
*/
PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageReqVO);
/**
* 将流程任务分配给指定用户
*

View File

@ -23,6 +23,8 @@ import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricActivityInstance;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.history.HistoricTaskInstance;
import org.activiti.engine.history.HistoricTaskInstanceQuery;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Comment;
@ -83,7 +85,8 @@ public class BpmTaskServiceImpl implements BpmTaskService {
public PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) {
// 查询待办任务
TaskQuery taskQuery = taskService.createTaskQuery()
.taskAssignee(String.valueOf(userId));
.taskAssignee(String.valueOf(userId)) // 分配给自己
.orderByTaskCreateTime().desc(); // 创建时间倒序
if (StrUtil.isNotBlank(pageVO.getName())) {
taskQuery.taskNameLike("%" + pageVO.getName() + "%");
}
@ -94,8 +97,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
taskQuery.taskCreatedBefore(pageVO.getEndCreateTime());
}
// 执行查询
List<Task> tasks = taskQuery.orderByTaskCreateTime().desc() // 创建时间倒序
.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
List<Task> tasks = taskQuery.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
if (CollUtil.isEmpty(tasks)) {
return PageResult.empty(taskQuery.count());
}
@ -103,7 +105,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
// 获得 ProcessInstance Map
Map<String, ProcessInstance> processInstanceMap = processInstanceService.getProcessInstanceMap(
convertSet(tasks, Task::getProcessInstanceId));
// 获得 User Map
Map<Long, SysUserDO> userMap = userService.getUserMap(
convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
@ -112,6 +113,39 @@ public class BpmTaskServiceImpl implements BpmTaskService {
taskQuery.count());
}
@Override
public PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageVO) {
// 查询已办任务
HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery()
.finished() // 已完成
.taskAssignee(String.valueOf(userId)) // 分配给自己
.orderByHistoricTaskInstanceEndTime().desc(); // 审批时间倒序
if (StrUtil.isNotBlank(pageVO.getName())) {
taskQuery.taskNameLike("%" + pageVO.getName() + "%");
}
if (pageVO.getBeginCreateTime() != null) {
taskQuery.taskCreatedAfter(pageVO.getBeginCreateTime());
}
if (pageVO.getEndCreateTime() != null) {
taskQuery.taskCreatedBefore(pageVO.getEndCreateTime());
}
// 执行查询
List<HistoricTaskInstance> tasks = taskQuery.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
if (CollUtil.isEmpty(tasks)) {
return PageResult.empty(taskQuery.count());
}
// 获得 ProcessInstance Map
Map<String, ProcessInstance> processInstanceMap = processInstanceService.getProcessInstanceMap(
convertSet(tasks, HistoricTaskInstance::getProcessInstanceId));
// 获得 User Map
Map<Long, SysUserDO> userMap = userService.getUserMap(
convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
// 拼接结果
return new PageResult<>(BpmTaskConvert.INSTANCE.convertList2(tasks, processInstanceMap, userMap),
taskQuery.count());
}
@Override
public void updateTaskAssign(String id, Long userId) {
taskService.setAssignee(id, String.valueOf(userId));
@ -122,11 +156,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
}
// 任务编号流程名称任务节点流程发起人接收时间审批时间耗时名称开始时间流程记录撤回
// 任务编号任务名称所属流程委托代办人流程发起人优先级审批操作审批意见耗时创建时间名称开始时间申请详情
// 任务编号任务名称流程名称流程发起人接收时间审批时间耗时名称接收时间详情TODO 撤回
@Override
@Transactional
public void completeTask(TaskReqVO taskReq) {
@ -139,8 +168,6 @@ public class BpmTaskServiceImpl implements BpmTaskService {
// .build());
}
@Override
public TaskHandleVO getTaskSteps(TaskQueryReqVO taskQuery) {
// TaskHandleVO handleVO = new TaskHandleVO();