<?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.dms.mapper.DmsDispatchMemberMapper">
    
    <resultMap type="DmsDispatchMember" id="DmsDispatchMemberResult">
        <result property="memberId"    column="member_id"    />
        <result property="planId"    column="plan_id"    />
        <result property="userId"    column="user_id"    />
        <result property="userName"    column="user_name"    />
        <result property="memberRole"    column="member_role"    />
        <result property="allocatedHours"    column="allocated_hours"    />
        <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="selectDmsDispatchMemberVo">
        select member_id, plan_id, user_id, user_name, member_role, allocated_hours, remark,
               create_by, create_time, update_by, update_time
        from dms_dispatch_member
    </sql>

    <select id="selectDmsDispatchMemberList" parameterType="DmsDispatchMember" resultMap="DmsDispatchMemberResult">
        <include refid="selectDmsDispatchMemberVo"/>
        <where>
            <if test="planId != null">
                and plan_id = #{planId}
            </if>
            <if test="userId != null">
                and user_id = #{userId}
            </if>
            <if test="memberRole != null and memberRole != ''">
                and member_role = #{memberRole}
            </if>
        </where>
        order by member_id
    </select>
    
    <select id="selectDmsDispatchMemberByMemberId" parameterType="Long" resultMap="DmsDispatchMemberResult">
        <include refid="selectDmsDispatchMemberVo"/>
        where member_id = #{memberId}
    </select>
        
    <insert id="insertDmsDispatchMember" parameterType="DmsDispatchMember">
        <selectKey keyProperty="memberId" resultType="long" order="BEFORE">
            select SEQ_DMS_DISPATCH_MEMBER.nextval as memberId from DUAL
        </selectKey>
        insert into dms_dispatch_member
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="memberId != null">member_id,</if>
            <if test="planId != null">plan_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="userName != null">user_name,</if>
            <if test="memberRole != null">member_role,</if>
            <if test="allocatedHours != null">allocated_hours,</if>
            <if test="remark != null">remark,</if>
            <if test="createBy != null">create_by,</if>
            create_time
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="memberId != null">#{memberId},</if>
            <if test="planId != null">#{planId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="userName != null">#{userName},</if>
            <if test="memberRole != null">#{memberRole},</if>
            <if test="allocatedHours != null">#{allocatedHours},</if>
            <if test="remark != null">#{remark},</if>
            <if test="createBy != null">#{createBy},</if>
            sysdate
        </trim>
    </insert>

    <update id="updateDmsDispatchMember" parameterType="DmsDispatchMember">
        update dms_dispatch_member
        <trim prefix="SET" suffixOverrides=",">
            <if test="planId != null">plan_id = #{planId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="userName != null">user_name = #{userName},</if>
            <if test="memberRole != null">member_role = #{memberRole},</if>
            <if test="allocatedHours != null">allocated_hours = #{allocatedHours},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="updateBy != null">update_by = #{updateBy},</if>
            update_time = sysdate
        </trim>
        where member_id = #{memberId}
    </update>

    <delete id="deleteDmsDispatchMemberByMemberId" parameterType="Long">
        delete from dms_dispatch_member where member_id = #{memberId}
    </delete>

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

    <delete id="deleteDmsDispatchMemberByPlanId" parameterType="Long">
        delete from dms_dispatch_member where plan_id = #{planId}
    </delete>
</mapper>
