package com.wzj.soopin.goods.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzj.soopin.goods.domain.bo.ProductBo;
import com.wzj.soopin.goods.domain.entity.Product;
import com.wzj.soopin.goods.domain.vo.ProductVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 商品信息Mapper接口
 *
 * @author zcc
 */
@Mapper
public interface ProductMapper extends BaseMapper<Product> {


    Page<ProductVO> getlist(@Param("page") Page<Product> page, @Param("query") ProductBo query);



    @Select("SELECT " +
        "name, " +
        "sales, " +
        "price, " +
        "CASE WHEN sales = 0 OR sales IS NULL THEN price ELSE sales * price END AS total_amount " +
        "FROM pms_product " +
        "ORDER BY total_amount DESC " +
        "LIMIT 20")
    List<Map<String, Object>> getTop20Product();


    ProductVO selectProductWithSkus(@Param("id") Long id);

    @Select("SELECT " +
        "SUM(CASE WHEN auth_flag = 1 THEN 1 ELSE 0 END) AS count1, " +
        "SUM(CASE WHEN auth_flag = 2 THEN 1 ELSE 0 END) AS count2 " +
        "FROM pms_product")
    Map<String, Object> countProduct();


    IPage<ProductVO> getProduct(@Param("page") Page<Product> page,  @Param("query") ProductBo query);
}
