<?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.fuxi.ws.data.dao.WStoreMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WStore">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    <id column="GoodsID" jdbcType="VARCHAR" property="goodsid" />
    <id column="ColorID" jdbcType="VARCHAR" property="colorid" />
    <id column="SizeID" jdbcType="VARCHAR" property="sizeid" />
    <result column="DepartmentID" jdbcType="VARCHAR" property="departmentid" />
    <result column="Quantity" jdbcType="INTEGER" property="quantity" />
    <result column="TotalQty" jdbcType="INTEGER" property="totalqty" />
    <result column="TotalSell" jdbcType="INTEGER" property="totalsell" />
    <result column="Price" jdbcType="DECIMAL" property="price" />
    <result column="ListIndex" jdbcType="SMALLINT" property="listindex" />
    <result column="SKU_ID" jdbcType="INTEGER" property="skuId" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    <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="Base_Column_List">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    GoodsID, ColorID, SizeID, DepartmentID, Quantity, TotalQty, TotalSell, Price, ListIndex, 
    SKU_ID
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WStoreExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_Store
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WStoreKey" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_Store
    where GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WStoreKey">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    delete from W_Store
    where GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WStore">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    insert into W_Store (GoodsID, ColorID, SizeID, 
      DepartmentID, Quantity, TotalQty, 
      TotalSell, Price, ListIndex<!-- , 
      SKU_ID -->)
    values (#{goodsid,jdbcType=VARCHAR}, #{colorid,jdbcType=VARCHAR}, #{sizeid,jdbcType=VARCHAR}, 
      #{departmentid,jdbcType=VARCHAR}, #{quantity,jdbcType=INTEGER}, #{totalqty,jdbcType=INTEGER}, 
      #{totalsell,jdbcType=INTEGER}, #{price,jdbcType=DECIMAL}, #{listindex,jdbcType=SMALLINT}<!-- , 
      #{skuId,jdbcType=INTEGER} -->)
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WStore">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    insert into W_Store
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="goodsid != null">
        GoodsID,
      </if>
      <if test="colorid != null">
        ColorID,
      </if>
      <if test="sizeid != null">
        SizeID,
      </if>
      <if test="departmentid != null">
        DepartmentID,
      </if>
      <if test="quantity != null">
        Quantity,
      </if>
      <if test="totalqty != null">
        TotalQty,
      </if>
      <if test="totalsell != null">
        TotalSell,
      </if>
      <if test="price != null">
        Price,
      </if>
      <if test="listindex != null">
        ListIndex,
      </if>
      <!-- <if test="skuId != null">
        SKU_ID,
      </if> -->
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="goodsid != null">
        #{goodsid,jdbcType=VARCHAR},
      </if>
      <if test="colorid != null">
        #{colorid,jdbcType=VARCHAR},
      </if>
      <if test="sizeid != null">
        #{sizeid,jdbcType=VARCHAR},
      </if>
      <if test="departmentid != null">
        #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="quantity != null">
        #{quantity,jdbcType=INTEGER},
      </if>
      <if test="totalqty != null">
        #{totalqty,jdbcType=INTEGER},
      </if>
      <if test="totalsell != null">
        #{totalsell,jdbcType=INTEGER},
      </if>
      <if test="price != null">
        #{price,jdbcType=DECIMAL},
      </if>
      <if test="listindex != null">
        #{listindex,jdbcType=SMALLINT},
      </if>
      <!-- <if test="skuId != null">
        #{skuId,jdbcType=INTEGER},
      </if> -->
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WStoreExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    select count(*) from W_Store
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WStore">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    update W_Store
    <set>
      <if test="departmentid != null">
        DepartmentID = #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="quantity != null">
        Quantity = #{quantity,jdbcType=INTEGER},
      </if>
      <if test="totalqty != null">
        TotalQty = #{totalqty,jdbcType=INTEGER},
      </if>
      <if test="totalsell != null">
        TotalSell = #{totalsell,jdbcType=INTEGER},
      </if>
      <if test="price != null">
        Price = #{price,jdbcType=DECIMAL},
      </if>
      <if test="listindex != null">
        ListIndex = #{listindex,jdbcType=SMALLINT},
      </if>
      <!-- <if test="skuId != null">
        SKU_ID = #{skuId,jdbcType=INTEGER},
      </if> -->
    </set>
    where GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WStore">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Apr 25 12:25:27 CST 2017.
    -->
    update W_Store
    set DepartmentID = #{departmentid,jdbcType=VARCHAR},
      Quantity = #{quantity,jdbcType=INTEGER},
      TotalQty = #{totalqty,jdbcType=INTEGER},
      TotalSell = #{totalsell,jdbcType=INTEGER},
      Price = #{price,jdbcType=DECIMAL},
      ListIndex = #{listindex,jdbcType=SMALLINT}
      <!-- ,
      SKU_ID = #{skuId,jdbcType=INTEGER} -->
    where GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
  </update>

	<!-- 商品具体颜色尺码的库存 -->
	<select id="inventory" resultType="java.util.LinkedHashMap">
		select
		a.DepartmentID,a.GoodsID,a.ColorID,a.SizeID,a.Quantity,b.No,
		a.TotalQty,a.TotalSell,isnull(a.Price,(select top 1 Price from W_Goods
		t where t.GoodsID=a.GoodsID)) Price,b.Color,c.Size,d.BarCode,c.No as SizeNo
		from W_Store a with(nolock)
		join
		Color b with(nolock) on a.ColorID=b.ColorID
		join Size c with(nolock) on
		a.SizeID=c.SizeID
		left join barcode d with(nolock) on a.GoodsID=d.GoodsID and a.ColorID=d.ColorID and a.SizeID=d.SizeID
		where
		a.goodsid=#{ goodsid } order by a.ListIndex,b.Color,c.Size
	</select>
	
	<select id="selectstoredtl" resultType="java.util.LinkedHashMap">
		select a.GoodsID,a.ColorID,b.No ColorNo,b.Color,a.SizeID,c.No SizeNo,c.Size,
		isnull(a.Price,(select top 1 Price from W_Goods
		t where t.GoodsID=a.GoodsID)) Price
		from W_Store a with(nolock) inner join
		Color b with(nolock) on a.ColorID=b.ColorID
		join Size c with(nolock) on
		a.SizeID=c.SizeID
		where
		a.goodsid=#{ goodsid } order by a.ListIndex,b.Color,c.Size
	</select>

	<!-- 商品具体颜色尺码的库存——含Sku码 -->
	<select id="selectSkuStore" resultType="java.util.LinkedHashMap">
			select
		a.DepartmentID,a.GoodsID,a.ColorID,a.SizeID,a.Quantity,b.No,
		a.TotalQty,a.TotalSell,isnull(a.Price,(select top 1 Price from W_Goods
		t with(nolock) where t.GoodsID=a.GoodsID)) Price,b.Color,c.Size,c.No as SizeNo,
		isnull((select top 1
		BarCode from BarCode r with(nolock) where r.GoodsID=a.GoodsID and
		r.ColorID=a.ColorID and r.SizeID=a.SizeID),'') BarCode
		from W_Store a with(nolock)
		join
		Color b with(nolock) on a.ColorID=b.ColorID
		join Size c with(nolock) on
		a.SizeID=c.SizeID
		where a.goodsid=#{ goodsid }
		order by a.ListIndex,b.Color,c.Size
	</select>
	
	<delete id="deleteByGoodsID" parameterType="java.lang.String">    
    delete from W_Store
    where GoodsID = #{goodsid,jdbcType=VARCHAR}
  </delete>
</mapper>