<?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.WdOrdersMapper">
  <resultMap id="BaseResultMap" type="com.fuxi.ws.data.entity.WdOrders">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Aug 18 16:02:07 CST 2016.
    -->
    <id column="OrderID" jdbcType="BIGINT" property="orderid" />
    <result column="SourceOrderID" jdbcType="VARCHAR" property="sourceorderid" />
    <result column="ReturnID" jdbcType="VARCHAR" property="returnid" />
    <result column="Source" jdbcType="TINYINT" property="source" />
    <result column="OrderType" jdbcType="TINYINT" property="ordertype" />
    <result column="Vipid" jdbcType="VARCHAR" property="vipid" />
    <result column="wxId" jdbcType="NVARCHAR" property="wxid" />
    <result column="Date" jdbcType="TIMESTAMP" property="date" />
    <result column="pay_time" jdbcType="TIMESTAMP" property="payTime" />
    <result column="PaymentType" jdbcType="TINYINT" property="paymenttype" />
    <result column="QuantitySum" jdbcType="INTEGER" property="quantitysum" />
    <result column="AmountSum" jdbcType="DECIMAL" property="amountsum" />
    <result column="Payment" jdbcType="DECIMAL" property="payment" />
    <result column="CashPaper" jdbcType="DECIMAL" property="cashpaper" />
    <result column="DepositAmount" jdbcType="DECIMAL" property="depositamount" />
    <result column="ExchangedPoint" jdbcType="DECIMAL" property="exchangedpoint" />
    <result column="Payed" jdbcType="DECIMAL" property="payed" />
    <result column="AllotSales" jdbcType="DECIMAL" property="allotsales" />
    <result column="sales_time" jdbcType="TIMESTAMP" property="salesTime" />
    <result column="DeliveryType" jdbcType="VARCHAR" property="deliverytype" />
    <result column="buyer_province" jdbcType="VARCHAR" property="buyerProvince" />
    <result column="buyer_city" jdbcType="VARCHAR" property="buyerCity" />
    <result column="District" jdbcType="VARCHAR" property="district" />
    <result column="Address" jdbcType="VARCHAR" property="address" />
    
    <result column="departmentid" jdbcType="VARCHAR" property="departmentid" />
    <result column="DistributeID" jdbcType="VARCHAR" property="distributeid" />
    <result column="DistrictName" jdbcType="VARCHAR" property="districtname" />
    <result column="Department" jdbcType="VARCHAR" property="department" />
    <result column="DistributeName" jdbcType="NVARCHAR" property="distributename" />
    <result column="VipName" jdbcType="VARCHAR" property="vipname" />
    <result column="VipPhoto" jdbcType="VARCHAR" property="vipphoto" />
    <result column="Status" jdbcType="TINYINT" property="status" />
  </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 Aug 18 16:02:07 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 Thu Aug 18 16:02:07 CST 2016.
    -->
    OrderID, SourceOrderID, ReturnID, Source, OrderType, Vipid, wxId, Date, pay_time, 
    PaymentType, QuantitySum, AmountSum, Payment, CashPaper, DepositAmount, ExchangedPoint, 
    Payed, AllotSales, sales_time, DeliveryType, buyer_province, buyer_city, District, 
    Address, departmentid, DistributeID, DistrictName, Department, DistributeName, 
    VipName, VipPhoto, Status
  </sql>
  <select id="selectByExample" parameterType="com.fuxi.ws.data.entity.WdOrdersExample" resultMap="BaseResultMap">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Aug 18 16:02:07 CST 2016.
    -->
    select
    <if test="distinct">
      distinct
    </if>
    'false' as QUERYID,
    <include refid="Base_Column_List" />
    from WD_Orders
    <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 Aug 18 16:02:07 CST 2016.
    -->
    select 
    <include refid="Base_Column_List" />
    from WD_Orders
    where OrderID = #{orderid,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 Aug 18 16:02:07 CST 2016.
    -->
    delete from WD_Orders
    where OrderID = #{orderid,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.fuxi.ws.data.entity.WdOrders">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Aug 18 16:02:07 CST 2016.
    -->
    insert into WD_Orders (OrderID, SourceOrderID, ReturnID, 
      Source, OrderType, Vipid, 
      wxId, Date, pay_time, 
      PaymentType, QuantitySum, AmountSum, 
      Payment, CashPaper, DepositAmount, 
      ExchangedPoint, Payed, AllotSales, 
      sales_time, DeliveryType, buyer_province, 
      buyer_city, District, Address, 
       departmentid, DistributeID, 
      DistrictName, Department, DistributeName, 
      VipName, VipPhoto, Status
      )
    values (#{orderid,jdbcType=BIGINT}, #{sourceorderid,jdbcType=VARCHAR}, #{returnid,jdbcType=VARCHAR}, 
      #{source,jdbcType=TINYINT}, #{ordertype,jdbcType=TINYINT}, #{vipid,jdbcType=VARCHAR}, 
      #{wxid,jdbcType=NVARCHAR}, #{date,jdbcType=TIMESTAMP}, #{payTime,jdbcType=TIMESTAMP}, 
      #{paymenttype,jdbcType=TINYINT}, #{quantitysum,jdbcType=INTEGER}, #{amountsum,jdbcType=DECIMAL}, 
      #{payment,jdbcType=DECIMAL}, #{cashpaper,jdbcType=DECIMAL}, #{depositamount,jdbcType=DECIMAL}, 
      #{exchangedpoint,jdbcType=DECIMAL}, #{payed,jdbcType=DECIMAL}, #{allotsales,jdbcType=DECIMAL}, 
      #{salesTime,jdbcType=TIMESTAMP}, #{deliverytype,jdbcType=VARCHAR}, #{buyerProvince,jdbcType=VARCHAR}, 
      #{buyerCity,jdbcType=VARCHAR}, #{district,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, 
     	#{departmentid,jdbcType=VARCHAR}, #{distributeid,jdbcType=VARCHAR}, 
      #{districtname,jdbcType=VARCHAR}, #{department,jdbcType=VARCHAR}, #{distributename,jdbcType=NVARCHAR}, 
      #{vipname,jdbcType=VARCHAR}, #{vipphoto,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.fuxi.ws.data.entity.WdOrders">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Aug 18 16:02:07 CST 2016.
    -->
    insert into WD_Orders
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="orderid != null">
        OrderID,
      </if>
      <if test="sourceorderid != null">
        SourceOrderID,
      </if>
      <if test="returnid != null">
        ReturnID,
      </if>
      <if test="source != null">
        Source,
      </if>
      <if test="ordertype != null">
        OrderType,
      </if>
      <if test="vipid != null">
        Vipid,
      </if>
      <if test="wxid != null">
        wxId,
      </if>
      <if test="date != null">
        Date,
      </if>
      <if test="payTime != null">
        pay_time,
      </if>
      <if test="paymenttype != null">
        PaymentType,
      </if>
      <if test="quantitysum != null">
        QuantitySum,
      </if>
      <if test="amountsum != null">
        AmountSum,
      </if>
      <if test="payment != null">
        Payment,
      </if>
      <if test="cashpaper != null">
        CashPaper,
      </if>
      <if test="depositamount != null">
        DepositAmount,
      </if>
      <if test="exchangedpoint != null">
        ExchangedPoint,
      </if>
      <if test="payed != null">
        Payed,
      </if>
      <if test="allotsales != null">
        AllotSales,
      </if>
      <if test="salesTime != null">
        sales_time,
      </if>
      <if test="deliverytype != null">
        DeliveryType,
      </if>
      <if test="buyerProvince != null">
        buyer_province,
      </if>
      <if test="buyerCity != null">
        buyer_city,
      </if>
      <if test="district != null">
        District,
      </if>
      <if test="address != null">
        Address,
      </if>
     
      <if test="departmentid != null">
        departmentid,
      </if>
      <if test="distributeid != null">
        DistributeID,
      </if>
      <if test="districtname != null">
        DistrictName,
      </if>
      <if test="department != null">
        Department,
      </if>
      <if test="distributename != null">
        DistributeName,
      </if>
      <if test="vipname != null">
        VipName,
      </if>
      <if test="vipphoto != null">
        VipPhoto,
      </if>
      <if test="status != null">
        Status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="orderid != null">
        #{orderid,jdbcType=BIGINT},
      </if>
      <if test="sourceorderid != null">
        #{sourceorderid,jdbcType=VARCHAR},
      </if>
      <if test="returnid != null">
        #{returnid,jdbcType=VARCHAR},
      </if>
      <if test="source != null">
        #{source,jdbcType=TINYINT},
      </if>
      <if test="ordertype != null">
        #{ordertype,jdbcType=TINYINT},
      </if>
      <if test="vipid != null">
        #{vipid,jdbcType=VARCHAR},
      </if>
      <if test="wxid != null">
        #{wxid,jdbcType=NVARCHAR},
      </if>
      <if test="date != null">
        #{date,jdbcType=TIMESTAMP},
      </if>
      <if test="payTime != null">
        #{payTime,jdbcType=TIMESTAMP},
      </if>
      <if test="paymenttype != null">
        #{paymenttype,jdbcType=TINYINT},
      </if>
      <if test="quantitysum != null">
        #{quantitysum,jdbcType=INTEGER},
      </if>
      <if test="amountsum != null">
        #{amountsum,jdbcType=DECIMAL},
      </if>
      <if test="payment != null">
        #{payment,jdbcType=DECIMAL},
      </if>
      <if test="cashpaper != null">
        #{cashpaper,jdbcType=DECIMAL},
      </if>
      <if test="depositamount != null">
        #{depositamount,jdbcType=DECIMAL},
      </if>
      <if test="exchangedpoint != null">
        #{exchangedpoint,jdbcType=DECIMAL},
      </if>
      <if test="payed != null">
        #{payed,jdbcType=DECIMAL},
      </if>
      <if test="allotsales != null">
        #{allotsales,jdbcType=DECIMAL},
      </if>
      <if test="salesTime != null">
        #{salesTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deliverytype != null">
        #{deliverytype,jdbcType=VARCHAR},
      </if>
      <if test="buyerProvince != null">
        #{buyerProvince,jdbcType=VARCHAR},
      </if>
      <if test="buyerCity != null">
        #{buyerCity,jdbcType=VARCHAR},
      </if>
      <if test="district != null">
        #{district,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="departmentid != null">
        #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="distributeid != null">
        #{distributeid,jdbcType=VARCHAR},
      </if>
      <if test="districtname != null">
        #{districtname,jdbcType=VARCHAR},
      </if>
      <if test="department != null">
        #{department,jdbcType=VARCHAR},
      </if>
      <if test="distributename != null">
        #{distributename,jdbcType=NVARCHAR},
      </if>
      <if test="vipname != null">
        #{vipname,jdbcType=VARCHAR},
      </if>
      <if test="vipphoto != null">
        #{vipphoto,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.fuxi.ws.data.entity.WdOrdersExample" resultType="java.lang.Integer">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Aug 18 16:02:07 CST 2016.
    -->
    select count(*) from WD_Orders
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByPrimaryKeySelective" parameterType="com.fuxi.ws.data.entity.WdOrders">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Aug 18 16:02:07 CST 2016.
    -->
    update WD_Orders
    <set>
      <if test="sourceorderid != null">
        SourceOrderID = #{sourceorderid,jdbcType=VARCHAR},
      </if>
      <if test="returnid != null">
        ReturnID = #{returnid,jdbcType=VARCHAR},
      </if>
      <if test="source != null">
        Source = #{source,jdbcType=TINYINT},
      </if>
      <if test="ordertype != null">
        OrderType = #{ordertype,jdbcType=TINYINT},
      </if>
      <if test="vipid != null">
        Vipid = #{vipid,jdbcType=VARCHAR},
      </if>
      <if test="wxid != null">
        wxId = #{wxid,jdbcType=NVARCHAR},
      </if>
      <if test="date != null">
        Date = #{date,jdbcType=TIMESTAMP},
      </if>
      <if test="payTime != null">
        pay_time = #{payTime,jdbcType=TIMESTAMP},
      </if>
      <if test="paymenttype != null">
        PaymentType = #{paymenttype,jdbcType=TINYINT},
      </if>
      <if test="quantitysum != null">
        QuantitySum = #{quantitysum,jdbcType=INTEGER},
      </if>
      <if test="amountsum != null">
        AmountSum = #{amountsum,jdbcType=DECIMAL},
      </if>
      <if test="payment != null">
        Payment = #{payment,jdbcType=DECIMAL},
      </if>
      <if test="cashpaper != null">
        CashPaper = #{cashpaper,jdbcType=DECIMAL},
      </if>
      <if test="depositamount != null">
        DepositAmount = #{depositamount,jdbcType=DECIMAL},
      </if>
      <if test="exchangedpoint != null">
        ExchangedPoint = #{exchangedpoint,jdbcType=DECIMAL},
      </if>
      <if test="payed != null">
        Payed = #{payed,jdbcType=DECIMAL},
      </if>
      <if test="allotsales != null">
        AllotSales = #{allotsales,jdbcType=DECIMAL},
      </if>
      <if test="salesTime != null">
        sales_time = #{salesTime,jdbcType=TIMESTAMP},
      </if>
      <if test="deliverytype != null">
        DeliveryType = #{deliverytype,jdbcType=VARCHAR},
      </if>
      <if test="buyerProvince != null">
        buyer_province = #{buyerProvince,jdbcType=VARCHAR},
      </if>
      <if test="buyerCity != null">
        buyer_city = #{buyerCity,jdbcType=VARCHAR},
      </if>
      <if test="district != null">
        District = #{district,jdbcType=VARCHAR},
      </if>
      <if test="address != null">
        Address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="departmentid != null">
        departmentid = #{departmentid,jdbcType=VARCHAR},
      </if>
      <if test="distributeid != null">
        DistributeID = #{distributeid,jdbcType=VARCHAR},
      </if>
      <if test="districtname != null">
        DistrictName = #{districtname,jdbcType=VARCHAR},
      </if>
      <if test="department != null">
        Department = #{department,jdbcType=VARCHAR},
      </if>
      <if test="distributename != null">
        DistributeName = #{distributename,jdbcType=NVARCHAR},
      </if>
      <if test="vipname != null">
        VipName = #{vipname,jdbcType=VARCHAR},
      </if>
      <if test="vipphoto != null">
        VipPhoto = #{vipphoto,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        Status = #{status,jdbcType=TINYINT},
      </if>
    </set>
    where OrderID = #{orderid,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.fuxi.ws.data.entity.WdOrders">
    <!--
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
      This element was generated on Thu Aug 18 16:02:07 CST 2016.
    -->
    update WD_Orders
    set SourceOrderID = #{sourceorderid,jdbcType=VARCHAR},
      ReturnID = #{returnid,jdbcType=VARCHAR},
      Source = #{source,jdbcType=TINYINT},
      OrderType = #{ordertype,jdbcType=TINYINT},
      Vipid = #{vipid,jdbcType=VARCHAR},
      wxId = #{wxid,jdbcType=NVARCHAR},
      Date = #{date,jdbcType=TIMESTAMP},
      pay_time = #{payTime,jdbcType=TIMESTAMP},
      PaymentType = #{paymenttype,jdbcType=TINYINT},
      QuantitySum = #{quantitysum,jdbcType=INTEGER},
      AmountSum = #{amountsum,jdbcType=DECIMAL},
      Payment = #{payment,jdbcType=DECIMAL},
      CashPaper = #{cashpaper,jdbcType=DECIMAL},
      DepositAmount = #{depositamount,jdbcType=DECIMAL},
      ExchangedPoint = #{exchangedpoint,jdbcType=DECIMAL},
      Payed = #{payed,jdbcType=DECIMAL},
      AllotSales = #{allotsales,jdbcType=DECIMAL},
      sales_time = #{salesTime,jdbcType=TIMESTAMP},
      DeliveryType = #{deliverytype,jdbcType=VARCHAR},
      buyer_province = #{buyerProvince,jdbcType=VARCHAR},
      buyer_city = #{buyerCity,jdbcType=VARCHAR},
      District = #{district,jdbcType=VARCHAR},
      Address = #{address,jdbcType=VARCHAR},
      departmentid = #{departmentid,jdbcType=VARCHAR},
      DistributeID = #{distributeid,jdbcType=VARCHAR},
      DistrictName = #{districtname,jdbcType=VARCHAR},
      Department = #{department,jdbcType=VARCHAR},
      DistributeName = #{distributename,jdbcType=NVARCHAR},
      VipName = #{vipname,jdbcType=VARCHAR},
      VipPhoto = #{vipphoto,jdbcType=VARCHAR},
      Status = #{status,jdbcType=TINYINT}
    where OrderID = #{orderid,jdbcType=BIGINT}
  </update>
  
  
  <select id="vipReturnSum" resultType="java.util.LinkedHashMap">
	select t.Returnprice,t.Times 
		from(
		select round(sum(a.AllotSales),2)*-1 returnprice,count(a.date) Times			
		from WD_Orders a
		where a.VIPID=#{
		vipid } and a.OrderType=2 ) t
	</select>
</mapper>