<?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.DcMidTransitMapper">
    <resultMap id="BaseResultMap" type="com.bailuntec.domain.entity.DcMidTransit">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <id column="id" jdbcType="INTEGER" property="id"/>
        <result column="bailun_sku" jdbcType="VARCHAR" property="bailunSku"/>
        <result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode"/>
        <result column="quantity_purchase" jdbcType="INTEGER" property="quantityPurchase"/>
        <result column="gmt_purchase_modified" jdbcType="TIMESTAMP" property="gmtPurchaseModified"/>
        <result column="quantity_transfer" jdbcType="INTEGER" property="quantityTransfer"/>
        <result column="gmt_transfer_modified" jdbcType="TIMESTAMP" property="gmtTransferModified"/>
        <result column="quantity_out_stock" jdbcType="INTEGER" property="quantityOutStock"/>
        <result column="gmt_out_stock_modified" jdbcType="TIMESTAMP" property="gmtOutStockModified"/>
        <result column="quantity_unshipped" jdbcType="INTEGER" property="quantityUnshipped"/>
        <result column="gmt_unshipped_modified" jdbcType="TIMESTAMP" property="gmtUnshippedModified"/>
        <result column="company_id" jdbcType="INTEGER" property="companyId"/>
        <result column="amount_purchase_transit" jdbcType="DECIMAL" property="amountPurchaseTransit"/>
    </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, bailun_sku, warehouse_code, quantity_purchase, gmt_purchase_modified, quantity_transfer,
        gmt_transfer_modified, quantity_out_stock, gmt_out_stock_modified, quantity_unshipped,
        gmt_unshipped_modified, company_id, amount_purchase_transit
    </sql>
    <select id="selectByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample"
            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_mid_transit
        <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_mid_transit
        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_mid_transit
        where id = #{id,jdbcType=INTEGER}
    </delete>
    <delete id="deleteByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from dc_mid_transit
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
    </delete>

    <insert id="insert" parameterType="com.bailuntec.domain.entity.DcMidTransit">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        insert into dc_mid_transit (id, bailun_sku, warehouse_code,
        quantity_purchase, gmt_purchase_modified,
        quantity_transfer, gmt_transfer_modified,
        quantity_out_stock, gmt_out_stock_modified,
        quantity_unshipped, gmt_unshipped_modified,
        company_id, amount_purchase_transit)
        values (#{id,jdbcType=INTEGER}, #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR},
        #{quantityPurchase,jdbcType=INTEGER}, #{gmtPurchaseModified,jdbcType=TIMESTAMP},
        #{quantityTransfer,jdbcType=INTEGER}, #{gmtTransferModified,jdbcType=TIMESTAMP},
        #{quantityOutStock,jdbcType=INTEGER}, #{gmtOutStockModified,jdbcType=TIMESTAMP},
        #{quantityUnshipped,jdbcType=INTEGER}, #{gmtUnshippedModified,jdbcType=TIMESTAMP},
        #{companyId,jdbcType=INTEGER}, #{amountPurchaseTransit,jdbcType=DECIMAL})
    </insert>
    <insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcMidTransit">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        insert into dc_mid_transit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="bailunSku != null">
                bailun_sku,
            </if>
            <if test="warehouseCode != null">
                warehouse_code,
            </if>
            <if test="quantityPurchase != null">
                quantity_purchase,
            </if>
            <if test="gmtPurchaseModified != null">
                gmt_purchase_modified,
            </if>
            <if test="quantityTransfer != null">
                quantity_transfer,
            </if>
            <if test="gmtTransferModified != null">
                gmt_transfer_modified,
            </if>
            <if test="quantityOutStock != null">
                quantity_out_stock,
            </if>
            <if test="gmtOutStockModified != null">
                gmt_out_stock_modified,
            </if>
            <if test="quantityUnshipped != null">
                quantity_unshipped,
            </if>
            <if test="gmtUnshippedModified != null">
                gmt_unshipped_modified,
            </if>
            <if test="companyId != null">
                company_id,
            </if>
            <if test="amountPurchaseTransit != null">
                amount_purchase_transit,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="bailunSku != null">
                #{bailunSku,jdbcType=VARCHAR},
            </if>
            <if test="warehouseCode != null">
                #{warehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="quantityPurchase != null">
                #{quantityPurchase,jdbcType=INTEGER},
            </if>
            <if test="gmtPurchaseModified != null">
                #{gmtPurchaseModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityTransfer != null">
                #{quantityTransfer,jdbcType=INTEGER},
            </if>
            <if test="gmtTransferModified != null">
                #{gmtTransferModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityOutStock != null">
                #{quantityOutStock,jdbcType=INTEGER},
            </if>
            <if test="gmtOutStockModified != null">
                #{gmtOutStockModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityUnshipped != null">
                #{quantityUnshipped,jdbcType=INTEGER},
            </if>
            <if test="gmtUnshippedModified != null">
                #{gmtUnshippedModified,jdbcType=TIMESTAMP},
            </if>
            <if test="companyId != null">
                #{companyId,jdbcType=INTEGER},
            </if>
            <if test="amountPurchaseTransit != null">
                #{amountPurchaseTransit,jdbcType=DECIMAL},
            </if>
        </trim>
    </insert>
    <select id="countByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample"
            resultType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        select count(*) from dc_mid_transit
        <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_mid_transit
        <set>
            <if test="record.id != null">
                id = #{record.id,jdbcType=INTEGER},
            </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.quantityPurchase != null">
                quantity_purchase = #{record.quantityPurchase,jdbcType=INTEGER},
            </if>
            <if test="record.gmtPurchaseModified != null">
                gmt_purchase_modified = #{record.gmtPurchaseModified,jdbcType=TIMESTAMP},
            </if>
            <if test="record.quantityTransfer != null">
                quantity_transfer = #{record.quantityTransfer,jdbcType=INTEGER},
            </if>
            <if test="record.gmtTransferModified != null">
                gmt_transfer_modified = #{record.gmtTransferModified,jdbcType=TIMESTAMP},
            </if>
            <if test="record.quantityOutStock != null">
                quantity_out_stock = #{record.quantityOutStock,jdbcType=INTEGER},
            </if>
            <if test="record.gmtOutStockModified != null">
                gmt_out_stock_modified = #{record.gmtOutStockModified,jdbcType=TIMESTAMP},
            </if>
            <if test="record.quantityUnshipped != null">
                quantity_unshipped = #{record.quantityUnshipped,jdbcType=INTEGER},
            </if>
            <if test="record.gmtUnshippedModified != null">
                gmt_unshipped_modified = #{record.gmtUnshippedModified,jdbcType=TIMESTAMP},
            </if>
            <if test="record.companyId != null">
                company_id = #{record.companyId,jdbcType=INTEGER},
            </if>
            <if test="record.amountPurchaseTransit != null">
                amount_purchase_transit = #{record.amountPurchaseTransit,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_mid_transit
        set id = #{record.id,jdbcType=INTEGER},
        bailun_sku = #{record.bailunSku,jdbcType=VARCHAR},
        warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
        quantity_purchase = #{record.quantityPurchase,jdbcType=INTEGER},
        gmt_purchase_modified = #{record.gmtPurchaseModified,jdbcType=TIMESTAMP},
        quantity_transfer = #{record.quantityTransfer,jdbcType=INTEGER},
        gmt_transfer_modified = #{record.gmtTransferModified,jdbcType=TIMESTAMP},
        quantity_out_stock = #{record.quantityOutStock,jdbcType=INTEGER},
        gmt_out_stock_modified = #{record.gmtOutStockModified,jdbcType=TIMESTAMP},
        quantity_unshipped = #{record.quantityUnshipped,jdbcType=INTEGER},
        gmt_unshipped_modified = #{record.gmtUnshippedModified,jdbcType=TIMESTAMP},
        company_id = #{record.companyId,jdbcType=INTEGER},
        amount_purchase_transit = #{record.amountPurchaseTransit,jdbcType=DECIMAL}
        <if test="_parameter != null">
            <include refid="Update_By_Example_Where_Clause"/>
        </if>
    </update>
    <update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.DcMidTransit">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update dc_mid_transit
        <set>
            <if test="bailunSku != null">
                bailun_sku = #{bailunSku,jdbcType=VARCHAR},
            </if>
            <if test="warehouseCode != null">
                warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="quantityPurchase != null">
                quantity_purchase = #{quantityPurchase,jdbcType=INTEGER},
            </if>
            <if test="gmtPurchaseModified != null">
                gmt_purchase_modified = #{gmtPurchaseModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityTransfer != null">
                quantity_transfer = #{quantityTransfer,jdbcType=INTEGER},
            </if>
            <if test="gmtTransferModified != null">
                gmt_transfer_modified = #{gmtTransferModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityOutStock != null">
                quantity_out_stock = #{quantityOutStock,jdbcType=INTEGER},
            </if>
            <if test="gmtOutStockModified != null">
                gmt_out_stock_modified = #{gmtOutStockModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityUnshipped != null">
                quantity_unshipped = #{quantityUnshipped,jdbcType=INTEGER},
            </if>
            <if test="gmtUnshippedModified != null">
                gmt_unshipped_modified = #{gmtUnshippedModified,jdbcType=TIMESTAMP},
            </if>
            <if test="companyId != null">
                company_id = #{companyId,jdbcType=INTEGER},
            </if>
            <if test="amountPurchaseTransit != null">
                amount_purchase_transit = #{amountPurchaseTransit,jdbcType=DECIMAL},
            </if>
        </set>
        where id = #{id,jdbcType=INTEGER}
    </update>
    <update id="updateByPrimaryKey" parameterType="com.bailuntec.domain.entity.DcMidTransit">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update dc_mid_transit
        set bailun_sku = #{bailunSku,jdbcType=VARCHAR},
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
        quantity_purchase = #{quantityPurchase,jdbcType=INTEGER},
        gmt_purchase_modified = #{gmtPurchaseModified,jdbcType=TIMESTAMP},
        quantity_transfer = #{quantityTransfer,jdbcType=INTEGER},
        gmt_transfer_modified = #{gmtTransferModified,jdbcType=TIMESTAMP},
        quantity_out_stock = #{quantityOutStock,jdbcType=INTEGER},
        gmt_out_stock_modified = #{gmtOutStockModified,jdbcType=TIMESTAMP},
        quantity_unshipped = #{quantityUnshipped,jdbcType=INTEGER},
        gmt_unshipped_modified = #{gmtUnshippedModified,jdbcType=TIMESTAMP},
        company_id = #{companyId,jdbcType=INTEGER},
        amount_purchase_transit = #{amountPurchaseTransit,jdbcType=DECIMAL}
        where id = #{id,jdbcType=INTEGER}
    </update>
    <insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcMidTransit">
        <!--
          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_mid_transit
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="bailunSku != null">
                bailun_sku,
            </if>
            <if test="warehouseCode != null">
                warehouse_code,
            </if>
            <if test="quantityPurchase != null">
                quantity_purchase,
            </if>
            <if test="gmtPurchaseModified != null">
                gmt_purchase_modified,
            </if>
            <if test="quantityTransfer != null">
                quantity_transfer,
            </if>
            <if test="gmtTransferModified != null">
                gmt_transfer_modified,
            </if>
            <if test="quantityOutStock != null">
                quantity_out_stock,
            </if>
            <if test="gmtOutStockModified != null">
                gmt_out_stock_modified,
            </if>
            <if test="quantityUnshipped != null">
                quantity_unshipped,
            </if>
            <if test="gmtUnshippedModified != null">
                gmt_unshipped_modified,
            </if>
            <if test="companyId != null">
                company_id,
            </if>
            <if test="amountPurchaseTransit != null">
                amount_purchase_transit,
            </if>
        </trim>
        values
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=INTEGER},
            </if>
            <if test="bailunSku != null">
                #{bailunSku,jdbcType=VARCHAR},
            </if>
            <if test="warehouseCode != null">
                #{warehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="quantityPurchase != null">
                #{quantityPurchase,jdbcType=INTEGER},
            </if>
            <if test="gmtPurchaseModified != null">
                #{gmtPurchaseModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityTransfer != null">
                #{quantityTransfer,jdbcType=INTEGER},
            </if>
            <if test="gmtTransferModified != null">
                #{gmtTransferModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityOutStock != null">
                #{quantityOutStock,jdbcType=INTEGER},
            </if>
            <if test="gmtOutStockModified != null">
                #{gmtOutStockModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityUnshipped != null">
                #{quantityUnshipped,jdbcType=INTEGER},
            </if>
            <if test="gmtUnshippedModified != null">
                #{gmtUnshippedModified,jdbcType=TIMESTAMP},
            </if>
            <if test="companyId != null">
                #{companyId,jdbcType=INTEGER},
            </if>
            <if test="amountPurchaseTransit != null">
                #{amountPurchaseTransit,jdbcType=DECIMAL},
            </if>
        </trim>
        on duplicate key update
        <trim suffixOverrides=",">
            <if test="id != null">
                id = #{id,jdbcType=INTEGER},
            </if>
            <if test="bailunSku != null">
                bailun_sku = #{bailunSku,jdbcType=VARCHAR},
            </if>
            <if test="warehouseCode != null">
                warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
            </if>
            <if test="quantityPurchase != null">
                quantity_purchase = #{quantityPurchase,jdbcType=INTEGER},
            </if>
            <if test="gmtPurchaseModified != null">
                gmt_purchase_modified = #{gmtPurchaseModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityTransfer != null">
                quantity_transfer = #{quantityTransfer,jdbcType=INTEGER},
            </if>
            <if test="gmtTransferModified != null">
                gmt_transfer_modified = #{gmtTransferModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityOutStock != null">
                quantity_out_stock = #{quantityOutStock,jdbcType=INTEGER},
            </if>
            <if test="gmtOutStockModified != null">
                gmt_out_stock_modified = #{gmtOutStockModified,jdbcType=TIMESTAMP},
            </if>
            <if test="quantityUnshipped != null">
                quantity_unshipped = #{quantityUnshipped,jdbcType=INTEGER},
            </if>
            <if test="gmtUnshippedModified != null">
                gmt_unshipped_modified = #{gmtUnshippedModified,jdbcType=TIMESTAMP},
            </if>
            <if test="companyId != null">
                company_id = #{companyId,jdbcType=INTEGER},
            </if>
            <if test="amountPurchaseTransit != null">
                amount_purchase_transit = #{amountPurchaseTransit,jdbcType=DECIMAL},
            </if>
        </trim>
    </insert>
    <insert id="upsert" parameterType="com.bailuntec.domain.entity.DcMidTransit">
        <!--
          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_mid_transit
        (id, bailun_sku, warehouse_code, quantity_purchase, gmt_purchase_modified, quantity_transfer,
        gmt_transfer_modified, quantity_out_stock, gmt_out_stock_modified, quantity_unshipped,
        gmt_unshipped_modified, company_id, amount_purchase_transit)
        values
        (#{id,jdbcType=INTEGER}, #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR},
        #{quantityPurchase,jdbcType=INTEGER}, #{gmtPurchaseModified,jdbcType=TIMESTAMP},
        #{quantityTransfer,jdbcType=INTEGER}, #{gmtTransferModified,jdbcType=TIMESTAMP},
        #{quantityOutStock,jdbcType=INTEGER}, #{gmtOutStockModified,jdbcType=TIMESTAMP},
        #{quantityUnshipped,jdbcType=INTEGER}, #{gmtUnshippedModified,jdbcType=TIMESTAMP},
        #{companyId,jdbcType=INTEGER}, #{amountPurchaseTransit,jdbcType=DECIMAL})
        on duplicate key update
        id = #{id,jdbcType=INTEGER},
        bailun_sku = #{bailunSku,jdbcType=VARCHAR},
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
        quantity_purchase = #{quantityPurchase,jdbcType=INTEGER},
        gmt_purchase_modified = #{gmtPurchaseModified,jdbcType=TIMESTAMP},
        quantity_transfer = #{quantityTransfer,jdbcType=INTEGER},
        gmt_transfer_modified = #{gmtTransferModified,jdbcType=TIMESTAMP},
        quantity_out_stock = #{quantityOutStock,jdbcType=INTEGER},
        gmt_out_stock_modified = #{gmtOutStockModified,jdbcType=TIMESTAMP},
        quantity_unshipped = #{quantityUnshipped,jdbcType=INTEGER},
        gmt_unshipped_modified = #{gmtUnshippedModified,jdbcType=TIMESTAMP},
        company_id = #{companyId,jdbcType=INTEGER},
        amount_purchase_transit = #{amountPurchaseTransit,jdbcType=DECIMAL}
    </insert>
    <select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcMidTransitExample"
            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_mid_transit
        <if test="_parameter != null">
            <include refid="Example_Where_Clause"/>
        </if>
        <if test="orderByClause != null">
            order by ${orderByClause}
        </if>
        limit 1
    </select>

    <!--  <select id="selectQuantityTransferTransit" resultType="com.bailuntec.domain.dto.TransferTransitQuantity">-->
    <!--    SELECT bailun_sku                                 as bailunSku,-->
    <!--           warehouse_code                             as warehouseCode,-->
    <!--           sum(count)                                 as count,-->
    <!--           sum(countplan)                             as countplan,-->
    <!--           sum(IF(transport_type = '国内陆运', count, 0)) as landCount,-->
    <!--           sum(IF(transport_type = '海运', count, 0))   as oceanCount,-->
    <!--           sum(IF(transport_type = '空运', count, 0))   as airCount,-->
    <!--           sum(IF(transport_type = '铁路运输', count, 0)) as railwayCount-->
    <!--    FROM (-->
    <!--           SELECT tb5.bailun_sku                         bailun_sku,-->
    <!--                  tb5.warehouse_code                     warehouse_code,-->
    <!--                  (-->
    <!--                    tb5.count - IFNULL(tb4.count, 0)) AS count,-->
    <!--                  0                                   as countplan,-->
    <!--                  tb5.transport_type                     transport_type-->
    <!--           FROM (-->
    <!--                  SELECT tb1.bailun_sku,-->
    <!--                         tb1.warehouse_code,-->
    <!--                         sum(tb1.count) count,-->
    <!--                         tb1.transport_type-->
    <!--                  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,-->
    <!--                           warehouse_code-->
    <!--                ) tb5-->
    <!--                  LEFT JOIN (-->
    <!--             SELECT bailun_sku,-->
    <!--                    warehouse_code,-->
    <!--                    sum(count) count-->
    <!--             FROM (-->
    <!--                    SELECT t1.bailun_sku,-->
    <!--                           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, warehouse_code, transfer_order_id-->
    <!--                          FROM dc_base_transfer_inbound-->
    <!--                          WHERE deleted = 0-->
    <!--                          GROUP BY bailun_sku, 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.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.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,-->
    <!--                      warehouse_code-->
    <!--           ) tb4 ON tb5.bailun_sku = tb4.bailun_sku-->
    <!--             AND tb5.warehouse_code = tb4.warehouse_code-->
    <!--           WHERE (-->
    <!--                   tb5.count - IFNULL(tb4.count, 0)) > 0-->
    <!--           UNION ALL-->
    <!--           SELECT bailun_sku,-->
    <!--                  warehouse_code,-->
    <!--                  sum(count) AS count,-->
    <!--                  sum(count) AS countplan,-->
    <!--                  transport_type-->
    <!--           FROM dc_base_transfer_plan-->
    <!--           WHERE STATUS = 1-->
    <!--             AND deleted = 0-->
    <!--           GROUP BY bailun_sku,-->
    <!--                    warehouse_code-->
    <!--         ) t-->
    <!--    GROUP BY bailun_sku,-->
    <!--             warehouse_code-->
    <!--  </select>-->

    <select id="selectQuantityTransferTransit" resultType="com.bailuntec.domain.dto.TransferTransitQuantity">
        SELECT bailun_sku                                 as bailunSku,
               warehouse_code                             as warehouseCode,
               sum(count)                                 as `count`,
               sum(countplan)                             as countplan,
               sum(IF(transport_type = '国内陆运', count, 0)) as landCount,
               sum(IF(transport_type = '海运', count, 0))   as oceanCount,
               sum(IF(transport_type = '空运', count, 0))   as airCount,
               sum(IF(transport_type = '铁路运输', count, 0)) as railwayCount
        FROM (
                 SELECT t1.targetwareno                                                                      as warehouse_code,
                        t2.sku                                                                               as bailun_sku,
                        t1.transporttype                                                                     as transport_type,
                        if(t2.deliverycount - t2.storagecount &lt; 0, 0, t2.deliverycount - t2.storagecount) as `count`,
                        0                                                                                    as countplan
                 FROM dc_base_transfer_info t1
                          LEFT JOIN dc_base_transfer_info_skus t2 on t1.dataid = t2.dataid
                 where t1.stateid &lt; 5
                   and t1.isdeleted = 0
                   and t1.isexception = 0
                 UNION ALL
                 SELECT bailun_sku,
                        warehouse_code,
                        `count`,
                        `count` AS countplan,
                        transport_type
                 FROM dc_base_transfer_plan
                 WHERE STATUS = 1
                   AND deleted = 0
             ) t
        where t.bailun_sku is not null
        GROUP BY bailun_sku, warehouse_code
    </select>

    <insert id="calculateTransferTransit">
        insert into dc_mid_transit(bailun_sku, warehouse_code,
        quantity_transfer,quantity_transfer_plan,quantity_land_transfer,quantity_ocean_transfer,quantity_air_transfer,quantity_railway_transfer,
        gmt_transfer_modified)
        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},
            #{item.landCount,jdbcType=INTEGER},
            #{item.oceanCount,jdbcType=INTEGER},
            #{item.airCount,jdbcType=INTEGER},
            #{item.railwayCount,jdbcType=INTEGER},
            #{localDateTime,jdbcType=TIMESTAMP}
            )
        </foreach>
        ON DUPLICATE KEY UPDATE
        quantity_transfer = values(quantity_transfer),
        quantity_transfer_plan = values(quantity_transfer_plan),
        quantity_land_transfer = values(quantity_land_transfer),
        quantity_ocean_transfer = values(quantity_ocean_transfer),
        quantity_air_transfer = values(quantity_air_transfer),
        quantity_railway_transfer = values(quantity_railway_transfer),
        gmt_transfer_modified = values(gmt_transfer_modified)
    </insert>

    <insert id="calculatePurchaseTransit">
        insert into dc_mid_transit(bailun_sku, warehouse_code,
        quantity_purchase,
        amount_purchase_transit,
        quantity_land_purchase,
        quantity_ocean_purchase,
        quantity_air_purchase,
        quantity_railway_purchase,
        gmt_purchase_modified)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.bailunSku,jdbcType=VARCHAR}, #{item.warehouseCode,jdbcType=VARCHAR}, #{item.count,jdbcType=INTEGER},
            #{item.amountPurchaseTransit,jdbcType=DECIMAL},#{item.landCount,jdbcType=INTEGER},#{item.oceanCount,jdbcType=INTEGER},#{item.airCount,jdbcType=INTEGER},#{item.railwayCount,jdbcType=INTEGER},
            #{localDateTime,jdbcType=TIMESTAMP}
            )
        </foreach>
        ON DUPLICATE KEY UPDATE quantity_purchase = values(quantity_purchase), amount_purchase_transit =
        values(amount_purchase_transit),quantity_land_purchase = values(quantity_land_purchase),quantity_ocean_purchase
        = values(quantity_ocean_purchase),quantity_air_purchase =
        values(quantity_air_purchase),quantity_railway_purchase = values(quantity_railway_purchase),
        gmt_purchase_modified = values(gmt_purchase_modified)
    </insert>

    <insert id="calculateOutStock">
        insert into dc_mid_transit(bailun_sku,
        warehouse_code,
        quantity_out_stock,
        gmt_out_stock_modified,
        quantity_out_stock_aliexpress)
        values
        <foreach collection="list" item="item" index="index" separator=",">
            (
            #{item.bailunSku,jdbcType=VARCHAR},
            #{item.warehouseCode,jdbcType=VARCHAR},
            #{item.quantityOutStock,jdbcType=INTEGER},
            #{localDateTime,jdbcType=TIMESTAMP},
            #{item.aliexpressQuantity, jdbcType=INTEGER
                }
            )
        </foreach>
        ON DUPLICATE KEY UPDATE quantity_out_stock = values(quantity_out_stock) ,gmt_out_stock_modified =
        values(gmt_out_stock_modified), quantity_out_stock_aliexpress = values(quantity_out_stock_aliexpress)
    </insert>

    <delete id="deleteMidDailyTransit">
        delete
        from dc_daily_transit
        where record_time = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
    </delete>

    <insert id="insertMidDailyTransit">
        INSERT into dc_daily_transit (`bailun_sku`,
                                      `warehouse_code`,
                                      `quantity_purchase`,
                                      `quantity_transfer`,
                                      `quantity_transfer_plan`,
                                      `record_time`)
        SELECT `bailun_sku`,
               `warehouse_code`,
               `quantity_purchase`,
               `quantity_transfer`,
               `quantity_transfer_plan`,
               DATE_SUB(CURDATE(), INTERVAL 1 DAY)
        FROM dc_mid_transit
    </insert>

    <update id="updateSkuUnitPrice">
        update dc_daily_transit t1, dc_base_sku t2
        set t1.unit_price = t2.unit_price
        WHERE t1.record_time = DATE_SUB(CURDATE(), INTERVAL 1 DAY)
          and t1.bailun_sku = t2.bailun_sku
    </update>

    <select id="selectQuantityOutStock" resultType="com.bailuntec.domain.dto.OutStockQuantity">
        SELECT t1.bailun_sku                  as bailunSku,
               t1.warehouse_code              as warehouseCode,
               t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_pushed - t2.usable_stock - t2.occupy_stock +
               ifnull(t3.safe_stock, 0)       as quantityOutStock,
               if((t1.aliexpress_quantity - t2.usable_stock - t2.occupy_stock + ifnull(t3.safe_stock, 0)) &lt; 0, 0,
                  (t1.aliexpress_quantity - t2.usable_stock - t2.occupy_stock +
                   ifnull(t3.safe_stock, 0))) as aliexpressQuantity
        FROM (
                 SELECT bailun_sku,
                        warehouse_code,
                        SUM(bailun_sku_quantity_ordered) AS bailun_sku_quantity_ordered,
                        SUM(bailun_sku_quantity_pushed)  AS bailun_sku_quantity_pushed,
                        sum(case
                                when platform_type = 'Aliexpress'
                                    then bailun_sku_quantity_ordered - bailun_sku_quantity_pushed
                                else 0 end)              as aliexpress_quantity
                 FROM dc_base_oms_sku_30
                 WHERE bailun_order_status = 'Handling'
                   and company_id = 1
                   and has_delete = 0
                   and has_scalp = 0
                   and has_buyer_remark = 0
                   and has_platsku_remark = 0
                   and has_fba_s = 0
                   and has_innersale = 0
                   and paid_time >= '2019-03-01 12:00:00'
                   and bailun_sku_quantity_ordered > bailun_sku_quantity_shipped
                   and bailun_interception_status in ('None', 'Failed')
                   and warehouse_code != ''
                   and platform_type != 'FBA'
                 GROUP BY bailun_sku, warehouse_code
             ) t1
                 INNER JOIN dc_base_stock t2 ON t1.bailun_sku = t2.bailun_sku and t1.warehouse_code = t2.warehouse_code
                 LEFT JOIN dc_auto_jit_inventory t3
                           ON t1.bailun_sku = t3.bailun_sku and t1.warehouse_code = t3.warehouse_code and t3.status = 1
        WHERE (t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_pushed - t2.usable_stock - t2.occupy_stock +
               ifnull(t3.safe_stock, 0)) >= 0
    </select>

    <select id="selectQuantityPurchaseTransit" resultType="com.bailuntec.domain.dto.PurchaseTransitQuantity">
        SELECT bailun_sku                                              as bailunSku,
               warehouse_code                                          as warehouseCode,
               sum(count)                                              as count,
               sum(count * price)                                      AS amountPurchaseTransit,
               sum(case when transport_type = 1 then count else 0 end) as landCount,
               sum(case when transport_type = 2 then count else 0 end) as oceanCount,
               sum(case when transport_type = 3 then count else 0 end) as airCount,
               sum(case when transport_type = 4 then count else 0 end) as railwayCount
        FROM (
                 SELECT tb1.bailun_sku                              AS bailun_sku,
                        tb1.warehouse_code                          AS warehouse_code,
                        tb1.purchase_id                             AS purchase_id,
                        sum(if((tb1.count - IFNULL(tb2.count, 0)) &lt; 0, 0,
                               (tb1.count - IFNULL(tb2.count, 0)))) AS count,
                        tb1.transport_type                          AS transport_type,
                        price
                 FROM (
                          SELECT bailun_sku,
                                 warehouse_code,
                                 parent_id,
                                 purchase_id,
                                 estimated_arrival_time,
                                 has_transfer,
                                 sum(count) AS count,
                                 price,
                                 transport_type
                          FROM dc_base_purchase
                          WHERE buy_status IN (0, 1, 2, 3, 9)
                            AND has_delete = 0
                          GROUP BY bailun_sku,
                                   parent_id
                      ) tb1
                          LEFT JOIN (
                     SELECT bailun_sku,
                            warehouse_code,
                            parent_id,
                            sum(count) AS count
                     FROM dc_base_purchase_inbound
                     WHERE 1 = 1
                     GROUP BY bailun_sku,
                              parent_id
                 ) tb2 ON tb1.bailun_sku = tb2.bailun_sku
                     AND tb1.parent_id = tb2.parent_id
                 GROUP BY tb1.bailun_sku,
                          tb1.warehouse_code,
                          tb1.purchase_id
             ) t
        GROUP BY bailun_sku,
                 warehouse_code
        HAVING count > 0
    </select>


    <update id="updateOldOutStockToZero">
        update dc_mid_transit
        set quantity_out_stock            =0,
            quantity_out_stock_aliexpress = 0
        where gmt_out_stock_modified &lt; #{outStockModified,jdbcType=TIMESTAMP}
    </update>
    <update id="updateOldTransferToZero">
        update dc_mid_transit
        set quantity_transfer         =0,
            quantity_transfer_plan    =0,
            quantity_land_transfer    = 0,
            quantity_ocean_transfer   = 0,
            quantity_air_transfer     = 0,
            quantity_railway_transfer = 0
        where gmt_transfer_modified &lt; #{transferModified,jdbcType=TIMESTAMP}
    </update>
    <update id="updateOldPurchaseToZero">
        update dc_mid_transit
        set quantity_purchase         =0,
            amount_purchase_transit=0,
            quantity_land_purchase    = 0,
            quantity_ocean_purchase   = 0,
            quantity_air_purchase     = 0,
            quantity_railway_purchase = 0
        where gmt_purchase_modified &lt; #{purchaseModified,jdbcType=TIMESTAMP}
    </update>
    <update id="updateOldUnshippedToZero">
        update dc_mid_transit
        set quantity_unshipped =0
        where gmt_unshipped_modified &lt; #{unshippedModified,jdbcType=TIMESTAMP}
    </update>
    <select id="selectMaxOutStockModified" resultType="java.time.LocalDateTime">
        select max(gmt_out_stock_modified)
        from dc_mid_transit
    </select>
    <select id="selectMaxTransferModified" resultType="java.time.LocalDateTime">
        select max(gmt_transfer_modified)
        from dc_mid_transit
    </select>
    <select id="selectMaxPurchaseModified" resultType="java.time.LocalDateTime">
        select max(gmt_purchase_modified)
        from dc_mid_transit
    </select>
    <select id="selectMaxUnshippedModified" resultType="java.time.LocalDateTime">
        select max(gmt_unshipped_modified)
        from dc_mid_transit
    </select>
    <select id="selectUnShipped"></select>

    <insert id="calculateUnShipped">
        insert into dc_mid_transit(bailun_sku, warehouse_code, quantity_unshipped, gmt_unshipped_modified,
                                   bailun_order_ids)
        SELECT t1.bailun_sku,
               t1.warehouse_code,
               t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_shipped,
               CURRENT_TIMESTAMP,
               t1.bailun_order_ids
        FROM (
                 SELECT bailun_sku,
                        warehouse_code,
                        SUM(bailun_sku_quantity_ordered)                                                     AS bailun_sku_quantity_ordered,
                        SUM(bailun_sku_quantity_shipped)                                                     AS bailun_sku_quantity_shipped,
                        GROUP_CONCAT(DISTINCT
                                     (case when warehouse_code = 'BLGZ03' then bailun_order_id else '' end)) as 'bailun_order_ids'
                 FROM dc_base_oms_sku_30
                 WHERE bailun_order_status = 'Handling'
                   and bailun_interception_status in ('None', 'Failed')
                   and warehouse_code != ''
                   and platform_type != 'FBA'
                   and has_delete = 0
                   and has_scalp = 0
                   and has_buyer_remark = 0
                   and has_platsku_remark = 0
                   and has_fba_s = 0
                   and has_innersale = 0
                   and paid_time >= '2019-03-01 12:00:00'
                   and bailun_sku_quantity_ordered > bailun_sku_quantity_shipped
                 GROUP BY bailun_sku,
                          warehouse_code
             ) t1
        WHERE (t1.bailun_sku_quantity_ordered - t1.bailun_sku_quantity_shipped) >= 0
        ON DUPLICATE KEY UPDATE quantity_unshipped     = VALUES(quantity_unshipped),
                                gmt_unshipped_modified = VALUES(gmt_unshipped_modified),
                                bailun_order_ids       = VALUES(bailun_order_ids)
    </insert>
</mapper>
