feat: 场景用例支持自定义排序
This commit is contained in:
parent
0236bc3a6e
commit
806bad3206
|
@ -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)
|
||||
|
|
|
@ -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<String, List<String>> statusFilter = new HashMap<>();
|
||||
|
@ -235,6 +236,7 @@ public class ApiAutomationService {
|
|||
scenario.setNum(nextNum);
|
||||
List<ApiMethodUrlDTO> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,5 +57,7 @@ public class ApiScenario implements Serializable {
|
|||
|
||||
private Integer executeTimes;
|
||||
|
||||
private Long order;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
}
|
|
@ -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<Long> values) {
|
||||
addCriterion("`order` in", values, "order");
|
||||
return (Criteria) this;
|
||||
}
|
||||
|
||||
public Criteria andOrderNotIn(List<Long> 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 {
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
<result column="delete_time" jdbcType="BIGINT" property="deleteTime" />
|
||||
<result column="delete_user_id" jdbcType="VARCHAR" property="deleteUserId" />
|
||||
<result column="execute_times" jdbcType="INTEGER" property="executeTimes" />
|
||||
<result column="order" jdbcType="BIGINT" property="order" />
|
||||
</resultMap>
|
||||
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="io.metersphere.base.domain.ApiScenarioWithBLOBs">
|
||||
<result column="scenario_definition" jdbcType="LONGVARCHAR" property="scenarioDefinition" />
|
||||
|
@ -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`
|
||||
</sql>
|
||||
<sql id="Blob_Column_List">
|
||||
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>
|
||||
<insert id="insertSelective" parameterType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
|
||||
insert into api_scenario
|
||||
|
@ -252,6 +255,9 @@
|
|||
<if test="executeTimes != null">
|
||||
execute_times,
|
||||
</if>
|
||||
<if test="order != null">
|
||||
`order`,
|
||||
</if>
|
||||
<if test="scenarioDefinition != null">
|
||||
scenario_definition,
|
||||
</if>
|
||||
|
@ -341,6 +347,9 @@
|
|||
<if test="executeTimes != null">
|
||||
#{executeTimes,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="order != null">
|
||||
#{order,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="scenarioDefinition != null">
|
||||
#{scenarioDefinition,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
|
@ -439,6 +448,9 @@
|
|||
<if test="record.executeTimes != null">
|
||||
execute_times = #{record.executeTimes,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="record.order != null">
|
||||
`order` = #{record.order,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="record.scenarioDefinition != null">
|
||||
scenario_definition = #{record.scenarioDefinition,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
|
@ -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}
|
||||
<if test="_parameter != null">
|
||||
<include refid="Update_By_Example_Where_Clause" />
|
||||
</if>
|
||||
|
@ -598,6 +612,9 @@
|
|||
<if test="executeTimes != null">
|
||||
execute_times = #{executeTimes,jdbcType=INTEGER},
|
||||
</if>
|
||||
<if test="order != null">
|
||||
`order` = #{order,jdbcType=BIGINT},
|
||||
</if>
|
||||
<if test="scenarioDefinition != null">
|
||||
scenario_definition = #{scenarioDefinition,jdbcType=LONGVARCHAR},
|
||||
</if>
|
||||
|
@ -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}
|
||||
</update>
|
||||
</mapper>
|
|
@ -72,4 +72,12 @@ public interface ExtApiScenarioMapper {
|
|||
List<String> selectIdsByExecuteTimeIsNull();
|
||||
|
||||
Long countExecuteTimesByProjectID(String projectId);
|
||||
|
||||
List<String> selectProjectIds();
|
||||
|
||||
List<String> 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);
|
||||
}
|
||||
|
|
|
@ -461,6 +461,28 @@
|
|||
SELECT SUM(execute_times) FROM api_scenario
|
||||
WHERE project_id = #{0}
|
||||
</select>
|
||||
<select id="selectProjectIds" resultType="java.lang.String">
|
||||
select DISTINCT project_id from api_scenario;
|
||||
</select>
|
||||
<select id="getIdsOrderByCreateTime" resultType="java.lang.String">
|
||||
select id from api_scenario where project_id = #{projectId} order by create_time DESC;
|
||||
</select>
|
||||
|
||||
<select id="getLastOrder" resultType="java.lang.Long">
|
||||
select `order` from api_scenario where project_id = #{projectId}
|
||||
<if test="baseOrder != null">
|
||||
and `order` > #{baseOrder}
|
||||
</if>
|
||||
order by `order` desc limit 1;
|
||||
</select>
|
||||
|
||||
<select id="getPreOrder" resultType="java.lang.Long">
|
||||
select `order` from api_scenario where project_id = #{projectId}
|
||||
<if test="baseOrder != null">
|
||||
and `order` < #{baseOrder}
|
||||
</if>
|
||||
order by `order` desc limit 1;
|
||||
</select>
|
||||
|
||||
<sql id="queryWhereConditionReview">
|
||||
<where>
|
||||
|
|
|
@ -142,8 +142,7 @@ public class ServiceUtils {
|
|||
Long order = 0L;
|
||||
List<String> 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;
|
||||
|
|
|
@ -111,6 +111,7 @@ public class AppStartListener implements ApplicationListener<ApplicationReadyEve
|
|||
initOnceOperate(performanceTestService::initScenarioLoadTest, "init.scenario.load.test");
|
||||
initOnceOperate(testCaseService::initOrderField, "init.sort.test.case");
|
||||
initOnceOperate(apiTestCaseService::initOrderField, "init.sort.api.test.case");
|
||||
initOnceOperate(apiAutomationService::initOrderField, "init.sort.api.scenario");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,3 +36,5 @@ update api_scenario set module_path = replace (`module_path`,'/默认模块','/
|
|||
|
||||
ALTER TABLE test_case ADD `order` bigint(20) NOT NULL COMMENT '自定义排序,间隔5000';
|
||||
ALTER TABLE api_test_case ADD `order` bigint(20) NOT NULL COMMENT '自定义排序,间隔5000';
|
||||
ALTER TABLE api_scenario ADD `order` bigint(20) NOT NULL COMMENT '自定义排序,间隔5000';
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import {getUUID} from "@/common/js/utils";
|
||||
import {getUploadConfig, request} from "@/common/js/ajax";
|
||||
import {basePost} from "@/network/base-network";
|
||||
|
||||
function buildBodyFile(item, bodyUploadFiles, obj, bodyParam) {
|
||||
if (bodyParam) {
|
||||
|
@ -99,3 +100,7 @@ export function saveScenario(url, scenario, scenarioDefinition, _this,success) {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function editApiScenarioCaseOrder(request, callback) {
|
||||
return basePost('/api/automation/edit/order', request, callback);
|
||||
}
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
:field-key=tableHeaderKey
|
||||
:remember-order="true"
|
||||
operator-width="200"
|
||||
:enable-order-drag="enableOrderDrag"
|
||||
row-key="id"
|
||||
@refresh="search(projectId)"
|
||||
@callBackSelectAll="callBackSelectAll"
|
||||
@callBackSelect="callBackSelect"
|
||||
|
@ -234,13 +236,14 @@ import {API_SCENARIO_CONFIGS} from "@/business/components/common/components/sear
|
|||
import {API_SCENARIO_LIST} from "../../../../../common/js/constants";
|
||||
|
||||
import {
|
||||
getCustomTableHeader, getCustomTableWidth, getLastTableSortField, saveLastTableSortField
|
||||
getCustomTableHeader, getCustomTableWidth, getLastTableSortField, handleRowDrop, saveLastTableSortField
|
||||
} from "@/common/js/tableUtils";
|
||||
import {API_SCENARIO_FILTERS} from "@/common/js/table-constants";
|
||||
import {scenario} from "@/business/components/track/plan/event-bus";
|
||||
import MsTable from "@/business/components/common/components/table/MsTable";
|
||||
import MsTableColumn from "@/business/components/common/components/table/MsTableColumn";
|
||||
import HeaderLabelOperate from "@/business/components/common/head/HeaderLabelOperate";
|
||||
import {editApiScenarioCaseOrder} from "@/business/components/api/automation/api-automation";
|
||||
|
||||
export default {
|
||||
name: "MsApiScenarioList",
|
||||
|
@ -345,6 +348,7 @@ export default {
|
|||
operators: [],
|
||||
selectRows: new Set(),
|
||||
isStop: false,
|
||||
enableOrderDrag: true,
|
||||
trashOperators: [
|
||||
{
|
||||
tip: this.$t('commons.reduction'),
|
||||
|
@ -563,6 +567,8 @@ export default {
|
|||
this.condition.projectId = this.projectId;
|
||||
}
|
||||
|
||||
this.enableOrderDrag = this.condition.orders.length > 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');
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue