From 040ecb2532859f369518cb49287c5c2d4cf22308 Mon Sep 17 00:00:00 2001 From: gssong <1742057357@qq.com> Date: 星期一, 08 四月 2024 21:30:36 +0800 Subject: [PATCH] add 添加初始化配置数据(demo使用,不用可删除) --- /dev/null | 114 -------------------------------------- ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java | 24 ++++++++ 2 files changed, 24 insertions(+), 114 deletions(-) diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/flowable/cmd/CustomInjectUserTaskCmd.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/flowable/cmd/CustomInjectUserTaskCmd.java deleted file mode 100644 index a403c7c..0000000 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/flowable/cmd/CustomInjectUserTaskCmd.java +++ /dev/null @@ -1,114 +0,0 @@ -package org.dromara.workflow.flowable.cmd; - -import org.flowable.bpmn.BpmnAutoLayout; -import org.flowable.bpmn.model.*; -import org.flowable.bpmn.model.Process; -import org.flowable.common.engine.impl.interceptor.Command; -import org.flowable.common.engine.impl.interceptor.CommandContext; -import org.flowable.engine.impl.cmd.AbstractDynamicInjectionCmd; -import org.flowable.engine.impl.dynamic.BaseDynamicSubProcessInjectUtil; -import org.flowable.engine.impl.dynamic.DynamicUserTaskBuilder; -import org.flowable.engine.impl.persistence.entity.DeploymentEntity; -import org.flowable.engine.impl.persistence.entity.ExecutionEntity; -import org.flowable.engine.impl.persistence.entity.ProcessDefinitionEntity; - -import java.util.List; -import java.util.Map; - - -public class CustomInjectUserTaskCmd extends AbstractDynamicInjectionCmd implements Command<Void> { - - private final FlowElement currentElement; - private final String processInstanceId; - private final DynamicUserTaskBuilder dynamicUserTaskBuilder; - - public CustomInjectUserTaskCmd(String processInstanceId, DynamicUserTaskBuilder dynamicUserTaskBuilder, FlowElement currentElement) { - this.currentElement = currentElement; - this.processInstanceId = processInstanceId; - this.dynamicUserTaskBuilder = dynamicUserTaskBuilder; - } - - @Override - protected void updateBpmnProcess(CommandContext commandContext, Process process, BpmnModel bpmnModel, ProcessDefinitionEntity originalProcessDefinitionEntity, DeploymentEntity newDeploymentEntity) { - if (!(this.currentElement instanceof UserTask currentUserTask)) { - return; - } - if (currentUserTask.getOutgoingFlows().isEmpty() || currentUserTask.getOutgoingFlows().size() > 1) { - return; - } - SequenceFlow currentOutgoingFlow = currentUserTask.getOutgoingFlows().get(0); - FlowElement targetFlowElement = currentOutgoingFlow.getTargetFlowElement(); - //鍒涘缓鏂扮殑浠诲姟鑺傜偣鍜屼袱鏉¤繛绾� - UserTask newUserTask = createUserTask(process); - SequenceFlow newSequenceFlow1 = new SequenceFlow(currentUserTask.getId(), newUserTask.getId()); - newSequenceFlow1.setId(dynamicUserTaskBuilder.nextFlowId(process.getFlowElementMap())); - SequenceFlow newSequenceFlow2 = new SequenceFlow(newUserTask.getId(), targetFlowElement.getId()); - newSequenceFlow2.setId(dynamicUserTaskBuilder.nextFlowId(process.getFlowElementMap())); - //娣诲姞鍒版祦绋� - process.addFlowElement(newUserTask); - process.addFlowElement(newSequenceFlow1); - process.addFlowElement(newSequenceFlow2); - process.removeFlowElement(currentOutgoingFlow.getId()); - //鑾峰彇寮�濮嬭妭鐐� - StartEvent startEvent = process.findFlowElementsOfType(StartEvent.class, false).get(0); - //缁樺埗鏂扮殑娴佺▼鍥� - GraphicInfo elementGraphicInfo = bpmnModel.getGraphicInfo(currentUserTask.getId()); - if (elementGraphicInfo != null) { - double yDiff = 0; - double xDiff = 80; - if (elementGraphicInfo.getY() < 173) { - yDiff = 173 - elementGraphicInfo.getY(); - elementGraphicInfo.setY(173); - } - - Map<String, GraphicInfo> locationMap = bpmnModel.getLocationMap(); - for (String locationId : locationMap.keySet()) { - if (startEvent.getId().equals(locationId)) { - continue; - } - - GraphicInfo locationGraphicInfo = locationMap.get(locationId); - locationGraphicInfo.setX(locationGraphicInfo.getX() + xDiff); - locationGraphicInfo.setY(locationGraphicInfo.getY() + yDiff); - } - - Map<String, List<GraphicInfo>> flowLocationMap = bpmnModel.getFlowLocationMap(); - for (String flowId : flowLocationMap.keySet()) { - List<GraphicInfo> flowGraphicInfoList = flowLocationMap.get(flowId); - for (GraphicInfo flowGraphicInfo : flowGraphicInfoList) { - flowGraphicInfo.setX(flowGraphicInfo.getX() + xDiff); - flowGraphicInfo.setY(flowGraphicInfo.getY() + yDiff); - } - } - //绉婚櫎褰撳墠娴佺▼杩炵嚎 - bpmnModel.removeFlowGraphicInfoList(currentOutgoingFlow.getId()); - //閲嶆柊缁樺埗 - new BpmnAutoLayout(bpmnModel).execute(); - } - BaseDynamicSubProcessInjectUtil.processFlowElements(commandContext, process, bpmnModel, originalProcessDefinitionEntity, newDeploymentEntity); - } - - @Override - protected void updateExecutions(CommandContext commandContext, ProcessDefinitionEntity processDefinitionEntity, ExecutionEntity processInstance, List<ExecutionEntity> childExecutions) { - } - - private UserTask createUserTask(Process process) { - UserTask userTask = new UserTask(); - if (dynamicUserTaskBuilder.getId() != null) { - userTask.setId(dynamicUserTaskBuilder.getId()); - } else { - userTask.setId(dynamicUserTaskBuilder.nextTaskId(process.getFlowElementMap())); - } - dynamicUserTaskBuilder.setDynamicTaskId(userTask.getId()); - - userTask.setName(dynamicUserTaskBuilder.getName()); - userTask.setAssignee(dynamicUserTaskBuilder.getAssignee()); - return userTask; - } - - @Override - public Void execute(CommandContext commandContext) { - createDerivedProcessDefinitionForProcessInstance(commandContext, processInstanceId); - return null; - } -} diff --git a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java index 77b2b0a..1627eba 100644 --- a/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java +++ b/ruoyi-modules/ruoyi-workflow/src/main/java/org/dromara/workflow/service/impl/ActProcessDefinitionServiceImpl.java @@ -19,11 +19,13 @@ import org.dromara.common.tenant.helper.TenantHelper; import org.dromara.workflow.common.constant.FlowConstant; import org.dromara.workflow.domain.WfCategory; +import org.dromara.workflow.domain.WfDefinitionConfig; import org.dromara.workflow.domain.WfNodeConfig; import org.dromara.workflow.domain.bo.ProcessDefinitionBo; import org.dromara.workflow.domain.bo.WfDefinitionConfigBo; import org.dromara.workflow.domain.vo.ProcessDefinitionVo; import org.dromara.workflow.domain.vo.WfDefinitionConfigVo; +import org.dromara.workflow.mapper.WfDefinitionConfigMapper; import org.dromara.workflow.service.IActProcessDefinitionService; import org.dromara.workflow.service.IWfCategoryService; import org.dromara.workflow.service.IWfDefinitionConfigService; @@ -62,6 +64,7 @@ private final ProcessMigrationService processMigrationService; private final IWfCategoryService wfCategoryService; private final IWfDefinitionConfigService iWfDefinitionConfigService; + private final WfDefinitionConfigMapper wfDefinitionConfigMapper; private final IWfNodeConfigService iWfNodeConfigService; /** @@ -340,6 +343,8 @@ zipInputStream.close(); } } + //鍒濆鍖栭厤缃暟鎹紙demo浣跨敤锛屼笉鐢ㄥ彲鍒犻櫎锛� + initWfDefConfig(); } else { String originalFilename = file.getOriginalFilename(); String bpmnResourceSuffix = ResourceNameUtil.BPMN_RESOURCE_SUFFIXES[0]; @@ -370,6 +375,25 @@ } /** + * 鍒濆鍖栭厤缃暟鎹紙demo浣跨敤锛屼笉鐢ㄥ彲鍒犻櫎锛� + */ + private void initWfDefConfig() { + List<WfDefinitionConfig> wfDefinitionConfigs = wfDefinitionConfigMapper.selectList(); + if (CollUtil.isEmpty(wfDefinitionConfigs)) { + ProcessDefinition processDefinition = QueryUtils.definitionQuery().processDefinitionKey("leave1").latestVersion().singleResult(); + if (processDefinition != null) { + WfDefinitionConfigBo wfFormDefinition = new WfDefinitionConfigBo(); + wfFormDefinition.setDefinitionId(processDefinition.getId()); + wfFormDefinition.setProcessKey(processDefinition.getKey()); + wfFormDefinition.setTableName("test_leave"); + wfFormDefinition.setVersion(processDefinition.getVersion()); + iWfDefinitionConfigService.saveOrUpdate(wfFormDefinition); + } + } + + } + + /** * 璁剧疆琛ㄥ崟鍐呭 * * @param oldProcessDefinition 閮ㄧ讲鍓嶆渶鏂版祦绋嬪畾涔� -- Gitblit v1.9.3