|
|
@@ -731,81 +731,128 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
return success;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 查询咨询订单信息(律师端)
|
|
|
+ *
|
|
|
+ * @param pageNum 页码
|
|
|
+ * @param pageSize 页容
|
|
|
+ * @param startDate 开始时间
|
|
|
+ * @param endDate 结束时间
|
|
|
+ * @param lawyerId 律师ID
|
|
|
+ * @return 订单信息Map,包含订单列表、总数、进行中数量、已完成数量
|
|
|
+ */
|
|
|
@Override
|
|
|
public Map<String, Object> getLawyerConsultationOrderInfo(int pageNum, int pageSize, String startDate, String endDate, String lawyerId) {
|
|
|
+ log.info("LawyerConsultationOrderServiceImpl.getLawyerConsultationOrderInfo?pageNum={},pageSize={},startDate={},endDate={},lawyerId={}",
|
|
|
+ pageNum, pageSize, startDate, endDate, lawyerId);
|
|
|
+
|
|
|
Map<String, Object> resultMap = new HashMap<>();
|
|
|
- Page<LawyerConsultationOrderVO> page = new Page<>(pageNum, pageSize);
|
|
|
|
|
|
- // 如果按律师姓名搜索,先查询匹配的律师ID列表
|
|
|
+ // 参数校验:律师ID不能为空
|
|
|
if (!StringUtils.hasText(lawyerId)) {
|
|
|
+ log.warn("查询咨询订单信息失败:律师ID为空");
|
|
|
Page<LawyerConsultationOrderVO> emptyPage = new Page<>(pageNum, pageSize);
|
|
|
emptyPage.setRecords(Collections.emptyList());
|
|
|
emptyPage.setTotal(0);
|
|
|
- // return R.data(emptyPage);
|
|
|
+ resultMap.put("lawyerOrderCount", 0L);
|
|
|
+ resultMap.put("lawyerInProgressOrderCount", 0);
|
|
|
+ resultMap.put("lawyerCompleteOrderCount", 0);
|
|
|
+ resultMap.put("lawyerConsultationOrderList", Collections.emptyList());
|
|
|
+ return resultMap;
|
|
|
}
|
|
|
|
|
|
- // 查询订单列表
|
|
|
- QueryWrapper<LawyerConsultationOrderVO> lawyerConsultationOrderQueryWrapper = new QueryWrapper<>();
|
|
|
- lawyerConsultationOrderQueryWrapper.in("lco.order_status", Arrays.asList("2", "3"));
|
|
|
- lawyerConsultationOrderQueryWrapper.eq("lco.lawyer_user_id", lawyerId);
|
|
|
- if(StringUtils.hasText(startDate) && StringUtils.hasText(startDate)){
|
|
|
- lawyerConsultationOrderQueryWrapper.between("lco.payment_time", startDate + " 00:00:00", endDate + " 23:59:59");
|
|
|
- }
|
|
|
- lawyerConsultationOrderQueryWrapper.eq("lco.delete_flag", 0);
|
|
|
- IPage<LawyerConsultationOrderVO> voPage = consultationOrderMapper.getLawyerConsultationOrderList(
|
|
|
- page, lawyerConsultationOrderQueryWrapper);
|
|
|
+ // 创建分页对象
|
|
|
+ Page<LawyerConsultationOrderVO> page = new Page<>(pageNum, pageSize);
|
|
|
|
|
|
- // 填充律师问题场景信息
|
|
|
- fillLawyerServiceArea(voPage);
|
|
|
+ // 构建查询条件:查询进行中(2)和已完成(3)状态的订单
|
|
|
+ QueryWrapper<LawyerConsultationOrderVO> queryWrapper = new QueryWrapper<>();
|
|
|
+ queryWrapper.in("lco.order_status", Arrays.asList("2", "3"));
|
|
|
+ queryWrapper.eq("lco.lawyer_user_id", lawyerId);
|
|
|
+ queryWrapper.eq("lco.delete_flag", 0);
|
|
|
|
|
|
- // 為待支付訂單計算倒計時(30分鐘有效期)
|
|
|
- if (voPage != null && voPage.getRecords() != null) {
|
|
|
- Date now = new Date();
|
|
|
- long validitySeconds = 30 * 60; // 30分鐘 = 1800秒
|
|
|
+ // 时间范围查询:如果开始时间和结束时间都存在,则进行范围查询
|
|
|
+ if (StringUtils.hasText(startDate) && StringUtils.hasText(endDate)) {
|
|
|
+ queryWrapper.between("lco.payment_time", startDate + " 00:00:00", endDate + " 23:59:59");
|
|
|
+ }
|
|
|
|
|
|
- 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);
|
|
|
- }
|
|
|
- }
|
|
|
+ // 查询订单列表
|
|
|
+ IPage<LawyerConsultationOrderVO> voPage = consultationOrderMapper.getLawyerConsultationOrderList(page, queryWrapper);
|
|
|
+
|
|
|
+ // 填充律师问题场景信息
|
|
|
+ if (voPage != null) {
|
|
|
+ fillLawyerServiceArea(voPage);
|
|
|
+ // 为待支付订单计算倒计时(30分钟有效期)
|
|
|
+ calculateCountdownForPendingOrders(voPage);
|
|
|
}
|
|
|
|
|
|
- //订单总数
|
|
|
- resultMap.put("lawyerOrderCount", voPage.getTotal());
|
|
|
+ // 统计订单总数
|
|
|
+ long totalCount = voPage != null ? voPage.getTotal() : 0L;
|
|
|
+ resultMap.put("lawyerOrderCount", totalCount);
|
|
|
|
|
|
- //进行中数据
|
|
|
- LambdaQueryWrapper<LawyerConsultationOrder> lawyerConsultationOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- lawyerConsultationOrderLambdaQueryWrapper.eq(LawyerConsultationOrder::getLawyerUserId, lawyerId);
|
|
|
- lawyerConsultationOrderLambdaQueryWrapper.eq(LawyerConsultationOrder::getDeleteFlag, 0);
|
|
|
- lawyerConsultationOrderLambdaQueryWrapper.eq(LawyerConsultationOrder::getOrderStatus, LawyerStatusEnum.INPROGRESS.getStatus());
|
|
|
- int inProgressCount = consultationOrderMapper.selectCount(lawyerConsultationOrderLambdaQueryWrapper);
|
|
|
+ // 统计进行中订单数量
|
|
|
+ int inProgressCount = countOrdersByStatus(lawyerId, LawyerStatusEnum.INPROGRESS.getStatus());
|
|
|
resultMap.put("lawyerInProgressOrderCount", inProgressCount);
|
|
|
|
|
|
- //已完成数据
|
|
|
- lawyerConsultationOrderLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
- lawyerConsultationOrderLambdaQueryWrapper.eq(LawyerConsultationOrder::getLawyerUserId, lawyerId);
|
|
|
- lawyerConsultationOrderLambdaQueryWrapper.eq(LawyerConsultationOrder::getDeleteFlag, 0);
|
|
|
- lawyerConsultationOrderLambdaQueryWrapper.eq(LawyerConsultationOrder::getOrderStatus, LawyerStatusEnum.COMPLETE.getStatus());
|
|
|
- int completeCount = consultationOrderMapper.selectCount(lawyerConsultationOrderLambdaQueryWrapper);
|
|
|
+ // 统计已完成订单数量
|
|
|
+ int completeCount = countOrdersByStatus(lawyerId, LawyerStatusEnum.COMPLETE.getStatus());
|
|
|
resultMap.put("lawyerCompleteOrderCount", completeCount);
|
|
|
|
|
|
- resultMap.put("lawyerConsultationOrderList", voPage.getRecords());
|
|
|
+ // 设置订单列表
|
|
|
+ List<LawyerConsultationOrderVO> orderList = voPage != null && voPage.getRecords() != null
|
|
|
+ ? voPage.getRecords() : Collections.emptyList();
|
|
|
+ resultMap.put("lawyerConsultationOrderList", orderList);
|
|
|
+
|
|
|
return resultMap;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 为待支付订单计算倒计时(30分钟有效期)
|
|
|
+ *
|
|
|
+ * @param voPage 订单分页对象
|
|
|
+ */
|
|
|
+ private void calculateCountdownForPendingOrders(IPage<LawyerConsultationOrderVO> voPage) {
|
|
|
+ if (voPage == null || voPage.getRecords() == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Date now = new Date();
|
|
|
+ long validitySeconds = 30 * 60; // 30分钟 = 1800秒
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 根据律师ID和订单状态统计订单数量
|
|
|
+ *
|
|
|
+ * @param lawyerId 律师ID
|
|
|
+ * @param orderStatus 订单状态
|
|
|
+ * @return 订单数量
|
|
|
+ */
|
|
|
+ private int countOrdersByStatus(String lawyerId, Integer orderStatus) {
|
|
|
+ LambdaQueryWrapper<LawyerConsultationOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(LawyerConsultationOrder::getLawyerUserId, lawyerId);
|
|
|
+ queryWrapper.eq(LawyerConsultationOrder::getDeleteFlag, 0);
|
|
|
+ queryWrapper.eq(LawyerConsultationOrder::getOrderStatus, orderStatus);
|
|
|
+ return consultationOrderMapper.selectCount(queryWrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 填充律师信息到订单VO
|
|
|
*
|
|
|
* @param orderVO 订单VO对象
|