<?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.DcDailyTransitFromMapper">
  <resultMap id="BaseResultMap" type="com.bailuntec.domain.entity.DcDailyTransitFrom">
    <!--
      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="warehouse_code" jdbcType="VARCHAR" property="warehouseCode" />
    <result column="source_warehouse_code" jdbcType="VARCHAR" property="sourceWarehouseCode" />
    <result column="quantity_transfer_delivery" jdbcType="INTEGER" property="quantityTransferDelivery" />
    <result column="quantity_transfer_inbound" jdbcType="INTEGER" property="quantityTransferInbound" />
    <result column="quantity_transfer" jdbcType="INTEGER" property="quantityTransfer" />
    <result column="quantity_transfer_plan" jdbcType="INTEGER" property="quantityTransferPlan" />
    <result column="record_time" jdbcType="DATE" property="recordTime" />
    <result column="company_id" jdbcType="INTEGER" property="companyId" />
    <result column="unit_price" jdbcType="DECIMAL" property="unitPrice" />
  </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, warehouse_code, source_warehouse_code, 
    quantity_transfer_delivery, quantity_transfer_inbound, quantity_transfer, quantity_transfer_plan, 
    record_time, company_id, unit_price
  </sql>
  <select id="selectByExample" parameterType="com.bailuntec.domain.example.DcDailyTransitFromExample" 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_daily_transit_from
    <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_daily_transit_from
    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_daily_transit_from
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.bailuntec.domain.example.DcDailyTransitFromExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from dc_daily_transit_from
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.bailuntec.domain.entity.DcDailyTransitFrom">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into dc_daily_transit_from (id, gmt_create, gmt_modified, 
      bailun_sku, warehouse_code, source_warehouse_code, 
      quantity_transfer_delivery, quantity_transfer_inbound, 
      quantity_transfer, quantity_transfer_plan, 
      record_time, company_id, unit_price
      )
    values (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, 
      #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, #{sourceWarehouseCode,jdbcType=VARCHAR}, 
      #{quantityTransferDelivery,jdbcType=INTEGER}, #{quantityTransferInbound,jdbcType=INTEGER}, 
      #{quantityTransfer,jdbcType=INTEGER}, #{quantityTransferPlan,jdbcType=INTEGER}, 
      #{recordTime,jdbcType=DATE}, #{companyId,jdbcType=INTEGER}, #{unitPrice,jdbcType=DECIMAL}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcDailyTransitFrom">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into dc_daily_transit_from
    <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="warehouseCode != null">
        warehouse_code,
      </if>
      <if test="sourceWarehouseCode != null">
        source_warehouse_code,
      </if>
      <if test="quantityTransferDelivery != null">
        quantity_transfer_delivery,
      </if>
      <if test="quantityTransferInbound != null">
        quantity_transfer_inbound,
      </if>
      <if test="quantityTransfer != null">
        quantity_transfer,
      </if>
      <if test="quantityTransferPlan != null">
        quantity_transfer_plan,
      </if>
      <if test="recordTime != null">
        record_time,
      </if>
      <if test="companyId != null">
        company_id,
      </if>
      <if test="unitPrice != null">
        unit_price,
      </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="warehouseCode != null">
        #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="sourceWarehouseCode != null">
        #{sourceWarehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="quantityTransferDelivery != null">
        #{quantityTransferDelivery,jdbcType=INTEGER},
      </if>
      <if test="quantityTransferInbound != null">
        #{quantityTransferInbound,jdbcType=INTEGER},
      </if>
      <if test="quantityTransfer != null">
        #{quantityTransfer,jdbcType=INTEGER},
      </if>
      <if test="quantityTransferPlan != null">
        #{quantityTransferPlan,jdbcType=INTEGER},
      </if>
      <if test="recordTime != null">
        #{recordTime,jdbcType=DATE},
      </if>
      <if test="companyId != null">
        #{companyId,jdbcType=INTEGER},
      </if>
      <if test="unitPrice != null">
        #{unitPrice,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.bailuntec.domain.example.DcDailyTransitFromExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from dc_daily_transit_from
    <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_daily_transit_from
    <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.warehouseCode != null">
        warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="record.sourceWarehouseCode != null">
        source_warehouse_code = #{record.sourceWarehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="record.quantityTransferDelivery != null">
        quantity_transfer_delivery = #{record.quantityTransferDelivery,jdbcType=INTEGER},
      </if>
      <if test="record.quantityTransferInbound != null">
        quantity_transfer_inbound = #{record.quantityTransferInbound,jdbcType=INTEGER},
      </if>
      <if test="record.quantityTransfer != null">
        quantity_transfer = #{record.quantityTransfer,jdbcType=INTEGER},
      </if>
      <if test="record.quantityTransferPlan != null">
        quantity_transfer_plan = #{record.quantityTransferPlan,jdbcType=INTEGER},
      </if>
      <if test="record.recordTime != null">
        record_time = #{record.recordTime,jdbcType=DATE},
      </if>
      <if test="record.companyId != null">
        company_id = #{record.companyId,jdbcType=INTEGER},
      </if>
      <if test="record.unitPrice != null">
        unit_price = #{record.unitPrice,jdbcType=DECIMAL},
      </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_daily_transit_from
    set id = #{record.id,jdbcType=INTEGER},
      gmt_create = #{record.gmtCreate,jdbcType=TIMESTAMP},
      gmt_modified = #{record.gmtModified,jdbcType=TIMESTAMP},
      bailun_sku = #{record.bailunSku,jdbcType=VARCHAR},
      warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
      source_warehouse_code = #{record.sourceWarehouseCode,jdbcType=VARCHAR},
      quantity_transfer_delivery = #{record.quantityTransferDelivery,jdbcType=INTEGER},
      quantity_transfer_inbound = #{record.quantityTransferInbound,jdbcType=INTEGER},
      quantity_transfer = #{record.quantityTransfer,jdbcType=INTEGER},
      quantity_transfer_plan = #{record.quantityTransferPlan,jdbcType=INTEGER},
      record_time = #{record.recordTime,jdbcType=DATE},
      company_id = #{record.companyId,jdbcType=INTEGER},
      unit_price = #{record.unitPrice,jdbcType=DECIMAL}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.DcDailyTransitFrom">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_daily_transit_from
    <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="warehouseCode != null">
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="sourceWarehouseCode != null">
        source_warehouse_code = #{sourceWarehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="quantityTransferDelivery != null">
        quantity_transfer_delivery = #{quantityTransferDelivery,jdbcType=INTEGER},
      </if>
      <if test="quantityTransferInbound != null">
        quantity_transfer_inbound = #{quantityTransferInbound,jdbcType=INTEGER},
      </if>
      <if test="quantityTransfer != null">
        quantity_transfer = #{quantityTransfer,jdbcType=INTEGER},
      </if>
      <if test="quantityTransferPlan != null">
        quantity_transfer_plan = #{quantityTransferPlan,jdbcType=INTEGER},
      </if>
      <if test="recordTime != null">
        record_time = #{recordTime,jdbcType=DATE},
      </if>
      <if test="companyId != null">
        company_id = #{companyId,jdbcType=INTEGER},
      </if>
      <if test="unitPrice != null">
        unit_price = #{unitPrice,jdbcType=DECIMAL},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.bailuntec.domain.entity.DcDailyTransitFrom">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_daily_transit_from
    set gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
      gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
      bailun_sku = #{bailunSku,jdbcType=VARCHAR},
      warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      source_warehouse_code = #{sourceWarehouseCode,jdbcType=VARCHAR},
      quantity_transfer_delivery = #{quantityTransferDelivery,jdbcType=INTEGER},
      quantity_transfer_inbound = #{quantityTransferInbound,jdbcType=INTEGER},
      quantity_transfer = #{quantityTransfer,jdbcType=INTEGER},
      quantity_transfer_plan = #{quantityTransferPlan,jdbcType=INTEGER},
      record_time = #{recordTime,jdbcType=DATE},
      company_id = #{companyId,jdbcType=INTEGER},
      unit_price = #{unitPrice,jdbcType=DECIMAL}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcDailyTransitFrom">
    <!--
      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_daily_transit_from
    <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="warehouseCode != null">
        warehouse_code,
      </if>
      <if test="sourceWarehouseCode != null">
        source_warehouse_code,
      </if>
      <if test="quantityTransferDelivery != null">
        quantity_transfer_delivery,
      </if>
      <if test="quantityTransferInbound != null">
        quantity_transfer_inbound,
      </if>
      <if test="quantityTransfer != null">
        quantity_transfer,
      </if>
      <if test="quantityTransferPlan != null">
        quantity_transfer_plan,
      </if>
      <if test="recordTime != null">
        record_time,
      </if>
      <if test="companyId != null">
        company_id,
      </if>
      <if test="unitPrice != null">
        unit_price,
      </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="warehouseCode != null">
        #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="sourceWarehouseCode != null">
        #{sourceWarehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="quantityTransferDelivery != null">
        #{quantityTransferDelivery,jdbcType=INTEGER},
      </if>
      <if test="quantityTransferInbound != null">
        #{quantityTransferInbound,jdbcType=INTEGER},
      </if>
      <if test="quantityTransfer != null">
        #{quantityTransfer,jdbcType=INTEGER},
      </if>
      <if test="quantityTransferPlan != null">
        #{quantityTransferPlan,jdbcType=INTEGER},
      </if>
      <if test="recordTime != null">
        #{recordTime,jdbcType=DATE},
      </if>
      <if test="companyId != null">
        #{companyId,jdbcType=INTEGER},
      </if>
      <if test="unitPrice != null">
        #{unitPrice,jdbcType=DECIMAL},
      </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="warehouseCode != null">
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="sourceWarehouseCode != null">
        source_warehouse_code = #{sourceWarehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="quantityTransferDelivery != null">
        quantity_transfer_delivery = #{quantityTransferDelivery,jdbcType=INTEGER},
      </if>
      <if test="quantityTransferInbound != null">
        quantity_transfer_inbound = #{quantityTransferInbound,jdbcType=INTEGER},
      </if>
      <if test="quantityTransfer != null">
        quantity_transfer = #{quantityTransfer,jdbcType=INTEGER},
      </if>
      <if test="quantityTransferPlan != null">
        quantity_transfer_plan = #{quantityTransferPlan,jdbcType=INTEGER},
      </if>
      <if test="recordTime != null">
        record_time = #{recordTime,jdbcType=DATE},
      </if>
      <if test="companyId != null">
        company_id = #{companyId,jdbcType=INTEGER},
      </if>
      <if test="unitPrice != null">
        unit_price = #{unitPrice,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <insert id="upsert" parameterType="com.bailuntec.domain.entity.DcDailyTransitFrom">
    <!--
      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_daily_transit_from
    (id, gmt_create, gmt_modified, bailun_sku, warehouse_code, source_warehouse_code, 
      quantity_transfer_delivery, quantity_transfer_inbound, quantity_transfer, quantity_transfer_plan, 
      record_time, company_id, unit_price)
    values
    (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, 
      #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, #{sourceWarehouseCode,jdbcType=VARCHAR}, 
      #{quantityTransferDelivery,jdbcType=INTEGER}, #{quantityTransferInbound,jdbcType=INTEGER}, 
      #{quantityTransfer,jdbcType=INTEGER}, #{quantityTransferPlan,jdbcType=INTEGER}, 
      #{recordTime,jdbcType=DATE}, #{companyId,jdbcType=INTEGER}, #{unitPrice,jdbcType=DECIMAL}
      )
    on duplicate key update 
    id = #{id,jdbcType=INTEGER}, 
    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 
    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 
    bailun_sku = #{bailunSku,jdbcType=VARCHAR}, 
    warehouse_code = #{warehouseCode,jdbcType=VARCHAR}, 
    source_warehouse_code = #{sourceWarehouseCode,jdbcType=VARCHAR}, 
    quantity_transfer_delivery = #{quantityTransferDelivery,jdbcType=INTEGER}, 
    quantity_transfer_inbound = #{quantityTransferInbound,jdbcType=INTEGER}, 
    quantity_transfer = #{quantityTransfer,jdbcType=INTEGER}, 
    quantity_transfer_plan = #{quantityTransferPlan,jdbcType=INTEGER}, 
    record_time = #{recordTime,jdbcType=DATE}, 
    company_id = #{companyId,jdbcType=INTEGER}, 
    unit_price = #{unitPrice,jdbcType=DECIMAL}
  </insert>
  <select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcDailyTransitFromExample" 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_daily_transit_from
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    limit 1
  </select>

  <select id="selectQuantityTransferTransitFrom" resultType="com.bailuntec.domain.dto.TransferTransitQuantity">
    SELECT
	bailun_sku AS bailunSku,
	source_warehouse_code AS sourceWarehouseCode,
	warehouse_code AS warehouseCode,
	sum( count ) AS count
FROM
	(
	SELECT
		tb5.bailun_sku bailun_sku,
		tb5.source_warehouse_code source_warehouse_code,
		tb5.warehouse_code warehouse_code,
		( tb5.count - IFNULL( tb4.count, 0 ) ) AS count
	FROM
		(
		SELECT
			tb1.bailun_sku,
			tb1.source_warehouse_code,
			tb1.warehouse_code,
			sum( tb1.count ) count
		FROM
			dc_base_transfer_bale tb1
			LEFT JOIN dc_base_transfer_complete tb2 ON tb1.transfer_order_id = tb2.transfer_order_id
		WHERE
			tb2.transfer_order_id IS NULL
			AND tb1.deleted = 0
		GROUP BY
			bailun_sku,
			source_warehouse_code,
			warehouse_code
		) tb5
		LEFT JOIN (
		SELECT
			bailun_sku,
			source_warehouse_code,
			warehouse_code,
			sum( count ) count
		FROM
			(
			SELECT
				t1.bailun_sku,
				t1.source_warehouse_code,
				t1.warehouse_code,
				( CASE WHEN t2.count > tbb.count THEN tbb.count ELSE t2.count END ) AS count,
				t1.transfer_order_id
			FROM
				(
				SELECT
					max( create_time ) AS create_time,
					bailun_sku,
					source_warehouse_code,
					warehouse_code,
					transfer_order_id
				FROM
					dc_base_transfer_inbound
				WHERE
					deleted = 0
				GROUP BY
					bailun_sku,
					source_warehouse_code,
					warehouse_code,
					transfer_order_id
				) t1
				INNER JOIN dc_base_transfer_inbound t2 ON t1.bailun_sku = t2.bailun_sku
				AND t1.source_warehouse_code = t2.source_warehouse_code
				AND t1.warehouse_code = t2.warehouse_code
				AND t1.transfer_order_id = t2.transfer_order_id
				AND t1.create_time = t2.create_time
				LEFT JOIN dc_base_transfer_bale tbb ON t1.bailun_sku = tbb.bailun_sku
				AND t1.source_warehouse_code = tbb.source_warehouse_code
				AND t1.warehouse_code = tbb.warehouse_code
				AND t1.transfer_order_id = tbb.transfer_order_id
				LEFT JOIN dc_base_transfer_complete tb2 ON t1.transfer_order_id = tb2.transfer_order_id
			WHERE
				tb2.bailun_sku IS NULL
			) tb3
		GROUP BY
			bailun_sku,
			source_warehouse_code,
			warehouse_code
		) tb4 ON tb5.bailun_sku = tb4.bailun_sku
		AND tb5.source_warehouse_code = tb4.source_warehouse_code
		AND tb5.warehouse_code = tb4.warehouse_code
	WHERE
		( tb5.count - IFNULL( tb4.count, 0 ) ) > 0
	) t
GROUP BY
	bailun_sku,
	source_warehouse_code,
	warehouse_code
  </select>

  <insert id="calculateTransferTransitFrom">
    insert into dc_daily_transit_from(bailun_sku, warehouse_code, quantity_transfer,quantity_transfer_plan, record_time, source_warehouse_code)
    values
    <foreach collection="list" item="item" index="index" separator=",">
      (
      #{item.bailunSku,jdbcType=VARCHAR}, #{item.warehouseCode,jdbcType=VARCHAR}, #{item.count,jdbcType=INTEGER},#{item.countplan,jdbcType=INTEGER}, #{localDate}, #{item.sourceWarehouseCode,jdbcType=VARCHAR}
      )
    </foreach>
  </insert>

  <select id="selectQuantityTransferDelivery" resultType="com.bailuntec.domain.dto.TransferTransitQuantity">
    select bailun_sku, warehouse_code, source_warehouse_code, sum(count) as count
    from dc_base_transfer_delivery
    where create_time &gt;= date_sub(#{localDate}, INTERVAL 30 day)
    and create_time &lt; #{localDate}
    and deleted = 0
    group by bailun_sku, source_warehouse_code, warehouse_code
  </select>

  <select id="selectQuantityTransferInbound" resultType="com.bailuntec.domain.dto.TransferTransitQuantity">
    select bailun_sku, warehouse_code, source_warehouse_code, sum(count) as count from
    (SELECT
    t1.bailun_sku,
    t1.warehouse_code,
    t1.source_warehouse_code,
    t1.transfer_order_id,
    t1.create_time,
    sum(t1.count) as count
    FROM
    dc_base_transfer_complete t1
    LEFT JOIN dc_base_transfer_inbound tb2 ON t1.transfer_order_id = tb2.transfer_order_id and t1.bailun_sku = tb2.bailun_sku and t1.warehouse_code = tb2.warehouse_code and t1.source_warehouse_code = tb2.source_warehouse_code and tb2.deleted = 0 and	tb2.create_time &lt; #{localDate} and tb2.create_time &gt;= date_sub(#{localDate}, INTERVAL 30 day)
    WHERE
    tb2.bailun_sku IS NULL
    AND t1.deleted = 0
    AND t1.create_time &gt;= date_sub(#{localDate}, INTERVAL 30 day)
    AND t1.create_time &lt; #{localDate}
    GROUP BY
    t1.bailun_sku,
    t1.warehouse_code,
    t1.source_warehouse_code,
    t1.transfer_order_id
    UNION ALL
    SELECT
    t1.bailun_sku,
    t1.warehouse_code,
    t1.source_warehouse_code,
    t1.transfer_order_id,
    t1.create_time,
    t2.count
    FROM
    (
    SELECT
    max(create_time) AS create_time,
    bailun_sku,
    warehouse_code,
    source_warehouse_code,
    transfer_order_id
    FROM
    dc_base_transfer_inbound
    WHERE
    deleted = 0
    and create_time &gt;= date_sub(#{localDate}, INTERVAL 30 day)
    and create_time &lt; #{localDate}
    GROUP BY
    bailun_sku,
    warehouse_code,
    source_warehouse_code,
    transfer_order_id) t1
    INNER JOIN dc_base_transfer_inbound t2 ON t1.bailun_sku = t2.bailun_sku
    AND t1.warehouse_code = t2.warehouse_code
    AND t1.source_warehouse_code = t2.source_warehouse_code
    AND t1.transfer_order_id = t2.transfer_order_id
    AND t1.create_time = t2.create_time) t
    group by bailun_sku, source_warehouse_code, warehouse_code
  </select>

  <update id="updateSkuUnitPrice">
         update dc_daily_transit_from t1, dc_base_sku t2 set t1.unit_price = t2.unit_price WHERE t1.record_time = #{localDate} and t1.bailun_sku=t2.bailun_sku
  </update>

  <update id="updateWarehouseName">
    update dc_daily_transit_from t1, dc_base_warehouse t2 set t1.warehouse_name = t2.warehouse_name where t1.warehouse_code = t2.warehouse_code and t1.record_time = #{localDate}
  </update>

  <update id="updateSourceWarehouseName">
    update dc_daily_transit_from t1, dc_base_warehouse t2 set t1.source_warehouse_name = t2.warehouse_name where t1.source_warehouse_code = t2.warehouse_code and t1.record_time = #{localDate}
  </update>

</mapper>