<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.fzm.mall.server.admin.goods_center.mapper.CountMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.fzm.mall.server.admin.goods_center.model.Count">
        <id column="id" property="id" />
        <result column="goods_id" property="goodsId" />
        <result column="sales" property="sales" />
        <result column="collect" property="collect" />
        <result column="view" property="view" />
        <result column="zan" property="zan" />
        <result column="praise" property="praise" />
        <result column="comment" property="comment" />
        <result column="popular" property="popular" />
        <result column="create_time" property="createTime" />
        <result column="update_time" property="updateTime" />
    </resultMap>

    <select id="salesTopTen" resultType="com.fzm.mall.server.admin.goods_center.entity.vo.SalesTopTenVO">
        SELECT c.goods_id as goodsId, sum(c.sales) as sales
        FROM goods_count c
                 LEFT JOIN goods_spu s ON c.goods_id = s.goods_id
        WHERE s.merchant_id = #{merchantId} AND s.status !=0
        GROUP BY c.goods_id
        ORDER BY sum(c.sales) DESC LIMIT 10
    </select>

</mapper>
