fix(接口导入): 修复接口导入选择覆盖时未覆盖mock期望的bug
修复接口导入选择覆盖时未覆盖mock期望的bug
This commit is contained in:
parent
4c5d863f60
commit
b86afe18d1
|
@ -719,6 +719,9 @@ public class ApiDefinitionService {
|
||||||
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||||
apiDefinition.setRequest(requestStr);
|
apiDefinition.setRequest(requestStr);
|
||||||
importApiCase(apiDefinition, apiTestImportRequest);
|
importApiCase(apiDefinition, apiTestImportRequest);
|
||||||
|
}else {
|
||||||
|
//不覆盖的接口,如果没有sameRequest则不导入。此时清空mock信息
|
||||||
|
mocks.clear();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, apiTestImportRequest, cases, mocks);
|
_importCreate(sameRequest, batchMapper, apiDefinition, apiTestCaseMapper, apiTestImportRequest, cases, mocks);
|
||||||
|
@ -811,6 +814,7 @@ public class ApiDefinitionService {
|
||||||
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
||||||
apiDefinition.setRequest(request);
|
apiDefinition.setRequest(request);
|
||||||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||||
|
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||||
importApiCase(apiDefinition, apiTestImportRequest);
|
importApiCase(apiDefinition, apiTestImportRequest);
|
||||||
} else {
|
} else {
|
||||||
apiDefinition.setId(existApi.getId());
|
apiDefinition.setId(existApi.getId());
|
||||||
|
@ -819,6 +823,7 @@ public class ApiDefinitionService {
|
||||||
}
|
}
|
||||||
apiDefinition.setOrder(existApi.getOrder());
|
apiDefinition.setOrder(existApi.getOrder());
|
||||||
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
reSetImportCasesApiId(cases, originId, apiDefinition.getId());
|
||||||
|
reSetImportMocksApiId(mocks, originId, apiDefinition.getId(), apiDefinition.getNum());
|
||||||
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
apiDefinitionMapper.updateByPrimaryKeyWithBLOBs(apiDefinition);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1381,7 +1381,7 @@ public class MockConfigService {
|
||||||
if (CollectionUtils.isNotEmpty(apiImport.getMocks())) {
|
if (CollectionUtils.isNotEmpty(apiImport.getMocks())) {
|
||||||
Map<String, List<MockExpectConfigWithBLOBs>> saveMap = new HashMap<>();
|
Map<String, List<MockExpectConfigWithBLOBs>> saveMap = new HashMap<>();
|
||||||
for (MockConfigImportDTO dto : apiImport.getMocks()) {
|
for (MockConfigImportDTO dto : apiImport.getMocks()) {
|
||||||
String apiId = dto.getApiId();//de33108c-26e2-4d4f-826a-a5f8e017d2f4
|
String apiId = dto.getApiId();
|
||||||
if (saveMap.containsKey(apiId)) {
|
if (saveMap.containsKey(apiId)) {
|
||||||
saveMap.get(apiId).add(dto);
|
saveMap.get(apiId).add(dto);
|
||||||
} else {
|
} else {
|
||||||
|
@ -1393,13 +1393,58 @@ public class MockConfigService {
|
||||||
|
|
||||||
for (Map.Entry<String, List<MockExpectConfigWithBLOBs>> entry : saveMap.entrySet()) {
|
for (Map.Entry<String, List<MockExpectConfigWithBLOBs>> entry : saveMap.entrySet()) {
|
||||||
String apiId = entry.getKey();
|
String apiId = entry.getKey();
|
||||||
this.deleteMockConfigByApiId(apiId);
|
|
||||||
|
|
||||||
List<MockExpectConfigWithBLOBs> list = entry.getValue();
|
List<MockExpectConfigWithBLOBs> list = entry.getValue();
|
||||||
|
|
||||||
|
MockConfig mockConfig = this.selectMockConfigByApiId(apiId);
|
||||||
|
if (mockConfig == null) {
|
||||||
|
this.insertMockExpectConfigs(apiId, request.getProjectId(), list, sqlSession);
|
||||||
|
} else {
|
||||||
|
this.updateMockExpectConfigs(mockConfig, list ,sqlSession);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateMockExpectConfigs(MockConfig mockConfig, List<MockExpectConfigWithBLOBs> list, SqlSession sqlSession) {
|
||||||
|
int batchCount = 0;
|
||||||
|
for (MockExpectConfigWithBLOBs mockExpect : list) {
|
||||||
|
MockExpectConfig expectInDb = this.findMockExpectConfigByMockConfigIdAndExpectNum(mockConfig.getId(),mockExpect.getExpectNum());
|
||||||
|
if(expectInDb == null){
|
||||||
|
mockExpect.setId(UUID.randomUUID().toString());
|
||||||
|
mockExpect.setMockConfigId(mockConfig.getId());
|
||||||
|
mockExpect.setCreateTime(System.currentTimeMillis());
|
||||||
|
mockExpect.setUpdateTime(System.currentTimeMillis());
|
||||||
|
mockExpect.setCreateUserId(SessionUtils.getUserId());
|
||||||
|
mockExpectConfigMapper.insert(mockExpect);
|
||||||
|
}else {
|
||||||
|
mockExpect.setMockConfigId(mockConfig.getId());
|
||||||
|
mockExpect.setId(expectInDb.getId());
|
||||||
|
mockExpect.setUpdateTime(System.currentTimeMillis());
|
||||||
|
mockExpectConfigMapper.updateByPrimaryKey(mockExpect);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (batchCount % 300 == 0) {
|
||||||
|
sqlSession.flushStatements();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private MockExpectConfig findMockExpectConfigByMockConfigIdAndExpectNum(String mockConfigId, String expectNum) {
|
||||||
|
MockExpectConfigExample example = new MockExpectConfigExample();
|
||||||
|
example.createCriteria().andMockConfigIdEqualTo(mockConfigId).andExpectNumEqualTo(expectNum);
|
||||||
|
List<MockExpectConfig> bloBs = this.mockExpectConfigMapper.selectByExample(example);
|
||||||
|
if(CollectionUtils.isNotEmpty(bloBs)){
|
||||||
|
return bloBs.get(0);
|
||||||
|
}else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void insertMockExpectConfigs(String apiId, String projectId, List<MockExpectConfigWithBLOBs> list, SqlSession sqlSession) {
|
||||||
String mockId = UUID.randomUUID().toString();
|
String mockId = UUID.randomUUID().toString();
|
||||||
MockConfig config = new MockConfig();
|
MockConfig config = new MockConfig();
|
||||||
config.setProjectId(request.getProjectId());
|
config.setProjectId(projectId);
|
||||||
config.setId(mockId);
|
config.setId(mockId);
|
||||||
config.setCreateUserId(SessionUtils.getUserId());
|
config.setCreateUserId(SessionUtils.getUserId());
|
||||||
config.setCreateTime(System.currentTimeMillis());
|
config.setCreateTime(System.currentTimeMillis());
|
||||||
|
@ -1421,6 +1466,15 @@ public class MockConfigService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private MockConfig selectMockConfigByApiId(String apiId) {
|
||||||
|
MockConfigExample example = new MockConfigExample();
|
||||||
|
example.createCriteria().andApiIdEqualTo(apiId);
|
||||||
|
List<MockConfig> mockConfigList = this.mockConfigMapper.selectByExample(example);
|
||||||
|
if (CollectionUtils.isNotEmpty(mockConfigList)) {
|
||||||
|
return mockConfigList.get(0);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue