package com.threeclear.pollute.entity;
import java.lang.reflect.Field;
import java.util.Date;
import com.baomidou.mybatisplus.extension.activerecord.Model;
import lombok.Data;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
*
*
* @author makejava
* @since 2021-06-29 19:43:50
*/
@SuppressWarnings("serial")
@Data
public class RlGeneralIndustryEnterprise extends Model<RlGeneralIndustryEnterprise> {
public final static Map COLUMN = new HashMap();
{
COLUMN.put("id", "id");
COLUMN.put("name", "企业名");
COLUMN.put("address", "企业地址");
}
//id
// @TableId
private Long id;
//企业名
private String name;
//企业地址
private String address;
/**
* 获取主键值
*
* @return 主键值
*/
@Override
protected Serializable pkVal() {
return this.id;
}
public TGridOperationLog comparatorObject(String unityOperate, Object oldObj) throws IllegalAccessException {
StringBuilder matter = new StringBuilder();
StringBuilder contentOld = new StringBuilder();
StringBuilder contentNew = new StringBuilder();
if (oldObj != null&&"更新".equals(unityOperate)) {
Map<String, Object> oldMap = changeValueToMap(oldObj);
Map<String, Object> newMap = changeValueToMap(this);
if (oldMap != null && !oldMap.isEmpty()) {
for (Map.Entry<String, Object> entry : oldMap.entrySet()) {
Object oldValue = entry.getValue();
System.out.println("oldValue = " + oldValue);
Object newValue = newMap.get(entry.getKey());
System.out.println("newValue = " + newValue);
if ((oldValue != null&&!oldValue.equals(newValue))||(newValue != null && !newValue.equals(oldValue))) {
matter.append(entry.getKey()).append("、");
contentOld.append(oldValue).append("、");
contentNew.append(newValue).append("、");
}
}
}
matter.deleteCharAt(matter.length() - 1);
contentOld.deleteCharAt(contentOld.length() - 1);
contentNew.deleteCharAt(contentOld.length() - 1);
// matter.deleteCharAt(matter.length() - 1);
} else {
matter.append("-");
contentOld.append("-");
contentNew.append("-");
}
return TGridOperationLog.TGridOperationLogBuilder
.aTGridOperationLog()
// .withOperationTime()
.withSourceName(name)
.withOperationType(unityOperate)
.withAlterColumn(String.valueOf(matter))
.withBeforeModification(String.valueOf(contentOld))
.withAfterModification(String.valueOf(contentNew))
.build();
}
/**
* 将类对象转换成Map
*
* @param entity 原对象
* @return Map
* @throws IllegalAccessException 类型转换时报错
*/
private static Map<String, Object> changeValueToMap(Object entity) throws IllegalAccessException {
Map<String, Object> resultMap = new HashMap<>();
Field[] fields = entity.getClass().getDeclaredFields();
for (Field field : fields) {
String name = field.getName();
// if (PropertyUtils.isReadable(entity, name) && PropertyUtils.isWriteable(entity, name)) {
// if (field.isAnnotationPresent(LogCompar.class)) {
// LogCompar anno = field.getAnnotation(LogCompar.class);
// //获取private对象字段值
// field.setAccessible(true);
// resultMap.put(anno.name(), field.get(entity));
// }
// }
field.setAccessible(true);
resultMap.put((String) COLUMN.get(name), field.get(entity));
}
return resultMap;
}
}
更新字段差异 记录
最新推荐文章于 2022-11-04 15:51:10 发布