package com.fzm.mall.server.front.goods.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fzm.mall.server.front.goods.mapper.MarketingCouponMapper;
import com.fzm.mall.server.front.goods.mapper.MarketingPromotionMapper;
import com.fzm.mall.server.front.goods.model.Spu;
import com.fzm.mall.server.front.goods.mapper.SpuMapper;
import com.fzm.mall.server.front.goods.model.vo.GoodsVo;
import com.fzm.mall.server.front.goods.model.vo.PageVoWithOne;
import com.fzm.mall.server.front.goods.model.vo.SaleHotVo;
import com.fzm.mall.server.front.goods.model.vo.SearchVo;
import com.fzm.mall.server.front.goods.service.ISpuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 商品表 服务实现类
 * </p>
 *
 * @author fzm
 * @since 2021-03-09
 */
@Service
public class SpuServiceImpl extends ServiceImpl<SpuMapper, Spu> implements ISpuService {

    @Autowired
    private SpuMapper spuMapper;


    @Override
    public List<GoodsVo> getByCategoryId(String categoryId, SearchVo searchVo) {
        int start = (searchVo.getPage()-1)*searchVo.getSize();
        int end = searchVo.getPage()* searchVo.getSize();
        return  spuMapper.getByCategoryId(categoryId,searchVo.getPrice(),searchVo.getSale(),start,end);
    }

    @Override
    public List<GoodsVo> getSearch(SearchVo searchVo) {
        int start = (searchVo.getPage()-1)*searchVo.getSize();
        int end = searchVo.getPage()* searchVo.getSize();
        String searchKey = "%"+searchVo.getSearchKey()+"%";
        return spuMapper.getSearch(searchKey,searchVo.getPrice(),searchVo.getSale(),start,end);
    }

    @Override
    public GoodsVo getByGoodId(String goodsId) {
        return spuMapper.getByGoodsId(goodsId);
    }

    @Override
    public Integer getSearchCount(SearchVo searchVo) {
        String searchKey = "%"+searchVo.getSearchKey()+"%";
        return spuMapper.getSearchCount(searchKey);
    }

    @Override
    public Integer getByCategoryIdCount(String categoryId) {
        return spuMapper.getByCategoryIdCount(categoryId);
    }

    @Override
    public String getTemplateIdByGoodsId(String goodsId) {
        return spuMapper.getTemplateIdByGoodsId(goodsId);
    }

    @Override
    public List<String> getCategoryId(String goodsId) {
        return spuMapper.getCategoryId(goodsId);
    }

    @Override
    public List<String> getGidsByCategoryId(String categoryIds) {
        return spuMapper.getGidsByCategoryId(categoryIds);
    }

    @Override
    public List<SaleHotVo> getByMerchantId(String merchantId) {
        return spuMapper.getByMerchantId(merchantId);
    }

    @Override
    public List<SaleHotVo> getAllByMerchantId(PageVoWithOne pageVoWithOne) {
        int start = (pageVoWithOne.getPage()-1)*pageVoWithOne.getSize();
        return spuMapper.getAllByMerchantId(pageVoWithOne.getParam(),start,pageVoWithOne.getSize());
    }

    @Override
    public Integer getAllCountByMerchantId(String merchantId) {
        return spuMapper.getAllCountByMerchantId(merchantId);
    }
}
