fix(订单中心):首页统计问题优化修复,显示数据更新

This commit is contained in:
2025-08-06 12:40:52 +08:00
parent 6d4fa0f26e
commit c571b7b894
11 changed files with 344 additions and 295 deletions
@@ -114,28 +114,44 @@ public class DashboardController {
}
}
@Operation(summary = "调试数据库时间查询")
@GetMapping("/debug-time-query")
public Result<Map<String, Object>> debugTimeQuery(
@Operation(summary = "测试今日收款订单数计算")
@GetMapping("/test-today-paid-orders")
public Result<Map<String, Object>> testTodayPaidOrders(
@Parameter(description = "景区ID") @RequestParam(required = false) Long tourismId,
@Parameter(description = "二维码ID") @RequestParam(required = false) String qrcodeId,
@Parameter(description = "设备编号") @RequestParam(required = false) String deviceSn,
@Parameter(description = "开始时间") @RequestParam(required = false) String startTime,
@Parameter(description = "结束时间") @RequestParam(required = false) String endTime) {
@Parameter(description = "结束时间") @RequestParam(required = false) String endTime,
@Parameter(description = "是否包含测试二维码") @RequestParam(required = false, defaultValue = "false") Boolean includeTestQrcodes) {
try {
Map<String, Object> params = new HashMap<>();
params.put("tourismId", tourismId);
params.put("qrcodeId", qrcodeId);
params.put("deviceSn", deviceSn);
params.put("startTime", startTime);
params.put("endTime", endTime);
params.put("includeTestQrcodes", includeTestQrcodes);
// 直接查询数据库中的时间范围数据
List<Map<String, Object>> timeRangeData = dashboardMapper.debugTimeRangeQuery(params);
// 测试各个统计方法
Long todayOrders = dashboardMapper.getTodayOrders(params);
Long todayPaidOrders = dashboardMapper.getTodayPaidOrders(params);
Long todayRefundedOrders = dashboardMapper.getTodayRefundedOrders(params);
// 手动计算验证
Long manualCalculation = todayOrders - todayRefundedOrders;
Map<String, Object> result = new HashMap<>();
result.put("params", params);
result.put("timeRangeData", timeRangeData);
result.put("dataCount", timeRangeData.size());
result.put("todayOrders", todayOrders);
result.put("todayPaidOrders", todayPaidOrders);
result.put("todayRefundedOrders", todayRefundedOrders);
result.put("manualCalculation", manualCalculation);
result.put("currentDate", new java.util.Date());
return Result.succeed(result, "调试时间查询成功");
return Result.succeed(result, "测试今日收款订单数计算成功");
} catch (Exception e) {
log.error("调试时间查询失败", e);
return Result.failed("调试失败:" + e.getMessage());
log.error("测试今日收款订单数计算失败", e);
return Result.failed("测试失败:" + e.getMessage());
}
}
@@ -21,7 +21,7 @@ public interface DashboardMapper {
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
"AND o.order_status IN (1, 3, 4, 5, 7, 8)",
"AND o.order_status IN (1, 3, 4, 5, 7, 8, 9)",
"<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
@@ -51,7 +51,7 @@ public interface DashboardMapper {
" AND q.is_test = 0",
"</if>",
"AND DATE(o.create_time) = CURDATE()",
"AND o.order_status IN (1, 3, 4, 5, 7, 8)",
"AND o.order_status IN (1, 3, 4, 5, 7, 8, 9)",
"<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
@@ -65,58 +65,6 @@ public interface DashboardMapper {
})
Long getTodayOrders(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT COUNT(*) as count",
"FROM orders o",
"JOIN qrcodes q ON o.code_id = q.code_id",
"WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
"AND DATE(o.create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)",
"<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o.device_sn = #{p.deviceSn}",
"</if>",
"</script>"
})
Long getYesterdayOrders(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT COUNT(*) as count",
"FROM orders o",
"JOIN qrcodes q ON o.code_id = q.code_id",
"WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
"AND o.order_status = 3",
"<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o.device_sn = #{p.deviceSn}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND o.create_time &lt;= #{p.endTime}",
"</if>",
"</script>"
})
Long getCompletedOrders(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT COUNT(*) as count",
@@ -173,51 +121,28 @@ public interface DashboardMapper {
@Select({
"<script>",
"SELECT",
" (SELECT COUNT(*) FROM orders o1",
" JOIN qrcodes q1 ON o1.code_id = q1.code_id",
" WHERE 1=1",
" SUM(CASE WHEN o.order_status IN (1, 3, 4, 5, 7) THEN 1 ELSE 0 END) as count",
"FROM orders o",
"JOIN qrcodes q ON o.code_id = q.code_id",
"WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q1.is_test = 0",
" AND q.is_test = 0",
"</if>",
" AND o1.order_status IN (1, 3, 4, 5, 7, 8)",
"<if test='p.tourismId != null'>",
" AND o1.tourism_id = #{p.tourismId}",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o1.code_id = #{p.qrcodeId}",
" AND o.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o1.device_sn = #{p.deviceSn}",
" AND o.device_sn = #{p.deviceSn}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o1.create_time >= #{p.startTime}",
" AND o.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND o1.create_time &lt;= #{p.endTime}",
" AND o.create_time &lt;= #{p.endTime}",
"</if>",
" ) - (SELECT COUNT(*) FROM orders o2",
" JOIN qrcodes q2 ON o2.code_id = q2.code_id",
" WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q2.is_test = 0",
"</if>",
" AND o2.order_status = 8",
"<if test='p.tourismId != null'>",
" AND o2.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o2.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o2.device_sn = #{p.deviceSn}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o2.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND o2.create_time &lt;= #{p.endTime}",
"</if>",
" )) as count",
"</script>"
})
Long getTotalPaidOrders(@Param("p") Map<String, Object> params);
@@ -225,41 +150,23 @@ public interface DashboardMapper {
@Select({
"<script>",
"SELECT",
" (SELECT COUNT(*) FROM orders o1",
" JOIN qrcodes q1 ON o1.code_id = q1.code_id",
" WHERE 1=1",
" SUM(CASE WHEN o.order_status IN (1, 3, 4, 5, 7) THEN 1 ELSE 0 END) as count",
"FROM orders o",
"JOIN qrcodes q ON o.code_id = q.code_id",
"WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q1.is_test = 0",
" AND q.is_test = 0",
"</if>",
" AND DATE(o1.create_time) = CURDATE()",
" AND o1.order_status IN (1, 3, 4, 5, 7, 8)",
" AND DATE(o.create_time) = CURDATE()",
"<if test='p.tourismId != null'>",
" AND o1.tourism_id = #{p.tourismId}",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o1.code_id = #{p.qrcodeId}",
" AND o.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o1.device_sn = #{p.deviceSn}",
" AND o.device_sn = #{p.deviceSn}",
"</if>",
" ) - (SELECT COUNT(*) FROM orders o2",
" JOIN qrcodes q2 ON o2.code_id = q2.code_id",
" WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q2.is_test = 0",
"</if>",
" AND DATE(o2.create_time) = CURDATE()",
" AND o2.order_status = 8",
"<if test='p.tourismId != null'>",
" AND o2.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o2.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o2.device_sn = #{p.deviceSn}",
"</if>",
" )) as count",
"</script>"
})
Long getTodayPaidOrders(@Param("p") Map<String, Object> params);
@@ -294,60 +201,6 @@ public interface DashboardMapper {
})
Long getTotalAmount(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT COALESCE(SUM(os.platform_amount), 0)",
"FROM order_statistics os",
"WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND os.qrcode_id IN (SELECT code_id FROM qrcodes WHERE is_test = 0)",
"</if>",
"<if test='p.tourismId != null'>",
" AND os.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND os.qrcode_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND os.device_sn = #{p.deviceSn}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND os.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND os.create_time &lt;= #{p.endTime}",
"</if>",
"</script>"
})
Long getPlatformAmount(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT COALESCE(SUM(os.tourism_amount), 0)",
"FROM order_statistics os",
"WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND os.qrcode_id IN (SELECT code_id FROM qrcodes WHERE is_test = 0)",
"</if>",
"<if test='p.tourismId != null'>",
" AND os.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND os.qrcode_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND os.device_sn = #{p.deviceSn}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND os.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND os.create_time &lt;= #{p.endTime}",
"</if>",
"</script>"
})
Long getTourismAmount(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT COALESCE(SUM(o.order_amount), 0) as amount",
@@ -390,6 +243,7 @@ public interface DashboardMapper {
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
"AND o.order_status IN (1, 3, 4, 5, 7, 8, 9)",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o.create_time >= #{p.startTime}",
"</if>",
@@ -467,6 +321,88 @@ public interface DashboardMapper {
})
List<TrendDataVO> getOrderTrend(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT",
" q.name as qrcodeName,",
" q.code_id as qrcodeId,",
" COUNT(o.id) as orderCount",
"FROM qrcodes q",
"LEFT JOIN orders o ON q.code_id = o.code_id AND o.order_status IN (3, 7)",
"WHERE q.is_del = 0",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
"<if test='p.tourismId != null'>",
" AND q.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND o.create_time &lt;= #{p.endTime}",
"</if>",
"GROUP BY q.code_id, q.name",
"HAVING orderCount > 0",
"ORDER BY orderCount DESC",
"LIMIT 20",
"</script>"
})
List<QrcodeOrderDataVO> getQrcodeOrderCount(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT COUNT(*) as count",
"FROM orders o",
"JOIN qrcodes q ON o.code_id = q.code_id",
"WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
"AND DATE(o.create_time) = DATE_SUB(CURDATE(), INTERVAL 1 DAY)",
"AND o.order_status IN (1, 3, 4, 5, 7, 8, 9)",
"<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o.device_sn = #{p.deviceSn}",
"</if>",
"</script>"
})
Long getYesterdayOrders(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT COUNT(*) as count",
"FROM orders o",
"JOIN qrcodes q ON o.code_id = q.code_id",
"WHERE 1=1",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
"AND o.order_status = 3",
"<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.qrcodeId != null and p.qrcodeId != \"\"'>",
" AND o.code_id = #{p.qrcodeId}",
"</if>",
"<if test='p.deviceSn != null and p.deviceSn != \"\"'>",
" AND o.device_sn = #{p.deviceSn}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND o.create_time &lt;= #{p.endTime}",
"</if>",
"</script>"
})
Long getCompletedOrders(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT",
@@ -587,35 +523,6 @@ public interface DashboardMapper {
})
List<IncomeDataVO> getIncomeBreakdown(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT",
" q.name as qrcodeName,",
" q.code_id as qrcodeId,",
" COUNT(o.id) as orderCount",
"FROM qrcodes q",
"LEFT JOIN orders o ON q.code_id = o.code_id AND o.order_status IN (3, 7)",
"WHERE q.is_del = 0",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
"<if test='p.tourismId != null'>",
" AND q.tourism_id = #{p.tourismId}",
"</if>",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND o.create_time &lt;= #{p.endTime}",
"</if>",
"GROUP BY q.code_id, q.name",
"HAVING orderCount > 0",
"ORDER BY orderCount DESC",
"LIMIT 20",
"</script>"
})
List<QrcodeOrderDataVO> getQrcodeOrderCount(@Param("p") Map<String, Object> params);
// 筛选选项
@Select("SELECT id as value, tourism_name as label FROM tourisms WHERE is_del = 0 ORDER BY create_time DESC")
List<FilterOptions.OptionItem> getTourismOptions();
@@ -634,41 +541,4 @@ public interface DashboardMapper {
"</script>"
})
List<FilterOptions.OptionItem> getQrcodeOptions(@Param("p") Map<String, Object> params);
@Select({
"<script>",
"SELECT DISTINCT device_sn as value, device_sn as label FROM qrcodes",
"WHERE is_del = 0",
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND is_test = 0",
"</if>",
"AND device_sn IS NOT NULL",
"ORDER BY device_sn",
"</script>"
})
List<FilterOptions.OptionItem> getDeviceOptions(@Param("p") Map<String, Object> params);
// 调试时间范围查询
@Select({
"<script>",
"SELECT",
" o.id,",
" o.order_no,",
" o.order_amount,",
" o.order_status,",
" o.create_time,",
" o.tourism_id",
"FROM orders o",
"WHERE 1=1",
"<if test='p.startTime != null and p.startTime != \"\"'>",
" AND o.create_time >= #{p.startTime}",
"</if>",
"<if test='p.endTime != null and p.endTime != \"\"'>",
" AND o.create_time &lt;= #{p.endTime}",
"</if>",
"ORDER BY o.create_time DESC",
"LIMIT 20",
"</script>"
})
List<Map<String, Object>> debugTimeRangeQuery(@Param("p") Map<String, Object> params);
}
}
@@ -81,6 +81,14 @@ public class DashboardServiceImpl implements IDashboardService {
Page<Order> pageParam = new Page<>(page, limit);
Page<Order> resultPage = orderService.page(pageParam, wrapper);
// 添加调试日志
log.info("获取订单列表 - 参数: {}, 结果数量: {}", params, resultPage.getRecords().size());
if (!resultPage.getRecords().isEmpty()) {
Order firstOrder = resultPage.getRecords().get(0);
log.info("第一个订单数据 - orderNo: {}, userId: {}, orderAmount: {}",
firstOrder.getOrderNo(), firstOrder.getUserId(), firstOrder.getOrderAmount());
}
// 转换为PageResult
return PageResult.<Order>builder()
.data(resultPage.getRecords())
@@ -99,6 +107,22 @@ public class DashboardServiceImpl implements IDashboardService {
/**
* 获取订单统计(包含对账数据)
*
* 订单状态说明:
* - 有效订单:order_status IN (1, 3, 4, 5, 7, 8, 9)
* - 1: 已支付排队中
* - 3: 设备执行完成
* - 4: 正在服务中
* - 5: 素材上传中
* - 7: 退款中
* - 8: 已退款
* - 9: 退款失败(算作有效订单)
*
* - 收款订单:order_status IN (1, 3, 4, 5, 7)
* - 已支付但未退款的订单
*
* - 退款订单:order_status = 8
* - 已成功退款的订单
*/
private OrderStatistics getOrderStatistics(Map<String, Object> params) {
OrderStatistics stats = new OrderStatistics();
@@ -132,10 +156,19 @@ public class DashboardServiceImpl implements IDashboardService {
// 获取总收款订单数量
Long totalPaidOrders = dashboardMapper.getTotalPaidOrders(params);
stats.setTotalPaidOrders(totalPaidOrders);
// 添加调试日志
log.info("总收款订单数统计 - 参数: {}, 结果: {}", params, totalPaidOrders);
log.info("时间范围详情 - startTime: {}, endTime: {}", params.get("startTime"), params.get("endTime"));
// 获取今日收款订单数量
Long todayPaidOrders = dashboardMapper.getTodayPaidOrders(params);
stats.setTodayPaidOrders(todayPaidOrders);
// 添加调试日志
log.info("今日收款订单数统计 - 参数: {}, 结果: {}", params, todayPaidOrders);
log.info("时间范围参数 - startTime: {}, endTime: {}", params.get("startTime"), params.get("endTime"));
log.info("hasTimeRange判断: {}", (params.get("startTime") != null && params.get("endTime") != null));
// 获取退款订单数量
Long refundedOrders = dashboardMapper.getRefundedOrders(params);
@@ -164,21 +197,35 @@ public class DashboardServiceImpl implements IDashboardService {
* 获取图表统计
*/
private ChartStatistics getChartStatistics(Map<String, Object> params) {
ChartStatistics stats = new ChartStatistics();
// 获取订单趋势(最近7天)
stats.setOrderTrend(dashboardMapper.getOrderTrend(params));
// 获取订单状态分布
stats.setOrderDistribution(dashboardMapper.getOrderDistribution(params));
// 获取收入构成
stats.setIncomeBreakdown(dashboardMapper.getIncomeBreakdown(params));
// 获取二维码订单数量
stats.setQrcodeOrderCount(dashboardMapper.getQrcodeOrderCount(params));
return stats;
ChartStatistics chartStats = new ChartStatistics();
try {
// 获取订单趋势数据
List<TrendDataVO> orderTrend = dashboardMapper.getOrderTrend(params);
chartStats.setOrderTrend(orderTrend);
// 获取订单状态分布数据
List<DistributionDataVO> orderDistribution = dashboardMapper.getOrderDistribution(params);
chartStats.setOrderDistribution(orderDistribution);
// 获取收入构成数据
List<IncomeDataVO> incomeBreakdown = dashboardMapper.getIncomeBreakdown(params);
chartStats.setIncomeBreakdown(incomeBreakdown);
// 获取二维码订单数量数据
List<QrcodeOrderDataVO> qrcodeOrderCount = dashboardMapper.getQrcodeOrderCount(params);
chartStats.setQrcodeOrderCount(qrcodeOrderCount);
} catch (Exception e) {
log.error("获取图表统计数据失败", e);
// 设置空数据避免前端报错
chartStats.setOrderTrend(new ArrayList<>());
chartStats.setOrderDistribution(new ArrayList<>());
chartStats.setIncomeBreakdown(new ArrayList<>());
chartStats.setQrcodeOrderCount(new ArrayList<>());
}
return chartStats;
}
/**
@@ -192,9 +239,7 @@ public class DashboardServiceImpl implements IDashboardService {
// 获取二维码列表
options.setQrcodeList(dashboardMapper.getQrcodeOptions(params));
// 获取设备列表
options.setDeviceList(dashboardMapper.getDeviceOptions(params));
return options;
}
@@ -84,8 +84,10 @@ public class OrderServiceImpl extends SuperServiceImpl<OrderMapper, Order> imple
*/
@Override
public PageResult<Order> findList(Map<String, Object> params){
log.info("查询订单列表,参数: {}", params);
Page<Order> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
List<Order> list = baseMapper.findList(page, params);
log.info("查询结果数量: {}", list.size());
for (Order order : list){
order.setMobile(userCenterService.findUserById(order.getUserId()).getMobile());
order.setTourismName(tourismMapper.selectById(order.getTourismId()).getTourismName());
@@ -30,8 +30,10 @@ public class QrCodeServiceImpl extends SuperServiceImpl<QrCodeMapper, QrCode> im
*/
@Override
public PageResult<QrCode> findList(Map<String, Object> params){
log.info("查询二维码列表,参数: {}", params);
Page<QrCode> page = new Page<>(MapUtils.getInteger(params, "page"), MapUtils.getInteger(params, "limit"));
List<QrCode> list = baseMapper.findList(page, params);
log.info("查询结果数量: {}", list.size());
return PageResult.<QrCode>builder().data(list).resp_code(0).count(page.getTotal()).build();
}
@@ -4,20 +4,33 @@
<mapper namespace="com.central.order.mapper.OrderMapper">
<select id="findList" resultType="com.central.order.model.Order">
select * from orders t
SELECT o.*, t.tourism_name as tourismName
FROM orders o
LEFT JOIN tourisms t ON o.tourism_id = t.id
<where>
<if test="p.orderNo != null and p.orderNo != ''">
AND t.order_no LIKE CONCAT('%', #{p.orderNo}, '%')
</if>
<if test="p.deviceSn != null and p.deviceSn != ''">
AND t.deviceSn LIKE CONCAT('%', #{p.deviceSn}, '%')
AND o.order_no LIKE CONCAT('%', #{p.orderNo}, '%')
</if>
<if test="p.orderStatus != null">
AND t.order_status = #{p.orderStatus}
AND o.order_status = #{p.orderStatus}
</if>
<if test="p.tourismId != null">
AND o.tourism_id = #{p.tourismId}
</if>
<if test="p.deviceSn != null and p.deviceSn != ''">
AND o.device_sn LIKE CONCAT('%', #{p.deviceSn}, '%')
</if>
<if test="p.codeId != null and p.codeId != ''">
AND o.code_id LIKE CONCAT('%', #{p.codeId}, '%')
</if>
<if test="p.userId != null and p.userId != ''">
AND o.user_id LIKE CONCAT('%', #{p.userId}, '%')
</if>
<if test="p.mobile != null and p.mobile != ''">
AND o.mobile LIKE CONCAT('%', #{p.mobile}, '%')
</if>
</where>
ORDER BY t.id DESC
ORDER BY o.create_time DESC
</select>
<!-- 动态获取参数采用备参 -->
@@ -4,7 +4,34 @@
<mapper namespace="com.central.order.mapper.QrCodeMapper">
<select id="findList" resultType="com.central.order.model.QrCode">
select * from qrcodes t
SELECT * FROM qrcodes q
<where>
<if test="p.tourismId != null and p.tourismId != ''">
AND q.tourism_id = #{p.tourismId}
</if>
<if test="p.waylineId != null and p.waylineId != ''">
AND q.wayline_id = #{p.waylineId}
</if>
<if test="p.status != null">
AND q.status = #{p.status}
</if>
<if test="p.isTest != null">
AND q.is_test = #{p.isTest}
</if>
<if test="p.tenantId != null and p.tenantId != ''">
AND q.tenant_id = #{p.tenantId}
</if>
<if test="p.name != null and p.name != ''">
AND q.name LIKE CONCAT('%', #{p.name}, '%')
</if>
<if test="p.codeId != null and p.codeId != ''">
AND q.code_id LIKE CONCAT('%', #{p.codeId}, '%')
</if>
<if test="p.deviceSn != null and p.deviceSn != ''">
AND q.device_sn = #{p.deviceSn}
</if>
</where>
ORDER BY q.create_time DESC
</select>
<resultMap id="QrCodeResultMap" type="com.central.order.model.QrCode">
@@ -212,11 +212,14 @@ const Welcome: React.FC = () => {
// 根据时间筛选状态动态显示标题
const getOrderTitle = () => {
return '总订单数';
return '总收款数量';
};
const getTodayTitle = () => {
return '今日订单';
if (hasTimeRange) {
return '区间总收款'; // 时间筛选时显示区间总收款
}
return '今日总收款'; // 无时间筛选时显示今日总收款
};
const getTodayValue = () => {
@@ -237,6 +240,28 @@ const Welcome: React.FC = () => {
return orderStats.todayRefundedOrders || 0; // 无时间筛选时显示今日退款订单数
};
// 今日收款数量始终显示今日数据,不受时间范围影响
const getTodayPaidValue = () => {
if (hasTimeRange) {
// 时间筛选时:区间收款订单数 = 区间总订单数 - 区间退款订单数
const totalOrders = orderStats.totalOrders || 0;
const refundedOrders = orderStats.refundedOrders || 0;
return totalOrders - refundedOrders;
}
// 无时间筛选时:今日收款订单数 = 今日总订单数 - 今日退款订单数
const todayOrders = orderStats.todayOrders || 0;
const todayRefundedOrders = orderStats.todayRefundedOrders || 0;
return todayOrders - todayRefundedOrders;
};
// 获取今日收款数量标题
const getTodayPaidTitle = () => {
if (hasTimeRange) {
return '区间净收款'; // 时间筛选时显示区间净收款
}
return '今日净收款'; // 无时间筛选时显示今日净收款
};
// 获取订单状态文本
const getOrderStatusText = (status: number) => {
const statusMap: { [key: number]: string } = {
@@ -262,27 +287,53 @@ const Welcome: React.FC = () => {
switch (type) {
case 'today':
// 自然日:当天 00:00:00 到 23:59:59
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 23, 59, 59);
console.log('今日筛选 - 当前时间:', now.toISOString());
console.log('今日筛选 - 开始时间:', startDate.toISOString());
console.log('今日筛选 - 结束时间:', endDate.toISOString());
break;
case 'week':
// 自然周:本周一 00:00:00 到 本周日 23:59:59
const dayOfWeek = now.getDay();
const daysToSubtract = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 周一到周日
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - daysToSubtract);
const daysToMonday = dayOfWeek === 0 ? 6 : dayOfWeek - 1; // 距离本周一的天数
startDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() - daysToMonday);
endDate = new Date(now.getFullYear(), now.getMonth(), now.getDate() + (6 - dayOfWeek), 23, 59, 59);
console.log('本周筛选 - 当前时间:', now.toISOString());
console.log('本周筛选 - 开始时间:', startDate.toISOString());
console.log('本周筛选 - 结束时间:', endDate.toISOString());
break;
case 'month':
// 自然月:本月1号 00:00:00 到 本月最后一天 23:59:59
startDate = new Date(now.getFullYear(), now.getMonth(), 1);
endDate = new Date(now.getFullYear(), now.getMonth() + 1, 0, 23, 59, 59);
console.log('本月筛选 - 当前时间:', now.toISOString());
console.log('本月筛选 - 开始时间:', startDate.toISOString());
console.log('本月筛选 - 结束时间:', endDate.toISOString());
break;
default:
return;
}
setTimeRange([
startDate.toISOString().slice(0, 19).replace('T', ' '),
endDate.toISOString().slice(0, 19).replace('T', ' ')
]);
// 使用本地时间格式化,避免时区问题
const formatLocalDateTime = (date: Date) => {
const year = date.getFullYear();
const month = String(date.getMonth() + 1).padStart(2, '0');
const day = String(date.getDate()).padStart(2, '0');
const hours = String(date.getHours()).padStart(2, '0');
const minutes = String(date.getMinutes()).padStart(2, '0');
const seconds = String(date.getSeconds()).padStart(2, '0');
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
};
const timeRangeStrings: [string, string] = [
formatLocalDateTime(startDate),
formatLocalDateTime(endDate)
];
console.log('设置时间范围:', timeRangeStrings);
setTimeRange(timeRangeStrings);
};
// 动态分账金额计算(基于净收入和分账比例)
@@ -523,7 +574,7 @@ const Welcome: React.FC = () => {
value={orderStats.totalOrders || 0}
/>
<Statistic
title="总收款数量"
title="总净收款数量"
value={orderStats.totalPaidOrders || 0}
/>
<Statistic
@@ -534,8 +585,8 @@ const Welcome: React.FC = () => {
<div className={styles.subStats}>
<Statistic title={getTodayTitle()} value={getTodayValue()} />
<Statistic
title="今日收款数量"
value={orderStats.todayPaidOrders || 0}
title={getTodayPaidTitle()}
value={getTodayPaidValue()}
/>
<Statistic
title={getTodayRefundTitle()}
@@ -656,9 +707,6 @@ const Welcome: React.FC = () => {
<div style={{ fontWeight: 'bold', color: '#1890ff' }}>
¥{(order.orderAmount / 100).toFixed(2)}
</div>
<div style={{ fontSize: '12px', color: '#666' }}>
用户ID: {order.userId}
</div>
</div>
</div>
))}
@@ -27,7 +27,7 @@ const TableList: React.FC = () => {
// 渲染状态标签
const renderStatus = useCallback((status: number) => {
const statusInfo = STATUS_CONFIG[status] || { color: 'gray', text: '未知状态' };
const statusInfo = STATUS_CONFIG[status as keyof typeof STATUS_CONFIG] || { color: 'gray', text: '未知状态' };
return <Tag color={statusInfo.color}>{statusInfo.text}</Tag>;
}, []);
@@ -40,7 +40,7 @@ const TableList: React.FC = () => {
const result = await updateOrder({
id: currentRow.id,
orderStatus: fields.orderStatus,
});
} as any);
hide();
if (result.resp_code === 0) {
@@ -166,7 +166,10 @@ const TableList: React.FC = () => {
dataIndex: 'orderStatus',
render: (status) => renderStatus(status as number),
width: 120,
filters: STATUS_OPTIONS,
filters: STATUS_OPTIONS.map(option => ({
text: option.label,
value: option.value,
})),
filterMultiple: false,
},
{
@@ -210,9 +213,9 @@ const TableList: React.FC = () => {
return (
<PageContainer header={{ title: '订单管理' }}>
<QueryFilter
defaultCollapsed
defaultCollapsed={false}
split
span={8}
span={6}
className="query-filter"
onFinish={async (values) => {
// 处理查询参数
@@ -225,6 +228,7 @@ const TableList: React.FC = () => {
const validParams = Object.fromEntries(
Object.entries(params).filter(([_, value]) => value !== undefined && value !== '')
);
console.log('订单查询条件变化:', validParams);
setParams(validParams);
}}
>
@@ -246,6 +250,13 @@ const TableList: React.FC = () => {
placeholder="请选择景区"
options={tourismOptions}
allowClear
fieldProps={{
loading: !tourismOptions.length,
showSearch: true,
filterOption: (input, option) =>
(option?.label ?? '').toString().toLowerCase().includes(input.toLowerCase()),
notFoundContent: tourismOptions.length === 0 ? '暂无景区数据' : undefined,
}}
/>
</QueryFilter>
@@ -261,7 +272,7 @@ const TableList: React.FC = () => {
orderNo,
orderStatus: orderStatus ? Number(orderStatus) : undefined,
tourismId: tourismId ? Number(tourismId) : undefined,
});
} as any);
return result;
}}
actionRef={actionRef}
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect } from 'react';
import {
ModalForm,
ProForm,
@@ -42,6 +42,16 @@ const UpdateForm: React.FC<UpdateFormProps> = ({
const [form] = Form.useForm();
const enableProfit = Form.useWatch('enableProfit', form);
// 监听values变化,重置表单数据
useEffect(() => {
if (updateModalVisible && values) {
form.setFieldsValue({
...values,
enableProfit: values?.enableProfit ?? 0,
});
}
}, [values, updateModalVisible, form]);
return (
<ModalForm
title="修改二维码"
@@ -96,6 +96,8 @@ const TableList: React.FC = () => {
const [tenantOptions, setTenantOptions] = useState<any[]>([]);
const formRef = useRef();
// 将 renderStatus 函数移到组件内部
const renderStatus = (status: number) => {
const statusColorMap: Record<number, { color: string; text: string }> = {
@@ -503,7 +505,10 @@ const TableList: React.FC = () => {
split
span={6}
className="query-filter"
onFinish={setParams}
onFinish={(values) => {
console.log('查询条件变化:', values);
setParams(values);
}}
>
<ProFormSelect
name="tourismId"