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

79 lines
3.9 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>
2026-01-16 15:37:45 +08:00
<select id="getOrderStatistics" resultType="com.ebike.feign.model.vo.FeignEbikeOrderStatisticsVo">
SELECT
operator_id AS operatorId,
create_time::date::timestamp AS createTime,
COUNT(*) AS orderCount,
COALESCE(SUM(total_amount), 0) AS orderAmount
FROM ebike_order
WHERE 1 = 1
<if test="operatorId != null">
AND operator_id = #{operatorId}
</if>
<if test="startTime != null">
AND create_time >= #{startTime}
</if>
<if test="endTime != null">
AND create_time &lt; #{endTime}
</if>
GROUP BY create_time::date, operator_id
ORDER BY create_time::date, operator_id
</select>
2025-11-28 14:28:42 +08:00
</mapper>