<?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.AndonEventMapper">

    <resultMap type="AndonEvent" id="AndonEventResult">
            <result property="eventId"    column="event_id"    />
            <result property="callCode"    column="call_code"    />
            <result property="callTypeCode"    column="call_type_code"    />
            <result property="sourceType"    column="source_type"    />
            <result property="sourceRefId"    column="source_ref_id"    />
            <result property="productLineCode"    column="product_line_code"    />
            <result property="stationCode"    column="station_code"    />
            <result property="teamCode"    column="team_code"    />
            <result property="orderCode"    column="order_code"    />
            <result property="materialCode"    column="material_code"    />
            <result property="deviceId"    column="device_id"    />
            <result property="deviceCode"    column="device_code"    />
            <result property="priority"    column="priority"    />
            <result property="eventStatus"    column="event_status"    />
            <result property="description"    column="description"    />
            <result property="ackBy"    column="ack_by"    />
            <result property="ackTime"    column="ack_time"    />
            <result property="responseStartTime"    column="response_start_time"    />
            <result property="responseEndTime"    column="response_end_time"    />
            <result property="resolution"    column="resolution"    />
            <result property="cancelReason"    column="cancel_reason"    />
            <result property="escalateLevel"    column="escalate_level"    />
            <result property="escalateTime"    column="escalate_time"    />
            <result property="ackDeadline"    column="ack_deadline"    />
            <result property="resolveDeadline"    column="resolve_deadline"    />
            <result property="isFlag"    column="is_flag"    />
            <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="selectAndonEventVo">
        select event_id, call_code, call_type_code, source_type, source_ref_id, product_line_code, station_code, team_code, order_code, material_code, device_id, device_code, priority, event_status, description, ack_by, ack_time, response_start_time, response_end_time, resolution, cancel_reason, escalate_level, escalate_time, ack_deadline, resolve_deadline, is_flag, remark, create_by, create_time, update_by, update_time from andon_event
    </sql>

    <select id="selectAndonEventList" parameterType="AndonEvent" resultMap="AndonEventResult">
        <include refid="selectAndonEventVo"/>
        <where>
                        <if test="callCode != null  and callCode != ''"> and call_code = #{callCode}</if>
                        <if test="callTypeCode != null  and callTypeCode != ''"> and call_type_code = #{callTypeCode}</if>
                        <if test="sourceType != null  and sourceType != ''"> and source_type = #{sourceType}</if>
                        <if test="sourceRefId != null "> and source_ref_id = #{sourceRefId}</if>
                        <if test="productLineCode != null  and productLineCode != ''"> and product_line_code = #{productLineCode}</if>
                        <if test="stationCode != null  and stationCode != ''"> and station_code = #{stationCode}</if>
                        <if test="teamCode != null  and teamCode != ''"> and team_code = #{teamCode}</if>
                        <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
                        <if test="materialCode != null  and materialCode != ''"> and material_code = #{materialCode}</if>
                        <if test="deviceId != null "> and device_id = #{deviceId}</if>
                        <if test="deviceCode != null  and deviceCode != ''"> and device_code = #{deviceCode}</if>
                        <if test="priority != null "> and priority = #{priority}</if>
                        <if test="eventStatus != null  and eventStatus != ''"> and event_status = #{eventStatus}</if>
                        <if test="description != null  and description != ''"> and description = #{description}</if>
                        <if test="ackBy != null  and ackBy != ''"> and ack_by = #{ackBy}</if>
                        <if test="ackTime != null "> and ack_time = #{ackTime}</if>
                        <if test="responseStartTime != null "> and response_start_time = #{responseStartTime}</if>
                        <if test="responseEndTime != null "> and response_end_time = #{responseEndTime}</if>
                        <if test="resolution != null  and resolution != ''"> and resolution = #{resolution}</if>
                        <if test="cancelReason != null  and cancelReason != ''"> and cancel_reason = #{cancelReason}</if>
                        <if test="escalateLevel != null "> and escalate_level = #{escalateLevel}</if>
                        <if test="escalateTime != null "> and escalate_time = #{escalateTime}</if>
                        <if test="ackDeadline != null "> and ack_deadline = #{ackDeadline}</if>
                        <if test="resolveDeadline != null "> and resolve_deadline = #{resolveDeadline}</if>
                        <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectAndonEventByEventId" parameterType="Long" resultMap="AndonEventResult">
            <include refid="selectAndonEventVo"/>
            where event_id = #{eventId}
    </select>

    <insert id="insertAndonEvent" parameterType="AndonEvent">
            <selectKey keyProperty="eventId" resultType="long" order="BEFORE">
                SELECT ANDON_EVENT_SEQ.NEXTVAL as eventId FROM DUAL
            </selectKey>
        insert into andon_event
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="eventId != null">event_id,</if>
                <if test="callCode != null and callCode != ''">call_code,</if>
                <if test="callTypeCode != null and callTypeCode != ''">call_type_code,</if>
                <if test="sourceType != null and sourceType != ''">source_type,</if>
                <if test="sourceRefId != null">source_ref_id,</if>
                <if test="productLineCode != null">product_line_code,</if>
                <if test="stationCode != null">station_code,</if>
                <if test="teamCode != null">team_code,</if>
                <if test="orderCode != null">order_code,</if>
                <if test="materialCode != null">material_code,</if>
                <if test="deviceId != null">device_id,</if>
                <if test="deviceCode != null">device_code,</if>
                <if test="priority != null">priority,</if>
                <if test="eventStatus != null and eventStatus != ''">event_status,</if>
                <if test="description != null">description,</if>
                <if test="ackBy != null">ack_by,</if>
                <if test="ackTime != null">ack_time,</if>
                <if test="responseStartTime != null">response_start_time,</if>
                <if test="responseEndTime != null">response_end_time,</if>
                <if test="resolution != null">resolution,</if>
                <if test="cancelReason != null">cancel_reason,</if>
                <if test="escalateLevel != null">escalate_level,</if>
                <if test="escalateTime != null">escalate_time,</if>
                <if test="ackDeadline != null">ack_deadline,</if>
                <if test="resolveDeadline != null">resolve_deadline,</if>
                <if test="isFlag != null and isFlag != ''">is_flag,</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="eventId != null">#{eventId},</if>
                <if test="callCode != null and callCode != ''">#{callCode},</if>
                <if test="callTypeCode != null and callTypeCode != ''">#{callTypeCode},</if>
                <if test="sourceType != null and sourceType != ''">#{sourceType},</if>
                <if test="sourceRefId != null">#{sourceRefId},</if>
                <if test="productLineCode != null">#{productLineCode},</if>
                <if test="stationCode != null">#{stationCode},</if>
                <if test="teamCode != null">#{teamCode},</if>
                <if test="orderCode != null">#{orderCode},</if>
                <if test="materialCode != null">#{materialCode},</if>
                <if test="deviceId != null">#{deviceId},</if>
                <if test="deviceCode != null">#{deviceCode},</if>
                <if test="priority != null">#{priority},</if>
                <if test="eventStatus != null and eventStatus != ''">#{eventStatus},</if>
                <if test="description != null">#{description},</if>
                <if test="ackBy != null">#{ackBy},</if>
                <if test="ackTime != null">#{ackTime},</if>
                <if test="responseStartTime != null">#{responseStartTime},</if>
                <if test="responseEndTime != null">#{responseEndTime},</if>
                <if test="resolution != null">#{resolution},</if>
                <if test="cancelReason != null">#{cancelReason},</if>
                <if test="escalateLevel != null">#{escalateLevel},</if>
                <if test="escalateTime != null">#{escalateTime},</if>
                <if test="ackDeadline != null">#{ackDeadline},</if>
                <if test="resolveDeadline != null">#{resolveDeadline},</if>
                <if test="isFlag != null and isFlag != ''">#{isFlag},</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="updateAndonEvent" parameterType="AndonEvent">
        update andon_event
        <trim prefix="SET" suffixOverrides=",">
                    <if test="callCode != null and callCode != ''">call_code = #{callCode},</if>
                    <if test="callTypeCode != null and callTypeCode != ''">call_type_code = #{callTypeCode},</if>
                    <if test="sourceType != null and sourceType != ''">source_type = #{sourceType},</if>
                    <if test="sourceRefId != null">source_ref_id = #{sourceRefId},</if>
                    <if test="productLineCode != null">product_line_code = #{productLineCode},</if>
                    <if test="stationCode != null">station_code = #{stationCode},</if>
                    <if test="teamCode != null">team_code = #{teamCode},</if>
                    <if test="orderCode != null">order_code = #{orderCode},</if>
                    <if test="materialCode != null">material_code = #{materialCode},</if>
                    <if test="deviceId != null">device_id = #{deviceId},</if>
                    <if test="deviceCode != null">device_code = #{deviceCode},</if>
                    <if test="priority != null">priority = #{priority},</if>
                    <if test="eventStatus != null and eventStatus != ''">event_status = #{eventStatus},</if>
                    <if test="description != null">description = #{description},</if>
                    <if test="ackBy != null">ack_by = #{ackBy},</if>
                    <if test="ackTime != null">ack_time = #{ackTime},</if>
                    <if test="responseStartTime != null">response_start_time = #{responseStartTime},</if>
                    <if test="responseEndTime != null">response_end_time = #{responseEndTime},</if>
                    <if test="resolution != null">resolution = #{resolution},</if>
                    <if test="cancelReason != null">cancel_reason = #{cancelReason},</if>
                    <if test="escalateLevel != null">escalate_level = #{escalateLevel},</if>
                    <if test="escalateTime != null">escalate_time = #{escalateTime},</if>
                    <if test="ackDeadline != null">ack_deadline = #{ackDeadline},</if>
                    <if test="resolveDeadline != null">resolve_deadline = #{resolveDeadline},</if>
                    <if test="isFlag != null and isFlag != ''">is_flag = #{isFlag},</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 event_id = #{eventId}
    </update>

    <delete id="deleteAndonEventByEventId" parameterType="Long">
        delete from andon_event where event_id = #{eventId}
    </delete>

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