<?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.EmsTagMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsTag" id="emsTagResult">
        <result property="id"    column="id"    />
        <result property="tagModel"    column="tag_model"    />
        <result property="tagCode"    column="tag_code"    />
        <result property="tagName"    column="tag_name"    />
    </resultMap>

    <sql id="selectEmsTagVo">
        select id, tag_model, tag_code, tag_name from dim_ems_tag
    </sql>

    <select id="selectEmsTagList" parameterType="com.ruoyi.ems.domain.EmsTag" resultMap="emsTagResult">
        <include refid="selectEmsTagVo"/>
        <where>  
            <if test="tagModel != null  and tagModel != ''"> and tag_model = #{tagModel}</if>
            <if test="tagCode != null  and tagCode != ''"> and tag_code = #{tagCode}</if>
            <if test="tagName != null  and tagName != ''"> and tag_name like concat('%', #{tagName}, '%')</if>
        </where>
    </select>
    
    <select id="selectEmsTagById" parameterType="Long" resultMap="emsTagResult">
        <include refid="selectEmsTagVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertEmsTag" parameterType="com.ruoyi.ems.domain.EmsTag" useGeneratedKeys="true" keyProperty="id">
        insert into dim_ems_tag
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="tagModel != null and tagModel != ''">tag_model,</if>
            <if test="tagCode != null and tagCode != ''">tag_code,</if>
            <if test="tagName != null and tagName != ''">tag_name,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="tagModel != null and tagModel != ''">#{tagModel},</if>
            <if test="tagCode != null and tagCode != ''">#{tagCode},</if>
            <if test="tagName != null and tagName != ''">#{tagName},</if>
         </trim>
    </insert>

    <update id="updateEmsTag" parameterType="com.ruoyi.ems.domain.EmsTag">
        update dim_ems_tag
        <trim prefix="SET" suffixOverrides=",">
            <if test="tagModel != null and tagModel != ''">tag_model = #{tagModel},</if>
            <if test="tagCode != null and tagCode != ''">tag_code = #{tagCode},</if>
            <if test="tagName != null and tagName != ''">tag_name = #{tagName},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsTagById" parameterType="Long">
        delete from dim_ems_tag where id = #{id}
    </delete>

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