fix:流程执行完成,更新算列状态
This commit is contained in:
6
.idea/MarsCodeWorkspaceAppSettings.xml
generated
Normal file
6
.idea/MarsCodeWorkspaceAppSettings.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="com.codeverse.userSettings.MarscodeWorkspaceAppSettingsState">
|
||||
<option name="progress" value="1.0" />
|
||||
</component>
|
||||
</project>
|
||||
@@ -51,4 +51,15 @@ public class SimulationRunFeignClientImpl implements ISimulationRunFeignClient {
|
||||
return SdmResponse.failed("内部调用生成自动化报告失败");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SdmResponse completeRunByFlowInstanceId(String flowInstanceId) {
|
||||
try {
|
||||
simulationRunFeignClient.completeRunByFlowInstanceId(flowInstanceId);
|
||||
return SdmResponse.success();
|
||||
}catch (Exception e){
|
||||
log.error("根据流程实例ID完成算列失败", e);
|
||||
return SdmResponse.failed("根据流程实例ID完成算列失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,4 +26,14 @@ public interface ISimulationRunFeignClient {
|
||||
@PostMapping("/run/generateReportInternal")
|
||||
SdmResponse<Void> generateReportInternal(@RequestBody SpdmReportReq req);
|
||||
|
||||
/**
|
||||
* 根据流程实例ID完成算列(将状态更新为完成)
|
||||
* 由Flowable流程结束监听器调用
|
||||
*
|
||||
* @param flowInstanceId 流程实例ID
|
||||
* @return SdmResponse
|
||||
*/
|
||||
@PostMapping("/run/completeRunByFlowInstanceId")
|
||||
SdmResponse completeRunByFlowInstanceId(@RequestParam("flowInstanceId") String flowInstanceId);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.sdm.flowable.listener;
|
||||
|
||||
import com.sdm.common.common.SdmResponse;
|
||||
import com.sdm.common.feign.inter.project.ISimulationRunFeignClient;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.flowable.engine.delegate.DelegateExecution;
|
||||
import org.flowable.engine.delegate.ExecutionListener;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 流程结束监听器
|
||||
* 当流程执行到结束事件(EndEvent)时触发,自动更新算列表(SimulationRun)的状态为完成
|
||||
*/
|
||||
@Slf4j
|
||||
@Component("processEndListener")
|
||||
public class ProcessEndListener implements ExecutionListener {
|
||||
|
||||
@Autowired
|
||||
private ISimulationRunFeignClient simulationRunFeignClient;
|
||||
|
||||
@Override
|
||||
public void notify(DelegateExecution execution) {
|
||||
try {
|
||||
// 获取流程变量
|
||||
String runId = (String) execution.getVariable("runId");
|
||||
String processInstanceId = execution.getProcessInstanceId();
|
||||
String processDefinitionId = execution.getProcessDefinitionId();
|
||||
|
||||
log.info("流程结束监听器触发 - 流程实例ID: {}, 流程定义ID: {}, runId: {}",
|
||||
processInstanceId, processDefinitionId, runId);
|
||||
|
||||
// 校验必要参数
|
||||
if (StringUtils.isBlank(runId)) {
|
||||
log.warn("流程结束监听器: runId为空,无法更新算列表状态。流程实例ID: {}", processInstanceId);
|
||||
return;
|
||||
}
|
||||
|
||||
// 调用project服务更新算列表状态为完成
|
||||
SdmResponse response = simulationRunFeignClient.completeRunByFlowInstanceId(processInstanceId);
|
||||
|
||||
if (response.isSuccess()) {
|
||||
log.info("流程结束监听器: 算列表状态更新成功 - runId: {}, 流程实例ID: {}", runId, processInstanceId);
|
||||
} else {
|
||||
log.error("流程结束监听器: 算列表状态更新失败 - runId: {}, 流程实例ID: {}, 错误信息: {}",
|
||||
runId, processInstanceId, response.getMessage());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// 异常不应该影响流程的正常结束,只记录日志
|
||||
log.error("流程结束监听器执行异常 - 流程实例ID: {}, 异常信息: {}",
|
||||
execution.getProcessInstanceId(), e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -511,6 +511,14 @@ public class Dto2BpmnConverter {
|
||||
EndEvent endEvent = new EndEvent();
|
||||
endEvent.setId(nodeDto.getId());
|
||||
endEvent.setName(nodeDto.getName());
|
||||
|
||||
// 添加流程结束监听器,在进入结束节点时触发
|
||||
FlowableListener processEndListener = new FlowableListener();
|
||||
processEndListener.setEvent("start"); // 进入结束节点时触发
|
||||
processEndListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
|
||||
processEndListener.setImplementation("${processEndListener}");
|
||||
endEvent.getExecutionListeners().add(processEndListener);
|
||||
|
||||
process.addFlowElement(endEvent);
|
||||
log.info("创建结束事件节点 nodeId:{}", nodeDto.getId());
|
||||
break;
|
||||
|
||||
@@ -395,4 +395,17 @@ public class SimulationRunController implements ISimulationRunFeignClient {
|
||||
return runService.syncKeyResultToTask(req);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据流程实例ID完成算列(将状态更新为完成)
|
||||
* 由Flowable流程结束监听器调用
|
||||
*
|
||||
* @param flowInstanceId 流程实例ID
|
||||
* @return SdmResponse
|
||||
*/
|
||||
@SysLog("根据流程实例ID完成算列")
|
||||
@PostMapping("/completeRunByFlowInstanceId")
|
||||
@Override
|
||||
public SdmResponse completeRunByFlowInstanceId(@RequestParam("flowInstanceId") String flowInstanceId) {
|
||||
return runService.completeRunByFlowInstanceId(flowInstanceId);
|
||||
}
|
||||
}
|
||||
@@ -110,4 +110,13 @@ public interface ISimulationRunService extends IService<SimulationRun> {
|
||||
|
||||
SdmResponse syncKeyResultToTask(KeyResultReq req);
|
||||
|
||||
/**
|
||||
* 根据流程实例ID完成算列(将状态更新为完成)
|
||||
* 由Flowable流程结束监听器调用
|
||||
*
|
||||
* @param flowInstanceId 流程实例ID
|
||||
* @return SdmResponse
|
||||
*/
|
||||
SdmResponse completeRunByFlowInstanceId(String flowInstanceId);
|
||||
|
||||
}
|
||||
@@ -2309,4 +2309,44 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
|
||||
}
|
||||
return SdmResponse.success();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public SdmResponse completeRunByFlowInstanceId(String flowInstanceId) {
|
||||
try {
|
||||
log.info("开始根据流程实例ID完成算列 - flowInstanceId: {}", flowInstanceId);
|
||||
|
||||
// 根据流程实例ID查询算列
|
||||
SimulationRun simulationRun = this.lambdaQuery()
|
||||
.eq(SimulationRun::getFlowInstanceId, flowInstanceId)
|
||||
.one();
|
||||
|
||||
if (simulationRun == null) {
|
||||
log.warn("未找到对应的算列记录 - flowInstanceId: {}", flowInstanceId);
|
||||
return SdmResponse.failed("未找到对应的算列记录");
|
||||
}
|
||||
|
||||
// 更新状态为完成
|
||||
boolean updateResult = this.lambdaUpdate()
|
||||
.set(SimulationRun::getStatus, RunStatusEnum.COMPLETED.getCode())
|
||||
.set(SimulationRun::getFinishTime, LocalDateTime.now())
|
||||
.set(SimulationRun::getCurrentStep, simulationRun.getTotalStep()) // 将当前步骤设置为总步骤
|
||||
.eq(SimulationRun::getUuid, simulationRun.getUuid())
|
||||
.update();
|
||||
|
||||
if (updateResult) {
|
||||
log.info("算列状态更新成功 - runId: {}, flowInstanceId: {}, status: {}",
|
||||
simulationRun.getUuid(), flowInstanceId, RunStatusEnum.COMPLETED.getCode());
|
||||
return SdmResponse.success("算列状态更新成功");
|
||||
} else {
|
||||
log.error("算列状态更新失败 - runId: {}, flowInstanceId: {}",
|
||||
simulationRun.getUuid(), flowInstanceId);
|
||||
return SdmResponse.failed("算列状态更新失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("完成算列异常 - flowInstanceId: {}, 异常信息: {}", flowInstanceId, e.getMessage(), e);
|
||||
return SdmResponse.failed("完成算列异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user