diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index 96357a4440..d8c0ff940d 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -109,6 +109,7 @@ public class ApiAutomationService { scenario.setScenarioDefinition(JSON.toJSONString(request.getScenarioDefinition())); scenario.setCreateTime(System.currentTimeMillis()); scenario.setUpdateTime(System.currentTimeMillis()); + scenario.setNum(getNextNum(request.getProjectId())); if (StringUtils.isNotEmpty(request.getStatus())) { scenario.setStatus(request.getStatus()); } else { @@ -127,6 +128,15 @@ public class ApiAutomationService { return scenario; } + private int getNextNum(String projectId) { + ApiScenario apiScenario = extApiScenarioMapper.getNextNum(projectId); + if (apiScenario == null) { + return 100001; + } else { + return Optional.of(apiScenario.getNum() + 1).orElse(100001); + } + } + public void update(SaveApiScenarioRequest request, List bodyFiles) { checkNameExist(request); List bodyUploadIds = request.getBodyUploadIds(); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java index ebb28f970e..da1c4eed4a 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -238,6 +238,7 @@ public class ApiDefinitionService { test.setModulePath(request.getModulePath()); test.setResponse(JSONObject.toJSONString(request.getResponse())); test.setEnvironmentId(request.getEnvironmentId()); + test.setNum(getNextNum(request.getProjectId())); if (request.getUserId() == null) { test.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId()); } else { @@ -248,6 +249,15 @@ public class ApiDefinitionService { return test; } + private int getNextNum(String projectId) { + ApiDefinition apiDefinition = extApiDefinitionMapper.getNextNum(projectId); + if (apiDefinition == null) { + return 100001; + } else { + return Optional.of(apiDefinition.getNum() + 1).orElse(100001); + } + } + private ApiDefinition createTest(ApiDefinitionResult request, ApiDefinitionMapper batchMapper) { SaveApiDefinitionRequest saveReq = new SaveApiDefinitionRequest(); BeanUtils.copyBean(saveReq, request); @@ -372,11 +382,16 @@ public class ApiDefinitionService { SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); ApiDefinitionMapper batchMapper = sqlSession.getMapper(ApiDefinitionMapper.class); List data = apiImport.getData(); + int num = 0; + if (!CollectionUtils.isEmpty(data) && data.get(0) != null && data.get(0).getProjectId() != null) { + num = getNextNum(data.get(0).getProjectId()); + } for (int i = 0; i < data.size(); i++) { ApiDefinitionResult item = data.get(i); if (item.getName().length() > 255) { item.setName(item.getName().substring(0, 255)); } + item.setNum(num++); createTest(item, batchMapper); if (i % 300 == 0) { sqlSession.flushStatements(); diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java index a6b8623523..81f160bc51 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestCaseService.java @@ -8,6 +8,7 @@ import io.metersphere.api.dto.definition.SaveApiTestCaseRequest; import io.metersphere.api.dto.ApiCaseBatchRequest; import io.metersphere.api.dto.definition.ApiTestCaseDTO; import io.metersphere.base.domain.*; +import io.metersphere.base.mapper.ApiDefinitionMapper; import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ApiTestFileMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; @@ -54,6 +55,8 @@ public class ApiTestCaseService { private FileService fileService; @Resource private ExtApiDefinitionExecResultMapper extApiDefinitionExecResultMapper; + @Resource + private ApiDefinitionMapper apiDefinitionMapper; private static final String BODY_FILE_DIR = "/opt/metersphere/data/body"; @@ -218,10 +221,22 @@ public class ApiTestCaseService { test.setPriority(request.getPriority()); test.setUpdateTime(System.currentTimeMillis()); test.setDescription(request.getDescription()); + test.setNum(getNextNum(request.getApiDefinitionId())); apiTestCaseMapper.insert(test); return test; } + private int getNextNum(String definitionId) { + ApiTestCase apiTestCase = extApiTestCaseMapper.getNextNum(definitionId); + if (apiTestCase == null) { + int n = apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum(); + return n * 1000 + 1; + } else { + return Optional.of(apiTestCase.getNum() + 1) + .orElse(apiDefinitionMapper.selectByPrimaryKey(definitionId).getNum() * 1000 + 1); + } + } + private void saveFile(String testId, MultipartFile file) { final FileMetadata fileMetadata = fileService.saveFile(file); ApiTestFile apiTestFile = new ApiTestFile(); diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java b/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java index 64a40d007e..002fe04a51 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDefinition.java @@ -33,5 +33,7 @@ public class ApiDefinition implements Serializable { private String path; + private Integer num; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java index 09c23da720..5f9f761aa1 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiDefinitionExample.java @@ -1063,6 +1063,66 @@ public class ApiDefinitionExample { addCriterion("`path` not between", value1, value2, "path"); return (Criteria) this; } + + public Criteria andNumIsNull() { + addCriterion("num is null"); + return (Criteria) this; + } + + public Criteria andNumIsNotNull() { + addCriterion("num is not null"); + return (Criteria) this; + } + + public Criteria andNumEqualTo(Integer value) { + addCriterion("num =", value, "num"); + return (Criteria) this; + } + + public Criteria andNumNotEqualTo(Integer value) { + addCriterion("num <>", value, "num"); + return (Criteria) this; + } + + public Criteria andNumGreaterThan(Integer value) { + addCriterion("num >", value, "num"); + return (Criteria) this; + } + + public Criteria andNumGreaterThanOrEqualTo(Integer value) { + addCriterion("num >=", value, "num"); + return (Criteria) this; + } + + public Criteria andNumLessThan(Integer value) { + addCriterion("num <", value, "num"); + return (Criteria) this; + } + + public Criteria andNumLessThanOrEqualTo(Integer value) { + addCriterion("num <=", value, "num"); + return (Criteria) this; + } + + public Criteria andNumIn(List values) { + addCriterion("num in", values, "num"); + return (Criteria) this; + } + + public Criteria andNumNotIn(List values) { + addCriterion("num not in", values, "num"); + return (Criteria) this; + } + + public Criteria andNumBetween(Integer value1, Integer value2) { + addCriterion("num between", value1, value2, "num"); + return (Criteria) this; + } + + public Criteria andNumNotBetween(Integer value1, Integer value2) { + addCriterion("num not between", value1, value2, "num"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java index 56d3050e07..81c0a35a33 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java @@ -41,5 +41,7 @@ public class ApiScenario implements Serializable { private String reportId; + private Integer num; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java index c668f1a2fe..c679af53c1 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java @@ -1333,6 +1333,66 @@ public class ApiScenarioExample { addCriterion("report_id not between", value1, value2, "reportId"); return (Criteria) this; } + + public Criteria andNumIsNull() { + addCriterion("num is null"); + return (Criteria) this; + } + + public Criteria andNumIsNotNull() { + addCriterion("num is not null"); + return (Criteria) this; + } + + public Criteria andNumEqualTo(Integer value) { + addCriterion("num =", value, "num"); + return (Criteria) this; + } + + public Criteria andNumNotEqualTo(Integer value) { + addCriterion("num <>", value, "num"); + return (Criteria) this; + } + + public Criteria andNumGreaterThan(Integer value) { + addCriterion("num >", value, "num"); + return (Criteria) this; + } + + public Criteria andNumGreaterThanOrEqualTo(Integer value) { + addCriterion("num >=", value, "num"); + return (Criteria) this; + } + + public Criteria andNumLessThan(Integer value) { + addCriterion("num <", value, "num"); + return (Criteria) this; + } + + public Criteria andNumLessThanOrEqualTo(Integer value) { + addCriterion("num <=", value, "num"); + return (Criteria) this; + } + + public Criteria andNumIn(List values) { + addCriterion("num in", values, "num"); + return (Criteria) this; + } + + public Criteria andNumNotIn(List values) { + addCriterion("num not in", values, "num"); + return (Criteria) this; + } + + public Criteria andNumBetween(Integer value1, Integer value2) { + addCriterion("num between", value1, value2, "num"); + return (Criteria) this; + } + + public Criteria andNumNotBetween(Integer value1, Integer value2) { + addCriterion("num not between", value1, value2, "num"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiTestCase.java b/backend/src/main/java/io/metersphere/base/domain/ApiTestCase.java index 67c9715a57..a09ede7bf5 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiTestCase.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiTestCase.java @@ -23,5 +23,7 @@ public class ApiTestCase implements Serializable { private Long updateTime; + private Integer num; + private static final long serialVersionUID = 1L; } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiTestCaseExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiTestCaseExample.java index c8aebfb60c..0f71b8a56e 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiTestCaseExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiTestCaseExample.java @@ -713,6 +713,66 @@ public class ApiTestCaseExample { addCriterion("update_time not between", value1, value2, "updateTime"); return (Criteria) this; } + + public Criteria andNumIsNull() { + addCriterion("num is null"); + return (Criteria) this; + } + + public Criteria andNumIsNotNull() { + addCriterion("num is not null"); + return (Criteria) this; + } + + public Criteria andNumEqualTo(Integer value) { + addCriterion("num =", value, "num"); + return (Criteria) this; + } + + public Criteria andNumNotEqualTo(Integer value) { + addCriterion("num <>", value, "num"); + return (Criteria) this; + } + + public Criteria andNumGreaterThan(Integer value) { + addCriterion("num >", value, "num"); + return (Criteria) this; + } + + public Criteria andNumGreaterThanOrEqualTo(Integer value) { + addCriterion("num >=", value, "num"); + return (Criteria) this; + } + + public Criteria andNumLessThan(Integer value) { + addCriterion("num <", value, "num"); + return (Criteria) this; + } + + public Criteria andNumLessThanOrEqualTo(Integer value) { + addCriterion("num <=", value, "num"); + return (Criteria) this; + } + + public Criteria andNumIn(List values) { + addCriterion("num in", values, "num"); + return (Criteria) this; + } + + public Criteria andNumNotIn(List values) { + addCriterion("num not in", values, "num"); + return (Criteria) this; + } + + public Criteria andNumBetween(Integer value1, Integer value2) { + addCriterion("num between", value1, value2, "num"); + return (Criteria) this; + } + + public Criteria andNumNotBetween(Integer value1, Integer value2) { + addCriterion("num not between", value1, value2, "num"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml index b9581ed987..c2b69a3b8f 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiDefinitionMapper.xml @@ -16,6 +16,7 @@ + @@ -82,7 +83,7 @@ id, project_id, `name`, `method`, module_path, environment_id, schedule, `status`, - module_id, user_id, create_time, update_time, protocol, `path` + module_id, user_id, create_time, update_time, protocol, `path`, num description, request, response @@ -140,14 +141,16 @@ `method`, module_path, environment_id, schedule, `status`, module_id, user_id, create_time, update_time, - protocol, `path`, description, - request, response) + protocol, `path`, num, + description, request, response + ) values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{method,jdbcType=VARCHAR}, #{modulePath,jdbcType=VARCHAR}, #{environmentId,jdbcType=VARCHAR}, #{schedule,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{moduleId,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, - #{protocol,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}, #{description,jdbcType=LONGVARCHAR}, - #{request,jdbcType=LONGVARCHAR}, #{response,jdbcType=LONGVARCHAR}) + #{protocol,jdbcType=VARCHAR}, #{path,jdbcType=VARCHAR}, #{num,jdbcType=INTEGER}, + #{description,jdbcType=LONGVARCHAR}, #{request,jdbcType=LONGVARCHAR}, #{response,jdbcType=LONGVARCHAR} + ) insert into api_definition @@ -194,6 +197,9 @@ `path`, + + num, + description, @@ -247,6 +253,9 @@ #{path,jdbcType=VARCHAR}, + + #{num,jdbcType=INTEGER}, + #{description,jdbcType=LONGVARCHAR}, @@ -309,6 +318,9 @@ `path` = #{record.path,jdbcType=VARCHAR}, + + num = #{record.num,jdbcType=INTEGER}, + description = #{record.description,jdbcType=LONGVARCHAR}, @@ -339,6 +351,7 @@ update_time = #{record.updateTime,jdbcType=BIGINT}, protocol = #{record.protocol,jdbcType=VARCHAR}, `path` = #{record.path,jdbcType=VARCHAR}, + num = #{record.num,jdbcType=INTEGER}, description = #{record.description,jdbcType=LONGVARCHAR}, request = #{record.request,jdbcType=LONGVARCHAR}, response = #{record.response,jdbcType=LONGVARCHAR} @@ -361,7 +374,8 @@ create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, protocol = #{record.protocol,jdbcType=VARCHAR}, - `path` = #{record.path,jdbcType=VARCHAR} + `path` = #{record.path,jdbcType=VARCHAR}, + num = #{record.num,jdbcType=INTEGER} @@ -408,6 +422,9 @@ `path` = #{path,jdbcType=VARCHAR}, + + num = #{num,jdbcType=INTEGER}, + description = #{description,jdbcType=LONGVARCHAR}, @@ -435,6 +452,7 @@ update_time = #{updateTime,jdbcType=BIGINT}, protocol = #{protocol,jdbcType=VARCHAR}, `path` = #{path,jdbcType=VARCHAR}, + num = #{num,jdbcType=INTEGER}, description = #{description,jdbcType=LONGVARCHAR}, request = #{request,jdbcType=LONGVARCHAR}, response = #{response,jdbcType=LONGVARCHAR} @@ -454,7 +472,8 @@ create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, protocol = #{protocol,jdbcType=VARCHAR}, - `path` = #{path,jdbcType=VARCHAR} + `path` = #{path,jdbcType=VARCHAR}, + num = #{num,jdbcType=INTEGER} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml index 5e4082cd5e..dba0bfbdb4 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml @@ -20,6 +20,7 @@ + @@ -86,7 +87,7 @@ id, project_id, tags, user_id, api_scenario_module_id, module_path, `name`, `level`, `status`, principal, step_total, follow_people, schedule, create_time, update_time, - pass_rate, last_result, report_id + pass_rate, last_result, report_id, num scenario_definition, description @@ -146,7 +147,7 @@ principal, step_total, follow_people, schedule, create_time, update_time, pass_rate, last_result, report_id, - scenario_definition, description + num, scenario_definition, description ) values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{apiScenarioModuleId,jdbcType=VARCHAR}, #{modulePath,jdbcType=VARCHAR}, @@ -154,7 +155,7 @@ #{principal,jdbcType=VARCHAR}, #{stepTotal,jdbcType=INTEGER}, #{followPeople,jdbcType=VARCHAR}, #{schedule,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, #{passRate,jdbcType=VARCHAR}, #{lastResult,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, - #{scenarioDefinition,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR} + #{num,jdbcType=INTEGER}, #{scenarioDefinition,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR} ) @@ -214,6 +215,9 @@ report_id, + + num, + scenario_definition, @@ -276,6 +280,9 @@ #{reportId,jdbcType=VARCHAR}, + + #{num,jdbcType=INTEGER}, + #{scenarioDefinition,jdbcType=LONGVARCHAR}, @@ -347,6 +354,9 @@ report_id = #{record.reportId,jdbcType=VARCHAR}, + + num = #{record.num,jdbcType=INTEGER}, + scenario_definition = #{record.scenarioDefinition,jdbcType=LONGVARCHAR}, @@ -378,6 +388,7 @@ pass_rate = #{record.passRate,jdbcType=VARCHAR}, last_result = #{record.lastResult,jdbcType=VARCHAR}, report_id = #{record.reportId,jdbcType=VARCHAR}, + num = #{record.num,jdbcType=INTEGER}, scenario_definition = #{record.scenarioDefinition,jdbcType=LONGVARCHAR}, description = #{record.description,jdbcType=LONGVARCHAR} @@ -403,7 +414,8 @@ update_time = #{record.updateTime,jdbcType=BIGINT}, pass_rate = #{record.passRate,jdbcType=VARCHAR}, last_result = #{record.lastResult,jdbcType=VARCHAR}, - report_id = #{record.reportId,jdbcType=VARCHAR} + report_id = #{record.reportId,jdbcType=VARCHAR}, + num = #{record.num,jdbcType=INTEGER} @@ -462,6 +474,9 @@ report_id = #{reportId,jdbcType=VARCHAR}, + + num = #{num,jdbcType=INTEGER}, + scenario_definition = #{scenarioDefinition,jdbcType=LONGVARCHAR}, @@ -490,6 +505,7 @@ pass_rate = #{passRate,jdbcType=VARCHAR}, last_result = #{lastResult,jdbcType=VARCHAR}, report_id = #{reportId,jdbcType=VARCHAR}, + num = #{num,jdbcType=INTEGER}, scenario_definition = #{scenarioDefinition,jdbcType=LONGVARCHAR}, description = #{description,jdbcType=LONGVARCHAR} where id = #{id,jdbcType=VARCHAR} @@ -512,7 +528,8 @@ update_time = #{updateTime,jdbcType=BIGINT}, pass_rate = #{passRate,jdbcType=VARCHAR}, last_result = #{lastResult,jdbcType=VARCHAR}, - report_id = #{reportId,jdbcType=VARCHAR} + report_id = #{reportId,jdbcType=VARCHAR}, + num = #{num,jdbcType=INTEGER} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiTestCaseMapper.xml index 5503bfda01..011d42f3fb 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiTestCaseMapper.xml @@ -11,6 +11,7 @@ + @@ -77,7 +78,7 @@ id, project_id, `name`, priority, api_definition_id, create_user_id, update_user_id, - create_time, update_time + create_time, update_time, num description, request, response @@ -134,13 +135,13 @@ insert into api_test_case (id, project_id, `name`, priority, api_definition_id, create_user_id, update_user_id, create_time, update_time, - description, request, response - ) + num, description, request, + response) values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{priority,jdbcType=VARCHAR}, #{apiDefinitionId,jdbcType=VARCHAR}, #{createUserId,jdbcType=VARCHAR}, #{updateUserId,jdbcType=VARCHAR}, #{createTime,jdbcType=BIGINT}, #{updateTime,jdbcType=BIGINT}, - #{description,jdbcType=LONGVARCHAR}, #{request,jdbcType=LONGVARCHAR}, #{response,jdbcType=LONGVARCHAR} - ) + #{num,jdbcType=INTEGER}, #{description,jdbcType=LONGVARCHAR}, #{request,jdbcType=LONGVARCHAR}, + #{response,jdbcType=LONGVARCHAR}) insert into api_test_case @@ -172,6 +173,9 @@ update_time, + + num, + description, @@ -210,6 +214,9 @@ #{updateTime,jdbcType=BIGINT}, + + #{num,jdbcType=INTEGER}, + #{description,jdbcType=LONGVARCHAR}, @@ -257,6 +264,9 @@ update_time = #{record.updateTime,jdbcType=BIGINT}, + + num = #{record.num,jdbcType=INTEGER}, + description = #{record.description,jdbcType=LONGVARCHAR}, @@ -282,6 +292,7 @@ update_user_id = #{record.updateUserId,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, update_time = #{record.updateTime,jdbcType=BIGINT}, + num = #{record.num,jdbcType=INTEGER}, description = #{record.description,jdbcType=LONGVARCHAR}, request = #{record.request,jdbcType=LONGVARCHAR}, response = #{record.response,jdbcType=LONGVARCHAR} @@ -299,7 +310,8 @@ create_user_id = #{record.createUserId,jdbcType=VARCHAR}, update_user_id = #{record.updateUserId,jdbcType=VARCHAR}, create_time = #{record.createTime,jdbcType=BIGINT}, - update_time = #{record.updateTime,jdbcType=BIGINT} + update_time = #{record.updateTime,jdbcType=BIGINT}, + num = #{record.num,jdbcType=INTEGER} @@ -331,6 +343,9 @@ update_time = #{updateTime,jdbcType=BIGINT}, + + num = #{num,jdbcType=INTEGER}, + description = #{description,jdbcType=LONGVARCHAR}, @@ -353,6 +368,7 @@ update_user_id = #{updateUserId,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, update_time = #{updateTime,jdbcType=BIGINT}, + num = #{num,jdbcType=INTEGER}, description = #{description,jdbcType=LONGVARCHAR}, request = #{request,jdbcType=LONGVARCHAR}, response = #{response,jdbcType=LONGVARCHAR} @@ -367,7 +383,8 @@ create_user_id = #{createUserId,jdbcType=VARCHAR}, update_user_id = #{updateUserId,jdbcType=VARCHAR}, create_time = #{createTime,jdbcType=BIGINT}, - update_time = #{updateTime,jdbcType=BIGINT} + update_time = #{updateTime,jdbcType=BIGINT}, + num = #{num,jdbcType=INTEGER} where id = #{id,jdbcType=VARCHAR} \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java index 2e4c12554b..30702b8122 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.java @@ -4,6 +4,7 @@ import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.definition.ApiComputeResult; import io.metersphere.api.dto.definition.ApiDefinitionRequest; import io.metersphere.api.dto.definition.ApiDefinitionResult; +import io.metersphere.base.domain.ApiDefinition; import org.apache.ibatis.annotations.Param; import java.util.List; @@ -25,4 +26,6 @@ public interface ExtApiDefinitionMapper { List countStateByProjectID(String projectId); List countApiCoverageByProjectID(String projectId); + + ApiDefinition getNextNum(@Param("projectId") String projectId); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml index 226b6b46a5..c6c91a5300 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiDefinitionMapper.xml @@ -194,7 +194,7 @@ + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java index dd368189cd..7645843c99 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.java @@ -29,4 +29,6 @@ public interface ExtApiScenarioMapper { List countRunResultByProjectID(String projectId); List selectIdsNotExistsInPlan(String projectId, String planId); + + ApiScenario getNextNum(@Param("projectId") String projectId); } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml index d4b91553d2..ce4b0b3e29 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiScenarioMapper.xml @@ -9,7 +9,7 @@ + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java index 1451d970bf..88f1298c65 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.java @@ -4,6 +4,7 @@ import io.metersphere.api.dto.datacount.ApiDataCountResult; import io.metersphere.api.dto.definition.ApiTestCaseDTO; import io.metersphere.api.dto.definition.ApiTestCaseRequest; import io.metersphere.api.dto.definition.ApiTestCaseResult; +import io.metersphere.base.domain.ApiTestCase; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import org.apache.ibatis.annotations.MapKey; import org.apache.ibatis.annotations.Param; @@ -25,4 +26,6 @@ public interface ExtApiTestCaseMapper { long countByProjectIDAndCreateInThisWeek(@Param("projectId") String projectId, @Param("firstDayTimestamp") long firstDayTimestamp, @Param("lastDayTimestamp") long lastDayTimestamp); List getRequest(@Param("request") ApiTestCaseRequest request); + + ApiTestCase getNextNum(@Param("definitionId") String definitionId); } \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml index fcf28b8024..6fa06d9a1b 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtApiTestCaseMapper.xml @@ -161,6 +161,7 @@ atc.create_time, atc.update_user_id, atc.update_time, + atc.num, ader.status execResult, ader.create_time execTime from @@ -204,7 +205,7 @@ + \ No newline at end of file diff --git a/backend/src/main/resources/db/migration/V57__init_api_definition_num.sql b/backend/src/main/resources/db/migration/V57__init_api_definition_num.sql new file mode 100644 index 0000000000..8c3055ec2e --- /dev/null +++ b/backend/src/main/resources/db/migration/V57__init_api_definition_num.sql @@ -0,0 +1,125 @@ +alter table api_definition add num int null comment 'api definition ID'; +alter table api_test_case add num int null comment 'api test case ID'; +alter table api_scenario add num int null comment 'api scenario ID'; + +DROP PROCEDURE IF EXISTS test_cursor; +DELIMITER // +CREATE PROCEDURE test_cursor() +BEGIN + DECLARE projectId VARCHAR(64); + DECLARE definitionId VARCHAR(64); + DECLARE apiTestCaseId VARCHAR(64); + DECLARE num1 INT; + DECLARE num2 INT; + DECLARE done INT DEFAULT 0; + DECLARE cursor1 CURSOR FOR (SELECT DISTINCT project_id + FROM api_definition + WHERE num IS NULL); + DECLARE cursor2 CURSOR FOR (SELECT id + FROM api_definition + WHERE project_id = projectId + ORDER BY create_time); + DECLARE cursor3 CURSOR FOR (SELECT id + FROM api_test_case + WHERE api_definition_id = definitionId + ORDER BY create_time); + + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + OPEN cursor1; + outer_loop: + LOOP + FETCH cursor1 INTO projectId; + IF done + THEN + LEAVE outer_loop; + END IF; + SET num1 = 100001; + OPEN cursor2; + inner_loop: + LOOP + FETCH cursor2 INTO definitionId; + IF done + THEN + LEAVE inner_loop; + END IF; + UPDATE api_definition + SET num = num1 + WHERE id = definitionId; + SET num2 = num1 * 1000 + 1; + OPEN cursor3; + inner_loop2: + LOOP + FETCH cursor3 INTO apiTestCaseId; + IF done + THEN + LEAVE inner_loop2; + END IF; + UPDATE api_test_case + SET num = num2 + WHERE id = apiTestCaseId; + SET num2 = num2 + 1; + END LOOP; + SET done = 0; + CLOSE cursor3; + SET num1 = num1 + 1; + END LOOP; + SET done = 0; + CLOSE cursor2; + END LOOP; + CLOSE cursor1; +END // +DELIMITER ; + +CALL test_cursor(); +DROP PROCEDURE IF EXISTS test_cursor; + + +DROP PROCEDURE IF EXISTS test_cursor1; +DELIMITER // +CREATE PROCEDURE test_cursor1() +BEGIN + DECLARE projectId VARCHAR(64); + DECLARE scenarioId VARCHAR(64); + DECLARE num INT; + DECLARE done INT DEFAULT 0; + DECLARE cursor1 CURSOR FOR (SELECT DISTINCT project_id + FROM api_scenario + WHERE num IS NULL); + DECLARE cursor2 CURSOR FOR (SELECT id + FROM api_scenario + WHERE project_id = projectId + ORDER BY create_time); + + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE; + OPEN cursor1; + outer_loop: + LOOP + FETCH cursor1 INTO projectId; + IF done + THEN + LEAVE outer_loop; + END IF; + SET num = 100001; + OPEN cursor2; + inner_loop: + LOOP + FETCH cursor2 INTO scenarioId; + IF done + THEN + LEAVE inner_loop; + END IF; + UPDATE api_scenario + SET num = num + WHERE id = scenarioId; + SET num = num + 1; + END LOOP; + SET done = 0; + CLOSE cursor2; + END LOOP; + CLOSE cursor1; +END // +DELIMITER ; + +CALL test_cursor1(); +DROP PROCEDURE IF EXISTS test_cursor1; \ No newline at end of file diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index bddab609e5..3ce27534e9 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -13,6 +13,8 @@ + + +