<?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.officialaccounttemplateevent.OfficialAccountTemplateEventMapper">

    <resultMap type="OfficialAccountTemplateEvent" id="OfficialAccountTemplateEventResult">
        <result property="id" column="id"/>
        <result property="patientId" column="patient_id"/>
        <result property="patientName" column="patient_name"/>
        <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="msgId" column="msg_id"/>
        <result property="status" column="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="selectOfficialAccountTemplateEventVo">
        select id, patient_id, patient_name, openid, official_account_app_id, send_time, msg_type, event_type, msg_id, status, create_by, create_time, update_by, update_time from official_account_template_event
    </sql>

    <select id="selectOfficialAccountTemplateEventList" parameterType="OfficialAccountTemplateEvent"
            resultMap="OfficialAccountTemplateEventResult">
        <include refid="selectOfficialAccountTemplateEventVo"/>
        <where>
            <if test="patientId != null ">
                and patient_id = #{patientId}
            </if>
            <if test="patientName != null  and patientName != ''">
                and patient_name like concat('%', #{patientName}, '%')
            </if>
            <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>
            <if test="msgId != null  and msgId != ''">
                and msg_id = #{msgId}
            </if>
            <if test="status != null  and status != ''">
                and status = #{status}
            </if>
        </where>
    </select>

    <select id="selectOfficialAccountTemplateEventById" parameterType="Long"
            resultMap="OfficialAccountTemplateEventResult">
        <include refid="selectOfficialAccountTemplateEventVo"/>
        where id = #{id}
    </select>

    <insert id="insertOfficialAccountTemplateEvent" parameterType="OfficialAccountTemplateEvent" useGeneratedKeys="true"
            keyProperty="id">
        insert into official_account_template_event
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="patientId != null">patient_id,
            </if>
            <if test="patientName != null">patient_name,
            </if>
            <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="msgId != null">msg_id,
            </if>
            <if test="status != null">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="patientId != null">#{patientId},
            </if>
            <if test="patientName != null">#{patientName},
            </if>
            <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="msgId != null">#{msgId},
            </if>
            <if test="status != null">#{status},
            </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="updateOfficialAccountTemplateEvent" parameterType="OfficialAccountTemplateEvent">
        update official_account_template_event
        <trim prefix="SET" suffixOverrides=",">
            <if test="patientId != null">patient_id =
                #{patientId},
            </if>
            <if test="patientName != null">patient_name =
                #{patientName},
            </if>
            <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="msgId != null">msg_id =
                #{msgId},
            </if>
            <if test="status != null">status =
                #{status},
            </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="deleteOfficialAccountTemplateEventById" parameterType="Long">
        delete from official_account_template_event where id = #{id}
    </delete>

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