@@ -27,6 +27,8 @@ import com.sdm.common.utils.RandomUtil;
import com.sdm.project.dao.SimulationDemandMapper ;
import com.sdm.project.dao.SimulationNodeMapper ;
import com.sdm.project.dao.SimulationProjectMapper ;
import com.sdm.project.model.bo.TaskExtraNode ;
import com.sdm.project.model.bo.TaskNode ;
import com.sdm.project.model.bo.TaskNodeTag ;
import com.sdm.project.model.entity.SimulationNode ;
import com.sdm.project.model.entity.SimulationRun ;
@@ -34,6 +36,7 @@ import com.sdm.project.model.entity.SimulationTask;
import com.sdm.project.model.entity.SimulationTaskMember ;
import com.sdm.project.model.po.PerformanceNodePo ;
import com.sdm.project.model.po.ProjectNodePo ;
import com.sdm.project.model.po.TaskNodeExtraPo ;
import com.sdm.project.model.po.TaskNodePo ;
import com.sdm.project.model.req.* ;
import com.sdm.project.model.vo.* ;
@@ -43,6 +46,7 @@ import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.MapUtils ;
import org.apache.commons.lang3.ObjectUtils ;
import org.apache.commons.lang3.StringUtils ;
import org.jetbrains.annotations.Nullable ;
import org.springframework.beans.BeanUtils ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
@@ -94,6 +98,9 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
private HashMap < String , String > idMap = new HashMap < > ( ) ;
@Autowired
private SimulationProjectMapper projectMapper ;
@Transactional
@Override
@@ -1081,4 +1088,249 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
public SdmResponse uploadProjectFiles ( UploadFilesReq req ) {
return dataFeignClient . uploadFiles ( req ) ;
}
@Transactional ( rollbackFor = Exception . class )
@Override
public SdmResponse addNodeForData ( SpdmAddNodeReq req ) {
log . info ( " addNodeForData参数为: {} " , req ) ;
Map < String , String > tagMap = req . getTagMap ( ) . stream ( ) . collect ( Collectors . groupingBy (
TaskNodeTag : : getKey ,
Collectors . collectingAndThen (
Collectors . toList ( ) ,
tagList - > tagList . get ( 0 ) . getValue ( )
)
) ) ;
log . info ( " tagMap为: {} " , tagMap ) ;
List < SpdmProjectNodeEditReq > result = addNodeForData ( req . getAddNodeList ( ) , tagMap ) ;
if ( CollectionUtils . isEmpty ( result ) ) {
TransactionAspectSupport . currentTransactionStatus ( ) . setRollbackOnly ( ) ;
return SdmResponse . failed ( " 数据总览新增节点失败! " ) ;
}
return SdmResponse . success ( ) ;
}
private List < SpdmProjectNodeEditReq > addNodeForData ( List < SpdmProjectNodeEditReq > addNodeList , Map < String , String > tagMap ) {
List < SpdmNodeExtraReq > nodeExtraReqList = new ArrayList < > ( ) ;
String curDateStr = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) . format ( new Date ( ) ) ;
Long tenantId = ThreadLocalContext . getTenantId ( ) ;
Long jobNumber = ThreadLocalContext . getUserId ( ) ;
List < SpdmProjectNodeEditReq > topNodeList = addNodeList . stream ( ) . filter ( node - > StringUtils . isBlank ( node . getPid ( ) ) ) . toList ( ) ;
if ( CollectionUtils . isNotEmpty ( topNodeList ) ) {
for ( SpdmProjectNodeEditReq projectNode : topNodeList ) {
projectNode . setUuid ( RandomUtil . generateString ( 32 ) ) ;
projectNode . setOwnRootNodeUuid ( projectNode . getUuid ( ) ) ;
projectNode . setCreateTime ( curDateStr ) ;
projectNode . setCreator ( jobNumber ) ;
projectNode . setTenantId ( tenantId ) ;
try {
setTagProperty ( projectNode , tagMap . get ( projectNode . getNodeType ( ) ) , projectNode . getUuid ( ) ) ;
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
List < SpdmNodeExtraReq > extras = projectNode . getExtras ( ) ;
if ( CollectionUtils . isEmpty ( extras ) ) {
continue ;
}
for ( SpdmNodeExtraReq extra : extras ) {
extra . setNodeId ( projectNode . getUuid ( ) ) ;
extra . setCreateTime ( curDateStr ) ;
extra . setCreator ( jobNumber ) ;
}
nodeExtraReqList . addAll ( extras ) ;
}
}
List < SpdmProjectNodeEditReq > nodeList = addNodeList . stream ( ) . filter ( node - > StringUtils . isNotBlank ( node . getPid ( ) ) ) . toList ( ) ;
if ( CollectionUtils . isNotEmpty ( nodeList ) ) {
List < String > pidList = nodeList . stream ( ) . map ( SpdmProjectNodeEditReq : : getPid ) . distinct ( ) . toList ( ) ;
log . info ( " pidList为: {} " , pidList ) ;
List < SimulationNode > parentNodeList = this . lambdaQuery ( ) . in ( SimulationNode : : getUuid , pidList ) . list ( ) ;
log . info ( " parentNodeList为: {} " , parentNodeList ) ;
if ( CollectionUtils . isEmpty ( parentNodeList ) ) {
log . error ( " 根据pidList: {},未查询到节点信息 " , pidList ) ;
return null ;
}
Map < String , SimulationNode > nodeMap = parentNodeList . stream ( ) . collect ( Collectors . groupingBy (
SimulationNode : : getUuid ,
Collectors . collectingAndThen (
Collectors . toList ( ) ,
list - > list . get ( 0 )
)
) ) ;
for ( SpdmProjectNodeEditReq addNode : nodeList ) {
SimulationNode parentNode = nodeMap . get ( addNode . getPid ( ) ) ;
if ( ObjectUtils . isEmpty ( parentNode ) ) {
log . error ( " 根据pid: {},未查询到父节点信息 " , addNode . getPid ( ) ) ;
continue ;
}
String parentNodeType = parentNode . getNodeType ( ) ;
String nodeType = addNode . getNodeType ( ) ;
addNode . setUuid ( RandomUtil . generateString ( 32 ) ) ;
addNode . setOwnRootNodeUuid ( ObjectUtils . isEmpty ( addNode . getPid ( ) ) ? addNode . getUuid ( ) : addNode . getPid ( ) ) ;
addNode . setCreateTime ( curDateStr ) ;
addNode . setCreator ( jobNumber ) ;
addNode . setTenantId ( tenantId ) ;
// 复制标签信息
copyTagInfoFromParentNode ( addNode , tagMap . get ( nodeType ) , parentNode , tagMap . get ( parentNodeType ) ) ;
List < SpdmNodeExtraReq > extras = addNode . getExtras ( ) ;
if ( CollectionUtils . isEmpty ( extras ) ) {
continue ;
}
for ( SpdmNodeExtraReq extra : extras ) {
extra . setNodeId ( addNode . getUuid ( ) ) ;
extra . setCreateTime ( curDateStr ) ;
extra . setCreator ( jobNumber ) ;
}
nodeExtraReqList . addAll ( extras ) ;
}
}
if ( CollectionUtils . isNotEmpty ( topNodeList ) & & nodeMapper . addNodeBatch ( topNodeList ) < = 0 ) {
log . error ( " 保存节点信息失败1 " ) ;
return null ;
}
if ( CollectionUtils . isNotEmpty ( nodeList ) & & nodeMapper . addNodeBatch ( nodeList ) < = 0 ) {
log . error ( " 保存节点信息失败2 " ) ;
return null ;
}
if ( CollectionUtils . isNotEmpty ( nodeExtraReqList ) & & nodeMapper . addNodeExtraBatch ( nodeExtraReqList ) < = 0 ) {
log . error ( " 保存节点额外信息失败 " ) ;
return null ;
}
for ( SpdmProjectNodeEditReq projectNode : topNodeList ) {
createDir ( projectNode . getUuid ( ) , projectNode . getNodeType ( ) , null , projectNode . getNodeName ( ) ) ;
}
for ( SpdmProjectNodeEditReq projectNode : nodeList ) {
createDir ( projectNode . getUuid ( ) , projectNode . getNodeType ( ) , projectNode . getPid ( ) , projectNode . getNodeName ( ) ) ;
}
return addNodeList ;
}
/**
*
* @param addNode 当前新增节点
* @param addNodeTag 当前新增节点的标签
* @param parentNode 当前新增节点的父节点
* @param parentNodeTag 当前新增节点的父节点的标签
*/
private void copyTagInfoFromParentNode ( SpdmProjectNodeEditReq addNode , String addNodeTag , SimulationNode parentNode , String parentNodeTag ) {
List < String > tagListProperty ;
for ( int i = 1 ; i < = 10 ; i + + ) {
try {
tagListProperty = getTagListProperty ( parentNode , " tag " + i ) ;
if ( CollectionUtils . isEmpty ( tagListProperty ) ) {
continue ;
}
setTagProperty ( addNode , " tag " + i , tagListProperty ) ;
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
}
if ( addNodeTag . equals ( parentNodeTag ) ) {
// 如果新增节点与父节点的类型相同, 需要将当前新增节点的uuid追加到该类型标签中
try {
tagListProperty = getTagListProperty ( parentNode , parentNodeTag ) ;
tagListProperty . add ( addNode . getUuid ( ) ) ;
setTagProperty ( addNode , addNodeTag , tagListProperty ) ;
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
} else {
// 如果新增节点与父节点的类型不同, 直接设置该标签为当前新增节点的uuid即可
try {
setTagProperty ( addNode , addNodeTag , addNode . getUuid ( ) ) ;
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
}
}
@Override
public SdmResponse addTaskForData ( SpdmTaskReq req ) {
log . info ( " addTaskForData参数为: {} " , req ) ;
List < TaskNode > result = handleAddTaskForData ( req . getAddTaskList ( ) ) ;
if ( CollectionUtils . isEmpty ( result ) ) {
TransactionAspectSupport . currentTransactionStatus ( ) . setRollbackOnly ( ) ;
return SdmResponse . failed ( " 数据总览新增任务失败! " ) ;
}
return SdmResponse . success ( ) ;
}
private List < TaskNode > handleAddTaskForData ( List < TaskNode > addTaskList ) {
List < TaskExtraNode > nodeExtraReqList = new ArrayList < > ( ) ;
String curDateStr = new SimpleDateFormat ( " yyyy-MM-dd HH:mm:ss " ) . format ( new Date ( ) ) ;
Long tenantId = ThreadLocalContext . getTenantId ( ) ;
Long jobNumber = ThreadLocalContext . getUserId ( ) ;
List < String > pidList = addTaskList . stream ( ) . map ( TaskNode : : getPid ) . distinct ( ) . toList ( ) ;
log . info ( " pidList为: {} " , pidList ) ;
List < SimulationNode > parentNodeList = this . lambdaQuery ( ) . in ( SimulationNode : : getUuid , pidList ) . list ( ) ;
log . info ( " parentNodeList为: {} " , parentNodeList ) ;
if ( CollectionUtils . isEmpty ( parentNodeList ) ) {
log . error ( " 根据pidList: {},未查询到节点信息 " , pidList ) ;
return null ;
}
Map < String , SimulationNode > nodeMap = parentNodeList . stream ( ) . collect ( Collectors . groupingBy (
SimulationNode : : getUuid ,
Collectors . collectingAndThen (
Collectors . toList ( ) ,
list - > list . get ( 0 )
)
) ) ;
for ( TaskNode addTask : addTaskList ) {
SimulationNode parentNode = nodeMap . get ( addTask . getPid ( ) ) ;
if ( ObjectUtils . isEmpty ( parentNode ) ) {
log . error ( " 根据pid: {},未查询到父节点信息 " , addTask . getPid ( ) ) ;
continue ;
}
addTask . setUuid ( RandomUtil . generateString ( 32 ) ) ;
addTask . setOwnRootNodeUuid ( ObjectUtils . isEmpty ( addTask . getPid ( ) ) ? addTask . getUuid ( ) : addTask . getPid ( ) ) ;
addTask . setCreateTime ( curDateStr ) ;
addTask . setCreator ( jobNumber ) ;
addTask . setTenantId ( tenantId ) ;
// 复制标签信息
copyTaskTagInfoFromParentNode ( addTask , parentNode ) ;
List < TaskExtraNode > extras = addTask . getExtras ( ) ;
if ( CollectionUtils . isEmpty ( extras ) ) {
continue ;
}
for ( TaskExtraNode extra : extras ) {
extra . setNodeId ( addTask . getUuid ( ) ) ;
extra . setCreateTime ( curDateStr ) ;
extra . setCreator ( jobNumber ) ;
}
nodeExtraReqList . addAll ( extras ) ;
}
if ( projectMapper . batchAddSimulationTask ( addTaskList ) < = 0 ) {
log . error ( " 保存任务失败 " ) ;
return null ;
}
if ( CollectionUtils . isNotEmpty ( nodeExtraReqList ) & & projectMapper . batchAddSimulationTaskExtra ( nodeExtraReqList ) < = 0 ) {
log . error ( " 保存任务额外信息失败 " ) ;
return null ;
}
for ( TaskNode taskNode : addTaskList ) {
createDir ( taskNode . getUuid ( ) , taskNode . getNodeType ( ) , taskNode . getPid ( ) , taskNode . getNodeName ( ) ) ;
}
return addTaskList ;
}
/**
*
* @param addNode 当前新增节点
* @param parentNode 当前新增节点的父节点
*/
private void copyTaskTagInfoFromParentNode ( TaskNode addNode , SimulationNode parentNode ) {
List < String > tagListProperty ;
for ( int i = 1 ; i < = 10 ; i + + ) {
try {
tagListProperty = getTagListProperty ( parentNode , " tag " + i ) ;
if ( CollectionUtils . isEmpty ( tagListProperty ) ) {
continue ;
}
setTagProperty ( addNode , " tag " + i , tagListProperty ) ;
} catch ( Exception e ) {
throw new RuntimeException ( e ) ;
}
}
}
}