fix(接口测试): 接口定义和场景用例首次添加标签后,变更历史的记录不变颜色

--user=郭雨琦 【接口测试】-接口定义和场景用例首次添加标签后,变更历史的记录不变颜色
This commit is contained in:
guoyuqi 2021-12-23 13:41:10 +08:00 committed by xiaomeinvG
parent 86758aef98
commit a8514fb774
1 changed files with 20 additions and 4 deletions

View File

@ -12,6 +12,7 @@ import io.metersphere.log.vo.DetailColumn;
import io.metersphere.log.vo.OperatingLogDetails; import io.metersphere.log.vo.OperatingLogDetails;
import io.metersphere.log.vo.StatusReference; import io.metersphere.log.vo.StatusReference;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.*; import java.util.*;
@ -19,6 +20,7 @@ import java.util.stream.Collectors;
public class ReflexObjectUtil { public class ReflexObjectUtil {
static final Gson gson = new GsonBuilder().setPrettyPrinting().create(); static final Gson gson = new GsonBuilder().setPrettyPrinting().create();
static final String DIFF_ADD = "++";
public static List<DetailColumn> getColumns(Object obj, Map<String, String> columns) { public static List<DetailColumn> getColumns(Object obj, Map<String, String> columns) {
List<DetailColumn> columnList = new LinkedList<>(); List<DetailColumn> columnList = new LinkedList<>();
@ -169,10 +171,7 @@ public class ReflexObjectUtil {
String diffStr = diff.diff(oldTags, newTags); String diffStr = diff.diff(oldTags, newTags);
diffValue = diff.apply(newTags, diffStr); diffValue = diff.apply(newTags, diffStr);
} else { } else {
int indexAdd = newTags.indexOf("["); diffValue = reviverJson(newTags, "root", DIFF_ADD);
String substring = newTags.substring(0, indexAdd + 2);
String substring1 = newTags.substring(indexAdd + 2);
diffValue = substring + "++" + substring1;
} }
column.setDiffValue(diffValue); column.setDiffValue(diffValue);
} }
@ -206,4 +205,21 @@ public class ReflexObjectUtil {
} }
return comparedColumns; return comparedColumns;
} }
private static String reviverJson(String str,String key,String option){
JSONObject obj = new JSONObject(str);
org.json.JSONArray arr = obj.getJSONArray(key);
for (int i = 0; i < arr.length(); i++) {
String s = arr.getString(i);
if(option.equals(DIFF_ADD)){
s = DIFF_ADD+s;
}
arr.put(i,s);
}
return obj.toString();
}
} }