From 40238efd8a82e2b13266a890e2990e22fdfa9b3b Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Fri, 28 May 2021 11:12:35 +0800
Subject: [PATCH] Merge branch 'otc' of http://120.27.238.55:7000/r/exchange into otc
---
src/main/java/com/xcong/excoin/rabbit/consumer/ChatConsumer.java | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 101 insertions(+), 5 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 fccfd6e..2305fb6 100644
--- a/src/main/java/com/xcong/excoin/rabbit/consumer/ChatConsumer.java
+++ b/src/main/java/com/xcong/excoin/rabbit/consumer/ChatConsumer.java
@@ -1,7 +1,103 @@
-package com.xcong.excoin.rabbit.consumer;/**
-*
-* @author wzy
-* @date 2021-05-27
-**/
+package com.xcong.excoin.rabbit.consumer;
+
+
+import cn.hutool.core.bean.BeanUtil;
+import cn.hutool.core.util.StrUtil;
+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;
+import com.xcong.excoin.modules.otc.entity.OtcMsgUserListEntity;
+import com.xcong.excoin.netty.bean.ChatRequest;
+import com.xcong.excoin.utils.RedisUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.amqp.rabbit.annotation.RabbitListener;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
+import org.springframework.stereotype.Component;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Date;
+
+@Slf4j
+@Component
+//@ConditionalOnProperty(prefix = "app", name = "rabbit-consumer", havingValue = "true")
public class ChatConsumer {
+
+ @Autowired
+ private OtcMsgUserListDao otcMsgUserListDao;
+
+ @Autowired
+ private OtcMsgHistoryDao otcMsgHistoryDao;
+
+ @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 = chat.getTargetId();
+ Long fromId = chat.getFromMemberId();
+
+ // 发送人是否存在聊天框
+ OtcMsgUserListEntity fromList = otcMsgUserListDao.selectChatListByToAndFrom(toId, fromId);
+ if (fromList == null) {
+ OtcMsgUserListEntity from = new OtcMsgUserListEntity();
+ from.setMemberId(toId);
+ from.setTargetId(fromId);
+ from.setIsRead(OtcMsgUserListEntity.ISREAD_ONE);
+ from.setLastMsgTime(new Date());
+ otcMsgUserListDao.insert(from);
+ }
+
+ // 收件人是否存在聊天框
+ OtcMsgUserListEntity toList = otcMsgUserListDao.selectChatListByToAndFrom(fromId, toId);
+ if (toList == null) {
+ OtcMsgUserListEntity from = new OtcMsgUserListEntity();
+ from.setMemberId(toId);
+ from.setTargetId(fromId);
+ from.setIsRead(OtcMsgUserListEntity.ISREAD_TWO);
+ from.setLastMsgTime(new Date());
+ otcMsgUserListDao.insert(from);
+ } else {
+ // 收件人正在聊的用户
+ 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_ONE);
+ toList.setLastMsgTime(new Date());
+ otcMsgUserListDao.updateById(toList);
+ }
+ }
+
+
+ OtcMsgHistoryEntity toHistory = new OtcMsgHistoryEntity();
+ toHistory.setMemberId(toId);
+ toHistory.setFromMemberId(fromId);
+ toHistory.setTargetId(toId);
+ toHistory.setIsSelf(OtcMsgHistoryEntity.ISSELF_TWO);
+ toHistory.setMsgType(chat.getMsgType());
+ 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