diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.http b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.http index 40bd2ccf5..4742c83e7 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.http +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.http @@ -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}} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java index 137b01a0d..c486309a3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java @@ -31,11 +31,17 @@ public class BpmTaskController { // TODO 芋艿:权限、validation; @GetMapping("todo-page") - @ApiOperation("获取 TODO 待办任务分页") + @ApiOperation("获取 Todo 待办任务分页") public CommonResult> getTodoTaskPage(@Valid BpmTaskTodoPageReqVO pageVO) { return success(taskService.getTodoTaskPage(getLoginUserId(), pageVO)); } + @GetMapping("done-page") + @ApiOperation("获取 Done 已办任务分页") + public CommonResult> getTodoTaskPage(@Valid BpmTaskDonePageReqVO pageVO) { + return success(taskService.getDoneTaskPage(getLoginUserId(), pageVO)); + } + @PostMapping("/task-steps") public CommonResult getTaskSteps(@RequestBody TaskQueryReqVO taskQuery) { return success(taskService.getTaskSteps(taskQuery)); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskDonePageItemRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskDonePageItemRespVO.java new file mode 100644 index 000000000..d43b92e83 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskDonePageItemRespVO.java @@ -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 撤回 + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskDonePageReqVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskDonePageReqVO.java new file mode 100644 index 000000000..c3d3c6ead --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskDonePageReqVO.java @@ -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; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskTodoPageItemRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskTodoPageItemRespVO.java index bf167bc39..2703b9690 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskTodoPageItemRespVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskTodoPageItemRespVO.java @@ -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 { } - // 任务编号、任务名称、任务节点、流程版本、流程发起人、接收时间【名称、开始时间】「处理」 - // 任务编号、任务名称、所属流程、委托代办人、流程发起人、优先级、状态、创建时间【名称、开始时间】「申请详情、通过、驳回、转办、历史」 - - // 任务编号、任务名称、流程名称、流程发起人、接收时间、状态【名称、接收时间】【处理、委托】 } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmTaskConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmTaskConvert.java index e62085c7a..101dc1e48 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmTaskConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmTaskConvert.java @@ -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 convertList2(List tasks, + Map processInstanceMap, + Map 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); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java index e7a734943..fefdecd7d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java @@ -44,7 +44,7 @@ public interface BpmTaskService { } /** - * 获得流程任务分页 + * 获得待办的流程任务分页 * * @param userId 用户编号 * @param pageReqVO 分页请求 @@ -52,6 +52,15 @@ public interface BpmTaskService { */ PageResult getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageReqVO); + /** + * 获得已办的流程任务分页 + * + * @param userId 用户编号 + * @param pageReqVO 分页请求 + * @return 流程任务分页 + */ + PageResult getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageReqVO); + /** * 将流程任务分配给指定用户 * diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java index e50f9ce76..8204fc608 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java @@ -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 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 tasks = taskQuery.orderByTaskCreateTime().desc() // 创建时间倒序 - .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); + List 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 processInstanceMap = processInstanceService.getProcessInstanceMap( convertSet(tasks, Task::getProcessInstanceId)); - // 获得 User Map Map 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 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 tasks = taskQuery.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); + if (CollUtil.isEmpty(tasks)) { + return PageResult.empty(taskQuery.count()); + } + + // 获得 ProcessInstance Map + Map processInstanceMap = processInstanceService.getProcessInstanceMap( + convertSet(tasks, HistoricTaskInstance::getProcessInstanceId)); + // 获得 User Map + Map 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();