<?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.DragFormMapper">
    
    <resultMap type="com.zkqy.system.entity.DragForm" id="DragFormResult">
        <result property="fId"    column="f_id"    />
        <result property="sqlKey" column="sql_key"/>
        <result property="dfName"    column="df_name"    />
        <result property="dfNickname"    column="df_nickname"    />
        <result property="dfVueTemplate"    column="df_vue_template"    />
        <result property="dfHtmlTemplate"    column="df_html_template"    />
        <result property="dfFormSql"    column="df_form_sql"    />
        <result property="dfNodeId"    column="df_node_id"    />
        <result property="dfDatabase"    column="df_database"    />
        <result property="dfTableName"    column="df_table_name"    />
        <result property="dfFliePath"    column="df_flie_path"    />
        <result property="dfNotes"    column="df_notes"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createTime"    column="create_time"    />
        <result property="createBy"    column="create_by"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
        <result property="spare"    column="spare"    />
        <result property="spare1"    column="spare1"    />
        <result property="dtId" column="dt_id"/>
    </resultMap>

    <sql id="selectDragFormVo">
        select f_id,sql_key, df_name, df_nickname, df_vue_template, df_html_template, df_form_sql, df_node_id, df_database, df_table_name, df_flie_path, df_notes, del_flag, create_time, create_by, update_by, update_time, spare, spare1 from drag_form
    </sql>

    <select id="selectDragFormList" parameterType="com.zkqy.system.entity.DragForm" resultMap="DragFormResult">
        <include refid="selectDragFormVo"/>
        <where>
            del_flag = 0
            <if test="dfName != null  and dfName != ''">and df_name like concat('%', #{dfName}, '%')</if>
            <if test="dfNickname != null  and dfNickname != ''">and df_nickname like concat('%', #{dfNickname}, '%')
            </if>
            <if test="dfVueTemplate != null  and dfVueTemplate != ''">and df_vue_template = #{dfVueTemplate}</if>
            <if test="dfHtmlTemplate != null  and dfHtmlTemplate != ''">and df_html_template = #{dfHtmlTemplate}</if>
            <if test="dfFormSql != null  and dfFormSql != ''">and df_form_sql = #{dfFormSql}</if>
            <if test="dfNodeId != null ">and df_node_id = #{dfNodeId}</if>
            <if test="dfDatabase != null  and dfDatabase != ''">and df_database = #{dfDatabase}</if>
            <if test="dfTableName != null  and dfTableName != ''">and df_table_name like concat('%', #{dfTableName},
                '%')
            </if>
            <if test="dfFliePath != null  and dfFliePath != ''">and df_flie_path = #{dfFliePath}</if>
            <if test="dfNotes != null  and dfNotes != ''">and df_notes = #{dfNotes}</if>
            <if test="spare != null  and spare != ''">and spare = #{spare}</if>
            <if test="spare1 != null  and spare1 != ''">and spare1 = #{spare1}</if>
        </where>
        order by create_time desc
    </select>
    
    <select id="selectDragFormByFId" parameterType="Long" resultMap="DragFormResult">
        SELECT
            d.f_id,
            d.sql_key,
            d.df_name,
            d.df_nickname,
            d.df_vue_template,
            d.df_html_template,
            d.df_form_sql,
            d.df_node_id,
            d.df_database,
            d.df_table_name,
            d.df_flie_path,
            d.df_notes,
            d.del_flag,
            d.create_time,
            d.create_by,
            d.update_by,
            d.update_time,
            d.spare,
            d.spare1,
            dtf.dt_id
        FROM
            drag_form d
                LEFT JOIN drag_table_form dtf ON d.f_id = dtf.df_id
        where d.f_id = #{fId}
    </select>
        
    <insert id="insertDragForm" parameterType="com.zkqy.system.entity.DragForm" useGeneratedKeys="true" keyProperty="fId">
        insert into drag_form
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="sqlKey != null">sql_key,</if>
            <if test="dfName != null">df_name,</if>
            <if test="dfNickname != null">df_nickname,</if>
            <if test="dfVueTemplate != null">df_vue_template,</if>
            <if test="dfHtmlTemplate != null">df_html_template,</if>
            <if test="dfFormSql != null">df_form_sql,</if>
            <if test="dfNodeId != null">df_node_id,</if>
            <if test="dfDatabase != null">df_database,</if>
            <if test="dfTableName != null">df_table_name,</if>
            <if test="dfFliePath != null">df_flie_path,</if>
            <if test="dfNotes != null">df_notes,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createBy != null">create_by,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="spare != null">spare,</if>
            <if test="spare1 != null">spare1,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="sqlKey != null">#{sqlKey},</if>
            <if test="dfName != null">#{dfName},</if>
            <if test="dfNickname != null">#{dfNickname},</if>
            <if test="dfVueTemplate != null">#{dfVueTemplate},</if>
            <if test="dfHtmlTemplate != null">#{dfHtmlTemplate},</if>
            <if test="dfFormSql != null">#{dfFormSql},</if>
            <if test="dfNodeId != null">#{dfNodeId},</if>
            <if test="dfDatabase != null">#{dfDatabase},</if>
            <if test="dfTableName != null">#{dfTableName},</if>
            <if test="dfFliePath != null">#{dfFliePath},</if>
            <if test="dfNotes != null">#{dfNotes},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="spare != null">#{spare},</if>
            <if test="spare1 != null">#{spare1},</if>
         </trim>
    </insert>

    <update id="updateDragForm" parameterType="com.zkqy.system.entity.DragForm">
        update drag_form
        <trim prefix="SET" suffixOverrides=",">
            <if test="sqlKey != null">sql_key = #{sqlKey},</if>
            <if test="dfName != null">df_name = #{dfName},</if>
            <if test="dfNickname != null">df_nickname = #{dfNickname},</if>
            <if test="dfVueTemplate != null">df_vue_template = #{dfVueTemplate},</if>
            <if test="dfHtmlTemplate != null">df_html_template = #{dfHtmlTemplate},</if>
            <if test="dfFormSql != null">df_form_sql = #{dfFormSql},</if>
            <if test="dfNodeId != null">df_node_id = #{dfNodeId},</if>
            <if test="dfDatabase != null">df_database = #{dfDatabase},</if>
            <if test="dfTableName != null">df_table_name = #{dfTableName},</if>
            <if test="dfFliePath != null">df_flie_path = #{dfFliePath},</if>
            <if test="dfNotes != null">df_notes = #{dfNotes},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="spare != null">spare = #{spare},</if>
            <if test="spare1 != null">spare1 = #{spare1},</if>
        </trim>
        where f_id = #{fId}
    </update>

    <delete id="deleteDragFormByFId" parameterType="Long">
        update drag_form
        set del_flag = 1
        where f_id = #{fId}
    </delete>

    <delete id="deleteDragFormByFIds" parameterType="String">
        update drag_form
        set del_flag = 1 where f_id in
        <foreach item="fId" collection="array" open="(" separator="," close=")">
            #{fId}
        </foreach>
    </delete>

    <select id="selectDragFormBySqlKey" resultMap="DragFormResult">
        <include refid="selectDragFormVo"/>
        where sql_key = #{sqlKey}
    </select>

    <select id="selectDragFormFId" resultType="int">
        select f_id from drag_form ORDER BY f_id desc LIMIT 1
    </select>
</mapper>