<?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.ems.mapper.EmsObjAttrValueMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsObjAttrValue" id="objAttrValueResult">
        <result property="id"    column="id"    />
        <result property="objCode"    column="obj_code"    />
        <result property="objType"    column="obj_type"    />
        <result property="attrKey"    column="attr_key"    />
        <result property="attrName"    column="attr_name"    />
        <result property="attrValue"    column="attr_value"    />
        <result property="modelCode"    column="model_code"    />
    </resultMap>

    <sql id="selectObjAttrValueVo">
        select id, obj_code, obj_type, attr_key, attr_name, attr_value, model_code from adm_ems_obj_attr_value
    </sql>

    <select id="selectObjAttrValueList" parameterType="com.ruoyi.ems.domain.EmsObjAttrValue" resultMap="objAttrValueResult">
        <include refid="selectObjAttrValueVo"/>
        <where>  
            <if test="objCode != null  and objCode != ''"> and obj_code = #{objCode}</if>
            <if test="objType != null "> and obj_type = #{objType}</if>
            <if test="attrKey != null  and attrKey != ''"> and attr_key = #{attrKey}</if>
            <if test="modelCode != null  and modelCode != ''"> and model_code = #{modelCode}</if>
        </where>
    </select>

    <select id="selectByObjCode" resultMap="objAttrValueResult">
        <include refid="selectObjAttrValueVo"/>
        where obj_type = #{objType} and obj_code = #{objCode}
    </select>

    <select id="selectObjAttrValueById" parameterType="Long" resultMap="objAttrValueResult">
        <include refid="selectObjAttrValueVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertObjAttrValue" parameterType="com.ruoyi.ems.domain.EmsObjAttrValue" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_obj_attr_value
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="objCode != null and objCode != ''">obj_code,</if>
            <if test="objType != null">obj_type,</if>
            <if test="attrKey != null and attrKey != ''">attr_key,</if>
            <if test="attrName != null and attrName != ''">attr_name,</if>
            <if test="attrValue != null">attr_value,</if>
            <if test="modelCode != null">model_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="objCode != null and objCode != ''">#{objCode},</if>
            <if test="objType != null">#{objType},</if>
            <if test="attrKey != null and attrKey != ''">#{attrKey},</if>
            <if test="attrName != null and attrName != ''">#{attrName},</if>
            <if test="attrValue != null">#{attrValue},</if>
            <if test="modelCode != null">#{modelCode},</if>
         </trim>
    </insert>

    <insert id="insertBatch" parameterType="java.util.List" >
        insert into adm_ems_obj_attr_value (obj_code, obj_type, attr_key, attr_name, attr_value, model_code)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.objCode}, #{item.objType}, #{item.attrKey}, #{item.attrName}, #{item.attrValue}, #{item.modelCode})
        </foreach>
    </insert>

    <update id="updateObjAttrValue" parameterType="com.ruoyi.ems.domain.EmsObjAttrValue">
        update adm_ems_obj_attr_value
        <trim prefix="SET" suffixOverrides=",">
            <if test="objCode != null and objCode != ''">obj_code = #{objCode},</if>
            <if test="objType != null">obj_type = #{objType},</if>
            <if test="attrKey != null and attrKey != ''">attr_key = #{attrKey},</if>
            <if test="attrName != null and attrName != ''">attr_name = #{attrName},</if>
            <if test="attrValue != null">attr_value = #{attrValue},</if>
            <if test="modelCode != null">model_code = #{modelCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteObjAttrValueById" parameterType="Long">
        delete from adm_ems_obj_attr_value where id = #{id}
    </delete>

    <delete id="deleteByObjCode" >
        delete from adm_ems_obj_attr_value where obj_type = #{objType} and obj_code = #{objCode}
    </delete>

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