<?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="org.springblade.modules.groupon.mapper.GrouponGoodsMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="grouponGoodsResultMap" type="org.springblade.modules.groupon.entity.GrouponGoods">
        <result column="id" property="id"/>
        <result column="is_delete" property="isDelete"/>
        <result column="create_user_id" property="createUserId"/>
        <result column="create_time" property="createTime"/>
        <result column="update_user_id" property="updateUserId"/>
        <result column="update_time" property="updateTime"/>
        <result column="groupon_id" property="grouponId"/>
        <result column="goods_id" property="goodsId"/>
        <result column="goods_num" property="goodsNum"/>
    </resultMap>


    <select id="selectGrouponGoodsPage" resultMap="grouponGoodsResultMap">
        select * from t_groupon_goods where is_delete = 0
    </select>
    <select id="getGoodsCover" resultType="org.springblade.modules.groupon.vo.GrouponGoodsVO">
            SELECT
                gg.groupon_id grouponId,
                gi.goods_cover goodsCover,
                gg.groupon_price price
            FROM
                t_groupon_goods gg
            JOIN t_goods_info gi ON gg.goods_id = gi.id
            WHERE
                gi.audit_status = 1
                and gg.groupon_id in
            <foreach item="item" index="index" collection="ids"
                     open="(" separator="," close=")">
                #{item}
            </foreach>
            order by gg.sort

    </select>
    <select id="getGoodsByGrouponId" resultType="org.springblade.modules.mall.vo.GoodsInfoVO">
        SELECT
            gi.*,
            gg.groupon_price
        FROM
            `t_groupon_goods` gg
            JOIN t_goods_info gi ON gg.goods_id = gi.id
        WHERE
            gi.audit_status = 1
            AND gg.groupon_id = #{grouponId}
        ORDER BY
            gg.sort
    </select>

</mapper>
