<?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.zcxk.dao.MessageTemplateMapper">
    <!-- 结果集 -->
    <resultMap type="com.zcxk.entity.MessageTemplate" id="MessageTemplateMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="name" column="NAME" jdbcType="VARCHAR"/>
        <result property="content" column="CONTENT" jdbcType="VARCHAR"/>
        <result property="paramTotal" column="PARAM_TOTAL" jdbcType="INTEGER"/>
        <result property="dateCreate" column="date_create" jdbcType="TIMESTAMP"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="appId" column="app_id" jdbcType="INTEGER"/>
        <result property="dateUpdate" column="date_update" jdbcType="TIMESTAMP"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
    </resultMap>

    <!-- 基本字段 -->
    <sql id="Base_Column_List">
        id, NAME, CONTENT, PARAM_TOTAL, date_create, create_by, update_by, app_id, date_update, status    </sql>

    <!-- 查询单个 -->
    <select id="selectById" resultMap="MessageTemplateMap">
        select
        <include refid="Base_Column_List"/>
        from uims_message_template
        where id = #{id}
    </select>


    <!-- 查询全部 -->
    <select id="selectAll" resultMap="MessageTemplateMap">
        select
        <include refid="Base_Column_List"/>
        from uims_message_template
    </select>

    <!--通过实体作为筛选条件查询-->
    <select id="selectList" resultMap="MessageTemplateMap">
        select
        <include refid="Base_Column_List"/>
        from uims_message_template
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="name != null and name != ''">
                and NAME = #{name}
            </if>
            <if test="content != null and content != ''">
                and CONTENT = #{content}
            </if>
            <if test="paramTotal != null">
                and PARAM_TOTAL = #{paramTotal}
            </if>
            <if test="dateCreate != null">
                and date_create = #{dateCreate}
            </if>
            <if test="createBy != null and createBy != ''">
                and create_by = #{createBy}
            </if>
            <if test="updateBy != null and updateBy != ''">
                and update_by = #{updateBy}
            </if>
            <if test="appId != null">
                and app_id = #{appId}
            </if>
            <if test="dateUpdate != null">
                and date_update = #{dateUpdate}
            </if>
            <if test="status != null">
                and status = #{status}
            </if>
        </where>
    </select>

    <!-- 新增所有列 -->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into uims_message_template(id, NAME, CONTENT, PARAM_TOTAL, date_create, create_by, update_by, app_id, date_update, status)
        values ( #{id}, #{name}, #{content}, #{paramTotal}, #{dateCreate}, #{createBy}, #{updateBy}, #{appId}, #{dateUpdate}, #{status})
    </insert>

    <!-- 批量新增 -->
    <insert id="batchInsert">
        insert into uims_message_template(id, NAME, CONTENT, PARAM_TOTAL, date_create, create_by, update_by, app_id,
        date_update, status)
        values
        <foreach collection="messageTemplates" item="item" index="index" separator=",">
            (
            #{item.id}, #{item.name}, #{item.content}, #{item.paramTotal}, #{item.dateCreate}, #{item.createBy},
            #{item.updateBy}, #{item.appId}, #{item.dateUpdate}, #{item.status} )
        </foreach>
    </insert>

    <!-- 通过主键修改数据 -->
    <update id="update">
        update uims_message.uims_message_template
        <set>
            <if test="name != null and name != ''">
                NAME = #{name},
            </if>
            <if test="content != null and content != ''">
                CONTENT = #{content},
            </if>
            <if test="paramTotal != null">
                PARAM_TOTAL = #{paramTotal},
            </if>
            <if test="dateCreate != null">
                date_create = #{dateCreate},
            </if>
            <if test="createBy != null and createBy != ''">
                create_by = #{createBy},
            </if>
            <if test="updateBy != null and updateBy != ''">
                update_by = #{updateBy},
            </if>
            <if test="appId != null">
                app_id = #{appId},
            </if>
            <if test="dateUpdate != null">
                date_update = #{dateUpdate},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
        </set>
        where id = #{id}
    </update>

    <!--通过主键删除-->
    <delete id="deleteById">
        delete from uims_message_template where id = #{id}
    </delete>

    <!-- 总数 -->
    <select id="count" resultType="int">
        select count(*) from uims_message_template
    </select>
    <select id="selectPage" resultMap="MessageTemplateMap">
        select
        <include refid="Base_Column_List"/>
        from uims_message_template
        <where>
            <if test="messageTemplate.id != null">
                and id = #{messageTemplate.id}
            </if>
            <if test="messageTemplate.name != null and messageTemplate.name != ''">
                and NAME = #{messageTemplate.name}
            </if>
            <if test="messageTemplate.content != null and messageTemplate.content != ''">
                and CONTENT = #{messageTemplate.content}
            </if>
            <if test="messageTemplate.paramTotal != null">
                and PARAM_TOTAL = #{messageTemplate.paramTotal}
            </if>
            <if test="messageTemplate.dateCreate != null">
                and date_create = #{messageTemplate.dateCreate}
            </if>
            <if test="messageTemplate.createBy != null and messageTemplate.createBy != ''">
                and create_by = #{messageTemplate.createBy}
            </if>
            <if test="messageTemplate.updateBy != null and messageTemplate.updateBy != ''">
                and update_by = #{messageTemplate.updateBy}
            </if>
            <if test="messageTemplate.appId != null">
                and app_id = #{messageTemplate.appId}
            </if>
            <if test="messageTemplate.dateUpdate != null">
                and date_update = #{messageTemplate.dateUpdate}
            </if>
            <if test="messageTemplate.status != null">
                and status = #{messageTemplate.status}
            </if>
        </where>
    </select>
</mapper>