| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 启动流程 |
| | | * @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 |