|
|
@@ -0,0 +1,54 @@
|
|
|
+package cn.reghao.tnb.file.app.zchat.service;
|
|
|
+
|
|
|
+import cn.reghao.jutil.jdk.string.SnowFlake;
|
|
|
+import cn.reghao.tnb.auth.api.iface.AccountQuery;
|
|
|
+import cn.reghao.tnb.common.auth.UserContext;
|
|
|
+import cn.reghao.tnb.file.api.dto.ObjectMeta;
|
|
|
+import cn.reghao.tnb.file.api.iface.OssService;
|
|
|
+import cn.reghao.tnb.file.app.zchat.db.mapper.ChatDialogueMapper;
|
|
|
+import cn.reghao.tnb.file.app.zchat.db.repository.MessageRepository;
|
|
|
+import cn.reghao.tnb.file.app.zchat.model.dto.ChatFileMsg;
|
|
|
+import cn.reghao.tnb.file.app.zchat.model.po.ChatDialogue;
|
|
|
+import cn.reghao.tnb.file.app.zchat.model.po.ChatFile;
|
|
|
+import cn.reghao.tnb.file.app.zchat.model.po.ChatMessage;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.dubbo.config.annotation.DubboReference;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @author reghao
|
|
|
+ * @date 2026-06-14 22:43:30
|
|
|
+ */
|
|
|
+@Slf4j
|
|
|
+@Service
|
|
|
+public class ChatMessageService {
|
|
|
+ @DubboReference(check = false, retries = 0, timeout = 60_000)
|
|
|
+ private AccountQuery accountQuery;
|
|
|
+ @DubboReference(check = false, retries = 0, timeout = 60_000)
|
|
|
+ private OssService ossService;
|
|
|
+
|
|
|
+ private final SnowFlake idGenerator;
|
|
|
+ private final ChatDialogueMapper chatDialogueMapper;
|
|
|
+ private final MessageRepository messageRepository;
|
|
|
+
|
|
|
+ public ChatMessageService(ChatDialogueMapper chatDialogueMapper, MessageRepository messageRepository) {
|
|
|
+ this.idGenerator = new SnowFlake(1L, 1L);
|
|
|
+ this.chatDialogueMapper = chatDialogueMapper;
|
|
|
+ this.messageRepository = messageRepository;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addFileMessage(ChatFileMsg chatFileMsg) {
|
|
|
+ long loginUser = UserContext.getUserId();
|
|
|
+ long chatId = chatFileMsg.getChatId();
|
|
|
+ ChatDialogue chatDialogue = chatDialogueMapper.findChatDialogue1(chatId, loginUser);
|
|
|
+ if (chatDialogue == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ String objectId = chatFileMsg.getObjectId();
|
|
|
+ ObjectMeta objectMeta = ossService.getObjectMeta(objectId);
|
|
|
+ long messageId = idGenerator.nextId();
|
|
|
+ ChatFile chatFile = new ChatFile();
|
|
|
+ ChatMessage chatMessage = new ChatMessage();
|
|
|
+ messageRepository.saveFileMessage(chatMessage, chatFile);
|
|
|
+ }
|
|
|
+}
|