|
|
@@ -19,10 +19,13 @@ import shop.alien.mapper.*;
|
|
|
import shop.alien.store.service.LifeMessageService;
|
|
|
import shop.alien.store.service.LifeUserService;
|
|
|
import shop.alien.util.common.JwtUtil;
|
|
|
+import shop.alien.util.common.constant.LawyerStatusEnum;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
import java.util.Objects;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
@@ -42,10 +45,14 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
private final LifeBlacklistMapper lifeBlacklistMapper;
|
|
|
private final LifeNoticeMapper lifeNoticeMapper;
|
|
|
private final LawyerUserMapper lawyerUserMapper;
|
|
|
+ private final LawyerConsultationOrderMapper lawyerConsultationOrderMapper;
|
|
|
|
|
|
@Override
|
|
|
public List<LifeMessageVo> getMessageList(String receiverId, int friendType, String search) throws Exception {
|
|
|
try {
|
|
|
+ if (receiverId == null) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
String blockerType = "user".equals(Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getString("userType")) ? "2" : "1";
|
|
|
String blockerId = JwtUtil.getCurrentUserInfo().getString("userId");
|
|
|
QueryWrapper<LifeFansVo> wrapper = new QueryWrapper<>();
|
|
|
@@ -84,6 +91,21 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
List<LifeMessageVo> lifeMessagePageList = lifeMessageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
|
|
|
List<LifeMessageVo> lifeMessagePageResultList = new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(lifeMessagePageList)) {
|
|
|
+ boolean currentIsUser = receiverId != null && receiverId.startsWith("user_");
|
|
|
+ boolean currentIsLawyer = receiverId != null && receiverId.startsWith("lawyer_");
|
|
|
+ Integer currentUserId = null;
|
|
|
+ Integer currentLawyerId = null;
|
|
|
+ if (currentIsUser) {
|
|
|
+ LifeUser currentUser = lifeUserMapper.selectOne(new QueryWrapper<LifeUser>()
|
|
|
+ .eq("user_phone", receiverId.substring(5)));
|
|
|
+ currentUserId = currentUser != null ? currentUser.getId() : null;
|
|
|
+ } else if (currentIsLawyer) {
|
|
|
+ LawyerUser currentLawyer = lawyerUserMapper.selectOne(new QueryWrapper<LawyerUser>()
|
|
|
+ .eq("phone", receiverId.substring(7)));
|
|
|
+ currentLawyerId = currentLawyer != null ? currentLawyer.getId() : null;
|
|
|
+ }
|
|
|
+ Map<String, Boolean> chatEnabledCache = new HashMap<>();
|
|
|
+
|
|
|
// 当前用户的所有关注
|
|
|
LambdaQueryWrapper<LifeFans> followWrapper = new LambdaQueryWrapper<>();
|
|
|
followWrapper.eq(LifeFans::getFansId, receiverId);
|
|
|
@@ -112,6 +134,28 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
List<String> notDisturbList = lifeMessageNotDisturbMapper.selectList(notDisturbWrapper).stream().map(LifeMessageNotDisturb::getNotDisturbId).collect(Collectors.toList());
|
|
|
|
|
|
for (LifeMessageVo messageVo : lifeMessagePageList) {
|
|
|
+ messageVo.setCanChat(true);
|
|
|
+ String messagePhoneId = messageVo.getPhoneId();
|
|
|
+ if (messagePhoneId != null && (currentIsUser || currentIsLawyer)) {
|
|
|
+ if (currentIsUser && messagePhoneId.startsWith("lawyer_")) {
|
|
|
+ Integer lawyerId = messageVo.getUserId();
|
|
|
+ if (lawyerId == null) {
|
|
|
+ LawyerUser lawyerUser = lawyerUserMapper.selectOne(new QueryWrapper<LawyerUser>()
|
|
|
+ .eq("phone", messagePhoneId.substring(7)));
|
|
|
+ lawyerId = lawyerUser != null ? lawyerUser.getId() : null;
|
|
|
+ }
|
|
|
+ messageVo.setCanChat(isChatEnabled(currentUserId, lawyerId, chatEnabledCache));
|
|
|
+ } else if (currentIsLawyer && messagePhoneId.startsWith("user_")) {
|
|
|
+ Integer userId = messageVo.getUserId();
|
|
|
+ if (userId == null) {
|
|
|
+ LifeUser lifeUser = lifeUserMapper.selectOne(new QueryWrapper<LifeUser>()
|
|
|
+ .eq("user_phone", messagePhoneId.substring(5)));
|
|
|
+ userId = lifeUser != null ? lifeUser.getId() : null;
|
|
|
+ }
|
|
|
+ messageVo.setCanChat(isChatEnabled(userId, currentLawyerId, chatEnabledCache));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// 免打扰
|
|
|
if (notDisturbList.contains(messageVo.getPhoneId())) {
|
|
|
messageVo.setIsNotDisturb("1");
|
|
|
@@ -144,7 +188,6 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
messageVo.setIsMerchant("0");
|
|
|
}
|
|
|
|
|
|
- String senderId = messageVo.getPhoneId();
|
|
|
lifeMessagePageResultList.add(messageVo);
|
|
|
}
|
|
|
}
|
|
|
@@ -156,6 +199,32 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ private boolean isChatEnabled(Integer userId, Integer lawyerId, Map<String, Boolean> cache) {
|
|
|
+ if (userId == null || lawyerId == null) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ String cacheKey = userId + "_" + lawyerId;
|
|
|
+ if (cache.containsKey(cacheKey)) {
|
|
|
+ return cache.get(cacheKey);
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<LawyerConsultationOrder> orderWrapper = new LambdaQueryWrapper<>();
|
|
|
+ orderWrapper.eq(LawyerConsultationOrder::getClientUserId, userId);
|
|
|
+ orderWrapper.eq(LawyerConsultationOrder::getLawyerUserId, lawyerId);
|
|
|
+ orderWrapper.eq(LawyerConsultationOrder::getDeleteFlag, 0);
|
|
|
+ orderWrapper.orderByDesc(LawyerConsultationOrder::getCreatedTime);
|
|
|
+ orderWrapper.last("limit 1");
|
|
|
+ LawyerConsultationOrder order = lawyerConsultationOrderMapper.selectOne(orderWrapper);
|
|
|
+ boolean enabled = true;
|
|
|
+ if (order != null) {
|
|
|
+ Integer status = order.getOrderStatus();
|
|
|
+ enabled = !Objects.equals(status, LawyerStatusEnum.COMPLETE.getStatus())
|
|
|
+ && !Objects.equals(status, LawyerStatusEnum.CANCEL.getStatus())
|
|
|
+ && !Objects.equals(status, LawyerStatusEnum.REFUNDED.getStatus());
|
|
|
+ }
|
|
|
+ cache.put(cacheKey, enabled);
|
|
|
+ return enabled;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public LifeMessageVo getStrangerMessageNum(String receiverId) throws Exception {
|
|
|
try {
|