<?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="cn.ezhizao.project.business.mapper.BizInboundOrderDetailMapper">

    <resultMap type="cn.ezhizao.project.business.domain.BizInboundOrderDetail" id="BizInboundOrderDetailResult">
        <id column="id" property="id"/>
    </resultMap>


    <select id="getList" parameterType="BizInboundOrderDetail" resultMap="BizInboundOrderDetailResult">
        SELECT * FROM biz_inbound_order_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="certificateCode != null  and certificateCode != ''"> AND certificate_code = #{certificateCode}</if>
            <if test="inboundNum != null "> AND inbound_num = #{inboundNum}</if>
            <if test="isInbound != null "> AND is_inbound = #{isInbound}</if>
            <if test="firstOperatorUserName != null  and firstOperatorUserName != ''"> AND first_operator_user_name like concat('%', #{firstOperatorUserName}, '%')</if>
            <if test="firstOperatorNickName != null  and firstOperatorNickName != ''"> AND first_operator_nick_name like concat('%', #{firstOperatorNickName}, '%')</if>
            <if test="secondOperatorUserName != null  and secondOperatorUserName != ''"> AND second_operator_user_name like concat('%', #{secondOperatorUserName}, '%')</if>
            <if test="secondOperatorNickName != null  and secondOperatorNickName != ''"> AND second_operator_nick_name like concat('%', #{secondOperatorNickName}, '%')</if>
            <if test="thirdOperatorUserName != null  and thirdOperatorUserName != ''"> AND third_operator_user_name like concat('%', #{thirdOperatorUserName}, '%')</if>
            <if test="thirdOperatorNickName != null  and thirdOperatorNickName != ''"> AND third_operator_nick_name like concat('%', #{thirdOperatorNickName}, '%')</if>
            <if test="packageTypeCode != null  and packageTypeCode != ''"> AND package_type_code = #{packageTypeCode}</if>
            <if test="transferCode != null  and transferCode != ''"> AND transfer_code = #{transferCode}</if>
        </trim>
    </select>
    <select id="getTaskStockList" resultType="cn.ezhizao.project.business.domain.BizTaksStockInboundOrderDetail">
        SELECT
        t1.inbound_order_id,
        t1.certificate_id,
        t1.certificate_lot_id,
        t1.certificate_code,
        t1.lot_code,
        t1.lot_id,
        t1.inbound_num,
        t1.is_inbound,
        t1.first_operator_user_id,
        t1.first_operator_user_name,
        t1.first_operator_nick_name,
        t1.second_operator_user_id,
        t1.second_operator_user_name,
        t1.second_operator_nick_name,
        t1.third_operator_user_id,
        t1.third_operator_user_name,
        t1.third_operator_nick_name,
        t1.package_type_code,
        t1.transfer_code,
        t1.pallet_code,
        t3.dept_id,t3.dept_name,t3.dept_code,t3.product_code,t3.product_id,t3.product_description,t3.inbound_number,t3.drawing_no
        FROM biz_inbound_order_detail t1
        left join biz_inbound_order t3 on t1.inbound_order_id = t3.id
        WHERE t1.is_inbound = 0 AND t1.deleted = 0 and t3.deleted = 0
        AND t1.lot_code IN (
        SELECT lot_code
        FROM biz_inbound_order_detail
        WHERE is_inbound = 1 AND deleted = 0
        );
    </select>

    <delete id="physicalDelete">
        DELETE FROM biz_inbound_order_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            <if test="id != null">
                id = #{id} AND
            </if>
       <!-- 删除条件为其他外键可以在这里加 -->
        </trim>
    </delete>
</mapper>
