<?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.bailuntec.mapper.DcBaseTransferVerifyMapper">
  <resultMap id="BaseResultMap" type="com.bailuntec.domain.entity.DcBaseTransferVerify">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="id" jdbcType="INTEGER" property="id" />
    <result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate" />
    <result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified" />
    <result column="bailun_sku" jdbcType="VARCHAR" property="bailunSku" />
    <result column="transfer_order_id" jdbcType="VARCHAR" property="transferOrderId" />
    <result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode" />
    <result column="warehouse_name" jdbcType="VARCHAR" property="warehouseName" />
    <result column="status" jdbcType="VARCHAR" property="status" />
    <result column="create_time" jdbcType="TIMESTAMP" property="createTime" />
    <result column="count" jdbcType="INTEGER" property="count" />
    <result column="sku_title" jdbcType="VARCHAR" property="skuTitle" />
    <result column="transfer_key" jdbcType="INTEGER" property="transferKey" />
    <result column="deleted" jdbcType="BIT" property="deleted" />
    <result column="estimated_arrival_time" jdbcType="TIMESTAMP" property="estimatedArrivalTime" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <where>
      <foreach collection="example.oredCriteria" item="criteria" separator="or">
        <if test="criteria.valid">
          <trim prefix="(" prefixOverrides="and" suffix=")">
            <foreach collection="criteria.criteria" item="criterion">
              <choose>
                <when test="criterion.noValue">
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue">
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue">
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue">
                  and ${criterion.condition}
                  <foreach close=")" collection="criterion.value" item="listItem" open="(" separator=",">
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    id, gmt_create, gmt_modified, bailun_sku, transfer_order_id, warehouse_code, warehouse_name, 
    status, create_time, count, sku_title, transfer_key, deleted, estimated_arrival_time
  </sql>
  <select id="selectByExample" parameterType="com.bailuntec.domain.example.DcBaseTransferVerifyExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    <include refid="Base_Column_List" />
    from dc_base_transfer_verify
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    <if test="rows != null">
      <if test="offset != null">
        limit ${offset}, ${rows}
      </if>
      <if test="offset == null">
        limit ${rows}
      </if>
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from dc_base_transfer_verify
    where id = #{id,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from dc_base_transfer_verify
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.bailuntec.domain.example.DcBaseTransferVerifyExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from dc_base_transfer_verify
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.bailuntec.domain.entity.DcBaseTransferVerify">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into dc_base_transfer_verify (id, gmt_create, gmt_modified, 
      bailun_sku, transfer_order_id, warehouse_code, 
      warehouse_name, status, create_time, 
      count, sku_title, transfer_key, 
      deleted, estimated_arrival_time)
    values (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
      #{bailunSku,jdbcType=VARCHAR}, #{transferOrderId,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, 
      #{warehouseName,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
      #{count,jdbcType=INTEGER}, #{skuTitle,jdbcType=VARCHAR}, #{transferKey,jdbcType=INTEGER}, 
      #{deleted,jdbcType=BIT}, #{estimatedArrivalTime,jdbcType=TIMESTAMP})
  </insert>
  <insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcBaseTransferVerify">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into dc_base_transfer_verify
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="gmtCreate != null">
        gmt_create,
      </if>
      <if test="gmtModified != null">
        gmt_modified,
      </if>
      <if test="bailunSku != null">
        bailun_sku,
      </if>
      <if test="transferOrderId != null">
        transfer_order_id,
      </if>
      <if test="warehouseCode != null">
        warehouse_code,
      </if>
      <if test="warehouseName != null">
        warehouse_name,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="count != null">
        count,
      </if>
      <if test="skuTitle != null">
        sku_title,
      </if>
      <if test="transferKey != null">
        transfer_key,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
      <if test="estimatedArrivalTime != null">
        estimated_arrival_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="gmtCreate != null">
        #{gmtCreate,jdbcType=TIMESTAMP},
      </if>
      <if test="gmtModified != null">
        #{gmtModified,jdbcType=TIMESTAMP},
      </if>
      <if test="bailunSku != null">
        #{bailunSku,jdbcType=VARCHAR},
      </if>
      <if test="transferOrderId != null">
        #{transferOrderId,jdbcType=VARCHAR},
      </if>
      <if test="warehouseCode != null">
        #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="warehouseName != null">
        #{warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="count != null">
        #{count,jdbcType=INTEGER},
      </if>
      <if test="skuTitle != null">
        #{skuTitle,jdbcType=VARCHAR},
      </if>
      <if test="transferKey != null">
        #{transferKey,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        #{deleted,jdbcType=BIT},
      </if>
      <if test="estimatedArrivalTime != null">
        #{estimatedArrivalTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.bailuntec.domain.example.DcBaseTransferVerifyExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from dc_base_transfer_verify
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_base_transfer_verify
    <set>
      <if test="record.id != null">
        id = #{record.id,jdbcType=INTEGER},
      </if>
      <if test="record.gmtCreate != null">
        gmt_create = #{record.gmtCreate,jdbcType=TIMESTAMP},
      </if>
      <if test="record.gmtModified != null">
        gmt_modified = #{record.gmtModified,jdbcType=TIMESTAMP},
      </if>
      <if test="record.bailunSku != null">
        bailun_sku = #{record.bailunSku,jdbcType=VARCHAR},
      </if>
      <if test="record.transferOrderId != null">
        transfer_order_id = #{record.transferOrderId,jdbcType=VARCHAR},
      </if>
      <if test="record.warehouseCode != null">
        warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="record.warehouseName != null">
        warehouse_name = #{record.warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="record.status != null">
        status = #{record.status,jdbcType=VARCHAR},
      </if>
      <if test="record.createTime != null">
        create_time = #{record.createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.count != null">
        count = #{record.count,jdbcType=INTEGER},
      </if>
      <if test="record.skuTitle != null">
        sku_title = #{record.skuTitle,jdbcType=VARCHAR},
      </if>
      <if test="record.transferKey != null">
        transfer_key = #{record.transferKey,jdbcType=INTEGER},
      </if>
      <if test="record.deleted != null">
        deleted = #{record.deleted,jdbcType=BIT},
      </if>
      <if test="record.estimatedArrivalTime != null">
        estimated_arrival_time = #{record.estimatedArrivalTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_base_transfer_verify
    set id = #{record.id,jdbcType=INTEGER},
      gmt_create = #{record.gmtCreate,jdbcType=TIMESTAMP},
      gmt_modified = #{record.gmtModified,jdbcType=TIMESTAMP},
      bailun_sku = #{record.bailunSku,jdbcType=VARCHAR},
      transfer_order_id = #{record.transferOrderId,jdbcType=VARCHAR},
      warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
      warehouse_name = #{record.warehouseName,jdbcType=VARCHAR},
      status = #{record.status,jdbcType=VARCHAR},
      create_time = #{record.createTime,jdbcType=TIMESTAMP},
      count = #{record.count,jdbcType=INTEGER},
      sku_title = #{record.skuTitle,jdbcType=VARCHAR},
      transfer_key = #{record.transferKey,jdbcType=INTEGER},
      deleted = #{record.deleted,jdbcType=BIT},
      estimated_arrival_time = #{record.estimatedArrivalTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.DcBaseTransferVerify">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_base_transfer_verify
    <set>
      <if test="gmtCreate != null">
        gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
      </if>
      <if test="gmtModified != null">
        gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
      </if>
      <if test="bailunSku != null">
        bailun_sku = #{bailunSku,jdbcType=VARCHAR},
      </if>
      <if test="transferOrderId != null">
        transfer_order_id = #{transferOrderId,jdbcType=VARCHAR},
      </if>
      <if test="warehouseCode != null">
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="warehouseName != null">
        warehouse_name = #{warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="count != null">
        count = #{count,jdbcType=INTEGER},
      </if>
      <if test="skuTitle != null">
        sku_title = #{skuTitle,jdbcType=VARCHAR},
      </if>
      <if test="transferKey != null">
        transfer_key = #{transferKey,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        deleted = #{deleted,jdbcType=BIT},
      </if>
      <if test="estimatedArrivalTime != null">
        estimated_arrival_time = #{estimatedArrivalTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.bailuntec.domain.entity.DcBaseTransferVerify">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_base_transfer_verify
    set gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
      gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
      bailun_sku = #{bailunSku,jdbcType=VARCHAR},
      transfer_order_id = #{transferOrderId,jdbcType=VARCHAR},
      warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      warehouse_name = #{warehouseName,jdbcType=VARCHAR},
      status = #{status,jdbcType=VARCHAR},
      create_time = #{createTime,jdbcType=TIMESTAMP},
      count = #{count,jdbcType=INTEGER},
      sku_title = #{skuTitle,jdbcType=VARCHAR},
      transfer_key = #{transferKey,jdbcType=INTEGER},
      deleted = #{deleted,jdbcType=BIT},
      estimated_arrival_time = #{estimatedArrivalTime,jdbcType=TIMESTAMP}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcBaseTransferVerify">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      @project https://github.com/itfsw/mybatis-generator-plugin
    -->
    insert into dc_base_transfer_verify
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="gmtCreate != null">
        gmt_create,
      </if>
      <if test="gmtModified != null">
        gmt_modified,
      </if>
      <if test="bailunSku != null">
        bailun_sku,
      </if>
      <if test="transferOrderId != null">
        transfer_order_id,
      </if>
      <if test="warehouseCode != null">
        warehouse_code,
      </if>
      <if test="warehouseName != null">
        warehouse_name,
      </if>
      <if test="status != null">
        status,
      </if>
      <if test="createTime != null">
        create_time,
      </if>
      <if test="count != null">
        count,
      </if>
      <if test="skuTitle != null">
        sku_title,
      </if>
      <if test="transferKey != null">
        transfer_key,
      </if>
      <if test="deleted != null">
        deleted,
      </if>
      <if test="estimatedArrivalTime != null">
        estimated_arrival_time,
      </if>
    </trim>
    values
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=INTEGER},
      </if>
      <if test="gmtCreate != null">
        #{gmtCreate,jdbcType=TIMESTAMP},
      </if>
      <if test="gmtModified != null">
        #{gmtModified,jdbcType=TIMESTAMP},
      </if>
      <if test="bailunSku != null">
        #{bailunSku,jdbcType=VARCHAR},
      </if>
      <if test="transferOrderId != null">
        #{transferOrderId,jdbcType=VARCHAR},
      </if>
      <if test="warehouseCode != null">
        #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="warehouseName != null">
        #{warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="count != null">
        #{count,jdbcType=INTEGER},
      </if>
      <if test="skuTitle != null">
        #{skuTitle,jdbcType=VARCHAR},
      </if>
      <if test="transferKey != null">
        #{transferKey,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        #{deleted,jdbcType=BIT},
      </if>
      <if test="estimatedArrivalTime != null">
        #{estimatedArrivalTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
    on duplicate key update 
    <trim suffixOverrides=",">
      <if test="id != null">
        id = #{id,jdbcType=INTEGER},
      </if>
      <if test="gmtCreate != null">
        gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
      </if>
      <if test="gmtModified != null">
        gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
      </if>
      <if test="bailunSku != null">
        bailun_sku = #{bailunSku,jdbcType=VARCHAR},
      </if>
      <if test="transferOrderId != null">
        transfer_order_id = #{transferOrderId,jdbcType=VARCHAR},
      </if>
      <if test="warehouseCode != null">
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="warehouseName != null">
        warehouse_name = #{warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=VARCHAR},
      </if>
      <if test="createTime != null">
        create_time = #{createTime,jdbcType=TIMESTAMP},
      </if>
      <if test="count != null">
        count = #{count,jdbcType=INTEGER},
      </if>
      <if test="skuTitle != null">
        sku_title = #{skuTitle,jdbcType=VARCHAR},
      </if>
      <if test="transferKey != null">
        transfer_key = #{transferKey,jdbcType=INTEGER},
      </if>
      <if test="deleted != null">
        deleted = #{deleted,jdbcType=BIT},
      </if>
      <if test="estimatedArrivalTime != null">
        estimated_arrival_time = #{estimatedArrivalTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <insert id="upsert" parameterType="com.bailuntec.domain.entity.DcBaseTransferVerify">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      @project https://github.com/itfsw/mybatis-generator-plugin
    -->
    insert into dc_base_transfer_verify
    (id, gmt_create, gmt_modified, bailun_sku, transfer_order_id, warehouse_code, warehouse_name, 
      status, create_time, count, sku_title, transfer_key, deleted, estimated_arrival_time
      )
    values
    (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP},
      #{bailunSku,jdbcType=VARCHAR}, #{transferOrderId,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, 
      #{warehouseName,jdbcType=VARCHAR}, #{status,jdbcType=VARCHAR}, #{createTime,jdbcType=TIMESTAMP},
      #{count,jdbcType=INTEGER}, #{skuTitle,jdbcType=VARCHAR}, #{transferKey,jdbcType=INTEGER}, 
      #{deleted,jdbcType=BIT}, #{estimatedArrivalTime,jdbcType=TIMESTAMP})
    on duplicate key update 
    id = #{id,jdbcType=INTEGER}, 
    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
    bailun_sku = #{bailunSku,jdbcType=VARCHAR}, 
    transfer_order_id = #{transferOrderId,jdbcType=VARCHAR}, 
    warehouse_code = #{warehouseCode,jdbcType=VARCHAR}, 
    warehouse_name = #{warehouseName,jdbcType=VARCHAR}, 
    status = #{status,jdbcType=VARCHAR}, 
    create_time = #{createTime,jdbcType=TIMESTAMP},
    count = #{count,jdbcType=INTEGER}, 
    sku_title = #{skuTitle,jdbcType=VARCHAR}, 
    transfer_key = #{transferKey,jdbcType=INTEGER}, 
    deleted = #{deleted,jdbcType=BIT}, 
    estimated_arrival_time = #{estimatedArrivalTime,jdbcType=TIMESTAMP}
  </insert>
  <select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcBaseTransferVerifyExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
      @project https://github.com/itfsw/mybatis-generator-plugin
    -->
    select
    <include refid="Base_Column_List" />
    from dc_base_transfer_verify
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    limit 1
  </select>

  <select id="listTransferTransitOrder" resultType="com.bailuntec.domain.entity.DcBaseTransferVerify">
      SELECT
	tb11.bailun_sku bailun_sku,
	tb11.warehouse_code warehouse_code,
	tb11.transfer_order_id transfer_order_id,
	tb5.estimated_arrival_time  estimated_arrival_time,
	tb11.create_time create_time,
	( tb11.count - IFNULL( tb4.count, 0 ) ) AS count 
FROM
	(
	SELECT
		tb1.bailun_sku,
		tb1.warehouse_code,
		tb1.transfer_order_id,
		tb1.create_time,
		sum( tb1.count ) count 
	FROM
		dc_base_transfer_bale tb1
		LEFT JOIN dc_base_transfer_complete tb2 ON tb1.deleted = tb2.deleted 
		AND tb1.bailun_sku = tb2.bailun_sku 
		AND tb1.warehouse_code = tb2.warehouse_code 
		AND tb1.transfer_order_id = tb2.transfer_order_id 
	WHERE
		tb2.bailun_sku IS NULL 
		AND tb1.bailun_sku = #{bailunSku} 
		AND tb1.warehouse_code = #{warehouseCode} 
		AND tb1.deleted = 0 
	GROUP BY
		bailun_sku,
		warehouse_code,
		transfer_order_id 
	) tb11
	LEFT JOIN (
	SELECT
		tb1.bailun_sku,
		tb1.warehouse_code,
		tb1.transfer_order_id,
		tb1.estimated_arrival_time,
		tb1.create_time,
		sum( tb1.count ) count 
	FROM
		dc_base_transfer_verify tb1
		LEFT JOIN dc_base_transfer_complete tb2 ON tb1.deleted = tb2.deleted 
		AND tb1.bailun_sku = tb2.bailun_sku 
		AND tb1.warehouse_code = tb2.warehouse_code 
		AND tb1.transfer_order_id = tb2.transfer_order_id 
	WHERE
		tb2.bailun_sku IS NULL 
		AND tb1.bailun_sku = #{bailunSku} 
		AND tb1.warehouse_code = #{warehouseCode} 
		AND tb1.deleted = 0 
	GROUP BY
		bailun_sku,
		warehouse_code,
		transfer_order_id 
	) tb5 ON tb5.bailun_sku = tb11.bailun_sku 
	AND tb5.warehouse_code = tb11.warehouse_code 
	AND tb5.transfer_order_id = tb11.transfer_order_id
	LEFT JOIN (
	SELECT
		bailun_sku,
		warehouse_code,
		transfer_order_id,
		sum( count ) count 
	FROM
		(
		SELECT
			tb1.bailun_sku,
			tb1.warehouse_code,
			max( tb1.count ) count,
			tb1.transfer_order_id 
		FROM
			dc_base_transfer_inbound tb1
			LEFT JOIN dc_base_transfer_complete tb2 ON tb2.deleted = 0 
			AND tb1.bailun_sku = tb2.bailun_sku 
			AND tb1.warehouse_code = tb2.warehouse_code 
			AND tb1.transfer_order_id = tb2.transfer_order_id 
		WHERE
			tb2.bailun_sku IS NULL 
			AND tb1.bailun_sku = #{bailunSku} 
			AND tb1.warehouse_code = #{warehouseCode} 
			AND tb1.deleted = 0 
		GROUP BY
			bailun_sku,
			warehouse_code,
			transfer_order_id 
		) tb3 
	GROUP BY
		bailun_sku,
		warehouse_code,
		transfer_order_id 
	) tb4 ON tb5.bailun_sku = tb4.bailun_sku 
	AND tb5.warehouse_code = tb4.warehouse_code 
	AND tb5.transfer_order_id = tb4.transfer_order_id 
WHERE
	( tb11.count - IFNULL( tb4.count, 0 ) ) > 0
	union select  bailun_sku,warehouse_code,transfer_plan_order_id,null,update_time,count from  dc_base_transfer_plan where  status = 1 and deleted=0   AND  bailun_sku =  #{bailunSku}
		AND  warehouse_code = #{warehouseCode}
  </select>
</mapper>