<?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.WReportorderMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WReportorder">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 CST 2016.
    -->
    <id column="ReportDate" jdbcType="TIMESTAMP" property="reportdate" />
    <result column="AccessNum" jdbcType="INTEGER" property="accessnum" />
    <result column="PurchaserNum" jdbcType="INTEGER" property="purchasernum" />
    <result column="OrderNum" jdbcType="INTEGER" property="ordernum" />
    <result column="OrderMoney" jdbcType="DECIMAL" property="ordermoney" />
    <result column="PayerNum" jdbcType="INTEGER" property="payernum" />
    <result column="PayNum" jdbcType="INTEGER" property="paynum" />
    <result column="PayMoney" jdbcType="DECIMAL" property="paymoney" />
    <result column="SaleNum" jdbcType="INTEGER" property="salenum" />
    <result column="AverageBuy" jdbcType="DECIMAL" property="averagebuy" />
    <result column="OrderOfPurchaser" jdbcType="DECIMAL" property="orderofpurchaser" />
    <result column="PayOfOrder" jdbcType="DECIMAL" property="payoforder" />
    <result column="PayOfAccess" jdbcType="DECIMAL" property="payofaccess" />
    <result column="NewVipNum" jdbcType="INTEGER" property="newvipnum" />
  </resultMap>
  <sql id="Example_Where_Clause">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 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 Fri Jul 15 16:07:59 CST 2016.
    -->
    ReportDate, AccessNum, PurchaserNum, OrderNum, OrderMoney, PayerNum, PayNum, PayMoney, 
    SaleNum, AverageBuy, OrderOfPurchaser, PayOfOrder, PayOfAccess, NewVipNum
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WReportorderExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 CST 2016.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from W_ReportOrder
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null">
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" parameterType="java.util.Date" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 CST 2016.
    -->
    select 
    <include refid="Base_Column_List" />
    from W_ReportOrder
    where ReportDate = #{reportdate,jdbcType=TIMESTAMP}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.util.Date">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 CST 2016.
    -->
    delete from W_ReportOrder
    where ReportDate = #{reportdate,jdbcType=TIMESTAMP}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WReportorder">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 CST 2016.
    -->
    insert into W_ReportOrder (ReportDate, AccessNum, PurchaserNum, 
      OrderNum, OrderMoney, PayerNum, 
      PayNum, PayMoney, SaleNum, 
      AverageBuy, OrderOfPurchaser, PayOfOrder, 
      PayOfAccess, NewVipNum)
    values (#{reportdate,jdbcType=TIMESTAMP}, #{accessnum,jdbcType=INTEGER}, #{purchasernum,jdbcType=INTEGER}, 
      #{ordernum,jdbcType=INTEGER}, #{ordermoney,jdbcType=DECIMAL}, #{payernum,jdbcType=INTEGER}, 
      #{paynum,jdbcType=INTEGER}, #{paymoney,jdbcType=DECIMAL}, #{salenum,jdbcType=INTEGER}, 
      #{averagebuy,jdbcType=DECIMAL}, #{orderofpurchaser,jdbcType=DECIMAL}, #{payoforder,jdbcType=DECIMAL}, 
      #{payofaccess,jdbcType=DECIMAL}, #{newvipnum,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WReportorder">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 CST 2016.
    -->
    insert into W_ReportOrder
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="reportdate != null">
        ReportDate,
      </if>
      <if test="accessnum != null">
        AccessNum,
      </if>
      <if test="purchasernum != null">
        PurchaserNum,
      </if>
      <if test="ordernum != null">
        OrderNum,
      </if>
      <if test="ordermoney != null">
        OrderMoney,
      </if>
      <if test="payernum != null">
        PayerNum,
      </if>
      <if test="paynum != null">
        PayNum,
      </if>
      <if test="paymoney != null">
        PayMoney,
      </if>
      <if test="salenum != null">
        SaleNum,
      </if>
      <if test="averagebuy != null">
        AverageBuy,
      </if>
      <if test="orderofpurchaser != null">
        OrderOfPurchaser,
      </if>
      <if test="payoforder != null">
        PayOfOrder,
      </if>
      <if test="payofaccess != null">
        PayOfAccess,
      </if>
      <if test="newvipnum != null">
        NewVipNum,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="reportdate != null">
        #{reportdate,jdbcType=TIMESTAMP},
      </if>
      <if test="accessnum != null">
        #{accessnum,jdbcType=INTEGER},
      </if>
      <if test="purchasernum != null">
        #{purchasernum,jdbcType=INTEGER},
      </if>
      <if test="ordernum != null">
        #{ordernum,jdbcType=INTEGER},
      </if>
      <if test="ordermoney != null">
        #{ordermoney,jdbcType=DECIMAL},
      </if>
      <if test="payernum != null">
        #{payernum,jdbcType=INTEGER},
      </if>
      <if test="paynum != null">
        #{paynum,jdbcType=INTEGER},
      </if>
      <if test="paymoney != null">
        #{paymoney,jdbcType=DECIMAL},
      </if>
      <if test="salenum != null">
        #{salenum,jdbcType=INTEGER},
      </if>
      <if test="averagebuy != null">
        #{averagebuy,jdbcType=DECIMAL},
      </if>
      <if test="orderofpurchaser != null">
        #{orderofpurchaser,jdbcType=DECIMAL},
      </if>
      <if test="payoforder != null">
        #{payoforder,jdbcType=DECIMAL},
      </if>
      <if test="payofaccess != null">
        #{payofaccess,jdbcType=DECIMAL},
      </if>
      <if test="newvipnum != null">
        #{newvipnum,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WReportorderExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 CST 2016.
    -->
    select count(*) from W_ReportOrder
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WReportorder">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 CST 2016.
    -->
    update W_ReportOrder
    <set>
      <if test="accessnum != null">
        AccessNum = #{accessnum,jdbcType=INTEGER},
      </if>
      <if test="purchasernum != null">
        PurchaserNum = #{purchasernum,jdbcType=INTEGER},
      </if>
      <if test="ordernum != null">
        OrderNum = #{ordernum,jdbcType=INTEGER},
      </if>
      <if test="ordermoney != null">
        OrderMoney = #{ordermoney,jdbcType=DECIMAL},
      </if>
      <if test="payernum != null">
        PayerNum = #{payernum,jdbcType=INTEGER},
      </if>
      <if test="paynum != null">
        PayNum = #{paynum,jdbcType=INTEGER},
      </if>
      <if test="paymoney != null">
        PayMoney = #{paymoney,jdbcType=DECIMAL},
      </if>
      <if test="salenum != null">
        SaleNum = #{salenum,jdbcType=INTEGER},
      </if>
      <if test="averagebuy != null">
        AverageBuy = #{averagebuy,jdbcType=DECIMAL},
      </if>
      <if test="orderofpurchaser != null">
        OrderOfPurchaser = #{orderofpurchaser,jdbcType=DECIMAL},
      </if>
      <if test="payoforder != null">
        PayOfOrder = #{payoforder,jdbcType=DECIMAL},
      </if>
      <if test="payofaccess != null">
        PayOfAccess = #{payofaccess,jdbcType=DECIMAL},
      </if>
      <if test="newvipnum != null">
        NewVipNum = #{newvipnum,jdbcType=INTEGER},
      </if>
    </set>
    where ReportDate = #{reportdate,jdbcType=TIMESTAMP}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WReportorder">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Fri Jul 15 16:07:59 CST 2016.
    -->
    update W_ReportOrder
    set AccessNum = #{accessnum,jdbcType=INTEGER},
      PurchaserNum = #{purchasernum,jdbcType=INTEGER},
      OrderNum = #{ordernum,jdbcType=INTEGER},
      OrderMoney = #{ordermoney,jdbcType=DECIMAL},
      PayerNum = #{payernum,jdbcType=INTEGER},
      PayNum = #{paynum,jdbcType=INTEGER},
      PayMoney = #{paymoney,jdbcType=DECIMAL},
      SaleNum = #{salenum,jdbcType=INTEGER},
      AverageBuy = #{averagebuy,jdbcType=DECIMAL},
      OrderOfPurchaser = #{orderofpurchaser,jdbcType=DECIMAL},
      PayOfOrder = #{payoforder,jdbcType=DECIMAL},
      PayOfAccess = #{payofaccess,jdbcType=DECIMAL},
      NewVipNum = #{newvipnum,jdbcType=INTEGER}
    where ReportDate = #{reportdate,jdbcType=TIMESTAMP}
  </update>

	<!-- 订单统计数据 -->
	<select id="getData" resultType="java.util.HashMap">
		select SUM(AccessNum)
		uvCounts,SUM(PurchaserNum)
		order_pers,SUM(OrderNum)
		orders,SUM(OrderMoney) order_amt,SUM(PayerNum)
		pay_pers,SUM(PayNum)
		pay_orders,
		SUM(PayMoney) pay_amt,SUM(SaleNum)
		sellGoods from
		W_ReportOrder where ReportDate
		between
		#{d1}
		and #{d2}
	</select>

	<!-- 数据图表 -->
	<select id="getCharts" resultType="java.util.LinkedHashMap">
		select
		CONVERT(varchar(10),ReportDate,121) ReportDate,
		OrderNum,PayNum,PayMoney,
		(case AccessNum when 0 then 0 else
		PurchaserNum/AccessNum end)
		order_conversion_chart,
		(case PurchaserNum
		when 0 then 0 else PayerNum/PurchaserNum end)
		pay_conversion_chart,
		(case AccessNum when 0 then 0 else PayerNum/AccessNum end)
		store_conversion_chart
		from W_ReportOrder where ReportDate
		between
		#{d1}
		and #{d2} order by ReportDate
	</select>
</mapper>