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

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.github.pagehelper.PageHelper;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.web.modules.trading.domain.BizSupplier;
import com.ruoyi.web.modules.trading.mapper.BizSupplierMapper;

/**
 * 小程序供应商登录上下文。
 */
@Component
public class AppSupplierSessionSupport
{
    @Autowired
    private BizSupplierMapper bizSupplierMapper;

    public Long requireSupplierId()
    {
        Long userId = SecurityUtils.getUserId();
        if (userId == null)
        {
            throw new ServiceException(AppSupplierHomeRules.MSG_NO_SUPPLIER);
        }
        PageHelper.clearPage();
        BizSupplier row = bizSupplierMapper.selectBizSupplierBySysUserId(userId);
        if (row == null || row.getId() == null)
        {
            throw new ServiceException(AppSupplierHomeRules.MSG_NO_SUPPLIER);
        }
        return row.getId();
    }
}
