add 设定对接人的权限
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package com.jero.util;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
|
||||
/**
|
||||
* 比对两个对象,输出变更字段
|
||||
* @author liJiaRao
|
||||
* @date 2021-09-22 17:05
|
||||
*/
|
||||
public class ObjRecordUtil {
|
||||
/**
|
||||
* @param oldObj 原数据对象
|
||||
* @param newObj 修改后数据对象
|
||||
* @return
|
||||
*/
|
||||
public static String addRecord(Object oldObj, Object newObj){
|
||||
try {
|
||||
// 得到类对象
|
||||
Class<?> class1 = oldObj.getClass();
|
||||
Class<?> class2 = newObj.getClass();
|
||||
if(!class1.equals(class2)){
|
||||
throw new RuntimeException("请传入两个相同的实体类对象");
|
||||
}
|
||||
// 得到属性集合
|
||||
Field[] fields1 = class1.getDeclaredFields();
|
||||
Field[] fields2 = class2.getDeclaredFields();
|
||||
StringBuilder info = new StringBuilder();
|
||||
Long id = null;
|
||||
for (Field field1 : fields1) {
|
||||
field1.setAccessible(true); // 设置属性是可以访问的(私有的也可以)
|
||||
if(id == null && field1.getName().equals("id")){
|
||||
id = (Long)field1.get(oldObj);
|
||||
}
|
||||
for (Field field2 : fields2) {
|
||||
field2.setAccessible(true); // 设置属性是可以访问的(私有的也可以)
|
||||
if(field1.equals(field2)){ // 比较属性名是否一样
|
||||
if(field2.get(newObj) == null || StringUtils.isEmpty(field2.get(newObj) + "")){
|
||||
break; // 属性名称一样就退出二级循环
|
||||
}
|
||||
if(!field1.get(oldObj).equals(field2.get(newObj))){ // 比较属性值是否一样
|
||||
// 得到注解
|
||||
ApiModelProperty pn = field1.getAnnotation(ApiModelProperty.class);
|
||||
if(pn != null){
|
||||
info.append(pn.value()).append(":\"").append(field1.get(oldObj)).append("\" 改成 \"").append(field2.get(newObj)).append("\",");
|
||||
}
|
||||
}
|
||||
break; // 属性名称一样就退出二级循环
|
||||
}
|
||||
}
|
||||
}
|
||||
if(info.length() != 0){
|
||||
// 设置日志信息
|
||||
return info.substring(0, info.length() - 1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user