<?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.WPromotionsdtlMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WPromotionsdtl">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    <id column="PromotionsID" jdbcType="INTEGER" property="promotionsid" />
    <id column="GoodsID" jdbcType="VARCHAR" property="goodsid" />
    <result column="PromotPrice" jdbcType="DECIMAL" property="promotprice" />
    <result column="ShowIndex" jdbcType="INTEGER" property="showindex" />
    <result column="NumOfPerson" jdbcType="SMALLINT" property="numofperson" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    <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 Mon Jan 04 15:22:44 CST 2016.
    -->
    PromotionsID, GoodsID, PromotPrice, ShowIndex, NumOfPerson
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WPromotionsdtlExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_PromotionsDtl
    <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.WPromotionsdtlKey" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_PromotionsDtl
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WPromotionsdtlKey">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    delete from W_PromotionsDtl
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WPromotionsdtl">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    insert into W_PromotionsDtl (PromotionsID, GoodsID, PromotPrice, 
      ShowIndex, NumOfPerson)
    values (#{promotionsid,jdbcType=INTEGER}, #{goodsid,jdbcType=VARCHAR}, #{promotprice,jdbcType=DECIMAL}, 
      #{showindex,jdbcType=INTEGER}, #{numofperson,jdbcType=SMALLINT})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WPromotionsdtl">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    insert into W_PromotionsDtl
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="promotionsid != null">
        PromotionsID,
      </if>
      <if test="goodsid != null">
        GoodsID,
      </if>
      <if test="promotprice != null">
        PromotPrice,
      </if>
      <if test="showindex != null">
        ShowIndex,
      </if>
      <if test="numofperson != null">
        NumOfPerson,
      </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="promotprice != null">
        #{promotprice,jdbcType=DECIMAL},
      </if>
      <if test="showindex != null">
        #{showindex,jdbcType=INTEGER},
      </if>
      <if test="numofperson != null">
        #{numofperson,jdbcType=SMALLINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WPromotionsdtlExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    select count(*) from W_PromotionsDtl
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WPromotionsdtl">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    update W_PromotionsDtl
    <set>
      <if test="promotprice != null">
        PromotPrice = #{promotprice,jdbcType=DECIMAL},
      </if>
      <if test="showindex != null">
        ShowIndex = #{showindex,jdbcType=INTEGER},
      </if>
      <if test="numofperson != null">
        NumOfPerson = #{numofperson,jdbcType=SMALLINT},
      </if>
    </set>
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WPromotionsdtl">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 04 15:22:44 CST 2016.
    -->
    update W_PromotionsDtl
    set PromotPrice = #{promotprice,jdbcType=DECIMAL},
      ShowIndex = #{showindex,jdbcType=INTEGER},
      NumOfPerson = #{numofperson,jdbcType=SMALLINT}
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and GoodsID = #{goodsid,jdbcType=VARCHAR}
  </update>

	<select id="seckillgoods" resultType="java.util.LinkedHashMap">
		select
		wpd.PromotionsID,wpd.PromotPrice,wpd.ShowIndex,wg.*
		from
		W_PromotionsDtl as wpd
		inner join W_Goods as wg on
		wpd.GoodsID=wg.GoodsID
		where wpd.PromotionsID=#{promotionsid,jdbcType=INTEGER} 
		order by wpd.ShowIndex asc
	</select>

	<select id="seckillgoodsinfo" resultType="java.util.LinkedHashMap">
		select	wpd.PromotPrice,wpd.NumOfPerson,wg.*
		from W_PromotionsDtl as wpd
		inner join W_Goods as wg on wpd.GoodsID=wg.GoodsID		
		where wpd.PromotionsID=#{promotionsid,jdbcType=INTEGER} and 
		wpd.GoodsID=#{goodsid,jdbcType=VARCHAR}
	</select>

	<select id="loadgoodsinfo" resultType="java.util.LinkedHashMap">
		select a.GoodsID,a.ColorID,a.SizeID,a.Quantity, a.TotalQty,a.TotalSell,
		isnull(a.Price,(select top 1 Price from W_Goods t with(nolock) where t.GoodsID=d.GoodsID)) Price,
		b.Color,c.Size,d.*
		from W_Goods d with(nolock)
		left join W_Store as a with(nolock) on a.GoodsID=d.GoodsID 
		left join Color b with(nolock) on a.ColorID=b.ColorID 
		left join Size c with(nolock) on a.SizeID=c.SizeID 
		where d.GoodsID=#{goodsid,jdbcType=VARCHAR}
	</select>

	<select id="delseckillstore" resultType="java.util.LinkedHashMap">
		${paramSQL}
	</select>

	<select id="seckills" resultType="java.util.LinkedHashMap">
		select
		a.PromotionsID,a.GoodsID,a.PromotPrice,b.Price,b.GoodName,b.ImgPath,
		a.ShowIndex
		,SUM(c.PromotQty) Inv
		from W_PromotionsDtl a with(nolock)
		join W_Goods b with(nolock)
		on a.GoodsID=b.GoodsID
		left join W_PromotionsStore c with(nolock) on
		c.GoodsID=b.GoodsID
		where a.PromotionsID=#{promotionsid}
		group by
		a.PromotionsID,a.GoodsID,a.PromotPrice,b.Price,b.GoodName,b.ImgPath,
		a.ShowIndex
		order by a.ShowIndex
	</select>
	
	<select id="getPromotiongoods" resultType="java.util.LinkedHashMap">
		select wpd.PromotionsID,wpd.GoodsID,wpd.PromotPrice,wpd.ShowIndex,wg.Code,
			wg.GoodName,wg.ImgPath,wg.Price,wg.AtList,
			(select sum(t.Quantity) from W_Store t with(nolock) where goodsid=wpd.Goodsid) StoreNum
		from
		W_PromotionsDtl as wpd with(nolock)
		inner join W_Goods as wg with(nolock) on
		wpd.GoodsID=wg.GoodsID
		where wpd.PromotionsID=#{promotionsid,jdbcType=INTEGER} 
		order by wpd.ShowIndex asc
	</select>
	
	<update id="updategoodsPromID">
		update w_goods set PromotionsID=#{promotionsid,jdbcType=INTEGER} 
		where GoodsID =#{goodsid,jdbcType=VARCHAR}
	</update>
	
	<update id="cleargoodsPromID">
		update w_goods set PromotionsID = null
		where PromotionsID=#{promotionsid,jdbcType=INTEGER}
	</update>
	
	<select id="promotionsgoodsdata" resultType="java.util.LinkedHashMap">
		select wpd.PromotionsID,wpd.GoodsID,wpd.PromotPrice,wpd.ShowIndex,wg.Code,
			wg.GoodName,wg.ImgPath,wg.Price,wg.AtList,
			(select sum(t.Quantity) from W_Store t with(nolock) where goodsid=wpd.Goodsid) StoreNum
		from
		W_PromotionsDtl as wpd with(nolock)
		inner join W_Goods as wg with(nolock) on
		wpd.GoodsID=wg.GoodsID
		where wpd.PromotionsID=#{promotionsid,jdbcType=INTEGER} 
		order by wpd.ShowIndex asc
	</select>
</mapper>