<?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.WVipsummaryMapper" >
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WVipsummary" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 07 18:43:51 CST 2019.
    -->
    <id column="CurrentDate" property="currentdate" jdbcType="INTEGER" />
    <result column="VserSource" property="vsersource" jdbcType="VARCHAR" />
    <result column="NewVipNum" property="newvipnum" jdbcType="INTEGER" />
    <result column="CancelVipNum" property="cancelvipnum" jdbcType="INTEGER" />
    <result column="CumulateVipNum" property="cumulatevipnum" 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 Mon Jan 07 18:43:51 CST 2019.
    -->
    <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 Mon Jan 07 18:43:51 CST 2019.
    -->
    CurrentDate, VserSource, NewVipNum, CancelVipNum, CumulateVipNum
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.fuxi.ws.data.entity.WVipsummaryExample" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 07 18:43:51 CST 2019.
    -->
    select
    <if test="distinct" >
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_VipSummary
    <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="java.lang.Integer" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 07 18:43:51 CST 2019.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_VipSummary
    where CurrentDate = #{currentdate,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 Mon Jan 07 18:43:51 CST 2019.
    -->
    delete from W_VipSummary
    where CurrentDate = #{currentdate,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WVipsummary" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 07 18:43:51 CST 2019.
    -->
    insert into W_VipSummary (CurrentDate, VserSource, NewVipNum, 
      CancelVipNum, CumulateVipNum)
    values (#{currentdate,jdbcType=INTEGER}, #{vsersource,jdbcType=VARCHAR}, #{newvipnum,jdbcType=INTEGER}, 
      #{cancelvipnum,jdbcType=INTEGER}, #{cumulatevipnum,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WVipsummary" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 07 18:43:51 CST 2019.
    -->
    insert into W_VipSummary
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="currentdate != null" >
        CurrentDate,
      </if>
      <if test="vsersource != null" >
        VserSource,
      </if>
      <if test="newvipnum != null" >
        NewVipNum,
      </if>
      <if test="cancelvipnum != null" >
        CancelVipNum,
      </if>
      <if test="cumulatevipnum != null" >
        CumulateVipNum,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="currentdate != null" >
        #{currentdate,jdbcType=INTEGER},
      </if>
      <if test="vsersource != null" >
        #{vsersource,jdbcType=VARCHAR},
      </if>
      <if test="newvipnum != null" >
        #{newvipnum,jdbcType=INTEGER},
      </if>
      <if test="cancelvipnum != null" >
        #{cancelvipnum,jdbcType=INTEGER},
      </if>
      <if test="cumulatevipnum != null" >
        #{cumulatevipnum,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WVipsummaryExample" resultType="java.lang.Integer" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 07 18:43:51 CST 2019.
    -->
    select count(*) from W_VipSummary
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WVipsummary" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 07 18:43:51 CST 2019.
    -->
    update W_VipSummary
    <set >
      <if test="vsersource != null" >
        VserSource = #{vsersource,jdbcType=VARCHAR},
      </if>
      <if test="newvipnum != null" >
        NewVipNum = #{newvipnum,jdbcType=INTEGER},
      </if>
      <if test="cancelvipnum != null" >
        CancelVipNum = #{cancelvipnum,jdbcType=INTEGER},
      </if>
      <if test="cumulatevipnum != null" >
        CumulateVipNum = #{cumulatevipnum,jdbcType=INTEGER},
      </if>
    </set>
    where CurrentDate = #{currentdate,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WVipsummary" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 07 18:43:51 CST 2019.
    -->
    update W_VipSummary
    set VserSource = #{vsersource,jdbcType=VARCHAR},
      NewVipNum = #{newvipnum,jdbcType=INTEGER},
      CancelVipNum = #{cancelvipnum,jdbcType=INTEGER},
      CumulateVipNum = #{cumulatevipnum,jdbcType=INTEGER}
    where CurrentDate = #{currentdate,jdbcType=INTEGER}
  </update>
  
  <select id="selectByCurrentDateKey" resultType="com.fuxi.ws.data.entity.WVipsummary" parameterType="java.util.Map" >
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Mon Jan 07 18:43:51 CST 2019.
    -->
   select ISNULL(SUM(NewVipNum),0) NewVipNum,ISNULL(SUM(CancelVipNum),0) CancelVipNum,ISNULL((select top 1 CumulateVipNum  from W_VipSummary where CurrentDate&lt;=#{intnext} order by CurrentDate desc, CumulateVipNum desc) ,0) CumulateVipNum from W_VipSummary
    where CurrentDate between  #{intlast}  and  #{intnext} 
  </select>
  
  <select id="selectWVipsummaryList" resultType="java.util.LinkedHashMap" parameterType="java.util.Map" >
	  select a.datatime,ISNULL(sum(b.NewVipNum),0) NewVipNum, ISNULL(sum(b.CumulateVipNum),0) CumulateVipNum,ISNULL(sum(b.CancelVipNum),0) CancelVipNum from 
	(SELECT convert(char(10), DATEADD(dd,number,#{intlast}),112) AS datatime
	FROM master..spt_values WHERE type = 'p'
	AND DATEDIFF(MI,DATEADD(dd,number, #{intlast}),#{intnext} ) > 0) a left join w_vipSummary as b on a.datatime=b.CurrentDate
	group by  a.datatime  order by a.datatime
  </select>
</mapper>