<?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.zkqy.system.mapper.DragTableStyleMapper">
    
    <resultMap type="com.zkqy.system.entity.DragTableStyle" id="DragTableStyleResult">
        <result property="id"    column="id"    />
        <result property="styleName"    column="style_name"    />
        <result property="styleCode"    column="style_code"    />
        <result property="tableKey"    column="table_key"    />
        <result property="styleCondtion"    column="style_condtion"    />
        <result property="styleField"    column="style_field"    />
        <result property="styleType"    column="style_type"    />
        <result property="styleDescription"    column="style_description"    />
        <result property="spare1"    column="spare1"    />
        <result property="spare2"    column="spare2"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createById"    column="create_by_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateById"    column="update_by_id"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDragTableStyleVo">
        select id, style_name, style_code, table_key, style_condtion, style_field, style_type, style_description, spare1, spare2, del_flag, create_by, create_by_id, create_time, update_by, update_by_id, update_time from drag_table_style
    </sql>

    <select id="selectDragTableStyleList" parameterType="com.zkqy.system.entity.DragTableStyle" resultMap="DragTableStyleResult">
        <include refid="selectDragTableStyleVo"/>
        where del_flag = '0'
            <if test="styleName != null  and styleName != ''"> and style_name like concat('%', #{styleName}, '%')</if>
            <if test="styleCode != null  and styleCode != ''"> and style_code = #{styleCode}</if>
            <if test="tableKey != null  and tableKey != ''"> and table_key = #{tableKey}</if>
            <if test="styleCondtion != null  and styleCondtion != ''"> and style_condtion = #{styleCondtion}</if>
            <if test="styleField != null  and styleField != ''"> and style_field = #{styleField}</if>
            <if test="styleType != null "> and style_type = #{styleType}</if>
            <if test="styleDescription != null  and styleDescription != ''"> and style_description = #{styleDescription}</if>
            <if test="spare1 != null  and spare1 != ''"> and spare1 = #{spare1}</if>
            <if test="spare2 != null  and spare2 != ''"> and spare2 = #{spare2}</if>
            <if test="createById != null "> and create_by_id = #{createById}</if>
            <if test="updateById != null "> and update_by_id = #{updateById}</if>
            order by create_time desc
    </select>
    
    <select id="selectDragTableStyleById" parameterType="Long" resultMap="DragTableStyleResult">
        <include refid="selectDragTableStyleVo"/>
        where id = #{id}
    </select>
        
    <insert id="batchInsertDragTableStyle" parameterType="com.zkqy.system.entity.DragTableStyle">
        insert into drag_table_style
            (style_name,style_code,table_key,style_condtion,style_field,style_type,style_description,spare1,spare2,create_by,create_by_id,create_time,del_flag)
        values
            <foreach collection="list" item="item" separator=",">
                (#{item.styleName},#{item.styleCode},#{item.tableKey},#{item.styleCondtion},#{item.styleField},#{item.styleType},
                 #{item.styleDescription},#{item.spare1},#{item.spare2},#{item.createBy},#{item.createById},#{item.createTime},'0')
            </foreach>
    </insert>

    <update id="updateDragTableStyle" parameterType="com.zkqy.system.entity.DragTableStyle">
            update drag_table_style
            <trim prefix="SET" suffixOverrides=",">
                <if test="styleName != null">style_name = #{styleName},</if>
                <if test="styleCode != null">style_code = #{styleCode},</if>
                <if test="tableKey != null">table_key = #{tableKey},</if>
                <if test="styleCondtion != null and styleCondtion != ''">style_condtion = #{styleCondtion},</if>
                <if test="styleField != null">style_field = #{styleField},</if>
                <if test="styleType != null">style_type = #{styleType},</if>
                <if test="styleDescription != null">style_description = #{styleDescription},</if>
                <if test="spare1 != null">spare1 = #{spare1},</if>
                <if test="spare2 != null">spare2 = #{spare2},</if>
                <if test="updateBy != null">update_by = #{updateBy},</if>
                <if test="updateById != null">update_by_id = #{updateById},</if>
                <if test="updateTime != null">update_time = #{updateTime},</if>
            </trim>
            where id = #{id}
    </update>

    <update id="deleteDragTableStyleByTableKeys" parameterType="String">
        update drag_table_style set del_flag = '2' where table_key in
        <foreach collection="list" item="tableKey" open="(" close=")" separator=",">
            #{tableKey}
        </foreach>
    </update>

    <update id="deleteDragTableStyleByIds">
        update drag_table_style set del_flag = '2' where id in
        <foreach item="id" collection="list" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <select id="selectIdByTableKey" resultType="long">
        select id from drag_table_style where del_flag = '0' and table_key = #{tableKey}
    </select>
</mapper>