<?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.cyksj.mapper.manage.distribute.DistributeWaitingSendPointsMapper">

    <select id="getWMoneyStatisticsDataView"
            resultType="com.cyksj.model.views.CpsUserWMoneyStatisticsDataView">
        select
        <if test="today">
            date_format(send_time, '%H') as `hour`,
        </if>
        <if test="!today">
            date_format(send_time, '%Y-%m-%d') `date`,
        </if>
        TRUNCATE(ifnull(sum(points),0)/ 1000,2) money
        from `distribute_waiting_send_points`
        where shared_id = #{cpsUserId}
        and send_status = 'waiting'
        <choose>
            <when test="today">
                <if test="first != null">
                    and send_time >= #{first}
                </if>
                <if test="end != null">
                    and send_time &lt;= #{end}
                </if>
                group by date_format(send_time, '%H')
                order by date_format(send_time, '%H')
            </when>
            <otherwise>
                <if test="first != null">
                    and date_format(send_time, '%Y-%m-%d') >= #{first}
                </if>
                <if test="end != null">
                    and date_format(send_time, '%Y-%m-%d') &lt; #{end}
                </if>
                group by date_format(send_time, '%Y-%m-%d')
                order by date_format(send_time, '%Y-%m-%d')
            </otherwise>
        </choose>
    </select>

    <select id="getWMoneyStatisticsDate" resultType="com.cyksj.model.views.BrokenLineCpsUserWMoneyView">
        select min(curdate) as firstDate,
        max(curdate) as lastDate from (select
        <if test="today">
            date_format(send_time, '%H') as `curdate`
        </if>
        <if test="!today">
            date_format(send_time, '%Y-%m-%d') `curdate`
        </if>
        from `distribute_waiting_send_points`
        where shared_id = #{cpsUserId}
        and send_status = 'waiting'
        <choose>
            <when test="today">
                <if test="first != null">
                    and send_time >= #{first}
                </if>
                <if test="end != null">
                    and send_time &lt;= #{end}
                </if>
                group by date_format(send_time, '%H')
            </when>
            <otherwise>
                <if test="first != null">
                    and date_format(send_time, '%Y-%m-%d') >= #{first}
                </if>
                <if test="end != null">
                    and date_format(send_time, '%Y-%m-%d') &lt; #{end}
                </if>
                group by date_format(send_time, '%Y-%m-%d')
            </otherwise>
        </choose>
        )s
    </select>
</mapper>