From 401e317238c78813b80ae352cbbfcdc5888c95a6 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Sat, 23 Jul 2022 12:23:37 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E4=BF=9D=E5=AD=98=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --user=郭雨琦 --bug=1015217 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001015217 --bug=1015215 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001015215 --- .../controller/ApiDefinitionController.java | 13 ++- .../api/service/ApiDefinitionService.java | 6 -- .../complete/EditCompleteHTTPApi.vue | 89 ++++++++++++------- .../components/list/ApiCaseSimpleList.vue | 6 +- .../api/definition/util/SyncSetting.vue | 61 +++++++++++++ 5 files changed, 128 insertions(+), 47 deletions(-) create mode 100644 frontend/src/business/components/api/definition/util/SyncSetting.vue diff --git a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java index b1bb26169f..e0a331eb36 100644 --- a/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java +++ b/backend/src/main/java/io/metersphere/api/controller/ApiDefinitionController.java @@ -13,10 +13,7 @@ import io.metersphere.api.dto.scenario.Body; import io.metersphere.api.dto.swaggerurl.SwaggerTaskResult; import io.metersphere.api.dto.swaggerurl.SwaggerUrlRequest; import io.metersphere.api.exec.queue.ExecThreadPoolExecutor; -import io.metersphere.api.service.ApiDefinitionService; -import io.metersphere.api.service.ApiTestEnvironmentService; -import io.metersphere.api.service.EsbApiParamService; -import io.metersphere.api.service.EsbImportService; +import io.metersphere.api.service.*; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; import io.metersphere.base.domain.Schedule; import io.metersphere.commons.constants.NoticeConstants; @@ -51,6 +48,8 @@ public class ApiDefinitionController { @Resource private ApiDefinitionService apiDefinitionService; @Resource + private ApiTestCaseService apiTestCaseService; + @Resource private CheckPermissionService checkPermissionService; @Resource private EsbApiParamService esbApiParamService; @@ -64,6 +63,12 @@ public class ApiDefinitionController { @PostMapping("/list/{goPage}/{pageSize}") @RequiresPermissions("PROJECT_API_DEFINITION:READ") public Pager> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody ApiDefinitionRequest request) { + if (request.getToBeUpdated() != null && request.getToBeUpdated()) { + Long toBeUpdatedTime = apiTestCaseService.getToBeUpdatedTime(request.getProjectId()); + if (toBeUpdatedTime != null) { + request.setToBeUpdateTime(toBeUpdatedTime); + } + } Page page = PageHelper.startPage(goPage, pageSize, true); return PageUtils.setPageInfo(page, apiDefinitionService.list(request)); } 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 7abb08f41a..e9f224d76d 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiDefinitionService.java @@ -170,12 +170,6 @@ public class ApiDefinitionService { public List list(ApiDefinitionRequest request) { request = this.initRequest(request, true, true); - if (request.getToBeUpdated() != null && request.getToBeUpdated()) { - Long toBeUpdatedTime = apiTestCaseService.getToBeUpdatedTime(request.getProjectId()); - if (toBeUpdatedTime != null) { - request.setToBeUpdateTime(toBeUpdatedTime); - } - } List resList = extApiDefinitionMapper.list(request); buildUserInfo(resList); if (StringUtils.isNotBlank(request.getProjectId())) { diff --git a/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue b/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue index eeeede915d..0917b60856 100644 --- a/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue +++ b/frontend/src/business/components/api/definition/components/complete/EditCompleteHTTPApi.vue @@ -192,7 +192,7 @@ {{ $t('workstation.sync') + $t('commons.setting') }}
- +
@@ -235,8 +235,8 @@ import {createComponent} from ".././jmeter/components"; import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting"; import MsDialogFooter from "@/business/components/common/components/MsDialogFooter"; import {getProjectMemberOption} from "@/network/user"; -import SyncSettings from "@/business/components/xpack/workstation/component/SyncSettings"; import {deepClone} from "@/common/js/tableUtils"; +import SyncSetting from "@/business/components/api/definition/util/SyncSetting"; const {Body} = require("@/business/components/api/definition/model/ApiTestModel"); const Sampler = require("@/business/components/api/definition/components/jmeter/components/sampler/sampler"); @@ -252,7 +252,7 @@ export default { ApiOtherInfo, MsFormDivider, MsJsr233Processor, MsResponseText, MsApiRequestForm, MsInputTag, MsSelectTree, MsChangeHistory, - HttpApiVersionDiff, SyncSettings, + HttpApiVersionDiff, SyncSetting, }, data() { let validateURL = (rule, value, callback) => { @@ -284,7 +284,7 @@ export default { }, httpForm: {environmentId: "", path: "", tags: []}, beforeHttpForm: {environmentId: "", path: "", tags: []}, - beforeRequest: {}, + beforeRequest: {arguments: []}, beforeResponse: {}, newData: {environmentId: "", path: "", tags: []}, dialogVisible: false, @@ -311,7 +311,8 @@ export default { syncCases: true, specialReceivers: false, caseCreator: false, - scenarioCreator: false + scenarioCreator: false, + apiSyncCaseRequest: {}, }; }, @@ -521,40 +522,52 @@ export default { } } if (hasLicense() && this.httpForm.caseTotal > 0) { - if (this.httpForm.name !== this.beforeHttpForm.name) { - this.batchSyncApiVisible = true; + + if (this.apiSyncCaseRequest && this.apiSyncCaseRequest.method) { + if (this.httpForm.method !== this.beforeHttpForm.method) { + this.batchSyncApiVisible = true; + } } - if (this.httpForm.method !== this.beforeHttpForm.method) { - this.batchSyncApiVisible = true; + if (this.apiSyncCaseRequest && this.apiSyncCaseRequest.path) { + if (this.httpForm.path !== this.beforeHttpForm.path) { + this.batchSyncApiVisible = true; + } } - if (this.httpForm.path !== this.beforeHttpForm.path) { - this.batchSyncApiVisible = true; + if (this.apiSyncCaseRequest && this.apiSyncCaseRequest.headers) { + if (this.request.headers && this.beforeRequest.headers) { + let submitRequestHeaders = JSON.stringify(this.request.headers); + let beforeRequestHeaders = JSON.stringify(this.beforeRequest.headers); + if (submitRequestHeaders !== beforeRequestHeaders) { + this.batchSyncApiVisible = true; + } + } } - if (this.httpForm.userId !== this.beforeHttpForm.userId) { - this.batchSyncApiVisible = true; + if (this.apiSyncCaseRequest && this.apiSyncCaseRequest.query) { + if (this.request.arguments && this.beforeRequest.arguments) { + let submitRequestQuery = JSON.stringify(this.request.arguments); + let beforeRequestQuery = JSON.stringify(this.beforeRequest.arguments); + if (submitRequestQuery !== beforeRequestQuery) { + this.batchSyncApiVisible = true; + } + } } - if (this.httpForm.moduleId !== this.beforeHttpForm.moduleId) { - this.batchSyncApiVisible = true; + if (this.apiSyncCaseRequest && this.apiSyncCaseRequest.rest) { + if (this.request.rest && this.beforeRequest.rest) { + let submitRequestRest = JSON.stringify(this.request.rest); + let beforeRequestRest = JSON.stringify(this.beforeRequest.rest); + if (submitRequestRest !== beforeRequestRest) { + this.batchSyncApiVisible = true; + } + } } - if (this.httpForm.status !== this.beforeHttpForm.status) { - this.batchSyncApiVisible = true; - } - if (!this.beforeHttpForm.tags) { - this.beforeHttpForm.tags = []; - this.beforeHttpForm.tags = JSON.stringify(this.beforeHttpForm.tags) - } - if (this.httpForm.tags !== this.beforeHttpForm.tags) { - this.batchSyncApiVisible = true; - } - let submitRequest = JSON.stringify(this.request); - let beforeRequestHeaders = JSON.stringify(this.beforeRequest); - if (submitRequest !== beforeRequestHeaders) { - this.batchSyncApiVisible = true; - } - let submitResponse = JSON.stringify(this.response); - let beforeResponse = JSON.stringify(this.response); - if (submitResponse !== beforeResponse) { - this.batchSyncApiVisible = true; + if (this.apiSyncCaseRequest && this.apiSyncCaseRequest.body) { + if (this.request.body && this.beforeRequest.body) { + let submitRequestBody = JSON.stringify(this.request.body); + let beforeRequestBody = JSON.stringify(this.beforeRequest.body); + if (submitRequestBody !== beforeRequestBody) { + this.batchSyncApiVisible = true; + } + } } if (this.batchSyncApiVisible !== true) { this.$emit('saveApi', this.httpForm); @@ -851,10 +864,18 @@ export default { } }); }, + getApplication() { + this.$get('/project_application/get/config/' + this.projectId + "/TRIGGER_UPDATE", res => { + if (res.data && res.data.triggerUpdate) { + this.apiSyncCaseRequest = JSON.parse(res.data.triggerUpdate); + } + }); + } }, created() { this.getMaintainerOptions(); + this.getApplication(); if (!this.basisData.environmentId) { this.basisData.environmentId = ""; } diff --git a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue index a52d70e9fb..c08100c0b3 100644 --- a/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue +++ b/frontend/src/business/components/api/definition/components/list/ApiCaseSimpleList.vue @@ -252,7 +252,7 @@ {{ $t('workstation.sync') + $t('commons.setting') }}
- + {{ $t('workstation.batch_sync_api_tips') }} 取 消 @@ -308,7 +308,7 @@ import {editApiTestCaseOrder} from "@/network/api"; import {TYPE_TO_C} from "@/business/components/api/automation/scenario/Setting"; import i18n from "@/i18n/i18n"; import MsSearch from "@/business/components/common/components/search/MsSearch"; -import SyncSettings from "@/business/components/xpack/workstation/component/SyncSettings"; +import SyncSetting from "@/business/components/api/definition/util/SyncSetting"; export default { name: "ApiCaseSimpleList", @@ -336,7 +336,7 @@ export default { MsRequestResultTail, MsApiCaseRunModeWithEnv, MsSearch, - SyncSettings, + SyncSetting, PlanStatusTableItem: () => import("../../../../track/common/tableItems/plan/PlanStatusTableItem"), MsTaskCenter: () => import("@/business/components/task/TaskCenter"), }, diff --git a/frontend/src/business/components/api/definition/util/SyncSetting.vue b/frontend/src/business/components/api/definition/util/SyncSetting.vue new file mode 100644 index 0000000000..8980860490 --- /dev/null +++ b/frontend/src/business/components/api/definition/util/SyncSetting.vue @@ -0,0 +1,61 @@ + + + + + +