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

import com.fzm.mall.server.front.goods.model.GoodsComment;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.fzm.mall.server.front.goods.model.vo.CommentVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 商品评论表（用于对商品的评论） Mapper 接口
 * </p>
 *
 * @author fzm
 * @since 2021-04-01
 */
public interface GoodCommentMapper extends BaseMapper<GoodsComment> {

    List<CommentVo> getByGoodsId(@Param("goodsId") String goodsId, @Param("start") int start, @Param("end") int end);

    @Select("select count(*) from goods_comment a left join user b on a.uid = b.uid  where a.goods_id = #{goodsId} and a.is_valid = 1")
    Integer getCount(@Param("goodsId") String goodsId);

    @Select("select oid from goods_comment where comment_id = #{commentId}")
    String getOidByCommentId(@Param("commentId") String commentId);

    List<CommentVo> getByGoodsIdByCommentId(@Param("commentId") String commentId);

    @Select("select avg(business_evaluate) from goods_comment where merchant_id = #{merchantId} ")
    BigDecimal getScope(@Param("merchantId") String MerchantId);
}
