package com.ruoyi.web.modules.industryservice.support;

import java.math.BigDecimal;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.industryservice.domain.BizDisposableIncome;

/**
 * 可支配收入数据填报校验
 */
public final class DisposableIncomeValidation
{
    private DisposableIncomeValidation()
    {
    }

    public static void validateRowForSave(BizDisposableIncome row)
    {
        if (row == null)
        {
            throw new ServiceException("参数不能为空");
        }
        if (row.getStatYear() == null)
        {
            throw new ServiceException("所属年份不能为空");
        }
        if (!YakHerdInventoryYearSupport.isAllowedYear(row.getStatYear()))
        {
            throw new ServiceException("所属年份不在可选范围内");
        }
        if (row.getRuralDisposableIncome() == null)
        {
            throw new ServiceException("农村居民人均可支配收入不能为空");
        }
        if (row.getRuralDisposableIncome().compareTo(BigDecimal.ZERO) < 0)
        {
            throw new ServiceException("农村居民人均可支配收入不能为负数");
        }
        if (row.getPovertyNetIncome() == null)
        {
            throw new ServiceException("脱贫人口人均纯收入不能为空");
        }
        if (row.getPovertyNetIncome().compareTo(BigDecimal.ZERO) < 0)
        {
            throw new ServiceException("脱贫人口人均纯收入不能为负数");
        }
        // 增幅、增速可选填，无额外必填约束
        if (StringUtils.isNotEmpty(row.getRemark()) && row.getRemark().length() > 500)
        {
            throw new ServiceException("备注不能超过500字");
        }
    }
}
