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

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


    <select id="getList" parameterType="BizTaksStockInboundOrderDetail" resultMap="BizTaksStockInboundOrderDetailResult">
        SELECT * FROM biz_taks_stock_inbound_order_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="certificateCode != null  and certificateCode != ''"> AND certificate_code = #{certificateCode}</if>
            <if test="lotCode != null  and lotCode != ''"> AND lot_code = #{lotCode}</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>
            <if test="transferEntryCode != null  and transferEntryCode != ''"> AND transfer_entry_code = #{transferEntryCode}</if>
            <if test="inboundNumber != null  and inboundNumber != ''"> AND inbound_number = #{inboundNumber}</if>
            <if test="prodNum != null "> AND prod_num = #{prodNum}</if>
            <if test="isTaksStock != null "> AND is_taks_stock = #{isTaksStock}</if>
            <if test="stockYear != null  and stockYear != ''"> AND stock_year = #{stockYear}</if>
            <if test="stockMonth != null  and stockMonth != ''"> AND stock_month = #{stockMonth}</if>
        </trim>
    </select>
    <select id="getAnyInboundInfo" resultType="BizTaksStockInboundOrderDetail">
        SELECT *,
        GROUP_CONCAT(barcode SEPARATOR ',') AS barcodes
        FROM
        biz_taks_stock_inbound_order_detail
        <trim prefix=" WHERE" suffix="" suffixOverrides="AND">
            deleted = 0
            <if test="inboundNumber != null  and inboundNumber != ''"> AND inbound_number like concat('%', #{inboundNumber}, '%')</if>
            <if test="barcode != null  and barcode != ''"> AND (lot_code,inbound_number) IN (SELECT lot_code,inbound_number FROM biz_taks_stock_inbound_order_detail WHERE barcode like concat('%', #{barcode}, '%') AND deleted = 0)</if>
            <if test="takeStockPeriodId != null and takeStockPeriodId != ''"> AND take_stock_period_id = #{takeStockPeriodId}</if>
            <if test="lotCode != null  and lotCode != ''"> AND lot_code like concat('%', #{lotCode}, '%')</if>
        </trim>
        GROUP BY inbound_number,lot_code
    </select>

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