<?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.MessageTypeMapper">
    <!-- 结果集 -->
    <resultMap type="com.zcxk.entity.MessageType" id="MessageTypeMap">
        <result property="id" column="id" jdbcType="INTEGER"/>
        <result property="type" column="type" jdbcType="VARCHAR"/>
        <result property="path" column="path" jdbcType="VARCHAR"/>
        <result property="dateCreate" column="date_create" jdbcType="TIMESTAMP"/>
        <result property="appId" column="app_id" jdbcType="VARCHAR"/>
        <result property="createBy" column="create_by" jdbcType="VARCHAR"/>
        <result property="updateBy" column="update_by" jdbcType="VARCHAR"/>
        <result property="status" column="status" jdbcType="INTEGER"/>
        <result property="dateUpdate" column="date_update" jdbcType="TIMESTAMP"/>
        <result property="shortName" column="short_name" jdbcType="VARCHAR"/>
        <result property="seq" column="SEQ" jdbcType="INTEGER"/>
    </resultMap>

    <!-- 基本字段 -->
    <sql id="Base_Column_List">
        id, type, path, date_create, app_id, create_by, update_by, status, date_update, short_name, SEQ    </sql>

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


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

    <!--通过实体作为筛选条件查询-->
    <select id="selectList" resultMap="MessageTypeMap">
        select
        <include refid="Base_Column_List"/>
        from uims_message_type
        <where>
            <if test="id != null">
                and id = #{id}
            </if>
            <if test="type != null and type != ''">
                and type = #{type}
            </if>
            <if test="path != null and path != ''">
                and path = #{path}
            </if>
            <if test="dateCreate != null">
                and date_create = #{dateCreate}
            </if>
            <if test="appId != null and appId != ''">
                and app_id = #{appId}
            </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="status != null">
                and status = #{status}
            </if>
            <if test="dateUpdate != null">
                and date_update = #{dateUpdate}
            </if>
            <if test="shortName != null and shortName != ''">
                and short_name = #{shortName}
            </if>
            <if test="seq != null">
                and SEQ = #{seq}
            </if>
        </where>
    </select>

    <!-- 新增所有列 -->
    <insert id="insert" keyProperty="id" useGeneratedKeys="true">
        insert into uims_message_type(id, type, path, date_create, app_id, create_by, update_by, status, date_update,
                                      short_name, SEQ)
        values (#{id}, #{type}, #{path}, #{dateCreate}, #{appId}, #{createBy}, #{updateBy}, #{status}, #{dateUpdate},
                #{shortName}, #{seq})
    </insert>

    <!-- 批量新增 -->
    <insert id="batchInsert">
        insert into uims_message_type(id, type, path, date_create, app_id, create_by, update_by, status, date_update,
        short_name, SEQ)
        values
        <foreach collection="messageTypes" item="item" index="index" separator=",">
            (
            #{item.id}, #{item.type}, #{item.path}, #{item.dateCreate}, #{item.appId}, #{item.createBy},
            #{item.updateBy}, #{item.status}, #{item.dateUpdate}, #{item.shortName}, #{item.seq} )
        </foreach>
    </insert>

    <!-- 通过主键修改数据 -->
    <update id="update">
        update uims_message.uims_message_type
        <set>
            <if test="type != null and type != ''">
                type = #{type},
            </if>
            <if test="path != null and path != ''">
                path = #{path},
            </if>
            <if test="dateCreate != null">
                date_create = #{dateCreate},
            </if>
            <if test="appId != null and appId != ''">
                app_id = #{appId},
            </if>
            <if test="createBy != null and createBy != ''">
                create_by = #{createBy},
            </if>
            <if test="updateBy != null and updateBy != ''">
                update_by = #{updateBy},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="dateUpdate != null">
                date_update = #{dateUpdate},
            </if>
            <if test="shortName != null and shortName != ''">
                short_name = #{shortName},
            </if>
            <if test="seq != null">
                SEQ = #{seq},
            </if>
        </set>
        where id = #{id}
    </update>

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

    <!-- 总数 -->
    <select id="count" resultType="int">
        select count(*)
        from uims_message_type
    </select>
    <select id="selectPage" resultMap="MessageTypeMap">
        select
        <include refid="Base_Column_List"/>
        from uims_message_type
        <where>
            <if test="messageType.id != null">
                and id = #{messageType.id}
            </if>
            <if test="messageType.type != null and messageType.type != ''">
                and type = #{messageType.type}
            </if>
            <if test="messageType.path != null and messageType.path != ''">
                and path = #{messageType.path}
            </if>
            <if test="messageType.dateCreate != null">
                and date_create = #{messageType.dateCreate}
            </if>
            <if test="messageType.appId != null and messageType.appId != ''">
                and app_id = #{messageType.appId}
            </if>
            <if test="messageType.createBy != null and messageType.createBy != ''">
                and create_by = #{messageType.createBy}
            </if>
            <if test="messageType.updateBy != null and messageType.updateBy != ''">
                and update_by = #{messageType.updateBy}
            </if>
            <if test="messageType.status != null">
                and status = #{messageType.status}
            </if>
            <if test="messageType.dateUpdate != null">
                and date_update = #{messageType.dateUpdate}
            </if>
            <if test="messageType.shortName != null and messageType.shortName != ''">
                and short_name = #{messageType.shortName}
            </if>
            <if test="messageType.seq != null">
                and SEQ = #{messageType.seq}
            </if>
        </where>
    </select>
</mapper>