<?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.EmsObjEventMapper">
    
    <resultMap type="com.ruoyi.ems.domain.EmsObjEvent" id="ObjEventResult">
        <result property="id"    column="id"    />
        <result property="modelCode"    column="model_code"    />
        <result property="eventKey"    column="event_key"    />
        <result property="eventType"    column="event_type"    />
        <result property="eventName"    column="event_name"    />
        <result property="eventDesc"    column="event_desc"    />
        <result property="eventCode"    column="event_code"    />
        <result property="extEventCode"    column="ext_event_code"    />
    </resultMap>

    <sql id="selectObjEventVo">
        select id, model_code, event_key, event_type, event_name, event_desc, event_code, ext_event_code from adm_ems_obj_event
    </sql>

    <select id="selectObjEventList" parameterType="com.ruoyi.ems.domain.EmsObjEvent" resultMap="ObjEventResult">
        <include refid="selectObjEventVo"/>
        <where>  
            <if test="modelCode != null  and modelCode != ''"> and model_code = #{modelCode}</if>
            <if test="eventKey != null  and eventKey != ''"> and event_key = #{eventKey}</if>
            <if test="eventType != null "> and event_type = #{eventType}</if>
            <if test="eventName != null  and eventName != ''"> and event_name like concat('%', #{eventName}, '%')</if>
            <if test="eventCode != null  and eventCode != ''"> and event_code = #{eventCode}</if>
        </where>
    </select>

    <select id="selectByModelCode" parameterType="java.lang.String" resultMap="ObjEventResult">
        <include refid="selectObjEventVo"/>
        where model_code = #{modelCode}
    </select>

    <select id="selectObjEventById" parameterType="Long" resultMap="ObjEventResult">
        <include refid="selectObjEventVo"/>
        where id = #{id}
    </select>
        
    <insert id="insertObjEvent" parameterType="com.ruoyi.ems.domain.EmsObjEvent" useGeneratedKeys="true" keyProperty="id">
        insert into adm_ems_obj_event
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="modelCode != null and modelCode != ''">model_code,</if>
            <if test="eventKey != null and eventKey != ''">event_key,</if>
            <if test="eventType != null">event_type,</if>
            <if test="eventName != null and eventName != ''">event_name,</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="modelCode != null and modelCode != ''">#{modelCode},</if>
            <if test="eventKey != null and eventKey != ''">#{eventKey},</if>
            <if test="eventType != null">#{eventType},</if>
            <if test="eventName != null and eventName != ''">#{eventName},</if>
            <if test="eventDesc != null">#{eventDesc},</if>
            <if test="eventCode != null">#{eventCode},</if>
            <if test="extEventCode != null">#{extEventCode},</if>
         </trim>
    </insert>

    <insert id="insertBatch" parameterType="java.util.List">
        insert into adm_ems_obj_event (model_code, event_key, event_type, event_name, event_desc, event_code, ext_event_code)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (#{item.modelCode}, #{item.eventKey}, #{item.eventType}, #{item.eventName}, #{item.eventDesc}, #{item.eventCode}, #{item.extEventCode})
        </foreach>
    </insert>

    <update id="updateObjEvent" parameterType="com.ruoyi.ems.domain.EmsObjEvent">
        update adm_ems_obj_event
        <trim prefix="SET" suffixOverrides=",">
            <if test="modelCode != null and modelCode != ''">model_code = #{modelCode},</if>
            <if test="eventKey != null and eventKey != ''">event_key = #{eventKey},</if>
            <if test="eventType != null">event_type = #{eventType},</if>
            <if test="eventName != null and eventName != ''">event_name = #{eventName},</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="deleteObjEventById" parameterType="Long">
        delete from adm_ems_obj_event where id = #{id}
    </delete>

    <delete id="deleteByModelCode" parameterType="String">
        delete from adm_ems_obj_event where model_code = #{modelCode}
    </delete>

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