package com.yonge.cooleshow.portal.service.impl;

import com.github.pagehelper.PageHelper;
import com.yonge.cooleshow.mall.common.api.CommonPage;
import com.yonge.cooleshow.mbg.mapper.PmsBrandMapper;
import com.yonge.cooleshow.mbg.mapper.PmsProductMapper;
import com.yonge.cooleshow.mbg.model.PmsBrand;
import com.yonge.cooleshow.mbg.model.PmsProduct;
import com.yonge.cooleshow.mbg.model.PmsProductExample;
import com.yonge.cooleshow.portal.dao.HomeDao;
import com.yonge.cooleshow.portal.service.PortalBrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 前台品牌管理Service实现类
 * Created by macro on 2020/5/15.
 */
@Service
public class PortalBrandServiceImpl implements PortalBrandService {
    @Autowired
    private HomeDao homeDao;
    @Autowired
    private PmsBrandMapper brandMapper;
    @Autowired
    private PmsProductMapper productMapper;

    @Override
    public List<PmsBrand> recommendList(Integer pageNum, Integer pageSize) {
        int offset = (pageNum - 1) * pageSize;
        return homeDao.getRecommendBrandList(offset, pageSize);
    }

    @Override
    public PmsBrand detail(Long brandId) {
        return brandMapper.selectByPrimaryKey(brandId);
    }

    @Override
    public CommonPage<PmsProduct> productList(Long brandId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        PmsProductExample example = new PmsProductExample();
        example.createCriteria().andDeleteStatusEqualTo(0)
                .andBrandIdEqualTo(brandId);
        List<PmsProduct> productList = productMapper.selectByExample(example);
        return CommonPage.restPage(productList);
    }
}
