<?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="edu.whut.infrastructure.dao.IGroupBuyActivityDao">

    <resultMap id="dataMap" type="edu.whut.infrastructure.dao.po.GroupBuyActivity">
        <id column="id" property="id"/>
        <result column="activity_id" property="activityId"/>
        <result column="activity_name" property="activityName"/>
        <result column="discount_id" property="discountId"/>
        <result column="group_type" property="groupType"/>
        <result column="take_limit_count" property="takeLimitCount"/>
        <result column="target" property="target"/>
        <result column="valid_time" property="validTime"/>
        <result column="status" property="status"/>
        <result column="start_time" property="startTime"/>
        <result column="end_time" property="endTime"/>
        <result column="tag_id" property="tagId"/>
        <result column="tag_scope" property="tagScope"/>
        <result column="create_time" property="createTime"/>
        <result column="update_time" property="updateTime"/>
    </resultMap>

    <select id="queryGroupBuyActivityList" resultMap="dataMap">
        select * from group_buy_activity
    </select>

    <select id="queryValidGroupBuyActivity" parameterType="edu.whut.infrastructure.dao.po.GroupBuyActivity" resultMap="dataMap">
        select
            activity_id, activity_name,discount_id, group_type, take_limit_count, target, valid_time,
            status, start_time, end_time, tag_id, tag_scope
        from group_buy_activity
        where source = #{source} and channel = #{channel}
        order by id desc
        limit 1
    </select>

    <select id="queryValidGroupBuyActivityId" parameterType="java.lang.Long" resultMap="dataMap">
        select
            activity_id, activity_name, discount_id, group_type, take_limit_count,
            target, valid_time, status, start_time, end_time, tag_id, tag_scope
        from group_buy_activity
        where activity_id = #{activityId} and status = 1
    </select>

    <select id="queryGroupBuyActivityByActivityId" parameterType="java.lang.Long" resultMap="dataMap">
        select
            activity_id, activity_name, discount_id, group_type, take_limit_count,
            target, valid_time, status, start_time, end_time, tag_id, tag_scope
        from group_buy_activity
        where activity_id = #{activityId}
    </select>

</mapper>
