<?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.WPromotionsMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WPromotions">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 17 16:51:53 CST 2017.
    -->
    <id column="PromotionsID" jdbcType="INTEGER" property="promotionsid" />
    <result column="Promotions" jdbcType="NVARCHAR" property="promotions" />
    <result column="PromotType" jdbcType="TINYINT" property="promottype" />
    <result column="BeginTime" jdbcType="TIMESTAMP" property="begintime" />
    <result column="EndTime" jdbcType="TIMESTAMP" property="endtime" />
    <result column="PhotoUrl" jdbcType="VARCHAR" property="photourl" />
    <result column="ModelUrl" jdbcType="VARCHAR" property="modelurl" />
    <result column="FinishUrl" jdbcType="VARCHAR" property="finishurl" />
    <result column="NeedGoods" jdbcType="TINYINT" property="needgoods" />
    <result column="UseShop" jdbcType="TINYINT" property="useshop" />
    <result column="LimntMoney" jdbcType="DECIMAL" property="limntmoney" />
    <result column="LimntQty" jdbcType="DECIMAL" property="limntqty" />
    <result column="PaymentType" jdbcType="TINYINT" property="paymenttype" />
    <result column="MuchAble" jdbcType="TINYINT" property="muchable" />
    <result column="Lucky" jdbcType="TINYINT" property="lucky" />
    <result column="StopFlag" jdbcType="TINYINT" property="stopflag" />
    <result column="Creater" jdbcType="VARCHAR" property="creater" />
    <result column="Created" jdbcType="TIMESTAMP" property="created" />
    <result column="Modifier" jdbcType="VARCHAR" property="modifier" />
    <result column="Modified" jdbcType="TIMESTAMP" property="modified" />
    <result column="LeadNum" jdbcType="INTEGER" property="leadnum" />
    <result column="ShareTitle" jdbcType="VARCHAR" property="sharetitle" />
    <result column="ShareSummary" jdbcType="VARCHAR" property="sharesummary" />
    <result column="ShareImage" jdbcType="VARCHAR" property="shareimage" />
    <result column="Deduction" jdbcType="DECIMAL" property="deduction" />
  </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 Oct 17 16:51:53 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 Oct 17 16:51:53 CST 2017.
    -->
    PromotionsID, Promotions, PromotType, BeginTime, EndTime, PhotoUrl, ModelUrl, FinishUrl, 
    NeedGoods, UseShop, LimntMoney, LimntQty, PaymentType, MuchAble, Lucky, StopFlag, 
    Creater, Created, Modifier, Modified, LeadNum, ShareTitle, ShareSummary, ShareImage, 
    Deduction
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WPromotionsExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 17 16:51:53 CST 2017.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_Promotions
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 17 16:51:53 CST 2017.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_Promotions
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 17 16:51:53 CST 2017.
    -->
    delete from W_Promotions
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WPromotions">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 17 16:51:53 CST 2017.
    -->
    insert into W_Promotions (PromotionsID, Promotions, PromotType, 
      BeginTime, EndTime, PhotoUrl, 
      ModelUrl, FinishUrl, NeedGoods, 
      UseShop, LimntMoney, LimntQty, 
      PaymentType, MuchAble, Lucky, 
      StopFlag, Creater, Created, 
      Modifier, Modified, LeadNum, 
      ShareTitle, ShareSummary, ShareImage, 
      Deduction)
    values (#{promotionsid,jdbcType=INTEGER}, #{promotions,jdbcType=NVARCHAR}, #{promottype,jdbcType=TINYINT}, 
      #{begintime,jdbcType=TIMESTAMP}, #{endtime,jdbcType=TIMESTAMP}, #{photourl,jdbcType=VARCHAR}, 
      #{modelurl,jdbcType=VARCHAR}, #{finishurl,jdbcType=VARCHAR}, #{needgoods,jdbcType=TINYINT}, 
      #{useshop,jdbcType=TINYINT}, #{limntmoney,jdbcType=DECIMAL}, #{limntqty,jdbcType=DECIMAL}, 
      #{paymenttype,jdbcType=TINYINT}, #{muchable,jdbcType=TINYINT}, #{lucky,jdbcType=TINYINT}, 
      #{stopflag,jdbcType=TINYINT}, #{creater,jdbcType=VARCHAR}, #{created,jdbcType=TIMESTAMP}, 
      #{modifier,jdbcType=VARCHAR}, #{modified,jdbcType=TIMESTAMP}, #{leadnum,jdbcType=INTEGER}, 
      #{sharetitle,jdbcType=VARCHAR}, #{sharesummary,jdbcType=VARCHAR}, #{shareimage,jdbcType=VARCHAR}, 
      #{deduction,jdbcType=DECIMAL})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WPromotions">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 17 16:51:53 CST 2017.
    -->
    insert into W_Promotions
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="promotionsid != null">
        PromotionsID,
      </if>
      <if test="promotions != null">
        Promotions,
      </if>
      <if test="promottype != null">
        PromotType,
      </if>
      <if test="begintime != null">
        BeginTime,
      </if>
      <if test="endtime != null">
        EndTime,
      </if>
      <if test="photourl != null">
        PhotoUrl,
      </if>
      <if test="modelurl != null">
        ModelUrl,
      </if>
      <if test="finishurl != null">
        FinishUrl,
      </if>
      <if test="needgoods != null">
        NeedGoods,
      </if>
      <if test="useshop != null">
        UseShop,
      </if>
      <if test="limntmoney != null">
        LimntMoney,
      </if>
      <if test="limntqty != null">
        LimntQty,
      </if>
      <if test="paymenttype != null">
        PaymentType,
      </if>
      <if test="muchable != null">
        MuchAble,
      </if>
      <if test="lucky != null">
        Lucky,
      </if>
      <if test="stopflag != null">
        StopFlag,
      </if>
      <if test="creater != null">
        Creater,
      </if>
      <if test="created != null">
        Created,
      </if>
      <if test="modifier != null">
        Modifier,
      </if>
      <if test="modified != null">
        Modified,
      </if>
      <if test="leadnum != null">
        LeadNum,
      </if>
      <if test="sharetitle != null">
        ShareTitle,
      </if>
      <if test="sharesummary != null">
        ShareSummary,
      </if>
      <if test="shareimage != null">
        ShareImage,
      </if>
      <if test="deduction != null">
        Deduction,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="promotionsid != null">
        #{promotionsid,jdbcType=INTEGER},
      </if>
      <if test="promotions != null">
        #{promotions,jdbcType=NVARCHAR},
      </if>
      <if test="promottype != null">
        #{promottype,jdbcType=TINYINT},
      </if>
      <if test="begintime != null">
        #{begintime,jdbcType=TIMESTAMP},
      </if>
      <if test="endtime != null">
        #{endtime,jdbcType=TIMESTAMP},
      </if>
      <if test="photourl != null">
        #{photourl,jdbcType=VARCHAR},
      </if>
      <if test="modelurl != null">
        #{modelurl,jdbcType=VARCHAR},
      </if>
      <if test="finishurl != null">
        #{finishurl,jdbcType=VARCHAR},
      </if>
      <if test="needgoods != null">
        #{needgoods,jdbcType=TINYINT},
      </if>
      <if test="useshop != null">
        #{useshop,jdbcType=TINYINT},
      </if>
      <if test="limntmoney != null">
        #{limntmoney,jdbcType=DECIMAL},
      </if>
      <if test="limntqty != null">
        #{limntqty,jdbcType=DECIMAL},
      </if>
      <if test="paymenttype != null">
        #{paymenttype,jdbcType=TINYINT},
      </if>
      <if test="muchable != null">
        #{muchable,jdbcType=TINYINT},
      </if>
      <if test="lucky != null">
        #{lucky,jdbcType=TINYINT},
      </if>
      <if test="stopflag != null">
        #{stopflag,jdbcType=TINYINT},
      </if>
      <if test="creater != null">
        #{creater,jdbcType=VARCHAR},
      </if>
      <if test="created != null">
        #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="modifier != null">
        #{modifier,jdbcType=VARCHAR},
      </if>
      <if test="modified != null">
        #{modified,jdbcType=TIMESTAMP},
      </if>
      <if test="leadnum != null">
        #{leadnum,jdbcType=INTEGER},
      </if>
      <if test="sharetitle != null">
        #{sharetitle,jdbcType=VARCHAR},
      </if>
      <if test="sharesummary != null">
        #{sharesummary,jdbcType=VARCHAR},
      </if>
      <if test="shareimage != null">
        #{shareimage,jdbcType=VARCHAR},
      </if>
      <if test="deduction != null">
        #{deduction,jdbcType=DECIMAL},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WPromotionsExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 17 16:51:53 CST 2017.
    -->
    select count(*) from W_Promotions
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WPromotions">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 17 16:51:53 CST 2017.
    -->
    update W_Promotions
    <set>
      <if test="promotions != null">
        Promotions = #{promotions,jdbcType=NVARCHAR},
      </if>
      <if test="promottype != null">
        PromotType = #{promottype,jdbcType=TINYINT},
      </if>
      <if test="begintime != null">
        BeginTime = #{begintime,jdbcType=TIMESTAMP},
      </if>
      <if test="endtime != null">
        EndTime = #{endtime,jdbcType=TIMESTAMP},
      </if>
      <if test="photourl != null">
        PhotoUrl = #{photourl,jdbcType=VARCHAR},
      </if>
      <if test="modelurl != null">
        ModelUrl = #{modelurl,jdbcType=VARCHAR},
      </if>
      <if test="finishurl != null">
        FinishUrl = #{finishurl,jdbcType=VARCHAR},
      </if>
      <if test="needgoods != null">
        NeedGoods = #{needgoods,jdbcType=TINYINT},
      </if>
      <if test="useshop != null">
        UseShop = #{useshop,jdbcType=TINYINT},
      </if>
      <if test="limntmoney != null">
        LimntMoney = #{limntmoney,jdbcType=DECIMAL},
      </if>
      <if test="limntqty != null">
        LimntQty = #{limntqty,jdbcType=DECIMAL},
      </if>
      <if test="paymenttype != null">
        PaymentType = #{paymenttype,jdbcType=TINYINT},
      </if>
      <if test="muchable != null">
        MuchAble = #{muchable,jdbcType=TINYINT},
      </if>
      <if test="lucky != null">
        Lucky = #{lucky,jdbcType=TINYINT},
      </if>
      <if test="stopflag != null">
        StopFlag = #{stopflag,jdbcType=TINYINT},
      </if>
      <if test="creater != null">
        Creater = #{creater,jdbcType=VARCHAR},
      </if>
      <if test="created != null">
        Created = #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="modifier != null">
        Modifier = #{modifier,jdbcType=VARCHAR},
      </if>
      <if test="modified != null">
        Modified = #{modified,jdbcType=TIMESTAMP},
      </if>
      <if test="leadnum != null">
        LeadNum = #{leadnum,jdbcType=INTEGER},
      </if>
      <if test="sharetitle != null">
        ShareTitle = #{sharetitle,jdbcType=VARCHAR},
      </if>
      <if test="sharesummary != null">
        ShareSummary = #{sharesummary,jdbcType=VARCHAR},
      </if>
      <if test="shareimage != null">
        ShareImage = #{shareimage,jdbcType=VARCHAR},
      </if>
      <if test="deduction != null">
        Deduction = #{deduction,jdbcType=DECIMAL},
      </if>
    </set>
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WPromotions">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Oct 17 16:51:53 CST 2017.
    -->
    update W_Promotions
    set Promotions = #{promotions,jdbcType=NVARCHAR},
      PromotType = #{promottype,jdbcType=TINYINT},
      BeginTime = #{begintime,jdbcType=TIMESTAMP},
      EndTime = #{endtime,jdbcType=TIMESTAMP},
      PhotoUrl = #{photourl,jdbcType=VARCHAR},
      ModelUrl = #{modelurl,jdbcType=VARCHAR},
      FinishUrl = #{finishurl,jdbcType=VARCHAR},
      NeedGoods = #{needgoods,jdbcType=TINYINT},
      UseShop = #{useshop,jdbcType=TINYINT},
      LimntMoney = #{limntmoney,jdbcType=DECIMAL},
      LimntQty = #{limntqty,jdbcType=DECIMAL},
      PaymentType = #{paymenttype,jdbcType=TINYINT},
      MuchAble = #{muchable,jdbcType=TINYINT},
      Lucky = #{lucky,jdbcType=TINYINT},
      StopFlag = #{stopflag,jdbcType=TINYINT},
      Creater = #{creater,jdbcType=VARCHAR},
      Created = #{created,jdbcType=TIMESTAMP},
      Modifier = #{modifier,jdbcType=VARCHAR},
      Modified = #{modified,jdbcType=TIMESTAMP},
      LeadNum = #{leadnum,jdbcType=INTEGER},
      ShareTitle = #{sharetitle,jdbcType=VARCHAR},
      ShareSummary = #{sharesummary,jdbcType=VARCHAR},
      ShareImage = #{shareimage,jdbcType=VARCHAR},
      Deduction = #{deduction,jdbcType=DECIMAL}
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
  </update>
  
	<select id="promotionsdata" resultType="java.util.LinkedHashMap">
		SELECT PromotionsID, Promotions,CONVERT(varchar(10),BeginTime, 121) +
		'<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10), BeginTime, 108) AS BeginTime,
		CONVERT(varchar(10),EndTime, 121) + '<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10), EndTime, 108) AS EndTime,Case when
		getdate()&gt;=BeginTime and getdate() <![CDATA[<]]>
		EndTime then 1
		when getdate() &gt;= EndTime then 1 else 0 end as
		Status,PaymentType
		FROM W_Promotions
		where PromotType =
		#{promottype,jdbcType=TINYINT}
		<if test="status == 0">
			and BeginTime &gt; getdate()
		</if>
		<if test="status == 1">
			and getdate() &gt;= BeginTime and EndTime &gt; getdate()
		</if>
		<if test="status == 2">
			and getdate() &gt;= EndTime
		</if>
		order by BeginTime desc
	</select>

	<!-- 读取商品列表信息 -->
	<select id="goodsList" resultType="java.util.LinkedHashMap">
		<![CDATA[SELECT a.GoodsID,a.ImgPath,a.Code,a.GoodName,a.Price,(select sum(t.Quantity) from W_Store t with(nolock) where t.goodsid=a.Goodsid) TotalQty
		FROM W_Goods AS a with(nolock) 
		where a.goodsid not in (SELECT b.GoodsID FROM W_Promotions a with(nolock) inner join
			W_PromotionsDtl b with(nolock) on a.PromotionsID=b.PromotionsID and NeedGoods=1 and a.PromotType=3 and a.StopFlag=0
			where ((a.BeginTime<=#{begintime,jdbcType=TIMESTAMP} and a.EndTime >=#{begintime,jdbcType=TIMESTAMP}) or (a.BeginTime<=#{endtime,jdbcType=TIMESTAMP}	and a.EndTime>=#{endtime,jdbcType=TIMESTAMP})
			or (a.BeginTime>=#{begintime,jdbcType=TIMESTAMP} and a.EndTime<=#{endtime,jdbcType=TIMESTAMP})))]]>
		<if test="conditions != null and conditions != ''">
			and ${conditions}
		</if>
		order by a.Created desc
	</select>

	<select id="getpromotioning" resultType="java.util.LinkedHashMap">
		SELECT a.PromotionsID,Promotions,b.GoodsID
		FROM W_Promotions a inner
		join
		W_PromotionsDtl b on a.PromotionsID=b.PromotionsID and
		a.NeedGoods=1
		and b.GoodsID<![CDATA[<>]]>''
		and b.GoodsID is not null
		where ((a.BeginTime<![CDATA[<=]]>#{begintime,jdbcType=TIMESTAMP}
		and a.EndTime &gt;=#{begintime,jdbcType=TIMESTAMP})
		or (a.BeginTime<![CDATA[<=]]>#{endtime,jdbcType=TIMESTAMP}
		and a.EndTime &gt;=#{endtime,jdbcType=TIMESTAMP})
		or
		(a.BeginTime&gt;=#{begintime,jdbcType=TIMESTAMP}
		and a.EndTime <![CDATA[<=]]>#{endtime,jdbcType=TIMESTAMP}))
		and PromotType = 3 and a.StopFlag=0
		<if test="promotionsid != null">
			and a.PromotionsID <![CDATA[<>]]>
			#{promotionsid,jdbcType=INTEGER}
		</if>
		union all
		SELECT PromotionsID,Promotions,'AllGoods'
		as GoodsID
		FROM
		W_Promotions a
		where a.NeedGoods = 0 and ((a.BeginTime<![CDATA[<=]]>#{begintime,jdbcType=TIMESTAMP}
		and a.EndTime &gt;=#{begintime,jdbcType=TIMESTAMP})
		or (a.BeginTime<![CDATA[<=]]>#{endtime,jdbcType=TIMESTAMP}
		and a.EndTime &gt;=#{endtime,jdbcType=TIMESTAMP})
		or (a.BeginTime<![CDATA[>=]]>#{begintime,jdbcType=TIMESTAMP}
		and a.EndTime <![CDATA[<=]]>#{endtime,jdbcType=TIMESTAMP}))
		and PromotType = 3 and a.StopFlag=0
		<if test="promotionsid != null">
			and a.PromotionsID <![CDATA[<>]]>
			#{promotionsid,jdbcType=INTEGER}
		</if>
	</select>
	<update id="updateAllgoodsPromID">
		update w_goods set PromotionsID=#{promotionsid,jdbcType=INTEGER}
		where
		not exists (SELECT a.PromotionsID
		FROM W_Promotions a inner join
		W_PromotionsDtl b on a.PromotionsID=b.PromotionsID and NeedGoods=1 and
		b.GoodsID<![CDATA[<>]]>''
		and b.GoodsID is not null
		where ((a.BeginTime<![CDATA[<=]]>#{begintime,jdbcType=TIMESTAMP}
		and a.EndTime &gt;=#{begintime,jdbcType=TIMESTAMP})
		or (a.BeginTime<![CDATA[<=]]>#{endtime,jdbcType=TIMESTAMP}
		and a.EndTime &gt;=#{endtime,jdbcType=TIMESTAMP})
		or
		(a.BeginTime&gt;=#{begintime,jdbcType=TIMESTAMP}
		and a.EndTime<![CDATA[<=]]>#{endtime,jdbcType=TIMESTAMP}))
		and PromotType = 3
		union all
		SELECT PromotionsID
		FROM W_Promotions a
		where NeedGoods = 0 and
		((a.BeginTime<![CDATA[<=]]>#{begintime,jdbcType=TIMESTAMP}
		and a.EndTime &gt;=#{begintime,jdbcType=TIMESTAMP})
		or (a.BeginTime<![CDATA[<=]]>#{endtime,jdbcType=TIMESTAMP}
		and a.EndTime &gt;=#{endtime,jdbcType=TIMESTAMP})
		or
		(a.BeginTime&gt;=#{begintime,jdbcType=TIMESTAMP}
		and a.EndTime<![CDATA[<=]]>#{endtime,jdbcType=TIMESTAMP}))
		and PromotType = 3
		)
	</update>

	<select id="getPromotionsIDs" resultType="java.util.LinkedHashMap">
		<![CDATA[
		SELECT a.PromotionsID, Promotions, PromotType,
		BeginTime, EndTime, PhotoUrl, ModelUrl, NeedGoods, LimntMoney,
		LimntQty, MuchAble, StopFlag, Creater,
		Created, Modifier, Modified
		FROM W_Promotions a inner join
		W_PromotionsDtl b on a.PromotionsID=b.PromotionsID and NeedGoods=1
		where (a.BeginTime<=GETDATE() and a.EndTime >=GETDATE()) and PromotType = #{ promottype } and
		b.GoodsID=#{ goodsid } and a.StopFlag=0
		union all
		SELECT PromotionsID, Promotions, PromotType, BeginTime, EndTime, PhotoUrl,
		ModelUrl, NeedGoods, LimntMoney, LimntQty, MuchAble, StopFlag,
		Creater,
		Created, Modifier, Modified
		FROM W_Promotions a
		where NeedGoods = 0 and (a.BeginTime<=GETDATE() and a.EndTime >=GETDATE()) and
		PromotType = #{ promottype }  and a.StopFlag=0
		]]>
	</select>

	<select id="getPromotionsIDs2" resultType="java.util.LinkedHashMap">
		SELECT a.PromotionsID, Promotions, PromotType,
		BeginTime, EndTime,
		PhotoUrl, ModelUrl, NeedGoods, LimntMoney,
		LimntQty, MuchAble,
		StopFlag, Creater,
		Created, Modifier, Modified, b.GoodsID
		FROM
		W_Promotions a inner
		join
		W_PromotionsDtl b on
		a.PromotionsID=b.PromotionsID and NeedGoods=1
		where (a.BeginTime<![CDATA[<=]]>GETDATE()
		and a.EndTime<![CDATA[>=]]>GETDATE())
		and PromotType = 3 and a.StopFlag=0 and a.PaymentType = #{
		paymenttype
		}
		<if test="list.size() &gt;0">
			and b.GoodsID in
			<foreach close=")" collection="list" index="index" item="item" open="(" separator=",">
				#{item}
			</foreach>
		</if>
		union all
		SELECT PromotionsID, Promotions, PromotType, BeginTime,
		EndTime, PhotoUrl,
		ModelUrl, NeedGoods, LimntMoney, LimntQty, MuchAble,
		StopFlag,
		Creater,
		Created, Modifier, Modified,'all'
		FROM W_Promotions a
		where
		NeedGoods = 0 and (a.BeginTime<![CDATA[<=]]>GETDATE()
		and a.EndTime <![CDATA[>=]]>GETDATE())
		and
		PromotType = 3 and a.StopFlag=0 and a.PaymentType = #{
		paymenttype }
	</select>

	<select id="recomgiftdata" resultType="java.util.LinkedHashMap">
		SELECT a.PromotionsID,a.Promotions,CONVERT(varchar(10),a.BeginTime,
		121) +
		'<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10),a.BeginTime, 108) AS BeginTime,
		CONVERT(varchar(10),a.EndTime, 121) + '<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10),a.EndTime, 108) AS EndTime,Case when
		getdate()&gt;=a.BeginTime and getdate() <![CDATA[<]]>
		EndTime then 1
		when getdate() &gt;=a.EndTime then 1 else 0 end as
		Status,
		a.LeadNum,c.GoodName,c.ImgPath
		FROM W_Promotions a inner join
		W_PromotionsDtl b on a.PromotionsID=b.PromotionsID inner join
		W_Goods c
		on c.GoodsID=b.GoodsID
		where PromotType = 5
		order by BeginTime
		desc
	</select>

	<!-- 幸运抽奖列表 -->
	<select id="rotarylist" resultType="java.util.LinkedHashMap">
		select a.PromotionsID,CONVERT(varchar(10),a.BeginTime, 121) +
		'<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10),a.BeginTime, 108) as BeginTime,
		CONVERT(varchar(10),a.EndTime, 121) + '<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10),a.EndTime, 108) as EndTime,a.Promotions,
		case
		a.Lucky when 1 then '每天' else '一次性' end as Lucky,
		a.LeadNum,ISNULL(b.AllVipCount,0) as
		AllVipCount,ISNULL(c.DrawTimesSum,0) as DrawTimesSum,
		ISNULL(d.VipCount,0) as VipCount, ISNULL(e.WinningTimeSum,0) as
		WinningTimeSum,
		CASE WHEN a.BeginTime&gt;GETDATE() then 1 else 0 end as
		editflag,CASE WHEN a.BeginTime <![CDATA[>]]>
		GETDATE() then 1 WHEN a.BeginTime <![CDATA[<=]]>
		GETDATE() and a.EndTime <![CDATA[>=]]>
		GETDATE() then 2 else 3 end as Status,a.StopFlag  
		from W_Promotions as a
		left join (select
		PromotionsID,COUNT(Vipid) as AllVipCount from
		W_LuckyEnter group by
		PromotionsID) as b on
		a.PromotionsID=b.PromotionsID
		left join (select
		PromotionsID,SUM(DrawTimes) as DrawTimesSum from
		W_LuckyEnter group by
		PromotionsID) as c on
		a.PromotionsID=c.PromotionsID
		left join (select
		PromotionsID,COUNT(Vipid) as VipCount from W_LuckyEnter
		where
		WinningTime&gt;0 group by PromotionsID) as d on
		a.PromotionsID=d.PromotionsID
		left join (select
		PromotionsID,SUM(WinningTime) as WinningTimeSum from
		W_LuckyEnter group
		by PromotionsID) as e on
		a.PromotionsID=e.PromotionsID
		where
		PromotType=6
		<if test="status == 1 ">
			and a.BeginTime&gt;GETDATE()
		</if>
		<if test="status == 2 ">
			and a.BeginTime<![CDATA[<=]]>getdate()
			and a.EndTime &gt;= getdate()
		</if>
		<if test="status == 3 ">
			and a.EndTime<![CDATA[<]]>GETDATE()
		</if>
	</select>

	<!-- 幸运抽奖九宫格明细 -->
	<select id="rotarydetail" resultType="java.util.LinkedHashMap">
		select
		a.PromotionsID,a.LuckyID,a.LuckyType,a.TicketID,a.LuckyNum,a.LuckyName,
		a.GoodsID,a.Background,a.Foreground,a.LuckTotal,b.Code,b.GoodName Name,c.TicketName,c.Parvalue,a.WinRate 
		from W_Lucky as a
		left join W_Goods as b on a.GoodsID=b.GoodsID
		left join
		W_Ticket as c on
		a.TicketID=c.TicketID
		where a.PromotionsID =
		#{promotionsid,jdbcType=INTEGER}
		order by LuckyID asc
	</select>

	<!-- 限时秒杀列表 -->
	<select id="seckilllist" resultType="java.util.LinkedHashMap">
		select PromotionsID,CONVERT(varchar(10),BeginTime, 121) + '<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10),BeginTime, 108) as BeginTime,
		CONVERT(varchar(10),EndTime, 121) + '<![CDATA[<br/>]]>'
		+ CONVERT(varchar(10),EndTime, 108) as EndTime,Promotions,
		StopFlag,CASE WHEN BeginTime <![CDATA[>]]>
		GETDATE() then 1 WHEN BeginTime <![CDATA[<=]]> GETDATE() and EndTime <![CDATA[>=]]> GETDATE() and StopFlag = 1  then 1 else 0 end as EditFlag,
		CASE WHEN BeginTime <![CDATA[>]]>
		GETDATE() then 1 WHEN BeginTime <![CDATA[<=]]>
		GETDATE() and EndTime <![CDATA[>=]]>
		GETDATE() then 2 else 3 end as Status
		from W_Promotions
		where PromotType=1
		<if test="status == 1 ">
			and BeginTime <![CDATA[>]]> GETDATE()
		</if>
		<if test="status == 2 ">
			and BeginTime <![CDATA[<=]]> GETDATE() and EndTime <![CDATA[>=]]> GETDATE() and StopFlag = 0
		</if>
		<if test="status == 3 ">
			and (EndTime <![CDATA[<]]> GETDATE() or (BeginTime <![CDATA[<=]]> GETDATE() and EndTime <![CDATA[>=]]> GETDATE() and StopFlag = 1))
		</if>
		order by PromotionsID desc
	</select>
	<!-- 读取门店列表信息 -->
	<select id="shopsList" resultType="java.util.LinkedHashMap">
		select DepartmentID,Code,Department 
		from Department (nolock)
		<if test="conditions != null and conditions != ''">
			where ${conditions}
		</if>
		order by Code asc
	</select>
</mapper>