|
|
@@ -3,6 +3,7 @@ package shop.alien.lawyer.service.impl;
|
|
|
import com.alibaba.fastjson2.JSON;
|
|
|
import com.alibaba.fastjson2.JSONObject;
|
|
|
import com.alibaba.nacos.common.utils.CollectionUtils;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
@@ -361,6 +362,8 @@ public class LawyerClientConsultationOrderServiceImpl extends ServiceImpl<Lawyer
|
|
|
fillLawyerServiceArea(voPage);
|
|
|
// 为待支付订单计算倒计时(30分钟有效期)
|
|
|
calculateCountdownForPendingOrders(voPage);
|
|
|
+ //填充未读消息
|
|
|
+ fillUnreadMessage(voPage,lawyerId);
|
|
|
}
|
|
|
|
|
|
// 获取统计信息
|
|
|
@@ -377,6 +380,58 @@ public class LawyerClientConsultationOrderServiceImpl extends ServiceImpl<Lawyer
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 填充未读消息数量
|
|
|
+ *
|
|
|
+ * @param voPage 订单VO分页对象
|
|
|
+ */
|
|
|
+ private void fillUnreadMessage(IPage<LawyerConsultationOrderVO> voPage,String lawyerId) {
|
|
|
+ List<LawyerConsultationOrderVO> orderList = voPage.getRecords();
|
|
|
+ if (CollectionUtils.isEmpty(orderList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 提取所有律师ID,并加上lawyer_前缀
|
|
|
+ List<String> lawyerIdList = orderList.stream()
|
|
|
+ .map(LawyerConsultationOrderVO::getClientUserPhone)
|
|
|
+ .filter(Objects::nonNull)
|
|
|
+ .map(phone -> "user_" + phone)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+
|
|
|
+ if (CollectionUtils.isEmpty(lawyerIdList)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ LawyerUser lawyerUser = lawyerUserMapper.selectById(lawyerId);
|
|
|
+ String phone = lawyerUser.getPhone();
|
|
|
+
|
|
|
+ LambdaQueryWrapper<LifeMessage> lifeMessageLambdaQueryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ lifeMessageLambdaQueryWrapper.in(LifeMessage::getSenderId, lawyerIdList);
|
|
|
+ lifeMessageLambdaQueryWrapper.eq(LifeMessage::getDeleteFlag, 0);
|
|
|
+ lifeMessageLambdaQueryWrapper.eq(LifeMessage::getIsRead, 0);
|
|
|
+ lifeMessageLambdaQueryWrapper.eq(LifeMessage::getReceiverId, "lawyer_" + phone);
|
|
|
+ List<LifeMessage> lifeMessageList = lifeMessageMapper.selectList(lifeMessageLambdaQueryWrapper);
|
|
|
+
|
|
|
+
|
|
|
+ // 按照senderId进行分组,返回senderId和数量的map
|
|
|
+ Map<String, Long> senderIdCountMap = new HashMap<>();
|
|
|
+ if(CollectionUtils.isNotEmpty(lifeMessageList)){
|
|
|
+ senderIdCountMap = lifeMessageList.stream()
|
|
|
+ .collect(Collectors.groupingBy(LifeMessage::getSenderId, Collectors.counting()));
|
|
|
+ }
|
|
|
+
|
|
|
+ for(LawyerConsultationOrderVO lawyerConsultationOrderVO : voPage.getRecords()){
|
|
|
+ String lawyerPhone = "user_" + lawyerConsultationOrderVO.getClientUserPhone();
|
|
|
+ if(!senderIdCountMap.isEmpty() && senderIdCountMap.containsKey(lawyerPhone) && lawyerConsultationOrderVO.getOrderStatus() == 2){
|
|
|
+ long messageCount = senderIdCountMap.get(lawyerPhone);
|
|
|
+ lawyerConsultationOrderVO.setUnreadMessage(messageCount);
|
|
|
+ } else {
|
|
|
+ lawyerConsultationOrderVO.setUnreadMessage(0L);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 构建空结果Map
|
|
|
*
|
|
|
* @param pageNum 页码
|