<?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.OrderRentVehicleReceivedStatisticsMapper">

	<!-- 可根据自己的需求，是否要使用 -->
    <resultMap type="com.xxfc.platform.order.entity.OrderRentVehicleReceivedStatistics" id="orderRentVehicleReceivedStatisticsMap">
        <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="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"/>
        <result property="extraNoDeductibleAmount" column="extral_no_deductible_amount"/>
        <result property="orderRefundAmount" column="order_refund_amount"/>
        <result property="lateFeeAmount" column="late_fee_amount"/>
        <result property="extraAmount" column="extra_amount"/>
        <result property="companyName" column="company_name"/>
        <result property="noDeductibleAmount" column="no_deductible_amount"/>
        <result property="noDeductibleRefundAmount" column="no_deductible_refund_amount"/>
        <result property="lossSpecifiedAmount" column="loss_specified_amount"/>
        <result property="depositRefundAmount" column="deposit_refund_amount"/>
        <result property="depositAmount" column="deposit_amount"/>
        <result property="breakRulesRegulationAmount" column="break_rules_regulation_amount"/>
    </resultMap>
    <select id="selectOrderRentVehicleReceivedStatisticsGroupByDate" resultType="com.xxfc.platform.order.entity.OrderRentVehicleReceivedStatistics">
        select `year`,`date`,IFNULL(sum(`total_amount`-`order_refund_amount`),0) as `totalAmount`,IFNULL(sum(`total_quantity`),0) as `totalQuantity` from `order_rent_vehicle_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="selectOrderRentVehicleReceivedStatisticsGroupByMonth"  resultType="com.xxfc.platform.order.entity.OrderRentVehicleReceivedStatistics">
        select `year`,`month`,IFNULL(sum(`total_amount`-`order_refund_amount`),0) as `totalAmount`,IFNULL(sum(`total_quantity`),0) as `totalQuantity` from `order_rent_vehicle_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="selectOrderRentVehicleReceivedStatisticsGroupByWeekOfYear" resultType="com.xxfc.platform.order.entity.OrderRentVehicleReceivedStatistics">
        select `year`,`week_of_year`,IFNULL(sum(`total_amount`-`order_refund_amount`),0) as `totalAmount`,IFNULL(sum(`total_quantity`),0) as `totalQuantity` from `order_rent_vehicle_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>