fix(接口定义): 创建其他版本接口定义,提示ID已存在

--bug=1009908 --user=lyh 【接口定义】开启了自定义用例ID,创建其他版本接口定义,提示ID已存在
https://www.tapd.cn/55049933/s/1097514
This commit is contained in:
shiziyuan9527 2022-01-24 17:06:57 +08:00 committed by zhangdahai112
parent ab97478583
commit 333c3713d2
1 changed files with 15 additions and 3 deletions

View File

@ -302,10 +302,15 @@ public class ApiAutomationService {
private void checkCustomNumExist(SaveApiScenarioRequest request) {
ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria()
.andCustomNumEqualTo(request.getCustomNum())
String id = request.getId();
ApiScenarioWithBLOBs apiScenarioWithBLOBs = apiScenarioMapper.selectByPrimaryKey(id);
ApiScenarioExample.Criteria criteria = example.createCriteria();
criteria.andCustomNumEqualTo(request.getCustomNum())
.andProjectIdEqualTo(request.getProjectId())
.andIdNotEqualTo(request.getId());
.andIdNotEqualTo(id);
if (apiScenarioWithBLOBs != null && StringUtils.isNotBlank(apiScenarioWithBLOBs.getRefId())) {
criteria.andRefIdNotEqualTo(apiScenarioWithBLOBs.getRefId());
}
List<ApiScenario> list = apiScenarioMapper.selectByExample(example);
if (CollectionUtils.isNotEmpty(list)) {
MSException.throwException("自定义ID " + request.getCustomNum() + " 已存在!");
@ -374,6 +379,13 @@ public class ApiAutomationService {
apiScenarioMapper.insertSelective(scenario);
}
if (StringUtils.isNotBlank(request.getCustomNum()) && !StringUtils.equals(request.getCustomNum(), beforeScenario.getCustomNum())) {
example.clear();
example.createCriteria().andRefIdEqualTo(beforeScenario.getRefId());
ApiScenarioWithBLOBs apiScenarioWithBLOBs = new ApiScenarioWithBLOBs();
apiScenarioWithBLOBs.setCustomNum(request.getCustomNum());
apiScenarioMapper.updateByExampleSelective(apiScenarioWithBLOBs, example);
}
apiScenarioReferenceIdService.saveByApiScenario(scenario);
extScheduleMapper.updateNameByResourceID(request.getId(), request.getName());// 修改场景name同步到修改首页定时任务