From 1e2e80d50787381e181c978de2f3827e9fabd59b Mon Sep 17 00:00:00 2001 From: chenjianxing Date: Fri, 19 Feb 2021 14:37:25 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E5=9C=BA?= =?UTF-8?q?=E6=99=AF=E5=85=A8=E9=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ApiAutomationController.java | 2 +- .../automation/ApiScenarioBatchRequest.java | 21 +++++ .../dto/automation/ApiScenarioRequest.java | 10 +-- .../api/service/ApiAutomationService.java | 19 ++--- .../base/mapper/ext/ExtApiScenarioMapper.java | 3 + .../base/mapper/ext/ExtApiScenarioMapper.xml | 31 ++++--- .../api/automation/ApiAutomation.vue | 4 + .../automation/scenario/ApiScenarioList.vue | 82 +++++++++---------- .../automation/scenario/ApiScenarioModule.vue | 1 + .../module/ApiScenarioModuleHeader.vue | 9 +- .../components/import/ApiImport.vue | 8 +- .../definition/components/list/ApiList.vue | 1 - 12 files changed, 111 insertions(+), 80 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioBatchRequest.java 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 927a3a6c2c..54f73a0079 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiAutomationController.java @@ -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); } diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioBatchRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioBatchRequest.java new file mode 100644 index 0000000000..3840581f8b --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioBatchRequest.java @@ -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 ids; + private String projectId; + private String environmentId; + private String executeStatus; + private boolean notInTestPlan; + private String planId; + + private ApiScenarioRequest condition; +} diff --git a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java index 12b85d5a13..8034b6a573 100644 --- a/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java +++ b/backend/src/main/java/io/metersphere/api/dto/automation/ApiScenarioRequest.java @@ -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 moduleIds; private String name; - private String workspaceId; private String userId; private String planId; private boolean recent = false; - private List orders; - private Map> filters; - private Map combine; - private List ids; private boolean isSelectThisWeedData; private long createTime = 0; private String executeStatus; 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 4bb57218e2..7ad4ec20db 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -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 apiScenarios = selectByIdsWithBLOBs(request.getScenarioIds()); + List apiScenarios = selectByIdsWithBLOBs(request.getIds()); apiScenarios.forEach(item -> { JSONObject object = JSONObject.parseObject(item.getScenarioDefinition()); object.put("environmentId", request.getEnvironmentId()); 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 07ea9c380d..258706df46 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 @@ -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 selectIdsNotExistsInPlan(String projectId, String planId); ApiScenario getNextNum(@Param("projectId") String projectId); + + List selectIdsByQuery(@Param("request") ApiScenarioRequest request); } 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 7dce263d4f..3aa0322a8f 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 @@ -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 + + + + + @@ -144,8 +149,8 @@ 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},'%')) AND project.workspace_id = #{request.workspaceId} @@ -223,19 +228,13 @@ 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} ) - - order by - - api_scenario.${order.name} ${order.type} - - - + + + \ No newline at end of file diff --git a/frontend/src/business/components/api/automation/ApiAutomation.vue b/frontend/src/business/components/api/automation/ApiAutomation.vue index 8345b4a917..179eeadd3a 100644 --- a/frontend/src/business/components/api/automation/ApiAutomation.vue +++ b/frontend/src/business/components/api/automation/ApiAutomation.vue @@ -8,6 +8,7 @@ @setModuleOptions="setModuleOptions" @setNodeTree="setNodeTree" @enableTrash="enableTrash" + @exportAPI="exportAPI" :type="'edit'" ref="nodeTree"/> @@ -267,6 +268,9 @@ }, enableTrash(data) { this.trashEnable = data; + }, + exportAPI() { + this.$refs.apiScenarioList[0].exportApi(); } } } diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue index 7f3f94c983..8ff9bec445 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioList.vue @@ -9,7 +9,8 @@ @@ -24,7 +25,7 @@ @@ -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)); + }); + } } } diff --git a/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue b/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue index 9fd0ef46d9..d67f771493 100644 --- a/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue +++ b/frontend/src/business/components/api/automation/scenario/ApiScenarioModule.vue @@ -20,6 +20,7 @@ :condition="condition" :current-module="currentModule" :is-read-only="isReadOnly" + :project-id="projectId" @exportAPI="exportAPI" @addScenario="addScenario" @refreshTable="$emit('refreshTable')" diff --git a/frontend/src/business/components/api/automation/scenario/module/ApiScenarioModuleHeader.vue b/frontend/src/business/components/api/automation/scenario/module/ApiScenarioModuleHeader.vue index 3d3059d91d..b4b4b63f9d 100644 --- a/frontend/src/business/components/api/automation/scenario/module/ApiScenarioModuleHeader.vue +++ b/frontend/src/business/components/api/automation/scenario/module/ApiScenarioModuleHeader.vue @@ -21,7 +21,6 @@