Commit 157f5583 authored by suhuiguang's avatar suhuiguang

fix(大编辑):bug修复

1.json字段比较优化
parent be15dbb6
......@@ -72,6 +72,11 @@
<version>0.10.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<version>1.5.3</version>
</dependency>
</dependencies>
<build>
<plugins>
......
......@@ -2,6 +2,7 @@ package com.yeejoin.amos.boot.module.jg.biz.edit.process.equip;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.bean.copier.CopyOptions;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.text.CharSequenceUtil;
import com.alibaba.fastjson.JSON;
......@@ -46,6 +47,9 @@ import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.search.sort.SortOrder;
import org.json.JSONException;
import org.skyscreamer.jsonassert.JSONAssert;
import org.skyscreamer.jsonassert.JSONCompareMode;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.typroject.tyboot.core.foundation.context.RequestContext;
......@@ -127,6 +131,9 @@ public class CommonEquipDataProcessService {
public static final String BASE_COLUMN_REC_DATE = "\"REC_DATE\"";
public static final String BASE_COLUMN_REC_USERID = "\"REC_USER_ID\"";
private static final CopyOptions options = CopyOptions.create()
.setIgnoreNullValue(false).ignoreCase();
@PostConstruct
public void init() {
Set<Class<? extends IBaseChangeData>> subClasses = getAllSubClasses();
......@@ -153,7 +160,7 @@ public class CommonEquipDataProcessService {
}
public static <T extends IBaseChangeData> void castMap2Bean(Map<String, Object> map, T target) {
BeanUtil.copyProperties(JSON.parse(JSONObject.toJSONString(map)), target, true);
BeanUtil.copyProperties(JSON.parse(JSONObject.toJSONString(map)), target, options);
}
......@@ -685,8 +692,31 @@ public class CommonEquipDataProcessService {
FieldDisplayDefine displayDefine = field.getAnnotation(FieldDisplayDefine.class);
TableField tableField = field.getAnnotation(TableField.class);
// 业务字段对比处理逻辑
if (!Objects.equals(oldVal, newVal)) {
if (displayDefine != null && displayDefine.isExist()) {
if (displayDefine != null && displayDefine.isExist()) {
// json 比较逻辑
if (displayDefine.type().equals(JSON.class)) {
if (!isJsonEqualLoose((String) oldVal, (String) newVal)) {
String columnName = tableField.value();
wrapper.set(columnName, newVal);
String fieldName = displayDefine.value();
FieldChangeMeta fieldChangeMeta = new FieldChangeMeta();
fieldChangeMeta.setColumnKey(field.getName());
fieldChangeMeta.setColumnFamily(group.value());
fieldChangeMeta.setColumnLabel(fieldName);
fieldChangeMeta.setChangeId(changeId);
fieldChangeMeta.setIsRepeatColumn(displayDefine.isRepeatColumn());
// 字段类型前端渲染时使用
fieldChangeMeta.setColumnType(displayDefine.type().getSimpleName());
fieldChangeMeta.setColumnOldValue(Objects.toString(oldVal, ""));
fieldChangeMeta.setColumnNewValue(Objects.toString(newVal, ""));
fieldChangeMeta.setDisplayOldValue(formatService.format(displayDefine, fieldChangeMeta.getColumnOldValue()));
fieldChangeMeta.setDisplayNewValue(formatService.format(displayDefine, fieldChangeMeta.getColumnNewValue()));
changeData.add(fieldChangeMeta);
}
continue;
}
// 其他比较逻辑
if (!Objects.equals(oldVal, newVal)) {
String columnName = tableField.value();
wrapper.set(columnName, newVal);
String fieldName = displayDefine.value();
......@@ -717,6 +747,7 @@ public class CommonEquipDataProcessService {
}
}
} catch (IllegalAccessException e) {
System.err.println("字段访问失败: " + field.getName());
}
......@@ -734,6 +765,15 @@ public class CommonEquipDataProcessService {
return changeData;
}
public static boolean isJsonEqualLoose(String expectedJson, String actualJson) {
try {
JSONAssert.assertEquals(expectedJson, actualJson, JSONCompareMode.LENIENT);
return true;
} catch (Error | JSONException e) {
return false;
}
}
public Map<String, Object> getEquipDetailByRecord(String record) {
Map<String, Object> re = new HashMap<>();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment