@@ -1,5 +1,6 @@
package com.sdm.project.service.impl ;
import com.alibaba.fastjson2.JSON ;
import com.alibaba.fastjson2.JSONObject ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
@@ -11,6 +12,8 @@ import com.sdm.common.common.SdmResponse;
import com.sdm.common.common.ThreadLocalContext ;
import com.sdm.common.entity.enums.DirTypeEnum ;
import com.sdm.common.entity.enums.NodeTypeEnum ;
import com.sdm.common.entity.flowable.dto.FlowElementDTO ;
import com.sdm.common.entity.flowable.dto.ProcessDefinitionDTO ;
import com.sdm.common.entity.req.capability.FlowNodeDto ;
import com.sdm.common.entity.req.data.* ;
import com.sdm.common.entity.req.system.UserQueryReq ;
@@ -20,6 +23,9 @@ import com.sdm.common.entity.resp.data.BatchAddFileInfoResp;
import com.sdm.common.entity.resp.data.FileMetadataInfoResp ;
import com.sdm.common.entity.resp.flowable.ProcessInstanceResp ;
import com.sdm.common.entity.resp.system.CIDUserResp ;
import com.sdm.common.feign.impl.capability.SimulationFlowFeignClientImpl ;
import com.sdm.common.feign.impl.data.DataClientFeignClientImpl ;
import com.sdm.common.feign.impl.flowable.FlowableClientFeignClientImpl ;
import com.sdm.common.feign.impl.system.SysUserFeignClientImpl ;
import com.sdm.common.feign.inter.capability.ISimulationFlowFeignClient ;
import com.sdm.common.feign.inter.data.IDataFeignClient ;
@@ -95,13 +101,13 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
SysUserFeignClientImpl sysUserFeignClient ;
@Autowired
private I DataFeignClient dataFeignClient ;
private DataClient FeignClientImpl dataFeignClient ;
@Autowired
private I FlowableFeignClient flowableFeignClient ;
private FlowableClient FeignClientImpl flowableFeignClient ;
@Autowired
private I SimulationFlowFeignClient flowFeignClient ;
private SimulationFlowFeignClientImpl flowFeignClient ;
private static final String TEMP_REPORT_PATH = " /opt/report/ " ;
@@ -557,14 +563,12 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
if ( flowTemplateResp . getData ( ) ! = null ) {
try {
List < FlowNodeDto > flowNodeDtoList = new ArrayList < > ( ) ;
List < Map < String , String > > result = extractFlowElements ( flowTemplateResp . getData ( ) . getTemplateContent ( ) ) ;
for ( Map < String , String > map : result ) {
ProcessDefinitionDTO definitionDTO = JSON . parseObject ( flowTemplateResp . getData ( ) . getTemplateContent ( ) , ProcessDefinitionDTO . class );
for ( FlowElementDTO flowElement : definitionDTO . getFlowElements ( ) ) {
FlowNodeDto flowNodeDto = new FlowNodeDto ( ) ;
flowNodeDto . setUuid ( generateUuid ( " flow_node_ " ) ) ;
flowNodeDto . setNodeName ( map . get ( " n ame" ) ) ;
// flowNodeReq.setFlowInstanceId(simulationRun.getFlowInstanceId()) ;
flowNodeDto . setNodeId ( map . get ( " id " ) ) ;
flowNodeDto . setTemplateId ( simulationRun . getFlowTemplate ( ) ) ;
flowNodeDto . setNodeName ( flowElement . getN ame( ) ) ;
flowNodeDto . setNodeId ( flowElement . getId ( ) ) ;
flowNodeDto . setRunId ( simulationRun . getUuid ( ) ) ;
flowNodeDtoList . add ( flowNodeDto ) ;
}
@@ -589,6 +593,8 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
log . error ( " 解析流程模板json文件失败,flowTemplateId:{} " , simulationRun . getFlowTemplate ( ) , e ) ;
throw new RuntimeException ( " 解析流程模板json文件失败: " + e . getMessage ( ) , e ) ;
}
simulationRun . setProcessDefinitionId ( flowTemplateResp . getData ( ) . getProcessDefinitionId ( ) ) ;
this . updateById ( simulationRun ) ;
}
}
return SdmResponse . success ( simulationRun . getUuid ( ) ) ;
@@ -608,29 +614,6 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
return response ;
}
/**
* 解析流程模板json结构 获取节点id和名称
* @param jsonString
* @return
* @throws Exception
*/
public static List < Map < String , String > > extractFlowElements ( String jsonString ) throws Exception {
ObjectMapper mapper = new ObjectMapper ( ) ;
JsonNode rootNode = mapper . readTree ( jsonString ) ;
JsonNode flowElements = rootNode . path ( " flowElements " ) ;
List < Map < String , String > > elements = new ArrayList < > ( ) ;
for ( JsonNode element : flowElements ) {
if ( " sequenceFlow " . equals ( element . get ( " type " ) . asText ( ) ) ) {
continue ;
}
Map < String , String > item = new HashMap < > ( ) ;
item . put ( " id " , element . path ( " id " ) . asText ( ) ) ;
item . put ( " name " , element . path ( " name " ) . asText ( ) ) ;
elements . add ( item ) ;
}
return elements ;
}
@Override
@Transactional ( rollbackFor = Exception . class )
public SdmResponse deleteTaskRun ( SpdmTaskRunReq req ) {
@@ -937,21 +920,31 @@ public class SimulationRunServiceImpl extends ServiceImpl<SimulationRunMapper, S
@Transactional ( rollbackFor = Exception . class )
public SdmResponse startProcessInstance ( SpdmTaskRunReq req ) {
SimulationRun simulationRun = this . lambdaQuery ( ) . eq ( SimulationRun : : getUuid , req . getRunId ( ) ) . one ( ) ;
// 启动流程实例
SdmResponse < ProcessInstanceResp > sdmResponse = flowableFeignClient . startByProcessDefinitionKey ( simulationRun . getFlowTemplate ( ) ) ;
// 启动流程实例 多次执行会生成多个流程实例id, 更新算例run表
SdmResponse < ProcessInstanceResp > sdmResponse = flowableFeignClient . startByProcessDefinitionId ( simulationRun . getProcessDefinitionId ( ) , null ) ;
if ( sdmResponse . getData ( ) ! = null ) {
this . lambdaUpdate ( ) . set ( SimulationRun : : getFlowInstanceId , sdmResponse . getData ( ) . getId ( ) ) . eq ( SimulationRun : : getUuid , req . getRunId ( ) ) . update ( ) ;
// 更新node节点的流程实例id
FlowNodeDto flowNodeDto = new FlowNodeDto ( ) ;
flowNodeDto . setRunId ( req . getRunId ( ) ) ;
flowNodeDto . setFlowInstanceId ( sdmResponse . getData ( ) . getId ( ) ) ;
flowFeignClient . batchUpdateSimulationFlowNode ( flowNodeDto ) ;
this . lambdaUpdate ( ) . set ( SimulationRun : : getFlowInstanceId , sdmResponse . getData ( ) . getProcessInstance Id ( ) ) . eq ( SimulationRun : : getUuid , req . getRunId ( ) ) . update ( ) ;
} else {
return SdmResponse . failed ( " 流程实例启动失败 " ) ;
}
return sdmResponse ;
}
@Override
public SdmResponse saveNodeParams ( SpdmNodeParamReq req ) {
FlowNodeDto flowNodeReq = new FlowNodeDto ( ) ;
flowNodeReq . setUuid ( req . getNodeUuid ( ) ) ;
SdmResponse < FlowNodeDto > sdmResponse = flowFeignClient . querySimulationFlowNode ( flowNodeReq ) ;
if ( sdmResponse . getData ( ) ! = null ) {
// ProcessDefinitionDTO definitionDTO = JSON.parseObject(sdmResponse.getData().get(), ProcessDefinitionDTO.class);
FlowNodeDto flowNodeDto = sdmResponse . getData ( ) ;
}
return null ;
}
public static void deleteFolder ( File folder ) {
if ( folder . isDirectory ( ) ) {
File [ ] files = folder . listFiles ( ) ;