fix(接口定义): 回收站恢复校验

--bug=1007481 --user=赵勇 【接口定义】-删除一个接口A-新建相同接口地址B再恢复删除接口A,恢复成功,编辑接口B和A保存后提示接口地址已存在 https://www.tapd.cn/55049933/s/1059216
This commit is contained in:
fit2-zhao 2021-10-26 16:49:50 +08:00 committed by fit2-zhao
parent b3dc331132
commit 729d5a2aa0
2 changed files with 14 additions and 9 deletions

View File

@ -14,7 +14,9 @@ import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestEnvironmentService; import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.api.service.EsbApiParamService; import io.metersphere.api.service.EsbApiParamService;
import io.metersphere.api.service.EsbImportService; import io.metersphere.api.service.EsbImportService;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.base.domain.Schedule;
import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.NoticeConstants;
import io.metersphere.commons.constants.OperLogConstants; import io.metersphere.commons.constants.OperLogConstants;
import io.metersphere.commons.constants.PermissionConstants; import io.metersphere.commons.constants.PermissionConstants;
@ -27,7 +29,6 @@ import io.metersphere.dto.RelationshipEdgeDTO;
import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.log.annotation.MsAuditLog;
import io.metersphere.notice.annotation.SendNotice; import io.metersphere.notice.annotation.SendNotice;
import io.metersphere.service.CheckPermissionService; import io.metersphere.service.CheckPermissionService;
import io.metersphere.service.ScheduleService;
import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest; import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions; import org.apache.shiro.authz.annotation.RequiresPermissions;
@ -43,8 +44,6 @@ import java.util.List;
@RestController @RestController
@RequestMapping(value = "/api/definition") @RequestMapping(value = "/api/definition")
public class ApiDefinitionController { public class ApiDefinitionController {
@Resource
private ScheduleService scheduleService;
@Resource @Resource
private ApiDefinitionService apiDefinitionService; private ApiDefinitionService apiDefinitionService;
@Resource @Resource

View File

@ -343,14 +343,22 @@ public class ApiDefinitionService {
ServiceUtils.getSelectAllIds(request, request.getCondition(), ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiDefinitionMapper.selectIds(query)); (query) -> extApiDefinitionMapper.selectIds(query));
if (request.getIds() != null || !request.getIds().isEmpty()) { if (request.getIds() != null || !request.getIds().isEmpty()) {
//检查模块是否还在
//检查原来模块是否还在 //检查原来模块是否还在
ApiDefinitionExample example = new ApiDefinitionExample(); ApiDefinitionExample example = new ApiDefinitionExample();
example.createCriteria().andIdIn(request.getIds()); example.createCriteria().andIdIn(request.getIds());
List<ApiDefinition> reductionCaseList = apiDefinitionMapper.selectByExample(example); List<ApiDefinition> reductionCaseList = apiDefinitionMapper.selectByExample(example);
Map<String, List<ApiDefinition>> nodeMap = new HashMap<>(); Map<String, List<ApiDefinition>> nodeMap = new HashMap<>();
for (ApiDefinition api : reductionCaseList) { for (ApiDefinition api : reductionCaseList) {
//检查是否同名
SaveApiDefinitionRequest apiDefinitionRequest = new SaveApiDefinitionRequest();
apiDefinitionRequest.setProjectId(request.getProjectId());
apiDefinitionRequest.setMethod(api.getMethod());
apiDefinitionRequest.setProtocol(api.getProtocol());
apiDefinitionRequest.setPath(api.getPath());
apiDefinitionRequest.setName(api.getName());
apiDefinitionRequest.setId(api.getId());
checkNameExist(apiDefinitionRequest);
String moduleId = api.getModuleId(); String moduleId = api.getModuleId();
if (StringUtils.isEmpty(moduleId)) { if (StringUtils.isEmpty(moduleId)) {
moduleId = ""; moduleId = "";
@ -363,7 +371,6 @@ public class ApiDefinitionService {
nodeMap.put(moduleId, list); nodeMap.put(moduleId, list);
} }
} }
// Map<String,List<ApiDefinition>> nodeMap = reductionCaseList.stream().collect(Collectors.groupingBy(ApiDefinition :: getModuleId));
ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class); ApiModuleService apiModuleService = CommonBeanFactory.getBean(ApiModuleService.class);
for (Map.Entry<String, List<ApiDefinition>> entry : nodeMap.entrySet()) { for (Map.Entry<String, List<ApiDefinition>> entry : nodeMap.entrySet()) {
String nodeId = entry.getKey(); String nodeId = entry.getKey();
@ -371,8 +378,7 @@ public class ApiDefinitionService {
if (nodeCount <= 0) { if (nodeCount <= 0) {
String projectId = request.getProjectId(); String projectId = request.getProjectId();
ApiModule node = apiModuleService.getDefaultNode(projectId, request.getProtocol()); ApiModule node = apiModuleService.getDefaultNode(projectId, request.getProtocol());
List<ApiDefinition> testCaseList = entry.getValue(); for (ApiDefinition apiDefinition : entry.getValue()) {
for (ApiDefinition apiDefinition : testCaseList) {
ApiDefinitionWithBLOBs updateCase = new ApiDefinitionWithBLOBs(); ApiDefinitionWithBLOBs updateCase = new ApiDefinitionWithBLOBs();
updateCase.setId(apiDefinition.getId()); updateCase.setId(apiDefinition.getId());
updateCase.setModuleId(node.getId()); updateCase.setModuleId(node.getId());