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

import java.util.Locale;
import org.springframework.stereotype.Component;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.web.modules.trading.domain.BizSupplierSettlement;

/**
 * 供应商结算校验。
 */
@Component
public class SettlementValidation
{
    public void validateSettleVoucher(BizSupplierSettlement request)
    {
        if (request == null || request.getId() == null)
        {
            throw new ServiceException("结算单主键不能为空");
        }
        if (StringUtils.isEmpty(request.getSettleVoucherUrl())
                || StringUtils.isEmpty(request.getSettleVoucherPath()))
        {
            throw new ServiceException(SettlementRules.MSG_SETTLE_VOUCHER_REQUIRED);
        }
        String path = request.getSettleVoucherPath().toLowerCase(Locale.ROOT);
        if (!path.endsWith(".jpg") && !path.endsWith(".jpeg") && !path.endsWith(".png"))
        {
            throw new ServiceException(SettlementRules.MSG_SETTLE_VOUCHER_INVALID);
        }
    }
}
