<?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.xinelu.manage.mapper.officialaccountsubscribeevent.OfficialAccountSubscribeEventMapper">

    <resultMap type="OfficialAccountSubscribeEvent" id="OfficialAccountSubscribeEventResult">
        <result property="id" column="id"/>
        <result property="openid" column="openid"/>
        <result property="officialAccountAppId" column="official_account_app_id"/>
        <result property="sendTime" column="send_time"/>
        <result property="msgType" column="msg_type"/>
        <result property="eventType" column="event_type"/>
        <result property="subscribeStatus" column="subscribe_status"/>
        <result property="createBy" column="create_by"/>
        <result property="createTime" column="create_time"/>
        <result property="updateBy" column="update_by"/>
        <result property="updateTime" column="update_time"/>
    </resultMap>

    <sql id="selectOfficialAccountSubscribeEventVo">
        select id, openid, official_account_app_id, send_time, msg_type, event_type, subscribe_status, create_by, create_time, update_by, update_time from official_account_subscribe_event
    </sql>

    <select id="selectOfficialAccountSubscribeEventList" parameterType="OfficialAccountSubscribeEvent"
            resultMap="OfficialAccountSubscribeEventResult">
        <include refid="selectOfficialAccountSubscribeEventVo"/>
        <where>
            <if test="openid != null  and openid != ''">
                and openid = #{openid}
            </if>
            <if test="officialAccountAppId != null  and officialAccountAppId != ''">
                and official_account_app_id = #{officialAccountAppId}
            </if>
            <if test="sendTime != null ">
                and send_time = #{sendTime}
            </if>
            <if test="msgType != null  and msgType != ''">
                and msg_type = #{msgType}
            </if>
            <if test="eventType != null  and eventType != ''">
                and event_type = #{eventType}
            </if>
        </where>
    </select>

    <select id="selectOfficialAccountSubscribeEventById" parameterType="Long"
            resultMap="OfficialAccountSubscribeEventResult">
        <include refid="selectOfficialAccountSubscribeEventVo"/>
        where id = #{id}
    </select>

    <insert id="insertOfficialAccountSubscribeEvent" parameterType="OfficialAccountSubscribeEvent"
            useGeneratedKeys="true"
            keyProperty="id">
        insert into official_account_subscribe_event
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="openid != null">openid,
            </if>
            <if test="officialAccountAppId != null">official_account_app_id,
            </if>
            <if test="sendTime != null">send_time,
            </if>
            <if test="msgType != null">msg_type,
            </if>
            <if test="eventType != null">event_type,
            </if>
            <if test="subscribeStatus != null">subscribe_status,
            </if>
            <if test="createBy != null">create_by,
            </if>
            <if test="createTime != null">create_time,
            </if>
            <if test="updateBy != null">update_by,
            </if>
            <if test="updateTime != null">update_time,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="openid != null">#{openid},
            </if>
            <if test="officialAccountAppId != null">#{officialAccountAppId},
            </if>
            <if test="sendTime != null">#{sendTime},
            </if>
            <if test="msgType != null">#{msgType},
            </if>
            <if test="eventType != null">#{eventType},
            </if>
            <if test="subscribeStatus != null">#{subscribeStatus},
            </if>
            <if test="createBy != null">#{createBy},
            </if>
            <if test="createTime != null">#{createTime},
            </if>
            <if test="updateBy != null">#{updateBy},
            </if>
            <if test="updateTime != null">#{updateTime},
            </if>
        </trim>
    </insert>

    <update id="updateOfficialAccountSubscribeEvent" parameterType="OfficialAccountSubscribeEvent">
        update official_account_subscribe_event
        <trim prefix="SET" suffixOverrides=",">
            <if test="openid != null">openid =
                #{openid},
            </if>
            <if test="officialAccountAppId != null">official_account_app_id =
                #{officialAccountAppId},
            </if>
            <if test="sendTime != null">send_time =
                #{sendTime},
            </if>
            <if test="msgType != null">msg_type =
                #{msgType},
            </if>
            <if test="eventType != null">event_type =
                #{eventType},
            </if>
            <if test="subscribeStatus != null">subscribe_status =
                #{subscribeStatus},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteOfficialAccountSubscribeEventById" parameterType="Long">
        delete from official_account_subscribe_event where id = #{id}
    </delete>

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

    <select id="getSubscribeEventInfo" resultType="int">
        select count(1) from official_account_subscribe_event where openid = #{openid}
    </select>

    <update id="updateSubscribeEventInfo" parameterType="OfficialAccountSubscribeEvent">
        update official_account_subscribe_event
        <trim prefix="SET" suffixOverrides=",">
            <if test="openid != null">openid =
                #{openid},
            </if>
            <if test="officialAccountAppId != null">official_account_app_id =
                #{officialAccountAppId},
            </if>
            <if test="sendTime != null">send_time =
                #{sendTime},
            </if>
            <if test="msgType != null">msg_type =
                #{msgType},
            </if>
            <if test="eventType != null">event_type =
                #{eventType},
            </if>
            <if test="subscribeStatus != null">subscribe_status =
                #{subscribeStatus},
            </if>
            <if test="createBy != null">create_by =
                #{createBy},
            </if>
            <if test="createTime != null">create_time =
                #{createTime},
            </if>
            <if test="updateBy != null">update_by =
                #{updateBy},
            </if>
            <if test="updateTime != null">update_time =
                #{updateTime},
            </if>
        </trim>
        where openid = #{openid}
    </update>
</mapper>