<?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.WPromotionsstoreMapper" >
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WPromotionsstore" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 04 17:05:01 CST 2015.
    -->
    <id column="PromotionsID" property="promotionsid" jdbcType="INTEGER" />
    <id column="GoodsID" property="goodsid" jdbcType="VARCHAR" />
    <id column="ColorID" property="colorid" jdbcType="VARCHAR" />
    <id column="SizeID" property="sizeid" jdbcType="VARCHAR" />
    <result column="PromotPrice" property="promotprice" jdbcType="DECIMAL" />
    <result column="PromotQty" property="promotqty" jdbcType="INTEGER" />
  </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 Aug 04 17:05:01 CST 2015.
    -->
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <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 collection="criterion.value" item="listItem" open="(" close=")" 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 Aug 04 17:05:01 CST 2015.
    -->
    PromotionsID, GoodsID, ColorID, SizeID, PromotPrice, PromotQty
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.fuxi.ws.data.entity.WPromotionsstoreExample" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 04 17:05:01 CST 2015.
    -->
    select
    <if test="distinct" >
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_PromotionsStore with(nolock)
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="com.fuxi.ws.data.entity.WPromotionsstoreKey" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 04 17:05:01 CST 2015.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_PromotionsStore with(nolock)
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WPromotionsstoreKey" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 04 17:05:01 CST 2015.
    -->
    delete from W_PromotionsStore
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WPromotionsstore" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 04 17:05:01 CST 2015.
    -->
    insert into W_PromotionsStore (PromotionsID, GoodsID, ColorID, 
      SizeID, PromotPrice, PromotQty
      )
    values (#{promotionsid,jdbcType=INTEGER}, #{goodsid,jdbcType=VARCHAR}, #{colorid,jdbcType=VARCHAR}, 
      #{sizeid,jdbcType=VARCHAR}, #{promotprice,jdbcType=DECIMAL}, #{promotqty,jdbcType=INTEGER}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WPromotionsstore" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 04 17:05:01 CST 2015.
    -->
    insert into W_PromotionsStore
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="promotionsid != null" >
        PromotionsID,
      </if>
      <if test="goodsid != null" >
        GoodsID,
      </if>
      <if test="colorid != null" >
        ColorID,
      </if>
      <if test="sizeid != null" >
        SizeID,
      </if>
      <if test="promotprice != null" >
        PromotPrice,
      </if>
      <if test="promotqty != null" >
        PromotQty,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="promotionsid != null" >
        #{promotionsid,jdbcType=INTEGER},
      </if>
      <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="promotprice != null" >
        #{promotprice,jdbcType=DECIMAL},
      </if>
      <if test="promotqty != null" >
        #{promotqty,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WPromotionsstoreExample" resultType="java.lang.Integer" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 04 17:05:01 CST 2015.
    -->
    select count(*) from W_PromotionsStore with(nolock)
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WPromotionsstore" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 04 17:05:01 CST 2015.
    -->
    update W_PromotionsStore
    <set >
      <if test="promotprice != null" >
        PromotPrice = #{promotprice,jdbcType=DECIMAL},
      </if>
      <if test="promotqty != null" >
        PromotQty = #{promotqty,jdbcType=INTEGER},
      </if>
    </set>
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WPromotionsstore" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 04 17:05:01 CST 2015.
    -->
    update W_PromotionsStore
    set PromotPrice = #{promotprice,jdbcType=DECIMAL},
      PromotQty = #{promotqty,jdbcType=INTEGER}
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
      and ColorID = #{colorid,jdbcType=VARCHAR}
      and SizeID = #{sizeid,jdbcType=VARCHAR}
  </update>
  
  <!-- 秒杀商品具体颜色尺码的库存 -->
	<select id="seckillstore" resultType="java.util.LinkedHashMap">
		select a.*,b.Color,c.Size,d.Price,e.Quantity,e.TotalQty,e.TotalSell 
		from W_PromotionsStore as a with(nolock)
		inner join Color b with(nolock) on a.ColorID=b.ColorID
		inner join Size c with(nolock) on a.SizeID=c.SizeID 
		inner join W_Goods as d with(nolock) on a.GoodsID=d.GoodsID
		inner join W_Store as e with(nolock) on a.GoodsID=e.GoodsID and a.ColorID=e.ColorID and a.SizeID=e.SizeID 
		where a.PromotionsID=#{promotionsid,jdbcType=INTEGER} and 
		a.GoodsID=#{ goodsid,jdbcType=VARCHAR }
	</select>
	
	<select id="inventory" resultType="java.util.LinkedHashMap">
		select
		a.GoodsID,a.ColorID,a.SizeID,a.PromotQty,a.PromotPrice,
		b.Color,c.Size,s.TotalQty,s.TotalSell,ISNULL(e.Quantity,0) as Quantity 
		from W_PromotionsStore a with(nolock)
		join Color b with(nolock) on a.ColorID=b.ColorID
		join Size c with(nolock) on a.SizeID=c.SizeID
		join W_Store s with(nolock) on a.GoodsID=s.GoodsID and a.ColorID=s.ColorID and a.SizeID=s.SizeID 
		left join (select a.GoodsID,sum(a.Quantity)-sum(a.ReturnQty) as Quantity
		from EShopOrderDetail as a with(nolock)
		inner join EShopOrder as b with(nolock) on a.EShopOrderID=b.EShopOrderID
		where b.OrderKind=2 and b.order_flag not in (0,1) and b.Vipid=#{vipid,jdbcType=VARCHAR} 
		group by a.GoodsID) as e on a.GoodsID=e.GoodsID 
		where a.PromotionsID=#{promotionsid,jdbcType=INTEGER} and 
		a.goodsid=#{ goodsid,jdbcType=VARCHAR }
	</select>
	
	<!-- 秒杀商品库存 -->
	<select id="checkstorebygoodsid" resultType="java.util.LinkedHashMap">
		select GoodsID,SUM(isnull(PromotQty,0)) as QtySum 
		from W_PromotionsStore with(nolock) 
		where a.PromotionsID=#{promotionsid,jdbcType=INTEGER} and 
		a.goodsid=#{ goodsid,jdbcType=VARCHAR }
	</select>
</mapper>