<?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.yiqi.activity.mapper.ActivityGroupInfoMapper">

    <resultMap type="ActivityGroupInfo" id="ActivityGroupInfoResult">
        <result property="id" column="id"/>
        <result property="activityId" column="activity_id"/>
        <result property="canMultiUse" column="can_multi_use"/>
        <result property="maxUseCount" column="max_use_count"/>
        <result property="isShowAppBuyPage" column="is_show_app_buy_page"/>
        <result property="isShowWxBuyPage" column="is_show_wx_buy_page"/>
        <result property="isShowWxBuyPageFromQrcode" column="is_show_wx_buy_page_from_qrcode"/>
        <result property="maxBuyCount" column="max_buy_count"/>
        <result property="groupPrice" column="group_price"/>
        <result property="groupNum" column="group_num"/>
        <result property="createById" column="create_by_id"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateById" column="update_by_id"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
        <result property="remark" column="remark"/>
    </resultMap>

    <sql id="selectActivityGroupInfoVo">
        select a.id,a.title, a.description, a.img_url, a.content, a.start_date, a.end_date, a.activity_type,a.status
                   , ag.can_multi_use, ag.max_use_count, ag.is_show_app_buy_page, ag.is_show_wx_buy_page, ag.is_show_wx_buy_page_from_qrcode
                   , ag.max_buy_count, ag.group_price, ag.group_num
                   , a.create_by_id, a.create_by, a.create_time, a.update_by_id, a.update_by, a.update_time, a.remark
        from activity_group_info as ag left join activity_info as a on ag.activity_id=a.id
    </sql>

    <select id="selectActivityGroupInfoList" parameterType="ActivityInfo" resultType="com.yiqi.activity.domain.vo.ActivityGroupInfoQueryVO">
        <include refid="selectActivityGroupInfoVo"/>
        <where>
            a.del_flag='0' and a.activity_type='4'
            <if test="title != null  and title != ''">
                and a.title like concat('%', #{title}, '%')
            </if>
            <if test="startDate != null ">
                and a.start_date &gt;= #{startDate}
            </if>
            <if test="endDate != null ">
                and a.end_date &lt;= #{endDate}
            </if>
        </where>
    </select>

    <select id="selectActivityGroupInfoById" parameterType="Long"
            resultMap="ActivityGroupInfoResult">
        <include refid="selectActivityGroupInfoVo"/>
        where id = #{id}
    </select>

    <insert id="insertActivityGroupInfo" parameterType="ActivityGroupInfo" useGeneratedKeys="true"
            keyProperty="id">
        insert into activity_group_info
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="activityId != null">activity_id,
            </if>
            <if test="canMultiUse != null and canMultiUse != ''">can_multi_use,
            </if>
            <if test="maxUseCount != null">max_use_count,
            </if>
            <if test="isShowAppBuyPage != null and isShowAppBuyPage != ''">is_show_app_buy_page,
            </if>
            <if test="isShowWxBuyPage != null and isShowWxBuyPage != ''">is_show_wx_buy_page,
            </if>
            <if test="isShowWxBuyPageFromQrcode != null and isShowWxBuyPageFromQrcode != ''">is_show_wx_buy_page_from_qrcode,
            </if>
            <if test="maxBuyCount != null">max_buy_count,
            </if>
            <if test="groupPrice != null">group_price,
            </if>
            <if test="groupNum != null">group_num,
            </if>
            <if test="createById != null">create_by_id,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateById != null">update_by_id,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
            <if test="remark != null">remark,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="activityId != null">#{activityId},
            </if>
            <if test="canMultiUse != null and canMultiUse != ''">#{canMultiUse},
            </if>
            <if test="maxUseCount != null">#{maxUseCount},
            </if>
            <if test="isShowAppBuyPage != null and isShowAppBuyPage != ''">#{isShowAppBuyPage},
            </if>
            <if test="isShowWxBuyPage != null and isShowWxBuyPage != ''">#{isShowWxBuyPage},
            </if>
            <if test="isShowWxBuyPageFromQrcode != null and isShowWxBuyPageFromQrcode != ''">#{isShowWxBuyPageFromQrcode},
            </if>
            <if test="maxBuyCount != null">#{maxBuyCount},
            </if>
            <if test="groupPrice != null">#{groupPrice},
            </if>
            <if test="groupNum != null">#{groupNum},
            </if>
            <if test="createById != null">#{createById},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateById != null">#{updateById},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
            <if test="remark != null">#{remark},
            </if>
        </trim>
    </insert>

    <update id="updateActivityGroupInfo" parameterType="ActivityGroupInfo">
        update activity_group_info
        <trim prefix="SET" suffixOverrides=",">
            <if test="activityId != null">activity_id =
                #{activityId},
            </if>
            <if test="canMultiUse != null and canMultiUse != ''">can_multi_use =
                #{canMultiUse},
            </if>
            <if test="maxUseCount != null">max_use_count =
                #{maxUseCount},
            </if>
            <if test="isShowAppBuyPage != null and isShowAppBuyPage != ''">is_show_app_buy_page =
                #{isShowAppBuyPage},
            </if>
            <if test="isShowWxBuyPage != null and isShowWxBuyPage != ''">is_show_wx_buy_page =
                #{isShowWxBuyPage},
            </if>
            <if test="isShowWxBuyPageFromQrcode != null and isShowWxBuyPageFromQrcode != ''">is_show_wx_buy_page_from_qrcode =
                #{isShowWxBuyPageFromQrcode},
            </if>
            <if test="maxBuyCount != null">max_buy_count =
                #{maxBuyCount},
            </if>
            <if test="groupPrice != null">group_price =
                #{groupPrice},
            </if>
            <if test="groupNum != null">group_num =
                #{groupNum},
            </if>
            <if test="createById != null">create_by_id =
                #{createById},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateById != null">update_by_id =
                #{updateById},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
            <if test="remark != null">remark =
                #{remark},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteActivityGroupInfoById" parameterType="Long">
        delete from activity_group_info where id = #{id}
    </delete>

    <delete id="deleteActivityGroupInfoByIds" parameterType="String">
        delete from activity_group_info where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>



</mapper>