<?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.flossom.common.core.mapper.WxScriptMessageMapper">

    <resultMap type="WxScriptMessage" id="WxScriptMessageResult">
        <result property="id"    column="id"    />
        <result property="messageType"    column="message_type"    />
        <result property="messageTitle"    column="message_title"    />
        <result property="instrumentId"    column="instrument_id"    />
        <result property="instrumentName"    column="instrument_name"    />
        <result property="messageContent"    column="message_content"    />
        <result property="status"    column="status"    />
        <result property="type"    column="type"    />
        <result property="link"    column="link"    />
        <result property="linkParams"    column="link_params"    />
        <result property="redirectAppid"    column="redirect_appid"    />
        <result property="redirectUrl"    column="redirect_url"    />
        <result property="videoNo"    column="video_no"    />
        <result property="feedId"    column="feed_id"    />
        <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="selectWxScriptMessageVo">
        select id, message_type, message_title, instrument_id, instrument_name, message_content, status, type, link, link_params, redirect_appid, redirect_url, video_no, feed_id, create_by, create_time, update_by, update_time from wx_script_message
    </sql>

    <select id="selectWxScriptMessageList" parameterType="WxScriptMessage" resultMap="WxScriptMessageResult">
        <include refid="selectWxScriptMessageVo"/>
        <where>
            <if test="messageType != null "> and message_type = #{messageType}</if>
            <if test="messageTitle != null  and messageTitle != ''"> and message_title = #{messageTitle}</if>
            <if test="instrumentId != null "> and instrument_id = #{instrumentId}</if>
            <if test="instrumentName != null  and instrumentName != ''"> and instrument_name like concat('%', #{instrumentName}, '%')</if>
            <if test="messageContent != null  and messageContent != ''"> and message_content = #{messageContent}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="type != null "> and type = #{type}</if>
            <if test="link != null  and link != ''"> and link = #{link}</if>
            <if test="linkParams != null  and linkParams != ''"> and link_params = #{linkParams}</if>
            <if test="redirectAppid != null  and redirectAppid != ''"> and redirect_appid = #{redirectAppid}</if>
            <if test="redirectUrl != null  and redirectUrl != ''"> and redirect_url = #{redirectUrl}</if>
            <if test="videoNo != null  and videoNo != ''"> and video_no = #{videoNo}</if>
            <if test="feedId != null  and feedId != ''"> and feed_id = #{feedId}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectWxScriptMessageById" parameterType="Long" resultMap="WxScriptMessageResult">
        <include refid="selectWxScriptMessageVo"/>
        where id = #{id}
    </select>

    <insert id="insertWxScriptMessage" parameterType="WxScriptMessage">
        insert into wx_script_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">id,</if>
            <if test="messageType != null">message_type,</if>
            <if test="messageTitle != null">message_title,</if>
            <if test="instrumentId != null">instrument_id,</if>
            <if test="instrumentName != null">instrument_name,</if>
            <if test="messageContent != null">message_content,</if>
            <if test="status != null">status,</if>
            <if test="type != null">type,</if>
            <if test="link != null">link,</if>
            <if test="linkParams != null">link_params,</if>
            <if test="redirectAppid != null">redirect_appid,</if>
            <if test="redirectUrl != null">redirect_url,</if>
            <if test="videoNo != null">video_no,</if>
            <if test="feedId != null">feed_id,</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="id != null">#{id},</if>
            <if test="messageType != null">#{messageType},</if>
            <if test="messageTitle != null">#{messageTitle},</if>
            <if test="instrumentId != null">#{instrumentId},</if>
            <if test="instrumentName != null">#{instrumentName},</if>
            <if test="messageContent != null">#{messageContent},</if>
            <if test="status != null">#{status},</if>
            <if test="type != null">#{type},</if>
            <if test="link != null">#{link},</if>
            <if test="linkParams != null">#{linkParams},</if>
            <if test="redirectAppid != null">#{redirectAppid},</if>
            <if test="redirectUrl != null">#{redirectUrl},</if>
            <if test="videoNo != null">#{videoNo},</if>
            <if test="feedId != null">#{feedId},</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="updateWxScriptMessage" parameterType="WxScriptMessage">
        update wx_script_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="messageType != null">message_type = #{messageType},</if>
            <if test="messageTitle != null">message_title = #{messageTitle},</if>
            <if test="instrumentId != null">instrument_id = #{instrumentId},</if>
            <if test="instrumentName != null">instrument_name = #{instrumentName},</if>
            <if test="messageContent != null">message_content = #{messageContent},</if>
            <if test="status != null">status = #{status},</if>
            <if test="type != null">type = #{type},</if>
            <if test="link != null">link = #{link},</if>
            <if test="linkParams != null">link_params = #{linkParams},</if>
            <if test="redirectAppid != null">redirect_appid = #{redirectAppid},</if>
            <if test="redirectUrl != null">redirect_url = #{redirectUrl},</if>
            <if test="videoNo != null">video_no = #{videoNo},</if>
            <if test="feedId != null">feed_id = #{feedId},</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="deleteWxScriptMessageById" parameterType="Long">
        delete from wx_script_message where id = #{id}
    </delete>

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

    <select id="selectOneByMessageType" parameterType="integer" resultMap="WxScriptMessageResult">
        <include refid="selectWxScriptMessageVo"/>
        where
            message_type = #{messageType}
            and status = 0
            order by create_time desc
            LIMIT 1
    </select>
</mapper>
