<?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.WPromotionstickMapper" >
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WPromotionstick" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 25 16:42:45 CST 2015.
    -->
    <id column="PromotionsID" property="promotionsid" jdbcType="INTEGER" />
    <id column="TicketID" property="ticketid" jdbcType="BIGINT" />
    <result column="WinRate" property="winrate" jdbcType="TINYINT" />
  </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 25 16:42:45 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 25 16:42:45 CST 2015.
    -->
    PromotionsID, TicketID, WinRate
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.fuxi.ws.data.entity.WPromotionstickExample" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 25 16:42:45 CST 2015.
    -->
    select
    <if test="distinct" >
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_PromotionsTick
    <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.WPromotionstickKey" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 25 16:42:45 CST 2015.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_PromotionsTick
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and TicketID = #{ticketid,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WPromotionstickKey" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 25 16:42:45 CST 2015.
    -->
    delete from W_PromotionsTick
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and TicketID = #{ticketid,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WPromotionstick" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 25 16:42:45 CST 2015.
    -->
    insert into W_PromotionsTick (PromotionsID, TicketID, WinRate
      )
    values (#{promotionsid,jdbcType=INTEGER}, #{ticketid,jdbcType=BIGINT}, #{winrate,jdbcType=TINYINT}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WPromotionstick" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 25 16:42:45 CST 2015.
    -->
    insert into W_PromotionsTick
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="promotionsid != null" >
        PromotionsID,
      </if>
      <if test="ticketid != null" >
        TicketID,
      </if>
      <if test="winrate != null" >
        WinRate,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="promotionsid != null" >
        #{promotionsid,jdbcType=INTEGER},
      </if>
      <if test="ticketid != null" >
        #{ticketid,jdbcType=BIGINT},
      </if>
      <if test="winrate != null" >
        #{winrate,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WPromotionstickExample" resultType="java.lang.Integer" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 25 16:42:45 CST 2015.
    -->
    select count(*) from W_PromotionsTick
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WPromotionstick" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 25 16:42:45 CST 2015.
    -->
    update W_PromotionsTick
    <set >
      <if test="winrate != null" >
        WinRate = #{winrate,jdbcType=TINYINT},
      </if>
    </set>
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and TicketID = #{ticketid,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WPromotionstick" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Tue Aug 25 16:42:45 CST 2015.
    -->
    update W_PromotionsTick
    set WinRate = #{winrate,jdbcType=TINYINT}
    where PromotionsID = #{promotionsid,jdbcType=INTEGER}
      and TicketID = #{ticketid,jdbcType=BIGINT}
  </update>
  
  <select id="redenvelopetickets" resultType="java.util.LinkedHashMap">
	select a.PromotionsID,a.WinRate,b.* 
	from W_PromotionsTick as a 
	inner join W_Ticket as b on a.TicketID=b.TicketID 
	order by b.MinConsumption asc
  </select>
  
  <select id="redenvelopetickets2" resultType="java.util.LinkedHashMap">
	select a.PromotionsID,a.WinRate,b.* 
	from W_PromotionsTick as a 
	inner join W_Ticket as b on a.TicketID=b.TicketID 
	where a.PromotionsID=#{promotionsid,jdbcType=INTEGER}
	order by b.MinConsumption asc
  </select>
  
  <select id="redenvelopelist" resultType="java.util.LinkedHashMap">
	select PromotionsID,CONVERT(varchar(19),BeginTime, 121) as BeginTime,CONVERT(varchar(10),BeginTime, 121) as BeginTime1,CONVERT(varchar(10),BeginTime, 108) as BeginTime2,
	CONVERT(varchar(19),EndTime, 121) as EndTime,CONVERT(varchar(10),EndTime, 121) as EndTime1,CONVERT(varchar(10),EndTime, 108) as EndTime2,Promotions,StopFlag 
	from W_Promotions 
	where PromotType=4 
	<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="delpromotions" resultType="java.util.LinkedHashMap">
	delete from W_PromotionsTick where PromotionsID=#{promotionsid,jdbcType=INTEGER}
  </select>
  
   <select id="redenvelopevalue" resultType="java.util.LinkedHashMap">
	select * from W_Ticket 
	where TicketID in (select TicketID from W_PromotionsTick where PromotionsID=#{promotionsid,jdbcType=INTEGER})
	order by Parvalue desc
  </select>
  
   <select id="shaketickets" resultType="java.util.LinkedHashMap">
	select a.PromotionsID,a.WinRate,b.* 
	from W_PromotionsTick as a 
	inner join W_Ticket as b on a.TicketID=b.TicketID 
	inner join W_Promotions as c on a.PromotionsID=c.PromotionsID
	where GETDATE() between c.BeginTime and c.EndTime
	and a.PromotionsID=#{promotionsid,jdbcType=INTEGER}
  </select>
</mapper>