From 513442b07fdc6ecdd1deb0e476a0b58ad7a51679 Mon Sep 17 00:00:00 2001 From: xuhy <3313886187@qq.com> Date: 星期五, 28 二月 2025 16:12:34 +0800 Subject: [PATCH] bug修改 --- ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StateProcessTemplateServiceImpl.java | 78 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 78 insertions(+), 0 deletions(-) diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StateProcessTemplateServiceImpl.java b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StateProcessTemplateServiceImpl.java index 9b71738..cbefcad 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StateProcessTemplateServiceImpl.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/service/impl/StateProcessTemplateServiceImpl.java @@ -27,6 +27,7 @@ import com.ruoyi.common.core.domain.BaseModel; import com.ruoyi.common.core.domain.entity.SysUser; import com.ruoyi.common.core.domain.model.LoginUser; +import com.ruoyi.common.core.domain.model.LoginUserApplet; import com.ruoyi.common.enums.StateProcessActionEnum; import com.ruoyi.common.enums.TaskEventType; import com.ruoyi.common.exception.GlobalException; @@ -300,6 +301,83 @@ } /** + * 启动流程 + * @param processStartBO + * @return + */ + @Transactional(rollbackFor = Exception.class) + @Override + public Boolean startApplet(ProcessStartBO processStartBO) { + String userId = "1"; + String nickName = "admin"; + FlowCreator creator = FlowCreator.of(userId, nickName); + //查询流程绑定 + StateProcessModule stateProcessModule = stateProcessModuleService.getOne(Wrappers.<StateProcessModule>lambdaQuery() + .eq(StateProcessModule::getCategory, processStartBO.getCategory())); + if (ObjectUtil.isNull(stateProcessModule) || ObjectUtil.isEmpty(stateProcessModule.getTemplateId())) { + throw new GlobalException("请先配置流程引擎模版!"); + } + //查询模版,准备启动 + StateProcessTemplate template = this.getById(stateProcessModule.getTemplateId()); + StateProcessTemplate lastTemplate = this.getOne(Wrappers.<StateProcessTemplate>lambdaQuery() + .eq(StateProcessTemplate::getTemplateKey, template.getTemplateKey()) + .apply("(template_key, template_version) in(" + + "SELECT template_key, MAX(template_version) " + + "FROM state_process_template " + + "GROUP BY template_key)") + ); + + if (ObjectUtil.isNull(lastTemplate)) { + throw new GlobalException(StateErrorCode.PROCESS_TEMPLATE_NOT_EXISTS.getValue()); + } + FlwProcess flwProcess = flowLongEngine.processService().getProcessById(lastTemplate.getWorkFlowId()); + if (ObjectUtil.isNull(flwProcess)) { + throw new GlobalException(StateErrorCode.PROCESS_NOT_DEPLOY.getValue()); + } + if (!Objects.equals(lastTemplate.getWorkflowVersion(), flwProcess.getProcessVersion())) { + throw new GlobalException(StateErrorCode.PROCESS_VERSION_ERROR.getValue()); + } + //监听器参数补全 + processStartBO.getVariable().put("category", processStartBO.getCategory()); + // 开启流程 + Optional<FlwInstance> flwInstanceOptional = flowLongEngine.startInstanceById(flwProcess.getId(), creator, processStartBO.getVariable()); + if(flwInstanceOptional.isPresent()){ + FlwInstance instance = flwInstanceOptional.get(); + //存储任务中心信息 + StateTaskCenter stateTaskCenter = new StateTaskCenter(); + stateTaskCenter.setId(IdUtils.simpleUUID()); + stateTaskCenter.setName(processStartBO.getName()); + stateTaskCenter.setModuleName(processStartBO.getModuleName()); + stateTaskCenter.setCategory(processStartBO.getCategory()); + stateTaskCenter.setFlowId(instance.getId().toString()); + stateTaskCenter.setRemark(processStartBO.getRemark()); + stateTaskCenter.setCreateBy(nickName); + stateTaskCenter.setVariable(JSONUtil.toJsonStr(processStartBO.getVariable())); + stateTaskCenter.setProjectId(JSONObject.parseObject(JSONUtil.toJsonStr(processStartBO.getVariable())).getString("projectId")); + stateTaskCenterService.save(stateTaskCenter); + + // action记录 + StateProcessInstanceAction stateProcessInstanceAction = new StateProcessInstanceAction(); + stateProcessInstanceAction.setId(IdUtils.simpleUUID()); + stateProcessInstanceAction.setInstanceId(instance.getId().toString()); + stateProcessInstanceAction.setActionType(StateProcessActionEnum.START.getValue()); + stateProcessInstanceAction.setAuditorId(creator.getCreateId()); + stateProcessInstanceActionService.save(stateProcessInstanceAction); + + // 添加拓展信息 + StateProcessExtInstance stateProcessExtInstance = new StateProcessExtInstance(); + stateProcessExtInstance.setId(instance.getId().toString()); + stateProcessExtInstance.setTemplateId(lastTemplate.getId()); + stateProcessExtInstance.setProcessId(flwProcess.getId().toString()); + + //保存version + stateProcessExtInstance.setProcessVersion(flwProcess.getProcessVersion()); + stateProcessExtInstanceService.save(stateProcessExtInstance); + } + return true; + } + + /** * 待办 * @param processTaskListBO * @return -- Gitblit v1.7.1