<?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.cm.common.plugin.dao.dynamic.IDynamicFormDao">

    <resultMap id="dynamicFormDTO" type="com.cm.common.plugin.pojo.dtos.dynamic.DynamicFormDTO">
        <id property="id" column="id"/>
        <result property="tableName" column="table_name"/>
        <result property="fieldName" column="field_name"/>
        <result property="fieldExplain" column="field_explain"/>
        <result property="fieldType" column="field_type"/>
        <result property="fieldDefault" column="field_default"/>
        <result property="dictionaryId" column="dictionary_id"/>
        <result property="verifyType" column="verify_type"/>
        <result property="verifyRegular" column="verify_regular"/>
        <result property="fieldSort" column="field_sort"/>
        <result property="listShow" column="list_show"/>
        <result property="listShowWidth" column="list_show_width"/>
        <result property="formShow" column="form_show"/>
        <result property="joinTable" column="join_table"/>
        <result property="joinTableField" column="join_table_field"/>
        <result property="joinTableSort" column="join_table_sort"/>
        <result property="joinTableListShow" column="join_table_list_show"/>
        <result property="joinTableFormShow" column="join_table_form_show"/>
    </resultMap>

    <!-- 保存动态表单 -->
    <insert id="saveDynamicForm" parameterType="map">
        INSERT INTO dynamic_config_form(
            id,
            table_name,
            field_name,
            field_explain,
            field_type,
            field_default,
            dictionary_id,
            verify_type,
            verify_regular,
            field_sort,
            list_show,
            form_show
        ) VALUES(
            #{id},
            #{tableName},
            #{fieldName},
            #{fieldExplain},
            #{fieldType},
            #{fieldDefault},
            #{dictionaryId},
            #{verifyType},
            #{verifyRegular},
            #{fieldSort},
            #{listShow},
            #{formShow}
        )
    </insert>

    <!-- 更新动态表单 -->
    <update id="updateDynamicForm" parameterType="map">
        UPDATE
            dynamic_config_form
        SET
            field_name = #{fieldName},
            field_explain = #{fieldExplain},
            field_type = #{fieldType},
            field_default = #{fieldDefault},
            dictionary_id = #{dictionaryId},
            verify_type = #{verifyType},
            verify_regular = #{verifyRegular},
            field_sort = #{fieldSort},
            list_show = #{listShow},
            form_show = #{formShow}
        WHERE
            table_name = #{tableName}
        AND
            field_name = #{fieldName}
    </update>

    <!-- 动态表单详情 -->
    <select id="listDynamicForm" parameterType="map" resultMap="dynamicFormDTO">
        SELECT
            *
        FROM
            dynamic_config_form
        WHERE
            is_delete = 0
        AND
            table_name = #{tableName}
        <if test="fieldNameList != null and fieldNameList.size > 0">
        AND
            field_name IN
            <foreach collection="fieldNameList" index="index" item="item" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        ORDER BY
            field_sort
    </select>

</mapper>