<?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.zbf.system.mapper.OutBoundMapper">

    <resultMap type="OutBound" id="OutBoundResult">
            <result property="id"    column="id"    />
            <result property="itemList"    column="item_list"    />
            <result property="ckType"    column="ck_type"    />
            <result property="applyTime"    column="apply_time"    />
            <result property="applyer"    column="applyer"    />
            <result property="deliveryId"    column="delivery_id"    />
            <result property="deptmanager"    column="deptmanager"    />
            <result property="managerName"    column="manager_name"    />
            <result property="crossDeptManager"    column="cross_dept_manager"    />
            <result property="instanceId"    column="instance_id"    />
            <result property="taskId"    column="task_id"    />
            <result property="fInstanceId"    column="f_instance_id"    />
            <result property="createTime"    column="create_time"    />
            <result property="updateTime"    column="update_time"    />
            <result property="finishName"    column="finish_name"    />
    </resultMap>

    <sql id="selectOutBoundVo">
        select id, item_list, ck_type, apply_time, applyer,delivery_id,deptmanager,manager_name,cross_dept_manager,instance_id,task_id,f_instance_id,create_time,update_time,finish_name from out_bound
    </sql>

    <select id="selectOutBoundList" parameterType="OutBound" resultMap="OutBoundResult">
        <include refid="selectOutBoundVo"/>
        <where>
            <if test="itemList != null  and itemList != ''"> and item_list = #{itemList}</if>
            <if test="deliveryId != null  and deliveryId != ''"> and delivery_id = #{deliveryId}</if>
            <if test="ckType != null  and ckType != ''"> and ck_type = #{ckType}</if>
            <if test="params.beginApplyTime != null and params.beginApplyTime != '' and params.endApplyTime != null and params.endApplyTime != ''"> and applytime between #{params.beginApplyTime} and #{params.endApplyTime}</if>
            <if test="applyer != null  and applyer != ''"> and applyer = #{applyer}</if>
            <if test="instanceId != null  and instanceId != ''"> and instance_id = #{instanceId}</if>
            <if test="taskId != null  and taskId != ''"> and task_id = #{taskId}</if>
            <if test="fInstanceId != null  and fInstanceId != ''"> and f_instance_id = #{fInstanceId}</if>
            <if test="applyTime != null  and applyTime != ''"> and apply_time >= #{applyTime}</if>
        </where>
        order by create_time desc
    </select>

    <select id="selectOutBoundById" parameterType="Long" resultMap="OutBoundResult">
            <include refid="selectOutBoundVo"/>
            where id = #{id}
    </select>

    <insert id="insertOutBound" parameterType="OutBound" useGeneratedKeys="true" keyProperty="id">
        insert into out_bound
        <trim prefix="(" suffix=")" suffixOverrides=",">
                    <if test="deliveryId != null and deliveryId != ''">delivery_id,</if>
                    <if test="itemList != null and itemList != ''">item_list,</if>
                    <if test="ckType != null">ck_type,</if>
                    <if test="applyTime != null">apply_time,</if>
                    <if test="applyer != null">applyer,</if>
                    <if test="deptmanager != null">deptmanager,</if>
                    <if test="managerName != null">manager_name,</if>
                    <if test="crossDeptManager != null">cross_dept_manager,</if>
                    <if test="instanceId != null">instance_id,</if>
                    <if test="taskId != null">task_id,</if>
                    <if test="fInstanceId != null">f_instance_id,</if>
                    <if test="createTime != null">create_time,</if>
                    <if test="updateTime != null">update_time,</if>
                    <if test="finishName != null">finish_name,</if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
                    <if test="deliveryId != null and deliveryId != ''">#{deliveryId},</if>
                    <if test="itemList != null and itemList != ''">#{itemList},</if>
                    <if test="ckType != null">#{ckType},</if>
                    <if test="applyTime != null">#{applyTime},</if>
                    <if test="applyer != null">#{applyer},</if>
                    <if test="deptmanager != null">#{deptmanager},</if>
                    <if test="managerName != null">#{managerName},</if>
                    <if test="crossDeptManager != null">#{crossDeptManager},</if>
                    <if test="instanceId != null">#{instanceId},</if>
                    <if test="taskId != null">#{taskId},</if>
                    <if test="fInstanceId != null">#{fInstanceId},</if>
                    <if test="createTime != null">#{createTime},</if>
                    <if test="updateTime != null">#{updateTime},</if>
                    <if test="finishName != null">#{finishName},</if>
        </trim>
    </insert>

    <update id="updateOutBound" parameterType="OutBound">
        update out_bound
        <trim prefix="SET" suffixOverrides=",">
                    <if test="deliveryId != null and deliveryId != ''">delivery_id = #{deliveryId},</if>
                    <if test="itemList != null and itemList != ''">item_list = #{itemList},</if>
                    <if test="ckType != null">ck_type = #{ckType},</if>
                    <if test="applyTime != null">apply_time = #{applyTime},</if>
                    <if test="applyer != null">applyer = #{applyer},</if>
                    <if test="instanceId != null">instance_id = #{instanceId},</if>
                    <if test="taskId != null">task_id = #{taskId},</if>
                    <if test="fInstanceId != null">f_instance_id = #{fInstanceId},</if>
                    <if test="updateTime != null">update_time = #{updateTime},</if>
                    <if test="finishName != null">finish_name = #{finishName},</if>
        </trim>
        where id = #{id}
    </update>

    <update id="enableOutBoundByIds" parameterType="String">
        update out_bound set status=0 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>
    <update id="disabledOutBoundByIds" parameterType="String">
        update out_bound set status=1 where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </update>

    <delete id="deleteOutBoundById" parameterType="Long">
        delete from out_bound  where id = #{id}
    </delete>

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