diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java index 8159e8b58b..b0fe4d56ea 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -14,6 +14,7 @@ import io.metersphere.base.domain.Schedule; import io.metersphere.commons.constants.*; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; +import io.metersphere.controller.request.ResetOrderRequest; import io.metersphere.controller.request.ScheduleRequest; import io.metersphere.log.annotation.MsAuditLog; import io.metersphere.notice.annotation.SendNotice; @@ -105,6 +106,12 @@ public class ApiAutomationController { return apiAutomationService.update(request, bodyFiles, scenarioFiles); } + + @PostMapping("/edit/order") + public void orderCase(@RequestBody ResetOrderRequest request) { + apiAutomationService.updateOrder(request); + } + @GetMapping("/delete/{id}") @MsAuditLog(module = "api_automation", type = OperLogConstants.DELETE, beforeEvent = "#msClass.getLogDetails(#id)", msClass = ApiAutomationService.class) @RequiresPermissions(PermissionConstants.PROJECT_API_SCENARIO_READ_DELETE) 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 5b8daa7a9d..55d7afafc2 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -31,6 +31,7 @@ import io.metersphere.base.mapper.ext.*; import io.metersphere.commons.constants.*; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.*; +import io.metersphere.controller.request.ResetOrderRequest; import io.metersphere.controller.request.ScheduleRequest; import io.metersphere.dto.ApiReportCountDTO; import io.metersphere.dto.BaseSystemConfigDTO; @@ -189,7 +190,7 @@ public class ApiAutomationService { */ private ApiScenarioRequest initRequest(ApiScenarioRequest request, boolean setDefultOrders, boolean checkThisWeekData) { if (setDefultOrders) { - request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); + request.setOrders(ServiceUtils.getDefaultSortOrder(request.getOrders())); } if (StringUtils.isNotEmpty(request.getExecuteStatus())) { Map> statusFilter = new HashMap<>(); @@ -235,6 +236,7 @@ public class ApiAutomationService { scenario.setNum(nextNum); List useUrl = this.parseUrl(scenario); scenario.setUseUrl(JSONArray.toJSONString(useUrl)); + scenario.setOrder(ServiceUtils.getNextOrder(scenario.getProjectId(), extApiScenarioMapper::getLastOrder)); //检查场景的请求步骤。如果含有ESB请求步骤的话,要做参数计算处理。 esbApiParamService.checkScenarioRequests(request); @@ -2502,4 +2504,22 @@ public class ApiAutomationService { return result.longValue(); } } + + public void initOrderField() { + ServiceUtils.initOrderField(ApiScenarioWithBLOBs.class, ApiScenarioMapper.class, + extApiScenarioMapper::selectProjectIds, + extApiScenarioMapper::getIdsOrderByCreateTime); + } + + /** + * 用例自定义排序 + * @param request + */ + public void updateOrder(ResetOrderRequest request) { + ServiceUtils.updateOrderField(request, ApiScenarioWithBLOBs.class, + apiScenarioMapper::selectByPrimaryKey, + extApiScenarioMapper::getPreOrder, + extApiScenarioMapper::getLastOrder, + apiScenarioMapper::updateByPrimaryKeySelective); + } } 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 4792eac9d2..b8d13cbc46 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenario.java @@ -57,5 +57,7 @@ public class ApiScenario implements Serializable { private Integer executeTimes; + private Long order; + 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 a47f821fea..3ccebd5ce5 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiScenarioExample.java @@ -1853,6 +1853,66 @@ public class ApiScenarioExample { addCriterion("execute_times not between", value1, value2, "executeTimes"); return (Criteria) this; } + + public Criteria andOrderIsNull() { + addCriterion("`order` is null"); + return (Criteria) this; + } + + public Criteria andOrderIsNotNull() { + addCriterion("`order` is not null"); + return (Criteria) this; + } + + public Criteria andOrderEqualTo(Long value) { + addCriterion("`order` =", value, "order"); + return (Criteria) this; + } + + public Criteria andOrderNotEqualTo(Long value) { + addCriterion("`order` <>", value, "order"); + return (Criteria) this; + } + + public Criteria andOrderGreaterThan(Long value) { + addCriterion("`order` >", value, "order"); + return (Criteria) this; + } + + public Criteria andOrderGreaterThanOrEqualTo(Long value) { + addCriterion("`order` >=", value, "order"); + return (Criteria) this; + } + + public Criteria andOrderLessThan(Long value) { + addCriterion("`order` <", value, "order"); + return (Criteria) this; + } + + public Criteria andOrderLessThanOrEqualTo(Long value) { + addCriterion("`order` <=", value, "order"); + return (Criteria) this; + } + + public Criteria andOrderIn(List values) { + addCriterion("`order` in", values, "order"); + return (Criteria) this; + } + + public Criteria andOrderNotIn(List values) { + addCriterion("`order` not in", values, "order"); + return (Criteria) this; + } + + public Criteria andOrderBetween(Long value1, Long value2) { + addCriterion("`order` between", value1, value2, "order"); + return (Criteria) this; + } + + public Criteria andOrderNotBetween(Long value1, Long value2) { + addCriterion("`order` not between", value1, value2, "order"); + return (Criteria) this; + } } public static class Criteria extends GeneratedCriteria { 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 4e4e1bed04..2addae4fd7 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiScenarioMapper.xml @@ -28,6 +28,7 @@ + @@ -96,7 +97,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, num, original_state, custom_num, create_user, - version, delete_time, delete_user_id, execute_times + version, delete_time, delete_user_id, execute_times, `order` scenario_definition, description, use_url @@ -158,8 +159,9 @@ pass_rate, last_result, report_id, num, original_state, custom_num, create_user, version, delete_time, - delete_user_id, execute_times, scenario_definition, - description, use_url) + delete_user_id, execute_times, `order`, + scenario_definition, description, + use_url) values (#{id,jdbcType=VARCHAR}, #{projectId,jdbcType=VARCHAR}, #{tags,jdbcType=VARCHAR}, #{userId,jdbcType=VARCHAR}, #{apiScenarioModuleId,jdbcType=VARCHAR}, #{modulePath,jdbcType=VARCHAR}, #{name,jdbcType=VARCHAR}, #{level,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, @@ -168,8 +170,9 @@ #{passRate,jdbcType=VARCHAR}, #{lastResult,jdbcType=VARCHAR}, #{reportId,jdbcType=VARCHAR}, #{num,jdbcType=INTEGER}, #{originalState,jdbcType=VARCHAR}, #{customNum,jdbcType=VARCHAR}, #{createUser,jdbcType=VARCHAR}, #{version,jdbcType=INTEGER}, #{deleteTime,jdbcType=BIGINT}, - #{deleteUserId,jdbcType=VARCHAR}, #{executeTimes,jdbcType=INTEGER}, #{scenarioDefinition,jdbcType=LONGVARCHAR}, - #{description,jdbcType=LONGVARCHAR}, #{useUrl,jdbcType=LONGVARCHAR}) + #{deleteUserId,jdbcType=VARCHAR}, #{executeTimes,jdbcType=INTEGER}, #{order,jdbcType=BIGINT}, + #{scenarioDefinition,jdbcType=LONGVARCHAR}, #{description,jdbcType=LONGVARCHAR}, + #{useUrl,jdbcType=LONGVARCHAR}) insert into api_scenario @@ -252,6 +255,9 @@ execute_times, + + `order`, + scenario_definition, @@ -341,6 +347,9 @@ #{executeTimes,jdbcType=INTEGER}, + + #{order,jdbcType=BIGINT}, + #{scenarioDefinition,jdbcType=LONGVARCHAR}, @@ -439,6 +448,9 @@ execute_times = #{record.executeTimes,jdbcType=INTEGER}, + + `order` = #{record.order,jdbcType=BIGINT}, + scenario_definition = #{record.scenarioDefinition,jdbcType=LONGVARCHAR}, @@ -481,6 +493,7 @@ delete_time = #{record.deleteTime,jdbcType=BIGINT}, delete_user_id = #{record.deleteUserId,jdbcType=VARCHAR}, execute_times = #{record.executeTimes,jdbcType=INTEGER}, + `order` = #{record.order,jdbcType=BIGINT}, scenario_definition = #{record.scenarioDefinition,jdbcType=LONGVARCHAR}, description = #{record.description,jdbcType=LONGVARCHAR}, use_url = #{record.useUrl,jdbcType=LONGVARCHAR} @@ -515,7 +528,8 @@ version = #{record.version,jdbcType=INTEGER}, delete_time = #{record.deleteTime,jdbcType=BIGINT}, delete_user_id = #{record.deleteUserId,jdbcType=VARCHAR}, - execute_times = #{record.executeTimes,jdbcType=INTEGER} + execute_times = #{record.executeTimes,jdbcType=INTEGER}, + `order` = #{record.order,jdbcType=BIGINT} @@ -598,6 +612,9 @@ execute_times = #{executeTimes,jdbcType=INTEGER}, + + `order` = #{order,jdbcType=BIGINT}, + scenario_definition = #{scenarioDefinition,jdbcType=LONGVARCHAR}, @@ -637,6 +654,7 @@ delete_time = #{deleteTime,jdbcType=BIGINT}, delete_user_id = #{deleteUserId,jdbcType=VARCHAR}, execute_times = #{executeTimes,jdbcType=INTEGER}, + `order` = #{order,jdbcType=BIGINT}, scenario_definition = #{scenarioDefinition,jdbcType=LONGVARCHAR}, description = #{description,jdbcType=LONGVARCHAR}, use_url = #{useUrl,jdbcType=LONGVARCHAR} @@ -668,7 +686,8 @@ version = #{version,jdbcType=INTEGER}, delete_time = #{deleteTime,jdbcType=BIGINT}, delete_user_id = #{deleteUserId,jdbcType=VARCHAR}, - execute_times = #{executeTimes,jdbcType=INTEGER} + execute_times = #{executeTimes,jdbcType=INTEGER}, + `order` = #{order,jdbcType=BIGINT} where id = #{id,jdbcType=VARCHAR} \ 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 87ffee4d73..1a62f81bda 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 @@ -72,4 +72,12 @@ public interface ExtApiScenarioMapper { List selectIdsByExecuteTimeIsNull(); Long countExecuteTimesByProjectID(String projectId); + + List selectProjectIds(); + + List getIdsOrderByCreateTime(@Param("projectId") String projectId); + + Long getPreOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder); + + Long getLastOrder(@Param("projectId")String projectId, @Param("baseOrder") Long baseOrder); } 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 1192cfed60..fc86fde515 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 @@ -461,6 +461,28 @@ SELECT SUM(execute_times) FROM api_scenario WHERE project_id = #{0} + + + + + + diff --git a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java index 06edb1328c..bac48aa1b2 100644 --- a/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java +++ b/backend/src/main/java/io/metersphere/commons/utils/ServiceUtils.java @@ -142,8 +142,7 @@ public class ServiceUtils { Long order = 0L; List ids = getIdsOrderByCreateTimeFunc.apply(projectId); for (String id : ids) { - T item = null; - item = (T) clazz.newInstance(); + T item = clazz.newInstance(); setId.invoke(item, id); setOrder.invoke(item, order); order += 5000; diff --git a/backend/src/main/java/io/metersphere/listener/AppStartListener.java b/backend/src/main/java/io/metersphere/listener/AppStartListener.java index 9a639158a6..7ca9e63a03 100644 --- a/backend/src/main/java/io/metersphere/listener/AppStartListener.java +++ b/backend/src/main/java/io/metersphere/listener/AppStartListener.java @@ -111,6 +111,7 @@ public class AppStartListener implements ApplicationListener 0 ? false : true; + //检查是否只查询本周数据 this.condition.selectThisWeedData = false; this.condition.executeStatus = null; @@ -592,12 +598,20 @@ export default { item.tags = JSON.parse(item.tags); } }); - if (this.$refs.scenarioTable) { - this.$refs.scenarioTable.clear(); - this.$nextTick(() => { - this.$refs.scenarioTable.doLayout(); + + this.$nextTick(() => { + handleRowDrop(this.tableData, (param) => { + param.projectId = this.condition.projectId; + editApiScenarioCaseOrder(param); }); - } + + if (this.$refs.scenarioTable) { + this.$refs.scenarioTable.clear(); + this.$refs.scenarioTable.doLayout(); + } + + }); + this.$emit('getTrashCase'); }); }