|
|
@@ -20,9 +20,9 @@ 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 shop.alien.util.type.LifeMessageUtil;
|
|
|
import shop.alien.util.type.LifeNoticeUtil;
|
|
|
import shop.alien.util.type.PhoneTypeIdResult;
|
|
|
-import shop.alien.util.type.TypeUtil;
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Comparator;
|
|
|
@@ -50,7 +50,7 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
private final LawyerUserMapper lawyerUserMapper;
|
|
|
private final LawyerConsultationOrderMapper lawyerConsultationOrderMapper;
|
|
|
|
|
|
- private final TypeUtil typeUtil;
|
|
|
+ private final LifeMessageUtil lifeMessageUtil;
|
|
|
|
|
|
private final LifeNoticeUtil lifeNoticeUtil;
|
|
|
|
|
|
@@ -79,23 +79,17 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
wrapper.apply("(user.user_name like '%" + search + "%' or suser.name like '%" + search + "%' or sinfo.store_name like '%" + search + "%')");
|
|
|
// 聊过
|
|
|
} else if (1 == friendType) {
|
|
|
- wrapper.apply("message.phoneId in ( " +
|
|
|
- " select receiver_id " +
|
|
|
- " from life_message " +
|
|
|
- " where sender_id = '" + receiverId + "' and delete_flag = 0 " +
|
|
|
- " group by receiver_id " +
|
|
|
- ")");
|
|
|
+ wrapper.apply("message.phoneId in ( " + lifeMessageUtil.sqlDistinctReceiverIdsBySender(receiverId) + ")");
|
|
|
// 没聊过
|
|
|
} else if (2 == friendType) {
|
|
|
- wrapper.apply("message.phoneId not in ( " +
|
|
|
- " select receiver_id " +
|
|
|
- " from life_message " +
|
|
|
- " where sender_id = '" + receiverId + "' and delete_flag = 0 " +
|
|
|
- " group by receiver_id " +
|
|
|
- ")");
|
|
|
+ wrapper.apply("message.phoneId not in ( " + lifeMessageUtil.sqlDistinctReceiverIdsBySender(receiverId) + ")");
|
|
|
}
|
|
|
wrapper.orderByDesc("message.created_time");
|
|
|
- List<LifeMessageVo> lifeMessagePageList = lifeMessageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
|
|
|
+ PhoneTypeIdResult participant = lifeMessageUtil.resolveIdentity(receiverId);
|
|
|
+ Integer participantUserType = participant != null ? participant.getType() : -1;
|
|
|
+ Integer participantRefId = participant != null ? participant.getId() : -1;
|
|
|
+ List<LifeMessageVo> lifeMessagePageList = lifeMessageMapper.getLifeMessagePageByPhoneId(
|
|
|
+ receiverId, participantUserType, participantRefId, wrapper);
|
|
|
List<LifeMessageVo> lifeMessagePageResultList = new ArrayList<>();
|
|
|
if (!CollectionUtils.isEmpty(lifeMessagePageList)) {
|
|
|
boolean currentIsUser = receiverId != null && receiverId.startsWith("user_");
|
|
|
@@ -129,7 +123,7 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
|
|
|
// 查询所有未读消息
|
|
|
LambdaQueryWrapper<LifeMessage> messageWrapper = new LambdaQueryWrapper<>();
|
|
|
- messageWrapper.eq(LifeMessage::getReceiverId, receiverId);
|
|
|
+ lifeMessageUtil.applyReceiverQuery(messageWrapper, receiverId);
|
|
|
messageWrapper.eq(LifeMessage::getIsRead, 0);
|
|
|
messageWrapper.eq(LifeMessage::getDeleteFlag, 0);
|
|
|
messageWrapper.apply("(instr(delete_phone_id, '" + receiverId + "') is null or instr(delete_phone_id, '" + receiverId + "') = 0)");
|
|
|
@@ -264,15 +258,14 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
" where blocker_type = '" + blockerType + "' and blocker_id = '" + blockerId + "' and blocked_type = '1' and delete_flag = 0 " +
|
|
|
") or suser.id is null)");
|
|
|
// 没聊过
|
|
|
- wrapper.apply("message.phoneId not in ( " +
|
|
|
- " select receiver_id " +
|
|
|
- " from life_message " +
|
|
|
- " where sender_id = '" + receiverId + "' and delete_flag = 0 " +
|
|
|
- " group by receiver_id " +
|
|
|
- ")");
|
|
|
+ wrapper.apply("message.phoneId not in ( " + lifeMessageUtil.sqlDistinctReceiverIdsBySender(receiverId) + ")");
|
|
|
wrapper.orderByDesc("message.created_time");
|
|
|
|
|
|
- List<LifeMessageVo> lifeMessagePageList = lifeMessageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
|
|
|
+ PhoneTypeIdResult participant = lifeMessageUtil.resolveIdentity(receiverId);
|
|
|
+ Integer participantUserType = participant != null ? participant.getType() : -1;
|
|
|
+ Integer participantRefId = participant != null ? participant.getId() : -1;
|
|
|
+ List<LifeMessageVo> lifeMessagePageList = lifeMessageMapper.getLifeMessagePageByPhoneId(
|
|
|
+ receiverId, participantUserType, participantRefId, wrapper);
|
|
|
LifeMessageVo vo = new LifeMessageVo();
|
|
|
if (!CollectionUtils.isEmpty(lifeMessagePageList)) {
|
|
|
vo.setUserName(lifeMessagePageList.get(0).getUserName());
|
|
|
@@ -315,10 +308,13 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
// 当前用户的所有未关注人消息
|
|
|
wrapper = new QueryWrapper<>();
|
|
|
wrapper.eq("num", 1);
|
|
|
- wrapper.apply("(sender_id not in (" + friendsIdsStr + ") and receiver_id not in (" + friendsIdsStr + "))");
|
|
|
+ wrapper.apply("message.phoneId not in (" + friendsIdsStr + ")");
|
|
|
wrapper.orderByDesc("message.created_time");
|
|
|
-// IPage<LifeMessageVo> ipage = new Page<>(1, Integer.MAX_VALUE);
|
|
|
- List<LifeMessageVo> lifeMessageVoList = lifeMessageMapper.getLifeMessagePageByPhoneId(receiverId, wrapper);
|
|
|
+ PhoneTypeIdResult participant = lifeMessageUtil.resolveIdentity(receiverId);
|
|
|
+ Integer participantUserType = participant != null ? participant.getType() : -1;
|
|
|
+ Integer participantRefId = participant != null ? participant.getId() : -1;
|
|
|
+ List<LifeMessageVo> lifeMessageVoList = lifeMessageMapper.getLifeMessagePageByPhoneId(
|
|
|
+ receiverId, participantUserType, participantRefId, wrapper);
|
|
|
LifeMessageVo messageVos = null;
|
|
|
if(CollectionUtils.isEmpty(lifeMessageVoList)){
|
|
|
return messageVos;
|
|
|
@@ -391,7 +387,18 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
lawyerUser1 = lawyerUserMapper.selectOne(new QueryWrapper<LawyerUser>().eq("phone", senderId.substring(7)));
|
|
|
}
|
|
|
|
|
|
- List<LifeMessageVo> lifeMessageVos = lifeMessageMapper.getMessageListByReceiverId(receiverId, senderId);
|
|
|
+ PhoneTypeIdResult receiverIdentity = lifeMessageUtil.resolveIdentity(receiverId);
|
|
|
+ PhoneTypeIdResult senderIdentity = lifeMessageUtil.resolveIdentity(senderId);
|
|
|
+ if (receiverIdentity == null || senderIdentity == null) {
|
|
|
+ JSONObject empty = new JSONObject();
|
|
|
+ empty.put("messageList", new ArrayList<>());
|
|
|
+ empty.put("isStranger", true);
|
|
|
+ return empty;
|
|
|
+ }
|
|
|
+ List<LifeMessageVo> lifeMessageVos = lifeMessageMapper.getMessageListByReceiverId(
|
|
|
+ receiverId,
|
|
|
+ senderIdentity.getType(), senderIdentity.getId(),
|
|
|
+ receiverIdentity.getType(), receiverIdentity.getId());
|
|
|
for (LifeMessageVo lifeMessageVo : lifeMessageVos) {
|
|
|
if (lifeMessageVo.getReceiverId().equals(receiverId)) {
|
|
|
if (null != lifeUser1) {
|
|
|
@@ -429,10 +436,9 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
}
|
|
|
|
|
|
// 查询两个人是否是陌生人(只有一条消息)
|
|
|
- QueryWrapper<LifeMessage> wrapper = new QueryWrapper<>();
|
|
|
- // 没聊过
|
|
|
- wrapper.apply("((sender_id = '" + senderId + "' and receiver_id = '" + receiverId + "') or (sender_id = '" + receiverId + "' and receiver_id = '" + senderId + "'))");
|
|
|
- wrapper.orderByDesc("created_time");
|
|
|
+ LambdaQueryWrapper<LifeMessage> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ lifeMessageUtil.applyConversationQuery(wrapper, senderId, receiverId);
|
|
|
+ wrapper.orderByDesc(LifeMessage::getCreatedTime);
|
|
|
int count = lifeMessageMapper.selectCount(wrapper);
|
|
|
|
|
|
JSONObject jsonObject = new JSONObject();
|
|
|
@@ -460,16 +466,11 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
// return lifeMessageMapper.selectCount(wrapper) <= 1;
|
|
|
|
|
|
// 查询我发送过的消息
|
|
|
- QueryWrapper<LifeMessage> wrapper = new QueryWrapper<>();
|
|
|
- //本人发送的数量
|
|
|
- wrapper.apply("(sender_id = '" + senderId + "' and receiver_id = '" + receiverId + "')");
|
|
|
-// wrapper.eq("sender_id", senderId);
|
|
|
-// wrapper.eq("receiver_id", receiverId);
|
|
|
-
|
|
|
+ LambdaQueryWrapper<LifeMessage> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ lifeMessageUtil.applySenderReceiverPairQuery(wrapper, senderId, receiverId);
|
|
|
int senderCount = lifeMessageMapper.selectCount(wrapper);
|
|
|
- //查询对方发送过的消息
|
|
|
- QueryWrapper<LifeMessage> wrapper1 = new QueryWrapper<>();
|
|
|
- wrapper1.apply("(sender_id = '" + receiverId + "' and receiver_id = '" + senderId + "')");
|
|
|
+ LambdaQueryWrapper<LifeMessage> wrapper1 = new LambdaQueryWrapper<>();
|
|
|
+ lifeMessageUtil.applySenderReceiverPairQuery(wrapper1, receiverId, senderId);
|
|
|
int receiverCount = lifeMessageMapper.selectCount(wrapper1);
|
|
|
if (senderCount == 0){
|
|
|
//本条可以发
|
|
|
@@ -502,8 +503,7 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
public int read(String receiverId, String senderId) throws Exception {
|
|
|
try {
|
|
|
LambdaUpdateWrapper<LifeMessage> wrapper = new LambdaUpdateWrapper<>();
|
|
|
- wrapper.eq(LifeMessage::getReceiverId, receiverId);
|
|
|
- wrapper.eq(LifeMessage::getSenderId, senderId);
|
|
|
+ lifeMessageUtil.applySenderReceiverPairUpdate(wrapper, senderId, receiverId);
|
|
|
wrapper.eq(LifeMessage::getDeleteFlag, 0);
|
|
|
wrapper.set(LifeMessage::getIsRead, 1);
|
|
|
return lifeMessageMapper.update(null, wrapper);
|
|
|
@@ -516,8 +516,8 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
@Override
|
|
|
public int noReadCount(String receiverId) throws Exception {
|
|
|
try {
|
|
|
- LambdaUpdateWrapper<LifeMessage> wrapper = new LambdaUpdateWrapper<>();
|
|
|
- wrapper.eq(LifeMessage::getReceiverId, receiverId);
|
|
|
+ LambdaQueryWrapper<LifeMessage> wrapper = new LambdaQueryWrapper<>();
|
|
|
+ lifeMessageUtil.applyReceiverQuery(wrapper, receiverId);
|
|
|
wrapper.eq(LifeMessage::getIsRead, 0);
|
|
|
wrapper.eq(LifeMessage::getDeleteFlag, 0);
|
|
|
return lifeMessageMapper.selectCount(wrapper);
|
|
|
@@ -530,7 +530,15 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
@Override
|
|
|
public int deleteMessageByPhoneId(String senderId, String receiverId) throws Exception {
|
|
|
try {
|
|
|
- return lifeMessageMapper.deleteMessageByPhoneId(senderId, receiverId);
|
|
|
+ PhoneTypeIdResult sender = lifeMessageUtil.resolveIdentity(senderId);
|
|
|
+ PhoneTypeIdResult receiver = lifeMessageUtil.resolveIdentity(receiverId);
|
|
|
+ if (sender == null || receiver == null) {
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ return lifeMessageMapper.deleteMessageByPhoneId(
|
|
|
+ sender.getType(), sender.getId(),
|
|
|
+ receiver.getType(), receiver.getId(),
|
|
|
+ senderId, receiverId);
|
|
|
} catch (Exception e) {
|
|
|
log.error("LifeMessageServiceImpl.deleteMessageByPhoneId Error Mgs={}", e.getMessage());
|
|
|
throw new Exception(e);
|
|
|
@@ -563,7 +571,7 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
|
|
|
// 查询未读消息数量(life_message 按 receiver_user_type + receiver_ref_id)
|
|
|
LambdaQueryWrapper<LifeMessage> messageWrapper = new LambdaQueryWrapper<>();
|
|
|
- applyReceiverIdentityFilter(messageWrapper, receiverId);
|
|
|
+ lifeMessageUtil.applyReceiverQuery(messageWrapper, receiverId);
|
|
|
messageWrapper.eq(LifeMessage::getIsRead, 0);
|
|
|
messageWrapper.notIn(LifeMessage::getSenderId, notDisturbIdsStr);
|
|
|
messageWrapper.apply("(instr(delete_phone_id, '" + receiverId + "') is null or instr(delete_phone_id, '" + receiverId + "') = 0)");
|
|
|
@@ -586,7 +594,11 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
public List<LifeFansVo> getTalkedUserList() throws Exception {
|
|
|
try {
|
|
|
String phoneId = Objects.requireNonNull(JwtUtil.getCurrentUserInfo()).getString("userType") + "_" + JwtUtil.getCurrentUserInfo().getString("phone");
|
|
|
- return lifeMessageMapper.getTalkedUserList(phoneId);
|
|
|
+ PhoneTypeIdResult participant = lifeMessageUtil.resolveIdentity(phoneId);
|
|
|
+ if (participant == null) {
|
|
|
+ return new ArrayList<>();
|
|
|
+ }
|
|
|
+ return lifeMessageMapper.getTalkedUserList(phoneId, participant.getType(), participant.getId());
|
|
|
} catch (Exception e) {
|
|
|
log.error("LifeMessageServiceImpl.getTalkedUserList Error Mgs={}", e.getMessage());
|
|
|
throw new Exception(e);
|
|
|
@@ -603,19 +615,4 @@ public class LifeMessageServiceImpl extends ServiceImpl<LifeMessageMapper, LifeM
|
|
|
return lifeUserMapper.selectOne(wrapper).getIsBanned() == 1;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 按接收人 userType + refId 过滤消息;解析失败时回退 receiver_id。
|
|
|
- */
|
|
|
- private void applyReceiverIdentityFilter(LambdaQueryWrapper<LifeMessage> wrapper, String receiverId) {
|
|
|
- PhoneTypeIdResult resolved = typeUtil.resolveTypeAndId(receiverId);
|
|
|
- if (resolved != null && resolved.getType() != null && resolved.getId() != null) {
|
|
|
- wrapper.and(w -> w.nested(n -> n.eq(LifeMessage::getReceiverUserType, resolved.getType())
|
|
|
- .eq(LifeMessage::getReceiverRefId, resolved.getId()))
|
|
|
- .or()
|
|
|
- .eq(LifeMessage::getReceiverId, receiverId));
|
|
|
- } else {
|
|
|
- wrapper.eq(LifeMessage::getReceiverId, receiverId);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|