<?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.ruoyi.interfaces.mapper.MdDataFieldMapper">

    <resultMap type="com.ruoyi.interfaces.domain.MdDataField" id="MdDataFieldResult">
        <result property="dsCode"    column="DS_CODE"    />
        <result property="metaTable"    column="META_TABLE"    />
        <result property="fieldCode"    column="FIELD_CODE"    />
        <result property="fieldName"    column="FIELD_NAME"    />
        <result property="fieldType"    column="FIELD_TYPE"    />
        <result property="fieldLength"    column="FIELD_LENGTH"    />
        <result property="fieldPrecision"    column="FIELD_PRECISION"    />
        <result property="fieldIspri"    column="FIELD_ISPRI"    />
        <result property="fieldIsnullable"    column="FIELD_ISNULLABLE"    />
        <result property="fieldDefault"    column="FIELD_DEFAULT"    />
        <result property="fieldDesc"    column="FIELD_DESC"    />
        <result property="fieldStatus"    column="FIELD_STATUS"    />
        <result property="fieldOrder"    column="FIELD_ORDER"    />
        <result property="fieldExtend"    column="FIELD_EXTEND"    />
        <result property="fieldExtendTable"    column="FIELD_EXTEND_TABLE"    />
        <result property="fieldInputType"    column="FIELD_INPUT_TYPE"    />
        <result property="fieldInputFormat"    column="FIELD_INPUT_FORMAT"    />
        <result property="fieldInputDefault"    column="FIELD_INPUT_DEFAULT"    />
        <result property="fieldViewType"    column="FIELD_VIEW_TYPE"    />
        <result property="fieldDict"    column="FIELD_DICT"    />
    </resultMap>

    <sql id="selectMdDataFieldVo">
        select DS_CODE, META_TABLE, FIELD_CODE, FIELD_NAME, FIELD_TYPE, FIELD_LENGTH, FIELD_PRECISION, FIELD_ISPRI, FIELD_ISNULLABLE, FIELD_DEFAULT, FIELD_DESC, FIELD_STATUS, FIELD_ORDER, FIELD_EXTEND, FIELD_EXTEND_TABLE, FIELD_INPUT_TYPE, FIELD_INPUT_FORMAT, FIELD_INPUT_DEFAULT, FIELD_VIEW_TYPE, FIELD_DICT from md_data_field
    </sql>

    <select id="selectMdDataFieldList" parameterType="com.ruoyi.interfaces.domain.MdDataField" resultMap="MdDataFieldResult">
        <include refid="selectMdDataFieldVo"/>
        <where>
            <if test="fieldName != null  and fieldName != ''"> and FIELD_NAME like concat('%', #{fieldName}, '%')</if>
            <if test="fieldType != null  and fieldType != ''"> and FIELD_TYPE = #{fieldType}</if>
            <if test="fieldLength != null  and fieldLength != ''"> and FIELD_LENGTH = #{fieldLength}</if>
            <if test="fieldPrecision != null  and fieldPrecision != ''"> and FIELD_PRECISION = #{fieldPrecision}</if>
            <if test="fieldIspri != null  and fieldIspri != ''"> and FIELD_ISPRI = #{fieldIspri}</if>
            <if test="fieldIsnullable != null  and fieldIsnullable != ''"> and FIELD_ISNULLABLE = #{fieldIsnullable}</if>
            <if test="fieldDefault != null  and fieldDefault != ''"> and FIELD_DEFAULT = #{fieldDefault}</if>
            <if test="fieldDesc != null  and fieldDesc != ''"> and FIELD_DESC = #{fieldDesc}</if>
            <if test="fieldStatus != null  and fieldStatus != ''"> and FIELD_STATUS = #{fieldStatus}</if>
            <if test="fieldOrder != null "> and FIELD_ORDER = #{fieldOrder}</if>
            <if test="fieldExtend != null  and fieldExtend != ''"> and FIELD_EXTEND = #{fieldExtend}</if>
            <if test="fieldExtendTable != null  and fieldExtendTable != ''"> and FIELD_EXTEND_TABLE = #{fieldExtendTable}</if>
            <if test="fieldInputType != null  and fieldInputType != ''"> and FIELD_INPUT_TYPE = #{fieldInputType}</if>
            <if test="fieldInputFormat != null  and fieldInputFormat != ''"> and FIELD_INPUT_FORMAT = #{fieldInputFormat}</if>
            <if test="fieldInputDefault != null  and fieldInputDefault != ''"> and FIELD_INPUT_DEFAULT = #{fieldInputDefault}</if>
            <if test="fieldViewType != null  and fieldViewType != ''"> and FIELD_VIEW_TYPE = #{fieldViewType}</if>
            <if test="fieldDict != null  and fieldDict != ''"> and FIELD_DICT = #{fieldDict}</if>
        </where>
        order by FIELD_ORDER
    </select>

    <select id="selectMdDataFieldByDsCode" parameterType="String" resultMap="MdDataFieldResult">
        <include refid="selectMdDataFieldVo"/>
        where DS_CODE = #{dsCode}
    </select>

    <insert id="insertMdDataField" parameterType="com.ruoyi.interfaces.domain.MdDataField">
        insert into md_data_field
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dsCode != null">DS_CODE,</if>
            <if test="metaTable != null">META_TABLE,</if>
            <if test="fieldCode != null">FIELD_CODE,</if>
            <if test="fieldName != null">FIELD_NAME,</if>
            <if test="fieldType != null">FIELD_TYPE,</if>
            <if test="fieldLength != null">FIELD_LENGTH,</if>
            <if test="fieldPrecision != null">FIELD_PRECISION,</if>
            <if test="fieldIspri != null">FIELD_ISPRI,</if>
            <if test="fieldIsnullable != null">FIELD_ISNULLABLE,</if>
            <if test="fieldDefault != null">FIELD_DEFAULT,</if>
            <if test="fieldDesc != null">FIELD_DESC,</if>
            <if test="fieldStatus != null">FIELD_STATUS,</if>
            <if test="fieldOrder != null">FIELD_ORDER,</if>
            <if test="fieldExtend != null">FIELD_EXTEND,</if>
            <if test="fieldExtendTable != null">FIELD_EXTEND_TABLE,</if>
            <if test="fieldInputType != null">FIELD_INPUT_TYPE,</if>
            <if test="fieldInputFormat != null">FIELD_INPUT_FORMAT,</if>
            <if test="fieldInputDefault != null">FIELD_INPUT_DEFAULT,</if>
            <if test="fieldViewType != null">FIELD_VIEW_TYPE,</if>
            <if test="fieldDict != null">FIELD_DICT,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dsCode != null">#{dsCode},</if>
            <if test="metaTable != null">#{metaTable},</if>
            <if test="fieldCode != null">#{fieldCode},</if>
            <if test="fieldName != null">#{fieldName},</if>
            <if test="fieldType != null">#{fieldType},</if>
            <if test="fieldLength != null">#{fieldLength},</if>
            <if test="fieldPrecision != null">#{fieldPrecision},</if>
            <if test="fieldIspri != null">#{fieldIspri},</if>
            <if test="fieldIsnullable != null">#{fieldIsnullable},</if>
            <if test="fieldDefault != null">#{fieldDefault},</if>
            <if test="fieldDesc != null">#{fieldDesc},</if>
            <if test="fieldStatus != null">#{fieldStatus},</if>
            <if test="fieldOrder != null">#{fieldOrder},</if>
            <if test="fieldExtend != null">#{fieldExtend},</if>
            <if test="fieldExtendTable != null">#{fieldExtendTable},</if>
            <if test="fieldInputType != null">#{fieldInputType},</if>
            <if test="fieldInputFormat != null">#{fieldInputFormat},</if>
            <if test="fieldInputDefault != null">#{fieldInputDefault},</if>
            <if test="fieldViewType != null">#{fieldViewType},</if>
            <if test="fieldDict != null">#{fieldDict},</if>
        </trim>
    </insert>

    <update id="updateMdDataField" parameterType="com.ruoyi.interfaces.domain.MdDataField">
        update md_data_field
        <trim prefix="SET" suffixOverrides=",">

            <if test="fieldName != null">FIELD_NAME = #{fieldName},</if>
            <if test="fieldType != null">FIELD_TYPE = #{fieldType},</if>
            <if test="fieldLength != null">FIELD_LENGTH = #{fieldLength},</if>
            <if test="fieldPrecision != null">FIELD_PRECISION = #{fieldPrecision},</if>
            <if test="fieldIspri != null">FIELD_ISPRI = #{fieldIspri},</if>
            <if test="fieldIsnullable != null">FIELD_ISNULLABLE = #{fieldIsnullable},</if>
            <if test="fieldDefault != null">FIELD_DEFAULT = #{fieldDefault},</if>
            <if test="fieldDesc != null">FIELD_DESC = #{fieldDesc},</if>
            <if test="fieldStatus != null">FIELD_STATUS = #{fieldStatus},</if>
            <if test="fieldOrder != null">FIELD_ORDER = #{fieldOrder},</if>
            <if test="fieldExtend != null">FIELD_EXTEND = #{fieldExtend},</if>
            <if test="fieldExtendTable != null">FIELD_EXTEND_TABLE = #{fieldExtendTable},</if>
            <if test="fieldInputType != null">FIELD_INPUT_TYPE = #{fieldInputType},</if>
            <if test="fieldInputFormat != null">FIELD_INPUT_FORMAT = #{fieldInputFormat},</if>
            <if test="fieldInputDefault != null">FIELD_INPUT_DEFAULT = #{fieldInputDefault},</if>
            <if test="fieldViewType != null">FIELD_VIEW_TYPE = #{fieldViewType},</if>
            <if test="fieldDict != null">FIELD_DICT = #{fieldDict},</if>
        </trim>
        where DS_CODE = #{dsCode} and
        META_TABLE = #{metaTable} and
        FIELD_CODE = #{fieldCode}
    </update>

    <delete id="deleteMdDataFieldByDsCode" parameterType="String">
        delete from md_data_field where DS_CODE = #{dsCode}
    </delete>

    <delete id="deleteMdDataFieldByDsCodes" parameterType="String">
        delete from md_data_field where DS_CODE in
        <foreach item="dsCode" collection="array" open="(" separator="," close=")">
            #{dsCode}
        </foreach>
    </delete>
    <delete id="deleteMdDataFieldOne">
        delete
        from md_data_field
        where DS_CODE = #{dsCode}
          and meta_Table = #{metaTable}
          and field_Code = #{fieldCode}
    </delete>
</mapper>