<?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.aucma.production.mapper.AndonEventLogMapper">

    <resultMap type="AndonEventLog" id="AndonEventLogResult">
            <result property="logId"    column="log_id"    />
            <result property="eventId"    column="event_id"    />
            <result property="operation"    column="operation"    />
            <result property="content"    column="content"    />
            <result property="operatorUserId"    column="operator_user_id"    />
            <result property="operatorUserName"    column="operator_user_name"    />
            <result property="operationTime"    column="operation_time"    />
            <result property="remark"    column="remark"    />
            <result property="createBy"    column="create_by"    />
            <result property="createTime"    column="create_time"    />
            <result property="updateBy"    column="update_by"    />
            <result property="updateTime"    column="update_time"    />
    </resultMap>

    <sql id="selectAndonEventLogVo">
        select log_id, event_id, operation, content, operator_user_id, operator_user_name, operation_time, remark, create_by, create_time, update_by, update_time from andon_event_log
    </sql>

    <select id="selectAndonEventLogList" parameterType="AndonEventLog" resultMap="AndonEventLogResult">
        <include refid="selectAndonEventLogVo"/>
        <where>
                        <if test="eventId != null "> and event_id = #{eventId}</if>
                        <if test="operation != null  and operation != ''"> and operation = #{operation}</if>
                        <if test="content != null  and content != ''"> and content = #{content}</if>
                        <if test="operatorUserId != null "> and operator_user_id = #{operatorUserId}</if>
                        <if test="operatorUserName != null  and operatorUserName != ''"> and operator_user_name like concat(concat('%', #{operatorUserName}), '%')</if>
                        <if test="operationTime != null "> and operation_time = #{operationTime}</if>
        </where>
    </select>

    <select id="selectAndonEventLogByLogId" parameterType="Long" resultMap="AndonEventLogResult">
            <include refid="selectAndonEventLogVo"/>
            where log_id = #{logId}
    </select>

    <insert id="insertAndonEventLog" parameterType="AndonEventLog">
            <selectKey keyProperty="logId" resultType="long" order="BEFORE">
                SELECT ANDON_EVENT_LOG_SEQ.NEXTVAL as logId FROM DUAL
            </selectKey>
        insert into andon_event_log
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="logId != null">log_id,</if>
                <if test="eventId != null">event_id,</if>
                <if test="operation != null and operation != ''">operation,</if>
                <if test="content != null">content,</if>
                <if test="operatorUserId != null">operator_user_id,</if>
                <if test="operatorUserName != null">operator_user_name,</if>
                <if test="operationTime != null">operation_time,</if>
                <if test="remark != null">remark,</if>
                <if test="createBy != null">create_by,</if>
                <if test="createTime != null">create_time,</if>
                <if test="updateBy != null">update_by,</if>
                <if test="updateTime != null">update_time,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                <if test="logId != null">#{logId},</if>
                <if test="eventId != null">#{eventId},</if>
                <if test="operation != null and operation != ''">#{operation},</if>
                <if test="content != null">#{content},</if>
                <if test="operatorUserId != null">#{operatorUserId},</if>
                <if test="operatorUserName != null">#{operatorUserName},</if>
                <if test="operationTime != null">#{operationTime},</if>
                <if test="remark != null">#{remark},</if>
                <if test="createBy != null">#{createBy},</if>
                <if test="createTime != null">#{createTime},</if>
                <if test="updateBy != null">#{updateBy},</if>
                <if test="updateTime != null">#{updateTime},</if>
        </trim>
    </insert>

    <update id="updateAndonEventLog" parameterType="AndonEventLog">
        update andon_event_log
        <trim prefix="SET" suffixOverrides=",">
                    <if test="eventId != null">event_id = #{eventId},</if>
                    <if test="operation != null and operation != ''">operation = #{operation},</if>
                    <if test="content != null">content = #{content},</if>
                    <if test="operatorUserId != null">operator_user_id = #{operatorUserId},</if>
                    <if test="operatorUserName != null">operator_user_name = #{operatorUserName},</if>
                    <if test="operationTime != null">operation_time = #{operationTime},</if>
                    <if test="remark != null">remark = #{remark},</if>
                    <if test="createBy != null">create_by = #{createBy},</if>
                    <if test="createTime != null">create_time = #{createTime},</if>
                    <if test="updateBy != null">update_by = #{updateBy},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
        </trim>
        where log_id = #{logId}
    </update>

    <delete id="deleteAndonEventLogByLogId" parameterType="Long">
        delete from andon_event_log where log_id = #{logId}
    </delete>

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