BPM:新增【流程任务】菜单,用于全部流程实例的查询

This commit is contained in:
YunaiV 2024-03-22 09:06:52 +08:00
parent ba4b3701bf
commit acea73c991
5 changed files with 83 additions and 15 deletions

View File

@ -59,8 +59,12 @@ public class BpmTaskController {
@GetMapping("todo-page") @GetMapping("todo-page")
@Operation(summary = "获取 Todo 待办任务分页") @Operation(summary = "获取 Todo 待办任务分页")
@PreAuthorize("@ss.hasPermission('bpm:task:query')") @PreAuthorize("@ss.hasPermission('bpm:task:query')")
public CommonResult<PageResult<BpmTaskRespVO>> getTodoTaskPage(@Valid BpmTaskPageReqVO pageVO) { public CommonResult<PageResult<BpmTaskRespVO>> getTaskTodoPage(@Valid BpmTaskPageReqVO pageVO) {
PageResult<Task> pageResult = taskService.getTodoTaskPage(getLoginUserId(), pageVO); PageResult<Task> pageResult = taskService.getTaskTodoPage(getLoginUserId(), pageVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty());
}
// 拼接数据 // 拼接数据
Map<String, ProcessInstance> processInstanceMap = processInstanceService.getProcessInstanceMap( Map<String, ProcessInstance> processInstanceMap = processInstanceService.getProcessInstanceMap(
convertSet(pageResult.getList(), Task::getProcessInstanceId)); convertSet(pageResult.getList(), Task::getProcessInstanceId));
@ -72,14 +76,39 @@ public class BpmTaskController {
@GetMapping("done-page") @GetMapping("done-page")
@Operation(summary = "获取 Done 已办任务分页") @Operation(summary = "获取 Done 已办任务分页")
@PreAuthorize("@ss.hasPermission('bpm:task:query')") @PreAuthorize("@ss.hasPermission('bpm:task:query')")
public CommonResult<PageResult<BpmTaskRespVO>> getDoneTaskPage(@Valid BpmTaskPageReqVO pageVO) { public CommonResult<PageResult<BpmTaskRespVO>> getTaskDonePage(@Valid BpmTaskPageReqVO pageVO) {
PageResult<HistoricTaskInstance> pageResult = taskService.getDoneTaskPage(getLoginUserId(), pageVO); PageResult<HistoricTaskInstance> pageResult = taskService.getTaskDonePage(getLoginUserId(), pageVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty());
}
// 拼接数据 // 拼接数据
Map<String, HistoricProcessInstance> processInstanceMap = processInstanceService.getHistoricProcessInstanceMap( Map<String, HistoricProcessInstance> processInstanceMap = processInstanceService.getHistoricProcessInstanceMap(
convertSet(pageResult.getList(), HistoricTaskInstance::getProcessInstanceId)); convertSet(pageResult.getList(), HistoricTaskInstance::getProcessInstanceId));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap( Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId()))); convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId())));
return success(BpmTaskConvert.INSTANCE.buildDoneTaskPage(pageResult, processInstanceMap, userMap)); return success(BpmTaskConvert.INSTANCE.buildTaskPage(pageResult, processInstanceMap, userMap, null));
}
@GetMapping("manager-page")
@Operation(summary = "获取全部任务的分页", description = "用于【流程任务】菜单")
@PreAuthorize("@ss.hasPermission('bpm:task:mananger-query')")
public CommonResult<PageResult<BpmTaskRespVO>> getDoneTaskPage(@Valid BpmTaskPageReqVO pageVO) {
PageResult<HistoricTaskInstance> pageResult = taskService.getTaskPage(getLoginUserId(), pageVO);
if (CollUtil.isEmpty(pageResult.getList())) {
return success(PageResult.empty());
}
// 拼接数据
Map<String, HistoricProcessInstance> processInstanceMap = processInstanceService.getHistoricProcessInstanceMap(
convertSet(pageResult.getList(), HistoricTaskInstance::getProcessInstanceId));
// 获得 User Dept Map
Set<Long> userIds = convertSet(processInstanceMap.values(), instance -> Long.valueOf(instance.getStartUserId()));
userIds.addAll(convertSet(pageResult.getList(), task -> NumberUtils.parseLong(task.getAssignee())));
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(
convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
return success(BpmTaskConvert.INSTANCE.buildTaskPage(pageResult, processInstanceMap, userMap, deptMap));
} }
@GetMapping("/list-by-process-instance-id") @GetMapping("/list-by-process-instance-id")

View File

@ -51,9 +51,11 @@ public interface BpmProcessInstanceConvert {
MapUtils.findAndThen(categoryMap, respVO.getCategory(), category -> respVO.setCategoryName(category.getName())); MapUtils.findAndThen(categoryMap, respVO.getCategory(), category -> respVO.setCategoryName(category.getName()));
respVO.setTasks(BeanUtils.toBean(taskMap.get(respVO.getId()), BpmProcessInstanceRespVO.Task.class)); respVO.setTasks(BeanUtils.toBean(taskMap.get(respVO.getId()), BpmProcessInstanceRespVO.Task.class));
// user // user
AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(pageResult.getList().get(i).getStartUserId())); if (userMap != null) {
respVO.setStartUser(BeanUtils.toBean(startUser, BpmProcessInstanceRespVO.User.class)); AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(pageResult.getList().get(i).getStartUserId()));
MapUtils.findAndThen(deptMap, startUser.getDeptId(), dept -> respVO.getStartUser().setDeptName(dept.getName())); respVO.setStartUser(BeanUtils.toBean(startUser, BpmProcessInstanceRespVO.User.class));
MapUtils.findAndThen(deptMap, startUser.getDeptId(), dept -> respVO.getStartUser().setDeptName(dept.getName()));
}
} }
return vpPageResult; return vpPageResult;
} }

View File

@ -52,12 +52,19 @@ public interface BpmTaskConvert {
}); });
} }
default PageResult<BpmTaskRespVO> buildDoneTaskPage(PageResult<HistoricTaskInstance> pageResult, default PageResult<BpmTaskRespVO> buildTaskPage(PageResult<HistoricTaskInstance> pageResult,
Map<String, HistoricProcessInstance> processInstanceMap, Map<String, HistoricProcessInstance> processInstanceMap,
Map<Long, AdminUserRespDTO> userMap) { Map<Long, AdminUserRespDTO> userMap,
Map<Long, DeptRespDTO> deptMap) {
List<BpmTaskRespVO> taskVOList = CollectionUtils.convertList(pageResult.getList(), task -> { List<BpmTaskRespVO> taskVOList = CollectionUtils.convertList(pageResult.getList(), task -> {
BpmTaskRespVO taskVO = BeanUtils.toBean(task, BpmTaskRespVO.class); BpmTaskRespVO taskVO = BeanUtils.toBean(task, BpmTaskRespVO.class);
taskVO.setStatus(FlowableUtils.getTaskStatus(task)).setReason(FlowableUtils.getTaskReason(task)); taskVO.setStatus(FlowableUtils.getTaskStatus(task)).setReason(FlowableUtils.getTaskReason(task));
// 用户信息
AdminUserRespDTO assignUser = userMap.get(NumberUtils.parseLong(task.getAssignee()));
if (assignUser != null) {
taskVO.setAssigneeUser(BeanUtils.toBean(assignUser, BpmProcessInstanceRespVO.User.class));
findAndThen(deptMap, assignUser.getDeptId(), dept -> taskVO.getAssigneeUser().setDeptName(dept.getName()));
}
// 流程实例 // 流程实例
HistoricProcessInstance processInstance = processInstanceMap.get(taskVO.getProcessInstanceId()); HistoricProcessInstance processInstance = processInstanceMap.get(taskVO.getProcessInstanceId());
if (processInstance != null) { if (processInstance != null) {

View File

@ -27,7 +27,7 @@ public interface BpmTaskService {
* @param pageReqVO 分页请求 * @param pageReqVO 分页请求
* @return 流程任务分页 * @return 流程任务分页
*/ */
PageResult<Task> getTodoTaskPage(Long userId, BpmTaskPageReqVO pageReqVO); PageResult<Task> getTaskTodoPage(Long userId, BpmTaskPageReqVO pageReqVO);
/** /**
* 获得已办的流程任务分页 * 获得已办的流程任务分页
@ -36,7 +36,16 @@ public interface BpmTaskService {
* @param pageReqVO 分页请求 * @param pageReqVO 分页请求
* @return 流程任务分页 * @return 流程任务分页
*/ */
PageResult<HistoricTaskInstance> getDoneTaskPage(Long userId, BpmTaskPageReqVO pageReqVO); PageResult<HistoricTaskInstance> getTaskDonePage(Long userId, BpmTaskPageReqVO pageReqVO);
/**
* 获得全部的流程任务分页
*
* @param userId 用户编号
* @param pageReqVO 分页请求
* @return 流程任务分页
*/
PageResult<HistoricTaskInstance> getTaskPage(Long userId, BpmTaskPageReqVO pageReqVO);
/** /**
* 获得流程任务 Map * 获得流程任务 Map

View File

@ -86,7 +86,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
private AdminUserApi adminUserApi; private AdminUserApi adminUserApi;
@Override @Override
public PageResult<Task> getTodoTaskPage(Long userId, BpmTaskPageReqVO pageVO) { public PageResult<Task> getTaskTodoPage(Long userId, BpmTaskPageReqVO pageVO) {
TaskQuery taskQuery = taskService.createTaskQuery() TaskQuery taskQuery = taskService.createTaskQuery()
.taskAssignee(String.valueOf(userId)) // 分配给自己 .taskAssignee(String.valueOf(userId)) // 分配给自己
.active() .active()
@ -108,7 +108,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
} }
@Override @Override
public PageResult<HistoricTaskInstance> getDoneTaskPage(Long userId, BpmTaskPageReqVO pageVO) { public PageResult<HistoricTaskInstance> getTaskDonePage(Long userId, BpmTaskPageReqVO pageVO) {
HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery() HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery()
.finished() // 已完成 .finished() // 已完成
.taskAssignee(String.valueOf(userId)) // 分配给自己 .taskAssignee(String.valueOf(userId)) // 分配给自己
@ -130,6 +130,27 @@ public class BpmTaskServiceImpl implements BpmTaskService {
return new PageResult<>(tasks, count); return new PageResult<>(tasks, count);
} }
@Override
public PageResult<HistoricTaskInstance> getTaskPage(Long userId, BpmTaskPageReqVO pageVO) {
HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery()
.includeTaskLocalVariables()
.orderByHistoricTaskInstanceEndTime().desc(); // 审批时间倒序
if (StrUtil.isNotBlank(pageVO.getName())) {
taskQuery.taskNameLike("%" + pageVO.getName() + "%");
}
if (ArrayUtil.isNotEmpty(pageVO.getCreateTime())) {
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[0]));
taskQuery.taskCreatedAfter(DateUtils.of(pageVO.getCreateTime()[1]));
}
// 执行查询
long count = taskQuery.count();
if (count == 0) {
return PageResult.empty();
}
List<HistoricTaskInstance> tasks = taskQuery.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
return new PageResult<>(tasks, count);
}
@Override @Override
public List<Task> getTasksByProcessInstanceIds(List<String> processInstanceIds) { public List<Task> getTasksByProcessInstanceIds(List<String> processInstanceIds) {
if (CollUtil.isEmpty(processInstanceIds)) { if (CollUtil.isEmpty(processInstanceIds)) {