11 changed files with 382 additions and 0 deletions
@ -0,0 +1,39 @@ |
|||
package cc.hiver.core.logisticsorder.entity; |
|||
|
|||
import cc.hiver.core.base.HiverBaseEntity; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.math.BigDecimal; |
|||
|
|||
/** |
|||
* 物流中转实体 |
|||
* |
|||
* @author 王富康 |
|||
* @date 2024/8/24 |
|||
*/ |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
@ApiModel(value = "物流订单修改记录表") |
|||
@TableName(value = "t_logistics_order_change_log", autoResultMap = true) |
|||
public class LogisticsOrderChangeLog extends HiverBaseEntity { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "订单ID") |
|||
private String orderId; |
|||
|
|||
@ApiModelProperty(value = "修改前数据") |
|||
private String oldData; |
|||
|
|||
@ApiModelProperty(value = "修改后数据") |
|||
private String newData; |
|||
|
|||
@ApiModelProperty(value = "修改人姓名") |
|||
private String createByName; |
|||
|
|||
|
|||
} |
|||
@ -0,0 +1,18 @@ |
|||
package cc.hiver.core.logisticsorder.vo; |
|||
|
|||
import java.lang.annotation.ElementType; |
|||
import java.lang.annotation.Retention; |
|||
import java.lang.annotation.RetentionPolicy; |
|||
import java.lang.annotation.Target; |
|||
|
|||
/** |
|||
* 对比属性 |
|||
* |
|||
* @author qiaohui |
|||
* @createTime 2024-09-09 22:49:15 |
|||
*/ |
|||
@Target(ElementType.FIELD) |
|||
@Retention(RetentionPolicy.RUNTIME) |
|||
public @interface CompareField { |
|||
String name() default ""; |
|||
} |
|||
@ -0,0 +1,89 @@ |
|||
package cc.hiver.core.logisticsorder.vo; |
|||
|
|||
import java.beans.PropertyDescriptor; |
|||
import java.lang.reflect.Field; |
|||
import java.lang.reflect.Method; |
|||
import java.math.BigDecimal; |
|||
import java.util.ArrayList; |
|||
import java.util.List; |
|||
import java.util.Objects; |
|||
|
|||
/** |
|||
* 比较对象的不同属性值 |
|||
* |
|||
* @author qiaohui |
|||
* @createTime 2024-09-09 22:49:26 |
|||
*/ |
|||
public class CompareObjectUtils<T> { |
|||
|
|||
public List<DiffAttr> CompareObjWithAnnotation(Object oldBean, Object newBean) { |
|||
|
|||
List<DiffAttr> attrList = new ArrayList<>(); |
|||
|
|||
T pojo1 = (T) oldBean; |
|||
T pojo2 = (T) newBean; |
|||
|
|||
try { |
|||
Class clazz = pojo1.getClass(); |
|||
Field[] fields = pojo1.getClass().getDeclaredFields(); |
|||
for (Field field : fields) { |
|||
boolean hasAnnotion = field.isAnnotationPresent(CompareField.class); |
|||
if (!hasAnnotion) { |
|||
continue; |
|||
} |
|||
PropertyDescriptor pd = new PropertyDescriptor(field.getName(), clazz); |
|||
Method getMethod = pd.getReadMethod(); |
|||
|
|||
Object o1 = getMethod.invoke(pojo1); |
|||
Object o2 = getMethod.invoke(pojo2); |
|||
if (Objects.isNull(o1) && Objects.isNull(o2)) { |
|||
continue; |
|||
} |
|||
|
|||
String oldVal = Objects.nonNull(o1) ? o1.toString() : ""; |
|||
String newVal = Objects.nonNull(o2) ? o2.toString() : ""; |
|||
|
|||
if(isBigDecimal(oldVal) && isBigDecimal(newVal)){ |
|||
if(new BigDecimal(oldVal).compareTo(new BigDecimal(newVal)) == 0){ |
|||
continue; |
|||
} |
|||
} |
|||
|
|||
if (oldVal.equals(newVal)) { |
|||
continue; |
|||
} |
|||
CompareField compareField = field.getAnnotation(CompareField.class); |
|||
DiffAttr diffAttr = new DiffAttr(compareField.name(), oldVal, newVal); |
|||
attrList.add(diffAttr); |
|||
} |
|||
} catch (Exception e) { |
|||
attrList = null; |
|||
} finally { |
|||
return attrList; |
|||
} |
|||
} |
|||
|
|||
public static boolean isBigDecimal(String str){ |
|||
if(str==null || str.trim().length() == 0){ |
|||
return false; |
|||
} |
|||
char[] chars = str.toCharArray(); |
|||
int sz = chars.length; |
|||
int i = (chars[0] == '-') ? 1 : 0; |
|||
if(i == sz) return false; |
|||
|
|||
if(chars[i] == '.') return false;//除了负号,第一位不能为'小数点'
|
|||
|
|||
boolean radixPoint = false; |
|||
for(; i < sz; i++){ |
|||
if(chars[i] == '.'){ |
|||
if(radixPoint) return false; |
|||
radixPoint = true; |
|||
}else if(!(chars[i] >= '0' && chars[i] <= '9')){ |
|||
return false; |
|||
} |
|||
} |
|||
return true; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,47 @@ |
|||
package cc.hiver.core.logisticsorder.vo; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* |
|||
* @author qiaohui |
|||
* @createTime 2024-09-09 22:50:45 |
|||
*/ |
|||
public class DiffAttr implements Serializable { |
|||
private String name; |
|||
private String oldVal; |
|||
private String newVal; |
|||
|
|||
public DiffAttr() { |
|||
} |
|||
|
|||
public DiffAttr(String name, String oldVal, String newVal) { |
|||
this.name = name; |
|||
this.oldVal = oldVal; |
|||
this.newVal = newVal; |
|||
} |
|||
|
|||
public String getName() { |
|||
return name; |
|||
} |
|||
|
|||
public void setName(String name) { |
|||
this.name = name; |
|||
} |
|||
|
|||
public String getOldVal() { |
|||
return oldVal; |
|||
} |
|||
|
|||
public void setOldVal(String oldVal) { |
|||
this.oldVal = oldVal; |
|||
} |
|||
|
|||
public String getNewVal() { |
|||
return newVal; |
|||
} |
|||
|
|||
public void setNewVal(String newVal) { |
|||
this.newVal = newVal; |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
package cc.hiver.core.logisticsorder.vo; |
|||
|
|||
import cc.hiver.core.base.HiverBaseEntity; |
|||
import com.baomidou.mybatisplus.annotation.TableName; |
|||
import io.swagger.annotations.ApiModel; |
|||
import io.swagger.annotations.ApiModelProperty; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
|
|||
import java.util.List; |
|||
|
|||
/** |
|||
* 返回给前端修改记录 |
|||
* |
|||
* @author qiaohui |
|||
* @date 2024-09-09 22:55:25 |
|||
*/ |
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
public class LogisticsOrderChangeLogVo extends HiverBaseEntity { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
@ApiModelProperty(value = "订单ID") |
|||
private String orderId; |
|||
|
|||
@ApiModelProperty(value = "修改人姓名") |
|||
private String createByName; |
|||
|
|||
@ApiModelProperty(value = "修改内容") |
|||
private List<DiffAttr> diffAttrList; |
|||
} |
|||
Loading…
Reference in new issue