<?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.GrouponMapper">

    <!-- 通用查询映射结果 -->
    <resultMap id="grouponResultMap" type="org.springblade.modules.groupon.entity.Groupon">
        <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="main_title" property="mainTitle"/>
        <result column="sub_title" property="subTitle"/>
        <result column="groupon_start_time" property="grouponStartTime"/>
        <result column="groupon_end_time" property="grouponEndTime"/>
        <result column="take_start_time" property="takeStartTime"/>
        <result column="take_end_time" property="takeEndTime"/>
        <result column="status" property="status"/>
        <result column="views" property="views"/>
        <result column="audit_status" property="auditStatus"/>
        <result column="audit_time" property="auditTime"/>
        <result column="source" property="source"/>
        <result column="is_perfect" property="isPerfect"/>
    </resultMap>


    <select id="selectGrouponPage" resultMap="grouponResultMap">
        select * from t_groupon where is_delete = 0
    </select>
    <select id="selectGroupon" resultType="org.springblade.modules.groupon.vo.GrouponVO">
        SELECT
            g.*
        FROM
            t_groupon_self_take gst
            JOIN t_self_take st ON gst.self_take_id = st.id
            JOIN t_groupon g on gst.groupon_id = g.id
        WHERE
            st.address LIKE concat(#{address}, '%') and  g.`status` = 1 and g.audit_status = 1
            <if test="type == 1">
                and NOW() &lt;= g.groupon_end_time
            </if>
            <if test="type == 2">
                and NOW() > g.groupon_end_time
            </if>
        GROUP BY g.id
        ORDER BY g.create_time desc
    </select>

</mapper>
