fix(订单中心):首页统计数据规则修改,时间筛选无效bug修复

This commit is contained in:
2025-08-04 20:29:06 +08:00
parent b830b201f7
commit fdcf22832a
3 changed files with 121 additions and 9 deletions
@@ -75,4 +75,65 @@ public class DashboardController {
return Result.failed("获取二维码选项失败:" + e.getMessage());
}
}
@Operation(summary = "测试时间参数传递")
@GetMapping("/test-time-params")
public Result<Map<String, Object>> testTimeParams(
@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, 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);
// 测试各个统计方法
Long totalOrders = dashboardMapper.getTotalOrders(params);
Long totalAmount = dashboardMapper.getTotalAmount(params);
Long refundAmount = dashboardMapper.getRefundAmount(params);
Map<String, Object> result = new HashMap<>();
result.put("params", params);
result.put("totalOrders", totalOrders);
result.put("totalAmount", totalAmount);
result.put("refundAmount", refundAmount);
return Result.succeed(result, "测试时间参数成功");
} catch (Exception e) {
log.error("测试时间参数失败", e);
return Result.failed("测试失败:" + e.getMessage());
}
}
@Operation(summary = "调试数据库时间查询")
@GetMapping("/debug-time-query")
public Result<Map<String, Object>> debugTimeQuery(
@Parameter(description = "开始时间") @RequestParam(required = false) String startTime,
@Parameter(description = "结束时间") @RequestParam(required = false) String endTime) {
try {
Map<String, Object> params = new HashMap<>();
params.put("startTime", startTime);
params.put("endTime", endTime);
// 直接查询数据库中的时间范围数据
List<Map<String, Object>> timeRangeData = dashboardMapper.debugTimeRangeQuery(params);
Map<String, Object> result = new HashMap<>();
result.put("params", params);
result.put("timeRangeData", timeRangeData);
result.put("dataCount", timeRangeData.size());
return Result.succeed(result, "调试时间查询成功");
} catch (Exception e) {
log.error("调试时间查询失败", e);
return Result.failed("调试失败:" + e.getMessage());
}
}
}
@@ -241,7 +241,12 @@ public interface DashboardMapper {
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
" AND o.create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)",
"<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>",
"<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
@@ -263,8 +268,13 @@ public interface DashboardMapper {
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
" AND o.create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)",
" AND o.order_status = 3",
"<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>",
"<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
@@ -286,8 +296,13 @@ public interface DashboardMapper {
"<if test='p.includeTestQrcodes == null or p.includeTestQrcodes == false'>",
" AND q.is_test = 0",
"</if>",
" AND o.create_time >= DATE_SUB(CURDATE(), INTERVAL 7 DAY)",
" AND o.order_status = 8",
"<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>",
"<if test='p.tourismId != null'>",
" AND o.tourism_id = #{p.tourismId}",
"</if>",
@@ -454,4 +469,28 @@ public interface DashboardMapper {
"</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);
}