<?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.kym.mapper.WashOrderMapper">

    <resultMap id="StationStatMap" type="com.kym.entity.vo.StationTrendVo">
        <result column="stat_time" property="statTime"/>
        <result column="total_orders" property="totalOrders"/>
        <result column="total_amount" property="totalAmount"/>
        <result column="amount_receivable" property="amountReceivable"/>
        <result column="amount_received" property="amountReceived"/>

    </resultMap>


    <select id="StationTrend" resultMap="StationStatMap" parameterType="com.kym.entity.queryParams.StatQueryParam">
        SELECT
        <if test="params.stationIds != null and params.stationId != ''">
            t1.station_id,
        </if>
        DATE_FORMAT(t1.start_time, '%Y-%m-%d') stat_time,
        count(t1.id) total_orders,
        SUM(t1.amount) total_amount,
        SUM(t1.amount_receivable) amount_receivable,
        SUM(t1.amount_received) amount_received
        FROM
        (SELECT
        *
        FROM
        t_wash_order
        <where>
            <if test="params.stationId != null and params.stationId != ''">
                and station_id = #{params.stationId}
            </if>
        </where>
        ) t1
        GROUP BY stat_time
        <trim prefix="having" suffixOverrides="and">
            <if test="params.startTime != null">
                stat_time &gt;= #{params.startTime} and
            </if>
            <if test="params.endTime != null">
                stat_time &lt;= #{params.endTime} and
            </if>
        </trim>
        order by stat_time desc
    </select>

</mapper>
