refactor: 重构场景全选

This commit is contained in:
chenjianxing 2021-02-19 14:37:25 +08:00
parent 5e8cbfe931
commit 1e2e80d507
12 changed files with 111 additions and 80 deletions

View File

@ -105,7 +105,7 @@ public class ApiAutomationController {
@PostMapping("/batch/edit")
@RequiresRoles(value = {RoleConstants.TEST_USER, RoleConstants.TEST_MANAGER}, logical = Logical.OR)
public void bathEdit(@RequestBody SaveApiScenarioRequest request) {
public void bathEdit(@RequestBody ApiScenarioBatchRequest request) {
apiAutomationService.bathEdit(request);
}

View File

@ -0,0 +1,21 @@
package io.metersphere.api.dto.automation;
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
public class ApiScenarioBatchRequest extends ApiScenarioWithBLOBs {
private List<String> ids;
private String projectId;
private String environmentId;
private String executeStatus;
private boolean notInTestPlan;
private String planId;
private ApiScenarioRequest condition;
}

View File

@ -1,5 +1,6 @@
package io.metersphere.api.dto.automation;
import io.metersphere.controller.request.BaseQueryRequest;
import io.metersphere.controller.request.OrderRequest;
import lombok.Getter;
import lombok.Setter;
@ -9,21 +10,14 @@ import java.util.Map;
@Getter
@Setter
public class ApiScenarioRequest {
public class ApiScenarioRequest extends BaseQueryRequest {
private String id;
private String excludeId;
private String projectId;
private String moduleId;
private List<String> moduleIds;
private String name;
private String workspaceId;
private String userId;
private String planId;
private boolean recent = false;
private List<OrderRequest> orders;
private Map<String, List<String>> filters;
private Map<String, Object> combine;
private List<String> ids;
private boolean isSelectThisWeedData;
private long createTime = 0;
private String executeStatus;

View File

@ -688,20 +688,17 @@ public class ApiAutomationService {
return dto;
}
public void bathEdit(SaveApiScenarioRequest request) {
if (CollectionUtils.isEmpty(request.getScenarioIds())) {
return;
}
if (request.isSelectAllDate()) {
request.setScenarioIds(this.getAllScenarioIdsByFontedSelect(
request.getModuleIds(), request.getName(), request.getProjectId(), request.getFilters(), request.getUnSelectIds()));
}
public void bathEdit(ApiScenarioBatchRequest request) {
ServiceUtils.getSelectAllIds(request, request.getCondition(),
(query) -> extApiScenarioMapper.selectIdsByQuery((ApiScenarioRequest) query));
if (StringUtils.isNotBlank(request.getEnvironmentId())) {
bathEditEnv(request);
return;
}
ApiScenarioExample apiScenarioExample = new ApiScenarioExample();
apiScenarioExample.createCriteria().andIdIn(request.getScenarioIds());
apiScenarioExample.createCriteria().andIdIn(request.getIds());
ApiScenarioWithBLOBs apiScenarioWithBLOBs = new ApiScenarioWithBLOBs();
BeanUtils.copyBean(apiScenarioWithBLOBs, request);
apiScenarioWithBLOBs.setUpdateTime(System.currentTimeMillis());
@ -710,9 +707,9 @@ public class ApiAutomationService {
apiScenarioExample);
}
public void bathEditEnv(SaveApiScenarioRequest request) {
public void bathEditEnv(ApiScenarioBatchRequest request) {
if (StringUtils.isNotBlank(request.getEnvironmentId())) {
List<ApiScenarioWithBLOBs> apiScenarios = selectByIdsWithBLOBs(request.getScenarioIds());
List<ApiScenarioWithBLOBs> apiScenarios = selectByIdsWithBLOBs(request.getIds());
apiScenarios.forEach(item -> {
JSONObject object = JSONObject.parseObject(item.getScenarioDefinition());
object.put("environmentId", request.getEnvironmentId());

View File

@ -6,6 +6,7 @@ import io.metersphere.api.dto.datacount.ApiDataCountResult;
import io.metersphere.base.domain.ApiScenario;
import io.metersphere.base.domain.ApiScenarioExample;
import io.metersphere.base.domain.ApiScenarioWithBLOBs;
import io.metersphere.controller.request.BaseQueryRequest;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -34,4 +35,6 @@ public interface ExtApiScenarioMapper {
List<String> selectIdsNotExistsInPlan(String projectId, String planId);
ApiScenario getNextNum(@Param("projectId") String projectId);
List<String> selectIdsByQuery(@Param("request") ApiScenarioRequest request);
}

View File

@ -134,6 +134,11 @@
from api_scenario
left join project on api_scenario.project_id = project.id
left join user on api_scenario.user_id = user.id
<include refid="queryWhereCondition"/>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
<sql id="queryWhereCondition">
<where>
<if test="request.combine != null">
<include refid="combine">
@ -144,8 +149,8 @@
<if test="request.name != null">
and (api_scenario.name like CONCAT('%', #{request.name},'%')
or api_scenario.tags like CONCAT('%', #{request.name},'%')
or api_scenario.num like CONCAT('%', #{request.name},'%'))
or api_scenario.tags like CONCAT('%', #{request.name},'%')
or api_scenario.num like CONCAT('%', #{request.name},'%'))
</if>
<if test="request.workspaceId != null">
AND project.workspace_id = #{request.workspaceId}
@ -223,19 +228,13 @@
</if>
<if test="request.notInTestPlan == true ">
and api_scenario.id not in (
select pc.api_scenario_id
from test_plan_api_scenario pc
where pc.test_plan_id = #{request.planId}
select pc.api_scenario_id
from test_plan_api_scenario pc
where pc.test_plan_id = #{request.planId}
)
</if>
</where>
<if test="request.orders != null and request.orders.size() > 0">
order by
<foreach collection="request.orders" separator="," item="order">
api_scenario.${order.name} ${order.type}
</foreach>
</if>
</select>
</sql>
<select id="selectByTagId" resultType="io.metersphere.base.domain.ApiScenarioWithBLOBs">
select * from api_scenario where tags like CONCAT('%', #{id},'%')
@ -321,4 +320,12 @@
SELECT * FROM api_scenario WHERE api_scenario.project_id = #{projectId} ORDER BY num DESC LIMIT 1;
</select>
<select id="selectIdsByQuery" resultType="java.lang.String">
select api_scenario.id
from api_scenario
left join project on api_scenario.project_id = project.id
<include refid="queryWhereCondition"/>
<include refid="io.metersphere.base.mapper.ext.ExtBaseMapper.orders"/>
</select>
</mapper>

View File

@ -8,6 +8,7 @@
@setModuleOptions="setModuleOptions"
@setNodeTree="setNodeTree"
@enableTrash="enableTrash"
@exportAPI="exportAPI"
:type="'edit'"
ref="nodeTree"/>
</ms-aside-container>
@ -267,6 +268,9 @@
},
enableTrash(data) {
this.trashEnable = data;
},
exportAPI() {
this.$refs.apiScenarioList[0].exportApi();
}
}
}

View File

@ -9,7 +9,8 @@
<el-table ref="scenarioTable" border :data="tableData" class="adjust-table ms-select-all-fixed"
@sort-change="sort"
@filter-change="filter"
@select-all="select" @select="select"
@select-all="handleSelectAll"
@select="handleSelect"
@header-dragend="headerDragend"
:height="screenHeight"
v-loading="loading">
@ -24,7 +25,7 @@
<el-table-column v-if="!referenced" width="30" min-width="30" :resizable="false" align="center">
<template v-slot:default="scope">
<show-more-btn :is-show="isSelect(scope.row)" :buttons="buttons" :size="selectDataCounts"/>
<show-more-btn :is-show="scope.row.showMore" :buttons="buttons" :size="selectDataCounts"/>
</template>
</el-table-column>
@ -155,7 +156,7 @@ import MsTableHeader from "@/business/components/common/components/MsTableHeader
import MsTablePagination from "@/business/components/common/pagination/TablePagination";
import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn";
import MsTag from "../../../common/components/MsTag";
import {getCurrentProjectID, getUUID} from "@/common/js/utils";
import {downloadFile, getCurrentProjectID, getUUID} from "@/common/js/utils";
import MsApiReportDetail from "../report/ApiReportDetail";
import MsTableMoreBtn from "./TableMoreBtn";
import MsScenarioExtendButtons from "@/business/components/api/automation/scenario/ScenarioExtendBtns";
@ -166,10 +167,17 @@ import MsTableOperatorButton from "@/business/components/common/components/MsTab
import PriorityTableItem from "../../../track/common/tableItems/planview/PriorityTableItem";
import PlanStatusTableItem from "../../../track/common/tableItems/plan/PlanStatusTableItem";
import BatchEdit from "../../../track/case/components/BatchEdit";
import {WORKSPACE_ID} from "../../../../../common/js/constants";
import {PROJECT_NAME, WORKSPACE_ID} from "../../../../../common/js/constants";
import EnvironmentSelect from "../../definition/components/environment/EnvironmentSelect";
import BatchMove from "../../../track/case/components/BatchMove";
import {_filter, _sort} from "@/common/js/tableUtils";
import {
_filter,
_handleSelect,
_handleSelectAll,
_sort,
getSelectDataCounts,
setUnSelectIds, toggleAllSelection
} from "@/common/js/tableUtils";
export default {
name: "MsApiScenarioList",
@ -255,7 +263,7 @@ export default {
}
],
isSelectAllDate: false,
unSelection: [],
selectRows: new Set(),
selectDataCounts: 0,
typeArr: [
{id: 'level', name: this.$t('test_track.case.priority')},
@ -331,6 +339,7 @@ export default {
this.search();
},
search() {
this.selectRows = new Set();
this.condition.moduleIds = this.selectNodeIds;
if (this.trashEnable) {
this.condition.filters = {status: ["Trash"]};
@ -481,11 +490,9 @@ export default {
}
},
buildBatchParam(param) {
param.scenarioIds = this.selection;
param.ids = Array.from(this.selectRows).map(row => row.id);
param.projectId = getCurrentProjectID();
param.selectAllDate = this.isSelectAllDate;
param.unSelectIds = this.unSelection;
param = Object.assign(param, this.condition);
param.condition = this.condition;
},
handleBatchExecute() {
this.infoDb = false;
@ -499,16 +506,21 @@ export default {
this.batchReportId = run.id;
});
},
select(selection) {
this.selection = selection.map(s => s.id);
//
this.selectRowsCount(this.selection)
this.$emit('selection', selection);
handleSelectAll(selection) {
_handleSelectAll(this, selection, this.tableData, this.selectRows);
setUnSelectIds(this.tableData, this.condition, this.selectRows);
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
},
isSelect(row) {
return this.selection.includes(row.id)
handleSelect(selection, row) {
_handleSelect(this, selection, row, this.selectRows);
setUnSelectIds(this.tableData, this.condition, this.selectRows);
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
},
isSelectDataAll(data) {
this.condition.selectAll = data;
setUnSelectIds(this.tableData, this.condition, this.selectRows);
this.selectDataCounts = getSelectDataCounts(this.condition, this.total, this.selectRows);
toggleAllSelection(this.$refs.scenarioTable, this.tableData, this.selectRows);
},
edit(row) {
let data = JSON.parse(JSON.stringify(row));
@ -549,28 +561,6 @@ export default {
this.infoDb = true;
this.reportId = row.reportId;
},
//
isSelectDataAll(dataType) {
this.isSelectAllDate = dataType;
this.selectRowsCount(this.selection);
//
if (this.selection.length != this.tableData.length) {
this.$refs.scenarioTable.toggleAllSelection(true);
}
},
//
selectRowsCount(selection) {
let selectedIDs = selection;
let allIDs = this.tableData.map(s => s.id);
this.unSelection = allIDs.filter(function (val) {
return selectedIDs.indexOf(val) === -1
});
if (this.isSelectAllDate) {
this.selectDataCounts = this.total - this.unSelection.length;
} else {
this.selectDataCounts = this.selection.length;
}
},
//
isSelectThissWeekData() {
let dataRange = this.$route.params.dataSelectRange;
@ -623,6 +613,16 @@ export default {
openScenario(item) {
this.$emit('openScenario', item)
},
exportApi() {
let param = this.buildBatchParam();
param.protocol = this.currentProtocol;
this.result = this.$post("/api/definition/export", param, response => {
let obj = response.data;
obj.protocol = this.currentProtocol;
this.buildApiPath(obj.data);
downloadFile("Metersphere_Api_" + localStorage.getItem(PROJECT_NAME) + ".json", JSON.stringify(obj));
});
}
}
}
</script>

View File

@ -20,6 +20,7 @@
:condition="condition"
:current-module="currentModule"
:is-read-only="isReadOnly"
:project-id="projectId"
@exportAPI="exportAPI"
@addScenario="addScenario"
@refreshTable="$emit('refreshTable')"

View File

@ -21,7 +21,6 @@
</div>
</template>
<script>
import {getCurrentProjectID} from "../../../../../../common/js/utils";
import {buildNodePath} from "@/business/components/api/definition/model/NodeTree";
import ModuleTrashButton from "@/business/components/api/definition/components/module/ModuleTrashButton";
import ApiImport from "@/business/components/api/definition/components/import/ApiImport";
@ -31,7 +30,6 @@ export default {
components: {ApiImport, ModuleTrashButton},
data() {
return {
// options: OPTIONS,
moduleOptions: {}
}
},
@ -54,16 +52,17 @@ export default {
return false
}
},
projectId: String
},
methods: {
handleCommand(e) {
switch (e) {
case "import":
if (!getCurrentProjectID()) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}
this.result = this.$get("/api/automation/module/list/" + getCurrentProjectID() + "/", response => {
this.result = this.$get("/api/automation/module/list/" + this.projectId + "/", response => {
if (response.data != undefined && response.data != null) {
this.data = response.data;
let moduleOptions = [];
@ -76,7 +75,7 @@ export default {
this.$refs.apiImport.open(this.currentModule);
break;
default:
if (!getCurrentProjectID()) {
if (!this.projectId) {
this.$warning(this.$t('commons.check_project_tip'));
return;
}

View File

@ -5,7 +5,9 @@
<div class="header-bar">
<div>{{ $t('api_test.api_import.data_format') }}</div>
<el-radio-group v-model="selectedPlatformValue">
<el-radio v-for="(item, index) in platforms" v-if="!isScenarioModel || item.name != 'Swagger'" :key="index" :label="item.value">{{ item.name }}</el-radio>
<span v-for="(item, index) in platforms" :key="index">
<el-radio v-if="!isScenarioModel || item.name != 'Swagger'" :label="item.value">{{ item.name }}</el-radio>
</span>
</el-radio-group>
<div class="operate-button">
@ -310,6 +312,10 @@ export default {
margin: 10px 0;
}
.el-radio {
margin-right: 20px;
}
.header-bar, .format-tip, .el-form {
border: solid #E1E1E1 1px;
margin: 10px 0;

View File

@ -192,7 +192,6 @@ import MsBatchEdit from "../basis/BatchEdit";
import {API_METHOD_COLOUR, API_STATUS, DUBBO_METHOD, REQ_METHOD, SQL_METHOD, TCP_METHOD} from "../../model/JsonData";
import {downloadFile, getCurrentProjectID} from "@/common/js/utils";
import {PROJECT_NAME, WORKSPACE_ID} from '@/common/js/constants';
import ApiListContainer from "./ApiListContainer";
import MsTableHeaderSelectPopover from "@/business/components/common/components/table/MsTableHeaderSelectPopover";
import ApiStatus from "@/business/components/api/definition/components/list/ApiStatus";
import MsTableAdvSearchBar from "@/business/components/common/components/search/MsTableAdvSearchBar";