ebike-plus/ebike-user/src/main/resources/mapper/EbikeOrderMapper.xml

58 lines
3.2 KiB
XML
Raw Normal View History

2025-11-28 14:28:42 +08:00
<?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.cdzy.user.mapper.EbikeOrderMapper">
<resultMap id="EbikeRevenueStatisticsVoMap" type="com.cdzy.user.model.vo.EbikeRevenueStatisticsVo">
<id column="operator_id" property="operatorId"/>
<result column="today_revenue" property="todayRevenue" javaType="java.math.BigDecimal"/>
<result column="yesterday_revenue" property="yesterdayRevenue" javaType="java.math.BigDecimal"/>
<result column="this_week_revenue" property="thisWeekRevenue" javaType="java.math.BigDecimal"/>
<result column="last_week_revenue" property="lastWeekRevenue" javaType="java.math.BigDecimal"/>
<result column="this_month_revenue" property="thisMonthRevenue" javaType="java.math.BigDecimal"/>
<result column="last_month_revenue" property="lastMonthRevenue" javaType="java.math.BigDecimal"/>
</resultMap>
<select id="selectRevenueComparison" resultMap="EbikeRevenueStatisticsVoMap">
SELECT operator_id,
COALESCE(SUM(CASE
WHEN payment_time &gt;= DATE_TRUNC('day', CURRENT_TIMESTAMP)
AND payment_time &lt; CURRENT_TIMESTAMP
THEN actual_amount END), 0) AS today_revenue,
COALESCE(SUM(CASE
WHEN payment_time &gt;= DATE_TRUNC('day', CURRENT_TIMESTAMP - INTERVAL '1 day')
AND payment_time &lt; DATE_TRUNC('day', CURRENT_TIMESTAMP)
THEN actual_amount END), 0) AS yesterday_revenue,
COALESCE(SUM(CASE
WHEN payment_time &gt;= DATE_TRUNC('week', CURRENT_TIMESTAMP)
AND payment_time &lt; CURRENT_TIMESTAMP
THEN actual_amount END), 0) AS this_week_revenue,
COALESCE(SUM(CASE
WHEN payment_time &gt;= DATE_TRUNC('week', CURRENT_TIMESTAMP - INTERVAL '7 days')
AND payment_time &lt; DATE_TRUNC('week', CURRENT_TIMESTAMP)
THEN actual_amount END), 0) AS last_week_revenue,
COALESCE(SUM(CASE
WHEN payment_time &gt;= DATE_TRUNC('month', CURRENT_TIMESTAMP)
AND payment_time &lt; CURRENT_TIMESTAMP
THEN actual_amount END), 0) AS this_month_revenue,
COALESCE(SUM(CASE
WHEN payment_time &gt;= DATE_TRUNC('month', CURRENT_TIMESTAMP - INTERVAL '1 month')
AND payment_time &lt; DATE_TRUNC('month', CURRENT_TIMESTAMP)
THEN actual_amount END), 0) AS last_month_revenue
FROM ebike_order
WHERE order_status = 3
AND payment_time IS NOT NULL
AND is_deleted = false
AND operator_id IS NOT NULL
GROUP BY operator_id
ORDER BY operator_id;
</select>
</mapper>