package com.zcloud.common.utils;

import com.zcloud.common.annotation.EntityProperty;
import io.swagger.annotations.ApiModelProperty;
import org.springframework.util.ObjectUtils;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * @author zhangyue
 * @date 2024/4/3 15:05
 */
public class BeanCompareUtils {
    public static String compareObjectsName(Object object1, Object object2) throws IllegalAccessException {

        Class<?> clazz = object1.getClass();

        if (!clazz.equals(object2.getClass())) {
            throw new IllegalArgumentException("The two objects should be of the same class");
        }

        Field[] fields = clazz.getDeclaredFields();
        StringBuffer result = new StringBuffer();
        for (Field field : fields) {
            field.setAccessible(true);
            Object value1 = field.get(object1);
            Object value2 = field.get(object2);
            ApiModelProperty annotation = field.getAnnotation(ApiModelProperty.class);
            // 获取value属性的值
            String name = annotation.value();
            if(!Objects.equals(value1,value2)){
                result.append(","+name);
            }
        }

        return result.toString();
    }
}
