<?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.EmsFacsEventMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsFacsEvent" id="EventResult">
        <result property="id"    column="id"    />
        <result property="facsCode"    column="facs_code"    />
        <result property="eventName"    column="event_name"    />
        <result property="eventType"    column="event_type"    />
        <result property="eventDesc"    column="event_desc"    />
        <result property="eventCode"    column="event_code"    />
        <result property="extEventCode"    column="ext_event_code"    />
    </resultMap>

    <sql id="selectEmsFacsEventVo">
        select id, facs_code, event_name, event_type, event_desc, event_code, ext_event_code from adm_ems_facs_event
    </sql>

    <select id="selectEmsFacsEventList" parameterType="com.ruoyi.ems.domain.EmsFacsEvent" resultMap="EventResult">
        <include refid="selectEmsFacsEventVo"/>
        <where>  
            <if test="facsCode != null  and facsCode != ''"> and facs_code = #{facsCode}</if>
            <if test="eventName != null  and eventName != ''"> and event_name like concat('%', #{eventName}, '%')</if>
            <if test="eventType != null "> and event_type = #{eventType}</if>
            <if test="eventDesc != null  and eventDesc != ''"> and event_desc = #{eventDesc}</if>
            <if test="eventCode != null  and eventCode != ''"> and event_code = #{eventCode}</if>
            <if test="extEventCode != null  and extEventCode != ''"> and ext_event_code = #{extEventCode}</if>
        </where>
    </select>
    
    <select id="selectEmsFacsEventById" parameterType="Long" resultMap="EventResult">
        <include refid="selectEmsFacsEventVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertEmsFacsEvent" parameterType="com.ruoyi.ems.domain.EmsFacsEvent" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_facs_event
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="facsCode != null and facsCode != ''">facs_code,</if>
            <if test="eventName != null and eventName != ''">event_name,</if>
            <if test="eventType != null">event_type,</if>
            <if test="eventDesc != null">event_desc,</if>
            <if test="eventCode != null">event_code,</if>
            <if test="extEventCode != null">ext_event_code,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="facsCode != null and facsCode != ''">#{facsCode},</if>
            <if test="eventName != null and eventName != ''">#{eventName},</if>
            <if test="eventType != null">#{eventType},</if>
            <if test="eventDesc != null">#{eventDesc},</if>
            <if test="eventCode != null">#{eventCode},</if>
            <if test="extEventCode != null">#{extEventCode},</if>
         </trim>
    </insert>

    <insert id="insertEmsFacsEventBatch" parameterType="java.util.List">
        insert into adm_ems_facs_event (facs_code, event_name, event_type, event_desc, event_code, ext_event_code) values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.facsCode},#{item.eventName},#{item.eventType},#{item.eventDesc},#{item.eventCode},#{item.extEventCode})
        </foreach>
    </insert>

    <update id="updateEmsFacsEvent" parameterType="com.ruoyi.ems.domain.EmsFacsEvent">
        update adm_ems_facs_event
        <trim prefix="SET" suffixOverrides=",">
            <if test="facsCode != null and facsCode != ''">facs_code = #{facsCode},</if>
            <if test="eventName != null and eventName != ''">event_name = #{eventName},</if>
            <if test="eventType != null">event_type = #{eventType},</if>
            <if test="eventDesc != null">event_desc = #{eventDesc},</if>
            <if test="eventCode != null">event_code = #{eventCode},</if>
            <if test="extEventCode != null">ext_event_code = #{extEventCode},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteEmsFacsEventById" parameterType="Long">
        delete from adm_ems_facs_event where id = #{id}
    </delete>

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

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