package com.fzm.mall.server.front.goods.mapper;

import com.fzm.mall.server.front.goods.model.Spu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.mall.server.front.goods.model.vo.GoodsVo;
import com.fzm.mall.server.front.goods.model.vo.SaleHotVo;
import com.fzm.mall.server.front.goods.model.vo.SearchVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 商品表 Mapper 接口
 * </p>
 *
 * @author fzm
 * @since 2021-03-09
 */
public interface SpuMapper extends BaseMapper<Spu> {

    List<GoodsVo> getByCategoryId(@Param("categoryId") String categoryId, @Param("price") String price, @Param("sale") String sale, @Param("start") int start, @Param("end") int end);

    List<GoodsVo> getSearch(@Param("searchKey") String searchKey, @Param("price") String price, @Param("sale") String sale, @Param("start") int start, @Param("end") int end);

    GoodsVo getByGoodsId(@Param("goodsId") String goodsId);

    @Select(" select count(*) from goods_spu a left join goods_count b on a.goods_id = b.goods_id left join  merchant c on a.merchant_id = c.merchant_id where a.name like  #{searchKey}  and a.status = 1 ;")
    Integer getSearchCount(@Param("searchKey") String searchKey);

    Integer getByCategoryIdCount(@Param("categoryId") String categoryId);

    @Select("select template_id from goods_spu where goods_id = #{goodsId}")
    String getTemplateIdByGoodsId(@Param("goodsId") String goodsId);

    @Select("select category_id from goods_category_spu where goods_id = #{goodsId} and status=1")
    List<String> getCategoryId(@Param("goodsId") String goodsId);

    @Select("select goods_id from goods_category_spu where category_id in (${categoryIds}) and status=1")
    List<String> getGidsByCategoryId(@Param("categoryIds") String categoryIds);

    @Select("select * from goods_spu where status = 1 and merchant_id = #{merchantId} order by create_time desc limit 3")
    List<SaleHotVo> getByMerchantId(@Param("merchantId") String merchantId);

    @Select("select * from goods_spu where status = 1 and merchant_id = #{merchantId} order by create_time desc limit #{start},#{size}")
    List<SaleHotVo> getAllByMerchantId(@Param("merchantId")String param, @Param("start") int start, @Param("size") Integer size);

    @Select("select count(*) from goods_spu where status = 1 and merchant_id = #{merchantId}")
    Integer getAllCountByMerchantId(String merchantId);
}
