Search in sources :

Example 1 with DeptRespDTO

use of cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO in project ruoyi-vue-pro by YunaiV.

the class BpmTaskServiceImpl method getTaskListByProcessInstanceId.

@Override
public List<BpmTaskRespVO> getTaskListByProcessInstanceId(String processInstanceId) {
    // 获得任务列表
    List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId).orderByHistoricTaskInstanceStartTime().desc().list();
    if (CollUtil.isEmpty(tasks)) {
        return Collections.emptyList();
    }
    // 获得 TaskExtDO Map
    List<BpmTaskExtDO> bpmTaskExtDOs = taskExtMapper.selectListByTaskIds(convertSet(tasks, HistoricTaskInstance::getId));
    Map<String, BpmTaskExtDO> bpmTaskExtDOMap = convertMap(bpmTaskExtDOs, BpmTaskExtDO::getTaskId);
    // 获得 ProcessInstance Map
    HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(processInstanceId);
    // 获得 User Map
    Set<Long> userIds = convertSet(tasks, task -> NumberUtils.parseLong(task.getAssignee()));
    userIds.add(NumberUtils.parseLong(processInstance.getStartUserId()));
    Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
    // 获得 Dept Map
    Map<Long, DeptRespDTO> deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));
    // 拼接数据
    return BpmTaskConvert.INSTANCE.convertList3(tasks, bpmTaskExtDOMap, processInstance, userMap, deptMap);
}
Also used : AdminUserRespDTO(cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO) HistoricTaskInstance(org.flowable.task.api.history.HistoricTaskInstance) BpmTaskExtDO(cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO) HistoricProcessInstance(org.flowable.engine.history.HistoricProcessInstance) DeptRespDTO(cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO)

Example 2 with DeptRespDTO

use of cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO in project ruoyi-vue-pro by YunaiV.

the class BpmTaskConvert method convertList3.

default List<BpmTaskRespVO> convertList3(List<HistoricTaskInstance> tasks, Map<String, BpmTaskExtDO> bpmTaskExtDOMap, HistoricProcessInstance processInstance, Map<Long, AdminUserRespDTO> userMap, Map<Long, DeptRespDTO> deptMap) {
    return CollectionUtils.convertList(tasks, task -> {
        BpmTaskRespVO respVO = convert3(task);
        BpmTaskExtDO taskExtDO = bpmTaskExtDOMap.get(task.getId());
        copyTo(taskExtDO, respVO);
        if (processInstance != null) {
            AdminUserRespDTO startUser = userMap.get(NumberUtils.parseLong(processInstance.getStartUserId()));
            respVO.setProcessInstance(convert(processInstance, startUser));
        }
        AdminUserRespDTO assignUser = userMap.get(NumberUtils.parseLong(task.getAssignee()));
        if (assignUser != null) {
            respVO.setAssigneeUser(convert3(assignUser));
            DeptRespDTO dept = deptMap.get(assignUser.getDeptId());
            if (dept != null) {
                respVO.getAssigneeUser().setDeptName(dept.getName());
            }
        }
        return respVO;
    });
}
Also used : AdminUserRespDTO(cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO) BpmTaskRespVO(cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO) BpmTaskExtDO(cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO) DeptRespDTO(cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO)

Example 3 with DeptRespDTO

use of cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO in project ruoyi-vue-pro by YunaiV.

the class BpmTaskAssignLeaderAbstractScript method calculateTaskCandidateUsers.

protected Set<Long> calculateTaskCandidateUsers(TaskEntity task, int level) {
    Assert.isTrue(level > 0, "level 必须大于 0");
    // 获得发起人
    ProcessInstance processInstance = bpmProcessInstanceService.getProcessInstance(task.getProcessInstanceId());
    Long startUserId = NumberUtils.parseLong(processInstance.getStartUserId());
    // 获得对应 leve 的部门
    DeptRespDTO dept = null;
    for (int i = 0; i < level; i++) {
        // 获得 level 对应的部门
        if (dept == null) {
            dept = getStartUserDept(startUserId);
            if (dept == null) {
                // 找不到发起人的部门,所以无法使用该规则
                return emptySet();
            }
        } else {
            DeptRespDTO parentDept = deptApi.getDept(dept.getParentId());
            if (parentDept == null) {
                // 找不到父级部门,所以只好结束寻找。原因是:例如说,级别比较高的人,所在部门层级比较少
                break;
            }
            dept = parentDept;
        }
    }
    return dept.getLeaderUserId() != null ? asSet(dept.getLeaderUserId()) : emptySet();
}
Also used : DeptRespDTO(cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO) ProcessInstance(org.flowable.engine.runtime.ProcessInstance)

Example 4 with DeptRespDTO

use of cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO in project ruoyi-vue-pro by YunaiV.

the class BpmTaskAssignLeaderX2ScriptTest method testCalculateTaskCandidateUsers_existParentDept.

@Test
public void testCalculateTaskCandidateUsers_existParentDept() {
    // 准备参数
    TaskEntity task = buildTaskEntity(1L);
    // mock 方法(startUser)
    AdminUserRespDTO startUser = randomPojo(AdminUserRespDTO.class, o -> o.setDeptId(10L));
    when(adminUserApi.getUser(eq(1L))).thenReturn(startUser);
    DeptRespDTO startUserDept = randomPojo(DeptRespDTO.class, o -> o.setId(10L).setParentId(100L).setLeaderUserId(20L));
    when(deptApi.getDept(eq(10L))).thenReturn(startUserDept);
    // mock 方法(父 dept)
    DeptRespDTO parentDept = randomPojo(DeptRespDTO.class, o -> o.setId(100L).setParentId(1000L).setLeaderUserId(200L));
    when(deptApi.getDept(eq(100L))).thenReturn(parentDept);
    // 调用
    Set<Long> result = script.calculateTaskCandidateUsers(task);
    // 断言
    assertEquals(asSet(200L), result);
}
Also used : AdminUserRespDTO(cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) DeptRespDTO(cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO) Test(org.junit.jupiter.api.Test) BaseMockitoUnitTest(cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest)

Example 5 with DeptRespDTO

use of cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO in project ruoyi-vue-pro by YunaiV.

the class BpmTaskAssignLeaderAbstractScript method calculateTaskCandidateUsers.

protected Set<Long> calculateTaskCandidateUsers(TaskEntity task, int level) {
    Assert.isTrue(level > 0, "level 必须大于 0");
    // 获得发起人
    Long startUserId = Long.parseLong(task.getProcessInstance().getStartUserId());
    // 获得对应 leve 的部门
    DeptRespDTO dept = null;
    for (int i = 0; i < level; i++) {
        // 获得 level 对应的部门
        if (dept == null) {
            dept = getStartUserDept(startUserId);
            if (dept == null) {
                // 找不到发起人的部门,所以无法使用该规则
                return emptySet();
            }
        } else {
            DeptRespDTO parentDept = deptApi.getDept(dept.getParentId());
            if (parentDept == null) {
                // 找不到父级部门,所以只好结束寻找。原因是:例如说,级别比较高的人,所在部门层级比较少
                break;
            }
            dept = parentDept;
        }
    }
    return dept.getLeaderUserId() != null ? asSet(dept.getLeaderUserId()) : emptySet();
}
Also used : DeptRespDTO(cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO)

Aggregations

DeptRespDTO (cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO)8 AdminUserRespDTO (cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO)5 BaseMockitoUnitTest (cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest)3 Test (org.junit.jupiter.api.Test)3 BpmTaskExtDO (cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO)2 TaskEntity (org.activiti.engine.impl.persistence.entity.TaskEntity)2 HistoricProcessInstance (org.flowable.engine.history.HistoricProcessInstance)2 BpmTaskRespVO (cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO)1 BpmProcessDefinitionExtDO (cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionExtDO)1 BpmTaskAssignRuleDO (cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO)1 BpmProcessInstanceExtDO (cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmProcessInstanceExtDO)1 ProcessDefinition (org.flowable.engine.repository.ProcessDefinition)1 ProcessInstance (org.flowable.engine.runtime.ProcessInstance)1 HistoricTaskInstance (org.flowable.task.api.history.HistoricTaskInstance)1