mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-03 12:14:57 +08:00
【功能修改】 新增我的待办任务接口
This commit is contained in:
parent
c05f9fe98e
commit
c70ef4493a
@ -30,10 +30,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
|||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||||
@ -77,6 +74,15 @@ public class BpmTaskController {
|
|||||||
return success(BpmTaskConvert.INSTANCE.buildTodoTaskPage(pageResult, processInstanceMap, userMap));
|
return success(BpmTaskConvert.INSTANCE.buildTodoTaskPage(pageResult, processInstanceMap, userMap));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("my-todo")
|
||||||
|
@Operation(summary = "获取我的待办任务,取第一条")
|
||||||
|
@Parameter(name = "processInstanceId", description = "流程实例的编号", required = true)
|
||||||
|
@PreAuthorize("@ss.hasPermission('bpm:task:query')")
|
||||||
|
public CommonResult<BpmTaskRespVO> getMyTodoTask(@RequestParam("processInstanceId") String processInstanceId) {
|
||||||
|
List<BpmTaskRespVO> taskList = taskService.getTodoTask(getLoginUserId(), processInstanceId);
|
||||||
|
return success(findFirst(taskList, Objects::nonNull));
|
||||||
|
}
|
||||||
|
|
||||||
@GetMapping("done-page")
|
@GetMapping("done-page")
|
||||||
@Operation(summary = "获取 Done 已办任务分页")
|
@Operation(summary = "获取 Done 已办任务分页")
|
||||||
@PreAuthorize("@ss.hasPermission('bpm:task:query')")
|
@PreAuthorize("@ss.hasPermission('bpm:task:query')")
|
||||||
|
@ -67,9 +67,6 @@ public class BpmTaskRespVO {
|
|||||||
private List<String> formFields;
|
private List<String> formFields;
|
||||||
@Schema(description = "提交的表单值", requiredMode = Schema.RequiredMode.REQUIRED)
|
@Schema(description = "提交的表单值", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||||
private Map<String, Object> formVariables;
|
private Map<String, Object> formVariables;
|
||||||
// @芋艿 都改成了 fieldsPermission。 buttonsSetting。和 BpmSimpleModelNodeVO 统一
|
|
||||||
@Schema(description = "表单字段权限值")
|
|
||||||
private Map<String, String> fieldsPermission;
|
|
||||||
@Schema(description = "操作按钮设置值")
|
@Schema(description = "操作按钮设置值")
|
||||||
private Map<Integer, OperationButtonSetting> buttonsSetting;
|
private Map<Integer, OperationButtonSetting> buttonsSetting;
|
||||||
|
|
||||||
|
@ -112,10 +112,6 @@ public interface BpmTaskConvert {
|
|||||||
findAndThen(deptMap, ownerUser.getDeptId(), dept -> taskVO.getOwnerUser().setDeptName(dept.getName()));
|
findAndThen(deptMap, ownerUser.getDeptId(), dept -> taskVO.getOwnerUser().setDeptName(dept.getName()));
|
||||||
}
|
}
|
||||||
if (BpmTaskStatusEnum.RUNNING.getStatus().equals(taskStatus)){
|
if (BpmTaskStatusEnum.RUNNING.getStatus().equals(taskStatus)){
|
||||||
// 设置表单权限 TODO @芋艿 是不是还要加一个全局的权限 基于 processInstance 的权限;回复:可能不需要,但是发起人,需要有个权限配置
|
|
||||||
// TODO @jason:貌似这么返回,主要解决当前审批 task 的表单权限,但是不同抄送人的表单权限,可能不太对。例如说,对 A 抄送人是隐藏某个字段。
|
|
||||||
// @芋艿 表单权限需要分离开。单独的接口来获取了 BpmProcessInstanceService.getProcessInstanceFormFieldsPermission
|
|
||||||
taskVO.setFieldsPermission(BpmnModelUtils.parseFormFieldsPermission(bpmnModel, task.getTaskDefinitionKey()));
|
|
||||||
// 操作按钮设置
|
// 操作按钮设置
|
||||||
taskVO.setButtonsSetting(BpmnModelUtils.parseButtonsSetting(bpmnModel, task.getTaskDefinitionKey()));
|
taskVO.setButtonsSetting(BpmnModelUtils.parseButtonsSetting(bpmnModel, task.getTaskDefinitionKey()));
|
||||||
}
|
}
|
||||||
|
@ -32,6 +32,15 @@ public interface BpmTaskService {
|
|||||||
*/
|
*/
|
||||||
PageResult<Task> getTaskTodoPage(Long userId, BpmTaskPageReqVO pageReqVO);
|
PageResult<Task> getTaskTodoPage(Long userId, BpmTaskPageReqVO pageReqVO);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获得待办任务列表
|
||||||
|
*
|
||||||
|
* @param userId 用户编号
|
||||||
|
* @param processInstanceId 流程实例编号
|
||||||
|
* @return 流程任务列表
|
||||||
|
*/
|
||||||
|
List<BpmTaskRespVO> getTodoTask(Long userId, String processInstanceId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获得已办的流程任务分页
|
* 获得已办的流程任务分页
|
||||||
*
|
*
|
||||||
|
@ -5,11 +5,14 @@ import cn.hutool.core.lang.Assert;
|
|||||||
import cn.hutool.core.util.*;
|
import cn.hutool.core.util.*;
|
||||||
import cn.hutool.extra.spring.SpringUtil;
|
import cn.hutool.extra.spring.SpringUtil;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
||||||
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
|
||||||
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
||||||
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
|
||||||
|
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceRespVO;
|
||||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
|
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.*;
|
||||||
import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert;
|
import cn.iocoder.yudao.module.bpm.convert.task.BpmTaskConvert;
|
||||||
import cn.iocoder.yudao.module.bpm.enums.definition.*;
|
import cn.iocoder.yudao.module.bpm.enums.definition.*;
|
||||||
@ -21,6 +24,7 @@ import cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableCon
|
|||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils;
|
||||||
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
|
import cn.iocoder.yudao.module.bpm.service.definition.BpmModelService;
|
||||||
|
import cn.iocoder.yudao.module.bpm.service.definition.BpmProcessDefinitionService;
|
||||||
import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService;
|
import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService;
|
||||||
import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskTimeoutReqDTO;
|
import cn.iocoder.yudao.module.bpm.service.message.dto.BpmMessageSendWhenTaskTimeoutReqDTO;
|
||||||
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
import cn.iocoder.yudao.module.system.api.dept.DeptApi;
|
||||||
@ -38,6 +42,7 @@ import org.flowable.engine.HistoryService;
|
|||||||
import org.flowable.engine.ManagementService;
|
import org.flowable.engine.ManagementService;
|
||||||
import org.flowable.engine.RuntimeService;
|
import org.flowable.engine.RuntimeService;
|
||||||
import org.flowable.engine.TaskService;
|
import org.flowable.engine.TaskService;
|
||||||
|
import org.flowable.engine.history.HistoricProcessInstance;
|
||||||
import org.flowable.engine.runtime.ProcessInstance;
|
import org.flowable.engine.runtime.ProcessInstance;
|
||||||
import org.flowable.task.api.DelegationState;
|
import org.flowable.task.api.DelegationState;
|
||||||
import org.flowable.task.api.Task;
|
import org.flowable.task.api.Task;
|
||||||
@ -56,6 +61,7 @@ import java.util.stream.Stream;
|
|||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*;
|
||||||
|
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
|
||||||
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
||||||
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_RETURN_FLAG;
|
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.enums.BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_RETURN_FLAG;
|
||||||
|
|
||||||
@ -81,6 +87,8 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||||||
@Resource
|
@Resource
|
||||||
private BpmProcessInstanceService processInstanceService;
|
private BpmProcessInstanceService processInstanceService;
|
||||||
@Resource
|
@Resource
|
||||||
|
private BpmProcessDefinitionService bpmProcessDefinitionService;
|
||||||
|
@Resource
|
||||||
private BpmProcessInstanceCopyService processInstanceCopyService;
|
private BpmProcessInstanceCopyService processInstanceCopyService;
|
||||||
@Resource
|
@Resource
|
||||||
private BpmModelService modelService;
|
private BpmModelService modelService;
|
||||||
@ -116,6 +124,68 @@ public class BpmTaskServiceImpl implements BpmTaskService {
|
|||||||
return new PageResult<>(tasks, count);
|
return new PageResult<>(tasks, count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<BpmTaskRespVO> getTodoTask(Long userId, String processInstanceId) {
|
||||||
|
TaskQuery taskQuery = taskService.createTaskQuery()
|
||||||
|
.active()
|
||||||
|
.processInstanceId(processInstanceId)
|
||||||
|
.includeTaskLocalVariables()
|
||||||
|
.includeProcessVariables()
|
||||||
|
.orderByTaskCreateTime().asc(); // 按创建时间升序
|
||||||
|
HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(processInstanceId);
|
||||||
|
BpmnModel bpmnModel = bpmProcessDefinitionService.getProcessDefinitionBpmnModel(processInstance.getProcessDefinitionId());
|
||||||
|
List<Task> todoList = taskQuery.list();
|
||||||
|
// 找到子任务。用于减签
|
||||||
|
Map<String, List<Task>> childrenTaskMap = convertMultiMap(
|
||||||
|
filterList(todoList, r -> StrUtil.isNotEmpty(r.getParentTaskId())),
|
||||||
|
Task::getParentTaskId);
|
||||||
|
// 获取用户信息
|
||||||
|
Set<Long> userIds = CollUtil.newHashSet();
|
||||||
|
todoList.forEach(task -> {
|
||||||
|
CollUtil.addIfAbsent(userIds, NumberUtils.parseLong((task.getAssignee())));
|
||||||
|
CollUtil.addIfAbsent(userIds, NumberUtils.parseLong((task.getOwner())));
|
||||||
|
});
|
||||||
|
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
|
||||||
|
Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(
|
||||||
|
convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
|
||||||
|
return CollectionUtils.convertList(todoList, task -> {
|
||||||
|
// 找到分配给当前用户,或者当前用户加签的任务(为了减签)
|
||||||
|
if (!userId.equals(NumberUtil.parseLong(task.getAssignee(), null)) &&
|
||||||
|
(!userId.equals(NumberUtil.parseLong(task.getOwner(), null)) || BpmTaskSignTypeEnum.of(task.getScopeType()) == null)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
BpmTaskRespVO taskVO = BeanUtils.toBean(task, BpmTaskRespVO.class);
|
||||||
|
taskVO.setStatus(FlowableUtils.getTaskStatus(task)).setReason(FlowableUtils.getTaskReason(task));
|
||||||
|
taskVO.setButtonsSetting(BpmnModelUtils.parseButtonsSetting(bpmnModel, task.getTaskDefinitionKey()));
|
||||||
|
AdminUserRespDTO ownerUser = userMap.get(NumberUtils.parseLong(task.getOwner()));
|
||||||
|
if (ownerUser != null) {
|
||||||
|
taskVO.setOwnerUser(BeanUtils.toBean(ownerUser, BpmProcessInstanceRespVO.User.class));
|
||||||
|
findAndThen(deptMap, ownerUser.getDeptId(), dept -> taskVO.getOwnerUser().setDeptName(dept.getName()));
|
||||||
|
}
|
||||||
|
// 当前用户加签的任务. 找到它的子任务 (为了减签)
|
||||||
|
if (userId.equals(NumberUtil.parseLong(task.getOwner(), null))
|
||||||
|
&& BpmTaskSignTypeEnum.of(task.getScopeType()) != null) {
|
||||||
|
List<Task> childTasks = childrenTaskMap.get(task.getId());
|
||||||
|
if (CollUtil.isNotEmpty(childTasks)) {
|
||||||
|
taskVO.setChildren(
|
||||||
|
CollectionUtils.convertList(childTasks, childTask -> {
|
||||||
|
BpmTaskRespVO childTaskVO = BeanUtils.toBean(task, BpmTaskRespVO.class);
|
||||||
|
childTaskVO.setStatus(FlowableUtils.getTaskStatus(task));
|
||||||
|
AdminUserRespDTO assignUser = userMap.get(NumberUtils.parseLong(childTask.getAssignee()));
|
||||||
|
if (assignUser != null) {
|
||||||
|
childTaskVO.setAssigneeUser(BeanUtils.toBean(assignUser, BpmProcessInstanceRespVO.User.class));
|
||||||
|
findAndThen(deptMap, assignUser.getDeptId(), dept -> childTaskVO.getAssigneeUser().setDeptName(dept.getName()));
|
||||||
|
}
|
||||||
|
return childTaskVO;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return taskVO;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PageResult<HistoricTaskInstance> getTaskDonePage(Long userId, BpmTaskPageReqVO pageVO) {
|
public PageResult<HistoricTaskInstance> getTaskDonePage(Long userId, BpmTaskPageReqVO pageVO) {
|
||||||
HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery()
|
HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery()
|
||||||
|
Loading…
Reference in New Issue
Block a user