|
|
@@ -561,56 +561,188 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
* @return 分页订单列表
|
|
|
*/
|
|
|
@Override
|
|
|
- public R<IPage<LawyerConsultationOrderVO>> getConsultationOrderListById(int pageNum, int pageSize,
|
|
|
+ public Map<String, Object> getConsultationOrderListById(int pageNum, int pageSize,
|
|
|
String userId, String orderStatus,
|
|
|
String lawyerName) {
|
|
|
- Page<LawyerConsultationOrderVO> page = new Page<>(pageNum, pageSize);
|
|
|
+ log.info("查询咨询订单信息(律师端)- pageNum={}, pageSize={}, userId={},"
|
|
|
+ + "orderStatus={}, lawyerName={}",
|
|
|
+ pageNum, pageSize,userId, orderStatus, lawyerName);
|
|
|
|
|
|
- // 如果按律师姓名搜索,先查询匹配的律师ID列表
|
|
|
- List<Integer> lawyerUserIds = null;
|
|
|
- if (StringUtils.hasText(lawyerName)) {
|
|
|
- lawyerUserIds = queryLawyerIdsByName(lawyerName);
|
|
|
- // 如果没有找到匹配的律师,返回空结果
|
|
|
- if (CollectionUtils.isEmpty(lawyerUserIds)) {
|
|
|
- Page<LawyerConsultationOrderVO> emptyPage = new Page<>(pageNum, pageSize);
|
|
|
- emptyPage.setRecords(Collections.emptyList());
|
|
|
- emptyPage.setTotal(0);
|
|
|
- return R.data(emptyPage);
|
|
|
- }
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 参数校验:用户ID不能为空
|
|
|
+ if (!StringUtils.hasText(userId)) {
|
|
|
+ log.warn("查询咨询订单信息失败:用户ID不为空");
|
|
|
+ return buildEmptyResultMap(pageNum, pageSize);
|
|
|
}
|
|
|
|
|
|
+ // 创建分页对象
|
|
|
+ Page<LawyerConsultationOrderVO> page = new Page<>(pageNum, pageSize);
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ QueryWrapper<LawyerConsultationOrderVO> queryWrapper = buildOrderQueryWrapper(
|
|
|
+ lawyerName, orderStatus, userId);
|
|
|
+ QueryWrapper<LawyerConsultationOrderVO> statisticsWrapper = buildStatisticsQueryWrapper(
|
|
|
+ lawyerName, userId);
|
|
|
+
|
|
|
// 查询订单列表
|
|
|
- IPage<LawyerConsultationOrderVO> voPage = consultationOrderMapper.getConsultationOrderListById(
|
|
|
- page, userId, orderStatus, lawyerUserIds);
|
|
|
+ IPage<LawyerConsultationOrderVO> voPage = consultationOrderMapper.getLawyerConsultationOrderList(
|
|
|
+ page, queryWrapper);
|
|
|
|
|
|
// 填充律师问题场景信息
|
|
|
- fillLawyerServiceArea(voPage);
|
|
|
+ if (voPage != null) {
|
|
|
+ fillLawyerServiceArea(voPage);
|
|
|
+ // 为待支付订单计算倒计时(30分钟有效期)
|
|
|
+ calculateCountdownForPendingOrders(voPage);
|
|
|
+ }
|
|
|
|
|
|
- // 為待支付訂單計算倒計時(30分鐘有效期)
|
|
|
- if (voPage != null && voPage.getRecords() != null) {
|
|
|
- Date now = new Date();
|
|
|
- long validitySeconds = 30 * 60; // 30分鐘 = 1800秒
|
|
|
+ // 获取统计信息
|
|
|
+ statisticsWrapper.groupBy("lco.order_status");
|
|
|
+ List<Map<String, Object>> statisticsInfo = consultationOrderMapper.getLawyerStatisticsInfo(
|
|
|
+ statisticsWrapper);
|
|
|
|
|
|
- for (LawyerConsultationOrderVO vo : voPage.getRecords()) {
|
|
|
- // 僅對待支付訂單(orderStatus=0)計算倒計時
|
|
|
- if (vo.getOrderStatus() != null && vo.getOrderStatus() == 0) {
|
|
|
- Date orderTime = vo.getOrderTime();
|
|
|
- if (orderTime != null) {
|
|
|
- long elapsedSeconds = (now.getTime() - orderTime.getTime()) / 1000;
|
|
|
- long remainingSeconds = validitySeconds - elapsedSeconds;
|
|
|
- // 如果已過期,設置為0
|
|
|
- vo.setCountdownSeconds(Math.max(0, remainingSeconds));
|
|
|
- } else {
|
|
|
- vo.setCountdownSeconds(0L);
|
|
|
- }
|
|
|
- } else {
|
|
|
- // 非待支付訂單,倒計時為null
|
|
|
- vo.setCountdownSeconds(null);
|
|
|
- }
|
|
|
+ // 构建状态统计Map
|
|
|
+ Map<Integer, Integer> statusCountMap = buildStatusCountMap(statisticsInfo);
|
|
|
+
|
|
|
+ // 统计待支付订单数量
|
|
|
+ Integer waitPayStatus = LawyerStatusEnum.WAIT_PAY.getStatus();
|
|
|
+ int waitPayStatusCount = statusCountMap.getOrDefault(waitPayStatus, 0);
|
|
|
+
|
|
|
+ // 统计待接单订单数量
|
|
|
+ Integer waitAcceptStatus = LawyerStatusEnum.WAIT_ACCEPT.getStatus();
|
|
|
+ int waitAcceptStatusCount = statusCountMap.getOrDefault(waitAcceptStatus, 0);
|
|
|
+
|
|
|
+ // 统计进行中订单数量
|
|
|
+ Integer inProgressStatus = LawyerStatusEnum.INPROGRESS.getStatus();
|
|
|
+ int inProgressCount = statusCountMap.getOrDefault(inProgressStatus, 0);
|
|
|
+
|
|
|
+ // 统计已完成订单数量
|
|
|
+ Integer completeStatus = LawyerStatusEnum.COMPLETE.getStatus();
|
|
|
+ int completeCount = statusCountMap.getOrDefault(completeStatus, 0);
|
|
|
+
|
|
|
+ // 统计已取消订单数量
|
|
|
+ Integer cancelStatus = LawyerStatusEnum.CANCEL.getStatus();
|
|
|
+ int cancelStatusCount = statusCountMap.getOrDefault(cancelStatus, 0);
|
|
|
+
|
|
|
+ // 统计已退款订单数量
|
|
|
+ Integer refundedStatus = LawyerStatusEnum.REFUNDED.getStatus();
|
|
|
+ int refundedStatusCount = statusCountMap.getOrDefault(refundedStatus, 0);
|
|
|
+
|
|
|
+ // 构建返回结果
|
|
|
+ resultMap.put("lawyerWaitPayStatusOrderCount", waitPayStatusCount);
|
|
|
+ resultMap.put("lawyerWaitAcceptStatusOrderCount", waitAcceptStatusCount);
|
|
|
+ resultMap.put("lawyerInProgressOrderCount", inProgressCount);
|
|
|
+ resultMap.put("lawyerCompleteOrderCount", completeCount);
|
|
|
+ resultMap.put("lawyerCancelStatusOrderCount", cancelStatusCount);
|
|
|
+ resultMap.put("lawyerRefundedStatusOrderCount", refundedStatusCount);
|
|
|
+ resultMap.put("lawyerOrderCount", (long) (waitPayStatusCount + waitAcceptStatusCount + inProgressCount + completeCount + cancelStatusCount + refundedStatusCount));
|
|
|
+
|
|
|
+ // 设置订单列表
|
|
|
+ List<LawyerConsultationOrderVO> orderList = (voPage != null && voPage.getRecords() != null)
|
|
|
+ ? voPage.getRecords() : Collections.emptyList();
|
|
|
+ resultMap.put("lawyerConsultationOrderList", orderList);
|
|
|
+
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建状态统计Map
|
|
|
+ *
|
|
|
+ * @param statisticsInfo 统计信息列表
|
|
|
+ * @return 状态统计Map,key为订单状态,value为订单数量
|
|
|
+ */
|
|
|
+ private Map<Integer, Integer> buildStatusCountMap(List<Map<String, Object>> statisticsInfo) {
|
|
|
+ Map<Integer, Integer> statusCountMap = new HashMap<>();
|
|
|
+ if (CollectionUtils.isEmpty(statisticsInfo)) {
|
|
|
+ return statusCountMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (Map<String, Object> map : statisticsInfo) {
|
|
|
+ Object statusObj = map.get("order_status");
|
|
|
+ Object countObj = map.get("order_count");
|
|
|
+
|
|
|
+ if (statusObj == null || countObj == null) {
|
|
|
+ continue;
|
|
|
}
|
|
|
+
|
|
|
+ Integer status = (Integer) statusObj;
|
|
|
+ // COUNT(*) 返回类型可能是Long
|
|
|
+ Long countLong = (Long) countObj;
|
|
|
+ statusCountMap.put(status, countLong.intValue());
|
|
|
}
|
|
|
|
|
|
- return R.data(voPage);
|
|
|
+ return statusCountMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建统计查询条件
|
|
|
+ *
|
|
|
+ * @param lawyerName 律师ID
|
|
|
+ * @param userId 客户端用户名
|
|
|
+ * @return 统计查询条件包装器
|
|
|
+ */
|
|
|
+ private QueryWrapper<LawyerConsultationOrderVO> buildStatisticsQueryWrapper(String lawyerName,
|
|
|
+ String userId) {
|
|
|
+ QueryWrapper<LawyerConsultationOrderVO> queryWrapper = new QueryWrapper<>();
|
|
|
+ if(StringUtils.hasText(lawyerName)){
|
|
|
+ queryWrapper.like("lu.name", lawyerName);
|
|
|
+ }
|
|
|
+ queryWrapper.like("lco.client_user_id", userId);
|
|
|
+ queryWrapper.eq("lco.delete_flag", 0);
|
|
|
+ return queryWrapper;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建空结果Map
|
|
|
+ *
|
|
|
+ * @param pageNum 页码
|
|
|
+ * @param pageSize 页容量
|
|
|
+ * @return 空结果Map
|
|
|
+ */
|
|
|
+ private Map<String, Object> buildEmptyResultMap(int pageNum, int pageSize) {
|
|
|
+ Map<String, Object> resultMap = new HashMap<>();
|
|
|
+ Page<LawyerConsultationOrderVO> emptyPage = new Page<>(pageNum, pageSize);
|
|
|
+ emptyPage.setRecords(Collections.emptyList());
|
|
|
+ emptyPage.setTotal(0);
|
|
|
+ resultMap.put("lawyerOrderCount", 0L);
|
|
|
+ resultMap.put("lawyerInProgressOrderCount", 0);
|
|
|
+ resultMap.put("lawyerCompleteOrderCount", 0);
|
|
|
+ resultMap.put("lawyerConsultationOrderList", Collections.emptyList());
|
|
|
+ return resultMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构建订单查询条件
|
|
|
+ *
|
|
|
+ * @param lawyerName 律师名称
|
|
|
+ * @param orderStatus 订单状态
|
|
|
+ * @param userId 客户端用户名
|
|
|
+ * @return 查询条件包装器
|
|
|
+ */
|
|
|
+ private QueryWrapper<LawyerConsultationOrderVO> buildOrderQueryWrapper(String lawyerName, String orderStatus,
|
|
|
+ String userId) {
|
|
|
+ QueryWrapper<LawyerConsultationOrderVO> queryWrapper = new QueryWrapper<>();
|
|
|
+
|
|
|
+ // 订单状态条件
|
|
|
+ if (StringUtils.hasText(orderStatus)) {
|
|
|
+ queryWrapper.in("lco.order_status", Collections.singletonList(orderStatus));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 律师名称条件
|
|
|
+ if(StringUtils.hasText(lawyerName)){
|
|
|
+ queryWrapper.like("lu.name", lawyerName);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 客户端用户名条件
|
|
|
+ queryWrapper.eq("lco.client_user_id", userId);
|
|
|
+
|
|
|
+ // 删除标记条件
|
|
|
+ queryWrapper.eq("lco.delete_flag", 0);
|
|
|
+
|
|
|
+ // 排序条件
|
|
|
+ queryWrapper.orderByDesc("lco.created_time");
|
|
|
+ return queryWrapper;
|
|
|
}
|
|
|
|
|
|
/**
|