From 18cc316657462276e6f43c1170d22301fe092d53 Mon Sep 17 00:00:00 2001 From: guoyuqi Date: Wed, 22 Dec 2021 20:48:01 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89=E5=92=8C=E5=9C=BA=E6=99=AF?= =?UTF-8?q?=E7=94=A8=E4=BE=8B=E6=B7=BB=E5=8A=A0=E6=A0=87=E7=AD=BE=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E5=8F=98=E6=9B=B4=E5=8E=86=E5=8F=B2=E4=B8=AD=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1009037 --user=郭雨琦 【ID1009037】【接口测试】-接口定义和场景用例添加标签后,变更历史中没有记录 --- .../log/utils/ReflexObjectUtil.java | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) 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 c8e795884a..256a1cded0 100644 --- a/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java +++ b/backend/src/main/java/io/metersphere/log/utils/ReflexObjectUtil.java @@ -153,16 +153,27 @@ public class ReflexObjectUtil { GsonDiff diff = new GsonDiff(); Object originalValue = originalColumns.get(i).getOriginalValue(); Object newValue = newColumns.get(i).getOriginalValue(); - List originalValueArray = JSON.parseArray(originalValue.toString(), String.class); + String oldTags = null; + if (originalValue != null && !StringUtils.equals("null", originalValue.toString())) { + List originalValueArray = JSON.parseArray(originalValue.toString(), String.class); + Collections.sort(originalValueArray); + Object originalObject = JSON.toJSON(originalValueArray); + oldTags = ApiDefinitionDiffUtil.JSON_START + ((originalColumns.get(i) != null && originalObject != null) ? originalObject.toString() : "\"\"") + ApiDefinitionDiffUtil.JSON_END; + } List newValueArray = JSON.parseArray(newValue.toString(), String.class); - Collections.sort(originalValueArray); Collections.sort(newValueArray); - Object originalObject = JSON.toJSON(originalValueArray); Object newObject = JSON.toJSON(newValueArray); - String oldTags = ApiDefinitionDiffUtil.JSON_START + ((originalColumns.get(i) != null && originalObject != null) ? originalObject.toString() : "\"\"") + ApiDefinitionDiffUtil.JSON_END; String newTags = ApiDefinitionDiffUtil.JSON_START + ((newColumns.get(i) != null && newObject != null) ? newObject.toString() : "\"\"") + ApiDefinitionDiffUtil.JSON_END; - String diffStr = diff.diff(oldTags, newTags); - String diffValue = diff.apply(newTags, diffStr); + String diffValue; + if (oldTags != null) { + String diffStr = diff.diff(oldTags, newTags); + diffValue = diff.apply(newTags, diffStr); + } else { + int indexAdd = newTags.indexOf("["); + String substring = newTags.substring(0, indexAdd + 2); + String substring1 = newTags.substring(indexAdd + 2); + diffValue = substring + "++" + substring1; + } column.setDiffValue(diffValue); } // 深度对比