1、优化新增项目接口
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
package com.sdm.project.service.impl;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
|
||||
@@ -68,6 +70,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.transaction.interceptor.TransactionAspectSupport;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -189,6 +192,8 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
|
||||
if (CollectionUtils.isEmpty(addNodeList)) {
|
||||
return SdmResponse.failed("addNodeList不能为空!");
|
||||
}
|
||||
StopWatch stopWatch = new StopWatch("新增节点方法计时");
|
||||
stopWatch.start("项目/阶段名称重名校验");
|
||||
for (SpdmProjectNodeEditReq addNode : addNodeList) {
|
||||
// 项目/阶段名称重名校验
|
||||
if (CollectionUtils.isNotEmpty(this.lambdaQuery().eq(SimulationNode::getNodeName, addNode.getNodeName()).list())) {
|
||||
@@ -202,13 +207,17 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
|
||||
}
|
||||
}
|
||||
}
|
||||
stopWatch.stop();
|
||||
List<TaskNodeTag> tagMap = req.getTagMap();
|
||||
// 手动回滚数据
|
||||
stopWatch.start("addNode方法");
|
||||
addNodeList = addNode(addNodeList, tagMap, tenantId, jobNumber);
|
||||
stopWatch.stop();
|
||||
if (CollectionUtils.isEmpty(addNodeList)) {
|
||||
TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
||||
return SdmResponse.failed("操作节点失败,原因:新增节点时失败!");
|
||||
}
|
||||
stopWatch.start("批量更新节点权限");
|
||||
Long userId = ThreadLocalContext.getUserId();
|
||||
// 批量更新权限
|
||||
List<BatchUpdatePermissionReq.FilePermissionItem> filePermissions = new ArrayList<>();
|
||||
@@ -259,21 +268,33 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
|
||||
BatchUpdatePermissionReq batchReq = new BatchUpdatePermissionReq();
|
||||
batchReq.setFilePermissions(filePermissions);
|
||||
log.info("创建项目阶段时,批量更新权限,任务数量:{}", filePermissions.size());
|
||||
SdmResponse response = dataFeignClient.batchUpdatePermission(batchReq);
|
||||
log.info("创建项目阶段时,批量更新权限结果:{}", response);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("批量更新权限失败:{}", response.getMessage());
|
||||
}
|
||||
CompletableFuture.runAsync(() -> {
|
||||
SdmResponse response = dataFeignClient.batchUpdatePermission(batchReq);
|
||||
log.info("创建项目阶段时,批量更新权限结果:{}", response);
|
||||
if (!response.isSuccess()) {
|
||||
log.error("批量更新权限失败:{}", response.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("同步待办");
|
||||
for (SpdmProjectNodeEditReq addNode : addNodeList) {
|
||||
String projectSource = addNode.getProjectSource();
|
||||
String nodeType = addNode.getNodeType();
|
||||
if (SYNC_PROJECT_SOURCE.equals(projectSource) && NodeTypeEnum.PROJECT.getValue().equals(nodeType)) {
|
||||
// 同步待办信息
|
||||
getTodoListByProjectNum(addNode.getNodeCode(),addNodeList, addNode.getUuid(),memberList);
|
||||
List<SpdmProjectNodeEditReq> finalAddNodeList = addNodeList;
|
||||
List<String> finalMemberList = memberList;
|
||||
CompletableFuture.runAsync(() -> {
|
||||
getTodoListByProjectNum(addNode.getNodeCode(), finalAddNodeList, addNode.getUuid(), finalMemberList);
|
||||
});
|
||||
}
|
||||
}
|
||||
stopWatch.stop();
|
||||
// 输出计时结果(两种方式:格式化打印/自定义输出)
|
||||
System.out.println("===== 格式化打印新增项目节点接口耗时(推荐日志输出) =====");
|
||||
System.out.println(stopWatch.prettyPrint()); // Spring内置格式化,含耗时百分比,直接打印日志即可
|
||||
return SdmResponse.success(addNodeList);
|
||||
}
|
||||
|
||||
@@ -903,11 +924,13 @@ public class NodeServiceImpl extends ServiceImpl<SimulationNodeMapper, Simulatio
|
||||
if (CollectionUtils.isNotEmpty(allNodeManagerList) && nodeMapper.addNodeMemberBatch(allNodeManagerList) <= 0) {
|
||||
return null;
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(allExtraList) && nodeMapper.addNodeExtraBatch(allExtraList) <= 0) {
|
||||
return null;
|
||||
if (CollectionUtils.isNotEmpty(allExtraList)) {
|
||||
CompletableFuture.runAsync(() -> nodeMapper.addNodeExtraBatch(allExtraList));
|
||||
}
|
||||
addNodeList.forEach(addNode -> addNode.setReferenceId(addNode.getPid()));
|
||||
addNodeList.forEach(addNode -> addNode.setPid(addNode.getUuid()));
|
||||
addNodeList.forEach(addNode -> {
|
||||
addNode.setReferenceId(addNode.getPid());
|
||||
addNode.setPid(addNode.getUuid());
|
||||
});
|
||||
return addNodeList;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user