<?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="cn.com.tenlion.configtable.dao.configtablefield.IConfigTableFieldDao">

    <resultMap id="configTableFieldDTO" type="cn.com.tenlion.configtable.pojo.dtos.configtablefield.ConfigTableFieldDTO">
        <result column="config_table_field_id" property="configTableFieldId"/>
        <result column="config_table_field_code" property="configTableFieldCode"/>
        <result column="config_table_field_name" property="configTableFieldName"/>
        <result column="config_table_field_remark" property="configTableFieldRemark"/>
        <result column="config_table_field_type" property="configTableFieldType"/>
        <result column="config_table_field_number" property="configTableFieldNumber"/>
        <result column="config_table_field_order" property="configTableFieldOrder"/>
        <result column="config_table_field_row" property="configTableFieldRow"/>
        <result column="config_table_field_row_col" property="configTableFieldRowCol"/>
        <result column="config_table_field_must" property="configTableFieldMust"/>
        <result column="config_table_field_dictionaries" property="configTableFieldDictionaries"/>
        <result column="config_table_field_mode" property="configTableFieldMode"/>
        <result column="config_table_field_display" property="configTableFieldDisplay"/>
        <result column="config_table_field_placeholder" property="configTableFieldPlaceholder"/>
        <result column="config_table_field_default" property="configTableFieldDefault"/>
        <result column="config_table_field_config" property="configTableFieldConfig"/>
        <result column="config_table_id" property="configTableId"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="configTableFieldBO" type="cn.com.tenlion.configtable.pojo.bos.configtablefield.ConfigTableFieldBO">
        <result column="config_table_field_id" property="configTableFieldId"/>
        <result column="config_table_field_code" property="configTableFieldCode"/>
        <result column="config_table_field_name" property="configTableFieldName"/>
        <result column="config_table_field_remark" property="configTableFieldRemark"/>
        <result column="config_table_field_type" property="configTableFieldType"/>
        <result column="config_table_field_number" property="configTableFieldNumber"/>
        <result column="config_table_field_order" property="configTableFieldOrder"/>
        <result column="config_table_field_row" property="configTableFieldRow"/>
        <result column="config_table_field_row_col" property="configTableFieldRowCol"/>
        <result column="config_table_field_must" property="configTableFieldMust"/>
        <result column="config_table_id" property="configTableId"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <resultMap id="configTableFieldPO" type="cn.com.tenlion.configtable.pojo.pos.configtablefield.ConfigTableFieldPO">
        <result column="config_table_field_id" property="configTableFieldId"/>
        <result column="config_table_field_code" property="configTableFieldCode"/>
        <result column="config_table_field_name" property="configTableFieldName"/>
        <result column="config_table_field_remark" property="configTableFieldRemark"/>
        <result column="config_table_field_type" property="configTableFieldType"/>
        <result column="config_table_field_number" property="configTableFieldNumber"/>
        <result column="config_table_field_order" property="configTableFieldOrder"/>
        <result column="config_table_field_row" property="configTableFieldRow"/>
        <result column="config_table_field_row_col" property="configTableFieldRowCol"/>
        <result column="config_table_field_must" property="configTableFieldMust"/>
        <result column="config_table_id" property="configTableId"/>
        <result column="creator" property="creator"/>
        <result column="gmt_create" property="gmtCreate"/>
        <result column="modifier" property="modifier"/>
        <result column="gmt_modified" property="gmtModified"/>
        <result column="is_delete" property="isDelete"/>
    </resultMap>

    <!-- 更新排序与布局 -->
    <update id="updateOrder" parameterType="map">
        UPDATE
            m_config_table_field
        SET
        <if test="configTableFieldName != null and configTableFieldName != ''">
            config_table_field_name = #{configTableFieldName},
        </if>
        <if test="configTableFieldPlaceholder != null and configTableFieldPlaceholder != ''">
            config_table_field_placeholder = #{configTableFieldPlaceholder},
        </if>
        <if test="configTableFieldConfig != null and configTableFieldConfig != ''">
            config_table_field_config = #{configTableFieldConfig},
        </if>
            config_table_field_display = #{configTableFieldDisplay},
            config_table_field_must = #{configTableFieldMust},
            config_table_field_default = #{configTableFieldDefault},
            config_table_field_row = #{configTableFieldRow},
            config_table_field_row_col = #{configTableFieldRowCol},
            config_table_field_order = #{configTableFieldOrder}
        WHERE
            config_table_field_id = #{configTableFieldId} AND config_table_id = #{configTableId}
    </update>

    <!-- 编号查询用于重复编号排查 -->
    <select id="getTableFieldCode" parameterType="map" resultMap="configTableFieldDTO">
        SELECT
            t1.config_table_field_code,
            t1.config_table_field_name,
            t1.config_table_field_remark,
            t1.config_table_field_type,
            t1.config_table_field_number,
            t1.config_table_field_order,
            t1.config_table_field_row,
            t1.config_table_field_row_col,
            t1.config_table_field_must,
            t1.config_table_field_id,
            t1.config_table_id,
            t1.config_table_field_dictionaries,
            t1.config_table_field_mode,
            t1.config_table_field_display,
            t1.config_table_field_config
        FROM
            m_config_table_field t1
        WHERE
            t1.is_delete = 0 AND t1.config_table_field_code = #{configTableFieldCode} AND t1.config_table_id = #{configTableId}
    </select>

    <!-- 新增 -->
    <insert id="save" parameterType="map">
        INSERT INTO m_config_table_field(
            config_table_field_id,
            config_table_field_code,
            config_table_field_name,
            config_table_field_remark,
            config_table_field_type,
            config_table_field_number,
            config_table_field_order,
            config_table_field_row,
            config_table_field_row_col,
            config_table_field_must,
            config_table_id,
            config_table_field_dictionaries,
            config_table_field_mode,
            config_table_field_display,
            config_table_field_placeholder,
            config_table_field_default,
            config_table_field_config,
            creator,
            gmt_create,
            modifier,
            gmt_modified,
            is_delete
        ) VALUES(
            #{configTableFieldId},
            #{configTableFieldCode},
            #{configTableFieldName},
            #{configTableFieldRemark},
            #{configTableFieldType},
            #{configTableFieldNumber},
            #{configTableFieldOrder},
            #{configTableFieldRow},
            12,
            #{configTableFieldMust},
            #{configTableId},
            #{configTableFieldDictionaries},
            #{configTableFieldMode},
            #{configTableFieldDisplay},
            #{configTableFieldPlaceholder},
            #{configTableFieldDefault},
            #{configTableFieldConfig},
            #{creator},
            #{gmtCreate},
            #{modifier},
            #{gmtModified},
            #{isDelete}
        )
    </insert>

    <!-- 删除 -->
    <update id="remove" parameterType="map">
        UPDATE
            m_config_table_field
        SET
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            is_delete = 1
        WHERE
            config_table_field_id IN
        <foreach collection="configTableFieldIds" index="index" open="(" separator="," close=")">
            #{configTableFieldIds[${index}]}
        </foreach>
    </update>

    <!-- 删除（物理） -->
    <update id="delete" parameterType="map">
        DELETE FROM
            m_config_table_field
        WHERE
            config_table_field_id IN
        <foreach collection="configTableFieldIds" index="index" open="(" separator="," close=")">
            #{configTableFieldIds[${index}]}
        </foreach>
    </update>

    <!-- 修改 -->
    <update id="update" parameterType="map">
        UPDATE
            m_config_table_field
        SET
        <if test="configTableFieldCode != null and configTableFieldCode != ''">
            config_table_field_code = #{configTableFieldCode},
        </if>
        <if test="configTableFieldName != null and configTableFieldName != ''">
            config_table_field_name = #{configTableFieldName},
        </if>
        <if test="configTableFieldRemark != null and configTableFieldRemark != ''">
            config_table_field_remark = #{configTableFieldRemark},
        </if>
        <if test="configTableFieldType != null and configTableFieldType != ''">
            config_table_field_type = #{configTableFieldType},
        </if>
        <if test="configTableFieldNumber != null and configTableFieldNumber != 0">
            config_table_field_number = #{configTableFieldNumber},
        </if>
        <if test="configTableFieldOrder != null and configTableFieldOrder != 0">
            config_table_field_order = #{configTableFieldOrder},
        </if>
        <if test="configTableFieldRow != null and configTableFieldRow != 0">
            config_table_field_row = #{configTableFieldRow},
        </if>
        <if test="configTableFieldRowCol != null and configTableFieldRowCol != null">
            config_table_field_row_col = #{configTableFieldRowCol},
        </if>
        <if test="configTableFieldMust != null and configTableFieldMust != ''">
            config_table_field_must = #{configTableFieldMust},
        </if>
        <if test="configTableFieldDisplay != null and configTableFieldDisplay != ''">
            config_table_field_display = #{configTableFieldDisplay},
        </if>
        <if test="configTableFieldConfig != null and configTableFieldConfig != ''">
            config_table_field_config = #{configTableFieldConfig},
        </if>
            config_table_field_placeholder = #{configTableFieldPlaceholder},
            config_table_field_default = #{configTableFieldDefault},
            config_table_field_mode = #{configTableFieldMode},
            config_table_field_dictionaries = #{configTableFieldDictionaries},
            gmt_modified = #{gmtModified},
            modifier = #{modifier},
            config_table_field_id = config_table_field_id
        WHERE
            config_table_field_id = #{configTableFieldId}
    </update>

    <!-- 详情 -->
    <select id="get" parameterType="map" resultMap="configTableFieldDTO">
        SELECT
            t1.config_table_field_code,
            t1.config_table_field_name,
            t1.config_table_field_remark,
            t1.config_table_field_type,
            t1.config_table_field_number,
            t1.config_table_field_order,
            t1.config_table_field_row,
            t1.config_table_field_row_col,
            t1.config_table_field_must,
            t1.config_table_field_id,
            t1.config_table_id,
            t1.config_table_field_dictionaries,
            t1.config_table_field_mode,
            t1.config_table_field_display,
            t1.config_table_field_placeholder,
            t1.config_table_field_default,
            t1.config_table_field_config
        FROM
            m_config_table_field t1
        WHERE
            t1.is_delete = 0
            <if test="configTableFieldId != null and configTableFieldId != ''">
        AND
            t1.config_table_field_id = #{configTableFieldId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getBO" parameterType="map" resultMap="configTableFieldBO">
        SELECT
            t1.config_table_field_id,
            t1.config_table_field_code,
            t1.config_table_field_name,
            t1.config_table_field_remark,
            t1.config_table_field_type,
            t1.config_table_field_number,
            t1.config_table_field_order,
            t1.config_table_field_row,
            t1.config_table_field_row_col,
            t1.config_table_field_must,
            t1.config_table_id,
            t1.config_table_field_dictionaries,
            t1.config_table_field_mode,
            t1.config_table_field_display,
            t1.config_table_field_placeholder,
            t1.config_table_field_default,
            t1.config_table_field_config,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_config_table_field t1
        WHERE
            t1.is_delete = 0
            <if test="configTableFieldId != null and configTableFieldId != ''">
        AND
            t1.config_table_field_id = #{configTableFieldId}
            </if>
    </select>

    <!-- 详情 -->
    <select id="getPO" parameterType="map" resultMap="configTableFieldPO">
        SELECT
            t1.config_table_field_id,
            t1.config_table_field_code,
            t1.config_table_field_name,
            t1.config_table_field_remark,
            t1.config_table_field_type,
            t1.config_table_field_number,
            t1.config_table_field_order,
            t1.config_table_field_row,
            t1.config_table_field_row_col,
            t1.config_table_field_must,
            t1.config_table_id,
            t1.config_table_field_dictionaries,
            t1.config_table_field_mode,
            t1.config_table_field_display,
            t1.config_table_field_placeholder,
            t1.config_table_field_default,
            t1.config_table_field_config,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_config_table_field t1
        WHERE
            t1.is_delete = 0
            <if test="configTableFieldId != null and configTableFieldId != ''">
        AND
            t1.config_table_field_id = #{configTableFieldId}
            </if>
    </select>

    <!-- 列表 -->
    <select id="list" parameterType="map" resultMap="configTableFieldDTO">
        SELECT
            t1.config_table_field_id,
            t1.config_table_field_code,
            t1.config_table_field_name,
            t1.config_table_field_remark,
            t1.config_table_field_type,
            t1.config_table_field_number,
            t1.config_table_field_order,
            t1.config_table_field_row,
            t1.config_table_field_row_col,
            t1.config_table_field_must,
            t1.config_table_id,
            t1.config_table_field_dictionaries,
            t1.config_table_field_mode,
            t1.config_table_field_display,
            t1.config_table_field_placeholder,
            t1.config_table_field_default,
            t1.config_table_field_config,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete,
            1
        FROM
            m_config_table_field t1
        WHERE
            t1.is_delete = 0
        <if test="configTableId != null and configTableId != ''">
            AND t1.config_table_id = #{configTableId}
        </if>
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
            AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="configTableFieldIds != null and configTableFieldIds.size > 0">
        AND
            t1.config_table_field_id IN
            <foreach collection="configTableFieldIds" index="index" open="(" separator="," close=")">
                #{configTableFieldIds[${index}]}
            </foreach>
        </if>
        ORDER BY t1.config_table_field_order
    </select>

    <!-- 列表 -->
    <select id="listBO" parameterType="map" resultMap="configTableFieldBO">
        SELECT
            t1.config_table_field_id,
            t1.config_table_field_code,
            t1.config_table_field_name,
            t1.config_table_field_remark,
            t1.config_table_field_type,
            t1.config_table_field_number,
            t1.config_table_field_order,
            t1.config_table_field_row,
            t1.config_table_field_row_col,
            t1.config_table_field_must,
            t1.config_table_id,
            t1.config_table_field_dictionaries,
            t1.config_table_field_mode,
            t1.config_table_field_display,
            t1.config_table_field_placeholder,
            t1.config_table_field_default,
            t1.config_table_field_config,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_config_table_field t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="configTableFieldIds != null and configTableFieldIds.size > 0">
        AND
            t1.config_table_field_id IN
            <foreach collection="configTableFieldIds" index="index" open="(" separator="," close=")">
                #{configTableFieldIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 列表 -->
    <select id="listPO" parameterType="map" resultMap="configTableFieldPO">
        SELECT
            t1.config_table_field_id,
            t1.config_table_field_code,
            t1.config_table_field_name,
            t1.config_table_field_remark,
            t1.config_table_field_type,
            t1.config_table_field_number,
            t1.config_table_field_order,
            t1.config_table_field_row,
            t1.config_table_field_row_col,
            t1.config_table_field_must,
            t1.config_table_id,
            t1.config_table_field_dictionaries,
            t1.config_table_field_mode,
            t1.config_table_field_display,
            t1.config_table_field_placeholder,
            t1.config_table_field_default,
            t1.config_table_field_config,
            t1.creator,
            t1.gmt_create,
            t1.modifier,
            t1.gmt_modified,
            t1.is_delete
        FROM
            m_config_table_field t1
        WHERE
            t1.is_delete = 0
        <if test="keywords != null and keywords != ''">
        AND (
            <!-- 这里添加其他条件 -->
            t1.id LIKE CONCAT('%', #{keywords}, '%')
        )
        </if>
        <if test="startTime != null and startTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ >= ]]> #{startTime}
        </if>
        <if test="endTime != null and endTime != ''">
        AND
            LEFT(t1.gmt_create, 10) <![CDATA[ <= ]]> #{endTime}
        </if>
        <if test="configTableFieldIds != null and configTableFieldIds.size > 0">
        AND
            t1.config_table_field_id IN
            <foreach collection="configTableFieldIds" index="index" open="(" separator="," close=")">
                #{configTableFieldIds[${index}]}
            </foreach>
        </if>
    </select>

    <!-- 统计  -->
    <select id="count" parameterType="map" resultType="Integer">
        SELECT
            COUNT(*)
        FROM
            m_config_table_field t1
        WHERE
            t1.is_delete = 0
    </select>

</mapper>