<?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.xxfc.platform.order.mapper.OrderTourReceivedStatisticsMapper">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xxfc.platform.order.entity.OrderTourReceivedStatistics" id="orderTourReceivedStatisticsMap">
        <result property="id" column="id"/>
        <result property="year" column="year"/>
        <result property="month" column="month"/>
        <result property="date" column="date"/>
        <result property="weekOfYear" column="week_of_year"/>
        <result property="companyName" column="company_name"/>
        <result property="extraAmount" column="extra_amount"/>
        <result property="lateFeeAmount" column="late_fee_amount"/>
        <result property="orderRefundAmount" column="order_refund_amount"/>
        <result property="totalAmount" column="total_amount"/>
        <result property="totalQuantity" column="total_quantity"/>
        <result property="hasPay" column="has_pay"/>
        <result property="orderOrigin" column="order_origin"/>
        <result property="payWay" column="pay_way"/>
        <result property="companyId" column="company_id"/>
        <result property="crtTime" column="crt_time"/>
    </resultMap>

    <select id="selectOrderTourReceivedStatisticsGroupByDate" resultType="com.xxfc.platform.order.entity.OrderTourReceivedStatistics">
         select `year`,`date`,IFNULL(sum(`total_amount`-`order_refund_amount`),0) as `totalAmount`,IFNULL(sum(`total_quantity`),0) as `totalQuantity` from  `order_tour_received_statistics` where 1=1
        <if test="orderState!=null">
            and `has_pay`=#{orderState}
        </if>
        <if test="orderOrigin!=null">
            and `order_origin`=#{orderOrigin}
        </if>
        <if test="payWay!=null">
            and `pay_way`=#{payWay}
        </if>
        <if test="startDate!=null and endDate!=null">
            and `date` between #{startDate} and #{endDate}
        </if>
        <if test="startDate!=null and endDate==null">
            and <![CDATA[
                `date` >= #{startDate}
            ]]>
        </if>
        <if test="startDate==null and endDate!=null">
            and <![CDATA[
                `date` <= #{endDate}
            ]]>
        </if>
        group  by `year`, `date`
        order by null
    </select>

    <select id="selectOrderTourReceivedStatisticsGroupByMonth" resultType="com.xxfc.platform.order.entity.OrderTourReceivedStatistics">
        select `year`,`month`,IFNULL(sum(`total_amount`-`order_refund_amount`),0) as `totalAmount`,IFNULL(sum(`total_quantity`),0) as `totalQuantity` from  `order_tour_received_statistics` where 1=1
        <if test="orderState!=null">
            and `has_pay`=#{orderState}
        </if>
        <if test="orderOrigin!=null">
            and `order_origin`=#{orderOrigin}
        </if>
        <if test="payWay!=null">
            and `pay_way`=#{payWay}
        </if>
        <if test="startDate!=null and endDate!=null">
            and `date` between #{startDate} and #{endDate}
        </if>
        <if test="startDate!=null and endDate==null">
            and <![CDATA[
                `date` >= #{startDate}
            ]]>
        </if>
        <if test="startDate==null and endDate!=null">
            and <![CDATA[
                `date` <= #{endDate}
            ]]>
        </if>
        group  by `year`, `month`
        order by null
    </select>

    <select id="selectOrderTourReceivedStatisticsGroupByWeekOfYear" resultType="com.xxfc.platform.order.entity.OrderTourReceivedStatistics">
        select `year`,`week_of_year`,IFNULL(sum(`total_amount`-`order_refund_amount`),0) as `totalAmount`,IFNULL(sum(`total_quantity`),0) as `totalQuantity` from  `order_tour_received_statistics` where 1=1
        <if test="orderState!=null">
            and `has_pay`=#{orderState}
        </if>
        <if test="orderOrigin!=null">
            and `order_origin`=#{orderOrigin}
        </if>
        <if test="payWay!=null">
            and `pay_way`=#{payWay}
        </if>
        <if test="startDate!=null and endDate!=null">
            and `date` between #{startDate} and #{endDate}
        </if>
        <if test="startDate!=null and endDate==null">
            and <![CDATA[
                `date` >= #{startDate}
            ]]>
        </if>
        <if test="startDate==null and endDate!=null">
            and <![CDATA[
                `date` <= #{endDate}
            ]]>
        </if>
        group  by `year`, `week_of_year`
        order by null
    </select>
</mapper>