Commit b083795ad6d35f64ddc36992b2abca177045b8ed
1 parent
1ab15dd1
实现 bpm 待办任务的后端接口
Showing
18 changed files
with
299 additions
and
160 deletions
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.http
0 → 100644
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/TaskController.java renamed to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/BpmTaskController.java
| ... | ... | @@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.util.servlet.ServletUtils; |
| 8 | 8 | import io.swagger.annotations.Api; |
| 9 | 9 | import io.swagger.annotations.ApiOperation; |
| 10 | +import org.springframework.validation.annotation.Validated; | |
| 10 | 11 | import org.springframework.web.bind.annotation.*; |
| 11 | 12 | |
| 12 | 13 | import javax.annotation.Resource; |
| ... | ... | @@ -16,48 +17,39 @@ import java.io.IOException; |
| 16 | 17 | import java.util.List; |
| 17 | 18 | |
| 18 | 19 | import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; |
| 20 | +import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; | |
| 19 | 21 | |
| 20 | -// TODO @json:swagger 和 validation 的注解,后续要补全下哈。可以等 workflow 基本写的差不多之后 | |
| 21 | -@Api(tags = "工作流待办任务") | |
| 22 | +@Api(tags = "流程任务") | |
| 22 | 23 | @RestController |
| 23 | -@RequestMapping("/workflow/task") | |
| 24 | -public class TaskController { | |
| 24 | +@RequestMapping("/bpm/task") | |
| 25 | +@Validated | |
| 26 | +public class BpmTaskController { | |
| 25 | 27 | |
| 26 | 28 | @Resource |
| 27 | - private BpmTaskService bpmTaskService; | |
| 29 | + private BpmTaskService taskService; | |
| 28 | 30 | |
| 29 | - @GetMapping("/todo/page") | |
| 30 | - @ApiOperation("获取待办任务分页") | |
| 31 | - public CommonResult<PageResult<TodoTaskRespVO>> getTodoTaskPage(@Valid TodoTaskPageReqVO pageVO) { | |
| 32 | - return success(bpmTaskService.getTodoTaskPage(pageVO)); | |
| 33 | - } | |
| 31 | + // TODO 芋艿:权限、validation; | |
| 34 | 32 | |
| 35 | - @GetMapping("/claim") | |
| 36 | - @ApiOperation("签收任务") | |
| 37 | - public CommonResult<Boolean> claimTask(@RequestParam("id") String taskId) { | |
| 38 | - bpmTaskService.claimTask(taskId); | |
| 39 | - return success(true); | |
| 33 | + @GetMapping("todo-page") | |
| 34 | + @ApiOperation("获取 TODO 待办任务分页") | |
| 35 | + public CommonResult<PageResult<BpmTaskTodoPageItemRespVO>> getTodoTaskPage(@Valid BpmTaskTodoPageReqVO pageVO) { | |
| 36 | + return success(taskService.getTodoTaskPage(getLoginUserId(), pageVO)); | |
| 40 | 37 | } |
| 41 | 38 | |
| 42 | 39 | @PostMapping("/task-steps") |
| 43 | 40 | public CommonResult<TaskHandleVO> getTaskSteps(@RequestBody TaskQueryReqVO taskQuery) { |
| 44 | - return success(bpmTaskService.getTaskSteps(taskQuery)); | |
| 45 | - } | |
| 46 | - | |
| 47 | - @PostMapping("/formKey") | |
| 48 | - public CommonResult<TodoTaskRespVO> getTaskFormKey(@RequestBody TaskQueryReqVO taskQuery) { | |
| 49 | - return success(bpmTaskService.getTaskFormKey(taskQuery)); | |
| 41 | + return success(taskService.getTaskSteps(taskQuery)); | |
| 50 | 42 | } |
| 51 | 43 | |
| 52 | 44 | @PostMapping("/complete") |
| 53 | 45 | public CommonResult<Boolean> complete(@RequestBody TaskReqVO taskReq) { |
| 54 | - bpmTaskService.completeTask(taskReq); | |
| 46 | + taskService.completeTask(taskReq); | |
| 55 | 47 | return success(true); |
| 56 | 48 | } |
| 57 | 49 | |
| 58 | 50 | @GetMapping("/process/history-steps") |
| 59 | 51 | public CommonResult<List<TaskStepVO>> getHistorySteps(@RequestParam("id") String processInstanceId) { |
| 60 | - return success(bpmTaskService.getHistorySteps(processInstanceId)); | |
| 52 | + return success(taskService.getHistorySteps(processInstanceId)); | |
| 61 | 53 | } |
| 62 | 54 | |
| 63 | 55 | /** |
| ... | ... | @@ -66,7 +58,7 @@ public class TaskController { |
| 66 | 58 | */ |
| 67 | 59 | @GetMapping("/process/highlight-img") |
| 68 | 60 | public void getHighlightImg(@RequestParam String processInstanceId, HttpServletResponse response) throws IOException { |
| 69 | - FileResp fileResp = bpmTaskService.getHighlightImg(processInstanceId); | |
| 61 | + FileResp fileResp = taskService.getHighlightImg(processInstanceId); | |
| 70 | 62 | ServletUtils.writeAttachment(response, fileResp.getFileName(), fileResp.getFileByte()); |
| 71 | 63 | } |
| 72 | 64 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskTodoPageItemRespVO.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(value = "流程任务的 Running 进行中的分页项 Response VO", description = "待办任务") | |
| 10 | +@Data | |
| 11 | +public class BpmTaskTodoPageItemRespVO { | |
| 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 = "任务状态", notes = "参见 bpm_process_instance_status", example = "1") | |
| 23 | + private Integer status; | |
| 24 | + | |
| 25 | + /** | |
| 26 | + * 所属流程实例 | |
| 27 | + */ | |
| 28 | + private ProcessInstance processInstance; | |
| 29 | + | |
| 30 | + @Data | |
| 31 | + @ApiModel("流程实例") | |
| 32 | + public static class ProcessInstance { | |
| 33 | + | |
| 34 | + @ApiModelProperty(value = "流程实例编号", required = true, example = "1024") | |
| 35 | + private String id; | |
| 36 | + | |
| 37 | + @ApiModelProperty(value = "发起人的用户编号", required = true, example = "1024") | |
| 38 | + private Long startUserId; | |
| 39 | + | |
| 40 | + @ApiModelProperty(value = "发起人的用户昵称", required = true, example = "芋艿") | |
| 41 | + private String startUserNickname; | |
| 42 | + | |
| 43 | + @ApiModelProperty(value = "流程定义的编号", required = true, example = "2048") | |
| 44 | + private String processDefinitionId; | |
| 45 | + | |
| 46 | + } | |
| 47 | + | |
| 48 | + // 任务编号、任务名称、任务节点、流程版本、流程发起人、接收时间【名称、开始时间】「处理」 | |
| 49 | + // 任务编号、任务名称、所属流程、委托代办人、流程发起人、优先级、状态、创建时间【名称、开始时间】「申请详情、通过、驳回、转办、历史」 | |
| 50 | + | |
| 51 | + // 任务编号、任务名称、流程名称、流程发起人、接收时间、状态【名称、接收时间】【处理、委托】 | |
| 52 | +} | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/TodoTaskPageReqVO.java renamed to yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/BpmTaskTodoPageReqVO.java
| ... | ... | @@ -2,15 +2,31 @@ package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.common.pojo.PageParam; |
| 4 | 4 | import io.swagger.annotations.ApiModel; |
| 5 | +import io.swagger.annotations.ApiModelProperty; | |
| 5 | 6 | import lombok.Data; |
| 6 | 7 | import lombok.EqualsAndHashCode; |
| 7 | 8 | import lombok.ToString; |
| 9 | +import org.springframework.format.annotation.DateTimeFormat; | |
| 8 | 10 | |
| 9 | -@ApiModel("待办任务申请分页 Request VO") | |
| 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("流程任务的 TODO 待办的分页 Request VO") | |
| 10 | 16 | @Data |
| 11 | 17 | @EqualsAndHashCode(callSuper = true) |
| 12 | 18 | @ToString(callSuper = true) |
| 13 | -public class TodoTaskPageReqVO extends PageParam { | |
| 19 | +public class BpmTaskTodoPageReqVO 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; | |
| 14 | 31 | |
| 15 | - private String assignee; | |
| 16 | 32 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/controller/task/vo/task/TodoTaskRespVO.java deleted
| 1 | -package cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task; | |
| 2 | - | |
| 3 | -import io.swagger.annotations.ApiModel; | |
| 4 | -import lombok.Data; | |
| 5 | -import lombok.ToString; | |
| 6 | - | |
| 7 | -@ApiModel("待办任务 Response VO") | |
| 8 | -@Data | |
| 9 | -@ToString | |
| 10 | -public class TodoTaskRespVO { | |
| 11 | - | |
| 12 | - // TODO @jason:swagger 注解。这样接口文档才完整哈 | |
| 13 | - | |
| 14 | - private String id; | |
| 15 | - | |
| 16 | - | |
| 17 | - private String processInstanceId; | |
| 18 | - | |
| 19 | - /** | |
| 20 | - * 1:未签收 | |
| 21 | - * 2:已签收 | |
| 22 | - */ | |
| 23 | - private Integer status; | |
| 24 | - | |
| 25 | - | |
| 26 | - private String processName; | |
| 27 | - | |
| 28 | - | |
| 29 | - private String processKey; | |
| 30 | - | |
| 31 | - | |
| 32 | - private String businessKey; | |
| 33 | - | |
| 34 | - | |
| 35 | - private String formKey; | |
| 36 | - | |
| 37 | -} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmProcessInstanceConvert.java
| ... | ... | @@ -26,7 +26,7 @@ public interface BpmProcessInstanceConvert { |
| 26 | 26 | BpmProcessInstanceConvert INSTANCE = Mappers.getMapper(BpmProcessInstanceConvert.class); |
| 27 | 27 | |
| 28 | 28 | @Mappings({ |
| 29 | - @Mapping(source = "instance.startUserId", target = "userId"), | |
| 29 | + @Mapping(source = "instance.startUserId", target = "startUserId"), | |
| 30 | 30 | @Mapping(source = "instance.id", target = "processInstanceId"), |
| 31 | 31 | @Mapping(source = "instance.startTime", target = "createTime"), |
| 32 | 32 | @Mapping(source = "definition.id", target = "processDefinitionId"), | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/BpmTaskConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.adminserver.modules.bpm.convert.task; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.BpmTaskTodoPageItemRespVO; | |
| 4 | +import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.TaskStepVO; | |
| 5 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | |
| 6 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 7 | +import org.activiti.engine.history.HistoricActivityInstance; | |
| 8 | +import org.activiti.engine.impl.persistence.entity.SuspensionState; | |
| 9 | +import org.activiti.engine.runtime.ProcessInstance; | |
| 10 | +import org.activiti.engine.task.Task; | |
| 11 | +import org.mapstruct.Mapper; | |
| 12 | +import org.mapstruct.Mapping; | |
| 13 | +import org.mapstruct.Mappings; | |
| 14 | +import org.mapstruct.Named; | |
| 15 | +import org.mapstruct.factory.Mappers; | |
| 16 | + | |
| 17 | +import java.util.List; | |
| 18 | +import java.util.Map; | |
| 19 | + | |
| 20 | +/** | |
| 21 | + * Bpm 任务 Convert | |
| 22 | + * | |
| 23 | + * @author 芋道源码 | |
| 24 | + */ | |
| 25 | +@Mapper | |
| 26 | +public interface BpmTaskConvert { | |
| 27 | + | |
| 28 | + BpmTaskConvert INSTANCE = Mappers.getMapper(BpmTaskConvert.class); | |
| 29 | + | |
| 30 | + @Mappings(value = { | |
| 31 | + @Mapping(source = "activityName", target = "stepName"), | |
| 32 | + @Mapping(source = "assignee", target = "assignee") | |
| 33 | + }) | |
| 34 | + TaskStepVO convert(HistoricActivityInstance instance); | |
| 35 | + | |
| 36 | + default List<BpmTaskTodoPageItemRespVO> convertList(List<Task> tasks, Map<String, ProcessInstance> processInstanceMap, | |
| 37 | + Map<Long, SysUserDO> userMap) { | |
| 38 | + return CollectionUtils.convertList(tasks, task -> { | |
| 39 | + ProcessInstance processInstance = processInstanceMap.get(task.getProcessInstanceId()); | |
| 40 | + return convert(task, processInstance, userMap.get(Long.valueOf(processInstance.getStartUserId()))); | |
| 41 | + }); | |
| 42 | + } | |
| 43 | + | |
| 44 | + @Mappings({ | |
| 45 | + @Mapping(source = "task.id", target = "id"), | |
| 46 | + @Mapping(source = "task.name", target = "name"), | |
| 47 | + @Mapping(source = "task.claimTime", target = "claimTime"), | |
| 48 | + @Mapping(source = "task.suspended", target = "status", qualifiedByName = "convertSuspendedToStatus"), | |
| 49 | + @Mapping(source = "processInstance.id", target = "processInstance.id"), | |
| 50 | + @Mapping(source = "processInstance.startUserId", target = "processInstance.startUserId"), | |
| 51 | + @Mapping(source = "processInstance.processDefinitionId", target = "processInstance.processDefinitionId"), | |
| 52 | + @Mapping(source = "user.nickname", target = "processInstance.startUserNickname") | |
| 53 | + }) | |
| 54 | + BpmTaskTodoPageItemRespVO convert(Task task, ProcessInstance processInstance, SysUserDO user); | |
| 55 | + | |
| 56 | + @Named("convertSuspendedToStatus") | |
| 57 | + default Integer convertAssigneeToStatus(boolean suspended) { | |
| 58 | + return suspended ? SuspensionState.SUSPENDED.getStateCode() : | |
| 59 | + SuspensionState.ACTIVE.getStateCode(); | |
| 60 | + } | |
| 61 | + | |
| 62 | +} | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/convert/task/TaskConvert.java deleted
| 1 | -package cn.iocoder.yudao.adminserver.modules.bpm.convert.task; | |
| 2 | - | |
| 3 | -import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.TaskStepVO; | |
| 4 | -import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.TodoTaskRespVO; | |
| 5 | -import org.activiti.api.task.model.Task; | |
| 6 | -import org.activiti.engine.history.HistoricActivityInstance; | |
| 7 | -import org.activiti.engine.repository.ProcessDefinition; | |
| 8 | -import org.mapstruct.Mapper; | |
| 9 | -import org.mapstruct.Mapping; | |
| 10 | -import org.mapstruct.Mappings; | |
| 11 | -import org.mapstruct.Named; | |
| 12 | -import org.mapstruct.factory.Mappers; | |
| 13 | - | |
| 14 | -@Mapper | |
| 15 | -public interface TaskConvert { | |
| 16 | - TaskConvert INSTANCE = Mappers.getMapper(TaskConvert.class); | |
| 17 | - | |
| 18 | - @Mappings(value = { | |
| 19 | - @Mapping(source = "task.id", target = "id"), | |
| 20 | - @Mapping(source = "task.businessKey", target = "businessKey"), | |
| 21 | - @Mapping(source = "task.assignee", target = "status",qualifiedByName = "convertAssigneeToStatus"), | |
| 22 | - @Mapping(source = "definition.name", target = "processName"), | |
| 23 | - @Mapping(source = "definition.key", target = "processKey"), | |
| 24 | - @Mapping(source = "definition.id", target = "processInstanceId") | |
| 25 | - }) | |
| 26 | - TodoTaskRespVO convert(Task task, ProcessDefinition definition); | |
| 27 | - | |
| 28 | - @Mappings(value = { | |
| 29 | - @Mapping(source = "assignee", target = "status",qualifiedByName = "convertAssigneeToStatus") | |
| 30 | - }) | |
| 31 | - TodoTaskRespVO convert(Task task); | |
| 32 | - | |
| 33 | - @Named("convertAssigneeToStatus") | |
| 34 | - default Integer convertAssigneeToStatus(String assignee) { | |
| 35 | - //TODO 不应该通过 assignee 定义状态 需要定义更多的状态 | |
| 36 | - return assignee == null ? 1 : 2; | |
| 37 | - } | |
| 38 | - | |
| 39 | - @Mappings(value = { | |
| 40 | - @Mapping(source = "activityName", target = "stepName"), | |
| 41 | - @Mapping(source = "assignee", target = "assignee") | |
| 42 | - }) | |
| 43 | - TaskStepVO convert(HistoricActivityInstance instance); | |
| 44 | -} |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/dataobject/task/BpmProcessInstanceExtDO.java
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/dal/mysql/task/BpmProcessInstanceExtMapper.java
| ... | ... | @@ -12,7 +12,7 @@ public interface BpmProcessInstanceExtMapper extends BaseMapperX<BpmProcessInsta |
| 12 | 12 | |
| 13 | 13 | default PageResult<BpmProcessInstanceExtDO> selectPage(Long userId, BpmProcessInstanceMyPageReqVO reqVO) { |
| 14 | 14 | return selectPage(reqVO, new QueryWrapperX<BpmProcessInstanceExtDO>() |
| 15 | - .eqIfPresent("user_id", userId) | |
| 15 | + .eqIfPresent("start_user_id", userId) | |
| 16 | 16 | .likeIfPresent("name", reqVO.getName()) |
| 17 | 17 | .eqIfPresent("process_definition_id", reqVO.getProcessDefinitionId()) |
| 18 | 18 | .eqIfPresent("category", reqVO.getCategory()) | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmProcessInstanceService.java
| ... | ... | @@ -4,8 +4,13 @@ import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmP |
| 4 | 4 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstanceMyPageReqVO; |
| 5 | 5 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.instance.BpmProcessInstancePageItemRespVO; |
| 6 | 6 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 7 | +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; | |
| 8 | +import org.activiti.engine.runtime.ProcessInstance; | |
| 7 | 9 | |
| 8 | 10 | import javax.validation.Valid; |
| 11 | +import java.util.List; | |
| 12 | +import java.util.Map; | |
| 13 | +import java.util.Set; | |
| 9 | 14 | |
| 10 | 15 | /** |
| 11 | 16 | * 流程实例 Service 接口 |
| ... | ... | @@ -33,4 +38,22 @@ public interface BpmProcessInstanceService { |
| 33 | 38 | PageResult<BpmProcessInstancePageItemRespVO> getMyProcessInstancePage(Long userId, |
| 34 | 39 | @Valid BpmProcessInstanceMyPageReqVO pageReqVO); |
| 35 | 40 | |
| 41 | + /** | |
| 42 | + * 获得流程实例列表 | |
| 43 | + * | |
| 44 | + * @param ids 流程实例的编号集合 | |
| 45 | + * @return 流程实例列表 | |
| 46 | + */ | |
| 47 | + List<ProcessInstance> getProcessInstances(Set<String> ids); | |
| 48 | + | |
| 49 | + /** | |
| 50 | + * 获得流程实例 Map | |
| 51 | + * | |
| 52 | + * @param ids 流程实例的编号集合 | |
| 53 | + * @return 流程实例列表 Map | |
| 54 | + */ | |
| 55 | + default Map<String, ProcessInstance> getProcessInstanceMap(Set<String> ids) { | |
| 56 | + return CollectionUtils.convertMap(getProcessInstances(ids), ProcessInstance::getProcessInstanceId); | |
| 57 | + } | |
| 58 | + | |
| 36 | 59 | } | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/BpmTaskService.java
| 1 | 1 | package cn.iocoder.yudao.adminserver.modules.bpm.service.task; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.collection.CollUtil; | |
| 4 | 3 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.*; |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| ... | ... | @@ -8,7 +7,6 @@ import org.activiti.engine.task.Task; |
| 8 | 7 | |
| 9 | 8 | import java.util.List; |
| 10 | 9 | import java.util.Map; |
| 11 | -import java.util.Set; | |
| 12 | 10 | |
| 13 | 11 | /** |
| 14 | 12 | * 工作任务 Service 接口 |
| ... | ... | @@ -21,6 +19,14 @@ public interface BpmTaskService { |
| 21 | 19 | /** |
| 22 | 20 | * 获得流程任务列表 |
| 23 | 21 | * |
| 22 | + * @param processInstanceId 流程实例的编号 | |
| 23 | + * @return 流程任务列表 | |
| 24 | + */ | |
| 25 | + List<Task> getTasksByProcessInstanceId(String processInstanceId); | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * 获得流程任务列表 | |
| 29 | + * | |
| 24 | 30 | * @param processInstanceIds 流程实例的编号数组 |
| 25 | 31 | * @return 流程任务列表 |
| 26 | 32 | */ |
| ... | ... | @@ -38,15 +44,28 @@ public interface BpmTaskService { |
| 38 | 44 | } |
| 39 | 45 | |
| 40 | 46 | /** |
| 41 | - * 获取当前用户的待办任务, 分页 | |
| 47 | + * 获得流程任务分页 | |
| 48 | + * | |
| 49 | + * @param userId 用户编号 | |
| 50 | + * @param pageReqVO 分页请求 | |
| 51 | + * @return 流程任务分页 | |
| 52 | + */ | |
| 53 | + PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageReqVO); | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * 将流程任务分配给指定用户 | |
| 57 | + * | |
| 58 | + * @param id 流程任务编号 | |
| 59 | + * @param userId 用户编号 | |
| 42 | 60 | */ |
| 43 | - PageResult<TodoTaskRespVO> getTodoTaskPage(TodoTaskPageReqVO pageReqVO); | |
| 61 | + void updateTaskAssign(String id, Long userId); | |
| 44 | 62 | |
| 45 | 63 | /** |
| 46 | 64 | * 签收任务 |
| 47 | - * @param taskId 用户任务id | |
| 65 | + * | |
| 66 | + * @param id 任务编号 | |
| 48 | 67 | */ |
| 49 | - void claimTask(String taskId); | |
| 68 | + void claimTask(String id); | |
| 50 | 69 | |
| 51 | 70 | /** |
| 52 | 71 | * 工作流,完成 userTask, 完成用户任务 一般传入参数 1。是否同意(variables). 2. 评论(comment) |
| ... | ... | @@ -68,13 +87,6 @@ public interface BpmTaskService { |
| 68 | 87 | List<TaskStepVO> getHistorySteps(String processInstanceId); |
| 69 | 88 | |
| 70 | 89 | /** |
| 71 | - * 获取用户任务的 formKey, 对应外置表单, 需要根据formKey 对应业务表单 | |
| 72 | - * @param taskQuery 查询参数 ,一般taskId | |
| 73 | - */ | |
| 74 | - TodoTaskRespVO getTaskFormKey(TaskQueryReqVO taskQuery); | |
| 75 | - | |
| 76 | - | |
| 77 | - /** | |
| 78 | 90 | * 返回高亮的流转进程 |
| 79 | 91 | * @param processInstanceId 实例Id |
| 80 | 92 | * @return {@link FileResp} 返回文件 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmProcessInstanceServiceImpl.java
| ... | ... | @@ -26,12 +26,16 @@ import org.activiti.engine.history.HistoricProcessInstanceQuery; |
| 26 | 26 | import org.activiti.engine.repository.ProcessDefinition; |
| 27 | 27 | import org.activiti.engine.runtime.ProcessInstance; |
| 28 | 28 | import org.activiti.engine.task.Task; |
| 29 | +import org.springframework.context.annotation.Lazy; | |
| 29 | 30 | import org.springframework.stereotype.Service; |
| 31 | +import org.springframework.transaction.annotation.Transactional; | |
| 30 | 32 | import org.springframework.validation.annotation.Validated; |
| 31 | 33 | |
| 32 | 34 | import javax.annotation.Resource; |
| 33 | 35 | import java.util.List; |
| 34 | 36 | import java.util.Map; |
| 37 | +import java.util.Set; | |
| 38 | +import java.util.function.Consumer; | |
| 35 | 39 | |
| 36 | 40 | import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.PROCESS_DEFINITION_IS_SUSPENDED; |
| 37 | 41 | import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.PROCESS_DEFINITION_NOT_EXISTS; |
| ... | ... | @@ -58,20 +62,21 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 58 | 62 | @Resource |
| 59 | 63 | private RuntimeService runtimeService; |
| 60 | 64 | @Resource |
| 61 | - private BpmTaskService taskService; | |
| 62 | - @Resource | |
| 63 | 65 | private HistoryService historyService; |
| 64 | 66 | |
| 65 | 67 | @Resource |
| 66 | 68 | private SysUserService userService; |
| 67 | 69 | @Resource |
| 70 | + @Lazy // 解决循环依赖 | |
| 71 | + private BpmTaskService taskService; | |
| 72 | + @Resource | |
| 68 | 73 | private BpmProcessDefinitionService processDefinitionService; |
| 69 | 74 | |
| 70 | 75 | @Resource |
| 71 | 76 | private BpmProcessInstanceExtMapper processInstanceExtMapper; |
| 72 | 77 | |
| 73 | 78 | @Override |
| 74 | -// @Transactional(rollbackFor = Exception.class) | |
| 79 | + @Transactional(rollbackFor = Exception.class) | |
| 75 | 80 | public String createProcessInstance(Long userId, BpmProcessInstanceCreateReqVO createReqVO) { |
| 76 | 81 | // 校验流程定义 |
| 77 | 82 | ProcessDefinition definition = processDefinitionService.getProcessDefinition(createReqVO.getProcessDefinitionId()); |
| ... | ... | @@ -90,6 +95,10 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 90 | 95 | // 记录流程实例的拓展表 |
| 91 | 96 | createProcessInstanceExt(instance, definition); |
| 92 | 97 | |
| 98 | + // TODO 芋艿:临时使用, 保证分配 | |
| 99 | + List<Task> tasks = taskService.getTasksByProcessInstanceId(instance.getId()); | |
| 100 | + tasks.forEach(task -> taskService.updateTaskAssign(task.getId(), userId)); | |
| 101 | + | |
| 93 | 102 | // 添加初始的评论 TODO 芋艿:在思考下 |
| 94 | 103 | // Task task = taskService.createTaskQuery().processInstanceId(instance.getId()).singleResult(); |
| 95 | 104 | // if (task != null) { |
| ... | ... | @@ -134,6 +143,11 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService |
| 134 | 143 | return BpmProcessInstanceConvert.INSTANCE.convertPage(pageResult, taskMap); |
| 135 | 144 | } |
| 136 | 145 | |
| 146 | + @Override | |
| 147 | + public List<ProcessInstance> getProcessInstances(Set<String> ids) { | |
| 148 | + return runtimeService.createProcessInstanceQuery().processInstanceIds(ids).list(); | |
| 149 | + } | |
| 150 | + | |
| 137 | 151 | /** |
| 138 | 152 | * 获得流程实例 |
| 139 | 153 | * | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/bpm/service/task/impl/BpmTaskServiceImpl.java
| ... | ... | @@ -2,16 +2,17 @@ package cn.iocoder.yudao.adminserver.modules.bpm.service.task.impl; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.io.IoUtil; |
| 5 | +import cn.hutool.core.util.StrUtil; | |
| 5 | 6 | import cn.iocoder.yudao.adminserver.modules.bpm.controller.task.vo.task.*; |
| 6 | -import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.TaskConvert; | |
| 7 | +import cn.iocoder.yudao.adminserver.modules.bpm.convert.task.BpmTaskConvert; | |
| 8 | +import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmProcessInstanceService; | |
| 7 | 9 | import cn.iocoder.yudao.adminserver.modules.bpm.service.task.BpmTaskService; |
| 10 | +import cn.iocoder.yudao.adminserver.modules.system.service.user.SysUserService; | |
| 11 | +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; | |
| 8 | 12 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 9 | 13 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 10 | -import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils; | |
| 14 | +import cn.iocoder.yudao.framework.common.util.object.PageUtils; | |
| 11 | 15 | import lombok.extern.slf4j.Slf4j; |
| 12 | -import org.activiti.api.task.model.builders.ClaimTaskPayloadBuilder; | |
| 13 | -import org.activiti.api.task.model.builders.TaskPayloadBuilder; | |
| 14 | -import org.activiti.api.task.runtime.TaskRuntime; | |
| 15 | 16 | import org.activiti.bpmn.constants.BpmnXMLConstants; |
| 16 | 17 | import org.activiti.bpmn.model.BpmnModel; |
| 17 | 18 | import org.activiti.bpmn.model.FlowNode; |
| ... | ... | @@ -26,7 +27,9 @@ import org.activiti.engine.repository.ProcessDefinition; |
| 26 | 27 | import org.activiti.engine.runtime.ProcessInstance; |
| 27 | 28 | import org.activiti.engine.task.Comment; |
| 28 | 29 | import org.activiti.engine.task.Task; |
| 30 | +import org.activiti.engine.task.TaskQuery; | |
| 29 | 31 | import org.activiti.image.ProcessDiagramGenerator; |
| 32 | +import org.springframework.context.annotation.Lazy; | |
| 30 | 33 | import org.springframework.stereotype.Service; |
| 31 | 34 | import org.springframework.transaction.annotation.Transactional; |
| 32 | 35 | import org.springframework.util.ObjectUtils; |
| ... | ... | @@ -39,14 +42,13 @@ import java.util.*; |
| 39 | 42 | import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.HIGHLIGHT_IMG_ERROR; |
| 40 | 43 | import static cn.iocoder.yudao.adminserver.modules.bpm.enums.BpmErrorCodeConstants.PROCESS_INSTANCE_NOT_EXISTS; |
| 41 | 44 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 45 | +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; | |
| 42 | 46 | |
| 43 | 47 | @Slf4j |
| 44 | 48 | @Service |
| 45 | 49 | public class BpmTaskServiceImpl implements BpmTaskService { |
| 46 | 50 | |
| 47 | 51 | @Resource |
| 48 | - private TaskRuntime taskRuntime; | |
| 49 | - @Resource | |
| 50 | 52 | private TaskService taskService; |
| 51 | 53 | @Resource |
| 52 | 54 | private RuntimeService runtimeService; |
| ... | ... | @@ -58,6 +60,17 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 58 | 60 | @Resource |
| 59 | 61 | private ProcessDiagramGenerator processDiagramGenerator; |
| 60 | 62 | |
| 63 | + @Resource | |
| 64 | + private SysUserService userService; | |
| 65 | + @Resource | |
| 66 | + @Lazy // 解决循环依赖 | |
| 67 | + private BpmProcessInstanceService processInstanceService; | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public List<Task> getTasksByProcessInstanceId(String processInstanceId) { | |
| 71 | + return taskService.createTaskQuery().processInstanceId(processInstanceId).list(); | |
| 72 | + } | |
| 73 | + | |
| 61 | 74 | @Override |
| 62 | 75 | public List<Task> getTasksByProcessInstanceIds(List<String> processInstanceIds) { |
| 63 | 76 | if (CollUtil.isEmpty(processInstanceIds)) { |
| ... | ... | @@ -67,30 +80,52 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 67 | 80 | } |
| 68 | 81 | |
| 69 | 82 | @Override |
| 70 | - public PageResult<TodoTaskRespVO> getTodoTaskPage(TodoTaskPageReqVO pageReqVO) { | |
| 71 | - // TODO @jason:封装一个方法,用于转换成 activiti 的分页对象 | |
| 72 | -// final Pageable pageable = Pageable.of((pageReqVO.getPageNo() - 1) * pageReqVO.getPageSize(), pageReqVO.getPageSize()); | |
| 73 | -// Page<Task> pageTasks = taskRuntime.tasks(pageable); | |
| 74 | -// int totalItems = pageTasks.getTotalItems(); | |
| 75 | -// List<Task> tasks = pageTasks.getContent(); | |
| 76 | -// final List<TodoTaskRespVO> respVOList = tasks.stream().map(task -> { | |
| 77 | -// ProcessDefinition definition = repositoryService.getProcessDefinition(task.getProcessDefinitionId()); | |
| 78 | -// return TaskConvert.INSTANCE.convert(task, definition); | |
| 79 | -// }).collect(Collectors.toList()); | |
| 80 | -// return new PageResult<>(respVOList, (long)totalItems); | |
| 81 | - return null; | |
| 83 | + public PageResult<BpmTaskTodoPageItemRespVO> getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) { | |
| 84 | + // 查询待办任务 | |
| 85 | + TaskQuery taskQuery = taskService.createTaskQuery() | |
| 86 | + .taskAssignee(String.valueOf(userId)); | |
| 87 | + if (StrUtil.isNotBlank(pageVO.getName())) { | |
| 88 | + taskQuery.taskName("%s" + pageVO.getName() + "%s"); | |
| 89 | + } | |
| 90 | + if (pageVO.getBeginCreateTime() != null) { | |
| 91 | + taskQuery.taskCreatedAfter(pageVO.getBeginCreateTime()); | |
| 92 | + } | |
| 93 | + if (pageVO.getEndCreateTime() != null) { | |
| 94 | + taskQuery.taskCreatedBefore(pageVO.getEndCreateTime()); | |
| 95 | + } | |
| 96 | + // 执行查询 | |
| 97 | + List<Task> tasks = taskQuery.orderByTaskCreateTime().desc() // 创建时间倒序 | |
| 98 | + .listPage(PageUtils.getStart(pageVO), pageVO.getPageSize()); | |
| 99 | + if (CollUtil.isEmpty(tasks)) { | |
| 100 | + return PageResult.empty(taskQuery.count()); | |
| 101 | + } | |
| 102 | + | |
| 103 | + // 获得 ProcessInstance Map | |
| 104 | + Map<String, ProcessInstance> processInstanceMap = processInstanceService.getProcessInstanceMap( | |
| 105 | + convertSet(tasks, Task::getProcessInstanceId)); | |
| 106 | + | |
| 107 | + // 获得 User Map | |
| 108 | + Map<Long, SysUserDO> userMap = userService.getUserMap( | |
| 109 | + convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId()))); | |
| 110 | + // 拼接结果 | |
| 111 | + return new PageResult<>(BpmTaskConvert.INSTANCE.convertList(tasks, processInstanceMap, userMap), | |
| 112 | + taskQuery.count()); | |
| 82 | 113 | } |
| 83 | 114 | |
| 115 | + @Override | |
| 116 | + public void updateTaskAssign(String id, Long userId) { | |
| 117 | + taskService.setAssignee(id, String.valueOf(userId)); | |
| 118 | + } | |
| 84 | 119 | |
| 85 | 120 | @Override |
| 86 | - public void claimTask(String taskId) { | |
| 87 | - taskRuntime.claim(new ClaimTaskPayloadBuilder() | |
| 88 | - .withTaskId(taskId) | |
| 89 | - .withAssignee(SecurityFrameworkUtils.getLoginUser().getUsername()) | |
| 90 | - .build()); | |
| 121 | + public void claimTask(String id) { | |
| 122 | + | |
| 91 | 123 | } |
| 92 | 124 | |
| 125 | + // 任务编号、流程名称、任务节点、流程发起人、接收时间、审批时间、耗时【名称、开始时间】「流程记录、撤回」 | |
| 126 | + // 任务编号、任务名称、所属流程、委托代办人、流程发起人、优先级、审批操作、审批意见、耗时、创建时间【名称、开始时间】「申请详情」 | |
| 93 | 127 | |
| 128 | + // 任务编号、任务名称、流程名称、流程发起人、接收时间、审批时间、耗时【名称、接收时间】「详情」TODO 撤回 | |
| 94 | 129 | |
| 95 | 130 | @Override |
| 96 | 131 | @Transactional |
| ... | ... | @@ -126,7 +161,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 126 | 161 | // 获得对应的步骤 |
| 127 | 162 | List<TaskStepVO> steps = new ArrayList<>(); |
| 128 | 163 | finished.forEach(instance -> { |
| 129 | - TaskStepVO stepVO = TaskConvert.INSTANCE.convert(instance); | |
| 164 | + TaskStepVO stepVO = BpmTaskConvert.INSTANCE.convert(instance); | |
| 130 | 165 | stepVO.setStatus(1); // TODO @jason:1 这个 magic number 要枚举起来。 |
| 131 | 166 | // TODO @jason:可以考虑把 comments 读取后,在统一调用 convert 拼接。另外 Comment 是废弃的类,有没其它可以使用的哈? |
| 132 | 167 | List<Comment> comments = taskService.getTaskComments(instance.getTaskId()); |
| ... | ... | @@ -144,7 +179,7 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 144 | 179 | .unfinished().list(); |
| 145 | 180 | // 获得对应的步骤 |
| 146 | 181 | for (HistoricActivityInstance instance : unfinished) { |
| 147 | - TaskStepVO stepVO = TaskConvert.INSTANCE.convert(instance); | |
| 182 | + TaskStepVO stepVO = BpmTaskConvert.INSTANCE.convert(instance); | |
| 148 | 183 | stepVO.setComment(""); |
| 149 | 184 | stepVO.setStatus(0); |
| 150 | 185 | steps.add(stepVO); |
| ... | ... | @@ -159,13 +194,6 @@ public class BpmTaskServiceImpl implements BpmTaskService { |
| 159 | 194 | } |
| 160 | 195 | |
| 161 | 196 | @Override |
| 162 | - public TodoTaskRespVO getTaskFormKey(TaskQueryReqVO taskQuery) { | |
| 163 | -// final Task task = taskRuntime.task(taskQuery.getTaskId()); | |
| 164 | -// return TaskConvert.INSTANCE.convert(task); | |
| 165 | - return null; | |
| 166 | - } | |
| 167 | - | |
| 168 | - @Override | |
| 169 | 197 | public FileResp getHighlightImg(String processInstanceId) { |
| 170 | 198 | // 查询历史 |
| 171 | 199 | //TODO 云扬四海 貌似流程结束后,点击审批进度会报错 | ... | ... |
yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java
| ... | ... | @@ -176,6 +176,9 @@ public class SysUserServiceImpl implements SysUserService { |
| 176 | 176 | |
| 177 | 177 | @Override |
| 178 | 178 | public List<SysUserDO> getUsers(Collection<Long> ids) { |
| 179 | + if (CollUtil.isEmpty(ids)) { | |
| 180 | + return Collections.emptyList(); | |
| 181 | + } | |
| 179 | 182 | return userMapper.selectBatchIds(ids); |
| 180 | 183 | } |
| 181 | 184 | ... | ... |
yudao-admin-ui/src/api/bpm/task.js
0 → 100644
yudao-admin-ui/src/views/oa/todo/index.vue renamed to yudao-admin-ui/src/views/bpm/task/todo.vue
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/pojo/PageResult.java