<?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.DcBaseStockRecordMapper">
  <resultMap id="BaseResultMap" type="com.bailuntec.domain.entity.DcBaseStockRecord">
    <!--
      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="warehouse_name" jdbcType="VARCHAR" property="warehouseName" />
    <result column="quantity_stock" jdbcType="INTEGER" property="quantityStock" />
    <result column="stock_time" jdbcType="TIMESTAMP" property="stockTime" />
    <result column="has_transfer" jdbcType="INTEGER" property="hasTransfer" />
  </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, warehouse_name, quantity_stock, 
    stock_time, has_transfer
  </sql>
  <select id="selectByExample" parameterType="com.bailuntec.domain.example.DcBaseStockRecordExample" 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_stock_record
    <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_stock_record
    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_stock_record
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.bailuntec.domain.example.DcBaseStockRecordExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from dc_base_stock_record
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.bailuntec.domain.entity.DcBaseStockRecord">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into dc_base_stock_record (id, gmt_create, gmt_modified, 
      bailun_sku, warehouse_code, warehouse_name, 
      quantity_stock, stock_time, has_transfer
      )
    values (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, 
      #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, #{warehouseName,jdbcType=VARCHAR}, 
      #{quantityStock,jdbcType=INTEGER}, #{stockTime,jdbcType=TIMESTAMP}, #{hasTransfer,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcBaseStockRecord">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into dc_base_stock_record
    <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="warehouseName != null">
        warehouse_name,
      </if>
      <if test="quantityStock != null">
        quantity_stock,
      </if>
      <if test="stockTime != null">
        stock_time,
      </if>
      <if test="hasTransfer != null">
        has_transfer,
      </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="warehouseName != null">
        #{warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="quantityStock != null">
        #{quantityStock,jdbcType=INTEGER},
      </if>
      <if test="stockTime != null">
        #{stockTime,jdbcType=TIMESTAMP},
      </if>
      <if test="hasTransfer != null">
        #{hasTransfer,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.bailuntec.domain.example.DcBaseStockRecordExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from dc_base_stock_record
    <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_stock_record
    <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.warehouseName != null">
        warehouse_name = #{record.warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="record.quantityStock != null">
        quantity_stock = #{record.quantityStock,jdbcType=INTEGER},
      </if>
      <if test="record.stockTime != null">
        stock_time = #{record.stockTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.hasTransfer != null">
        has_transfer = #{record.hasTransfer,jdbcType=INTEGER},
      </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_stock_record
    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},
      warehouse_name = #{record.warehouseName,jdbcType=VARCHAR},
      quantity_stock = #{record.quantityStock,jdbcType=INTEGER},
      stock_time = #{record.stockTime,jdbcType=TIMESTAMP},
      has_transfer = #{record.hasTransfer,jdbcType=INTEGER}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.DcBaseStockRecord">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_base_stock_record
    <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="warehouseName != null">
        warehouse_name = #{warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="quantityStock != null">
        quantity_stock = #{quantityStock,jdbcType=INTEGER},
      </if>
      <if test="stockTime != null">
        stock_time = #{stockTime,jdbcType=TIMESTAMP},
      </if>
      <if test="hasTransfer != null">
        has_transfer = #{hasTransfer,jdbcType=INTEGER},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.bailuntec.domain.entity.DcBaseStockRecord">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_base_stock_record
    set gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
      gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
      bailun_sku = #{bailunSku,jdbcType=VARCHAR},
      warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      warehouse_name = #{warehouseName,jdbcType=VARCHAR},
      quantity_stock = #{quantityStock,jdbcType=INTEGER},
      stock_time = #{stockTime,jdbcType=TIMESTAMP},
      has_transfer = #{hasTransfer,jdbcType=INTEGER}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcBaseStockRecord">
    <!--
      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_stock_record
    <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="warehouseName != null">
        warehouse_name,
      </if>
      <if test="quantityStock != null">
        quantity_stock,
      </if>
      <if test="stockTime != null">
        stock_time,
      </if>
      <if test="hasTransfer != null">
        has_transfer,
      </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="warehouseName != null">
        #{warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="quantityStock != null">
        #{quantityStock,jdbcType=INTEGER},
      </if>
      <if test="stockTime != null">
        #{stockTime,jdbcType=TIMESTAMP},
      </if>
      <if test="hasTransfer != null">
        #{hasTransfer,jdbcType=INTEGER},
      </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="warehouseName != null">
        warehouse_name = #{warehouseName,jdbcType=VARCHAR},
      </if>
      <if test="quantityStock != null">
        quantity_stock = #{quantityStock,jdbcType=INTEGER},
      </if>
      <if test="stockTime != null">
        stock_time = #{stockTime,jdbcType=TIMESTAMP},
      </if>
      <if test="hasTransfer != null">
        has_transfer = #{hasTransfer,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <insert id="upsert" parameterType="com.bailuntec.domain.entity.DcBaseStockRecord">
    <!--
      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_stock_record
    (id, gmt_create, gmt_modified, bailun_sku, warehouse_code, warehouse_name, quantity_stock, 
      stock_time, has_transfer)
    values
    (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, 
      #{bailunSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, #{warehouseName,jdbcType=VARCHAR}, 
      #{quantityStock,jdbcType=INTEGER}, #{stockTime,jdbcType=TIMESTAMP}, #{hasTransfer,jdbcType=INTEGER}
      )
    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}, 
    warehouse_name = #{warehouseName,jdbcType=VARCHAR}, 
    quantity_stock = #{quantityStock,jdbcType=INTEGER}, 
    stock_time = #{stockTime,jdbcType=TIMESTAMP}, 
    has_transfer = #{hasTransfer,jdbcType=INTEGER}
  </insert>
  <select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcBaseStockRecordExample" 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_stock_record
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    limit 1
  </select>

  <select id="selectPageByGroup" resultType="com.bailuntec.domain.entity.DcBaseStockRecord">
    select
    <include refid="Base_Column_List" />
    from dc_base_stock_record
    group by bailun_sku, warehouse_code
    order by id asc
    limit #{pageIndex}, #{pageSize}
  </select>

  <select id="selectCountByGroup" resultType="java.lang.Integer">
    select count(id)  from (select id from dc_base_stock_record group by bailun_sku, warehouse_code order by id asc) a
  </select>

    <select id="selectByStockTime" resultType="com.bailuntec.domain.entity.DcBaseStockRecord">
        select
        id, gmt_create, gmt_modified, bailun_sku, warehouse_code, warehouse_name, sum(quantity_stock) as quantity_stock,
    stock_time, has_transfer
        from dc_base_stock_record
        where bailun_sku = #{bailunSku}
        and warehouse_code = #{warehouseCode}
        order by stock_time asc
    </select>


    <select id="selectOrderPickByLimit" resultType="com.bailuntec.domain.entity.DcBaseOmsPick">
    select
    warehouse_code, warehouse_name, shipping_time, bailun_sku, quantity_shipped
    from dc_base_oms_pick
    where
    shipping_status = 'TotalShipping' and has_delete = false and company_id = 1
    and quantity_shipped > 0
    and shipping_time &gt;= #{startTime} and shipping_time &lt;= #{endTime}
    limit #{pageIndex}, #{pageSize}
  </select>


  <select id="selectOrderPickCount" parameterType="com.bailuntec.domain.entity.JobPointLog" resultType="java.lang.Integer">
    select
    count(shipping_time)
    from dc_base_oms_pick
    where
    shipping_status = 'TotalShipping' and has_delete = false and company_id = 1
    and shipping_time &gt;= #{startTime} and shipping_time &lt;= #{endTime}
  </select>


  <select id="selectPurchaseInboundCount" resultType="java.lang.Integer">
    select count(id)
    from dc_base_purchase_inbound
    where update_time &gt;= #{startTime} and update_time &lt;= #{endTime} and status = 1
  </select>

  <select id="selectTransferCount" resultType="java.lang.Integer">
    select count(id)
    from dc_base_transfer_complete
    where create_time &gt;= #{startTime} and create_time &lt;= #{endTime} and deleted = 0
  </select>

  <select id="selectPurchaseInboundByLimit" resultType="com.bailuntec.domain.entity.DcBasePurchaseInbound">
    select * from dc_base_purchase_inbound where status = 1 and count > 0 and update_time &gt;= #{startTime} and update_time &lt;= #{endTime} limit #{pageIndex}, #{pageSize}
  </select>

  <select id="selectTransferCompleteByLimit" resultType="com.bailuntec.domain.entity.DcBaseTransferComplete">
    select * from dc_base_transfer_complete where deleted = 0 and count > 0 and create_time &gt;= #{startTime} and create_time &lt;= #{endTime} limit #{pageIndex}, #{pageSize}
  </select>

  <!--<select id="selectByPage" parameterType="com.bailuntec.domain.entity.JobPointLog" resultType="com.bailuntec.domain.entity.DcBaseStockRecord">
    select
    <include refid="Base_Column_List" />
    from dc_base_stock_record
    order by stock_time asc, bailun_sku, warehouse_code
    limit #{pageIndex}, #{pageSize}
  </select>-->
</mapper>