<?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.EmsFacsAttrMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsFacsAttr" id="EmsFacsAttrResult">
        <result property="id"    column="id"    />
        <result property="facsCode"    column="facs_code"    />
        <result property="attrName"    column="attr_name"    />
        <result property="attrDesc"    column="attr_desc"    />
        <result property="attrValue"    column="attr_value"    />
        <result property="attrUnit"    column="attr_unit"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectEmsFacsAttrVo">
        select id, facs_code, attr_name, attr_desc, attr_value, attr_unit, create_time, update_time from adm_ems_facs_attr
    </sql>

    <select id="selectEmsFacsAttrList" parameterType="com.ruoyi.ems.domain.EmsFacsAttr" resultMap="EmsFacsAttrResult">
        <include refid="selectEmsFacsAttrVo"/>
        <where>  
            <if test="facsCode != null  and facsCode != ''"> and facs_code = #{facsCode}</if>
            <if test="attrName != null  and attrName != ''"> and attr_name like concat('%', #{attrName}, '%')</if>
            <if test="attrDesc != null  and attrDesc != ''"> and attr_desc = #{attrDesc}</if>
            <if test="attrValue != null  and attrValue != ''"> and attr_value = #{attrValue}</if>
            <if test="attrUnit != null  and attrUnit != ''"> and attr_unit = #{attrUnit}</if>
        </where>
    </select>
    
    <select id="selectEmsFacsAttrById" parameterType="Long" resultMap="EmsFacsAttrResult">
        <include refid="selectEmsFacsAttrVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertEmsFacsAttr" parameterType="com.ruoyi.ems.domain.EmsFacsAttr" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_facs_attr
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="facsCode != null and facsCode != ''">facs_code,</if>
            <if test="attrName != null and attrName != ''">attr_name,</if>
            <if test="attrDesc != null">attr_desc,</if>
            <if test="attrValue != null">attr_value,</if>
            <if test="attrUnit != null">attr_unit,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="facsCode != null and facsCode != ''">#{facsCode},</if>
            <if test="attrName != null and attrName != ''">#{attrName},</if>
            <if test="attrDesc != null">#{attrDesc},</if>
            <if test="attrValue != null">#{attrValue},</if>
            <if test="attrUnit != null">#{attrUnit},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
         </trim>
    </insert>

    <insert id="insertEmsFacsAttrBatch" parameterType="java.util.List">
        insert into adm_ems_facs_attr (facs_code, attr_name, attr_desc, attr_value, attr_unit, create_time, update_time) values
        <foreach collection="emsFacsAttrs" item="emsFacsAttr" index="index" separator=",">
            (#{emsFacsAttr.facsCode},#{emsFacsAttr.attrName},#{emsFacsAttr.attrDesc},#{emsFacsAttr.attrValue},#{emsFacsAttr.attrUnit},#{emsFacsAttr.createTime},#{emsFacsAttr.updateTime})
        </foreach>
    </insert>

    <update id="updateEmsFacsAttr" parameterType="com.ruoyi.ems.domain.EmsFacsAttr">
        update adm_ems_facs_attr
        <trim prefix="SET" suffixOverrides=",">
            <if test="facsCode != null and facsCode != ''">facs_code = #{facsCode},</if>
            <if test="attrName != null and attrName != ''">attr_name = #{attrName},</if>
            <if test="attrDesc != null">attr_desc = #{attrDesc},</if>
            <if test="attrValue != null">attr_value = #{attrValue},</if>
            <if test="attrUnit != null">attr_unit = #{attrUnit},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsFacsAttrById" parameterType="Long">
        delete from adm_ems_facs_attr where id = #{id}
    </delete>

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

    <delete id="deleteEmsFacsAttrByFactCode" parameterType="String">
        delete from adm_ems_facs_attr where facs_code = #{facsCode}
    </delete>
</mapper>