From f0ea497d0dbd0347cf7c11b7e4c8d1d1ab0caa15 Mon Sep 17 00:00:00 2001 From: junhong Date: Mon, 14 Feb 2022 17:37:39 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E7=B3=BB=E7=BB=9F=E8=AE=BE=E7=BD=AE):=20?= =?UTF-8?q?=E5=85=A8=E5=B1=80=E5=89=8D=E5=90=8E=E7=BD=AE=E8=84=9A=E6=9C=AC?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=8F=98=E6=9B=B4=E5=8E=86=E5=8F=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --story=1005618 --user=周骏弘 全局前后置脚本新增变更历史 https://www.tapd.cn/55049933/s/1103617 --- .../log/utils/ApiTestEnvironmentDiffUtil.java | 58 ++++++++++ .../log/utils/ReflexObjectUtil.java | 13 ++- .../environment/EnvironmentEdit.vue | 29 ++++- .../components/history/ChangeHistory.vue | 30 ++++- .../history/api/EnvironmentEditParams.vue | 107 ++++++++++++++++++ .../history/api/EnvironmentHistoryDetail.vue | 84 ++++++++++++++ .../workspace/environment/EnvironmentList.vue | 15 ++- frontend/src/i18n/en-US.js | 1 + frontend/src/i18n/zh-CN.js | 1 + frontend/src/i18n/zh-TW.js | 1 + 10 files changed, 325 insertions(+), 14 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/log/utils/ApiTestEnvironmentDiffUtil.java create mode 100644 frontend/src/business/components/history/api/EnvironmentEditParams.vue create mode 100644 frontend/src/business/components/history/api/EnvironmentHistoryDetail.vue diff --git a/backend/src/main/java/io/metersphere/log/utils/ApiTestEnvironmentDiffUtil.java b/backend/src/main/java/io/metersphere/log/utils/ApiTestEnvironmentDiffUtil.java new file mode 100644 index 0000000000..0af8a155a3 --- /dev/null +++ b/backend/src/main/java/io/metersphere/log/utils/ApiTestEnvironmentDiffUtil.java @@ -0,0 +1,58 @@ +package io.metersphere.log.utils; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONObject; +import io.metersphere.commons.utils.LogUtil; +import org.apache.commons.lang3.StringUtils; +import java.util.LinkedHashMap; +import java.util.Map; + +public class ApiTestEnvironmentDiffUtil { + + public static String diff(String newValue, String oldValue) { + try { + JSONObject bloBsNew = JSON.parseObject(newValue); + JSONObject bloBsOld = JSON.parseObject(oldValue); + + Map diffMap = new LinkedHashMap<>(); + diffMap.put("type", "preAndPostScript"); + + // 对比全局脚本配置参数 + if (!StringUtils.equals(bloBsNew.getString("globalScriptConfig"), bloBsOld.getString("globalScriptConfig"))) { + diffMap.put("globalScriptConfigRaw1", bloBsNew.getString("globalScriptConfig")); + diffMap.put("globalScriptConfigRaw2", bloBsOld.getString("globalScriptConfig")); + } + + // 对比全局前置脚本(单个请求) + if (!StringUtils.equals(bloBsNew.getString("preProcessor"), bloBsOld.getString("preProcessor"))) { + diffMap.put("preProcessorRaw1", bloBsNew.getString("preProcessor")); + diffMap.put("preProcessorRaw2", bloBsOld.getString("preProcessor")); + } + + // 对比全局前置脚本(所有请求) + if (!StringUtils.equals(bloBsNew.getString("preStepProcessor"), bloBsOld.getString("preStepProcessor"))) { + diffMap.put("preStepProcessorRaw1", bloBsNew.getString("preStepProcessor")); + diffMap.put("preStepProcessorRaw2", bloBsOld.getString("preStepProcessor")); + } + + // 对比全局后置脚本(单个请求) + if (!StringUtils.equals(bloBsNew.getString("postProcessor"), bloBsOld.getString("postProcessor"))) { + diffMap.put("postProcessorRaw1", bloBsNew.getString("postProcessor")); + diffMap.put("postProcessorRaw2", bloBsOld.getString("postProcessor")); + } + + // 对比全局后置脚本(所有请求) + if (!StringUtils.equals(bloBsNew.getString("postStepProcessor"), bloBsOld.getString("postStepProcessor"))) { + diffMap.put("postStepProcessorRaw1", bloBsNew.getString("postStepProcessor")); + diffMap.put("postStepProcessorRaw2", bloBsOld.getString("postStepProcessor")); + } + + if (diffMap.size() > 1) { + return JSON.toJSONString(diffMap); + } + } catch (Exception e) { + LogUtil.error(e); + } + return null; + } +} diff --git a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java index 155ef5f6dc..71ed4698a6 100644 --- a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java @@ -186,8 +186,17 @@ public class ReflexObjectUtil { String oldValue = column.getOriginalValue().toString(); column.setDiffValue(ApiDefinitionDiffUtil.diffResponse(newValue, oldValue)); } - } else { - String newValue = Objects.toString(column.getNewValue(), ""); + } + // 环境全局前后置脚本深度对比 + else if(StringUtils.equals(module, "PROJECT_ENVIRONMENT_SETTING")){ + if (originalColumns.get(i).getColumnName().equals("config")) { + String newValue = newColumns.get(i).getOriginalValue().toString(); + String oldValue = column.getOriginalValue().toString(); + column.setDiffValue(ApiTestEnvironmentDiffUtil.diff(newValue, oldValue)); + } + } + else { + String newValue = column.getNewValue().toString(); if (StringUtils.isNotEmpty(newValue)) { column.setNewValue(newValue.replaceAll("\\n", " ")); } diff --git a/frontend/src/business/components/api/test/components/environment/EnvironmentEdit.vue b/frontend/src/business/components/api/test/components/environment/EnvironmentEdit.vue index 164f462d2e..8cad79be4d 100644 --- a/frontend/src/business/components/api/test/components/environment/EnvironmentEdit.vue +++ b/frontend/src/business/components/api/test/components/environment/EnvironmentEdit.vue @@ -30,6 +30,11 @@ :is-read-only="isReadOnly"/> +
+ + {{ $t('operating_log.change_history') }} + +
+
+ + {{ $t('operating_log.change_history') }} + +
- + + + + + + @@ -103,6 +114,8 @@ import Jsr233ProcessorContent from "@/business/components/api/automation/scenari import {createComponent} from "@/business/components/api/definition/components/jmeter/components"; import EnvironmentGlobalScript from "@/business/components/api/test/components/environment/EnvironmentGlobalScript"; import GlobalAssertions from "@/business/components/api/definition/components/assertion/GlobalAssertions"; +import MsChangeHistory from "../../../../history/ChangeHistory"; +import MsDialogHeader from "../../../../common/components/MsDialogHeader"; export default { name: "EnvironmentEdit", @@ -115,7 +128,8 @@ export default { MsEnvironmentHttpConfig, MsEnvironmentSSLConfig, EnvironmentGlobalScript, - MsDatabaseConfig, MsApiHostTable, MsDialogFooter, MsApiKeyValue, MsApiScenarioVariables + MsDatabaseConfig, MsApiHostTable, MsDialogFooter, MsApiKeyValue, MsApiScenarioVariables, MsChangeHistory, + MsDialogHeader }, props: { environment: new Environment(), @@ -269,6 +283,9 @@ export default { } }); }, + openHis() { + this.$refs.changeHistory.open(this.environment.id, ["项目-环境设置", "項目-環境設置", "Project environment setting"]); + }, validate() { let isValidate = false; this.$refs['environment'].validate((valid) => { diff --git a/frontend/src/business/components/history/ChangeHistory.vue b/frontend/src/business/components/history/ChangeHistory.vue index 859362cb72..f231ae0041 100644 --- a/frontend/src/business/components/history/ChangeHistory.vue +++ b/frontend/src/business/components/history/ChangeHistory.vue @@ -49,16 +49,18 @@ + + + diff --git a/frontend/src/business/components/history/api/EnvironmentHistoryDetail.vue b/frontend/src/business/components/history/api/EnvironmentHistoryDetail.vue new file mode 100644 index 0000000000..85e60ca3ae --- /dev/null +++ b/frontend/src/business/components/history/api/EnvironmentHistoryDetail.vue @@ -0,0 +1,84 @@ + + + + + diff --git a/frontend/src/business/components/settings/workspace/environment/EnvironmentList.vue b/frontend/src/business/components/settings/workspace/environment/EnvironmentList.vue index 2ccd967d39..1121401b97 100644 --- a/frontend/src/business/components/settings/workspace/environment/EnvironmentList.vue +++ b/frontend/src/business/components/settings/workspace/environment/EnvironmentList.vue @@ -63,7 +63,12 @@ - + + @@ -138,6 +143,7 @@ import EnvironmentImport from "@/business/components/project/menu/EnvironmentImp import ShowMoreBtn from "@/business/components/track/case/components/ShowMoreBtn"; import {_handleSelect, _handleSelectAll, getSelectDataCounts, setUnSelectIds} from "@/common/js/tableUtils"; import EnvGroupCascader from "@/business/components/settings/workspace/environment/EnvGroupCascader"; +import MsDialogHeader from "../../../common/components/MsDialogHeader"; export default { name: "EnvironmentList", @@ -154,7 +160,8 @@ export default { MsTableOperator, MsTableButton, MsTableHeader, - ShowMoreBtn + ShowMoreBtn, + MsDialogHeader }, data() { return { @@ -308,7 +315,9 @@ export default { this.currentEnvironment = temEnv; this.dialogVisible = true; }, - + save(){ + this.$refs.environmentEdit.save(); + }, copyEnv(environment) { this.currentProjectId = environment.projectId; //复制时默认选择所要复制环境对应的项目 this.dialogTitle = this.$t('api_test.environment.copy_environment'); diff --git a/frontend/src/i18n/en-US.js b/frontend/src/i18n/en-US.js index e96d75efc3..87315c485c 100644 --- a/frontend/src/i18n/en-US.js +++ b/frontend/src/i18n/en-US.js @@ -1849,6 +1849,7 @@ export default { before_the_pre_script_step: "Before pre-script in step", after_the_post_script_step: "After the script is placed in the step", before_the_post_script_step: "Post-in-step before script", + global_script_config: "Global script config", } }, api_report: { diff --git a/frontend/src/i18n/zh-CN.js b/frontend/src/i18n/zh-CN.js index 629ea4edb4..7724e8624b 100644 --- a/frontend/src/i18n/zh-CN.js +++ b/frontend/src/i18n/zh-CN.js @@ -1854,6 +1854,7 @@ export default { before_the_pre_script_step: "步骤内前置脚本前", after_the_post_script_step: "步骤内后置脚本后", before_the_post_script_step: "步骤内后置脚本前", + global_script_config: "全局脚本配置", } }, api_report: { diff --git a/frontend/src/i18n/zh-TW.js b/frontend/src/i18n/zh-TW.js index 81516a1bea..62e71ac9c0 100644 --- a/frontend/src/i18n/zh-TW.js +++ b/frontend/src/i18n/zh-TW.js @@ -1854,6 +1854,7 @@ export default { before_the_pre_script_step: "步驟內前置腳本前", after_the_post_script_step: "步驟內後置腳本後", before_the_post_script_step: "步驟內後置腳本前", + global_script_config: "全局腳本配置", } }, api_report: {