Commit 9ecd3ed90dff1d7a2849f86b1d10cfb84be29c1e

Authored by YunaiV
1 parent 1a482667

fix(statistics): 兼容 PostgreSQL 统计查询

移植 #1307 的日期、空值、逻辑删除及排序兼容调整。
31 条实际 XML 映射在 MySQL 与 PostgreSQL 各执行 102 次,结果一致。

Refs #1307, #1308
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 FROM infra_api_access_log 7 FROM infra_api_access_log
8 WHERE user_type = #{userType} 8 WHERE user_type = #{userType}
9 AND create_time BETWEEN #{beginTime} AND #{endTime} 9 AND create_time BETWEEN #{beginTime} AND #{endTime}
10 - AND deleted = FALSE 10 + AND deleted = 0
11 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 11 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
12 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 12 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
13 </if> 13 </if>
@@ -19,7 +19,7 @@ @@ -19,7 +19,7 @@
19 WHERE user_id > 0 19 WHERE user_id > 0
20 AND user_type = #{userType} 20 AND user_type = #{userType}
21 AND create_time BETWEEN #{beginTime} AND #{endTime} 21 AND create_time BETWEEN #{beginTime} AND #{endTime}
22 - AND deleted = FALSE 22 + AND deleted = 0
23 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 23 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
24 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 24 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
25 </if> 25 </if>
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/member/MemberStatisticsMapper.xml
@@ -6,7 +6,7 @@ @@ -6,7 +6,7 @@
6 resultType="cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO"> 6 resultType="cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO">
7 SELECT area_id, COUNT(1) AS userCount 7 SELECT area_id, COUNT(1) AS userCount
8 FROM member_user 8 FROM member_user
9 - WHERE deleted = FALSE 9 + WHERE deleted = 0
10 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 10 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
11 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 11 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
12 </if> 12 </if>
@@ -17,7 +17,7 @@ @@ -17,7 +17,7 @@
17 resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO"> 17 resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO">
18 SELECT sex, COUNT(1) AS userCount 18 SELECT sex, COUNT(1) AS userCount
19 FROM member_user 19 FROM member_user
20 - WHERE deleted = FALSE 20 + WHERE deleted = 0
21 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 21 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
22 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 22 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
23 </if> 23 </if>
@@ -28,7 +28,7 @@ @@ -28,7 +28,7 @@
28 resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberTerminalStatisticsRespVO"> 28 resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberTerminalStatisticsRespVO">
29 SELECT register_terminal as terminal, COUNT(1) AS userCount 29 SELECT register_terminal as terminal, COUNT(1) AS userCount
30 FROM member_user 30 FROM member_user
31 - WHERE deleted = FALSE 31 + WHERE deleted = 0
32 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 32 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
33 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 33 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
34 </if> 34 </if>
@@ -38,7 +38,7 @@ @@ -38,7 +38,7 @@
38 <select id="selectUserCount" resultType="java.lang.Integer"> 38 <select id="selectUserCount" resultType="java.lang.Integer">
39 SELECT COUNT(1) 39 SELECT COUNT(1)
40 FROM member_user 40 FROM member_user
41 - WHERE deleted = FALSE 41 + WHERE deleted = 0
42 <if test="beginTime != null"> 42 <if test="beginTime != null">
43 AND create_time >= #{beginTime} 43 AND create_time >= #{beginTime}
44 </if> 44 </if>
@@ -52,15 +52,16 @@ @@ -52,15 +52,16 @@
52 52
53 <select id="selectListByCreateTimeBetween" 53 <select id="selectListByCreateTimeBetween"
54 resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberRegisterCountRespVO"> 54 resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberRegisterCountRespVO">
55 - SELECT DATE_FORMAT(create_time, '%Y-%m-%d') AS date, 55 + SELECT CAST(create_time AS DATE) AS date,
56 count(1) AS count 56 count(1) AS count
57 FROM member_user 57 FROM member_user
58 WHERE create_time BETWEEN #{beginTime} AND #{endTime} 58 WHERE create_time BETWEEN #{beginTime} AND #{endTime}
59 - AND deleted = FALSE 59 + AND deleted = 0
60 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 60 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
61 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 61 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
62 </if> 62 </if>
63 GROUP BY date 63 GROUP BY date
  64 + ORDER BY date
64 </select> 65 </select>
65 66
66 </mapper> 67 </mapper>
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/pay/PayWalletStatisticsMapper.xml
@@ -9,7 +9,7 @@ @@ -9,7 +9,7 @@
9 FROM pay_wallet_recharge 9 FROM pay_wallet_recharge
10 WHERE pay_status = #{payStatus} 10 WHERE pay_status = #{payStatus}
11 AND pay_time BETWEEN #{beginTime} AND #{endTime} 11 AND pay_time BETWEEN #{beginTime} AND #{endTime}
12 - AND deleted = FALSE 12 + AND deleted = 0
13 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 13 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
14 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 14 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
15 </if> 15 </if>
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 FROM pay_wallet_recharge 22 FROM pay_wallet_recharge
23 WHERE refund_status = #{refundStatus} 23 WHERE refund_status = #{refundStatus}
24 AND refund_time BETWEEN #{beginTime} AND #{endTime} 24 AND refund_time BETWEEN #{beginTime} AND #{endTime}
25 - AND deleted = FALSE 25 + AND deleted = 0
26 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 26 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
27 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 27 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
28 </if> 28 </if>
@@ -33,7 +33,7 @@ @@ -33,7 +33,7 @@
33 FROM pay_wallet_transaction 33 FROM pay_wallet_transaction
34 WHERE biz_type = #{bizType} 34 WHERE biz_type = #{bizType}
35 AND create_time BETWEEN #{beginTime} AND #{endTime} 35 AND create_time BETWEEN #{beginTime} AND #{endTime}
36 - AND deleted = FALSE 36 + AND deleted = 0
37 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 37 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
38 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 38 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
39 </if> 39 </if>
@@ -51,17 +51,17 @@ @@ -51,17 +51,17 @@
51 <if test="endTime != null"> 51 <if test="endTime != null">
52 AND pay_time &lt;= #{endTime} 52 AND pay_time &lt;= #{endTime}
53 </if> 53 </if>
54 - AND deleted = FALSE 54 + AND deleted = 0
55 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 55 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
56 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 56 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
57 </if> 57 </if>
58 </select> 58 </select>
59 59
60 <select id="selectRechargePriceSummary" resultType="java.lang.Integer"> 60 <select id="selectRechargePriceSummary" resultType="java.lang.Integer">
61 - SELECT IFNULL(SUM(pay_price), 0) 61 + SELECT COALESCE(SUM(pay_price), 0)
62 FROM pay_wallet_recharge 62 FROM pay_wallet_recharge
63 WHERE pay_status = #{payStatus} 63 WHERE pay_status = #{payStatus}
64 - AND deleted = FALSE 64 + AND deleted = 0
65 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 65 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
66 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 66 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
67 </if> 67 </if>
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/product/ProductStatisticsMapper.xml
@@ -42,7 +42,7 @@ @@ -42,7 +42,7 @@
42 </if> 42 </if>
43 ) AS cart_count 43 ) AS cart_count
44 -- 下单件数 44 -- 下单件数
45 - , (SELECT IFNULL(SUM(count), 0) 45 + , (SELECT COALESCE(SUM(count), 0)
46 FROM trade_order_item 46 FROM trade_order_item
47 WHERE spu_id = spu.id 47 WHERE spu_id = spu.id
48 AND create_time BETWEEN #{beginTime} AND #{endTime} 48 AND create_time BETWEEN #{beginTime} AND #{endTime}
@@ -51,7 +51,7 @@ @@ -51,7 +51,7 @@
51 </if> 51 </if>
52 ) AS order_count 52 ) AS order_count
53 -- 支付件数 53 -- 支付件数
54 - , (SELECT IFNULL(SUM(item.count), 0) 54 + , (SELECT COALESCE(SUM(item.count), 0)
55 FROM trade_order_item item 55 FROM trade_order_item item
56 JOIN trade_order o ON item.order_id = o.id 56 JOIN trade_order o ON item.order_id = o.id
57 WHERE spu_id = spu.id 57 WHERE spu_id = spu.id
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
63 </if> 63 </if>
64 ) AS order_pay_count 64 ) AS order_pay_count
65 -- 支付金额 65 -- 支付金额
66 - , (SELECT IFNULL(SUM(item.pay_price), 0) 66 + , (SELECT COALESCE(SUM(item.pay_price), 0)
67 FROM trade_order_item item 67 FROM trade_order_item item
68 JOIN trade_order o ON item.order_id = o.id 68 JOIN trade_order o ON item.order_id = o.id
69 WHERE spu_id = spu.id 69 WHERE spu_id = spu.id
@@ -75,7 +75,7 @@ @@ -75,7 +75,7 @@
75 </if> 75 </if>
76 ) AS order_pay_price 76 ) AS order_pay_price
77 -- 退款件数 77 -- 退款件数
78 - , (SELECT IFNULL(SUM(count), 0) 78 + , (SELECT COALESCE(SUM(count), 0)
79 FROM trade_after_sale 79 FROM trade_after_sale
80 WHERE spu_id = spu.id 80 WHERE spu_id = spu.id
81 AND refund_time IS NOT NULL 81 AND refund_time IS NOT NULL
@@ -85,7 +85,7 @@ @@ -85,7 +85,7 @@
85 </if> 85 </if>
86 ) AS after_sale_count 86 ) AS after_sale_count
87 -- 退款金额 87 -- 退款金额
88 - , (SELECT IFNULL(SUM(refund_price), 0) 88 + , (SELECT COALESCE(SUM(refund_price), 0)
89 FROM trade_after_sale 89 FROM trade_after_sale
90 WHERE spu_id = spu.id 90 WHERE spu_id = spu.id
91 AND refund_time IS NOT NULL 91 AND refund_time IS NOT NULL
@@ -95,7 +95,7 @@ @@ -95,7 +95,7 @@
95 </if> 95 </if>
96 ) AS after_sale_refund_price 96 ) AS after_sale_refund_price
97 FROM product_spu spu 97 FROM product_spu spu
98 - WHERE spu.deleted = FALSE 98 + WHERE spu.deleted = 0
99 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 99 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
100 AND spu.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 100 AND spu.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
101 </if> 101 </if>
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/trade/AfterSaleStatisticsMapper.xml
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 SUM(refund_price) AS afterSaleRefundPrice 8 SUM(refund_price) AS afterSaleRefundPrice
9 FROM trade_after_sale 9 FROM trade_after_sale
10 WHERE refund_time BETWEEN #{beginTime} AND #{endTime} 10 WHERE refund_time BETWEEN #{beginTime} AND #{endTime}
11 - AND deleted = FALSE 11 + AND deleted = 0
12 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 12 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
13 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 13 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
14 </if> 14 </if>
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 SELECT COUNT(1) 18 SELECT COUNT(1)
19 FROM trade_after_sale 19 FROM trade_after_sale
20 WHERE status = #{status} 20 WHERE status = #{status}
21 - AND deleted = FALSE 21 + AND deleted = 0
22 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 22 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
23 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 23 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
24 </if> 24 </if>
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/trade/BrokerageStatisticsMapper.xml
@@ -8,7 +8,7 @@ @@ -8,7 +8,7 @@
8 WHERE biz_type = #{bizType} 8 WHERE biz_type = #{bizType}
9 AND status = #{status} 9 AND status = #{status}
10 AND unfreeze_time BETWEEN #{beginTime} AND #{endTime} 10 AND unfreeze_time BETWEEN #{beginTime} AND #{endTime}
11 - AND deleted = FALSE 11 + AND deleted = 0
12 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 12 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
13 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 13 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
14 </if> 14 </if>
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 SELECT COUNT(1) 18 SELECT COUNT(1)
19 FROM trade_brokerage_withdraw 19 FROM trade_brokerage_withdraw
20 WHERE status = #{status} 20 WHERE status = #{status}
21 - AND deleted = FALSE 21 + AND deleted = 0
22 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 22 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
23 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 23 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
24 </if> 24 </if>
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 FROM trade_order AS s 16 FROM trade_order AS s
17 WHERE s.receiver_area_id = m.receiver_area_id 17 WHERE s.receiver_area_id = m.receiver_area_id
18 AND s.pay_status = TRUE 18 AND s.pay_status = TRUE
19 - AND s.deleted = FALSE 19 + AND s.deleted = 0
20 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 20 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
21 AND s.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 21 AND s.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
22 </if> 22 </if>
@@ -25,13 +25,13 @@ @@ -25,13 +25,13 @@
25 FROM trade_order AS s 25 FROM trade_order AS s
26 WHERE s.receiver_area_id = m.receiver_area_id 26 WHERE s.receiver_area_id = m.receiver_area_id
27 AND s.pay_status = TRUE 27 AND s.pay_status = TRUE
28 - AND s.deleted = FALSE 28 + AND s.deleted = 0
29 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 29 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
30 AND s.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 30 AND s.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
31 </if> 31 </if>
32 ) AS orderPayPrice 32 ) AS orderPayPrice
33 FROM trade_order m 33 FROM trade_order m
34 - WHERE deleted = FALSE 34 + WHERE deleted = 0
35 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 35 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
36 AND m.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 36 AND m.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
37 </if> 37 </if>
@@ -41,7 +41,7 @@ @@ -41,7 +41,7 @@
41 <select id="selectUserCountByCreateTimeBetween" resultType="java.lang.Integer"> 41 <select id="selectUserCountByCreateTimeBetween" resultType="java.lang.Integer">
42 SELECT COUNT(DISTINCT (user_id)) 42 SELECT COUNT(DISTINCT (user_id))
43 FROM trade_order 43 FROM trade_order
44 - WHERE deleted = FALSE 44 + WHERE deleted = 0
45 AND create_time BETWEEN #{beginTime} AND #{endTime} 45 AND create_time BETWEEN #{beginTime} AND #{endTime}
46 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 46 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
47 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 47 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
@@ -53,7 +53,7 @@ @@ -53,7 +53,7 @@
53 FROM trade_order 53 FROM trade_order
54 WHERE pay_time BETWEEN #{beginTime} AND #{endTime} 54 WHERE pay_time BETWEEN #{beginTime} AND #{endTime}
55 AND pay_status = TRUE 55 AND pay_status = TRUE
56 - AND deleted = FALSE 56 + AND deleted = 0
57 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 57 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
58 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 58 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
59 </if> 59 </if>
@@ -63,7 +63,7 @@ @@ -63,7 +63,7 @@
63 SELECT COUNT(1) 63 SELECT COUNT(1)
64 FROM trade_order 64 FROM trade_order
65 WHERE create_time BETWEEN #{beginTime} AND #{endTime} 65 WHERE create_time BETWEEN #{beginTime} AND #{endTime}
66 - AND deleted = FALSE 66 + AND deleted = 0
67 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 67 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
68 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 68 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
69 </if> 69 </if>
@@ -74,7 +74,7 @@ @@ -74,7 +74,7 @@
74 FROM trade_order 74 FROM trade_order
75 WHERE pay_status = TRUE 75 WHERE pay_status = TRUE
76 AND create_time BETWEEN #{beginTime} AND #{endTime} 76 AND create_time BETWEEN #{beginTime} AND #{endTime}
77 - AND deleted = FALSE 77 + AND deleted = 0
78 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 78 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
79 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 79 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
80 </if> 80 </if>
@@ -84,7 +84,7 @@ @@ -84,7 +84,7 @@
84 SELECT SUM(pay_price) 84 SELECT SUM(pay_price)
85 FROM trade_order AS s 85 FROM trade_order AS s
86 WHERE s.pay_status = TRUE 86 WHERE s.pay_status = TRUE
87 - AND deleted = FALSE 87 + AND deleted = 0
88 AND create_time BETWEEN #{beginTime} AND #{endTime} 88 AND create_time BETWEEN #{beginTime} AND #{endTime}
89 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 89 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
90 AND s.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 90 AND s.tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
@@ -93,32 +93,35 @@ @@ -93,32 +93,35 @@
93 93
94 <select id="selectListByPayTimeBetweenAndGroupByDay" 94 <select id="selectListByPayTimeBetweenAndGroupByDay"
95 resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderTrendRespVO"> 95 resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderTrendRespVO">
96 - SELECT DATE_FORMAT(pay_time, '%Y-%m-%d') AS date, 96 + SELECT CAST(pay_time AS DATE) AS date,
97 COUNT(1) AS orderPayCount, 97 COUNT(1) AS orderPayCount,
98 SUM(pay_price) AS orderPayPrice 98 SUM(pay_price) AS orderPayPrice
99 FROM trade_order 99 FROM trade_order
100 WHERE pay_status = TRUE 100 WHERE pay_status = TRUE
101 AND create_time BETWEEN #{beginTime} AND #{endTime} 101 AND create_time BETWEEN #{beginTime} AND #{endTime}
102 - AND deleted = FALSE 102 + AND deleted = 0
103 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 103 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
104 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 104 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
105 </if> 105 </if>
106 GROUP BY date 106 GROUP BY date
  107 + ORDER BY date
107 </select> 108 </select>
108 109
109 <select id="selectListByPayTimeBetweenAndGroupByMonth" 110 <select id="selectListByPayTimeBetweenAndGroupByMonth"
110 resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderTrendRespVO"> 111 resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderTrendRespVO">
111 - SELECT DATE_FORMAT(pay_time, '%Y-%m') AS date, 112 + SELECT CONCAT(EXTRACT(YEAR FROM pay_time), '-',
  113 + LPAD(CONCAT(EXTRACT(MONTH FROM pay_time)), 2, '0')) AS date,
112 COUNT(1) AS order_pay_count, 114 COUNT(1) AS order_pay_count,
113 SUM(pay_price) AS order_pay_price 115 SUM(pay_price) AS order_pay_price
114 FROM trade_order 116 FROM trade_order
115 WHERE pay_status = TRUE 117 WHERE pay_status = TRUE
116 AND create_time BETWEEN #{beginTime} AND #{endTime} 118 AND create_time BETWEEN #{beginTime} AND #{endTime}
117 - AND deleted = FALSE 119 + AND deleted = 0
118 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 120 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
119 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 121 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
120 </if> 122 </if>
121 GROUP BY date 123 GROUP BY date
  124 + ORDER BY date
122 </select> 125 </select>
123 126
124 <select id="selectCountByStatusAndDeliveryType" resultType="java.lang.Long"> 127 <select id="selectCountByStatusAndDeliveryType" resultType="java.lang.Long">
@@ -126,7 +129,7 @@ @@ -126,7 +129,7 @@
126 FROM trade_order 129 FROM trade_order
127 WHERE status = #{status} 130 WHERE status = #{status}
128 ANd delivery_type = #{deliveryType} 131 ANd delivery_type = #{deliveryType}
129 - AND deleted = FALSE 132 + AND deleted = 0
130 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 133 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
131 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 134 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
132 </if> 135 </if>
@@ -134,12 +137,12 @@ @@ -134,12 +137,12 @@
134 137
135 <select id="selectPaySummaryByPayStatusAndPayTimeBetween" 138 <select id="selectPaySummaryByPayStatusAndPayTimeBetween"
136 resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderSummaryRespVO"> 139 resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeOrderSummaryRespVO">
137 - SELECT IFNULL(SUM(pay_price), 0) AS order_pay_price, 140 + SELECT COALESCE(SUM(pay_price), 0) AS order_pay_price,
138 COUNT(1) AS order_pay_count 141 COUNT(1) AS order_pay_count
139 FROM trade_order 142 FROM trade_order
140 WHERE pay_status = #{payStatus} 143 WHERE pay_status = #{payStatus}
141 AND pay_time BETWEEN #{beginTime} AND #{endTime} 144 AND pay_time BETWEEN #{beginTime} AND #{endTime}
142 - AND deleted = FALSE 145 + AND deleted = 0
143 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null"> 146 <if test="@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId() != null">
144 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()} 147 AND tenant_id = ${@cn.iocoder.yudao.framework.tenant.core.context.TenantContextHolder@getTenantId()}
145 </if> 148 </if>
yudao-module-mall/yudao-module-statistics/src/main/resources/mapper/trade/TradeStatisticsMapper.xml
@@ -4,11 +4,11 @@ @@ -4,11 +4,11 @@
4 4
5 <select id="selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween" 5 <select id="selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween"
6 resultType="cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO"> 6 resultType="cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO">
7 - SELECT IFNULL(SUM(order_create_count), 0) AS count,  
8 - IFNULL(SUM(order_pay_price), 0) AS summary 7 + SELECT COALESCE(SUM(order_create_count), 0) AS count,
  8 + COALESCE(SUM(order_pay_price), 0) AS summary
9 FROM trade_statistics 9 FROM trade_statistics
10 WHERE time BETWEEN #{beginTime} AND #{endTime} 10 WHERE time BETWEEN #{beginTime} AND #{endTime}
11 - AND deleted = FALSE 11 + AND deleted = 0
12 </select> 12 </select>
13 13
14 <select id="selectVoByTimeBetween" 14 <select id="selectVoByTimeBetween"
@@ -25,14 +25,14 @@ @@ -25,14 +25,14 @@
25 SUM(after_sale_refund_price) AS afterSaleRefundPrice 25 SUM(after_sale_refund_price) AS afterSaleRefundPrice
26 FROM trade_statistics 26 FROM trade_statistics
27 WHERE time BETWEEN #{beginTime} AND #{endTime} 27 WHERE time BETWEEN #{beginTime} AND #{endTime}
28 - AND deleted = FALSE 28 + AND deleted = 0
29 </select> 29 </select>
30 30
31 <select id="selectExpensePriceByTimeBetween" resultType="java.lang.Integer"> 31 <select id="selectExpensePriceByTimeBetween" resultType="java.lang.Integer">
32 SELECT -- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额 32 SELECT -- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
33 SUM(wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice 33 SUM(wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice
34 FROM trade_statistics 34 FROM trade_statistics
35 - WHERE deleted = FALSE 35 + WHERE deleted = 0
36 <if test="beginTime != null"> 36 <if test="beginTime != null">
37 AND time >= #{beginTime} 37 AND time >= #{beginTime}
38 </if> 38 </if>
yudao-module-mall/yudao-module-trade/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml
@@ -17,14 +17,14 @@ @@ -17,14 +17,14 @@
17 resultType="cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO"> 17 resultType="cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserChildSummaryRespVO">
18 SELECT bu.id, bu.bind_user_time AS brokerageTime, 18 SELECT bu.id, bu.bind_user_time AS brokerageTime,
19 (SELECT SUM(price) FROM trade_brokerage_record r 19 (SELECT SUM(price) FROM trade_brokerage_record r
20 - WHERE r.user_id = bu.id AND biz_type = #{bizType} AND r.status = #{status} AND r.deleted = FALSE) AS brokeragePrice, 20 + WHERE r.user_id = bu.id AND biz_type = #{bizType} AND r.status = #{status} AND r.deleted = 0) AS brokeragePrice,
21 (SELECT COUNT(1) FROM trade_brokerage_record r 21 (SELECT COUNT(1) FROM trade_brokerage_record r
22 - WHERE r.user_id = bu.id AND biz_type = #{bizType} AND r.status = #{status} AND r.deleted = FALSE) AS brokerageOrderCount, 22 + WHERE r.user_id = bu.id AND biz_type = #{bizType} AND r.status = #{status} AND r.deleted = 0) AS brokerageOrderCount,
23 (SELECT COUNT(1) FROM trade_brokerage_user c 23 (SELECT COUNT(1) FROM trade_brokerage_user c
24 - WHERE c.bind_user_id = bu.id AND c.deleted = FALSE) AS brokerageUserCount 24 + WHERE c.bind_user_id = bu.id AND c.deleted = 0) AS brokerageUserCount
25 FROM trade_brokerage_user AS bu 25 FROM trade_brokerage_user AS bu
26 <where> 26 <where>
27 - bu.deleted = false 27 + bu.deleted = 0
28 <if test="ids != null and ids.size() > 0"> 28 <if test="ids != null and ids.size() > 0">
29 and bu.id in 29 and bu.id in
30 <foreach collection="ids" open="(" item="id" separator="," close=")"> 30 <foreach collection="ids" open="(" item="id" separator="," close=")">