<?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.WTicketMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WTicket">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 CST 2017.
    -->
    <id column="TicketID" jdbcType="BIGINT" property="ticketid" />
    <result column="DepartmentID" jdbcType="VARCHAR" property="departmentid" />
    <result column="TicketName" jdbcType="NVARCHAR" property="ticketname" />
    <result column="Background" jdbcType="VARCHAR" property="background" />
    <result column="Parvalue" jdbcType="INTEGER" property="parvalue" />
    <result column="MinConsumption" jdbcType="INTEGER" property="minconsumption" />
    <result column="ParVIP" jdbcType="INTEGER" property="parvip" />
    <result column="Pringting" jdbcType="INTEGER" property="pringting" />
    <result column="SendOut" jdbcType="INTEGER" property="sendout" />
    <result column="Used" jdbcType="INTEGER" property="used" />
    <result column="BeginTime" jdbcType="TIMESTAMP" property="begintime" />
    <result column="EndTime" jdbcType="TIMESTAMP" property="endtime" />
    <result column="Viptype" jdbcType="VARCHAR" property="viptype" />
    <result column="GoodsType" jdbcType="VARCHAR" property="goodstype" />
    <result column="UseScene" jdbcType="TINYINT" property="usescene" />
    <result column="UseShop" jdbcType="TINYINT" property="useshop" />
    <result column="GoodsID" jdbcType="VARCHAR" property="goodsid" />
    <result column="ViewLogo" jdbcType="TINYINT" property="viewlogo" />
    <result column="UseUrl" jdbcType="VARCHAR" property="useurl" />
    <result column="Memo" jdbcType="NVARCHAR" property="memo" />
    <result column="ParUse" jdbcType="BIT" property="paruse" />
    <result column="UsedFlag" jdbcType="BIT" property="usedflag" />
    <result column="Created" jdbcType="TIMESTAMP" property="created" />
    <result column="Creater" jdbcType="VARCHAR" property="creater" />
    <result column="TicketType" jdbcType="TINYINT" property="tickettype" />
    <result column="UseType" jdbcType="TINYINT" property="usetype" />
    <result column="TicketNo" jdbcType="VARCHAR" property="ticketno" />
    <result column="Hint" jdbcType="NVARCHAR" property="hint" />
    <result column="Color" jdbcType="VARCHAR" property="color" />
    <result column="Cover" jdbcType="VARCHAR" property="cover" />
    <result column="SendFlag" jdbcType="TINYINT" property="sendflag" />
    <result column="ExchangePoint" jdbcType="DECIMAL" property="exchangepoint" />
    <result column="BuyPrice" jdbcType="DECIMAL" property="buyprice" />
    <result column="EffectiveDay" jdbcType="INTEGER" property="effectiveday" />
    <result column="OnlineFlag" jdbcType="TINYINT" property="onlineflag" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 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 Thu Dec 14 15:34:47 CST 2017.
    -->
    TicketID, DepartmentID, TicketName, Background, Parvalue, MinConsumption, ParVIP, 
    Pringting, SendOut, Used, BeginTime, EndTime, Viptype, GoodsType, UseScene, UseShop, 
    GoodsID, ViewLogo, UseUrl, Memo, ParUse, UsedFlag, Created, Creater, TicketType, 
    UseType, TicketNo, Hint, Color, Cover, SendFlag, ExchangePoint, BuyPrice, EffectiveDay, 
    OnlineFlag
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WTicketExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 CST 2017.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_Ticket
    <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.Long" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 CST 2017.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_Ticket
    where TicketID = #{ticketid,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 CST 2017.
    -->
    delete from W_Ticket
    where TicketID = #{ticketid,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WTicket">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 CST 2017.
    -->
    insert into W_Ticket (TicketID, DepartmentID, TicketName, 
      Background, Parvalue, MinConsumption, 
      ParVIP, Pringting, SendOut, 
      Used, BeginTime, EndTime, 
      Viptype, GoodsType, UseScene, 
      UseShop, GoodsID, ViewLogo, 
      UseUrl, Memo, ParUse, 
      UsedFlag, Created, Creater, 
      TicketType, UseType, TicketNo, 
      Hint, Color, Cover, 
      SendFlag, ExchangePoint, BuyPrice, 
      EffectiveDay, OnlineFlag)
    values (#{ticketid,jdbcType=BIGINT}, #{departmentid,jdbcType=VARCHAR}, #{ticketname,jdbcType=NVARCHAR}, 
      #{background,jdbcType=VARCHAR}, #{parvalue,jdbcType=INTEGER}, #{minconsumption,jdbcType=INTEGER}, 
      #{parvip,jdbcType=INTEGER}, #{pringting,jdbcType=INTEGER}, #{sendout,jdbcType=INTEGER}, 
      #{used,jdbcType=INTEGER}, #{begintime,jdbcType=TIMESTAMP}, #{endtime,jdbcType=TIMESTAMP}, 
      #{viptype,jdbcType=VARCHAR}, #{goodstype,jdbcType=VARCHAR}, #{usescene,jdbcType=TINYINT}, 
      #{useshop,jdbcType=TINYINT}, #{goodsid,jdbcType=VARCHAR}, #{viewlogo,jdbcType=TINYINT}, 
      #{useurl,jdbcType=VARCHAR}, #{memo,jdbcType=NVARCHAR}, #{paruse,jdbcType=BIT}, 
      #{usedflag,jdbcType=BIT}, #{created,jdbcType=TIMESTAMP}, #{creater,jdbcType=VARCHAR}, 
      #{tickettype,jdbcType=TINYINT}, #{usetype,jdbcType=TINYINT}, #{ticketno,jdbcType=VARCHAR}, 
      #{hint,jdbcType=NVARCHAR}, #{color,jdbcType=VARCHAR}, #{cover,jdbcType=VARCHAR}, 
      #{sendflag,jdbcType=TINYINT}, #{exchangepoint,jdbcType=DECIMAL}, #{buyprice,jdbcType=DECIMAL}, 
      #{effectiveday,jdbcType=INTEGER}, #{onlineflag,jdbcType=TINYINT})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WTicket">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 CST 2017.
    -->
    insert into W_Ticket
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="ticketid != null">
        TicketID,
      </if>
      <if test="departmentid != null">
        DepartmentID,
      </if>
      <if test="ticketname != null">
        TicketName,
      </if>
      <if test="background != null">
        Background,
      </if>
      <if test="parvalue != null">
        Parvalue,
      </if>
      <if test="minconsumption != null">
        MinConsumption,
      </if>
      <if test="parvip != null">
        ParVIP,
      </if>
      <if test="pringting != null">
        Pringting,
      </if>
      <if test="sendout != null">
        SendOut,
      </if>
      <if test="used != null">
        Used,
      </if>
      <if test="begintime != null">
        BeginTime,
      </if>
      <if test="endtime != null">
        EndTime,
      </if>
      <if test="viptype != null">
        Viptype,
      </if>
      <if test="goodstype != null">
        GoodsType,
      </if>
      <if test="usescene != null">
        UseScene,
      </if>
      <if test="useshop != null">
        UseShop,
      </if>
      <if test="goodsid != null">
        GoodsID,
      </if>
      <if test="viewlogo != null">
        ViewLogo,
      </if>
      <if test="useurl != null">
        UseUrl,
      </if>
      <if test="memo != null">
        Memo,
      </if>
      <if test="paruse != null">
        ParUse,
      </if>
      <if test="usedflag != null">
        UsedFlag,
      </if>
      <if test="created != null">
        Created,
      </if>
      <if test="creater != null">
        Creater,
      </if>
      <if test="tickettype != null">
        TicketType,
      </if>
      <if test="usetype != null">
        UseType,
      </if>
      <if test="ticketno != null">
        TicketNo,
      </if>
      <if test="hint != null">
        Hint,
      </if>
      <if test="color != null">
        Color,
      </if>
      <if test="cover != null">
        Cover,
      </if>
      <if test="sendflag != null">
        SendFlag,
      </if>
      <if test="exchangepoint != null">
        ExchangePoint,
      </if>
      <if test="buyprice != null">
        BuyPrice,
      </if>
      <if test="effectiveday != null">
        EffectiveDay,
      </if>
      <if test="onlineflag != null">
        OnlineFlag,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="ticketid != null">
        #{ticketid,jdbcType=BIGINT},
      </if>
      <if test="departmentid != null">
        #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="ticketname != null">
        #{ticketname,jdbcType=NVARCHAR},
      </if>
      <if test="background != null">
        #{background,jdbcType=VARCHAR},
      </if>
      <if test="parvalue != null">
        #{parvalue,jdbcType=INTEGER},
      </if>
      <if test="minconsumption != null">
        #{minconsumption,jdbcType=INTEGER},
      </if>
      <if test="parvip != null">
        #{parvip,jdbcType=INTEGER},
      </if>
      <if test="pringting != null">
        #{pringting,jdbcType=INTEGER},
      </if>
      <if test="sendout != null">
        #{sendout,jdbcType=INTEGER},
      </if>
      <if test="used != null">
        #{used,jdbcType=INTEGER},
      </if>
      <if test="begintime != null">
        #{begintime,jdbcType=TIMESTAMP},
      </if>
      <if test="endtime != null">
        #{endtime,jdbcType=TIMESTAMP},
      </if>
      <if test="viptype != null">
        #{viptype,jdbcType=VARCHAR},
      </if>
      <if test="goodstype != null">
        #{goodstype,jdbcType=VARCHAR},
      </if>
      <if test="usescene != null">
        #{usescene,jdbcType=TINYINT},
      </if>
      <if test="useshop != null">
        #{useshop,jdbcType=TINYINT},
      </if>
      <if test="goodsid != null">
        #{goodsid,jdbcType=VARCHAR},
      </if>
      <if test="viewlogo != null">
        #{viewlogo,jdbcType=TINYINT},
      </if>
      <if test="useurl != null">
        #{useurl,jdbcType=VARCHAR},
      </if>
      <if test="memo != null">
        #{memo,jdbcType=NVARCHAR},
      </if>
      <if test="paruse != null">
        #{paruse,jdbcType=BIT},
      </if>
      <if test="usedflag != null">
        #{usedflag,jdbcType=BIT},
      </if>
      <if test="created != null">
        #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="creater != null">
        #{creater,jdbcType=VARCHAR},
      </if>
      <if test="tickettype != null">
        #{tickettype,jdbcType=TINYINT},
      </if>
      <if test="usetype != null">
        #{usetype,jdbcType=TINYINT},
      </if>
      <if test="ticketno != null">
        #{ticketno,jdbcType=VARCHAR},
      </if>
      <if test="hint != null">
        #{hint,jdbcType=NVARCHAR},
      </if>
      <if test="color != null">
        #{color,jdbcType=VARCHAR},
      </if>
      <if test="cover != null">
        #{cover,jdbcType=VARCHAR},
      </if>
      <if test="sendflag != null">
        #{sendflag,jdbcType=TINYINT},
      </if>
      <if test="exchangepoint != null">
        #{exchangepoint,jdbcType=DECIMAL},
      </if>
      <if test="buyprice != null">
        #{buyprice,jdbcType=DECIMAL},
      </if>
      <if test="effectiveday != null">
        #{effectiveday,jdbcType=INTEGER},
      </if>
      <if test="onlineflag != null">
        #{onlineflag,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WTicketExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 CST 2017.
    -->
    select count(*) from W_Ticket
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WTicket">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 CST 2017.
    -->
    update W_Ticket
    <set>
      <if test="departmentid != null">
        DepartmentID = #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="ticketname != null">
        TicketName = #{ticketname,jdbcType=NVARCHAR},
      </if>
      <if test="background != null">
        Background = #{background,jdbcType=VARCHAR},
      </if>
      <if test="parvalue != null">
        Parvalue = #{parvalue,jdbcType=INTEGER},
      </if>
      <if test="minconsumption != null">
        MinConsumption = #{minconsumption,jdbcType=INTEGER},
      </if>
      <if test="parvip != null">
        ParVIP = #{parvip,jdbcType=INTEGER},
      </if>
      <if test="pringting != null">
        Pringting = #{pringting,jdbcType=INTEGER},
      </if>
      <if test="sendout != null">
        SendOut = #{sendout,jdbcType=INTEGER},
      </if>
      <if test="used != null">
        Used = #{used,jdbcType=INTEGER},
      </if>
      <if test="begintime != null">
        BeginTime = #{begintime,jdbcType=TIMESTAMP},
      </if>
      <if test="endtime != null">
        EndTime = #{endtime,jdbcType=TIMESTAMP},
      </if>
      <if test="viptype != null">
        Viptype = #{viptype,jdbcType=VARCHAR},
      </if>
      <if test="goodstype != null">
        GoodsType = #{goodstype,jdbcType=VARCHAR},
      </if>
      <if test="usescene != null">
        UseScene = #{usescene,jdbcType=TINYINT},
      </if>
      <if test="useshop != null">
        UseShop = #{useshop,jdbcType=TINYINT},
      </if>
      <if test="goodsid != null">
        GoodsID = #{goodsid,jdbcType=VARCHAR},
      </if>
      <if test="viewlogo != null">
        ViewLogo = #{viewlogo,jdbcType=TINYINT},
      </if>
      <if test="useurl != null">
        UseUrl = #{useurl,jdbcType=VARCHAR},
      </if>
      <if test="memo != null">
        Memo = #{memo,jdbcType=NVARCHAR},
      </if>
      <if test="paruse != null">
        ParUse = #{paruse,jdbcType=BIT},
      </if>
      <if test="usedflag != null">
        UsedFlag = #{usedflag,jdbcType=BIT},
      </if>
      <if test="created != null">
        Created = #{created,jdbcType=TIMESTAMP},
      </if>
      <if test="creater != null">
        Creater = #{creater,jdbcType=VARCHAR},
      </if>
      <if test="tickettype != null">
        TicketType = #{tickettype,jdbcType=TINYINT},
      </if>
      <if test="usetype != null">
        UseType = #{usetype,jdbcType=TINYINT},
      </if>
      <if test="ticketno != null">
        TicketNo = #{ticketno,jdbcType=VARCHAR},
      </if>
      <if test="hint != null">
        Hint = #{hint,jdbcType=NVARCHAR},
      </if>
      <if test="color != null">
        Color = #{color,jdbcType=VARCHAR},
      </if>
      <if test="cover != null">
        Cover = #{cover,jdbcType=VARCHAR},
      </if>
      <if test="sendflag != null">
        SendFlag = #{sendflag,jdbcType=TINYINT},
      </if>
      <if test="exchangepoint != null">
        ExchangePoint = #{exchangepoint,jdbcType=DECIMAL},
      </if>
      <if test="buyprice != null">
        BuyPrice = #{buyprice,jdbcType=DECIMAL},
      </if>
      <if test="effectiveday != null">
        EffectiveDay = #{effectiveday,jdbcType=INTEGER},
      </if>
      <if test="onlineflag != null">
        OnlineFlag = #{onlineflag,jdbcType=TINYINT},
      </if>
    </set>
    where TicketID = #{ticketid,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WTicket">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Dec 14 15:34:47 CST 2017.
    -->
    update W_Ticket
    set DepartmentID = #{departmentid,jdbcType=VARCHAR},
      TicketName = #{ticketname,jdbcType=NVARCHAR},
      Background = #{background,jdbcType=VARCHAR},
      Parvalue = #{parvalue,jdbcType=INTEGER},
      MinConsumption = #{minconsumption,jdbcType=INTEGER},
      ParVIP = #{parvip,jdbcType=INTEGER},
      Pringting = #{pringting,jdbcType=INTEGER},
      SendOut = #{sendout,jdbcType=INTEGER},
      Used = #{used,jdbcType=INTEGER},
      BeginTime = #{begintime,jdbcType=TIMESTAMP},
      EndTime = #{endtime,jdbcType=TIMESTAMP},
      Viptype = #{viptype,jdbcType=VARCHAR},
      GoodsType = #{goodstype,jdbcType=VARCHAR},
      UseScene = #{usescene,jdbcType=TINYINT},
      UseShop = #{useshop,jdbcType=TINYINT},
      GoodsID = #{goodsid,jdbcType=VARCHAR},
      ViewLogo = #{viewlogo,jdbcType=TINYINT},
      UseUrl = #{useurl,jdbcType=VARCHAR},
      Memo = #{memo,jdbcType=NVARCHAR},
      ParUse = #{paruse,jdbcType=BIT},
      UsedFlag = #{usedflag,jdbcType=BIT},
      Created = #{created,jdbcType=TIMESTAMP},
      Creater = #{creater,jdbcType=VARCHAR},
      TicketType = #{tickettype,jdbcType=TINYINT},
      UseType = #{usetype,jdbcType=TINYINT},
      TicketNo = #{ticketno,jdbcType=VARCHAR},
      Hint = #{hint,jdbcType=NVARCHAR},
      Color = #{color,jdbcType=VARCHAR},
      Cover = #{cover,jdbcType=VARCHAR},
      SendFlag = #{sendflag,jdbcType=TINYINT},
      ExchangePoint = #{exchangepoint,jdbcType=DECIMAL},
      BuyPrice = #{buyprice,jdbcType=DECIMAL},
      EffectiveDay = #{effectiveday,jdbcType=INTEGER},
      OnlineFlag = #{onlineflag,jdbcType=TINYINT}
    where TicketID = #{ticketid,jdbcType=BIGINT}
  </update>

	<!-- 优惠券列表 -->
	<select id="wTicketlist" resultType="java.util.LinkedHashMap">		
		select
		a.TicketID,a.DepartmentID,a.TicketName,a.Parvalue,a.MinConsumption,a.ParVIP,
		a.Pringting,a.SendOut,a.Used,a.BeginTime,a.EndTime,a.Viptype,a.GoodsType,
		a.UsedFlag,case a.TicketType when 1 then '领用' when 2 then '赠送' when 3
		then '购买' when 4 then '兑换' end as TicketType,
		case a.UseType when 0 then '否' else '是'
		end as UseType,a.TicketType as
		TicketTypeID,a.UseType as
		UseTypeID,a.Created,a.Creater,b.Department,#{status} as status
		from W_Ticket a left join
		Department b
		on a.departmentid=b.departmentid
		where 1=1
		<if test="departmentid != '' and departmentid != null ">
			a.DepartmentID=#{ departmentid }
		</if>
		<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>
		<if test="tickettype != '' and tickettype != null ">
			and a.TicketType=#{ tickettype }
		</if>
		order by BeginTime desc
	</select>

	<!-- -->
	<select id="getTicketvalue" resultType="java.util.LinkedHashMap">
		select
		wv.TicketID,w.Parvalue,wv.Vipid,wv.TicketNo
		from W_VipTicket as wv
		inner join W_Ticket as w on wv.TicketID=w.TicketID
		where wv.Status=1
		and wv.EShopOrderID=#{eshoporderid,jdbcType=VARCHAR}
	</select>

	<!-- 优惠券管理 -->
	<select id="sendcoupon" resultType="java.util.LinkedHashMap">
		select
		TicketID,DepartmentID,TicketName,Parvalue,MinConsumption,ParVIP,Pringting,SendOut,Used,
		CONVERT(varchar(16),BeginTime,20) as
		BeginTime,CONVERT(varchar(16),EndTime,20) as EndTime,Memo,
		(case when
		GETDATE() &lt; EndTime then 0 else 1 end) as
		Flag
		from
		W_Ticket
		where TicketType != 1 and Pringting &gt; SendOut and
		(DepartmentID='' or
		DepartmentID is null or
		DepartmentID=#{departmentid,jdbcType=VARCHAR})
	</select>

	<!-- 会员优惠券数 -->
	<select id="usedcoupon" resultType="java.util.LinkedHashMap">
		select
		a.TicketID,isnull(b.num,0) as num
		from W_Ticket as a
		left join (select
		TicketID,COUNT(TicketNo) as num
		from W_VipTicket
		where Status=0 and
		Vipid=(select top 1 Vipid from VIP where
		MobilePhone=#{mobilephone,jdbcType=VARCHAR} order by DefaultLoginFlag
		desc)
		group by TicketID) as b on a.TicketID=b.TicketID
		where TicketType
		!= 1 and Pringting&gt;SendOut
		and (DepartmentID='' or DepartmentID is
		null or DepartmentID=#{departmentid,jdbcType=VARCHAR})
	</select>

	<!-- 优惠券使用记录 -->
	<select id="couponrecord" resultType="java.util.LinkedHashMap">
		select a.*,b.Parvalue
		from
		W_VipTicket as a
		left join W_Ticket as b on a.TicketID=b.TicketID
		where
		a.Status=1 and a.TicketID=#{ticketid,jdbcType=VARCHAR} and
		a.Vipid=(select top 1 Vipid from VIP where
		MobilePhone=#{mobilephone,jdbcType=VARCHAR} order by DefaultLoginFlag
		desc)
		order by a.UseTime desc
	</select>

	<!-- 优惠券使用记录(所有会员) -->
	<select id="ticketrecord" resultType="java.util.LinkedHashMap">
		select
		t.TicketNo,t.Vipid,t.EmployeeID,t.TicketID,CONVERT(varchar(19),t.GetTime,20)
		as GetTime,
		CONVERT(varchar(19),t.UseTime,20) as
		UseTime,t.EShopOrderID,t.TicketStyle,t.Status,v.MobilePhone,a.Parvalue
		from W_VipTicket as t
		left join W_Ticket as a on a.TicketID=t.TicketID
		inner join VIP as v on t.Vipid=v.VIPID
		where t.Status=1 and
		a.TicketType!=1
		and (a.DepartmentID='' or a.DepartmentID is null or
		a.DepartmentID=#{departmentid,jdbcType=VARCHAR})
	</select>

	<!-- 下拉选择优惠券 -->
	<select id="dropdownticket" resultType="java.util.LinkedHashMap">
		select
		t.TicketID,t.TicketName
		from W_Ticket as t
		where t.TicketType=2 and
		EndTime&gt;getdate()
	</select>

	<update id="updateBybaison" parameterType="com.fuxi.ws.data.entity.WTicket">
		update W_Ticket
		set
		TicketName = #{ticketname,jdbcType=NVARCHAR},
		Parvalue =
		#{parvalue,jdbcType=INTEGER},
		BeginTime =
		#{begintime,jdbcType=TIMESTAMP},
		EndTime =
		#{endtime,jdbcType=TIMESTAMP},
		ParUse = #{paruse,jdbcType=BIT},
		Memo =
		#{memo,jdbcType=NVARCHAR},
		TicketNo = #{ticketno,jdbcType=VARCHAR}
		where TicketNo = #{ticketno,jdbcType=VARCHAR}
	</update>
	
	<!-- 读取商品列表信息 -->
	<select id="goodsList" resultType="java.util.LinkedHashMap">
		SELECT a.GoodsID,a.ImgPath,a.Code,a.GoodName,a.Price,a.NoUseTicket,
		(select sum(t.Quantity) from W_Store t with(nolock) where t.goodsid=a.Goodsid) TotalQty
		FROM W_Goods AS a with(nolock) 
		<if test="conditions != null and conditions != ''">
			where ${conditions}
		</if>
		order by a.Created desc
	</select>
	
	<select id="getMaxTicketid" resultType="java.lang.Long">
		SELECT max(ticketid) ticketid
		FROM W_Ticket 
	</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>
	
	<select id="couponlist" resultType="java.util.LinkedHashMap">
		select *,CONVERT(varchar(10),tb.BeginTime,102) as BeginData,CONVERT(varchar(10),tb.EndTime,102) as EndData 
		from (
			select a.* 
			from W_Ticket as a (nolock) 
			where a.TicketType=2 and a.EndTime&gt;=GETDATE() and (a.Pringting-a.SendOut)&gt;0 and a.UseShop=1 and SendFlag=1 
			union all 
			select a.* 
			from W_Ticket as a (nolock) 
			left join W_TicketDept as b (nolock) on a.TicketID=b.TicketID
			where a.TicketType=2 and a.EndTime&gt;=GETDATE() and (a.Pringting-a.SendOut)&gt;0 and a.UseShop=2 and SendFlag=1 and b.DepartmentID=#{departmentid,jdbcType=VARCHAR} 
		) as tb 
		order by tb.Created desc
	</select>
	
	 <select id="addcouponrecord" resultType="java.util.LinkedHashMap">
	select a.TicketID,a.TICKETNO,vip.VIP,vip.MobilePhone,CONVERT(varchar(10),a.GetTime,102) as GetTime,CONVERT(varchar(10),a.UseTime,102) as UseTime,a.BeginTime,a.EndTime,
	case when
	GETDATE()>a.EndTime and GETDATE()>a.BeginTime and a.Status=0
	then '已过期'
	when a.Status=1 then '已使用'
	when a.Status=0 then
	'未使用' End as StatusType
	from W_VipTicket a inner join VIP vip
	on a.Vipid=vip.VIPID
		<if test="conditions != null and conditions != ''">
			where ${conditions}
		</if>
	</select>
	
</mapper>