mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-11-04 20:28:44 +08:00 
			
		
		
		
	【待办评审修改】 判断任务的加签人逻辑修改
This commit is contained in:
		@@ -9,10 +9,12 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
 | 
			
		||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmProcessInstanceRespVO;
 | 
			
		||||
import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO;
 | 
			
		||||
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
 | 
			
		||||
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.service.message.dto.BpmMessageSendWhenTaskCreatedReqDTO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
 | 
			
		||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
 | 
			
		||||
import org.flowable.bpmn.model.BpmnModel;
 | 
			
		||||
import org.flowable.engine.history.HistoricProcessInstance;
 | 
			
		||||
import org.flowable.engine.runtime.ProcessInstance;
 | 
			
		||||
import org.flowable.task.api.Task;
 | 
			
		||||
@@ -27,6 +29,8 @@ import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
 | 
			
		||||
import static cn.iocoder.yudao.framework.common.util.collection.MapUtils.findAndThen;
 | 
			
		||||
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils.isAddSignUserTask;
 | 
			
		||||
import static cn.iocoder.yudao.module.bpm.framework.flowable.core.util.FlowableUtils.isAssignUserTask;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Bpm 任务 Convert
 | 
			
		||||
@@ -123,6 +127,30 @@ public interface BpmTaskConvert {
 | 
			
		||||
        }));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    default List<BpmTaskRespVO> buildTodoTaskListByUserId(Long userId, List<Task> todoTaskList,
 | 
			
		||||
                                                          Map<String, List<Task>> childrenTaskMap,
 | 
			
		||||
                                                          BpmnModel bpmnModel,
 | 
			
		||||
                                                          Map<Long, AdminUserRespDTO> userMap,
 | 
			
		||||
                                                          Map<Long, DeptRespDTO> deptMap) {
 | 
			
		||||
       return convertList(todoTaskList, task -> {
 | 
			
		||||
           // 找到分配给当前用户,或者当前用户加签的任务(为了减签)
 | 
			
		||||
           if (!isAssignUserTask(userId, task) && !isAddSignUserTask(userId, task, childrenTaskMap)) {
 | 
			
		||||
               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()));
 | 
			
		||||
           buildTaskOwner(taskVO, task.getOwner(), userMap, deptMap);
 | 
			
		||||
           buildTaskAssignee(taskVO, task.getAssignee(), userMap, deptMap);
 | 
			
		||||
           // 如果是被加签的任务. 找到它的子任务 (为了减签)
 | 
			
		||||
           // TODO @jason:如果是向后加签,这个判断有问题哈。因为向后加签后,当前任务,assignee 还是没变。可以简单点,直接拿子任务哈。另外,需要考虑子任务的子任务。
 | 
			
		||||
           if (isAddSignUserTask(userId, task, childrenTaskMap)) {
 | 
			
		||||
               buildTaskChildren(taskVO, childrenTaskMap, userMap, deptMap);
 | 
			
		||||
           }
 | 
			
		||||
           return taskVO;
 | 
			
		||||
       });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    default BpmMessageSendWhenTaskCreatedReqDTO convert(ProcessInstance processInstance, AdminUserRespDTO startUser,
 | 
			
		||||
                                                        Task task) {
 | 
			
		||||
        BpmMessageSendWhenTaskCreatedReqDTO reqDTO = new BpmMessageSendWhenTaskCreatedReqDTO();
 | 
			
		||||
@@ -151,6 +179,7 @@ public interface BpmTaskConvert {
 | 
			
		||||
                    convertList(childTasks, childTask -> {
 | 
			
		||||
                        BpmTaskRespVO childTaskVO = BeanUtils.toBean(childTask, BpmTaskRespVO.class);
 | 
			
		||||
                        childTaskVO.setStatus(FlowableUtils.getTaskStatus(childTask));
 | 
			
		||||
                        buildTaskOwner(childTaskVO, childTask.getOwner(), userMap, deptMap);
 | 
			
		||||
                        buildTaskAssignee(childTaskVO, childTask.getAssignee(), userMap, deptMap);
 | 
			
		||||
                        return childTaskVO;
 | 
			
		||||
                    })
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,7 @@
 | 
			
		||||
package cn.iocoder.yudao.module.bpm.framework.flowable.core.util;
 | 
			
		||||
 | 
			
		||||
import cn.hutool.core.collection.CollUtil;
 | 
			
		||||
import cn.hutool.core.util.NumberUtil;
 | 
			
		||||
import cn.hutool.core.util.ObjectUtil;
 | 
			
		||||
import cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder;
 | 
			
		||||
import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils;
 | 
			
		||||
@@ -13,6 +15,7 @@ import org.flowable.engine.history.HistoricProcessInstance;
 | 
			
		||||
import org.flowable.engine.impl.cfg.ProcessEngineConfigurationImpl;
 | 
			
		||||
import org.flowable.engine.impl.util.CommandContextUtil;
 | 
			
		||||
import org.flowable.engine.runtime.ProcessInstance;
 | 
			
		||||
import org.flowable.task.api.Task;
 | 
			
		||||
import org.flowable.task.api.TaskInfo;
 | 
			
		||||
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
@@ -179,6 +182,40 @@ public class FlowableUtils {
 | 
			
		||||
        return taskLocalVariables;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断指定用户,是否是当前任务的分配人
 | 
			
		||||
     *
 | 
			
		||||
     * @param userId 用户编号
 | 
			
		||||
     * @param task   任务
 | 
			
		||||
     * @return 是否
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isAssignUserTask(Long userId, Task task) {
 | 
			
		||||
        return ObjectUtil.equal(userId, NumberUtil.parseLong(task.getAssignee(), null));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断指定用户,是否是当前任务的拥有人
 | 
			
		||||
     *
 | 
			
		||||
     * @param userId 用户编号
 | 
			
		||||
     * @param task   任务
 | 
			
		||||
     * @return 是否
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isOwnerUserTask(Long userId, Task task) {
 | 
			
		||||
        return ObjectUtil.equal(userId, NumberUtil.parseLong(task.getOwner(), null));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断指定用户,是否是当前任务的加签人
 | 
			
		||||
     * @param userId 用户 Id
 | 
			
		||||
     * @param task 任务
 | 
			
		||||
     * @param  childrenTaskMap 子任务集合
 | 
			
		||||
     * @return 是否
 | 
			
		||||
     */
 | 
			
		||||
    public static boolean isAddSignUserTask(Long userId, Task task, Map<String, List<Task>> childrenTaskMap) {
 | 
			
		||||
        return (isAssignUserTask(userId, task) || isOwnerUserTask(userId, task))
 | 
			
		||||
                && CollUtil.isNotEmpty(childrenTaskMap.get(task.getId()));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // ========== Expression 相关的工具方法 ==========
 | 
			
		||||
 | 
			
		||||
    public static Object getExpressionValue(VariableContainer variableContainer, String expressionString) {
 | 
			
		||||
 
 | 
			
		||||
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@@ -7,7 +7,6 @@ import cn.hutool.extra.spring.SpringUtil;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
 | 
			
		||||
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.object.BeanUtils;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
 | 
			
		||||
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
 | 
			
		||||
import cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils;
 | 
			
		||||
@@ -151,50 +150,15 @@ public class BpmTaskServiceImpl implements BpmTaskService {
 | 
			
		||||
        Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
 | 
			
		||||
        Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(
 | 
			
		||||
                convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
 | 
			
		||||
        // 2.2 构建 Task 列表的返回信息
 | 
			
		||||
 | 
			
		||||
        // 2.2 构建用户待办 Task 列表
 | 
			
		||||
        HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(processInstanceId);
 | 
			
		||||
        BpmnModel bpmnModel = bpmProcessDefinitionService.getProcessDefinitionBpmnModel(processInstance.getProcessDefinitionId());
 | 
			
		||||
        List<BpmTaskRespVO> taskList = convertList(todoList, task -> {
 | 
			
		||||
            // 找到分配给当前用户,或者当前用户加签的任务(为了减签)
 | 
			
		||||
            if (!isAssignUserTask(userId, task) && !isAddSignUserTask(userId, task)) {
 | 
			
		||||
                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()));
 | 
			
		||||
            BpmTaskConvert.INSTANCE.buildTaskOwner(taskVO, task.getOwner(), userMap, deptMap);
 | 
			
		||||
            // 如果是被加签的任务. 找到它的子任务 (为了减签)
 | 
			
		||||
            // TODO @jason:如果是向后加签,这个判断有问题哈。因为向后加签后,当前任务,assignee 还是没变。可以简单点,直接拿子任务哈。另外,需要考虑子任务的子任务。
 | 
			
		||||
            if (isAddSignUserTask(userId, task)) {
 | 
			
		||||
                // TODO @jason:这里其实可以考虑,在 157 到 173 把所有需要的数据都拿到,然后交给 BpmTaskConvert.INSTANCE 转换出 taskVO。这样,service 只保留一些逻辑性强的东西,类似 status、buttonsetting,都拿到 convert 里去。
 | 
			
		||||
                BpmTaskConvert.INSTANCE.buildTaskChildren(taskVO, childrenTaskMap, userMap, deptMap);
 | 
			
		||||
            }
 | 
			
		||||
            return taskVO;
 | 
			
		||||
        });
 | 
			
		||||
        return findFirst(taskList, Objects::nonNull);
 | 
			
		||||
    }
 | 
			
		||||
        List<BpmTaskRespVO> todoTasks = BpmTaskConvert.INSTANCE.buildTodoTaskListByUserId(userId, todoList, childrenTaskMap,
 | 
			
		||||
                bpmnModel, userMap, deptMap);
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断指定用户,是否是当前任务的分配人
 | 
			
		||||
     *
 | 
			
		||||
     * @param userId 用户编号
 | 
			
		||||
     * @param task 任务
 | 
			
		||||
     * @return 是否
 | 
			
		||||
     */
 | 
			
		||||
    private boolean isAssignUserTask(Long userId, Task task) {
 | 
			
		||||
        return ObjectUtil.equal(userId, NumberUtil.parseLong(task.getAssignee(), null));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 判断指定用户,是否是当前任务的加签人
 | 
			
		||||
     *
 | 
			
		||||
     * @param userId 用户编号
 | 
			
		||||
     * @param task 任务
 | 
			
		||||
     * @return 是否
 | 
			
		||||
     */
 | 
			
		||||
    private boolean isAddSignUserTask(Long userId, Task task) {
 | 
			
		||||
        return userId.equals(NumberUtil.parseLong(task.getOwner(), null))
 | 
			
		||||
                && BpmTaskSignTypeEnum.of(task.getScopeType()) != null;
 | 
			
		||||
        // 2.3 找到首个任务
 | 
			
		||||
        return findFirst(todoTasks, Objects::nonNull);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user