<?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.DragFormGroupMapper">
    
    <resultMap type="com.zkqy.system.entity.DragFormGroup" id="DragFormGroupResult">
        <result property="id"    column="id"    />
        <result property="groupKey"    column="group_key"    />
        <result property="fGName"    column="f_g_name"    />
        <result property="remark"    column="remark"    />
        <result property="formKeys"    column="form_keys"    />
        <result property="mainTable"    column="main_table"    />
        <result property="relationJson"    column="relation_json"    />
        <result property="showDataSql"    column="show_data_sql"    />
        <result property="updateTime"    column="update_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateById"    column="update_by_id"    />
        <result property="createTime"    column="create_time"    />
        <result property="createById"    column="create_by_id"    />
        <result property="createBy"    column="create_by"    />
        <result property="delFlag"    column="del_flag"    />
    </resultMap>

    <sql id="selectDragFormGroupVo">
        select id,
               group_key,
               f_g_name,
               remark,
               form_keys,
               main_table,
               relation_json,
               show_data_sql,
               update_time,
               update_by,
               update_by_id,
               create_time,
               create_by_id,
               create_by
        from drag_form_group
    </sql>

    <select id="selectDragFormGroupList" parameterType="com.zkqy.system.entity.DragFormGroup" resultMap="DragFormGroupResult">
        <include refid="selectDragFormGroupVo"/>
        <where>
            and del_flag = 0
            <if test="groupKey != null  and groupKey != ''">and group_key = #{groupKey}</if>
            <if test="fGName != null  and fGName != ''">and f_g_name like concat('%', #{fGName}, '%')</if>
            <if test="formKeys != null  and formKeys != ''">and form_keys = #{formKeys}</if>
            <if test="mainTable != null  and mainTable != ''">and main_table = #{mainTable}</if>
            <if test="relationJson != null  and relationJson != ''">and relation_json = #{relationJson}</if>
            <if test="showDataSql != null  and showDataSql != ''">and show_data_sql = #{showDataSql}</if>
            <if test="updateById != null  and updateById != ''">and update_by_id = #{updateById}</if>
            <if test="createById != null  and createById != ''">and create_by_id = #{createById}</if>
        </where>
    </select>
    
    <select id="selectDragFormGroupById" parameterType="Long" resultMap="DragFormGroupResult">
        <include refid="selectDragFormGroupVo"/>
        where id = #{id}
    </select>
    <select id="selectDragFormGroupByGroupKey" parameterType="string" resultMap="DragFormGroupResult">
        <include refid="selectDragFormGroupVo"/>
        where group_key = #{groupKey}
    </select>
        
    <insert id="insertDragFormGroup" parameterType="com.zkqy.system.entity.DragFormGroup" useGeneratedKeys="true" keyProperty="id">
        insert into drag_form_group
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="groupKey != null">group_key,</if>
            <if test="fGName != null">f_g_name,</if>
            <if test="remark != null">remark,</if>
            <if test="formKeys != null">form_keys,</if>
            <if test="mainTable != null">main_table,</if>
            <if test="relationJson != null">relation_json,</if>
            <if test="showDataSql != null">show_data_sql,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateById != null">update_by_id,</if>
            <if test="createTime != null">create_time,</if>
            <if test="createById != null">create_by_id,</if>
            <if test="createBy != null">create_by,</if>
            <if test="delFlag != null">del_flag,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="groupKey != null">#{groupKey},</if>
            <if test="fGName != null">#{fGName},</if>
            <if test="remark != null">#{remark},</if>
            <if test="formKeys != null">#{formKeys},</if>
            <if test="mainTable != null">#{mainTable},</if>
            <if test="relationJson != null">#{relationJson},</if>
            <if test="showDataSql != null">#{showDataSql},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateById != null">#{updateById},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="createById != null">#{createById},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="delFlag != null">#{delFlag},</if>
         </trim>
    </insert>

    <update id="updateDragFormGroup" parameterType="com.zkqy.system.entity.DragFormGroup">
        update drag_form_group
        <trim prefix="SET" suffixOverrides=",">
            <if test="groupKey != null">group_key = #{groupKey},</if>
            <if test="fGName != null">f_g_name = #{fGName},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="formKeys != null">form_keys = #{formKeys},</if>
            <if test="mainTable != null">main_table = #{mainTable},</if>
            <if test="relationJson != null">relation_json = #{relationJson},</if>
            <if test="showDataSql != null">show_data_sql = #{showDataSql},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateById != null">update_by_id = #{updateById},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="createById != null">create_by_id = #{createById},</if>
            <if test="createBy != null">create_by = #{createBy},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteDragFormGroupById" parameterType="Long">
        update {DBNAME}.drag_form_group
        set del_flag = 2 where id = #{id}
    </delete>

    <delete id="deleteDragFormGroupByIds" parameterType="String">
        update {DBNAME}.drag_form_group
        set del_flag = 2 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>
</mapper>