From a0d574ad2020539a2b8a3f6b78dca670912c778b Mon Sep 17 00:00:00 2001 From: kemengkai <282913448@qq.com> Date: Mon, 16 May 2022 16:25:16 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BB=BB=E5=8A=A1=E6=B5=81?= =?UTF-8?q?=E7=A8=8B=E9=A2=84=E6=B5=8B=E5=8A=9F=E8=83=BD=EF=BC=8C=E9=A2=84?= =?UTF-8?q?=E6=B5=8B=E6=9C=AA=E5=AE=A1=E6=89=B9=E7=AD=89=E5=BE=85=E5=AE=A1?= =?UTF-8?q?=E6=89=B9=E7=9A=84=E4=BB=BB=E5=8A=A1=E6=B5=81=E7=A8=8B=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 8 - yudao-module-bpm/yudao-module-bpm-biz/pom.xml | 12 +- .../admin/task/BpmTaskController.java | 11 - .../definition/BpmTaskAssignRuleMapper.java | 2 + .../bpm/dal/mysql/task/BpmTaskExtMapper.java | 10 + .../bpm/service/task/BpmTaskService.java | 10 - .../bpm/service/task/BpmTaskServiceImpl.java | 36 +- .../inst/domain/HistoricApproveTaskDTO.java | 2 +- .../hi/task/inst/domain/vo/HiTaskinstVO.java | 2 +- .../task/inst/service/HiTaskInstService.java | 350 ++++++++++++++++++ .../task/inst/service/HiTaskinstService.java | 263 ------------- 11 files changed, 380 insertions(+), 326 deletions(-) create mode 100644 yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/service/HiTaskInstService.java delete mode 100644 yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/service/HiTaskinstService.java diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index bb3185f3d..3d76fae7b 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -65,7 +65,6 @@ 3.1.471 1.2.7 1.4.0 - 2.1.3 @@ -579,13 +578,6 @@ justauth-spring-boot-starter ${justauth.version} - - - - org.dom4j - dom4j - ${dom4j.version} - diff --git a/yudao-module-bpm/yudao-module-bpm-biz/pom.xml b/yudao-module-bpm/yudao-module-bpm-biz/pom.xml index 2d19cd77a..d2d84f9cf 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/pom.xml +++ b/yudao-module-bpm/yudao-module-bpm-biz/pom.xml @@ -10,10 +10,6 @@ 4.0.0 yudao-module-bpm-biz - - 2.1.3 - - ${project.artifactId} bpm-base 模块,实现公用的工作流的逻辑,提供给 bpm-activiti 和 bpm-flowable 复用 @@ -30,6 +26,11 @@ yudao-module-system-api ${revision} + + cn.iocoder.boot + yudao-module-system-biz + ${revision} + @@ -85,11 +86,10 @@ 1.4.196 test - - org.dom4j dom4j + 2.1.3 diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmTaskController.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmTaskController.java index eb9fa9dbb..9d96dead9 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmTaskController.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/task/BpmTaskController.java @@ -7,9 +7,6 @@ import cn.iocoder.yudao.module.bpm.service.task.BpmTaskService; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; -import org.apache.ibatis.annotations.Param; -import org.flowable.bpmn.model.BpmnModel; -import org.flowable.engine.TaskService; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -18,7 +15,6 @@ import javax.annotation.Resource; import javax.validation.Valid; import java.util.List; -import java.util.Objects; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; @@ -55,13 +51,6 @@ public class BpmTaskController { return success(taskService.getTaskListByProcessInstanceId(processInstanceId)); } - @GetMapping("/get") - @ApiOperation(value = "获取审批单详情", notes = "包括完成的、未完成的") - @ApiImplicitParam(name = "taskId", value = "任务Id", required = true, dataTypeClass = String.class) - public CommonResult getTask(@Param("taskId") String processInstanceId) { - return success(taskService.getTaskInfo(processInstanceId)); - } - @PutMapping("/approve") @ApiOperation("通过任务") @PreAuthorize("@ss.hasPermission('bpm:task:update')") diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/definition/BpmTaskAssignRuleMapper.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/definition/BpmTaskAssignRuleMapper.java index 1205d30e1..c4061c0f8 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/definition/BpmTaskAssignRuleMapper.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/mysql/definition/BpmTaskAssignRuleMapper.java @@ -32,4 +32,6 @@ public interface BpmTaskAssignRuleMapper extends BaseMapperX { return selectList(BpmTaskExtDO::getTaskId, taskIds); } + /** + * 查询全部任务 + * + * @return 返回任务 + */ + @TenantIgnore + default List listAll() { + return selectList(); + } + /** * 查询任务 * diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java index a029de538..a3dbbd9ea 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskService.java @@ -67,15 +67,6 @@ public interface BpmTaskService { */ List getTaskListByProcessInstanceId(String processInstanceId); - /** - * 获取任务详情 - * - * @param processInstanceId 流程实例的编号 - * - * @return 流程任务列表 - */ - List getTaskInfo(String processInstanceId); - /** * 通过任务 * @@ -95,7 +86,6 @@ public interface BpmTaskService { /** * 回退任务 * - * @param userId 用户id * @param reqVO 回退任务信息 */ CommonResult backTask(BpmTaskBackReqVO reqVO); diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java index 70def931a..baaca08d8 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmTaskServiceImpl.java @@ -18,8 +18,8 @@ import cn.iocoder.yudao.module.bpm.dal.mysql.task.BpmTaskExtMapper; import cn.iocoder.yudao.module.bpm.domain.enums.definition.BpmTaskAssignRuleTypeEnum; import cn.iocoder.yudao.module.bpm.domain.enums.task.BpmProcessInstanceResultEnum; import cn.iocoder.yudao.module.bpm.service.message.BpmMessageService; +import cn.iocoder.yudao.module.business.hi.task.inst.service.HiTaskInstService; import cn.iocoder.yudao.module.system.api.dept.DeptApi; -import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO; import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; import lombok.extern.slf4j.Slf4j; @@ -45,7 +45,6 @@ import java.util.stream.Collectors; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; -import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLoginUserId; import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*; /** @@ -79,6 +78,8 @@ public class BpmTaskServiceImpl implements BpmTaskService { private BpmTaskAssignRuleMapper taskAssignRuleMapper; @Resource private BpmActivityMapper bpmActivityMapper; + @Resource + private HiTaskInstService hiTaskInstService; @Override public PageResult getTodoTaskPage(Long userId, BpmTaskTodoPageReqVO pageVO) { @@ -160,22 +161,22 @@ public class BpmTaskServiceImpl implements BpmTaskService { @Override public List getTaskListByProcessInstanceId(String processInstanceId) { // 获得任务列表 - List tasks = + /* List tasks = historyService.createHistoricTaskInstanceQuery().processInstanceId(processInstanceId) .orderByHistoricTaskInstanceStartTime().desc() // 创建时间倒序 .list(); if (CollUtil.isEmpty(tasks)) { return Collections.emptyList(); - } + }*/ // 获得 TaskExtDO Map // List bpmTaskExtDOList = // taskExtMapper.selectListByTaskIds(convertSet(tasks, HistoricTaskInstance::getId)); - List bpmTaskExtDOList = taskExtMapper.listByProcInstId(processInstanceId); +// List bpmTaskExtDOList = taskExtMapper.listByProcInstId(processInstanceId); // List bpmTaskExtDOList = BpmTaskConvert.INSTANCE.distinct(tmpBpmTaskExtDOList); // bpmTaskExtDOList.forEach(var -> log.info("var = " + var)); - Map bpmTaskExtDoMap = convertMap(bpmTaskExtDOList, BpmTaskExtDO::getTaskId); + /*Map bpmTaskExtDoMap = convertMap(bpmTaskExtDOList, BpmTaskExtDO::getTaskId); // 获得 ProcessInstance Map HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(processInstanceId); // 获得 User Map @@ -183,28 +184,11 @@ public class BpmTaskServiceImpl implements BpmTaskService { userIds.add(NumberUtils.parseLong(processInstance.getStartUserId())); Map userMap = adminUserApi.getUserMap(userIds); // 获得 Dept Map - Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId)); + Map deptMap = deptApi.getDeptMap(convertSet(userMap.values(), AdminUserRespDTO::getDeptId));*/ // 拼接数据 - return BpmTaskConvert.INSTANCE.convertList3(tasks, bpmTaskExtDoMap, processInstance, userMap, deptMap); - } - - @Override - public List getTaskInfo(String processInstanceId) { - - List bpmTaskExtDOList = taskExtMapper.listByProcInstId(processInstanceId); - - Map bpmTaskExtDoMap = convertMap(bpmTaskExtDOList, BpmTaskExtDO::getTaskId); - // 获得 ProcessInstance Map - HistoricProcessInstance processInstance = processInstanceService.getHistoricProcessInstance(processInstanceId); - // 获得 User Map - Set userIds = bpmTaskExtDOList.stream().map(BpmTaskExtDO::getAssigneeUserId).collect(Collectors.toSet()); - userIds.add(NumberUtils.parseLong(processInstance.getStartUserId())); - Map userMap = adminUserApi.getUserMap(userIds); - - - // 拼接数据 - return new ArrayList<>(); + List tmpBpmTaskExtDOList = taskExtMapper.listByProcInstId(processInstanceId); + return hiTaskInstService.taskGetComment(tmpBpmTaskExtDOList, ""); } @Override diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/domain/HistoricApproveTaskDTO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/domain/HistoricApproveTaskDTO.java index f0ead736f..0bb580d68 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/domain/HistoricApproveTaskDTO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/domain/HistoricApproveTaskDTO.java @@ -1,4 +1,4 @@ -package net.lab1024.smartadmin.module.business.approve.camunda.hi.task.inst.domain; +package cn.iocoder.yudao.module.business.hi.task.inst.domain; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/domain/vo/HiTaskinstVO.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/domain/vo/HiTaskinstVO.java index 1ed7e0520..b8547c6bb 100644 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/domain/vo/HiTaskinstVO.java +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/domain/vo/HiTaskinstVO.java @@ -1,4 +1,4 @@ -package net.lab1024.smartadmin.module.business.approve.camunda.hi.task.inst.domain.vo; +package cn.iocoder.yudao.module.business.hi.task.inst.domain.vo; import lombok.Data; import java.util.Date; diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/service/HiTaskInstService.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/service/HiTaskInstService.java new file mode 100644 index 000000000..030094e15 --- /dev/null +++ b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/service/HiTaskInstService.java @@ -0,0 +1,350 @@ +package cn.iocoder.yudao.module.business.hi.task.inst.service; + +import cn.hutool.core.bean.BeanUtil; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore; +import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO; +import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskTodoPageItemRespVO; +import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmTaskAssignRuleDO; +import cn.iocoder.yudao.module.bpm.dal.dataobject.task.BpmTaskExtDO; +import cn.iocoder.yudao.module.bpm.dal.mysql.definition.BpmTaskAssignRuleMapper; +import cn.iocoder.yudao.module.bpm.domain.enums.definition.BpmTaskAssignRuleTypeEnum; +import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService; +import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO; +import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO; +import cn.iocoder.yudao.module.system.dal.mysql.dept.DeptMapper; +import cn.iocoder.yudao.module.system.dal.mysql.user.AdminUserMapper; +import lombok.extern.slf4j.Slf4j; +import org.flowable.bpmn.model.*; +import org.flowable.common.engine.impl.de.odysseus.el.ExpressionFactoryImpl; +import org.flowable.common.engine.impl.de.odysseus.el.util.SimpleContext; +import org.flowable.common.engine.impl.javax.el.ExpressionFactory; +import org.flowable.common.engine.impl.javax.el.ValueExpression; +import org.flowable.engine.*; +import org.flowable.engine.history.HistoricProcessInstance; +import org.flowable.task.api.history.HistoricTaskInstance; +import org.flowable.variable.api.history.HistoricVariableInstance; +import org.springframework.stereotype.Service; + +import javax.annotation.Resource; +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +/** + * [ ] + * + * @author 孟凯 + * @version 1.0 + */ +@Slf4j +@Service +public class HiTaskInstService { + + @Resource + private HistoryService historyService; + @Resource + private RepositoryService repositoryService; + @Resource + private BpmTaskAssignRuleMapper bpmTaskAssignRuleMapper; + @Resource + private BpmProcessInstanceService processInstanceService; + @Resource + private AdminUserMapper adminUserApi; + @Resource + private DeptMapper deptMapper; + + /** + * 获取任务具体流程信息 + * + * @param taskList 任务信息 + * @param approved 任意选择条件 + * + * @return 返回流程信息 + */ + @TenantIgnore + public List taskGetComment(List taskList, Object approved) { + BpmTaskExtDO task = taskList.get(taskList.size() - 1); + Map bpmTaskMap = + taskList.stream().collect(Collectors.toMap(BpmTaskExtDO::getTaskId, Function.identity())); + // 获得 ProcessInstance Map + HistoricProcessInstance procInst = + processInstanceService.getHistoricProcessInstance(task.getProcessInstanceId()); + Map userDoMap = + adminUserApi.selectList().stream().collect(Collectors.toMap(AdminUserDO::getId, Function.identity())); + Map deptMap = + deptMapper.selectList().stream().collect(Collectors.toMap(DeptDO::getId, Function.identity())); + List hisTaskInstList = + historyService.createHistoricTaskInstanceQuery().processInstanceId(task.getProcessInstanceId()) + .orderByHistoricTaskInstanceStartTime().desc().list(); + LinkedList bpmTaskRespVOList = + nowTaskFormat(procInst, hisTaskInstList, bpmTaskMap, userDoMap, deptMap); + + //ProcessInstanceId流程实例 + String procInstId = task.getProcessInstanceId(); + List tmpBpmTaskAssignRuleDOList = + bpmTaskAssignRuleMapper.selectListByProcessDefinitionId(task.getProcessDefinitionId(), null); + List hisVarInstList = + historyService.createHistoricVariableInstanceQuery().processInstanceId(procInstId).list(); + Map hisVarInstMap = new HashMap<>(); + for (HistoricVariableInstance hisVarInst : hisVarInstList) { + hisVarInstMap.put(hisVarInst.getVariableName(), hisVarInst.getValue()); + } + hisVarInstMap.put("approved", approved); + //获取bpm(模型)对象 + BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId()); + getFlow(bpmnModel, task.getTaskDefKey(), tmpBpmTaskAssignRuleDOList, bpmTaskRespVOList, userDoMap, deptMap, + hisVarInstMap); + return bpmTaskRespVOList; + } + + /** + * 格式化任务信息 + */ + private LinkedList nowTaskFormat(HistoricProcessInstance procInst, List taskList, + Map bpmTaskExtDoMap, Map userMap, Map deptMap) { + LinkedList bpmTaskRespVOList = new LinkedList<>(); + for (HistoricTaskInstance hisTaskInst : taskList) { + BpmTaskRespVO respVO = initRespVo(hisTaskInst, bpmTaskExtDoMap, procInst, userMap); + AdminUserDO user = userMap.get(Long.valueOf(hisTaskInst.getAssignee())); + if (BeanUtil.isNotEmpty(user)) { + respVO.setAssigneeUser(setUser(user)); + DeptDO dept = deptMap.get(user.getDeptId()); + if (BeanUtil.isNotEmpty(dept)) { + respVO.getAssigneeUser().setDeptName(dept.getName()); + } + } + bpmTaskRespVOList.addFirst(respVO); + } + return bpmTaskRespVOList; + } + + private BpmTaskRespVO initRespVo(Object taskInst, Map bpmTaskExtDoMap, + HistoricProcessInstance procInst, Map userMap) { + BpmTaskRespVO respVO = new BpmTaskRespVO(); + if (taskInst instanceof HistoricTaskInstance) { + respVO = setBpmnTaskRespVo((HistoricTaskInstance)taskInst); + BeanUtil.copyProperties(taskInst, respVO); + BpmTaskExtDO bpmTaskExtDO = bpmTaskExtDoMap.get(respVO.getId()); + if (ObjectUtil.isNotEmpty(bpmTaskExtDO)) { + BeanUtil.copyProperties(bpmTaskExtDO, respVO); + respVO.setId(bpmTaskExtDO.getTaskId()); + } + } + if (taskInst instanceof BpmTaskExtDO) { + respVO = setBpmnTaskRespVo((BpmTaskExtDO)taskInst); + BeanUtil.copyProperties(taskInst, respVO); + } + // copyTo(bpmTaskExtDO, respVO); + if (procInst != null) { + AdminUserDO startUser = userMap.get(Long.valueOf(procInst.getStartUserId())); + if (BeanUtil.isEmpty(startUser)) { + throw new RuntimeException("查找不到审批用户!!!"); + } + respVO.setProcessInstance(setProcInst(procInst, startUser)); + } + return respVO; + } + + private BpmTaskRespVO.User setUser(AdminUserDO bean) { + if (bean == null) { + return null; + } + + BpmTaskRespVO.User user = new BpmTaskRespVO.User(); + + user.setId(bean.getId()); + user.setNickname(bean.getNickname()); + user.setDeptId(bean.getDeptId()); + + return user; + + } + + private BpmTaskRespVO setBpmnTaskRespVo(BpmTaskExtDO bean) { + if (bean == null) { + return null; + } + + BpmTaskRespVO bpmTaskRespVO = new BpmTaskRespVO(); + + bpmTaskRespVO.setDefinitionKey(bean.getTaskDefKey()); + bpmTaskRespVO.setId(bean.getTaskId()); + bpmTaskRespVO.setName(bean.getName()); + bpmTaskRespVO.setCreateTime(bean.getCreateTime()); + + return bpmTaskRespVO; + } + + public BpmTaskRespVO setBpmnTaskRespVo(HistoricTaskInstance bean) { + if (bean == null) { + return null; + } + + BpmTaskRespVO bpmTaskRespVO = new BpmTaskRespVO(); + + bpmTaskRespVO.setDefinitionKey(bean.getTaskDefinitionKey()); + bpmTaskRespVO.setId(bean.getId()); + bpmTaskRespVO.setName(bean.getName()); + bpmTaskRespVO.setClaimTime(bean.getClaimTime()); + bpmTaskRespVO.setCreateTime(bean.getCreateTime()); + bpmTaskRespVO.setEndTime(bean.getEndTime()); + bpmTaskRespVO.setDurationInMillis(bean.getDurationInMillis()); + + return bpmTaskRespVO; + } + + public BpmTaskTodoPageItemRespVO.ProcessInstance setProcInst(HistoricProcessInstance processInstance, + AdminUserDO startUser) { + if (processInstance == null && startUser == null) { + return null; + } + + BpmTaskTodoPageItemRespVO.ProcessInstance processInstanceResult = + new BpmTaskTodoPageItemRespVO.ProcessInstance(); + + if (processInstance != null) { + processInstanceResult.setId(processInstance.getId()); + processInstanceResult.setName(processInstance.getName()); + if (processInstance.getStartUserId() != null) { + processInstanceResult.setStartUserId(Long.parseLong(processInstance.getStartUserId())); + } + processInstanceResult.setProcessDefinitionId(processInstance.getProcessDefinitionId()); + } + if (startUser != null) { + processInstanceResult.setStartUserNickname(startUser.getNickname()); + } + + return processInstanceResult; + } + + private void getFlow(BpmnModel bpmnModel, String taskDefKey, List tmpBpmTaskAssignRuleDOList, + LinkedList bpmTaskRespVOList, Map userDoMap, Map deptMap, + Map taskVarMap) { + //传节点定义key获取当前节点 + FlowNode flowNode = (FlowNode)bpmnModel.getFlowElement(taskDefKey); + //输出连线 + List outgoingFlows = flowNode.getOutgoingFlows(); + //遍历返回下一个节点信息 + for (SequenceFlow outgoingFlow : outgoingFlows) { + //类型自己判断(获取下个节点是网关还是节点) + FlowElement targetFlowElement = outgoingFlow.getTargetFlowElement(); + getFlow(bpmnModel, targetFlowElement, tmpBpmTaskAssignRuleDOList, bpmTaskRespVOList, userDoMap, deptMap, + taskVarMap); + } + } + + private void getFlow(BpmnModel bpmnModel, FlowElement targetFlowElement, + List tmpBpmTaskAssignRuleDOList, LinkedList bpmTaskRespVOList, + Map userDoMap, Map deptMap, Map taskVarMap) { + // 下一个taskDefKey + String nextTaskDefKey = null; + //下个是节点 + if (targetFlowElement instanceof UserTask) { + // 判断是否是为并行任务 + List bpmTaskAssignRuleDOList = tmpBpmTaskAssignRuleDOList.stream().filter( + bpmTaskAssignRuleDO -> bpmTaskAssignRuleDO.getTaskDefinitionKey().equals(targetFlowElement.getId())) + .collect(Collectors.toList()); + if (CollUtil.isEmpty(bpmTaskAssignRuleDOList)) { + throw new RuntimeException("任务key不存在!!!"); + } + for (BpmTaskAssignRuleDO bpmTaskAssignRuleDO : bpmTaskAssignRuleDOList) { + nextTaskDefKey = bpmTaskAssignRuleDO.getTaskDefinitionKey(); + for (Long userId : bpmTaskAssignRuleDO.getOptions()) { + BpmTaskRespVO bpmTaskRespVO = + (BpmTaskRespVO)new BpmTaskRespVO().setName(targetFlowElement.getName()); + bpmTaskRespVOList.addFirst(bpmTaskRespVO); + AdminUserDO adminUserDO = userDoMap.get(userId); + DeptDO deptDO = deptMap.get(adminUserDO.getDeptId()); + bpmTaskRespVO.setAssigneeUser(setUser(adminUserDO)); + bpmTaskRespVO.getAssigneeUser().setDeptName(deptDO.getName()); + if (!bpmTaskAssignRuleDO.getType().equals(BpmTaskAssignRuleTypeEnum.USER_OR_SIGN.getType()) + && !bpmTaskAssignRuleDO.getType().equals(BpmTaskAssignRuleTypeEnum.USER_SIGN.getType())) { + break; + } + } + } + getFlow(bpmnModel, nextTaskDefKey, tmpBpmTaskAssignRuleDOList, bpmTaskRespVOList, userDoMap, deptMap, + taskVarMap); + // 下个节点是网关(调用下面的方法) + } else if (targetFlowElement instanceof ExclusiveGateway) { + String defaultFlow = ((ExclusiveGateway)targetFlowElement).getDefaultFlow(); + FlowElement nexFlowElement = getExclusiveGateway(targetFlowElement, taskVarMap, defaultFlow); + getFlow(bpmnModel, nexFlowElement, tmpBpmTaskAssignRuleDOList, bpmTaskRespVOList, userDoMap, deptMap, + taskVarMap); + } + } + + /** + * 获取排他网关分支名称、分支表达式、下一级任务节点 + * + * @param flowElement 任务节点 + * @param taskVarMap 审批数据 + */ + private FlowElement getExclusiveGateway(FlowElement flowElement, Map taskVarMap, + String defaultFlow) { + // 获取所有网关分支 + List targetFlows = ((ExclusiveGateway)flowElement).getOutgoingFlows(); + Boolean elExpressionFlag = Boolean.FALSE; + FlowElement sequenceFlowResult = null; + FlowElement defaultSequenceFlow = null; + // 循环每个网关分支 + for (SequenceFlow sequenceFlow : targetFlows) { + if (defaultFlow.equals(sequenceFlow.getId())) { + defaultSequenceFlow = sequenceFlow.getTargetFlowElement(); + continue; + } + elExpressionFlag = elExpression(sequenceFlow.getConditionExpression(), taskVarMap); + if (elExpressionFlag) { + // 获取下一个网关和节点数据 + FlowElement targetFlowElement = sequenceFlow.getTargetFlowElement(); + // 网关的下个节点是用户节点 + if (targetFlowElement instanceof UserTask) { + sequenceFlowResult = targetFlowElement; + break; + } else if (targetFlowElement instanceof EndEvent) { + log.info("排他网关的下一节点是EndEvent: 结束节点"); + } else if (targetFlowElement instanceof ServiceTask) { + log.info("排他网关的下一节点是ServiceTask: 内部方法"); + } else if (targetFlowElement instanceof ExclusiveGateway) { + defaultFlow = ((ExclusiveGateway)targetFlowElement).getDefaultFlow(); + return getExclusiveGateway(targetFlowElement, taskVarMap, defaultFlow); + } else if (targetFlowElement instanceof SubProcess) { + log.info("排他网关的下一节点是SubProcess: 内部子流程"); + } + } + } + if (!elExpressionFlag) { + if (defaultSequenceFlow instanceof UserTask) { + sequenceFlowResult = defaultSequenceFlow; + } else if (defaultSequenceFlow instanceof ExclusiveGateway) { + defaultFlow = ((ExclusiveGateway)defaultSequenceFlow).getDefaultFlow(); + return getExclusiveGateway(defaultSequenceFlow, taskVarMap, defaultFlow); + } + } + return sequenceFlowResult; + } + + /** + * 网关分叉条件判断,网关分叉,必须要有默认出口 + * + * @param elExpression el表达式 + * @param variableMap 流程所有变量 + * + * @return 返回true或false + */ + private Boolean elExpression(String elExpression, Map variableMap) { + ExpressionFactory factory = new ExpressionFactoryImpl(); + SimpleContext context = new SimpleContext(); + for (String k : variableMap.keySet()) { + if (variableMap.get(k) != null) { + context.setVariable(k, + factory.createValueExpression(variableMap.get(k), variableMap.get(k).getClass())); + } + } + ValueExpression e = factory.createValueExpression(context, elExpression, Boolean.class); + //el表达式和variables得到的结果 + return (Boolean)e.getValue(context); + } +} diff --git a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/service/HiTaskinstService.java b/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/service/HiTaskinstService.java deleted file mode 100644 index 0939de883..000000000 --- a/yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/business/hi/task/inst/service/HiTaskinstService.java +++ /dev/null @@ -1,263 +0,0 @@ -package cn.iocoder.yudao.module.business.hi.task.inst.service; - -import cn.hutool.core.bean.BeanUtil; -import cn.hutool.core.collection.CollUtil; -import cn.hutool.core.util.BooleanUtil; -import cn.hutool.json.JSONUtil; -import cn.iocoder.yudao.module.bpm.domain.vo.ApproveProcInstVO; -import lombok.extern.slf4j.Slf4j; -import org.flowable.common.engine.impl.de.odysseus.el.util.SimpleContext; -import org.flowable.engine.HistoryService; -import org.flowable.engine.RepositoryService; -import org.flowable.engine.TaskService; -import org.flowable.variable.api.history.HistoricVariableInstance; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -import java.util.*; - -/** - * [ ] - * - * @author 孟凯 - * @version 1.0 - * @company 1024创新实验室(www.1024lab.net) - * @copyright (c) 1024创新实验室( www.1024lab.net )Inc. All rights reserved. - * @date 2022-01-17 15:14:27 - * @since JDK1.8 - */ -@Slf4j -@Service -public class HiTaskinstService { - - - @Autowired - private TaskService taskService; - @Autowired - private HistoryService historyService; - @Autowired - private RepositoryService repositoryService; - - /** - * 获取任务具体流程信息 - * - * @param procInstId 流程id - * @param procDefId 流程部署id - * - * @return 返回流程信息 - */ - public List taskGetComment(String procInstId, String procDefId) { - Map variableMap = new HashMap<>(50); - List hisVarInstList = - historyService.createHistoricVariableInstanceQuery().processInstanceId(procInstId).list(); - hisVarInstList.forEach(hisVarInst -> { - variableMap.put(hisVarInst.getName(), hisVarInst.getValue()); - }); - - List procInstVOList = hiTaskinstDao.listByProcInstIdAndNotDelete(procInstId); - - BpmnModelInstance bpmnModelInstance = repositoryService.getBpmnModel(procDefId); - DomElement document1 = bpmnModelInstance.getDocument().getElementById(procDefId.split(":")[0]); - LinkedHashMap domElementMap = new LinkedHashMap<>(50); - getChildElementToMap(document1, domElementMap); - getChildNode(procInstVOList, domElementMap, variableMap); - return procInstVOList; - } - - /** - * 获取子节点信息,存储到map中 - * - * @param domElement 父节点 - * @param domElementMap 节点map - */ - private void getChildElementToMap(DomElement domElement, LinkedHashMap domElementMap) { - List childElements = domElement.getChildElements(); - for (DomElement childElement : childElements) { - if ("BPMNDiagram".equals(childElement.getLocalName())) { - break; - } - if ("extensionElements".equals(childElement.getLocalName())) { - break; - } - if (!"outgoing".equals(childElement.getLocalName()) && !"incoming".equals(childElement.getLocalName())) { - domElementMap.put(childElement.getAttribute("id"), childElement); - } - getChildElementToMap(childElement, domElementMap); - } - } - - /** - * 获取子节点信息 - * - * @param procInstVOList 流程VO列表 - * @param domElementMap 节点map - * @param variableMap 流程所有的变量 - */ - private void getChildNode(List procInstVOList, LinkedHashMap domElementMap, - Map variableMap) { - DomElement domElement = domElementMap.get(procInstVOList.get(procInstVOList.size() - 1).getTaskDefKey()); - for (DomElement childElement : domElement.getChildElements()) { - if ("outgoing".equals(childElement.getLocalName())) { - DomElement tmpDomElement = domElementMap.get(childElement.getTextContent()); - getChildNode(procInstVOList, domElementMap, variableMap, tmpDomElement); - } - } - } - - /** - * 获取子节点信息 - * - * @param procInstVOList 流程VO列表 - * @param domElementMap 节点map - * @param variableMap 流程所有的变量 - * @param domElement 父节点信息 - */ - private void getChildNode(List procInstVOList, LinkedHashMap domElementMap, - Map variableMap, DomElement domElement) { - if ("exclusiveGateway".equals(domElement.getLocalName())) { - DomElement domElementChild = getNodeExclusiveGateway(domElementMap, variableMap, domElement); - getChildNode(procInstVOList, domElementMap, variableMap, domElementChild); - } else if ("userTask".equals(domElement.getLocalName())) { - getProcInstVO(procInstVOList, domElement, variableMap); - for (DomElement childElement : domElement.getChildElements()) { - if ("outgoing".equals(childElement.getLocalName())) { - DomElement tmpDomElement = domElementMap.get(childElement.getTextContent()); - DomElement domElementChild = getNodeBySequenceFlow(domElementMap, tmpDomElement); - if ("endEvent".equals(domElementChild.getLocalName())) { - return; - } - getChildNode(procInstVOList, domElementMap, variableMap, domElementChild); - } - } - } else { - DomElement domElementChild = getNodeBySequenceFlow(domElementMap, domElement); - if (BeanUtil.isEmpty(domElementChild)) { - throw new RuntimeException("无流程可执行!!!"); - } - if ("endEvent".equals(domElementChild.getLocalName())) { - return; - } - getChildNode(procInstVOList, domElementMap, variableMap, domElementChild); - } - } - - /** - * 获取网关节点的子节点 - * - * @param domElementMap 流程所有的节点 - * @param variableMap 流程所有的变量 - * @param domElement 父节点信息 - * - * @return 返回子节点信息 - */ - private DomElement getNodeExclusiveGateway(LinkedHashMap domElementMap, - Map variableMap, DomElement domElement) { - Boolean elExpressionFlag = Boolean.FALSE; - ArrayList nullChildSequenceFlowList = new ArrayList<>(); - for (DomElement exclusiveGatewayChild : domElement.getChildElements()) { - if ("outgoing".equals(exclusiveGatewayChild.getLocalName()) && BooleanUtil.isFalse(elExpressionFlag)) { - DomElement sequenceFlowDomElement = domElementMap.get(exclusiveGatewayChild.getTextContent()); - if (CollUtil.isNotEmpty(sequenceFlowDomElement.getChildElements()) - && sequenceFlowDomElement.getChildElements().size() > 0) { - for (DomElement conditionExpression : sequenceFlowDomElement.getChildElements()) { - if ("conditionExpression".equals(conditionExpression.getLocalName())) { - elExpressionFlag = elExpression(conditionExpression.getTextContent(), variableMap); - if (BooleanUtil.isTrue(elExpressionFlag)) { - break; - } - } - } - } else { - nullChildSequenceFlowList.add(sequenceFlowDomElement); - } - if (elExpressionFlag) { - return getNodeBySequenceFlow(domElementMap, sequenceFlowDomElement); - } - } - } - if (CollUtil.isEmpty(nullChildSequenceFlowList) && nullChildSequenceFlowList.size() < 1) { - throw new RuntimeException("网关缺少无条件流程可执行!!!"); - } - if (nullChildSequenceFlowList.size() > 1) { - throw new RuntimeException("无条件流程大于1条!!!"); - } - return getNodeBySequenceFlow(domElementMap, nullChildSequenceFlowList.get(0)); - } - - /** - * 获取流程序列流的子节点 - * - * @param domElementMap 流程所有节点 - * @param domElement 父节点信息 - * - * @return 返回子节点 - */ - private DomElement getNodeBySequenceFlow(LinkedHashMap domElementMap, DomElement domElement) { - String targetRef = domElement.getAttribute("targetRef"); - return domElementMap.get(targetRef); - } - - /** - * 设置节点信息进ApproveProcInstVO - * - * @param procInstVOList ApproveProcInstVOList - * @param domElement 节点信息 - * @param variableMap 流程所有变量 - */ - private void getProcInstVO(List procInstVOList, DomElement domElement, - Map variableMap) { - String camundaNameSpaceUri = "http://camunda.org/schema/1.0/bpmn"; - boolean userListFlag = false; - List approveProcInstVOList = new ArrayList<>(); - for (DomElement childElement : domElement.getChildElements()) { - if ("multiInstanceLoopCharacteristics".equals(childElement.getLocalName())) { - userListFlag = true; - String collectionVar = childElement.getAttribute(camundaNameSpaceUri, "collection"); - Object taskUserList = variableMap.get(collectionVar); - approveProcInstVOList = JSONUtil.parseArray(taskUserList); - } - } - - if (userListFlag) { - approveProcInstVOList.forEach(tmpAssignee -> { - String assignee = String.valueOf(tmpAssignee); - ApproveProcInstVO approveProcInstVO = new ApproveProcInstVO(); - approveProcInstVO.setName(domElement.getAttribute("name")); - approveProcInstVO.setTaskDefKey(domElement.getAttribute("id")); - approveProcInstVO.setAssignee(assignee); - approveProcInstVO.setAssigneeName(employeeDao.getByLoginName(assignee, 0).getActualName()); - procInstVOList.add(approveProcInstVO); - }); - } else { - ApproveProcInstVO approveProcInstVO = new ApproveProcInstVO(); - approveProcInstVO.setName(domElement.getAttribute("name")); - approveProcInstVO.setTaskDefKey(domElement.getAttribute("id")); - approveProcInstVO.setAssignee(domElement.getAttribute(camundaNameSpaceUri, "assignee")); - approveProcInstVO.setAssigneeName( - employeeDao.getByLoginName(approveProcInstVO.getAssignee(), 0).getActualName()); - procInstVOList.add(approveProcInstVO); - } - } - - /** - * 网关分叉条件判断,网关分叉,必须要有默认出口 - * - * @param elExpression el表达式 - * @param variableMap 流程所有变量 - * - * @return 返回true或false - */ - private Boolean elExpression(String elExpression, Map variableMap) { - ExpressionFactory factory = new ExpressionFactoryImpl(); - SimpleContext context = new SimpleContext(); - for (String k : variableMap.keySet()) { - if (variableMap.get(k) != null) { - context.setVariable(k, - factory.createValueExpression(variableMap.get(k), variableMap.get(k).getClass())); - } - } - ValueExpression e = factory.createValueExpression(context, elExpression, Boolean.class); - //el表达式和variables得到的结果 - return (Boolean)e.getValue(context); - } -}