package com.gxwebsoft.credit.controller;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 导入解析辅助工具
 */
public final class ImportHelper {

    private ImportHelper() {
    }

    public static boolean isBlank(String value) {
        return value == null || value.trim().isEmpty();
    }

    public static BigDecimal parseBigDecimal(String value, String fieldLabel) {
        if (isBlank(value)) {
            return null;
        }
        try {
            return new BigDecimal(value.trim());
        } catch (Exception e) {
            throw new IllegalArgumentException(fieldLabel + "格式不正确");
        }
    }

    public static LocalDate parseLocalDate(String value, String fieldLabel) {
        if (isBlank(value)) {
            return null;
        }
        try {
            return LocalDate.parse(value.trim());
        } catch (Exception e) {
            throw new IllegalArgumentException(fieldLabel + "日期格式应为yyyy-MM-dd");
        }
    }
}
