fix(订单中心):首页统计数据规则修改,时间筛选无效bug修复,退款订单显示问题修复
This commit is contained in:
+32
@@ -18,6 +18,8 @@ import java.util.Map;
|
||||
import java.util.List;
|
||||
import com.central.order.model.vo.FilterOptions;
|
||||
import com.central.order.mapper.DashboardMapper;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.common.model.PageResult;
|
||||
|
||||
@Slf4j
|
||||
@RestController
|
||||
@@ -136,4 +138,34 @@ public class DashboardController {
|
||||
return Result.failed("调试失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "获取首页订单列表")
|
||||
@GetMapping("/orders")
|
||||
public Result<PageResult<Order>> getDashboardOrders(
|
||||
@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,
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "10") Integer limit) {
|
||||
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);
|
||||
params.put("page", page);
|
||||
params.put("limit", limit);
|
||||
|
||||
PageResult<Order> result = dashboardService.getDashboardOrders(params);
|
||||
return Result.succeed(result, "获取订单列表成功");
|
||||
} catch (Exception e) {
|
||||
log.error("获取订单列表失败", e);
|
||||
return Result.failed("获取订单列表失败:" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,6 +115,59 @@ public interface DashboardMapper {
|
||||
})
|
||||
Long getCompletedOrders(@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 = 8",
|
||||
"<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 <= #{p.endTime}",
|
||||
"</if>",
|
||||
"</script>"
|
||||
})
|
||||
Long getRefundedOrders(@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 = 8",
|
||||
"AND DATE(o.create_time) = CURDATE()",
|
||||
"<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 getTodayRefundedOrders(@Param("p") Map<String, Object> params);
|
||||
|
||||
// 对账相关统计
|
||||
@Select({
|
||||
"<script>",
|
||||
|
||||
+6
@@ -20,6 +20,12 @@ public class OrderStatistics {
|
||||
@Schema(description = "完成率")
|
||||
private BigDecimal completionRate;
|
||||
|
||||
@Schema(description = "退款订单数")
|
||||
private Long refundedOrders;
|
||||
|
||||
@Schema(description = "今日退款订单数")
|
||||
private Long todayRefundedOrders;
|
||||
|
||||
@Schema(description = "订单总金额(分)")
|
||||
private Long totalAmount;
|
||||
|
||||
|
||||
+8
-2
@@ -1,13 +1,19 @@
|
||||
package com.central.order.service;
|
||||
package com.central.order.service;
|
||||
|
||||
import com.central.order.model.vo.DashboardStatisticsVO;
|
||||
import com.central.common.model.PageResult;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface IDashboardService {
|
||||
/**
|
||||
* 获取首页统计数据
|
||||
* @param params 筛选参数
|
||||
*/
|
||||
DashboardStatisticsVO getDashboardStatistics(Map<String, Object> params);
|
||||
|
||||
/**
|
||||
* 获取首页订单列表
|
||||
*/
|
||||
PageResult<com.central.order.model.Order> getDashboardOrders(Map<String, Object> params);
|
||||
}
|
||||
|
||||
+65
@@ -11,6 +11,12 @@ import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ArrayList;
|
||||
import com.central.order.service.IOrderService;
|
||||
import com.central.order.model.Order;
|
||||
import com.central.common.model.PageResult;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
@@ -18,6 +24,7 @@ import java.util.Map;
|
||||
public class DashboardServiceImpl implements IDashboardService {
|
||||
|
||||
private final DashboardMapper dashboardMapper;
|
||||
private final IOrderService orderService;
|
||||
|
||||
@Override
|
||||
public DashboardStatisticsVO getDashboardStatistics(Map<String, Object> params) {
|
||||
@@ -40,6 +47,56 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
return statistics;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<com.central.order.model.Order> getDashboardOrders(Map<String, Object> params) {
|
||||
try {
|
||||
// 获取分页参数
|
||||
Integer page = (Integer) params.getOrDefault("page", 1);
|
||||
Integer limit = (Integer) params.getOrDefault("limit", 10);
|
||||
|
||||
// 构建查询条件
|
||||
LambdaQueryWrapper<Order> wrapper = new LambdaQueryWrapper<Order>()
|
||||
.orderByDesc(Order::getCreateTime);
|
||||
|
||||
// 如果有时间筛选条件,添加时间范围
|
||||
if (params.get("startTime") != null && !params.get("startTime").toString().isEmpty()) {
|
||||
wrapper.ge(Order::getCreateTime, params.get("startTime"));
|
||||
}
|
||||
if (params.get("endTime") != null && !params.get("endTime").toString().isEmpty()) {
|
||||
wrapper.le(Order::getCreateTime, params.get("endTime"));
|
||||
}
|
||||
|
||||
// 添加其他筛选条件
|
||||
if (params.get("tourismId") != null) {
|
||||
wrapper.eq(Order::getTourismId, params.get("tourismId"));
|
||||
}
|
||||
if (params.get("qrcodeId") != null && !params.get("qrcodeId").toString().isEmpty()) {
|
||||
wrapper.eq(Order::getCodeId, params.get("qrcodeId"));
|
||||
}
|
||||
if (params.get("deviceSn") != null && !params.get("deviceSn").toString().isEmpty()) {
|
||||
wrapper.eq(Order::getDeviceSn, params.get("deviceSn"));
|
||||
}
|
||||
|
||||
// 执行分页查询
|
||||
Page<Order> pageParam = new Page<>(page, limit);
|
||||
Page<Order> resultPage = orderService.page(pageParam, wrapper);
|
||||
|
||||
// 转换为PageResult
|
||||
return PageResult.<Order>builder()
|
||||
.data(resultPage.getRecords())
|
||||
.resp_code(0)
|
||||
.count(resultPage.getTotal())
|
||||
.build();
|
||||
} catch (Exception e) {
|
||||
log.error("获取首页订单列表失败", e);
|
||||
return PageResult.<Order>builder()
|
||||
.data(new ArrayList<>())
|
||||
.resp_code(0)
|
||||
.count(0L)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单统计(包含对账数据)
|
||||
*/
|
||||
@@ -70,6 +127,14 @@ public class DashboardServiceImpl implements IDashboardService {
|
||||
stats.setCompletionRate(completionRate);
|
||||
}
|
||||
|
||||
// 获取退款订单数量
|
||||
Long refundedOrders = dashboardMapper.getRefundedOrders(params);
|
||||
stats.setRefundedOrders(refundedOrders);
|
||||
|
||||
// 获取今日退款订单数量
|
||||
Long todayRefundedOrders = dashboardMapper.getTodayRefundedOrders(params);
|
||||
stats.setTodayRefundedOrders(todayRefundedOrders);
|
||||
|
||||
// 获取对账相关数据 - 使用 orders 表的数据
|
||||
Long totalAmount = dashboardMapper.getTotalAmount(params);
|
||||
Long refundAmount = dashboardMapper.getRefundAmount(params);
|
||||
|
||||
Reference in New Issue
Block a user