From 0d30c93d000413c6eb34f489ef17688ad4175201 Mon Sep 17 00:00:00 2001
From: KKSU <15274802129@163.com>
Date: Mon, 29 Apr 2024 18:18:21 +0800
Subject: [PATCH] 55测试环境
---
src/main/java/com/xcong/excoin/rabbit/consumer/ChatConsumer.java | 35 ++++++++++++++++++++++-------------
1 files changed, 22 insertions(+), 13 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/rabbit/consumer/ChatConsumer.java b/src/main/java/com/xcong/excoin/rabbit/consumer/ChatConsumer.java
index 4902736..770af5c 100644
--- a/src/main/java/com/xcong/excoin/rabbit/consumer/ChatConsumer.java
+++ b/src/main/java/com/xcong/excoin/rabbit/consumer/ChatConsumer.java
@@ -6,6 +6,7 @@
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.common.contants.AppContants;
import com.xcong.excoin.configurations.RabbitMqConfig;
+import com.xcong.excoin.modules.member.dao.MemberSettingDao;
import com.xcong.excoin.modules.otc.dao.OtcMsgHistoryDao;
import com.xcong.excoin.modules.otc.dao.OtcMsgUserListDao;
import com.xcong.excoin.modules.otc.entity.OtcMsgHistoryEntity;
@@ -23,7 +24,7 @@
@Slf4j
@Component
-//@ConditionalOnProperty(prefix = "app", name = "rabbit-consumer", havingValue = "true")
+@ConditionalOnProperty(prefix = "app", name = "websocket-job", havingValue = "true")
public class ChatConsumer {
@Autowired
@@ -35,43 +36,49 @@
@Autowired
private RedisUtils redisUtils;
+ @Autowired
+ private MemberSettingDao memberSettingDao;
+
@RabbitListener(queues = RabbitMqConfig.QUEUE_MSG_HISTORY)
@Transactional(rollbackFor = Exception.class)
public void msgHistoryConsumer(String content) {
log.info("收到历史消息处理:{}", content);
ChatRequest chat = JSONObject.parseObject(content, ChatRequest.class);
- Long toId = Long.parseLong(chat.getTo());
- Long fromId = Long.parseLong(chat.getFrom());
+ Long toId = chat.getTargetId();
+ Long fromId = chat.getFromMemberId();
// 发送人是否存在聊天框
- OtcMsgUserListEntity fromList = otcMsgUserListDao.selectChatListByToAndFrom(Long.parseLong(chat.getTo()), Long.parseLong(chat.getFrom()));
+ OtcMsgUserListEntity fromList = otcMsgUserListDao.selectChatListByToAndFrom(toId, fromId);
if (fromList == null) {
OtcMsgUserListEntity from = new OtcMsgUserListEntity();
- from.setMemberId(Long.parseLong(chat.getFrom()));
- from.setTargetId(Long.parseLong(chat.getTo()));
+ from.setMemberId(fromId);
+ from.setTargetId(toId);
from.setIsRead(OtcMsgUserListEntity.ISREAD_TWO);
from.setLastMsgTime(new Date());
otcMsgUserListDao.insert(from);
+ } else {
+ fromList.setLastMsgTime(new Date());
+ otcMsgUserListDao.updateById(fromList);
}
// 收件人是否存在聊天框
- OtcMsgUserListEntity toList = otcMsgUserListDao.selectChatListByToAndFrom(Long.parseLong(chat.getFrom()), Long.parseLong(chat.getTo()));
+ OtcMsgUserListEntity toList = otcMsgUserListDao.selectChatListByToAndFrom(fromId, toId);
if (toList == null) {
OtcMsgUserListEntity from = new OtcMsgUserListEntity();
- from.setMemberId(Long.parseLong(chat.getTo()));
- from.setTargetId(Long.parseLong(chat.getFrom()));
+ from.setMemberId(toId);
+ from.setTargetId(fromId);
from.setIsRead(OtcMsgUserListEntity.ISREAD_ONE);
from.setLastMsgTime(new Date());
otcMsgUserListDao.insert(from);
} else {
// 收件人正在聊的用户
- String value = redisUtils.getString(AppContants.MSG_CHATTING + chat.getTo());
- if (StrUtil.isNotBlank(value) && value.equals(chat.getFrom())) {
+ String value = redisUtils.getString(AppContants.MSG_CHATTING + toId);
+ if (StrUtil.isNotBlank(value) && value.equals(fromId.toString())) {
toList.setLastMsgTime(new Date());
otcMsgUserListDao.updateById(toList);
} else {
- toList.setIsRead(OtcMsgUserListEntity.ISREAD_TWO);
+ toList.setIsRead(OtcMsgUserListEntity.ISREAD_ONE);
toList.setLastMsgTime(new Date());
otcMsgUserListDao.updateById(toList);
}
@@ -84,13 +91,15 @@
toHistory.setTargetId(toId);
toHistory.setIsSelf(OtcMsgHistoryEntity.ISSELF_TWO);
toHistory.setMsgType(chat.getMsgType());
- toHistory.setMsg(chat.getContent());
+ toHistory.setMsg(chat.getMsg());
OtcMsgHistoryEntity fromHistory = new OtcMsgHistoryEntity();
BeanUtil.copyProperties(toHistory, fromHistory);
fromHistory.setIsSelf(OtcMsgHistoryEntity.ISSELF_ONE);
fromHistory.setMemberId(fromId);
+ memberSettingDao.updateMessageReminderByMemberId(toId);
+
otcMsgHistoryDao.insert(fromHistory);
otcMsgHistoryDao.insert(toHistory);
}
--
Gitblit v1.9.1