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

    <resultMap type="EmsObjAttrEnum" id="EmsObjAttrEnumResult">
        <result property="id" column="id"/>
        <result property="modelCode" column="model_code"/>
        <result property="attrKey" column="attr_key"/>
        <result property="attrValue" column="attr_value"/>
        <result property="attrValueName" column="attr_value_name"/>
    </resultMap>

    <sql id="selectEmsObjAttrEnumVo">
        select id, model_code, attr_key, attr_value, attr_value_name
        from adm_ems_obj_attr_enum
    </sql>

    <select id="selectObjAttrEnum" resultMap="EmsObjAttrEnumResult">
        <include refid="selectEmsObjAttrEnumVo"/>
        <where>
            <if test="modelCode != null  and modelCode != ''">and model_code = #{modelCode}</if>
            <if test="attrKey != null  and attrKey != ''">and attr_key = #{attrKey}</if>
            <if test="attrValue != null  and attrValue != ''">and attr_value = #{attrValue}</if>
        </where>
    </select>

    <select id="selectObjAttrEnumList" resultMap="EmsObjAttrEnumResult">
        <include refid="selectEmsObjAttrEnumVo"/>
        <where>
            <if test="modelCode != null  and modelCode != ''">and model_code = #{modelCode}</if>
            <if test="attrKey != null  and attrKey != ''">and attr_key = #{attrKey}</if>
        </where>
    </select>

    <insert id="insertObjAttrEnum" parameterType="EmsObjAttrEnum" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_obj_attr_enum
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="modelCode != null and modelCode != ''">model_code,</if>
            <if test="attrKey != null and attrKey != ''">attr_key,</if>
            <if test="attrValue != null and attrValue != ''">attr_value,</if>
            <if test="attrValueName != null">attr_value_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="modelCode != null and modelCode != ''">#{modelCode},</if>
            <if test="attrKey != null and attrKey != ''">#{attrKey},</if>
            <if test="attrValue != null and attrValue != ''">#{attrValue},</if>
            <if test="attrValueName != null">#{attrValueName},</if>
        </trim>
    </insert>

    <insert id="insertObjAttrEnumBatch" parameterType="java.util.List">
        insert into adm_ems_obj_attr_enum (model_code, attr_key, attr_value, attr_value_name) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.modelCode}, #{item.attrKey}, #{item.attrValue}, #{item.attrValueName})
        </foreach>
    </insert>

    <delete id="deleteByModelCode" parameterType="java.lang.String">
        delete
        from adm_ems_obj_attr_enum
        where model_code = #{modelCode}
    </delete>

    <delete id="deleteById">
        delete
        from adm_ems_obj_attr_enum
        where id = #{id}
    </delete>
</mapper>