<?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.DragTableStatisticMapper">
    
    <resultMap type="com.zkqy.system.entity.DragTableStatistic" id="DragTableStatisticResult">
        <result property="id"    column="id"    />
        <result property="statisticTitle"    column="statistic_title"    />
        <result property="tableKey"    column="table_key"    />
        <result property="statisticDescription"    column="statistic_description"    />
        <result property="statisticType"    column="statistic_type"    />
        <result property="statisticField"    column="statistic_field"    />
        <result property="statisticObject"    column="statistic_object"    />
        <result property="sqlKey"    column="sql_key"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="createBy"    column="create_by"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateBy"    column="update_by"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectDragTableStatisticVo">
        select id, statistic_title, table_key, statistic_description, statistic_type, statistic_field, statistic_object, sql_key, del_flag, create_by, create_time, update_by, update_time from drag_table_statistic
    </sql>

    <select id="selectDragTableStatisticList" parameterType="com.zkqy.system.entity.DragTableStatistic" resultMap="DragTableStatisticResult">
        <include refid="selectDragTableStatisticVo"/>
        where  del_flag = '0'
            <if test="statisticTitle != null  and statisticTitle != ''"> and statistic_title = #{statisticTitle}</if>
            <if test="tableKey != null  and tableKey != ''"> and table_key = #{tableKey}</if>
            <if test="statisticDescription != null  and statisticDescription != ''"> and statistic_description = #{statisticDescription}</if>
            <if test="statisticType != null "> and statistic_type = #{statisticType}</if>
            <if test="statisticField != null  and statisticField != ''"> and statistic_field = #{statisticField}</if>
            <if test="statisticObject != null  and statisticObject != ''"> and statistic_object = #{statisticObject}</if>
    </select>

    <select id="selectDragTableStatisticById" parameterType="Long" resultMap="DragTableStatisticResult">
        <include refid="selectDragTableStatisticVo"/>
        where id = #{id}
    </select>
        
    <insert id="batchInsertDragTableStatistic" useGeneratedKeys="true" keyProperty="id">
        insert into drag_table_statistic
            (statistic_title,table_key,statistic_description,statistic_type,statistic_field,statistic_object,sql_key,create_by_id,create_by,create_time,del_flag)
            values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.statisticTitle},#{item.tableKey},#{item.statisticDescription},#{item.statisticType},#{item.statisticField},#{item.statisticObject},
             #{item.sqlKey},#{item.createById},#{item.createBy},#{item.createTime},'0')
        </foreach>
    </insert>

    <insert id="insertDragTableStatistic" parameterType="com.zkqy.system.entity.DragTableStatistic" >
        insert into drag_table_statistic
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="statisticTitle != null">statistic_title,</if>
            <if test="tableKey != null">table_key,</if>
            <if test="statisticDescription != null">statistic_description,</if>
            <if test="statisticType != null">statistic_type,</if>
            <if test="statisticField != null">statistic_field,</if>
            <if test="statisticObject != null">statistic_object,</if>
            <if test="executeSql != null">execute_sql,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="createBy != null">create_by,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateBy != null">update_by,</if>
            <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="statisticTitle != null">#{statisticTitle},</if>
            <if test="tableKey != null">#{tableKey},</if>
            <if test="statisticDescription != null">#{statisticDescription},</if>
            <if test="statisticType != null">#{statisticType},</if>
            <if test="statisticField != null">#{statisticField},</if>
            <if test="statisticObject != null">#{statisticObject},</if>
            <if test="executeSql != null">#{executeSql},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="createBy != null">#{createBy},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateBy != null">#{updateBy},</if>
            <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateDragTableStatistic">
        update drag_table_statistic
        <trim prefix="SET" suffixOverrides=",">
            <if test="statisticTitle != null">statistic_title = #{statisticTitle},</if>
            <if test="tableKey != null">table_key = #{tableKey},</if>
            <if test="statisticDescription != null">statistic_description = #{statisticDescription},</if>
            <if test="statisticType != null">statistic_type = #{statisticType},</if>
            <if test="statisticField != null">statistic_field = #{statisticField},</if>
            <if test="statisticObject != null">statistic_object = #{statisticObject},</if>
            <if test="sqlKey != null">sql_key = #{sqlKey},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="deleteDragTableStatisticByTableKey" parameterType="String">
        update drag_table_statistic set del_flag = '2' where table_key = #{tableKey}
    </update>

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

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

    <select id="selectIdsByTableKey" parameterType="String" resultType="Long">
        select id from drag_table_statistic where del_flag = '0' and table_key = #{tableKey}
    </select>

    <select id="selectSqlKeyByTableKey" parameterType="String" resultType="String">
        select sql_key from drag_table_statistic where del_flag = '0' and table_key = #{tableKey}
    </select>
</mapper>