<?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.playlet.system.mapper.PlayletMessageMapper">

    <resultMap type="PlayletMessage" id="PlayletMessageResult">
        <result property="id"    column="ID"    />
        <result property="name"    column="NAME"    />
        <result property="title"    column="TITLE"    />
        <result property="detail"    column="DETAIL"    />
        <result property="type"    column="TYPE"    />
        <result property="createBy"    column="CREATE_BY"    />
        <result property="createTime"    column="CREATE_TIME"    />
        <result property="updateBy"    column="UPDATE_BY"    />
        <result property="updateTime"    column="UPDATE_TIME"    />
        <result property="remark"    column="REMARK"    />
    </resultMap>

    <sql id="selectPlayletMessageVo">
        select ID, NAME, TITLE, DETAIL, TYPE, CREATE_BY, CREATE_TIME, UPDATE_BY, UPDATE_TIME, REMARK from playlet_message
    </sql>

    <select id="selectPlayletMessageList" parameterType="PlayletMessage" resultMap="PlayletMessageResult">
        <include refid="selectPlayletMessageVo"/>
        <where>
            <if test="name != null  and name != ''"> and NAME like concat('%', #{name}, '%')</if>
            <if test="title != null  and title != ''"> and TITLE = #{title}</if>
            <if test="detail != null  and detail != ''"> and DETAIL = #{detail}</if>
            <if test="type != null  and type != ''"> and TYPE = #{type}</if>
            <if test="createBy != null  and createBy != ''"> and CREATE_BY = #{createBy}</if>
            <if test="createTime != null "> and CREATE_TIME = #{createTime}</if>
            <if test="updateBy != null  and updateBy != ''"> and UPDATE_BY = #{updateBy}</if>
            <if test="updateTime != null "> and UPDATE_TIME = #{updateTime}</if>
            <if test="remark != null  and remark != ''"> and REMARK = #{remark}</if>
        </where>
    </select>

    <select id="selectPlayletMessageById" parameterType="Long" resultMap="PlayletMessageResult">
        <include refid="selectPlayletMessageVo"/>
        where ID = #{id}
    </select>

    <insert id="insertPlayletMessage" parameterType="PlayletMessage" useGeneratedKeys="true" keyProperty="id">
        insert into playlet_message
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="name != null">NAME,</if>
            <if test="title != null">TITLE,</if>
            <if test="detail != null">DETAIL,</if>
            <if test="type != null">TYPE,</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>
            <if test="remark != null">REMARK,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="name != null">#{name},</if>
            <if test="title != null">#{title},</if>
            <if test="detail != null">#{detail},</if>
            <if test="type != null">#{type},</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>
            <if test="remark != null">#{remark},</if>
        </trim>
    </insert>

    <update id="updatePlayletMessage" parameterType="PlayletMessage">
        update playlet_message
        <trim prefix="SET" suffixOverrides=",">
            <if test="name != null">NAME = #{name},</if>
            <if test="title != null">TITLE = #{title},</if>
            <if test="detail != null">DETAIL = #{detail},</if>
            <if test="type != null">TYPE = #{type},</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>
            <if test="remark != null">REMARK = #{remark},</if>
        </trim>
        where ID = #{id}
    </update>

    <delete id="deletePlayletMessageById" parameterType="Long">
        delete from playlet_message where ID = #{id}
    </delete>

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

</mapper>