<?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.DcBaseStockFbaMapper">
  <resultMap id="BaseResultMap" type="com.bailuntec.domain.entity.DcBaseStockFba">
    <!--
      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="platform_sku" jdbcType="VARCHAR" property="platformSku" />
    <result column="warehouse_code" jdbcType="VARCHAR" property="warehouseCode" />
    <result column="usable_stock" jdbcType="INTEGER" property="usableStock" />
    <result column="in_warehouse" jdbcType="INTEGER" property="inWarehouse" />
    <result column="asin" jdbcType="VARCHAR" property="asin" />
  </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, platform_sku, warehouse_code, usable_stock, 
    in_warehouse, asin
  </sql>
  <select id="selectByExample" parameterType="com.bailuntec.domain.example.DcBaseStockFbaExample" 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_fba
    <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_fba
    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_fba
    where id = #{id,jdbcType=INTEGER}
  </delete>
  <delete id="deleteByExample" parameterType="com.bailuntec.domain.example.DcBaseStockFbaExample">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from dc_base_stock_fba
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.bailuntec.domain.entity.DcBaseStockFba">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into dc_base_stock_fba (id, gmt_create, gmt_modified, 
      bailun_sku, platform_sku, warehouse_code, 
      usable_stock, in_warehouse, asin
      )
    values (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, 
      #{bailunSku,jdbcType=VARCHAR}, #{platformSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, 
      #{usableStock,jdbcType=INTEGER}, #{inWarehouse,jdbcType=INTEGER}, #{asin,jdbcType=VARCHAR}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.bailuntec.domain.entity.DcBaseStockFba">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into dc_base_stock_fba
    <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="platformSku != null">
        platform_sku,
      </if>
      <if test="warehouseCode != null">
        warehouse_code,
      </if>
      <if test="usableStock != null">
        usable_stock,
      </if>
      <if test="inWarehouse != null">
        in_warehouse,
      </if>
      <if test="asin != null">
        asin,
      </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="platformSku != null">
        #{platformSku,jdbcType=VARCHAR},
      </if>
      <if test="warehouseCode != null">
        #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="usableStock != null">
        #{usableStock,jdbcType=INTEGER},
      </if>
      <if test="inWarehouse != null">
        #{inWarehouse,jdbcType=INTEGER},
      </if>
      <if test="asin != null">
        #{asin,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.bailuntec.domain.example.DcBaseStockFbaExample" resultType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select count(*) from dc_base_stock_fba
    <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_fba
    <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.platformSku != null">
        platform_sku = #{record.platformSku,jdbcType=VARCHAR},
      </if>
      <if test="record.warehouseCode != null">
        warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="record.usableStock != null">
        usable_stock = #{record.usableStock,jdbcType=INTEGER},
      </if>
      <if test="record.inWarehouse != null">
        in_warehouse = #{record.inWarehouse,jdbcType=INTEGER},
      </if>
      <if test="record.asin != null">
        asin = #{record.asin,jdbcType=VARCHAR},
      </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_fba
    set id = #{record.id,jdbcType=INTEGER},
      gmt_create = #{record.gmtCreate,jdbcType=TIMESTAMP},
      gmt_modified = #{record.gmtModified,jdbcType=TIMESTAMP},
      bailun_sku = #{record.bailunSku,jdbcType=VARCHAR},
      platform_sku = #{record.platformSku,jdbcType=VARCHAR},
      warehouse_code = #{record.warehouseCode,jdbcType=VARCHAR},
      usable_stock = #{record.usableStock,jdbcType=INTEGER},
      in_warehouse = #{record.inWarehouse,jdbcType=INTEGER},
      asin = #{record.asin,jdbcType=VARCHAR}
    <if test="_parameter != null">
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.bailuntec.domain.entity.DcBaseStockFba">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_base_stock_fba
    <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="platformSku != null">
        platform_sku = #{platformSku,jdbcType=VARCHAR},
      </if>
      <if test="warehouseCode != null">
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="usableStock != null">
        usable_stock = #{usableStock,jdbcType=INTEGER},
      </if>
      <if test="inWarehouse != null">
        in_warehouse = #{inWarehouse,jdbcType=INTEGER},
      </if>
      <if test="asin != null">
        asin = #{asin,jdbcType=VARCHAR},
      </if>
    </set>
    where id = #{id,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.bailuntec.domain.entity.DcBaseStockFba">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update dc_base_stock_fba
    set gmt_create = #{gmtCreate,jdbcType=TIMESTAMP},
      gmt_modified = #{gmtModified,jdbcType=TIMESTAMP},
      bailun_sku = #{bailunSku,jdbcType=VARCHAR},
      platform_sku = #{platformSku,jdbcType=VARCHAR},
      warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      usable_stock = #{usableStock,jdbcType=INTEGER},
      in_warehouse = #{inWarehouse,jdbcType=INTEGER},
      asin = #{asin,jdbcType=VARCHAR}
    where id = #{id,jdbcType=INTEGER}
  </update>
  <insert id="upsertSelective" parameterType="com.bailuntec.domain.entity.DcBaseStockFba">
    <!--
      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_fba
    <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="platformSku != null">
        platform_sku,
      </if>
      <if test="warehouseCode != null">
        warehouse_code,
      </if>
      <if test="usableStock != null">
        usable_stock,
      </if>
      <if test="inWarehouse != null">
        in_warehouse,
      </if>
      <if test="asin != null">
        asin,
      </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="platformSku != null">
        #{platformSku,jdbcType=VARCHAR},
      </if>
      <if test="warehouseCode != null">
        #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="usableStock != null">
        #{usableStock,jdbcType=INTEGER},
      </if>
      <if test="inWarehouse != null">
        #{inWarehouse,jdbcType=INTEGER},
      </if>
      <if test="asin != null">
        #{asin,jdbcType=VARCHAR},
      </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="platformSku != null">
        platform_sku = #{platformSku,jdbcType=VARCHAR},
      </if>
      <if test="warehouseCode != null">
        warehouse_code = #{warehouseCode,jdbcType=VARCHAR},
      </if>
      <if test="usableStock != null">
        usable_stock = #{usableStock,jdbcType=INTEGER},
      </if>
      <if test="inWarehouse != null">
        in_warehouse = #{inWarehouse,jdbcType=INTEGER},
      </if>
      <if test="asin != null">
        asin = #{asin,jdbcType=VARCHAR},
      </if>
    </trim>
  </insert>
  <insert id="upsert" parameterType="com.bailuntec.domain.entity.DcBaseStockFba">
    <!--
      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_fba
    (id, gmt_create, gmt_modified, bailun_sku, platform_sku, warehouse_code, usable_stock, 
      in_warehouse, asin)
    values
    (#{id,jdbcType=INTEGER}, #{gmtCreate,jdbcType=TIMESTAMP}, #{gmtModified,jdbcType=TIMESTAMP}, 
      #{bailunSku,jdbcType=VARCHAR}, #{platformSku,jdbcType=VARCHAR}, #{warehouseCode,jdbcType=VARCHAR}, 
      #{usableStock,jdbcType=INTEGER}, #{inWarehouse,jdbcType=INTEGER}, #{asin,jdbcType=VARCHAR}
      )
    on duplicate key update 
    id = #{id,jdbcType=INTEGER}, 
    gmt_create = #{gmtCreate,jdbcType=TIMESTAMP}, 
    gmt_modified = #{gmtModified,jdbcType=TIMESTAMP}, 
    bailun_sku = #{bailunSku,jdbcType=VARCHAR}, 
    platform_sku = #{platformSku,jdbcType=VARCHAR}, 
    warehouse_code = #{warehouseCode,jdbcType=VARCHAR}, 
    usable_stock = #{usableStock,jdbcType=INTEGER}, 
    in_warehouse = #{inWarehouse,jdbcType=INTEGER}, 
    asin = #{asin,jdbcType=VARCHAR}
  </insert>
  <select id="selectOneByExample" parameterType="com.bailuntec.domain.example.DcBaseStockFbaExample" 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_fba
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
    limit 1
  </select>


  <select id="listEuropeFbaStockSharePlatformSku" resultType="string">
        SELECT platform_sku FROM (SELECT tb1.platform_sku FROM dc_base_stock_fba tb1 left JOIN (SELECT warehouse_code,bailun_account FROM dc_base_warehouse WHERE system_flag='FBA' and  area_id in ('6','8','10','11','12')) tb2 on tb1.warehouse_code=tb2.warehouse_code and tb1.bailun_sku !=''  WHERE tb2.warehouse_code is not null ) tb GROUP BY platform_sku HAVING count(*) > 1
  </select>

  <select id="listEuropeFbaStockShare" resultType="com.bailuntec.domain.entity.DcBaseStockFba">
        SELECT * FROM (SELECT tb1.*,tb2.bailun_account FROM dc_base_stock_fba tb1 left JOIN (SELECT warehouse_code,bailun_account FROM dc_base_warehouse WHERE system_flag='FBA' and area_id  in ('6','8','10','11','12')) tb2 on tb1.warehouse_code=tb2.warehouse_code and tb1.bailun_sku !=''  WHERE tb2.warehouse_code is not null and platform_sku=#{fbaStockSharePlatformSku}) tb
  </select>

  <select id="listOtherFbaStock" resultType="com.bailuntec.domain.entity.DcBaseStockFba">
        SELECT * FROM (SELECT tb1.*,tb2.bailun_account FROM dc_base_stock_fba tb1 left JOIN (SELECT warehouse_code,bailun_account FROM dc_base_warehouse WHERE system_flag='FBA' and area_id in ('6','8','10','11','12')) tb2 on tb1.warehouse_code=tb2.warehouse_code and tb1.bailun_sku !=''  WHERE tb2.warehouse_code is not null ) tb GROUP BY platform_sku HAVING count(*) =1
      union
      SELECT * FROM (SELECT tb1.*,tb2.bailun_account FROM dc_base_stock_fba tb1 left JOIN (SELECT warehouse_code,bailun_account FROM dc_base_warehouse WHERE system_flag='FBA' and area_id not in ('6','8','10','11','12')) tb2 on tb1.warehouse_code=tb2.warehouse_code and tb1.bailun_sku !=''  WHERE tb2.warehouse_code is not null ) tb
  </select>

  <insert id="insertDcBaseStockFbaShare">
        replace into dc_base_stock_fba_share(`bailun_sku`, `platform_sku`)
                SELECT bailun_sku,platform_sku FROM (SELECT tb1.bailun_sku,tb1.platform_sku FROM dc_base_stock_fba tb1 left JOIN (SELECT warehouse_code,bailun_account FROM dc_base_warehouse WHERE system_flag='FBA' and  area_id in ('6','8','10','11','12')) tb2 on tb1.warehouse_code=tb2.warehouse_code and tb1.bailun_sku !=''  WHERE tb2.warehouse_code is not null ) tb GROUP BY platform_sku HAVING count(*) > 1
  </insert>
</mapper>