package com.gree.mall.manager.commonmapper;

import com.baomidou.mybatisplus.annotation.InterceptorIgnore;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gree.mall.manager.bean.goods.GoodsPackageList;
import com.gree.mall.manager.bean.goods.GoodsSpecBean;
import com.gree.mall.manager.bean.goods.GoodsTypeCount;
import com.gree.mall.manager.bean.goods.GoodsVO;
import com.gree.mall.manager.plus.entity.Goods;
import com.gree.mall.manager.plus.entity.GoodsCategory;
import com.gree.mall.manager.zfire.bean.ZfireParamBean;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;
@Mapper
public interface CustomGoodsMapper {

    /**
     * 商品列表
     *
     * @param objectPage
     * @param flag
     * @param keyword
     * @param startPrice
     * @param endPrice
     * @param startShare
     * @param endShare
     * @param sortStr
     * @param categoryId
     * @param status
     * @return
     */
    @InterceptorIgnore(tenantLine = "1", blockAttack = "1", illegalSql = "1")
    IPage<GoodsSpecBean> pageList(Page<GoodsSpecBean> objectPage,
                                  @Param("flag") String flag,
                                  @Param("keyword") String keyword,
                                  @Param("startPrice") BigDecimal startPrice,
                                  @Param("endPrice") BigDecimal endPrice,
                                  @Param("startShare") BigDecimal startShare,
                                  @Param("endShare") BigDecimal endShare,
                                  @Param("sortStr") String sortStr,
                                  @Param("categoryId") List<String> categoryId,
                                  @Param("status") Boolean status,
                                  @Param("goodsTypes") List<String> goodsTypes,
                                  @Param("companyWechatId")List<String> companyWechatId);

    @InterceptorIgnore(tenantLine = "1", blockAttack = "1", illegalSql = "1")
    List<GoodsSpecBean> list(@Param("commonTemplateId") String commonTemplateId);


    /**
     * 根据商品类型统计
     *
     * @return
     */
    @InterceptorIgnore(tenantLine = "1", blockAttack = "1", illegalSql = "1")
    public GoodsTypeCount countByType(@Param("companyWechatIds") List<String> companyWechatIds);

    /**
     * 获取活动中的商品数量
     *
     * @return
     */
    @InterceptorIgnore(tenantLine = "1", blockAttack = "1", illegalSql = "1")
    public Integer countByFlag(@Param("companyWechatIds") List<String> companyWechatIds);

    /**
     * 已售罄商品数量
     *
     * @return
     */
    @InterceptorIgnore(tenantLine = "1", blockAttack = "1", illegalSql = "1")
    public Integer ysq(@Param("companyWechatIds") List<String> companyWechatIds);

    /**
     * 查询我的收藏
     */
    @Select("select b.goods_id,b.img_url,b.goods_name,b.goods_price,b.status,a.create_time from goods_favorite a join goods b on a.goods_id=b.goods_id where a.user_id=#{userId} order by a.create_time desc")
    public IPage<Goods> myGoodsFavorite(Page page, @Param("userId") String userId);

    /**
     * 查询商品分类
     */
    @InterceptorIgnore(tenantLine = "1", blockAttack = "1", illegalSql = "1")
    public GoodsCategory queryGoodsCategoryByGoodsId(@Param("goodsId") String goodsId);

    /**
     * 用 商品规格的 分销金额 覆盖其 为null的 内部分销金额
     */
    void syncGoodsSpecInnerShareMsg(@Param("companyWechatId") String companyWechatId);


    IPage<GoodsPackageList> queryGoodsPackageList(Page objectPage,
                                                  @Param("keyword") String keyword,
                                                  @Param("startPrice") BigDecimal startPrice,
                                                  @Param("endPrice") BigDecimal endPrice,
                                                  @Param("startShare") BigDecimal startShare,
                                                  @Param("endShare") BigDecimal endShare,
                                                  @Param("sortStr") String sortStr,
                                                  @Param("categoryId") List<String> categoryId,
                                                  @Param("status") Boolean status,
                                                  @Param("companyWechatIds")List<String> companyWechatIds);

    IPage<GoodsVO> goodsList(Page page, @Param("ex") ZfireParamBean zfireParam);
}
