package com.cmvr.device.util;

import com.cmvr.device.domain.vo.TeMechanicalArmVo;

import java.lang.reflect.Field;

public class VoUtil {
    /**
     * 获取TeMechanicalArmVo对象中除设备ID外的非空属性名
     * @param vo TeMechanicalArmVo对象
     * @return 非空属性名，如果没有则返回null
     */
    public static String getNonNullPropertyName(TeMechanicalArmVo vo) {
        if (vo == null) return null;

        try {
            for (Field field : TeMechanicalArmVo.class.getDeclaredFields()) {
                if ("idDeDeviceRegistration".equals(field.getName())) continue;

                field.setAccessible(true);
                Object value = field.get(vo);

                // 排除null和空字符串
                if (value instanceof String) {
                    if (!((String) value).trim().isEmpty()) {
                        return field.getName();
                    }
                } else if (value != null) {
                    return field.getName();
                }
            }
        } catch (IllegalAccessException e) {
            throw new RuntimeException("获取属性值失败", e);
        }

        return null;
    }
}