Commit 2017b0316903a5718adbcf2bb24d90cd59609645
1 parent
77f06e79
实现 bpm 已办任务的后端接口
Showing
8 changed files
with
182 additions
and
18 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.http
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java
| ... | ... | @@ -31,11 +31,17 @@ public class BpmTaskController { |
| 31 | 31 | // TODO 芋艿:权限、validation; |
| 32 | 32 | |
| 33 | 33 | @GetMapping("todo-page") |
| 34 | - @ApiOperation("获取 TODO 待办任务分页") | |
| 34 | + @ApiOperation("获取 Todo 待办任务分页") | |
| 35 | 35 | public CommonResult<PageResult<BpmTaskTodoPageItemRespVO>> getTodoTaskPage(@Valid BpmTaskTodoPageReqVO pageVO) { |
| 36 | 36 | return success(taskService.getTodoTaskPage(getLoginUserId(), pageVO)); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | + @GetMapping("done-page") | |
| 40 | + @ApiOperation("获取 Done 已办任务分页") | |
| 41 | + public CommonResult<PageResult<BpmTaskDonePageItemRespVO>> getTodoTaskPage(@Valid BpmTaskDonePageReqVO pageVO) { | |
| 42 | + return success(taskService.getDoneTaskPage(getLoginUserId(), pageVO)); | |
| 43 | + } | |
| 44 | + | |
| 39 | 45 | @PostMapping("/task-steps") |
| 40 | 46 | public CommonResult<TaskHandleVO> getTaskSteps(@RequestBody TaskQueryReqVO taskQuery) { |
| 41 | 47 | return success(taskService.getTaskSteps(taskQuery)); | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskDonePageItemRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task; | |
| 2 | + | |
| 3 | +import io.swagger.annotations.ApiModel; | |
| 4 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | +import lombok.Data; | |
| 6 | + | |
| 7 | +import java.util.Date; | |
| 8 | + | |
| 9 | +@ApiModel("流程任务的 Done 已完成的分页项 Response VO") | |
| 10 | +@Data | |
| 11 | +public class BpmTaskDonePageItemRespVO { | |
| 12 | + | |
| 13 | + @ApiModelProperty(value = "任务编号", required = true, example = "1024") | |
| 14 | + private String id; | |
| 15 | + | |
| 16 | + @ApiModelProperty(value = "任务名字", required = true, example = "芋道") | |
| 17 | + private String name; | |
| 18 | + | |
| 19 | + @ApiModelProperty(value = "接收时间", required = true) | |
| 20 | + private Date claimTime; | |
| 21 | + | |
| 22 | + @ApiModelProperty(value = "创建时间", required = true) | |
| 23 | + private Date createTime; | |
| 24 | + | |
| 25 | + @ApiModelProperty(value = "结束时间", required = true) | |
| 26 | + private Date endTime; | |
| 27 | + | |
| 28 | + @ApiModelProperty(value = "持续时间", required = true, example = "1000") | |
| 29 | + private Long durationInMillis; | |
| 30 | + | |
| 31 | + /** | |
| 32 | + * 所属流程实例 | |
| 33 | + */ | |
| 34 | + private ProcessInstance processInstance; | |
| 35 | + | |
| 36 | + @Data | |
| 37 | + @ApiModel("流程实例") | |
| 38 | + public static class ProcessInstance { | |
| 39 | + | |
| 40 | + @ApiModelProperty(value = "流程实例编号", required = true, example = "1024") | |
| 41 | + private String id; | |
| 42 | + | |
| 43 | + @ApiModelProperty(value = "流程实例名称", required = true, example = "芋道") | |
| 44 | + private String name; | |
| 45 | + | |
| 46 | + @ApiModelProperty(value = "发起人的用户编号", required = true, example = "1024") | |
| 47 | + private Long startUserId; | |
| 48 | + | |
| 49 | + @ApiModelProperty(value = "发起人的用户昵称", required = true, example = "芋艿") | |
| 50 | + private String startUserNickname; | |
| 51 | + | |
| 52 | + @ApiModelProperty(value = "流程定义的编号", required = true, example = "2048") | |
| 53 | + private String processDefinitionId; | |
| 54 | + | |
| 55 | + } | |
| 56 | + | |
| 57 | + | |
| 58 | + // 任务编号、流程名称、任务节点、流程发起人、接收时间、审批时间、耗时【名称、开始时间】「流程记录、撤回」 | |
| 59 | + // 任务编号、任务名称、所属流程、委托代办人、流程发起人、优先级、审批操作、审批意见、耗时、创建时间【名称、开始时间】「申请详情」 | |
| 60 | + | |
| 61 | + // 任务编号、任务名称、流程名称、流程发起人、接收时间、审批时间、耗时【名称、接收时间】「详情」TODO 撤回 | |
| 62 | + | |
| 63 | +} | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskDonePageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import io.swagger.annotations.ApiModel; | |
| 5 | +import io.swagger.annotations.ApiModelProperty; | |
| 6 | +import lombok.Data; | |
| 7 | +import lombok.EqualsAndHashCode; | |
| 8 | +import lombok.ToString; | |
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 10 | + | |
| 11 | +import java.util.Date; | |
| 12 | + | |
| 13 | +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; | |
| 14 | + | |
| 15 | +@ApiModel("流程任务的 Done 已办的分页 Request VO") | |
| 16 | +@Data | |
| 17 | +@EqualsAndHashCode(callSuper = true) | |
| 18 | +@ToString(callSuper = true) | |
| 19 | +public class BpmTaskDonePageReqVO extends PageParam { | |
| 20 | + | |
| 21 | + @ApiModelProperty(value = "流程任务名", example = "芋道") | |
| 22 | + private String name; | |
| 23 | + | |
| 24 | + @ApiModelProperty(value = "开始的创建收间") | |
| 25 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 26 | + private Date beginCreateTime; | |
| 27 | + | |
| 28 | + @ApiModelProperty(value = "结束的创建时间") | |
| 29 | + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) | |
| 30 | + private Date endCreateTime; | |
| 31 | + | |
| 32 | +} | ... | ... |
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; |
| 6 | 6 | |
| 7 | 7 | import java.util.Date; |
| 8 | 8 | |
| 9 | -@ApiModel(value = "流程任务的 Running 进行中的分页项 Response VO", description = "待办任务") | |
| 9 | +@ApiModel("流程任务的 Running 进行中的分页项 Response VO") | |
| 10 | 10 | @Data |
| 11 | 11 | public class BpmTaskTodoPageItemRespVO { |
| 12 | 12 | |
| ... | ... | @@ -51,8 +51,4 @@ public class BpmTaskTodoPageItemRespVO { |
| 51 | 51 | |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - // 任务编号、任务名称、任务节点、流程版本、流程发起人、接收时间【名称、开始时间】「处理」 | |
| 55 | - // 任务编号、任务名称、所属流程、委托代办人、流程发起人、优先级、状态、创建时间【名称、开始时间】「申请详情、通过、驳回、转办、历史」 | |
| 56 | - | |
| 57 | - // 任务编号、任务名称、流程名称、流程发起人、接收时间、状态【名称、接收时间】【处理、委托】 | |
| 58 | 54 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmTaskConvert.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.bpm.convert.task; |
| 2 | 2 | |
| 3 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.BpmTaskDonePageItemRespVO; | |
| 3 | 4 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.BpmTaskTodoPageItemRespVO; |
| 4 | 5 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.TaskStepVO; |
| 5 | 6 | import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; |
| 6 | 7 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 7 | 8 | import org.activiti.engine.history.HistoricActivityInstance; |
| 9 | +import org.activiti.engine.history.HistoricTaskInstance; | |
| 8 | 10 | import org.activiti.engine.impl.persistence.entity.SuspensionState; |
| 9 | 11 | import org.activiti.engine.runtime.ProcessInstance; |
| 10 | 12 | import org.activiti.engine.task.Task; |
| ... | ... | @@ -61,4 +63,28 @@ public interface BpmTaskConvert { |
| 61 | 63 | SuspensionState.ACTIVE.getStateCode(); |
| 62 | 64 | } |
| 63 | 65 | |
| 66 | + default List<BpmTaskDonePageItemRespVO> convertList2(List<HistoricTaskInstance> tasks, | |
| 67 | + Map<String, ProcessInstance> processInstanceMap, | |
| 68 | + Map<Long, SysUserDO> userMap) { | |
| 69 | + return CollectionUtils.convertList(tasks, task -> { | |
| 70 | + ProcessInstance processInstance = processInstanceMap.get(task.getProcessInstanceId()); | |
| 71 | + return convert(task, processInstance, userMap.get(Long.valueOf(processInstance.getStartUserId()))); | |
| 72 | + }); | |
| 73 | + } | |
| 74 | + | |
| 75 | + @Mappings({ | |
| 76 | + @Mapping(source = "task.id", target = "id"), | |
| 77 | + @Mapping(source = "task.name", target = "name"), | |
| 78 | + @Mapping(source = "task.claimTime", target = "claimTime"), | |
| 79 | + @Mapping(source = "task.createTime", target = "createTime"), | |
| 80 | + @Mapping(source = "task.endTime", target = "endTime"), | |
| 81 | + @Mapping(source = "task.durationInMillis", target = "durationInMillis"), | |
| 82 | + @Mapping(source = "processInstance.id", target = "processInstance.id"), | |
| 83 | + @Mapping(source = "processInstance.name", target = "processInstance.name"), | |
| 84 | + @Mapping(source = "processInstance.startUserId", target = "processInstance.startUserId"), | |
| 85 | + @Mapping(source = "processInstance.processDefinitionId", target = "processInstance.processDefinitionId"), | |
| 86 | + @Mapping(source = "user.nickname", target = "processInstance.startUserNickname") | |
| 87 | + }) | |
| 88 | + BpmTaskDonePageItemRespVO convert(HistoricTaskInstance task, ProcessInstance processInstance, SysUserDO user); | |
| 89 | + | |
| 64 | 90 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java
| ... | ... | @@ -44,7 +44,7 @@ public interface BpmTaskService { |
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | - * 获得流程任务分页 | |
| 47 | + * 获得待办的流程任务分页 | |
| 48 | 48 | * |
| 49 | 49 | * @param userId 用户编号 |
| 50 | 50 | * @param pageReqVO 分页请求 |
| ... | ... | @@ -53,6 +53,15 @@ public interface BpmTaskService { |
| 53 | 53 | PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageReqVO); |
| 54 | 54 | |
| 55 | 55 | /** |
| 56 | + * 获得已办的流程任务分页 | |
| 57 | + * | |
| 58 | + * @param userId 用户编号 | |
| 59 | + * @param pageReqVO 分页请求 | |
| 60 | + * @return 流程任务分页 | |
| 61 | + */ | |
| 62 | + PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageReqVO); | |
| 63 | + | |
| 64 | + /** | |
| 56 | 65 | * 将流程任务分配给指定用户 |
| 57 | 66 | * |
| 58 | 67 | * @param id 流程任务编号 | ... | ... |
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; |
| 23 | 23 | import org.activiti.engine.TaskService; |
| 24 | 24 | import org.activiti.engine.history.HistoricActivityInstance; |
| 25 | 25 | import org.activiti.engine.history.HistoricProcessInstance; |
| 26 | +import org.activiti.engine.history.HistoricTaskInstance; | |
| 27 | +import org.activiti.engine.history.HistoricTaskInstanceQuery; | |
| 26 | 28 | import org.activiti.engine.repository.ProcessDefinition; |
| 27 | 29 | import org.activiti.engine.runtime.ProcessInstance; |
| 28 | 30 | import org.activiti.engine.task.Comment; |
| ... | ... | @@ -83,7 +85,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 83 | 85 | public PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) { |
| 84 | 86 | // 查询待办任务 |
| 85 | 87 | TaskQuery taskQuery = taskService.createTaskQuery() |
| 86 | - .taskAssignee(String.valueOf(userId)); | |
| 88 | + .taskAssignee(String.valueOf(userId)) // 分配给自己 | |
| 89 | + .orderByTaskCreateTime().desc(); // 创建时间倒序 | |
| 87 | 90 | if (StrUtil.isNotBlank(pageVO.getName())) { |
| 88 | 91 | taskQuery.taskNameLike("%" + pageVO.getName() + "%"); |
| 89 | 92 | } |
| ... | ... | @@ -94,8 +97,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 94 | 97 | taskQuery.taskCreatedBefore(pageVO.getEndCreateTime()); |
| 95 | 98 | } |
| 96 | 99 | // 执行查询 |
| 97 | - List<Task> tasks = taskQuery.orderByTaskCreateTime().desc() // 创建时间倒序 | |
| 98 | - .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); | |
| 100 | + List<Task> tasks = taskQuery.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); | |
| 99 | 101 | if (CollUtil.isEmpty(tasks)) { |
| 100 | 102 | return PageResult.empty(taskQuery.count()); |
| 101 | 103 | } |
| ... | ... | @@ -103,7 +105,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 103 | 105 | // 获得 ProcessInstance Map |
| 104 | 106 | Map<String, ProcessInstance> processInstanceMap = processInstanceService.getProcessInstanceMap( |
| 105 | 107 | convertSet(tasks, Task::getProcessInstanceId)); |
| 106 | - | |
| 107 | 108 | // 获得 User Map |
| 108 | 109 | Map<Long, SysUserDO> userMap = userService.getUserMap( |
| 109 | 110 | convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId()))); |
| ... | ... | @@ -113,6 +114,39 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 113 | 114 | } |
| 114 | 115 | |
| 115 | 116 | @Override |
| 117 | + public PageResult<BpmTaskDonePageItemRespVO> getDoneTaskPage(Long userId, BpmTaskDonePageReqVO pageVO) { | |
| 118 | + // 查询已办任务 | |
| 119 | + HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery() | |
| 120 | + .finished() // 已完成 | |
| 121 | + .taskAssignee(String.valueOf(userId)) // 分配给自己 | |
| 122 | + .orderByHistoricTaskInstanceEndTime().desc(); // 审批时间倒序 | |
| 123 | + if (StrUtil.isNotBlank(pageVO.getName())) { | |
| 124 | + taskQuery.taskNameLike("%" + pageVO.getName() + "%"); | |
| 125 | + } | |
| 126 | + if (pageVO.getBeginCreateTime() != null) { | |
| 127 | + taskQuery.taskCreatedAfter(pageVO.getBeginCreateTime()); | |
| 128 | + } | |
| 129 | + if (pageVO.getEndCreateTime() != null) { | |
| 130 | + taskQuery.taskCreatedBefore(pageVO.getEndCreateTime()); | |
| 131 | + } | |
| 132 | + // 执行查询 | |
| 133 | + List<HistoricTaskInstance> tasks = taskQuery.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); | |
| 134 | + if (CollUtil.isEmpty(tasks)) { | |
| 135 | + return PageResult.empty(taskQuery.count()); | |
| 136 | + } | |
| 137 | + | |
| 138 | + // 获得 ProcessInstance Map | |
| 139 | + Map<String, ProcessInstance> processInstanceMap = processInstanceService.getProcessInstanceMap( | |
| 140 | + convertSet(tasks, HistoricTaskInstance::getProcessInstanceId)); | |
| 141 | + // 获得 User Map | |
| 142 | + Map<Long, SysUserDO> userMap = userService.getUserMap( | |
| 143 | + convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId()))); | |
| 144 | + // 拼接结果 | |
| 145 | + return new PageResult<>(BpmTaskConvert.INSTANCE.convertList2(tasks, processInstanceMap, userMap), | |
| 146 | + taskQuery.count()); | |
| 147 | + } | |
| 148 | + | |
| 149 | + @Override | |
| 116 | 150 | public void updateTaskAssign(String id, Long userId) { |
| 117 | 151 | taskService.setAssignee(id, String.valueOf(userId)); |
| 118 | 152 | } |
| ... | ... | @@ -122,11 +156,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 122 | 156 | |
| 123 | 157 | } |
| 124 | 158 | |
| 125 | - // 任务编号、流程名称、任务节点、流程发起人、接收时间、审批时间、耗时【名称、开始时间】「流程记录、撤回」 | |
| 126 | - // 任务编号、任务名称、所属流程、委托代办人、流程发起人、优先级、审批操作、审批意见、耗时、创建时间【名称、开始时间】「申请详情」 | |
| 127 | - | |
| 128 | - // 任务编号、任务名称、流程名称、流程发起人、接收时间、审批时间、耗时【名称、接收时间】「详情」TODO 撤回 | |
| 129 | - | |
| 130 | 159 | @Override |
| 131 | 160 | @Transactional |
| 132 | 161 | public void completeTask(TaskReqVO taskReq) { |
| ... | ... | @@ -139,8 +168,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 139 | 168 | // .build()); |
| 140 | 169 | } |
| 141 | 170 | |
| 142 | - | |
| 143 | - | |
| 144 | 171 | @Override |
| 145 | 172 | public TaskHandleVO getTaskSteps(TaskQueryReqVO taskQuery) { |
| 146 | 173 | // TaskHandleVO handleVO = new TaskHandleVO(); | ... | ... |