refactor(接口测试): 优化场景更新方法
【【接口测试】github#31887,在接口自动化场景的当中,跨工作空间引用场景。点击保存,F12查看接口请求特别长。】 https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001043717 Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
parent
1c6fa21898
commit
028b641e02
|
@ -40,8 +40,7 @@ public class ExtFileAssociationService extends FileAssociationService {
|
|||
public void saveScenario(String id, MsTestElement scenario) {
|
||||
this.deleteByResourceId(id);
|
||||
List<BodyFile> files = new ArrayList<>();
|
||||
if (scenario != null && scenario instanceof MsScenario) {
|
||||
MsScenario msScenario = (MsScenario) scenario;
|
||||
if (scenario instanceof MsScenario msScenario) {
|
||||
if (!CollectionUtils.isEmpty(msScenario.getVariables())) {
|
||||
msScenario.getVariables().stream().filter(ScenarioVariable::isCSVValid).forEach(keyValue -> {
|
||||
files.addAll(keyValue.getFiles().stream().filter(BodyFile::isRef).collect(Collectors.toList()));
|
||||
|
|
|
@ -386,8 +386,8 @@ public class ApiScenarioService {
|
|||
} else {
|
||||
scenario.setVersion(version + 1);
|
||||
}
|
||||
new Thread(() -> deleteUpdateBodyFile(scenario, beforeScenario)).start();
|
||||
|
||||
deleteUpdateBodyFile(scenario, beforeScenario);
|
||||
scenario.setCreateUser(null); // 更新时不更新创建人
|
||||
ApiScenarioExample example = new ApiScenarioExample();
|
||||
example.createCriteria().andIdEqualTo(scenario.getId()).andVersionIdEqualTo(request.getVersionId());
|
||||
|
@ -412,32 +412,36 @@ public class ApiScenarioService {
|
|||
apiScenarioMapper.updateByExampleSelective(apiScenarioWithBLOBs, example);
|
||||
}
|
||||
|
||||
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario);
|
||||
|
||||
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name,同步到修改首页定时任务
|
||||
uploadFiles(request, bodyFiles, scenarioFiles);
|
||||
|
||||
// 存储依赖关系
|
||||
apiAutomationRelationshipEdgeService.initRelationshipEdge(beforeScenario, scenario);
|
||||
// 异步数据放到线程中处理
|
||||
new Thread(() -> {
|
||||
uploadFiles(request, bodyFiles, scenarioFiles);
|
||||
apiScenarioReferenceIdService.saveApiAndScenarioRelation(scenario);
|
||||
// 存储依赖关系
|
||||
apiAutomationRelationshipEdgeService.initRelationshipEdge(beforeScenario, scenario);
|
||||
|
||||
apiTestCaseService.checkAndSendReviewMessage(
|
||||
scenario.getId(),
|
||||
scenario.getName(),
|
||||
scenario.getProjectId(),
|
||||
"场景用例通知",
|
||||
NoticeConstants.TaskType.API_AUTOMATION_TASK,
|
||||
beforeScenario.getScenarioDefinition(),
|
||||
scenario.getScenarioDefinition(),
|
||||
scenario.getPrincipal()
|
||||
);
|
||||
apiTestCaseService.checkAndSendReviewMessage(
|
||||
scenario.getId(),
|
||||
scenario.getName(),
|
||||
scenario.getProjectId(),
|
||||
"场景用例通知",
|
||||
NoticeConstants.TaskType.API_AUTOMATION_TASK,
|
||||
beforeScenario.getScenarioDefinition(),
|
||||
scenario.getScenarioDefinition(),
|
||||
scenario.getPrincipal()
|
||||
);
|
||||
String defaultVersion = baseProjectVersionMapper.getDefaultVersion(request.getProjectId());
|
||||
if (StringUtils.equalsIgnoreCase(request.getVersionId(), defaultVersion)) {
|
||||
checkAndSetLatestVersion(beforeScenario.getRefId());
|
||||
}
|
||||
//同步修改所有版本的模块路径
|
||||
updateOtherVersionModule(beforeScenario.getRefId(), scenario);
|
||||
// 存储附件关系
|
||||
extFileAssociationService.saveScenario(scenario.getId(), request.getScenarioDefinition());
|
||||
}).start();
|
||||
|
||||
String defaultVersion = baseProjectVersionMapper.getDefaultVersion(request.getProjectId());
|
||||
if (StringUtils.equalsIgnoreCase(request.getVersionId(), defaultVersion)) {
|
||||
checkAndSetLatestVersion(beforeScenario.getRefId());
|
||||
}
|
||||
//同步修改所有版本的模块路径
|
||||
updateOtherVersionModule(beforeScenario.getRefId(), scenario);
|
||||
// 存储附件关系
|
||||
extFileAssociationService.saveScenario(scenario.getId(), request.getScenarioDefinition());
|
||||
return scenario;
|
||||
}
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ public class FileAssociationService {
|
|||
batchMapper.insert(fileAssociation);
|
||||
});
|
||||
sqlSession.flushStatements();
|
||||
if (sqlSession != null && sqlSessionFactory != null) {
|
||||
if (sqlSessionFactory != null) {
|
||||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue