<?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.DragTableConditionMapper">
    
    <resultMap type="com.zkqy.system.entity.DragTableCondition" id="DragTableConditionResult">
        <result property="tcId"    column="tc_id"    />
        <result property="tId"    column="t_id"    />
        <result property="conditionName"    column="condition_name"    />
        <result property="conditionField"    column="condition_field"    />
        <result property="conditionNotes"    column="condition_notes"    />
        <result property="conditionType"    column="condition_type"    />
        <result property="conditionDefaultValue"    column="condition_default_value"    />
        <result property="sort"    column="sort"    />
        <result property="conditionTableName"    column="condition_table_name"    />
        <result property="conditionTableFieldName"    column="condition_table_field_name"    />
        <result property="conditionTableFieldKey" column="condition_table_field_key"/>
        <result property="conditionDatasource"    column="condition_datasource"    />
        <result property="componentType"    column="component_type"    />
        <result property="componentSize"    column="component_size"    />
        <result property="componentIcon"    column="component_icon"    />
        <result property="isHidden"    column="is_hidden"    />
        <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>

    <resultMap id="retMap" type="com.zkqy.system.entity.CommonEntity" autoMapping="true">
        <collection property="resultMap" ofType="map" autoMapping="true"
                    javaType="map"></collection>
    </resultMap>

    <sql id="selectDragTableConditionVo">
        select tc_id, t_id, condition_name, condition_field, condition_notes, condition_type, condition_default_value, sort, condition_table_name,
               condition_table_field_name, condition_table_field_key, condition_datasource, component_type, component_size, component_icon, is_hidden, del_flag, create_by, create_time, update_by, update_time from drag_table_condition
    </sql>

    <select id="selectDragTableConditionList" resultMap="retMap">
        select * from drag_table_condition
        <where>
            <if test="conditions != null">
                <foreach collection="conditions" item="value" index="key" separator="and">
                    ${key}=#{value}
                </foreach>
            </if>
        </where>
    </select>
        
    <insert id="insertDragTableCondition">
        insert into drag_table_condition
        <foreach collection="fieldNames" item="fieldName" open="(" close=")" separator=",">
            ${fieldName}
        </foreach>
        values
        <foreach collection="fieldValues" item="map" separator=",">
            <foreach collection="map" item="value" index="key" separator="," open="(" close=")">
                #{value}
            </foreach>
        </foreach>
    </insert>

    <insert id="insertDragTableConditionByList"  parameterType="java.util.List">
        insert into drag_table_condition
        (t_id,condition_field)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.tId},#{item.conditionField})
        </foreach>
    </insert>

    <update id="updateDragTableCondition">
        update drag_table_condition set
        <foreach collection="fields" item="field" index="key" separator=",">
            ${key}=#{field}
        </foreach>
        <where>
            <if test="conditions != null">
                <foreach collection="conditions" item="value" index="key" separator="and">
                    ${key}=#{value}
                </foreach>
            </if>
        </where>
        where tc_id = #{tcId}
    </update>

    <delete id="deleteDragTableConditionByTcIds">
        delete from drag_table_condition
        <where>
            <if test="conditions != null">
                <foreach collection="conditions" item="value" index="key" separator="and">
                    ${key} in
                    <foreach collection="value" item="v" open="(" close=")" separator=",">
                        #{v}
                    </foreach>
                </foreach>
            </if>
        </where>
    </delete>

    <select id="selectDragTableConditionByTid" resultMap="DragTableConditionResult">
        <include refid="selectDragTableConditionVo"/>
        where t_id = #{tId}
    </select>

    <select id="selectDragTableSearchField" resultType="string">
        select condition_field from drag_table_condition where t_id = #{tId}
    </select>

    <delete id="deleteDragTableConditionBytIds">
        delete from drag_table_condition where t_id in
        <foreach item="ids" collection="list" open="(" separator="," close=")">
            #{ids}
        </foreach>
    </delete>



</mapper>