package org.jeecg.ctop.material.utils;

import java.lang.reflect.Field;
import java.math.BigDecimal;

/**
 * Administrator
 * 2022/3/15
 **/
public class FeidNotNullUtils {


    public static void setFeidValueNotNull (Object obj) {
        try {
            for (Field field : obj.getClass().getDeclaredFields()) {
                field.setAccessible(true);
                if (field.get(obj) == null) {
                    if (field.getGenericType().toString().equals("class java.lang.String")) {
                        field.set(obj, "0");
                    } else if (field.getGenericType().toString().equals("class java.lang.Integer")) {
                        field.set(obj, 0);
                    } else if (field.getGenericType().toString().equals("class java.lang.Double")) {
                        field.set(obj, 0.0);
                    } else if (field.getGenericType().toString().equals("class java.lang.Long")) {
                        field.set(obj, 0L);
                    } else if (field.getGenericType().toString().equals("class java.math.BigDecimal")) {
                        field.set(obj, new BigDecimal(0));
                    }
                }
            }

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}