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

    <resultMap type="AndonEventAssignment" id="AndonEventAssignmentResult">
            <result property="assignmentId"    column="assignment_id"    />
            <result property="eventId"    column="event_id"    />
            <result property="assigneeUserId"    column="assignee_user_id"    />
            <result property="assigneeUserName"    column="assignee_user_name"    />
            <result property="assigneeRoleKey"    column="assignee_role_key"    />
            <result property="assigneeTeamCode"    column="assignee_team_code"    />
            <result property="assignedTime"    column="assigned_time"    />
            <result property="acceptTime"    column="accept_time"    />
            <result property="finishTime"    column="finish_time"    />
            <result property="status"    column="status"    />
            <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="selectAndonEventAssignmentVo">
        select assignment_id, event_id, assignee_user_id, assignee_user_name, assignee_role_key, assignee_team_code, assigned_time, accept_time, finish_time, status, is_flag, remark, create_by, create_time, update_by, update_time from andon_event_assignment
    </sql>

    <select id="selectAndonEventAssignmentList" parameterType="AndonEventAssignment" resultMap="AndonEventAssignmentResult">
        <include refid="selectAndonEventAssignmentVo"/>
        <where>
                        <if test="eventId != null "> and event_id = #{eventId}</if>
                        <if test="assigneeUserId != null "> and assignee_user_id = #{assigneeUserId}</if>
                        <if test="assigneeUserName != null  and assigneeUserName != ''"> and assignee_user_name like concat(concat('%', #{assigneeUserName}), '%')</if>
                        <if test="assigneeRoleKey != null  and assigneeRoleKey != ''"> and assignee_role_key = #{assigneeRoleKey}</if>
                        <if test="assigneeTeamCode != null  and assigneeTeamCode != ''"> and assignee_team_code = #{assigneeTeamCode}</if>
                        <if test="assignedTime != null "> and assigned_time = #{assignedTime}</if>
                        <if test="acceptTime != null "> and accept_time = #{acceptTime}</if>
                        <if test="finishTime != null "> and finish_time = #{finishTime}</if>
                        <if test="status != null  and status != ''"> and status = #{status}</if>
                        <if test="isFlag != null  and isFlag != ''"> and is_flag = #{isFlag}</if>
        </where>
    </select>

    <select id="selectAndonEventAssignmentByAssignmentId" parameterType="Long" resultMap="AndonEventAssignmentResult">
            <include refid="selectAndonEventAssignmentVo"/>
            where assignment_id = #{assignmentId}
    </select>

    <insert id="insertAndonEventAssignment" parameterType="AndonEventAssignment">
            <selectKey keyProperty="assignmentId" resultType="long" order="BEFORE">
                SELECT ANDON_EVENT_ASSIGNMENT_SEQ.NEXTVAL as assignmentId FROM DUAL
            </selectKey>
        insert into andon_event_assignment
        <trim prefix="(" suffix=")" suffixOverrides=",">
                <if test="assignmentId != null">assignment_id,</if>
                <if test="eventId != null">event_id,</if>
                <if test="assigneeUserId != null">assignee_user_id,</if>
                <if test="assigneeUserName != null">assignee_user_name,</if>
                <if test="assigneeRoleKey != null">assignee_role_key,</if>
                <if test="assigneeTeamCode != null">assignee_team_code,</if>
                <if test="assignedTime != null">assigned_time,</if>
                <if test="acceptTime != null">accept_time,</if>
                <if test="finishTime != null">finish_time,</if>
                <if test="status != null">status,</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="assignmentId != null">#{assignmentId},</if>
                <if test="eventId != null">#{eventId},</if>
                <if test="assigneeUserId != null">#{assigneeUserId},</if>
                <if test="assigneeUserName != null">#{assigneeUserName},</if>
                <if test="assigneeRoleKey != null">#{assigneeRoleKey},</if>
                <if test="assigneeTeamCode != null">#{assigneeTeamCode},</if>
                <if test="assignedTime != null">#{assignedTime},</if>
                <if test="acceptTime != null">#{acceptTime},</if>
                <if test="finishTime != null">#{finishTime},</if>
                <if test="status != null">#{status},</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="updateAndonEventAssignment" parameterType="AndonEventAssignment">
        update andon_event_assignment
        <trim prefix="SET" suffixOverrides=",">
                    <if test="eventId != null">event_id = #{eventId},</if>
                    <if test="assigneeUserId != null">assignee_user_id = #{assigneeUserId},</if>
                    <if test="assigneeUserName != null">assignee_user_name = #{assigneeUserName},</if>
                    <if test="assigneeRoleKey != null">assignee_role_key = #{assigneeRoleKey},</if>
                    <if test="assigneeTeamCode != null">assignee_team_code = #{assigneeTeamCode},</if>
                    <if test="assignedTime != null">assigned_time = #{assignedTime},</if>
                    <if test="acceptTime != null">accept_time = #{acceptTime},</if>
                    <if test="finishTime != null">finish_time = #{finishTime},</if>
                    <if test="status != null">status = #{status},</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 assignment_id = #{assignmentId}
    </update>

    <delete id="deleteAndonEventAssignmentByAssignmentId" parameterType="Long">
        delete from andon_event_assignment where assignment_id = #{assignmentId}
    </delete>

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