|
|
@@ -3,6 +3,7 @@ package com.yc.ship.module.trade.utils;
|
|
|
import com.yc.ship.module.trade.framework.annotation.ForUpdate;
|
|
|
|
|
|
import java.lang.reflect.Field;
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
@@ -21,6 +22,9 @@ public class BeanUtils {
|
|
|
* @return
|
|
|
*/
|
|
|
public static <T> String getChangedFields(T newBean, T oldBean) {
|
|
|
+ if (newBean == null || oldBean == null) {
|
|
|
+ return "";
|
|
|
+ }
|
|
|
Field[] fields = newBean.getClass().getDeclaredFields();
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
for (Field field : fields) {
|
|
|
@@ -29,6 +33,11 @@ public class BeanUtils {
|
|
|
try {
|
|
|
Object newValue = field.get(newBean);
|
|
|
Object oldValue = field.get(oldBean);
|
|
|
+ if(newValue instanceof BigDecimal && oldValue instanceof BigDecimal) {
|
|
|
+ if(((BigDecimal) newValue).compareTo((BigDecimal) oldValue) == 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
if (!Objects.equals(newValue, oldValue)) {
|
|
|
//获取字段名称
|
|
|
builder.append(field.getAnnotation(ForUpdate.class).fieldName());
|