<?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.MdDataItemMapper">

    <resultMap type="com.ruoyi.interfaces.domain.MdDataItem" id="MdDataItemResult">
        <result property="dataId"    column="DATA_ID"    />
        <result property="cateId"    column="CATE_ID"    />
        <result property="itemName"    column="ITEM_NAME"    />
        <result property="itemEn"    column="ITEM_EN"    />
        <result property="itemTp"    column="ITEM_TP"    />
        <result property="itemDataTp"    column="ITEM_DATA_TP"    />
        <result property="itemDefaultVal"    column="ITEM_DEFAULT_VAL"    />
        <result property="itemUnit"    column="ITEM_UNIT"    />
        <result property="itemNotes"    column="ITEM_NOTES"    />
        <result property="createby"    column="CREATEBY"    />
        <result property="modifyby"    column="MODIFYBY"    />
    </resultMap>

    <sql id="selectMdDataItemVo">
        select DATA_ID, CATE_ID, ITEM_NAME, ITEM_EN, ITEM_TP, ITEM_DATA_TP, ITEM_DEFAULT_VAL, ITEM_UNIT, ITEM_NOTES, CREATEBY, MODIFYBY from md_data_item
    </sql>

    <select id="selectMdDataItemList" parameterType="com.ruoyi.interfaces.domain.MdDataItem" resultMap="MdDataItemResult">
        <include refid="selectMdDataItemVo"/>
        <where>
            <if test="cateId != null  and cateId != ''"> and CATE_ID = #{cateId}</if>
            <if test="itemName != null  and itemName != ''"> and ITEM_NAME like concat('%', #{itemName}, '%')</if>
            <if test="itemEn != null  and itemEn != ''"> and ITEM_EN = #{itemEn}</if>
            <if test="itemTp != null  and itemTp != ''"> and ITEM_TP = #{itemTp}</if>
            <if test="itemDataTp != null  and itemDataTp != ''"> and ITEM_DATA_TP = #{itemDataTp}</if>
            <if test="itemDefaultVal != null  and itemDefaultVal != ''"> and ITEM_DEFAULT_VAL = #{itemDefaultVal}</if>
            <if test="itemUnit != null  and itemUnit != ''"> and ITEM_UNIT = #{itemUnit}</if>
            <if test="itemNotes != null  and itemNotes != ''"> and ITEM_NOTES = #{itemNotes}</if>
            <if test="createby != null "> and CREATEBY = #{createby}</if>
            <if test="modifyby != null "> and MODIFYBY = #{modifyby}</if>
        </where>
    </select>

    <select id="selectMdDataItemByDataId" parameterType="String" resultMap="MdDataItemResult">
        <include refid="selectMdDataItemVo"/>
        where DATA_ID = #{dataId}
    </select>

    <insert id="insertMdDataItem" parameterType="com.ruoyi.interfaces.domain.MdDataItem">
        insert into md_data_item
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="dataId != null">DATA_ID,</if>
            <if test="cateId != null">CATE_ID,</if>
            <if test="itemName != null">ITEM_NAME,</if>
            <if test="itemEn != null">ITEM_EN,</if>
            <if test="itemTp != null">ITEM_TP,</if>
            <if test="itemDataTp != null">ITEM_DATA_TP,</if>
            <if test="itemDefaultVal != null">ITEM_DEFAULT_VAL,</if>
            <if test="itemUnit != null">ITEM_UNIT,</if>
            <if test="itemNotes != null">ITEM_NOTES,</if>
            <if test="createby != null">CREATEBY,</if>
            <if test="modifyby != null">MODIFYBY,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="dataId != null">#{dataId},</if>
            <if test="cateId != null">#{cateId},</if>
            <if test="itemName != null">#{itemName},</if>
            <if test="itemEn != null">#{itemEn},</if>
            <if test="itemTp != null">#{itemTp},</if>
            <if test="itemDataTp != null">#{itemDataTp},</if>
            <if test="itemDefaultVal != null">#{itemDefaultVal},</if>
            <if test="itemUnit != null">#{itemUnit},</if>
            <if test="itemNotes != null">#{itemNotes},</if>
            <if test="createby != null">#{createby},</if>
            <if test="modifyby != null">#{modifyby},</if>
        </trim>
    </insert>

    <update id="updateMdDataItem" parameterType="com.ruoyi.interfaces.domain.MdDataItem">
        update md_data_item
        <trim prefix="SET" suffixOverrides=",">
            <if test="cateId != null">CATE_ID = #{cateId},</if>
            <if test="itemName != null">ITEM_NAME = #{itemName},</if>
            <if test="itemEn != null">ITEM_EN = #{itemEn},</if>
            <if test="itemTp != null">ITEM_TP = #{itemTp},</if>
            <if test="itemDataTp != null">ITEM_DATA_TP = #{itemDataTp},</if>
            <if test="itemDefaultVal != null">ITEM_DEFAULT_VAL = #{itemDefaultVal},</if>
            <if test="itemUnit != null">ITEM_UNIT = #{itemUnit},</if>
            <if test="itemNotes != null">ITEM_NOTES = #{itemNotes},</if>
            <if test="createby != null">CREATEBY = #{createby},</if>
            <if test="modifyby != null">MODIFYBY = #{modifyby},</if>
        </trim>
        where DATA_ID = #{dataId}
    </update>

    <delete id="deleteMdDataItemByDataId" parameterType="String">
        delete from md_data_item where DATA_ID = #{dataId}
    </delete>

    <delete id="deleteMdDataItemByDataIds" parameterType="String">
        delete from md_data_item where DATA_ID in
        <foreach item="dataId" collection="array" open="(" separator="," close=")">
            #{dataId}
        </foreach>
    </delete>
</mapper>