mirror of
https://gitee.com/270580156/weiyu.git
synced 2025-12-30 02:42:25 +00:00
update to 0.4.5
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
# ===============================
|
||||
spring.application.name=bytedesk
|
||||
application.title=https://www.weiyuai.cn
|
||||
application.version=0.4.4
|
||||
application.version=0.4.5
|
||||
# server.host=127.0.0.1
|
||||
server.port=9003
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@echo off
|
||||
set RUN_NAME=bytedesk-starter-0.4.4.jar
|
||||
set RUN_NAME=bytedesk-starter.jar
|
||||
set LANG=en_US.UTF-8
|
||||
set PRG=%0
|
||||
set APPDIRFILE=%~dp0
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#!/bin/sh
|
||||
RUN_NAME="bytedesk-starter-0.4.4.jar"
|
||||
RUN_NAME="bytedesk-starter.jar"
|
||||
export LANG="en_US.UTF-8"
|
||||
PRG=$0
|
||||
APPDIRFILE=`dirname "$PRG"`
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@echo off
|
||||
set RUN_NAME=bytedesk-starter-0.4.4.jar
|
||||
set RUN_NAME=bytedesk-starter.jar
|
||||
set LANG=en_US.UTF-8
|
||||
set PRG=%0
|
||||
set APPDIRFILE=%~dp0
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
# @Author: jackning 270580156@qq.com
|
||||
# @Date: 2024-08-09 10:35:30
|
||||
# @LastEditors: jackning 270580156@qq.com
|
||||
# @LastEditTime: 2024-08-09 10:51:39
|
||||
# @LastEditTime: 2024-10-14 07:56:18
|
||||
# @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
# Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
# selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -13,7 +13,7 @@
|
||||
# 联系:270580156@qq.com
|
||||
# Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
###
|
||||
RUN_NAME="bytedesk-starter-0.4.4.jar"
|
||||
RUN_NAME="bytedesk-starter.jar"
|
||||
export LANG="en_US.UTF-8"
|
||||
PRG=$0
|
||||
APPDIRFILE=`dirname "$PRG"`
|
||||
|
||||
BIN
modules/.DS_Store
vendored
BIN
modules/.DS_Store
vendored
Binary file not shown.
BIN
modules/ai/.DS_Store
vendored
BIN
modules/ai/.DS_Store
vendored
Binary file not shown.
@@ -15,7 +15,7 @@
|
||||
<version>${revision}</version>
|
||||
|
||||
<name>bytedesk-module-ai</name>
|
||||
<description>https://www.weiyuai.cn</description>
|
||||
<description>https://ai.bytedesk.com</description>
|
||||
|
||||
<properties>
|
||||
<spring-ai.version>1.0.0-SNAPSHOT</spring-ai.version>
|
||||
|
||||
BIN
modules/ai/src/.DS_Store
vendored
BIN
modules/ai/src/.DS_Store
vendored
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-05-31 10:24:39
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-17 22:24:02
|
||||
* @LastEditTime: 2024-10-19 09:58:39
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -14,11 +14,7 @@
|
||||
*/
|
||||
package com.bytedesk.ai.provider.ollama;
|
||||
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.ollama.OllamaChatModel;
|
||||
import org.springframework.ai.ollama.OllamaEmbeddingModel;
|
||||
import org.springframework.ai.ollama.api.OllamaApi;
|
||||
import org.springframework.ai.ollama.api.OllamaOptions;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -71,22 +67,22 @@ public class OllamaConfig {
|
||||
// // FUNCTION CALLING
|
||||
// .build();
|
||||
// }
|
||||
@Bean
|
||||
ChatClient ollamaChatClient() {
|
||||
return ChatClient.create(ollamaChatModel());
|
||||
}
|
||||
// @Bean
|
||||
// ChatClient ollamaChatClient() {
|
||||
// return ChatClient.create(ollamaChatModel());
|
||||
// }
|
||||
|
||||
@Bean
|
||||
OllamaChatModel ollamaChatModel() {
|
||||
return new OllamaChatModel(ollamaApi(), OllamaOptions.create().withModel(
|
||||
ollamaChatModel).withTemperature(0.9));
|
||||
}
|
||||
// @Bean
|
||||
// OllamaChatModel ollamaChatModel() {
|
||||
// return new OllamaChatModel(ollamaApi(), OllamaOptions.create().withModel(
|
||||
// ollamaChatModel).withTemperature(0.9));
|
||||
// }
|
||||
|
||||
// https://docs.spring.io/spring-ai/reference/api/embeddings/ollama-embeddings.html
|
||||
@Bean
|
||||
OllamaEmbeddingModel ollamaEmbeddingModel() {
|
||||
return new OllamaEmbeddingModel(ollamaApi(), OllamaOptions.create().withModel(
|
||||
ollamaEmbeddingModel).withTemperature(0.9));
|
||||
}
|
||||
// @Bean
|
||||
// OllamaEmbeddingModel ollamaEmbeddingModel() {
|
||||
// return new OllamaEmbeddingModel(ollamaApi(), OllamaOptions.create().withModel(
|
||||
// ollamaEmbeddingModel).withTemperature(0.9));
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-05-31 09:50:56
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-27 16:16:13
|
||||
* @LastEditTime: 2024-10-19 10:00:06
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -14,10 +14,6 @@
|
||||
*/
|
||||
package com.bytedesk.ai.provider.ollama;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
// import org.springframework.ai.chat.model.ChatModel;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
// import org.springframework.ai.chat.prompt.Prompt;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -26,8 +22,6 @@ import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.bytedesk.core.utils.JsonResult;
|
||||
import com.bytedesk.kbase.upload.UploadVectorStore;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -38,20 +32,20 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@AllArgsConstructor
|
||||
public class OllamaController {
|
||||
|
||||
private final ChatClient chatClient;
|
||||
// private final ChatClient chatClient;
|
||||
|
||||
// private final ChatModel chatModel;
|
||||
|
||||
private final UploadVectorStore uploadVectorStore;
|
||||
// private final UploadVectorStore uploadVectorStore;
|
||||
|
||||
private final String PROMPT_BLUEPRINT = """
|
||||
Answer the query strictly referring the provided context:
|
||||
{context}
|
||||
Query:
|
||||
{query}
|
||||
In case you don't have any answer from the context provided, just say:
|
||||
I'm sorry I don't have the information you are looking for.
|
||||
""";
|
||||
// private final String PROMPT_BLUEPRINT = """
|
||||
// Answer the query strictly referring the provided context:
|
||||
// {context}
|
||||
// Query:
|
||||
// {query}
|
||||
// In case you don't have any answer from the context provided, just say:
|
||||
// I'm sorry I don't have the information you are looking for.
|
||||
// """;
|
||||
// private final String PROMPT_BLUEPRINT = """
|
||||
// 根据提供的文档信息回答问题,文档信息如下:
|
||||
// {context}
|
||||
@@ -61,29 +55,29 @@ public class OllamaController {
|
||||
// """;
|
||||
|
||||
// http://127.0.0.1:9003/visitor/api/v1/ai/ollama/simple?message=讲一个笑话
|
||||
@GetMapping("/simple")
|
||||
public ResponseEntity<?> getSimpleCompletion(
|
||||
@RequestParam(value = "message", defaultValue = "讲一个笑话") String message) {
|
||||
// @GetMapping("/simple")
|
||||
// public ResponseEntity<?> getSimpleCompletion(
|
||||
// @RequestParam(value = "message", defaultValue = "讲一个笑话") String message) {
|
||||
|
||||
String content = chatClient.prompt().user(message).call().content();
|
||||
// String content = chatClient.prompt().user(message).call().content();
|
||||
|
||||
return ResponseEntity.ok(JsonResult.success(content));
|
||||
}
|
||||
// return ResponseEntity.ok(JsonResult.success(content));
|
||||
// }
|
||||
|
||||
// http://127.0.0.1:9003/visitor/api/v1/ai/ollama/rich
|
||||
@GetMapping("/rich")
|
||||
public ResponseEntity<?> getRichCompletion(
|
||||
@RequestParam(value = "message", defaultValue = "讲一个笑话") String message) {
|
||||
// @GetMapping("/rich")
|
||||
// public ResponseEntity<?> getRichCompletion(
|
||||
// @RequestParam(value = "message", defaultValue = "讲一个笑话") String message) {
|
||||
|
||||
ChatResponse chatResponse = chatClient.prompt().user(message).call().chatResponse();
|
||||
// ChatResponse chatResponse = chatModel.call(
|
||||
// new Prompt(message,
|
||||
// OllamaOptions.builder()
|
||||
// .withModel(OllamaModel.MISTRAL)
|
||||
// // .withTemperature(0.4)
|
||||
// .build()));
|
||||
return ResponseEntity.ok(JsonResult.success(chatResponse));
|
||||
}
|
||||
// ChatResponse chatResponse = chatClient.prompt().user(message).call().chatResponse();
|
||||
// // ChatResponse chatResponse = chatModel.call(
|
||||
// // new Prompt(message,
|
||||
// // OllamaOptions.builder()
|
||||
// // .withModel(OllamaModel.MISTRAL)
|
||||
// // // .withTemperature(0.4)
|
||||
// // .build()));
|
||||
// return ResponseEntity.ok(JsonResult.success(chatResponse));
|
||||
// }
|
||||
|
||||
// FIXME: java.lang.NoClassDefFoundError:
|
||||
// org/eclipse/jetty/reactive/client/ReactiveRequest
|
||||
@@ -101,23 +95,23 @@ public class OllamaController {
|
||||
// 参考
|
||||
// https://github.com/habuma/spring-ai-rag-example/blob/main/src/main/java/com/example/springairag/AskController.java
|
||||
// http://127.0.0.1:9003/visitor/api/v1/ai/ollama/chat?query=考试日期
|
||||
@GetMapping("/chat")
|
||||
public ResponseEntity<?> chat(@RequestParam(value = "query", defaultValue = "考试日期") String query) {
|
||||
//
|
||||
List<String> contentList = uploadVectorStore.searchText(query);
|
||||
// @GetMapping("/chat")
|
||||
// public ResponseEntity<?> chat(@RequestParam(value = "query", defaultValue = "考试日期") String query) {
|
||||
// //
|
||||
// List<String> contentList = uploadVectorStore.searchText(query);
|
||||
|
||||
ChatResponse response = chatClient.prompt()
|
||||
.user(userSpec -> userSpec
|
||||
.text(PROMPT_BLUEPRINT)
|
||||
.param("query", query)
|
||||
.param("context", String.join("\n", contentList)))
|
||||
.call()
|
||||
.chatResponse();
|
||||
log.info("chat response: {}", response);
|
||||
String answer = response.getResult().getOutput().getContent();
|
||||
//
|
||||
return ResponseEntity.ok(JsonResult.success("chat success", answer));
|
||||
}
|
||||
// ChatResponse response = chatClient.prompt()
|
||||
// .user(userSpec -> userSpec
|
||||
// .text(PROMPT_BLUEPRINT)
|
||||
// .param("query", query)
|
||||
// .param("context", String.join("\n", contentList)))
|
||||
// .call()
|
||||
// .chatResponse();
|
||||
// log.info("chat response: {}", response);
|
||||
// String answer = response.getResult().getOutput().getContent();
|
||||
// //
|
||||
// return ResponseEntity.ok(JsonResult.success("chat success", answer));
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-09-27 14:58:12
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-27 16:22:18
|
||||
* @LastEditTime: 2024-10-15 17:46:42
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
package com.bytedesk.ai.provider.ollama;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.agentsflex.core.llm.Llm;
|
||||
@@ -23,9 +24,10 @@ import com.agentsflex.llm.ollama.OllamaLlm;
|
||||
import com.agentsflex.llm.ollama.OllamaLlmConfig;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bytedesk.ai.robot.RobotLlm;
|
||||
import com.bytedesk.core.message.IMessageSendService;
|
||||
import com.bytedesk.core.message.MessageProtobuf;
|
||||
import com.bytedesk.core.message.MessageTypeEnum;
|
||||
import com.bytedesk.core.message.MessageUtils;
|
||||
// import com.bytedesk.core.message.MessageUtils;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -33,6 +35,8 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Service
|
||||
public class OllamaService {
|
||||
|
||||
@Autowired
|
||||
private IMessageSendService messageSendService;
|
||||
|
||||
public void sendSseMessage(String query, RobotLlm robotllm, MessageProtobuf messageProtobuf) {
|
||||
//
|
||||
@@ -69,7 +73,8 @@ public class OllamaService {
|
||||
AiMessage aiMessage = response.getMessage();
|
||||
messageProtobuf.setType(MessageTypeEnum.STREAM);
|
||||
messageProtobuf.setContent(aiMessage.getContent());
|
||||
MessageUtils.notifyUser(messageProtobuf);
|
||||
// MessageUtils.notifyUser(messageProtobuf);
|
||||
messageSendService.sendMessage(messageProtobuf);
|
||||
//
|
||||
if (aiMessage.getStatus().equals(MessageStatus.END)) {
|
||||
log.info("aiMessage.getStatus() == END");
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-06-05 15:39:22
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-27 16:15:28
|
||||
* @LastEditTime: 2024-10-17 17:20:36
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -31,13 +31,14 @@ import com.bytedesk.ai.robot.RobotMessage;
|
||||
import com.bytedesk.ai.robot.RobotProtobuf;
|
||||
import com.bytedesk.ai.robot.RobotTypeEnum;
|
||||
import com.bytedesk.core.enums.ClientEnum;
|
||||
import com.bytedesk.core.thread.Thread;
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.thread.ThreadEntity;
|
||||
import com.bytedesk.core.message.IMessageSendService;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
import com.bytedesk.core.message.MessageProtobuf;
|
||||
import com.bytedesk.core.message.MessageService;
|
||||
import com.bytedesk.core.message.MessageStatusEnum;
|
||||
import com.bytedesk.core.message.MessageTypeEnum;
|
||||
import com.bytedesk.core.message.MessageUtils;
|
||||
// import com.bytedesk.core.message.MessageUtils;
|
||||
import com.bytedesk.core.rbac.user.UserProtobuf;
|
||||
import com.bytedesk.core.thread.ThreadService;
|
||||
import com.bytedesk.core.uid.UidUtils;
|
||||
@@ -83,6 +84,8 @@ public class ZhipuaiService {
|
||||
|
||||
private final UploadVectorStore uploadVectorStore;
|
||||
|
||||
private final IMessageSendService messageSendService;
|
||||
|
||||
// private final BytedeskEventPublisher bytedeskEventPublisher;
|
||||
|
||||
private final String PROMPT_BLUEPRINT = """
|
||||
@@ -98,7 +101,7 @@ public class ZhipuaiService {
|
||||
*/
|
||||
public void getSseAnswer(String uid, String sid, String question, SseEmitter emitter) {
|
||||
String topic = sid + "/" + uid;
|
||||
Thread thread = threadService.findByTopic(topic)
|
||||
ThreadEntity thread = threadService.findByTopic(topic)
|
||||
.orElseThrow(() -> new RuntimeException("thread with topic: " + topic + " not found"));
|
||||
|
||||
RobotMessage robotMessage = RobotMessage.builder().question(question).build();
|
||||
@@ -109,7 +112,7 @@ public class ZhipuaiService {
|
||||
UserProtobuf user = modelMapper.map(thread.getAgent(), UserProtobuf.class);
|
||||
//
|
||||
String messageUid = uidUtils.getCacheSerialUid();
|
||||
Message message = Message.builder()
|
||||
MessageEntity message = MessageEntity.builder()
|
||||
.type(MessageTypeEnum.ROBOT.name())
|
||||
.status(MessageStatusEnum.SUCCESS.name())
|
||||
.client(ClientEnum.SYSTEM.name())
|
||||
@@ -264,7 +267,8 @@ public class ZhipuaiService {
|
||||
messageProtobuf.setType(MessageTypeEnum.STREAM);
|
||||
messageProtobuf.setContent(answerContent);
|
||||
//
|
||||
MessageUtils.notifyUser(messageProtobuf);
|
||||
// MessageUtils.notifyUser(messageProtobuf);
|
||||
messageSendService.sendMessage(messageProtobuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -344,9 +348,8 @@ public class ZhipuaiService {
|
||||
messageProtobuf.setType(MessageTypeEnum.STREAM);
|
||||
messageProtobuf.setContent(answerContent);
|
||||
//
|
||||
MessageUtils.notifyUser(messageProtobuf);
|
||||
// String json = JSON.toJSONString(messageProtobuf);
|
||||
// bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
// MessageUtils.notifyUser(messageProtobuf);
|
||||
messageSendService.sendMessage(messageProtobuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -419,9 +422,8 @@ public class ZhipuaiService {
|
||||
messageProtobuf.setType(MessageTypeEnum.STREAM);
|
||||
messageProtobuf.setContent(answerContent);
|
||||
//
|
||||
MessageUtils.notifyUser(messageProtobuf);
|
||||
// String json = JSON.toJSONString(messageProtobuf);
|
||||
// bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
// MessageUtils.notifyUser(messageProtobuf);
|
||||
messageSendService.sendMessage(messageProtobuf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-06-12 07:17:13
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-28 10:37:37
|
||||
* @LastEditTime: 2024-10-15 18:06:58
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -14,7 +14,6 @@
|
||||
*/
|
||||
package com.bytedesk.ai.robot;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.Optional;
|
||||
|
||||
@@ -30,10 +29,10 @@ import com.bytedesk.ai.provider.ollama.OllamaService;
|
||||
import com.bytedesk.ai.provider.zhipuai.ZhipuaiService;
|
||||
import com.bytedesk.core.config.BytedeskProperties;
|
||||
import com.bytedesk.core.enums.ClientEnum;
|
||||
import com.bytedesk.core.message.IMessageSendService;
|
||||
import com.bytedesk.core.message.MessageCache;
|
||||
import com.bytedesk.core.message.MessageExtra;
|
||||
import com.bytedesk.core.message.MessageJsonEvent;
|
||||
import com.bytedesk.core.message.MessageProtoEvent;
|
||||
import com.bytedesk.core.message.MessageProtobuf;
|
||||
import com.bytedesk.core.message.MessageStatusEnum;
|
||||
import com.bytedesk.core.message.MessageTypeEnum;
|
||||
@@ -43,15 +42,11 @@ import com.bytedesk.core.rbac.organization.OrganizationCreateEvent;
|
||||
import com.bytedesk.core.rbac.user.UserProtobuf;
|
||||
import com.bytedesk.core.rbac.user.UserTypeEnum;
|
||||
import com.bytedesk.core.redis.pubsub.RedisPubsubService;
|
||||
import com.bytedesk.core.socket.protobuf.model.MessageProto;
|
||||
import com.bytedesk.core.thread.ThreadProtobuf;
|
||||
import com.bytedesk.core.thread.ThreadService;
|
||||
import com.bytedesk.core.thread.ThreadTypeEnum;
|
||||
import com.bytedesk.core.thread.Thread;
|
||||
import com.bytedesk.core.thread.ThreadEntity;
|
||||
import com.bytedesk.core.uid.UidUtils;
|
||||
import com.bytedesk.core.utils.MessageConvertUtils;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -76,6 +71,8 @@ public class RobotEventListener {
|
||||
|
||||
private final MessageCache messageCache;
|
||||
|
||||
private final IMessageSendService messageSendService;
|
||||
|
||||
@Order(5)
|
||||
@EventListener
|
||||
public void onOrganizationCreateEvent(OrganizationCreateEvent event) {
|
||||
@@ -84,36 +81,9 @@ public class RobotEventListener {
|
||||
log.info("robot - organization created: {}", organization.getName());
|
||||
//
|
||||
robotService.createDefaultRobot(orgUid, uidUtils.getCacheSerialUid());
|
||||
robotService.createDefaultAgentAsistantRobot(orgUid);
|
||||
robotService.createDefaultAgentAssistantRobot(orgUid);
|
||||
}
|
||||
|
||||
// 直接迁移到robotService.createThread方法
|
||||
// @EventListener
|
||||
// public void onThreadCreateEvent(ThreadCreateEvent event) {
|
||||
// Thread thread = event.getThread();
|
||||
// log.info("robot ThreadCreateEvent: {}", thread.getUid());
|
||||
// //
|
||||
// if (thread.getType().equals(ThreadTypeEnum.LLM.name())
|
||||
// && thread.getAgent().equals(BdConstants.EMPTY_JSON_STRING)) {
|
||||
// // 机器人会话:org/robot/{robot_uid}/{visitor_uid}
|
||||
// String topic = thread.getTopic();
|
||||
// //
|
||||
// String[] splits = topic.split("/");
|
||||
// if (splits.length < 4) {
|
||||
// throw new RuntimeException("robot topic format error");
|
||||
// }
|
||||
// String robotUid = splits[2];
|
||||
// Optional<Robot> robotOptional = robotService.findByUid(robotUid);
|
||||
// if (robotOptional.isPresent()) {
|
||||
// Robot robot = robotOptional.get();
|
||||
// // 更新机器人配置+大模型相关信息
|
||||
// thread.setAgent(JSON.toJSONString(ConvertAiUtils.convertToRobotProtobuf(robot)));
|
||||
// //
|
||||
// threadService.save(thread);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
@EventListener
|
||||
public void onMessageJsonEvent(MessageJsonEvent event) {
|
||||
// log.info("MessageJsonEvent {}", event.getJson());
|
||||
@@ -122,24 +92,24 @@ public class RobotEventListener {
|
||||
processMessage(messageJson);
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void onMessageProtoEvent(MessageProtoEvent event) {
|
||||
// log.info("MessageProtoEvent");
|
||||
try {
|
||||
MessageProto.Message messageProto = MessageProto.Message.parseFrom(event.getMessageBytes());
|
||||
//
|
||||
try {
|
||||
String messageJson = MessageConvertUtils.toJson(messageProto);
|
||||
//
|
||||
processMessage(messageJson);
|
||||
// @EventListener
|
||||
// public void onMessageProtoEvent(MessageProtoEvent event) {
|
||||
// // log.info("MessageProtoEvent");
|
||||
// try {
|
||||
// MessageProto.Message messageProto = MessageProto.Message.parseFrom(event.getMessageBytes());
|
||||
// //
|
||||
// try {
|
||||
// String messageJson = MessageConvertUtils.toJson(messageProto);
|
||||
// //
|
||||
// processMessage(messageJson);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// } catch (InvalidProtocolBufferException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
private void processMessage(String messageJson) {
|
||||
MessageProtobuf messageProtobuf = JSON.parseObject(messageJson, MessageProtobuf.class);
|
||||
@@ -189,11 +159,11 @@ public class RobotEventListener {
|
||||
} else if (threadProtobuf.getType().equals(ThreadTypeEnum.LLM)) {
|
||||
log.info("robot llm threadTopic {}, thread.type {}", threadTopic, threadProtobuf.getType());
|
||||
// 大模型对话,无知识库
|
||||
Optional<Thread> threadOptional = threadService.findByTopic(threadTopic);
|
||||
Optional<ThreadEntity> threadOptional = threadService.findByTopic(threadTopic);
|
||||
if (!threadOptional.isPresent()) {
|
||||
throw new RuntimeException("thread with topic " + threadTopic + " not found");
|
||||
}
|
||||
Thread thread = threadOptional.get();
|
||||
ThreadEntity thread = threadOptional.get();
|
||||
MessageExtra extraObject = JSONObject.parseObject(messageProtobuf.getExtra(), MessageExtra.class);
|
||||
//
|
||||
String agent = thread.getAgent();
|
||||
@@ -217,7 +187,8 @@ public class RobotEventListener {
|
||||
MessageProtobuf clonedMessage = SerializationUtils.clone(message);
|
||||
clonedMessage.setUid(uidUtils.getCacheSerialUid());
|
||||
clonedMessage.setType(MessageTypeEnum.PROCESSING);
|
||||
MessageUtils.notifyUser(clonedMessage);
|
||||
// MessageUtils.notifyUser(clonedMessage);
|
||||
messageSendService.sendMessage(clonedMessage);
|
||||
//
|
||||
// TODO: 获取大模型配置
|
||||
// robotProtobuf.getLlm().getProvider()
|
||||
@@ -236,7 +207,7 @@ public class RobotEventListener {
|
||||
|| threadProtobuf.getType().equals(ThreadTypeEnum.KBDOC)) {
|
||||
log.info("robot agent/workgroup threadTopic {}, thread.type {}", threadTopic, threadProtobuf.getType());
|
||||
// TODO: 取消查库
|
||||
Thread thread = threadService.findByTopic(threadTopic)
|
||||
ThreadEntity thread = threadService.findByTopic(threadTopic)
|
||||
.orElseThrow(() -> new RuntimeException("thread with topic " + threadTopic + " not found"));
|
||||
UserProtobuf agent = JSON.parseObject(thread.getAgent(), UserProtobuf.class);
|
||||
// 当前会话为机器人接待,而且是访客发送的消息
|
||||
@@ -272,8 +243,8 @@ public class RobotEventListener {
|
||||
MessageProtobuf clonedMessage = SerializationUtils.clone(message);
|
||||
clonedMessage.setUid(uidUtils.getCacheSerialUid());
|
||||
clonedMessage.setType(MessageTypeEnum.PROCESSING);
|
||||
//
|
||||
MessageUtils.notifyUser(clonedMessage);
|
||||
// MessageUtils.notifyUser(clonedMessage);
|
||||
messageSendService.sendMessage(clonedMessage);
|
||||
// 知识库
|
||||
if (bytedeskProperties.getJavaai()) {
|
||||
zhipuaiService.sendWsKbMessage(query, robot.getKbUid(), robot, message);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-03-22 16:44:41
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-28 10:25:02
|
||||
* @LastEditTime: 2024-10-14 09:28:31
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -44,11 +44,11 @@ import com.bytedesk.core.constant.I18Consts;
|
||||
import com.bytedesk.core.enums.LevelEnum;
|
||||
import com.bytedesk.core.rbac.auth.AuthService;
|
||||
import com.bytedesk.core.rbac.user.User;
|
||||
import com.bytedesk.core.thread.Thread;
|
||||
import com.bytedesk.core.thread.ThreadEntity;
|
||||
import com.bytedesk.core.thread.ThreadRequest;
|
||||
import com.bytedesk.core.thread.ThreadResponse;
|
||||
import com.bytedesk.core.thread.ThreadService;
|
||||
import com.bytedesk.core.thread.ThreadStatusEnum;
|
||||
import com.bytedesk.core.thread.ThreadStateEnum;
|
||||
import com.bytedesk.core.constant.AvatarConsts;
|
||||
// import com.bytedesk.core.quick_button.QuickButton;
|
||||
// import com.bytedesk.core.quick_button.QuickButtonService;
|
||||
@@ -178,18 +178,18 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
}
|
||||
|
||||
public ThreadResponse createThread(ThreadRequest request) {
|
||||
//
|
||||
//
|
||||
User owner = authService.getCurrentUser();
|
||||
String topic = request.getTopic();
|
||||
//
|
||||
Optional<Thread> threadOptional = threadService.findByTopicAndOwner(topic, owner);
|
||||
Optional<ThreadEntity> threadOptional = threadService.findByTopicAndOwner(topic, owner);
|
||||
if (threadOptional.isPresent()) {
|
||||
return threadService.convertToResponse(threadOptional.get());
|
||||
}
|
||||
//
|
||||
Thread thread = modelMapper.map(request, Thread.class);
|
||||
ThreadEntity thread = modelMapper.map(request, ThreadEntity.class);
|
||||
thread.setUid(uidUtils.getUid());
|
||||
thread.setStatus(ThreadStatusEnum.START.name());
|
||||
thread.setState(ThreadStateEnum.STARTED.name());
|
||||
//
|
||||
String user = JSON.toJSONString(request.getUser());
|
||||
log.info("request {}, user {}", request.toString(), user);
|
||||
@@ -213,7 +213,7 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
thread.setOwner(owner);
|
||||
thread.setOrgUid(owner.getOrgUid());
|
||||
//
|
||||
Thread savedThread = threadService.save(thread);
|
||||
ThreadEntity savedThread = threadService.save(thread);
|
||||
if (savedThread == null) {
|
||||
throw new RuntimeException("thread save failed");
|
||||
}
|
||||
@@ -222,17 +222,17 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
}
|
||||
|
||||
public ThreadResponse updateThread(ThreadRequest request) {
|
||||
//
|
||||
//
|
||||
String topic = request.getTopic();
|
||||
Optional<Thread> threadOptional = threadService.findByTopic(topic);
|
||||
Optional<ThreadEntity> threadOptional = threadService.findByTopic(topic);
|
||||
if (!threadOptional.isPresent()) {
|
||||
throw new RuntimeException("thread not found");
|
||||
}
|
||||
Thread thread = threadOptional.get();
|
||||
ThreadEntity thread = threadOptional.get();
|
||||
thread.setUser(JSON.toJSONString(request.getUser()));
|
||||
thread.setAgent(request.getAgent());
|
||||
//
|
||||
Thread savedThread = threadService.save(thread);
|
||||
ThreadEntity savedThread = threadService.save(thread);
|
||||
if (savedThread == null) {
|
||||
throw new RuntimeException("thread save failed");
|
||||
}
|
||||
@@ -275,7 +275,7 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//
|
||||
if (request.getServiceSettings() != null
|
||||
&& request.getServiceSettings().getQuickFaqUids() != null
|
||||
&& request.getServiceSettings().getQuickFaqUids().size() > 0) {
|
||||
@@ -362,7 +362,8 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
}
|
||||
|
||||
// public Boolean existsByNicknameAndPlatform(String name) {
|
||||
// return robotRepository.existsByNicknameAndLevel(name, LevelEnum.PLATFORM.name());
|
||||
// return robotRepository.existsByNicknameAndLevel(name,
|
||||
// LevelEnum.PLATFORM.name());
|
||||
// }
|
||||
|
||||
public Boolean existsByUid(String uid) {
|
||||
@@ -426,10 +427,10 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
return create(robotRequest);
|
||||
}
|
||||
|
||||
public RobotResponse createDefaultAgentAsistantRobot(String orgUid) {
|
||||
public RobotResponse createDefaultAgentAssistantRobot(String orgUid) {
|
||||
//
|
||||
RobotRequest robotRequest = RobotRequest.builder()
|
||||
.nickname(I18Consts.I18N_ROBOT_AGENT_ASISTANT_NICKNAME)
|
||||
.nickname(I18Consts.I18N_ROBOT_AGENT_ASSISTANT_NICKNAME)
|
||||
.build();
|
||||
// robotRequest.setType(RobotTypeEnum.AGENT_ASSISTANT.name());
|
||||
robotRequest.setType(RobotTypeEnum.KB.name());
|
||||
@@ -440,10 +441,10 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
|
||||
// 从json创建平台机器人
|
||||
public RobotResponse createRobotFromJson(RobotJson robotJson) {
|
||||
|
||||
|
||||
log.info("robotJson {}", robotJson.getNickname());
|
||||
RobotLlm llm = RobotLlm.builder().prompt(robotJson.getPrompt()).build();
|
||||
//
|
||||
//
|
||||
Robot robot = Robot.builder()
|
||||
.nickname(robotJson.getNickname())
|
||||
.avatar(robotJson.getAvatar())
|
||||
@@ -464,6 +465,14 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
}
|
||||
|
||||
public void initData() {
|
||||
|
||||
if (robotRepository.count() > 0) {
|
||||
return;
|
||||
}
|
||||
//
|
||||
String orgUid = BdConstants.DEFAULT_ORGANIZATION_UID;
|
||||
createDefaultRobot(orgUid, BdConstants.DEFAULT_ROBOT_UID);
|
||||
createDefaultAgentAssistantRobot(orgUid);
|
||||
//
|
||||
Map<String, ProviderJson> providerJsonMap = robotJsonService.loadProviders();
|
||||
for (Map.Entry<String, ProviderJson> entry : providerJsonMap.entrySet()) {
|
||||
@@ -473,7 +482,7 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
llmProviderService.createFromProviderJson(providerName, providerJson);
|
||||
}
|
||||
}
|
||||
//
|
||||
//
|
||||
Map<String, List<ModelJson>> modelJsonMap = robotJsonService.loadModels();
|
||||
for (Map.Entry<String, List<ModelJson>> entry : modelJsonMap.entrySet()) {
|
||||
String providerName = entry.getKey();
|
||||
@@ -484,21 +493,13 @@ public class RobotService extends BaseService<Robot, RobotRequest, RobotResponse
|
||||
}
|
||||
}
|
||||
}
|
||||
//
|
||||
//
|
||||
List<RobotJson> robotJsons = robotJsonService.loadRobots();
|
||||
for (RobotJson robotJson : robotJsons) {
|
||||
if (!existsByUid(robotJson.getUid())) {
|
||||
createRobotFromJson(robotJson);
|
||||
}
|
||||
}
|
||||
if (robotRepository.count() > 0) {
|
||||
return;
|
||||
}
|
||||
//
|
||||
String orgUid = BdConstants.DEFAULT_ORGANIZATION_UID;
|
||||
createDefaultRobot(orgUid, BdConstants.DEFAULT_ROBOT_UID);
|
||||
createDefaultAgentAsistantRobot(orgUid);
|
||||
//
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
BIN
modules/core/.DS_Store
vendored
BIN
modules/core/.DS_Store
vendored
Binary file not shown.
@@ -13,7 +13,7 @@
|
||||
<artifactId>bytedesk-module-core</artifactId>
|
||||
|
||||
<name>bytedesk-module-core</name>
|
||||
<description>https://www.weiyuai.cn</description>
|
||||
<description>https://ai.bytedesk.com</description>
|
||||
|
||||
<properties>
|
||||
<jsonwebtoken.version>0.12.5</jsonwebtoken.version>
|
||||
@@ -42,6 +42,38 @@
|
||||
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-artemis</artifactId>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- spring statemachine - 迁移到 cola statemachine -->
|
||||
<!-- https://github.com/spring-projects/spring-statemachine -->
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.statemachine/spring-statemachine-starter -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.statemachine</groupId>
|
||||
<artifactId>spring-statemachine-starter</artifactId>
|
||||
<version>4.0.0</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.statemachine/spring-statemachine-data-jpa -->
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework.statemachine</groupId>
|
||||
<artifactId>spring-statemachine-data-jpa</artifactId>
|
||||
<version>4.0.0</version>
|
||||
</dependency> -->
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.statemachine/spring-statemachine-data-redis -->
|
||||
<!-- <dependency>
|
||||
<groupId>org.springframework.statemachine</groupId>
|
||||
<artifactId>spring-statemachine-data-redis</artifactId>
|
||||
<version>4.0.0</version>
|
||||
</dependency> -->
|
||||
<!-- 替换上面的 spring-statemachine https://mvnrepository.com/artifact/com.alibaba.cola/cola-component-statemachine -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba.cola</groupId>
|
||||
<artifactId>cola-component-statemachine</artifactId>
|
||||
<version>5.0.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
|
||||
<dependency>
|
||||
|
||||
BIN
modules/core/src/.DS_Store
vendored
BIN
modules/core/src/.DS_Store
vendored
Binary file not shown.
BIN
modules/core/src/main/.DS_Store
vendored
BIN
modules/core/src/main/.DS_Store
vendored
Binary file not shown.
BIN
modules/core/src/main/java/.DS_Store
vendored
BIN
modules/core/src/main/java/.DS_Store
vendored
Binary file not shown.
BIN
modules/core/src/main/java/com/.DS_Store
vendored
BIN
modules/core/src/main/java/com/.DS_Store
vendored
Binary file not shown.
BIN
modules/core/src/main/java/com/bytedesk/.DS_Store
vendored
BIN
modules/core/src/main/java/com/bytedesk/.DS_Store
vendored
Binary file not shown.
Binary file not shown.
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-26 20:32:23
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-08-04 12:13:14
|
||||
* @LastEditTime: 2024-10-14 09:30:58
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.asistant;
|
||||
package com.bytedesk.core.assistant;
|
||||
|
||||
import com.bytedesk.core.base.BaseEntityNoOrg;
|
||||
import com.bytedesk.core.constant.AvatarConsts;
|
||||
@@ -30,7 +30,7 @@ import lombok.NoArgsConstructor;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* asistant - 如:文件助手
|
||||
* assistant - 如:文件助手
|
||||
*/
|
||||
@Entity
|
||||
@Data
|
||||
@@ -39,9 +39,9 @@ import lombok.experimental.Accessors;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EntityListeners({ AsistantEntityListener.class })
|
||||
@Table(name = "core_asistant")
|
||||
public class Asistant extends BaseEntityNoOrg {
|
||||
@EntityListeners({ AssistantEntityListener.class })
|
||||
@Table(name = "core_assistant")
|
||||
public class Assistant extends BaseEntityNoOrg {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-26 21:04:43
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-07-09 10:52:52
|
||||
* @LastEditTime: 2024-10-14 09:31:08
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.asistant;
|
||||
package com.bytedesk.core.assistant;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
@@ -30,23 +30,23 @@ import lombok.RequiredArgsConstructor;
|
||||
*/
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@RequestMapping("/api/v1/asistant")
|
||||
@Tag(name = "asistant - 助手", description = "asistant apis")
|
||||
public class AsistantController {
|
||||
@RequestMapping("/api/v1/assistant")
|
||||
@Tag(name = "assistant - 助手", description = "assistant apis")
|
||||
public class AssistantController {
|
||||
|
||||
private final AsistantService asistantService;
|
||||
private final AssistantService assistantService;
|
||||
|
||||
/**
|
||||
* query asistant
|
||||
* query assistant
|
||||
*
|
||||
* @return json
|
||||
*/
|
||||
@GetMapping("/query")
|
||||
public ResponseEntity<?> query(AsistantRequest asistantRequest) {
|
||||
public ResponseEntity<?> query(AssistantRequest assistantRequest) {
|
||||
//
|
||||
Page<AsistantResponse> asistantPage = asistantService.query(asistantRequest);
|
||||
Page<AssistantResponse> assistantPage = assistantService.query(assistantRequest);
|
||||
//
|
||||
return ResponseEntity.ok(JsonResult.success(asistantPage));
|
||||
return ResponseEntity.ok(JsonResult.success(assistantPage));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-27 12:09:59
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-06-25 10:31:03
|
||||
* @LastEditTime: 2024-10-14 09:31:18
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.asistant;
|
||||
package com.bytedesk.core.assistant;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -21,11 +21,11 @@ import jakarta.persistence.PostPersist;
|
||||
|
||||
// @Slf4j
|
||||
@Component
|
||||
public class AsistantEntityListener {
|
||||
public class AssistantEntityListener {
|
||||
|
||||
@PostPersist
|
||||
public void onPostPersist(Asistant asistant) {
|
||||
// log.debug("AsistantListener: onPostPersist {}", asistant.getNickname());
|
||||
public void onPostPersist(Assistant assistant) {
|
||||
// log.debug("AssistantListener: onPostPersist {}", assistant.getNickname());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-08-04 11:32:22
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-08-04 11:53:24
|
||||
* @LastEditTime: 2024-10-14 09:31:45
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.asistant;
|
||||
package com.bytedesk.core.assistant;
|
||||
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -27,17 +27,17 @@ import lombok.extern.slf4j.Slf4j;
|
||||
@Slf4j
|
||||
@Component
|
||||
@AllArgsConstructor
|
||||
public class AsistantEventListener {
|
||||
public class AssistantEventListener {
|
||||
|
||||
private final ThreadService threadService;
|
||||
|
||||
@EventListener
|
||||
public void onUserCreateEvent(UserCreateEvent event) {
|
||||
User user = event.getUser();
|
||||
log.info("asistant onUserCreateEvent: {}", user.getUid());
|
||||
log.info("assistant onUserCreateEvent: {}", user.getUid());
|
||||
//
|
||||
// 每创建一个用户,自动给此用户生成一条文件助理的会话
|
||||
threadService.createFileAsistantThread(user);
|
||||
threadService.createFileAssistantThread(user);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-26 21:07:55
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-04-26 21:10:46
|
||||
* @LastEditTime: 2024-10-14 09:32:04
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -12,10 +12,10 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.asistant;
|
||||
package com.bytedesk.core.assistant;
|
||||
|
||||
import org.springframework.data.jpa.repository.JpaRepository;
|
||||
|
||||
public interface AsistantRepository extends JpaRepository<Asistant, Long> {
|
||||
public interface AssistantRepository extends JpaRepository<Assistant, Long> {
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-26 21:05:09
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-08-04 12:14:23
|
||||
* @LastEditTime: 2024-10-14 09:32:11
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.asistant;
|
||||
package com.bytedesk.core.assistant;
|
||||
|
||||
import com.bytedesk.core.base.BaseRequestNoOrg;
|
||||
|
||||
@@ -25,7 +25,7 @@ import lombok.experimental.Accessors;
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AsistantRequest extends BaseRequestNoOrg {
|
||||
public class AssistantRequest extends BaseRequestNoOrg {
|
||||
|
||||
private String topic;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.asistant;
|
||||
package com.bytedesk.core.assistant;
|
||||
|
||||
import com.bytedesk.core.base.BaseResponse;
|
||||
|
||||
@@ -25,7 +25,7 @@ import lombok.experimental.Accessors;
|
||||
@Builder
|
||||
@Accessors(chain = true)
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class AsistantResponse extends BaseResponse {
|
||||
public class AssistantResponse extends BaseResponse {
|
||||
|
||||
// private String aid;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-26 21:04:54
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-26 10:33:02
|
||||
* @LastEditTime: 2024-10-14 09:35:01
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.asistant;
|
||||
package com.bytedesk.core.assistant;
|
||||
|
||||
import org.modelmapper.ModelMapper;
|
||||
import org.springframework.data.domain.Page;
|
||||
@@ -33,60 +33,60 @@ import lombok.AllArgsConstructor;
|
||||
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class AsistantService {
|
||||
public class AssistantService {
|
||||
|
||||
private final AsistantRepository asistantRepository;
|
||||
private final AssistantRepository assistantRepository;
|
||||
|
||||
private final ModelMapper modelMapper;
|
||||
|
||||
private final UidUtils uidUtils;
|
||||
|
||||
public Page<AsistantResponse> query(AsistantRequest asistantRequest) {
|
||||
public Page<AssistantResponse> query(AssistantRequest assistantRequest) {
|
||||
|
||||
Pageable pageable = PageRequest.of(asistantRequest.getPageNumber(), asistantRequest.getPageSize(),
|
||||
Pageable pageable = PageRequest.of(assistantRequest.getPageNumber(), assistantRequest.getPageSize(),
|
||||
Sort.Direction.ASC,
|
||||
"id");
|
||||
|
||||
Page<Asistant> asistantPage = asistantRepository.findAll(pageable);
|
||||
Page<Assistant> assistantPage = assistantRepository.findAll(pageable);
|
||||
|
||||
return asistantPage.map(asistant -> convertToResponse(asistant));
|
||||
return assistantPage.map(assistant -> convertToResponse(assistant));
|
||||
}
|
||||
|
||||
public Asistant create(AsistantRequest asistantRequest) {
|
||||
public Assistant create(AssistantRequest assistantRequest) {
|
||||
|
||||
Asistant asistant = modelMapper.map(asistantRequest, Asistant.class);
|
||||
if (!StringUtils.hasText(asistant.getUid())) {
|
||||
asistant.setUid(uidUtils.getUid());
|
||||
Assistant assistant = modelMapper.map(assistantRequest, Assistant.class);
|
||||
if (!StringUtils.hasText(assistant.getUid())) {
|
||||
assistant.setUid(uidUtils.getUid());
|
||||
}
|
||||
|
||||
return save(asistant);
|
||||
return save(assistant);
|
||||
}
|
||||
|
||||
private Asistant save(Asistant asistant) {
|
||||
return asistantRepository.save(asistant);
|
||||
private Assistant save(Assistant assistant) {
|
||||
return assistantRepository.save(assistant);
|
||||
}
|
||||
|
||||
public AsistantResponse convertToResponse(Asistant asistant) {
|
||||
return modelMapper.map(asistant, AsistantResponse.class);
|
||||
public AssistantResponse convertToResponse(Assistant assistant) {
|
||||
return modelMapper.map(assistant, AssistantResponse.class);
|
||||
}
|
||||
|
||||
//
|
||||
public void initData() {
|
||||
|
||||
if (asistantRepository.count() > 0) {
|
||||
if (assistantRepository.count() > 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
AsistantRequest asistantRequest = AsistantRequest.builder()
|
||||
.topic(TopicUtils.TOPIC_FILE_ASISTANT)
|
||||
.nickname(I18Consts.I18N_FILE_ASISTANT_NAME)
|
||||
.avatar(AvatarConsts.DEFAULT_FILE_ASISTANT_AVATAR_URL)
|
||||
.description(I18Consts.I18N_FILE_ASISTANT_DESCRIPTION)
|
||||
AssistantRequest assistantRequest = AssistantRequest.builder()
|
||||
.topic(TopicUtils.TOPIC_FILE_ASSISTANT)
|
||||
.nickname(I18Consts.I18N_FILE_ASSISTANT_NAME)
|
||||
.avatar(AvatarConsts.DEFAULT_FILE_ASSISTANT_AVATAR_URL)
|
||||
.description(I18Consts.I18N_FILE_ASSISTANT_DESCRIPTION)
|
||||
.build();
|
||||
asistantRequest.setUid(BdConstants.DEFAULT_FILE_ASISTANT_UID);
|
||||
asistantRequest.setType(TypeConsts.TYPE_SYSTEM);
|
||||
// asistantRequest.setOrgUid(BdConstants.DEFAULT_ORGANIZATION_UID);
|
||||
create(asistantRequest);
|
||||
assistantRequest.setUid(BdConstants.DEFAULT_FILE_ASSISTANT_UID);
|
||||
assistantRequest.setType(TypeConsts.TYPE_SYSTEM);
|
||||
// assistantRequest.setOrgUid(BdConstants.DEFAULT_ORGANIZATION_UID);
|
||||
create(assistantRequest);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-02-23 14:42:58
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-20 10:29:14
|
||||
* @LastEditTime: 2024-10-18 13:39:21
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -22,12 +22,16 @@ import com.bytedesk.core.action.Action;
|
||||
import com.bytedesk.core.action.ActionCreateEvent;
|
||||
import com.bytedesk.core.event.GenericApplicationEvent;
|
||||
// import com.bytedesk.core.cache.CaffeineCacheGroupEvent;
|
||||
import com.bytedesk.core.message.MessageProtoEvent;
|
||||
// import com.bytedesk.core.message.MessageProtoEvent;
|
||||
import com.bytedesk.core.message.MessageUpdateEvent;
|
||||
import com.bytedesk.core.quartz.event.QuartzDay0Event;
|
||||
import com.bytedesk.core.quartz.event.QuartzDay8Event;
|
||||
import com.bytedesk.core.quartz.event.QuartzFiveMinEvent;
|
||||
import com.bytedesk.core.quartz.event.QuartzFiveSecondEvent;
|
||||
import com.bytedesk.core.quartz.event.QuartzHalfHourEvent;
|
||||
import com.bytedesk.core.quartz.event.QuartzHourlyEvent;
|
||||
import com.bytedesk.core.quartz.event.QuartzOneMinEvent;
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
import com.bytedesk.core.message.MessageCreateEvent;
|
||||
import com.bytedesk.core.message.MessageJsonEvent;
|
||||
import com.bytedesk.core.rbac.organization.Organization;
|
||||
@@ -43,10 +47,9 @@ import com.bytedesk.core.socket.stomp.StompConnectedEvent;
|
||||
import com.bytedesk.core.socket.stomp.StompDisconnectedEvent;
|
||||
import com.bytedesk.core.socket.stomp.StompSubscribeEvent;
|
||||
import com.bytedesk.core.socket.stomp.StompUnsubscribeEvent;
|
||||
import com.bytedesk.core.thread.Thread;
|
||||
import com.bytedesk.core.thread.ThreadEntity;
|
||||
import com.bytedesk.core.thread.ThreadCreateEvent;
|
||||
import com.bytedesk.core.thread.ThreadUpdateEvent;
|
||||
import com.bytedesk.core.thread.ThreadUpdateStatusEvent;
|
||||
import com.bytedesk.core.topic.TopicCreateEvent;
|
||||
import com.bytedesk.core.topic.TopicUpdateEvent;
|
||||
|
||||
@@ -79,22 +82,38 @@ public class BytedeskEventPublisher {
|
||||
applicationEventPublisher.publishEvent(new UserUpdateEvent(user));
|
||||
}
|
||||
|
||||
public void publishMessageProtoEvent(byte[] messageBytes) {
|
||||
applicationEventPublisher.publishEvent(new MessageProtoEvent(this, messageBytes));
|
||||
}
|
||||
// public void publishMessageProtoEvent(byte[] messageBytes) {
|
||||
// applicationEventPublisher.publishEvent(new MessageProtoEvent(this, messageBytes));
|
||||
// }
|
||||
|
||||
public void publishMessageJsonEvent(String json) {
|
||||
applicationEventPublisher.publishEvent(new MessageJsonEvent(this, json));
|
||||
}
|
||||
|
||||
public void publishMessageCreateEvent(Message message) {
|
||||
public void publishMessageCreateEvent(MessageEntity message) {
|
||||
applicationEventPublisher.publishEvent(new MessageCreateEvent(this, message));
|
||||
}
|
||||
|
||||
public void publishMessageUpdateEvent(Message message) {
|
||||
public void publishMessageUpdateEvent(MessageEntity message) {
|
||||
applicationEventPublisher.publishEvent(new MessageUpdateEvent(this, message));
|
||||
}
|
||||
|
||||
public void publishQuartzDay8Event() {
|
||||
applicationEventPublisher.publishEvent(new QuartzDay8Event(this));
|
||||
}
|
||||
|
||||
public void publishQuartzDay0Event() {
|
||||
applicationEventPublisher.publishEvent(new QuartzDay0Event(this));
|
||||
}
|
||||
|
||||
public void publishQuartzHourlyEvent() {
|
||||
applicationEventPublisher.publishEvent(new QuartzHourlyEvent(this));
|
||||
}
|
||||
|
||||
public void publishQuartzHalfHourEvent() {
|
||||
applicationEventPublisher.publishEvent(new QuartzHalfHourEvent(this));
|
||||
}
|
||||
|
||||
public void publishQuartzFiveSecondEvent() {
|
||||
applicationEventPublisher.publishEvent(new QuartzFiveSecondEvent(this));
|
||||
}
|
||||
@@ -139,17 +158,17 @@ public class BytedeskEventPublisher {
|
||||
applicationEventPublisher.publishEvent(new StompUnsubscribeEvent(this, topic, clientId));
|
||||
}
|
||||
|
||||
public void publishThreadCreateEvent(Thread thread) {
|
||||
public void publishThreadCreateEvent(ThreadEntity thread) {
|
||||
applicationEventPublisher.publishEvent(new ThreadCreateEvent(this, thread));
|
||||
}
|
||||
|
||||
public void publishThreadUpdateEvent(Thread thread) {
|
||||
public void publishThreadUpdateEvent(ThreadEntity thread) {
|
||||
applicationEventPublisher.publishEvent(new ThreadUpdateEvent(this, thread));
|
||||
}
|
||||
|
||||
public void publishThreadUpdateStatusEvent(Thread thread, String status) {
|
||||
applicationEventPublisher.publishEvent(new ThreadUpdateStatusEvent(this, thread, status));
|
||||
}
|
||||
// public void publishThreadUpdateStatusEvent(Thread thread, String status) {
|
||||
// applicationEventPublisher.publishEvent(new ThreadUpdateStatusEvent(this, thread, status));
|
||||
// }
|
||||
|
||||
public void publishActionCreateEvent(Action action) {
|
||||
applicationEventPublisher.publishEvent(new ActionCreateEvent(this, action));
|
||||
|
||||
@@ -136,7 +136,7 @@ public class AvatarConsts {
|
||||
public static final String DEFAULT_GROUP_AVATAR_URL = "https://cdn.weiyuai.cn/avatars/group_default_avatar.png";
|
||||
|
||||
// 文件助手头像
|
||||
public static final String DEFAULT_FILE_ASISTANT_AVATAR_URL = "https://cdn.weiyuai.cn/avatars/file_asistant_avatar.png";
|
||||
public static final String DEFAULT_FILE_ASSISTANT_AVATAR_URL = "https://cdn.weiyuai.cn/avatars/file_assistant_avatar.png";
|
||||
|
||||
// 系统通知-公众号头像
|
||||
public static final String DEFAULT_SYSTEM_NOTIFICATION_AVATAR_URL = "https://cdn.weiyuai.cn/avatars/notification.png";
|
||||
|
||||
@@ -37,7 +37,7 @@ public class BdConstants {
|
||||
public static final String DEFAULT_AGENT_UID = "df_ag_uid";
|
||||
public static final String DEFAULT_WORKGROUP_UID = "df_wg_uid";
|
||||
public static final String DEFAULT_ROBOT_UID = "df_rt_uid";
|
||||
public static final String DEFAULT_FILE_ASISTANT_UID = "df_fa_uid";
|
||||
public static final String DEFAULT_FILE_ASSISTANT_UID = "df_fa_uid";
|
||||
public static final String DEFAULT_SYSTEM_UID = "df_sys_uid";
|
||||
public static final String DEFAULT_KB_UID = "df_kb_uid";
|
||||
public static final String DEFAULT_DY_UID = "df_dy_uid";
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-26 22:25:47
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-24 09:12:22
|
||||
* @LastEditTime: 2024-10-14 09:33:38
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -29,9 +29,9 @@ public class I18Consts {
|
||||
|
||||
public static final String I18N_PREFIX = "i18n.";
|
||||
// "文件助手"
|
||||
public static final String I18N_FILE_ASISTANT_NAME = I18N_PREFIX + "file.asistant";
|
||||
public static final String I18N_FILE_ASSISTANT_NAME = I18N_PREFIX + "file.assistant";
|
||||
// "手机、电脑文件互传"
|
||||
public static final String I18N_FILE_ASISTANT_DESCRIPTION = I18N_PREFIX + "file.asistant.description";
|
||||
public static final String I18N_FILE_ASSISTANT_DESCRIPTION = I18N_PREFIX + "file.assistant.description";
|
||||
// 系统通知
|
||||
public static final String I18N_SYSTEM_NOTIFICATION_NAME = I18N_PREFIX + "system.notification";
|
||||
public static final String I18N_SYSTEM_NOTIFICATION_DESCRIPTION = I18N_PREFIX + "system.notification.description";
|
||||
@@ -65,7 +65,7 @@ public class I18Consts {
|
||||
//
|
||||
public static final String I18N_ROBOT_NICKNAME = I18N_PREFIX + "robot.nickname";
|
||||
public static final String I18N_ROBOT_DESCRIPTION = I18N_PREFIX + "robot.description";
|
||||
public static final String I18N_ROBOT_AGENT_ASISTANT_NICKNAME = I18N_PREFIX + "robot.agent.asistant.nickname";
|
||||
public static final String I18N_ROBOT_AGENT_ASSISTANT_NICKNAME = I18N_PREFIX + "robot.agent.assistant.nickname";
|
||||
// public static final String I18N_ROBOT_LLM_PROMPT = I18N_PREFIX +
|
||||
// "llm.prompt";
|
||||
public static final String I18N_ROBOT_LLM_PROMPT = "角色:资深客服专家; 背景:有专业客服经验,对教育、电商、金融领域有深刻理解; 任务:根据上下文中提到的内容,对提出的问题给出有用、详细、礼貌的回答; 要求:1. 解决客户提出的问题,2. 安抚客户情绪,3. 提升客户满意度";
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-15 14:54:58
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-17 10:54:06
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.jms;
|
||||
|
||||
import org.springframework.boot.autoconfigure.jms.DefaultJmsListenerContainerFactoryConfigurer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.jms.annotation.EnableJms;
|
||||
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
|
||||
import org.springframework.jms.config.JmsListenerContainerFactory;
|
||||
import org.springframework.jms.support.converter.MappingJackson2MessageConverter;
|
||||
import org.springframework.jms.support.converter.MessageConverter;
|
||||
import org.springframework.jms.support.converter.MessageType;
|
||||
import org.springframework.jms.support.destination.DynamicDestinationResolver;
|
||||
|
||||
import jakarta.jms.ConnectionFactory;
|
||||
import jakarta.jms.Destination;
|
||||
import jakarta.jms.JMSException;
|
||||
import jakarta.jms.Session;
|
||||
|
||||
// http://localhost:8161/console/auth/login
|
||||
// https://spring.io/guides/gs/messaging-jms
|
||||
// https://docs.spring.io/spring-boot/reference/messaging/jms.html
|
||||
// https://activemq.apache.org/components/artemis/documentation/latest/index.html
|
||||
@EnableJms
|
||||
@Configuration
|
||||
public class JmsArtemisConfig {
|
||||
|
||||
@Bean
|
||||
public JmsListenerContainerFactory<?> jmsArtemisQueueFactory(ConnectionFactory connectionFactory,
|
||||
DefaultJmsListenerContainerFactoryConfigurer configurer) {
|
||||
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
|
||||
// This provides all auto-configured defaults to this factory, including the message converter
|
||||
configurer.configure(factory, connectionFactory);
|
||||
// You could still override some settings if necessary.
|
||||
factory.setPubSubDomain(false);
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public JmsListenerContainerFactory<?> jmsArtemisPubsubFactory(ConnectionFactory connectionFactory,
|
||||
DefaultJmsListenerContainerFactoryConfigurer configurer) {
|
||||
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
|
||||
// This provides all auto-configured defaults to this factory, including the message converter
|
||||
configurer.configure(factory, connectionFactory);
|
||||
// You could still override some settings if necessary.
|
||||
factory.setPubSubDomain(true);
|
||||
return factory;
|
||||
}
|
||||
|
||||
@Bean // Serialize message content to json using TextMessage
|
||||
public MessageConverter jacksonJmsMessageConverter() {
|
||||
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
|
||||
converter.setTargetType(MessageType.TEXT);
|
||||
converter.setTypeIdPropertyName("_type");
|
||||
return converter;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DynamicDestinationResolver destinationResolver() {
|
||||
return new DynamicDestinationResolver() {
|
||||
@Override
|
||||
public Destination resolveDestinationName(Session session, String destinationName, boolean pubSubDomain) throws JMSException {
|
||||
pubSubDomain = destinationName.startsWith(JmsArtemisConstants.TOPIC_PREFIX);
|
||||
return super.resolveDestinationName(session, destinationName, pubSubDomain);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-15 16:49:35
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-17 10:57:14
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.jms;
|
||||
|
||||
public class JmsArtemisConstants {
|
||||
|
||||
// queue 为队列消息,每个实例轮流收取
|
||||
public static final String QUEUE_PREFIX = "artemis.queue.";
|
||||
|
||||
public static final String QUEUE_STRING_NAME = QUEUE_PREFIX + "string";
|
||||
|
||||
public static final String QUEUE_MESSAGE_NAME = QUEUE_PREFIX + "message";
|
||||
|
||||
public static final String QUEUE_TEST_NAME = QUEUE_PREFIX + "test";
|
||||
|
||||
// topic 为pubsub广播消息,每个实例都收取
|
||||
public static final String TOPIC_PREFIX = "artemis.topic.";
|
||||
|
||||
public static final String TOPIC_STRING_NAME = TOPIC_PREFIX + "string";
|
||||
|
||||
public static final String TOPIC_MESSAGE_NAME = TOPIC_PREFIX + "message";
|
||||
|
||||
public static final String TOPIC_TEST_NAME = TOPIC_PREFIX + "test";
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-17 10:22:01
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-17 10:31:07
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.jms;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import com.bytedesk.core.config.BytedeskProperties;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
* for testing api
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/jms")
|
||||
public class JmsArtemisController {
|
||||
|
||||
@Autowired
|
||||
private JmsArtemisService jmsArtemisService;
|
||||
|
||||
@Autowired
|
||||
private BytedeskProperties bytedeskProperties;
|
||||
|
||||
// http://127.0.0.1:9003/jms/artemis/queue
|
||||
@GetMapping("/artemis/queue")
|
||||
public ResponseEntity<?> getJmsQueueArtemis() {
|
||||
if (!bytedeskProperties.getDebug()) {
|
||||
return ResponseEntity.status(503).body("debug is false");
|
||||
}
|
||||
|
||||
jmsArtemisService.testQueue();
|
||||
return ResponseEntity.ok("success");
|
||||
}
|
||||
|
||||
// http://127.0.0.1:9003/jms/artemis/topic
|
||||
@GetMapping("/artemis/topic")
|
||||
public ResponseEntity<?> getJmsTopicArtemis() {
|
||||
if (!bytedeskProperties.getDebug()) {
|
||||
return ResponseEntity.status(503).body("debug is false");
|
||||
}
|
||||
|
||||
jmsArtemisService.testTopic();
|
||||
return ResponseEntity.ok("success");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-15 14:57:05
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-17 10:39:14
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.jms;
|
||||
|
||||
import org.springframework.jms.annotation.JmsListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bytedesk.core.config.BytedeskEventPublisher;
|
||||
import com.bytedesk.core.message.MessageProtobuf;
|
||||
import com.bytedesk.core.utils.ApplicationContextHolder;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
// https://spring.io/guides/gs/messaging-jms
|
||||
@Slf4j
|
||||
@Component
|
||||
public class JmsArtemisListener {
|
||||
|
||||
@JmsListener(destination = JmsArtemisConstants.QUEUE_STRING_NAME, containerFactory = "jmsArtemisQueueFactory")
|
||||
public void receiveQueueMessage(String json) {
|
||||
log.info("jms receiveQueueMessage string {}", json);
|
||||
BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class);
|
||||
bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
}
|
||||
|
||||
@JmsListener(destination = JmsArtemisConstants.QUEUE_MESSAGE_NAME, containerFactory = "jmsArtemisQueueFactory")
|
||||
public void receiveQueueMessage(MessageProtobuf messageProtobuf) {
|
||||
String json = JSON.toJSONString(messageProtobuf);
|
||||
log.info("jms receiveQueueMessage messageProtobuf: {}", json);
|
||||
//
|
||||
BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class);
|
||||
bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
}
|
||||
|
||||
@JmsListener(destination = JmsArtemisConstants.QUEUE_TEST_NAME, containerFactory = "jmsArtemisQueueFactory")
|
||||
public void receiveQueueMessage(JmsArtemisMessage message) {
|
||||
log.info("jms receiveQueueMessage test {}", message);
|
||||
}
|
||||
|
||||
///////////////
|
||||
|
||||
@JmsListener(destination = JmsArtemisConstants.TOPIC_STRING_NAME, containerFactory = "jmsArtemisPubsubFactory")
|
||||
public void receiveTopicMessage(String json) {
|
||||
log.info("jms receiveTopicMessage string {}", json);
|
||||
BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class);
|
||||
bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
}
|
||||
|
||||
@JmsListener(destination = JmsArtemisConstants.TOPIC_MESSAGE_NAME, containerFactory = "jmsArtemisPubsubFactory")
|
||||
public void receiveTopicMessage(MessageProtobuf messageProtobuf) {
|
||||
String json = JSON.toJSONString(messageProtobuf);
|
||||
log.info("jms receiveTopicMessage messageProtobuf: {}", json);
|
||||
//
|
||||
BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class);
|
||||
bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
}
|
||||
|
||||
@JmsListener(destination = JmsArtemisConstants.TOPIC_TEST_NAME, containerFactory = "jmsArtemisPubsubFactory")
|
||||
public void receiveTopicMessage(JmsArtemisMessage message) {
|
||||
log.info("jms receiveTopicMessage test {}", message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-15 14:57:51
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-17 09:52:05
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.jms;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class JmsArtemisMessage {
|
||||
|
||||
private String to;
|
||||
|
||||
private String body;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-15 14:56:08
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-18 15:45:15
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.jms;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.bytedesk.core.message.MessageProtobuf;
|
||||
|
||||
@Service
|
||||
public class JmsArtemisService {
|
||||
|
||||
@Autowired
|
||||
private JmsTemplate jmsTemplate;
|
||||
|
||||
public void send(String destination, String message) {
|
||||
jmsTemplate.convertAndSend(destination, message);
|
||||
}
|
||||
|
||||
public void sendQueueMessage(String json) {
|
||||
jmsTemplate.convertAndSend(JmsArtemisConstants.QUEUE_STRING_NAME, json);
|
||||
}
|
||||
|
||||
public void sendTopicMessage(String json) {
|
||||
jmsTemplate.convertAndSend(JmsArtemisConstants.TOPIC_STRING_NAME, json);
|
||||
}
|
||||
|
||||
public void sendQueueMessage(MessageProtobuf message) {
|
||||
jmsTemplate.convertAndSend(JmsArtemisConstants.QUEUE_MESSAGE_NAME, message);
|
||||
}
|
||||
|
||||
public void sendTopicMessage(MessageProtobuf message) {
|
||||
jmsTemplate.convertAndSend(JmsArtemisConstants.TOPIC_MESSAGE_NAME, message);
|
||||
}
|
||||
|
||||
public void testQueue() {
|
||||
jmsTemplate.convertAndSend(JmsArtemisConstants.QUEUE_TEST_NAME, new JmsArtemisMessage("bytedesk@example.com", "HelloWorld"));
|
||||
}
|
||||
|
||||
public void testTopic() {
|
||||
jmsTemplate.convertAndSend(JmsArtemisConstants.TOPIC_TEST_NAME, new JmsArtemisMessage("bytedesk@example.com", "HelloWorld"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-15 16:27:05
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-15 16:27:08
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.message;
|
||||
|
||||
public interface IMessageSendService {
|
||||
|
||||
void sendMessage(String json);
|
||||
|
||||
void sendMessage(MessageProtobuf messageProtobuf);
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-01-29 16:21:24
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-07-30 16:57:33
|
||||
* @LastEditTime: 2024-10-15 17:42:44
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -33,7 +33,7 @@ import com.alibaba.fastjson2.JSONObject;
|
||||
import com.bytedesk.core.action.ActionAnnotation;
|
||||
import com.bytedesk.core.base.BaseController;
|
||||
import com.bytedesk.core.message_unread.MessageUnreadService;
|
||||
import com.bytedesk.core.socket.MqService;
|
||||
// import com.bytedesk.core.socket.MqService;
|
||||
import com.bytedesk.core.utils.DateUtils;
|
||||
import com.bytedesk.core.utils.JsonResult;
|
||||
|
||||
@@ -52,7 +52,9 @@ public class MessageController extends BaseController<MessageRequest> {
|
||||
|
||||
private final MessageService messageService;
|
||||
|
||||
private final MqService stompMqService;
|
||||
// private final MqService stompMqService;
|
||||
|
||||
private final IMessageSendService messageSendService;
|
||||
|
||||
private final MessageUnreadService messageUnreadService;
|
||||
|
||||
@@ -129,7 +131,8 @@ public class MessageController extends BaseController<MessageRequest> {
|
||||
|
||||
String json = (String) map.get("json");
|
||||
log.debug("json {}", json);
|
||||
stompMqService.sendJsonMessageToMq(json);
|
||||
// stompMqService.sendJsonMessageToMq(json);
|
||||
messageSendService.sendMessage(json);
|
||||
//
|
||||
return ResponseEntity.ok(JsonResult.success(json));
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ public class MessageCreateEvent extends ApplicationEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Message message;
|
||||
private final MessageEntity message;
|
||||
|
||||
public MessageCreateEvent(Object source, Message message) {
|
||||
public MessageCreateEvent(Object source, MessageEntity message) {
|
||||
super(source);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-01-29 16:21:24
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-08-30 16:33:09
|
||||
* @LastEditTime: 2024-10-19 11:02:50
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -38,7 +38,7 @@ import lombok.experimental.Accessors;
|
||||
@NoArgsConstructor
|
||||
@EntityListeners({ MessageEntityListener.class })
|
||||
@Table(name = "core_message")
|
||||
public class Message extends BaseEntity {
|
||||
public class MessageEntity extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -46,13 +46,10 @@ public class Message extends BaseEntity {
|
||||
// 如果使用int存储,enum中类型的顺序改变,会导致数据库中的数据类型改变,导致无法查询到数据
|
||||
// @Enumerated(EnumType.STRING) // 默认使用int类型表示,如果为了可读性,可以转换为使用字符串存储
|
||||
@Column(name = "message_type", nullable = false)
|
||||
// private MessageTypeEnum type = MessageTypeEnum.TEXT;
|
||||
private String type = MessageTypeEnum.TEXT.name();
|
||||
|
||||
// 仅对一对一/客服/技能组聊天有效,表示对方是否已读。群聊无效
|
||||
@Builder.Default
|
||||
// @Enumerated(EnumType.STRING)
|
||||
// private MessageStatusEnum status = MessageStatusEnum.SUCCESS;
|
||||
private String status = MessageStatusEnum.SUCCESS.name();
|
||||
|
||||
// 复杂类型可以使用json存储在此,通过type字段区分
|
||||
@@ -29,18 +29,18 @@ import lombok.extern.slf4j.Slf4j;
|
||||
public class MessageEntityListener {
|
||||
|
||||
@PostPersist
|
||||
public void onPostPersist(Message message) {
|
||||
public void onPostPersist(MessageEntity message) {
|
||||
// log.info("message MessageEntityListener: onPostPersist");
|
||||
Message clonedMessage = SerializationUtils.clone(message);
|
||||
MessageEntity clonedMessage = SerializationUtils.clone(message);
|
||||
//
|
||||
BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class);
|
||||
bytedeskEventPublisher.publishMessageCreateEvent(clonedMessage);
|
||||
}
|
||||
|
||||
@PostUpdate
|
||||
public void onPostUpdate(Message message) {
|
||||
public void onPostUpdate(MessageEntity message) {
|
||||
// log.info("message MessageEntityListener: onPostUpdate");
|
||||
Message clonedMessage = SerializationUtils.clone(message);
|
||||
MessageEntity clonedMessage = SerializationUtils.clone(message);
|
||||
//
|
||||
BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class);
|
||||
bytedeskEventPublisher.publishMessageUpdateEvent(clonedMessage);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-06-27 16:02:24
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-08-31 10:02:59
|
||||
* @LastEditTime: 2024-10-15 18:07:21
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -26,8 +26,6 @@ import com.bytedesk.core.quartz.event.QuartzFiveSecondEvent;
|
||||
import com.bytedesk.core.socket.protobuf.model.MessageProto;
|
||||
import com.bytedesk.core.thread.ThreadProtobuf;
|
||||
import com.bytedesk.core.utils.MessageConvertUtils;
|
||||
import com.google.protobuf.InvalidProtocolBufferException;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -61,29 +59,29 @@ public class MessageEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
@EventListener
|
||||
public void onMessageProtoEvent(MessageProtoEvent event) {
|
||||
log.info("MessageProtoEvent");
|
||||
//
|
||||
try {
|
||||
MessageProto.Message messageProto = MessageProto.Message.parseFrom(event.getMessageBytes());
|
||||
// JSON
|
||||
try {
|
||||
String messageJson = MessageConvertUtils.toJson(messageProto);
|
||||
//
|
||||
messageJson = processMessage(messageJson);
|
||||
messageSocketService.sendJsonMessage(messageJson);
|
||||
// process处理完毕之后,重新发送proto消息
|
||||
messageProto = MessageConvertUtils.toProtoBean(MessageProto.Message.newBuilder(), messageJson);
|
||||
messageSocketService.sendProtoMessage(messageProto);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//
|
||||
} catch (InvalidProtocolBufferException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
// @EventListener
|
||||
// public void onMessageProtoEvent(MessageProtoEvent event) {
|
||||
// log.info("MessageProtoEvent");
|
||||
// //
|
||||
// try {
|
||||
// MessageProto.Message messageProto = MessageProto.Message.parseFrom(event.getMessageBytes());
|
||||
// // JSON
|
||||
// try {
|
||||
// String messageJson = MessageConvertUtils.toJson(messageProto);
|
||||
// //
|
||||
// messageJson = processMessage(messageJson);
|
||||
// messageSocketService.sendJsonMessage(messageJson);
|
||||
// // process处理完毕之后,重新发送proto消息
|
||||
// messageProto = MessageConvertUtils.toProtoBean(MessageProto.Message.newBuilder(), messageJson);
|
||||
// messageSocketService.sendProtoMessage(messageProto);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// //
|
||||
// } catch (InvalidProtocolBufferException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
|
||||
private String processMessage(String messageJson) {
|
||||
// log.info("processMessage {}", messageJson);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-16 18:04:37
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-11 13:08:37
|
||||
* @LastEditTime: 2024-10-17 16:30:32
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -55,9 +55,9 @@ public class MessagePersistService {
|
||||
// 流式消息单独处理下
|
||||
if (type.equals(MessageTypeEnum.STREAM)) {
|
||||
// 更新消息内容
|
||||
Optional<Message> message = messageService.findByUid(uid);
|
||||
Optional<MessageEntity> message = messageService.findByUid(uid);
|
||||
if (message.isPresent()) {
|
||||
Message m = message.get();
|
||||
MessageEntity m = message.get();
|
||||
m.setContent(m.getContent() + messageProtobuf.getContent());
|
||||
messageService.save(m);
|
||||
}
|
||||
@@ -68,7 +68,7 @@ public class MessagePersistService {
|
||||
return;
|
||||
}
|
||||
//
|
||||
Message message = modelMapper.map(messageProtobuf, Message.class);
|
||||
MessageEntity message = modelMapper.map(messageProtobuf, MessageEntity.class);
|
||||
if (messageProtobuf.getStatus().equals(MessageStatusEnum.SENDING)) {
|
||||
message.setStatus(MessageStatusEnum.SUCCESS.name());
|
||||
}
|
||||
@@ -176,9 +176,9 @@ public class MessagePersistService {
|
||||
log.info("dealWithMessageReceipt: {}", type);
|
||||
// 回执消息内容存储被回执消息的uid
|
||||
// 当status已经为read时,不处理。防止deliverd在后面更新read消息
|
||||
Optional<Message> messageOpt = messageService.findByUid(message.getContent());
|
||||
Optional<MessageEntity> messageOpt = messageService.findByUid(message.getContent());
|
||||
if (messageOpt.isPresent() && messageOpt.get().getStatus() != MessageStatusEnum.READ.name()) {
|
||||
Message messageEntity = messageOpt.get();
|
||||
MessageEntity messageEntity = messageOpt.get();
|
||||
if (type.equals(MessageTypeEnum.READ)) {
|
||||
messageEntity.setStatus(MessageStatusEnum.READ.name());
|
||||
} else if (type.equals(MessageTypeEnum.DELIVERED)) {
|
||||
@@ -198,9 +198,9 @@ public class MessagePersistService {
|
||||
private void dealWithRateMessage(MessageTypeEnum type, MessageProtobuf message) {
|
||||
// log.info("dealWithMessageRateSubmit");
|
||||
// 如果是客服邀请评价,则content为邀请评价消息的uid,否则为空
|
||||
Optional<Message> messageOpt = messageService.findByUid(message.getContent());
|
||||
Optional<MessageEntity> messageOpt = messageService.findByUid(message.getContent());
|
||||
if (messageOpt.isPresent()) {
|
||||
Message messageEntity = messageOpt.get();
|
||||
MessageEntity messageEntity = messageOpt.get();
|
||||
if (type.equals(MessageTypeEnum.RATE_SUBMIT)) {
|
||||
messageEntity.setStatus(MessageStatusEnum.RATE_SUBMIT.name());
|
||||
messageEntity.setContent(message.getExtra());
|
||||
@@ -213,9 +213,9 @@ public class MessagePersistService {
|
||||
|
||||
private void dealWithLeaveMsg(MessageTypeEnum type, MessageProtobuf message) {
|
||||
// log.info("dealWithLeaveMsg");
|
||||
Optional<Message> messageOpt = messageService.findByUid(message.getContent());
|
||||
Optional<MessageEntity> messageOpt = messageService.findByUid(message.getContent());
|
||||
if (messageOpt.isPresent()) {
|
||||
Message messageEntity = messageOpt.get();
|
||||
MessageEntity messageEntity = messageOpt.get();
|
||||
if (type.equals(MessageTypeEnum.LEAVE_MSG_SUBMIT)) {
|
||||
messageEntity.setStatus(MessageStatusEnum.LEAVE_MSG_SUBMIT.name());
|
||||
messageEntity.setContent(message.getExtra());
|
||||
@@ -226,9 +226,9 @@ public class MessagePersistService {
|
||||
|
||||
private void dealWithFaqRateMessage(MessageTypeEnum type, MessageProtobuf message) {
|
||||
// log.info("dealWithFaqRateMessage");
|
||||
Optional<Message> messageOpt = messageService.findByUid(message.getContent());
|
||||
Optional<MessageEntity> messageOpt = messageService.findByUid(message.getContent());
|
||||
if (messageOpt.isPresent()) {
|
||||
Message messageEntity = messageOpt.get();
|
||||
MessageEntity messageEntity = messageOpt.get();
|
||||
if (type.equals(MessageTypeEnum.FAQ_UP)) {
|
||||
messageEntity.setStatus(MessageStatusEnum.RATE_UP.name());
|
||||
} else if (type.equals(MessageTypeEnum.FAQ_DOWN)) {
|
||||
@@ -241,9 +241,9 @@ public class MessagePersistService {
|
||||
private void dealWithRobotRateMessage(MessageTypeEnum type, MessageProtobuf message) {
|
||||
// log.info("dealWithRobotRateMessage");
|
||||
//
|
||||
Optional<Message> messageOpt = messageService.findByUid(message.getContent());
|
||||
Optional<MessageEntity> messageOpt = messageService.findByUid(message.getContent());
|
||||
if (messageOpt.isPresent()) {
|
||||
Message messageEntity = messageOpt.get();
|
||||
MessageEntity messageEntity = messageOpt.get();
|
||||
if (type.equals(MessageTypeEnum.ROBOT_UP)) {
|
||||
messageEntity.setStatus(MessageStatusEnum.RATE_UP.name());
|
||||
} else if (type.equals(MessageTypeEnum.ROBOT_DOWN)) {
|
||||
@@ -259,9 +259,9 @@ public class MessagePersistService {
|
||||
MessageTransferContent transferContentObject = JSONObject.parseObject(message.getContent(),
|
||||
MessageTransferContent.class);
|
||||
//
|
||||
Optional<Message> messageOpt = messageService.findByUid(transferContentObject.getUid());
|
||||
Optional<MessageEntity> messageOpt = messageService.findByUid(transferContentObject.getUid());
|
||||
if (messageOpt.isPresent()) {
|
||||
Message messageEntity = messageOpt.get();
|
||||
MessageEntity messageEntity = messageOpt.get();
|
||||
if (type.equals(MessageTypeEnum.TRANSFER_ACCEPT)) {
|
||||
messageEntity.setStatus(MessageStatusEnum.TRANSFER_ACCEPT.name());
|
||||
} else if (type.equals(MessageTypeEnum.TRANSFER_REJECT)) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-02-23 14:43:57
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-06-30 09:54:15
|
||||
* @LastEditTime: 2024-10-15 18:06:52
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -14,20 +14,20 @@
|
||||
*/
|
||||
package com.bytedesk.core.message;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
// import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
// import lombok.Data;
|
||||
// import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class MessageProtoEvent extends ApplicationEvent {
|
||||
// @Data
|
||||
// @EqualsAndHashCode(callSuper = false)
|
||||
// public class MessageProtoEvent extends ApplicationEvent {
|
||||
|
||||
private byte[] messageBytes;
|
||||
// private byte[] messageBytes;
|
||||
|
||||
public MessageProtoEvent(Object source, byte[] messageBytes) {
|
||||
super(source);
|
||||
this.messageBytes = messageBytes;
|
||||
}
|
||||
// public MessageProtoEvent(Object source, byte[] messageBytes) {
|
||||
// super(source);
|
||||
// this.messageBytes = messageBytes;
|
||||
// }
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
@@ -29,11 +29,11 @@ import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
*/
|
||||
@Repository
|
||||
@Tag(name = "message")
|
||||
public interface MessageRepository extends JpaRepository<Message, Long>, JpaSpecificationExecutor<Message> {
|
||||
public interface MessageRepository extends JpaRepository<MessageEntity, Long>, JpaSpecificationExecutor<MessageEntity> {
|
||||
|
||||
Optional<Message> findByUid(String uid);
|
||||
Optional<MessageEntity> findByUid(String uid);
|
||||
|
||||
Page<Message> findByThreadTopic(String topic, Pageable pageable);
|
||||
Page<MessageEntity> findByThreadTopic(String topic, Pageable pageable);
|
||||
// Page<Message> findByThreadsUidIn(String[] threadTids, Pageable pageable);
|
||||
|
||||
// Optional<Message> findFirstByThreadsUidInOrderByCreatedAtDesc(String[]
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-15 16:27:35
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-18 15:48:00
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.message;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bytedesk.core.config.BytedeskEventPublisher;
|
||||
import com.bytedesk.core.utils.ApplicationContextHolder;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@Slf4j
|
||||
@Service
|
||||
public class MessageSendServiceImpl implements IMessageSendService {
|
||||
|
||||
@Override
|
||||
public void sendMessage(String json) {
|
||||
log.debug("sendMessage: {}", json);
|
||||
publishMessageJsonEvent(json);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(MessageProtobuf messageProtobuf) {
|
||||
String json = JSON.toJSONString(messageProtobuf);
|
||||
log.debug("sendMessage messageProtobuf: {}", json);
|
||||
publishMessageJsonEvent(json);
|
||||
}
|
||||
|
||||
public void publishMessageJsonEvent(String json) {
|
||||
// log.debug("publishMessageJsonEvent: {}", json);
|
||||
BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class);
|
||||
bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-01-29 16:21:24
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-07 17:01:20
|
||||
* @LastEditTime: 2024-10-15 16:21:03
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -38,7 +38,7 @@ import lombok.AllArgsConstructor;
|
||||
// @Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class MessageService extends BaseService<Message, MessageRequest, MessageResponse> {
|
||||
public class MessageService extends BaseService<MessageEntity, MessageRequest, MessageResponse> {
|
||||
|
||||
private final MessageRepository messageRepository;
|
||||
|
||||
@@ -50,9 +50,9 @@ public class MessageService extends BaseService<Message, MessageRequest, Message
|
||||
Pageable pageable = PageRequest.of(request.getPageNumber(), request.getPageSize(), Sort.Direction.DESC,
|
||||
"createdAt");
|
||||
|
||||
Specification<Message> specs = MessageSpecification.search(request);
|
||||
Specification<MessageEntity> specs = MessageSpecification.search(request);
|
||||
|
||||
Page<Message> messagePage = messageRepository.findAll(specs, pageable);
|
||||
Page<MessageEntity> messagePage = messageRepository.findAll(specs, pageable);
|
||||
|
||||
return messagePage.map(ConvertUtils::convertToMessageResponse);
|
||||
}
|
||||
@@ -64,7 +64,7 @@ public class MessageService extends BaseService<Message, MessageRequest, Message
|
||||
Pageable pageable = PageRequest.of(request.getPageNumber(), request.getPageSize(), Sort.Direction.DESC,
|
||||
"createdAt");
|
||||
|
||||
Page<Message> messagePage = messageRepository.findByThreadTopic(request.getThreadTopic(), pageable);
|
||||
Page<MessageEntity> messagePage = messageRepository.findByThreadTopic(request.getThreadTopic(), pageable);
|
||||
|
||||
return messagePage.map(ConvertUtils::convertToMessageResponse);
|
||||
}
|
||||
@@ -82,7 +82,7 @@ public class MessageService extends BaseService<Message, MessageRequest, Message
|
||||
}
|
||||
|
||||
@Cacheable(value = "message", key = "#uid", unless = "#result == null")
|
||||
public Optional<Message> findByUid(String uid) {
|
||||
public Optional<MessageEntity> findByUid(String uid) {
|
||||
return messageRepository.findByUid(uid);
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ public class MessageService extends BaseService<Message, MessageRequest, Message
|
||||
@Caching(put = {
|
||||
@CachePut(value = "message", key = "#message.uid"),
|
||||
})
|
||||
public Message save(@NonNull Message message) {
|
||||
public MessageEntity save(@NonNull MessageEntity message) {
|
||||
try {
|
||||
return messageRepository.save(message);
|
||||
} catch (ObjectOptimisticLockingFailureException e) {
|
||||
@@ -102,7 +102,7 @@ public class MessageService extends BaseService<Message, MessageRequest, Message
|
||||
@Caching(evict = {
|
||||
@CacheEvict(value = "message", key = "#message.uid"),
|
||||
})
|
||||
public void delete(@NonNull Message message) {
|
||||
public void delete(@NonNull MessageEntity message) {
|
||||
deleteByUid(message.getUid());
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class MessageService extends BaseService<Message, MessageRequest, Message
|
||||
})
|
||||
public void deleteByUid(String uid) {
|
||||
// messageRepository.deleteByUid(uid);
|
||||
Optional<Message> messageOptional = findByUid(uid);
|
||||
Optional<MessageEntity> messageOptional = findByUid(uid);
|
||||
messageOptional.ifPresent(message -> {
|
||||
message.setDeleted(true);
|
||||
save(message);
|
||||
@@ -141,92 +141,17 @@ public class MessageService extends BaseService<Message, MessageRequest, Message
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageResponse convertToResponse(Message entity) {
|
||||
public MessageResponse convertToResponse(MessageEntity entity) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'convertToResponse'");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleOptimisticLockingFailureException(ObjectOptimisticLockingFailureException e, Message message) {
|
||||
public void handleOptimisticLockingFailureException(ObjectOptimisticLockingFailureException e, MessageEntity message) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'handleOptimisticLockingFailureException'");
|
||||
}
|
||||
|
||||
//
|
||||
// public void notifyUser(MessageProtobuf messageProtobuf) {
|
||||
// String json = JSON.toJSONString(messageProtobuf);
|
||||
// bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
// }
|
||||
|
||||
// public MessageProtobuf createNoticeMessage(String userUid, String orgUid, String content) {
|
||||
// //
|
||||
// UserProtobuf sender = UserUtils.getSystemChannelUser();
|
||||
// //
|
||||
// String topic = TopicUtils.getSystemTopic(userUid);
|
||||
// ThreadProtobuf thread = ThreadUtils.getThreadProtobuf(topic, ThreadTypeEnum.CHANNEL, sender);
|
||||
// //
|
||||
// MessageExtra extra = MessageUtils.getMessageExtra(orgUid);
|
||||
// //
|
||||
// MessageProtobuf message = MessageProtobuf.builder()
|
||||
// .uid(uidUtils.getCacheSerialUid())
|
||||
// .type(MessageTypeEnum.NOTICE)
|
||||
// .content(content)
|
||||
// .status(MessageStatusEnum.SUCCESS)
|
||||
// .createdAt(new Date())
|
||||
// .client(ClientEnum.SYSTEM)
|
||||
// .thread(thread)
|
||||
// .user(sender)
|
||||
// .extra(JSON.toJSONString(extra))
|
||||
// .build();
|
||||
// return message;
|
||||
// }
|
||||
|
||||
// 通知消息:登录
|
||||
// public MessageProtobuf createNoticeMessage(User user, String content) {
|
||||
// //
|
||||
// ThreadResponse noticeThread = threadService.createSystemChannelThread(user);
|
||||
// ThreadProtobuf thread = modelMapper.map(noticeThread, ThreadProtobuf.class);
|
||||
// UserProtobuf sender = thread.getUser();
|
||||
// //
|
||||
// MessageExtra extra = MessageExtra.builder().orgUid(user.getOrgUid()).build();
|
||||
// //
|
||||
// MessageProtobuf message = MessageProtobuf.builder()
|
||||
// .uid(uidUtils.getCacheSerialUid())
|
||||
// .type(MessageTypeEnum.NOTICE)
|
||||
// .content(content)
|
||||
// .status(MessageStatusEnum.SUCCESS)
|
||||
// .createdAt(new Date())
|
||||
// .client(ClientEnum.SYSTEM)
|
||||
// .thread(thread)
|
||||
// .user(sender)
|
||||
// .extra(JSON.toJSONString(extra))
|
||||
// .build();
|
||||
// return message;
|
||||
// }
|
||||
|
||||
// TODO: 事件消息:访客离线、访客上线
|
||||
// public MessageProtobuf createEventMessage(User user, String content) {
|
||||
// //
|
||||
// ThreadResponse noticeThread = threadService.createSystemChannelThread(user);
|
||||
// ThreadProtobuf thread = modelMapper.map(noticeThread, ThreadProtobuf.class);
|
||||
// UserProtobuf sender = thread.getUser();
|
||||
// //
|
||||
// MessageExtra extra = MessageExtra.builder().orgUid(user.getOrgUid()).build();
|
||||
// //
|
||||
// MessageProtobuf message = MessageProtobuf.builder()
|
||||
// .uid(uidUtils.getCacheSerialUid())
|
||||
// .type(MessageTypeEnum.EVENT)
|
||||
// .content(content)
|
||||
// .status(MessageStatusEnum.SUCCESS)
|
||||
// .createdAt(new Date())
|
||||
// .client(ClientEnum.SYSTEM)
|
||||
// .thread(thread)
|
||||
// .user(sender)
|
||||
// .extra(JSON.toJSONString(extra))
|
||||
// .build();
|
||||
|
||||
// return message;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-02-26 10:36:50
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-25 11:29:13
|
||||
* @LastEditTime: 2024-10-15 18:25:35
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -109,9 +109,9 @@ public class MessageSocketService {
|
||||
}
|
||||
|
||||
private void doSendToSubscribers(String topic, @NonNull MessageProto.Message messageProto) {
|
||||
log.debug("doSendToSubscribers: user={}, content={}, topic={}, type={}, clientId={}",
|
||||
messageProto.getUser().getNickname(), messageProto.getContent(), topic, messageProto.getType(),
|
||||
messageProto.getClient());
|
||||
// log.debug("doSendToSubscribers: user={}, content={}, topic={}, type={}, clientId={}",
|
||||
// messageProto.getUser().getNickname(), messageProto.getContent(), topic, messageProto.getType(),
|
||||
// messageProto.getClient());
|
||||
Set<Topic> topicSet = topicService.findByTopic(topic);
|
||||
log.info("topicList size {}", topicSet.size());
|
||||
topicSet.forEach(topicElement -> {
|
||||
@@ -123,16 +123,15 @@ public class MessageSocketService {
|
||||
}
|
||||
|
||||
private void doSendMessage(String topic, @NonNull MessageProto.Message messageProto, String clientId) {
|
||||
log.debug("doSendMessage: user={}, content={}, topic={}, type={}, clientId={}",
|
||||
messageProto.getUser().getNickname(), messageProto.getContent(), topic, messageProto.getType(), clientId);
|
||||
//
|
||||
// log.debug("doSendMessage: user={}, content={}, topic={}, type={}, clientId={}",
|
||||
// messageProto.getUser().getNickname(), messageProto.getContent(), topic, messageProto.getType(), clientId);
|
||||
MqttQoS mqttQoS = MqttQoS.AT_LEAST_ONCE;
|
||||
boolean dup = false;
|
||||
boolean retain = false;
|
||||
byte[] messageBytes = messageProto.toByteArray();
|
||||
// 当前活跃长连接信息
|
||||
if (mqttSessionService.containsKey(clientId)) {
|
||||
// log.debug("hasSession: topic {} clientId {}", topic, clientId);
|
||||
log.debug("doSendMessage hasSession: topic {} clientId {}", topic, clientId);
|
||||
// 订阅者收到MQTT消息的QoS级别, 最终取决于发布消息的QoS和主题订阅的QoS
|
||||
int messageId = mqttMessageIdService.getNextMessageId();
|
||||
//
|
||||
@@ -143,7 +142,6 @@ public class MessageSocketService {
|
||||
//
|
||||
final MqttSession mqttSession = mqttSessionService.get(clientId);
|
||||
mqttSession.getChannel().writeAndFlush(publishMessage);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import jakarta.persistence.criteria.Predicate;
|
||||
|
||||
public class MessageSpecification extends BaseSpecification {
|
||||
|
||||
public static Specification<Message> search(MessageRequest request) {
|
||||
public static Specification<MessageEntity> search(MessageRequest request) {
|
||||
return (root, query, criteriaBuilder) -> {
|
||||
List<Predicate> predicates = new ArrayList<>();
|
||||
predicates.addAll(getBasicPredicates(root, criteriaBuilder, request.getOrgUid()));
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-05-25 10:33:49
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-07-24 14:09:01
|
||||
* @LastEditTime: 2024-10-16 19:25:36
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
*/
|
||||
package com.bytedesk.core.message;
|
||||
|
||||
import com.bytedesk.core.thread.Thread;
|
||||
import com.bytedesk.core.thread.ThreadEntity;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
@@ -29,7 +29,7 @@ public class MessageTransferContent {
|
||||
private String note;
|
||||
|
||||
// 被转接会话
|
||||
private Thread thread;
|
||||
private ThreadEntity thread;
|
||||
|
||||
// 转接消息uid,用于transfer_accept/transfer_reject
|
||||
private String uid;
|
||||
|
||||
@@ -25,9 +25,9 @@ public class MessageUpdateEvent extends ApplicationEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final Message message;
|
||||
private final MessageEntity message;
|
||||
|
||||
public MessageUpdateEvent(Object source, Message message) {
|
||||
public MessageUpdateEvent(Object source, MessageEntity message) {
|
||||
super(source);
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-08-31 16:23:54
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-07 18:13:54
|
||||
* @LastEditTime: 2024-10-15 17:46:16
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -21,7 +21,7 @@ import com.bytedesk.core.config.BytedeskEventPublisher;
|
||||
import com.bytedesk.core.enums.ClientEnum;
|
||||
import com.bytedesk.core.rbac.user.UserProtobuf;
|
||||
import com.bytedesk.core.rbac.user.UserUtils;
|
||||
import com.bytedesk.core.thread.Thread;
|
||||
import com.bytedesk.core.thread.ThreadEntity;
|
||||
import com.bytedesk.core.thread.ThreadProtobuf;
|
||||
import com.bytedesk.core.thread.ThreadTypeEnum;
|
||||
import com.bytedesk.core.thread.ThreadUtils;
|
||||
@@ -58,7 +58,7 @@ public class MessageUtils {
|
||||
return message;
|
||||
}
|
||||
|
||||
public static MessageProtobuf createThreadMessage(String messageUid, Thread thread, MessageTypeEnum type, String content) {
|
||||
public static MessageProtobuf createThreadMessage(String messageUid, ThreadEntity thread, MessageTypeEnum type, String content) {
|
||||
//
|
||||
UserProtobuf sender = UserUtils.getSystemChannelUser();
|
||||
ThreadProtobuf threadProtobuf = thread.toProtobuf();
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-06-28 17:15:48
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-07-05 11:55:54
|
||||
* @LastEditTime: 2024-10-17 17:06:45
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -80,8 +80,6 @@ public class MessageUnread implements Serializable {
|
||||
|
||||
// 仅对一对一/客服/技能组聊天有效,表示对方是否已读。群聊无效
|
||||
@Builder.Default
|
||||
// @Enumerated(EnumType.STRING)
|
||||
// private MessageStatusEnum status = MessageStatusEnum.SUCCESS;
|
||||
private String status = MessageStatusEnum.SUCCESS.name();
|
||||
|
||||
// 复杂类型可以使用json存储在此,通过type字段区分
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-07-01 12:37:41
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-12 22:23:34
|
||||
* @LastEditTime: 2024-10-17 16:31:29
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -18,7 +18,7 @@ import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
import com.bytedesk.core.message.MessageCreateEvent;
|
||||
import com.bytedesk.core.message.MessageStatusEnum;
|
||||
import com.bytedesk.core.message.MessageTypeEnum;
|
||||
@@ -43,7 +43,7 @@ public class MessageUnreadEventListener {
|
||||
|
||||
@EventListener
|
||||
public void onMessageCreateEvent(MessageCreateEvent event) {
|
||||
Message message = event.getMessage();
|
||||
MessageEntity message = event.getMessage();
|
||||
if (message.getType().equals(MessageTypeEnum.STREAM.name())) {
|
||||
return;
|
||||
}
|
||||
@@ -126,16 +126,16 @@ public class MessageUnreadEventListener {
|
||||
|
||||
@EventListener
|
||||
public void onMessageUpdateEvent(MessageUpdateEvent event) {
|
||||
Message message = event.getMessage();
|
||||
MessageEntity message = event.getMessage();
|
||||
// log.info("message unread update event: {}", message.getContent());
|
||||
if (message.getType().equals(MessageTypeEnum.STREAM.name())) {
|
||||
return;
|
||||
}
|
||||
//
|
||||
String threadTopic = message.getThreadTopic();
|
||||
MessageStatusEnum messageStatus = MessageStatusEnum.fromValue(message.getStatus());
|
||||
MessageStatusEnum messageState = MessageStatusEnum.fromValue(message.getStatus());
|
||||
//
|
||||
if (messageStatus.ordinal() < MessageStatusEnum.DELIVERED.ordinal()) {
|
||||
if (messageState.ordinal() < MessageStatusEnum.DELIVERED.ordinal()) {
|
||||
return;
|
||||
}
|
||||
// 删除已读消息
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.modelmapper.ModelMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
import com.bytedesk.core.message.MessageResponse;
|
||||
import com.bytedesk.core.utils.ConvertUtils;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class MessageUnreadService {
|
||||
// @Caching(put = {
|
||||
// @CachePut(value = "message_unread", key = "#userUid"),
|
||||
// })
|
||||
public void create(Message message, String userUid) {
|
||||
public void create(MessageEntity message, String userUid) {
|
||||
MessageUnread messageUnread = modelMapper.map(message, MessageUnread.class);
|
||||
messageUnread.setUserUid(userUid);
|
||||
messageUnreadRepository.save(messageUnread);
|
||||
|
||||
@@ -14,13 +14,13 @@
|
||||
*/
|
||||
package com.bytedesk.core.push;
|
||||
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
public abstract class PushNotifier {
|
||||
|
||||
abstract void notify(Message e);
|
||||
abstract void notify(MessageEntity e);
|
||||
|
||||
abstract void send(String to, String content, HttpServletRequest request);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.bytedesk.core.push;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PushServiceImplAndroid extends PushNotifier {
|
||||
|
||||
@Async
|
||||
@Override
|
||||
void notify(Message e) {
|
||||
void notify(MessageEntity e) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'notify'");
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ import com.aliyuncs.exceptions.ClientException;
|
||||
import com.aliyuncs.exceptions.ServerException;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.aliyuncs.profile.IClientProfile;
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -42,7 +42,7 @@ public class PushServiceImplEmail extends PushNotifier {
|
||||
|
||||
@Async
|
||||
@Override
|
||||
void notify(Message e) {
|
||||
void notify(MessageEntity e) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'notify'");
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.bytedesk.core.push;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class PushServiceImplIos extends PushNotifier {
|
||||
|
||||
@Async
|
||||
@Override
|
||||
void notify(Message e) {
|
||||
void notify(MessageEntity e) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'notify'");
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ import com.aliyuncs.exceptions.ServerException;
|
||||
import com.aliyuncs.http.MethodType;
|
||||
import com.aliyuncs.profile.DefaultProfile;
|
||||
import com.bytedesk.core.config.BytedeskProperties;
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
import com.bytedesk.core.utils.Utils;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
@@ -57,7 +57,7 @@ public class PushServiceImplSms extends PushNotifier {
|
||||
|
||||
@Async
|
||||
@Override
|
||||
void notify(Message e) {
|
||||
void notify(MessageEntity e) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'notify'");
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-02-28 13:05:47
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-09 16:28:17
|
||||
* @LastEditTime: 2024-10-18 13:43:21
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -22,10 +22,16 @@ import org.quartz.TriggerBuilder;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import com.bytedesk.core.quartz.job.Daily0Job;
|
||||
import com.bytedesk.core.quartz.job.Daily8Job;
|
||||
import com.bytedesk.core.quartz.job.FiveMinJob;
|
||||
import com.bytedesk.core.quartz.job.FiveSecondJob;
|
||||
import com.bytedesk.core.quartz.job.HalfHourJob;
|
||||
import com.bytedesk.core.quartz.job.HourlyJob;
|
||||
import com.bytedesk.core.quartz.job.OneMinJob;
|
||||
|
||||
import static org.quartz.CronScheduleBuilder.*;
|
||||
|
||||
/**
|
||||
* Cron使用方法:
|
||||
* https://stackoverflow.com/questions/26147044/spring-cron-expression-for-every-day-101am
|
||||
@@ -62,7 +68,7 @@ public class QuartzConfig {
|
||||
public JobDetail fiveSecondJobJobDetail() {
|
||||
return JobBuilder.newJob(FiveSecondJob.class)
|
||||
.withIdentity("FiveSecondJob", "bytedesk")
|
||||
.withDescription("每5秒钟运行一次")
|
||||
.withDescription("run one 5 seconds")
|
||||
.storeDurably()
|
||||
.build();
|
||||
}
|
||||
@@ -75,8 +81,8 @@ public class QuartzConfig {
|
||||
.repeatForever();
|
||||
return TriggerBuilder.newTrigger()
|
||||
.forJob(fiveSecondJobJobDetail())
|
||||
.withIdentity("fiveSecondJobrigger", "bytedesk")
|
||||
.withDescription("每隔5秒钟检查一次")
|
||||
.withIdentity("fiveSecondJobTrigger", "bytedesk")
|
||||
.withDescription("run once 5 seconds")
|
||||
.withSchedule(scheduleBuilder)
|
||||
.build();
|
||||
}
|
||||
@@ -88,7 +94,7 @@ public class QuartzConfig {
|
||||
public JobDetail fiveMinJobJobDetail() {
|
||||
return JobBuilder.newJob(FiveMinJob.class)
|
||||
.withIdentity("FiveMinJob", "bytedesk")
|
||||
.withDescription("每5分钟运行一次")
|
||||
.withDescription("run once 5 minutes")
|
||||
.storeDurably()
|
||||
.build();
|
||||
}
|
||||
@@ -102,7 +108,7 @@ public class QuartzConfig {
|
||||
return TriggerBuilder.newTrigger()
|
||||
.forJob(fiveMinJobJobDetail())
|
||||
.withIdentity("fiveMinJobTrigger", "bytedesk")
|
||||
.withDescription("每隔5分钟检查一次")
|
||||
.withDescription("run once 5 minutes")
|
||||
.withSchedule(scheduleBuilder)
|
||||
.build();
|
||||
}
|
||||
@@ -114,7 +120,7 @@ public class QuartzConfig {
|
||||
public JobDetail oneMinJobJobDetail() {
|
||||
return JobBuilder.newJob(OneMinJob.class)
|
||||
.withIdentity("OneMinJob", "bytedesk")
|
||||
.withDescription("每1分钟运行一次")
|
||||
.withDescription("run once 1 minutes")
|
||||
.storeDurably()
|
||||
.build();
|
||||
}
|
||||
@@ -128,11 +134,91 @@ public class QuartzConfig {
|
||||
return TriggerBuilder.newTrigger()
|
||||
.forJob(oneMinJobJobDetail())
|
||||
.withIdentity("oneMinJobTrigger", "bytedesk")
|
||||
.withDescription("每隔1分钟检查一次")
|
||||
.withDescription("run once 1")
|
||||
.withSchedule(scheduleBuilder)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 每小时整点运行一次
|
||||
*/
|
||||
@Bean
|
||||
public JobDetail hourlyJobDetail() {
|
||||
return JobBuilder.newJob(
|
||||
HourlyJob.class)
|
||||
.withIdentity("HourlyJob", "bytedesk")
|
||||
.withDescription("run once every hour")
|
||||
.storeDurably()
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Trigger hourlyTrigger() {
|
||||
return TriggerBuilder.newTrigger().forJob(hourlyJobDetail())
|
||||
.withIdentity("hourlyTrigger", "bytedesk")
|
||||
.withDescription("run once every hour")
|
||||
.withSchedule(cronSchedule("0 0 * * * ?"))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* 每30分钟运行一次,在整点和半点运行
|
||||
*/
|
||||
@Bean
|
||||
public JobDetail halfHourJobDetail() {
|
||||
return JobBuilder.newJob(HalfHourJob.class)
|
||||
.withIdentity("HalfHourJob", "bytedesk")
|
||||
.withDescription("run once every half hour ").storeDurably().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Trigger halfHourTrigger() {
|
||||
return TriggerBuilder.newTrigger().forJob(
|
||||
halfHourJobDetail())
|
||||
.withIdentity("halfHourTrigger", "bytedesk")
|
||||
.withDescription("run once every half hour")
|
||||
.withSchedule(cronSchedule("0 0/30 * * * ?"))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* run once at 0 o'clock
|
||||
*/
|
||||
@Bean
|
||||
public JobDetail daily0JobDetail() {
|
||||
return JobBuilder.newJob(Daily0Job.class).withIdentity("Daily0Job", "bytedesk")
|
||||
.withDescription("run once at 0 o'click").storeDurably().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Trigger daily0Trigger() {
|
||||
return TriggerBuilder.newTrigger().forJob(
|
||||
daily0JobDetail()).withIdentity("daily0Trigger", "bytedesk")
|
||||
.withDescription("run once at 0 o'clock")
|
||||
.withSchedule(cronSchedule("0 0 0 * * ?"))
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
* run once at 8 o'clock
|
||||
*/
|
||||
@Bean
|
||||
public JobDetail daily8JobDetail() {
|
||||
return JobBuilder.newJob(Daily8Job.class)
|
||||
.withIdentity("Daily8Job", "bytedesk")
|
||||
.withDescription("run once at 8 o'clock")
|
||||
.storeDurably().build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Trigger daily8Trigger() {
|
||||
return TriggerBuilder.newTrigger().forJob(
|
||||
daily8JobDetail())
|
||||
.withIdentity("daily8Trigger", "bytedesk")
|
||||
.withDescription("run once at 8 o'clock")
|
||||
.withSchedule(cronSchedule("0 0 8 * * ?"))
|
||||
.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-05-14 09:35:27
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-05-14 11:46:34
|
||||
* @LastEditTime: 2024-10-18 12:52:31
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -38,7 +38,7 @@ public class QuartzConsts {
|
||||
/** 不触发立即执行 */
|
||||
public static final String MISFIRE_DO_NOTHING = "3";
|
||||
|
||||
public static final String JOB_METHORD_NAME = "jobMethodName";
|
||||
public static final String JOB_METHOD_NAME = "jobMethodName";
|
||||
|
||||
public enum Status
|
||||
{
|
||||
|
||||
@@ -43,7 +43,7 @@ public class QuartzJob extends QuartzJobBean implements Serializable {
|
||||
/**
|
||||
* 获取任务中保存的方法名字,动态调用方法
|
||||
*/
|
||||
String methodName = dataMap.getString(QuartzConsts.JOB_METHORD_NAME);
|
||||
String methodName = dataMap.getString(QuartzConsts.JOB_METHOD_NAME);
|
||||
try {
|
||||
QuartzJob job = new QuartzJob();
|
||||
Method method = job.getClass().getMethod(methodName);
|
||||
|
||||
@@ -170,7 +170,7 @@ public class QuartzService extends BaseService<QuartzEntity, QuartzRequest, Quar
|
||||
// cls.getDeclaredConstructor().newInstance();
|
||||
//
|
||||
JobDataMap jobDataMap = new JobDataMap();
|
||||
jobDataMap.put(QuartzConsts.JOB_METHORD_NAME, quartzRequest.getJobMethodName());
|
||||
jobDataMap.put(QuartzConsts.JOB_METHOD_NAME, quartzRequest.getJobMethodName());
|
||||
JobDetail jobDetail = JobBuilder
|
||||
// .newJob(QuartzJob.class)
|
||||
.newJob(cls)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-23 08:51:27
|
||||
* @Date: 2024-02-28 14:37:33
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-06-28 15:01:56
|
||||
* @LastEditTime: 2024-10-18 13:35:47
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -12,7 +12,7 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.thread;
|
||||
package com.bytedesk.core.quartz.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
@@ -21,18 +21,11 @@ import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ThreadStatusEvent extends ApplicationEvent {
|
||||
public class QuartzDay0Event extends ApplicationEvent {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public final String topic;
|
||||
|
||||
public final ThreadStatusEnum status;
|
||||
|
||||
public ThreadStatusEvent(Object source, String topic, ThreadStatusEnum status) {
|
||||
public QuartzDay0Event(Object source) {
|
||||
super(source);
|
||||
this.topic = topic;
|
||||
this.status = status;
|
||||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-02-28 14:37:33
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-18 13:36:13
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.quartz.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class QuartzDay8Event extends ApplicationEvent {
|
||||
|
||||
public QuartzDay8Event(Object source) {
|
||||
super(source);
|
||||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-02-28 14:37:33
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-18 13:35:19
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.quartz.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class QuartzHalfHourEvent extends ApplicationEvent {
|
||||
|
||||
public QuartzHalfHourEvent(Object source) {
|
||||
super(source);
|
||||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-02-28 14:37:33
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-18 13:34:45
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.quartz.event;
|
||||
|
||||
import org.springframework.context.ApplicationEvent;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class QuartzHourlyEvent extends ApplicationEvent {
|
||||
|
||||
public QuartzHourlyEvent(Object source) {
|
||||
super(source);
|
||||
//TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2022-03-10 14:41:11
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-18 13:44:43
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 技术/商务联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.quartz.job;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import com.bytedesk.core.config.BytedeskEventPublisher;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 1天-运行一次,凌晨0点
|
||||
*
|
||||
* @author kefux.com on 2019/4/20
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@DisallowConcurrentExecution
|
||||
public class Daily0Job extends QuartzJobBean implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final BytedeskEventPublisher bytedeskEventPublisher;
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext jobExecutionContext) {
|
||||
log.info("Daily0Job");
|
||||
|
||||
bytedeskEventPublisher.publishQuartzDay0Event();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-18 13:07:39
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-18 13:33:30
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.quartz.job;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import com.bytedesk.core.config.BytedeskEventPublisher;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 1天-运行一次,每天8点
|
||||
*
|
||||
* @author kefux.com on 2019/4/20
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@DisallowConcurrentExecution
|
||||
public class Daily8Job extends QuartzJobBean implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final BytedeskEventPublisher bytedeskEventPublisher;
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext jobExecutionContext) {
|
||||
log.info("Daily8Job");
|
||||
|
||||
bytedeskEventPublisher.publishQuartzDay8Event();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.bytedesk.core.quartz.job;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import com.bytedesk.core.config.BytedeskEventPublisher;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 半小时-运行一次
|
||||
*
|
||||
* @author kefux.com on 2019/4/20
|
||||
*/
|
||||
@Slf4j
|
||||
@AllArgsConstructor
|
||||
@DisallowConcurrentExecution
|
||||
public class HalfHourJob extends QuartzJobBean implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final BytedeskEventPublisher bytedeskEventPublisher;
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext jobExecutionContext) {
|
||||
log.info("HalfHourJob");
|
||||
//
|
||||
bytedeskEventPublisher.publishQuartzHalfHourEvent();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-18 13:26:53
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-18 13:45:48
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2022-03-10 14:41:11
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-18 13:29:07
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.quartz.job;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.quartz.DisallowConcurrentExecution;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.springframework.scheduling.quartz.QuartzJobBean;
|
||||
|
||||
import com.bytedesk.core.config.BytedeskEventPublisher;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 1小时-运行一次,0分
|
||||
*
|
||||
* @author kefux.com on 2019/4/20
|
||||
*/
|
||||
@Slf4j
|
||||
@DisallowConcurrentExecution
|
||||
@AllArgsConstructor
|
||||
public class HourlyJob extends QuartzJobBean implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private final BytedeskEventPublisher bytedeskEventPublisher;
|
||||
|
||||
@Override
|
||||
protected void executeInternal(JobExecutionContext jobExecutionContext) {
|
||||
log.info("HourlyJob");
|
||||
//
|
||||
bytedeskEventPublisher.publishQuartzHourlyEvent();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-02-28 13:07:58
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-09 20:28:34
|
||||
* @LastEditTime: 2024-10-18 13:33:04
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -30,8 +30,6 @@ import lombok.AllArgsConstructor;
|
||||
|
||||
/**
|
||||
* 1 min job
|
||||
* 1分钟定时任务
|
||||
*
|
||||
*/
|
||||
// @Slf4j
|
||||
@AllArgsConstructor
|
||||
@@ -45,6 +43,7 @@ public class OneMinJob extends QuartzJobBean implements Serializable {
|
||||
@Override
|
||||
protected void executeInternal(@NonNull JobExecutionContext context) throws JobExecutionException {
|
||||
// log.info("OneMinJob");
|
||||
//
|
||||
bytedeskEventPublisher.publishQuartzOneMinEvent();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-08-19 11:36:50
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-26 14:33:59
|
||||
* @LastEditTime: 2024-10-15 17:45:41
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -23,6 +23,7 @@ import com.bytedesk.core.action.Action;
|
||||
import com.bytedesk.core.action.ActionCreateEvent;
|
||||
import com.bytedesk.core.constant.BdConstants;
|
||||
import com.bytedesk.core.constant.I18Consts;
|
||||
import com.bytedesk.core.message.IMessageSendService;
|
||||
import com.bytedesk.core.message.MessageProtobuf;
|
||||
import com.bytedesk.core.message.MessageUtils;
|
||||
import com.bytedesk.core.rbac.user.User;
|
||||
@@ -38,6 +39,8 @@ public class AuthEventListener {
|
||||
|
||||
// private final MessageService messageService;
|
||||
|
||||
private final IMessageSendService messageSendService;
|
||||
|
||||
private final UidUtils uidUtils;
|
||||
|
||||
@EventListener
|
||||
@@ -60,9 +63,10 @@ public class AuthEventListener {
|
||||
contentObject.put(I18Consts.I18N_NOTICE_IP, action.getIp());
|
||||
contentObject.put(I18Consts.I18N_NOTICE_IPLOCATION, action.getIpLocation());
|
||||
//
|
||||
MessageProtobuf messsage = MessageUtils.createNoticeMessage(uidUtils.getCacheSerialUid(), user.getUid(), user.getOrgUid(),
|
||||
MessageProtobuf message = MessageUtils.createNoticeMessage(uidUtils.getCacheSerialUid(), user.getUid(), user.getOrgUid(),
|
||||
JSON.toJSONString(contentObject));
|
||||
MessageUtils.notifyUser(messsage);
|
||||
// MessageUtils.notifyUser(message);
|
||||
messageSendService.sendMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ public enum UserTypeEnum {
|
||||
VISITOR,
|
||||
ROBOT,
|
||||
MEMBER,
|
||||
ASISTANT,
|
||||
ASSISTANT,
|
||||
CHANNEL,
|
||||
USER
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-08-31 16:20:44
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-08-31 16:20:47
|
||||
* @LastEditTime: 2024-10-16 15:20:00
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -20,12 +20,12 @@ import com.bytedesk.core.constant.I18Consts;
|
||||
|
||||
public class UserUtils {
|
||||
|
||||
public static UserProtobuf getFileAsistantUser() {
|
||||
public static UserProtobuf getFileAssistantUser() {
|
||||
UserProtobuf user = UserProtobuf.builder()
|
||||
.nickname(I18Consts.I18N_FILE_ASISTANT_NAME)
|
||||
.avatar(AvatarConsts.DEFAULT_FILE_ASISTANT_AVATAR_URL)
|
||||
.nickname(I18Consts.I18N_FILE_ASSISTANT_NAME)
|
||||
.avatar(AvatarConsts.DEFAULT_FILE_ASSISTANT_AVATAR_URL)
|
||||
.build();
|
||||
user.setUid(BdConstants.DEFAULT_FILE_ASISTANT_UID);
|
||||
user.setUid(BdConstants.DEFAULT_FILE_ASSISTANT_UID);
|
||||
return user;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-07-23 08:12:54
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-07-28 17:01:21
|
||||
* @LastEditTime: 2024-10-15 10:54:54
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-04-15 17:13:01
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-07 17:11:46
|
||||
* @LastEditTime: 2024-10-15 17:54:29
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -24,10 +24,10 @@ import org.springframework.stereotype.Service;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.bytedesk.core.config.BytedeskEventPublisher;
|
||||
import com.bytedesk.core.event.GenericApplicationEvent;
|
||||
import com.bytedesk.core.message.IMessageSendService;
|
||||
import com.bytedesk.core.message.MessageCache;
|
||||
import com.bytedesk.core.message.MessageProtobuf;
|
||||
import com.bytedesk.core.message.MessageTypeEnum;
|
||||
import com.bytedesk.core.message.MessageUtils;
|
||||
import com.bytedesk.core.redis.pubsub.message.RedisPubsubMessageFile;
|
||||
import com.bytedesk.core.redis.pubsub.message.RedisPubsubMessageQa;
|
||||
import lombok.AllArgsConstructor;
|
||||
@@ -44,6 +44,8 @@ public class RedisPubsubStringListener implements MessageListener {
|
||||
|
||||
// private final BytedeskEventPublisher bytedeskEventPublisher;
|
||||
|
||||
private final IMessageSendService messageSendService;
|
||||
|
||||
private final Queue<RedisPubsubMessage> messageQueue = new LinkedList<>();
|
||||
|
||||
@Override
|
||||
@@ -128,7 +130,7 @@ public class RedisPubsubStringListener implements MessageListener {
|
||||
//
|
||||
messageProtobuf.setType(MessageTypeEnum.STREAM);
|
||||
messageProtobuf.setContent(messageQa.getAnswer());
|
||||
//
|
||||
MessageUtils.notifyUser(messageProtobuf);
|
||||
// MessageUtils.notifyUser(messageProtobuf);
|
||||
messageSendService.sendMessage(messageProtobuf);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-10-15 10:57:00
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-10-15 11:01:08
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
* 仅支持企业内部员工自用,严禁私自用于销售、二次销售或者部署SaaS方式销售
|
||||
* Business Source License 1.1: https://github.com/Bytedesk/bytedesk/blob/main/LICENSE
|
||||
* contact: 270580156@qq.com
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.redis.queue;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public class RedisQueueService {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate redisTemplate;
|
||||
|
||||
// 入队操作
|
||||
public void push(String queueKey, String value) {
|
||||
redisTemplate.opsForList().rightPush(queueKey, value);
|
||||
}
|
||||
|
||||
// 出队操作
|
||||
public String pop(String queueKey) {
|
||||
return (String) redisTemplate.opsForList().leftPop(queueKey);
|
||||
}
|
||||
|
||||
// 显示队列排队数量
|
||||
public Long getQueueSize(String queueKey) {
|
||||
return redisTemplate.opsForList().size(queueKey);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-01-29 16:21:46
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-08-04 10:43:29
|
||||
* @LastEditTime: 2024-10-15 18:13:11
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -12,34 +12,35 @@
|
||||
* 联系:270580156@qq.com
|
||||
* Copyright (c) 2024 by bytedesk.com, All Rights Reserved.
|
||||
*/
|
||||
package com.bytedesk.core.socket;
|
||||
package com.bytedesk.core.socket.mqtt;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.bytedesk.core.config.BytedeskEventPublisher;
|
||||
// import com.bytedesk.core.message.IMessageSendService;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
// import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
// @Slf4j
|
||||
@Service
|
||||
@AllArgsConstructor
|
||||
public class MqService {
|
||||
|
||||
private final BytedeskEventPublisher bytedeskEventPublisher;
|
||||
|
||||
// private final IMessageSendService messageSendService;
|
||||
|
||||
public void sendJsonMessageToMq(String json) {
|
||||
// log.debug("sendMessageToMq: {}", json);
|
||||
bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
}
|
||||
// public void sendJsonMessageToMq(String json) {
|
||||
// // log.debug("sendMessageToMq: {}", json);
|
||||
// // bytedeskEventPublisher.publishMessageJsonEvent(json);
|
||||
// messageSendService.sendMessage(json);
|
||||
// }
|
||||
|
||||
public void sendProtoMessageToMq(byte[] messageBytes) {
|
||||
// log.debug("sendMessageToMq: {}", messageBytes);
|
||||
bytedeskEventPublisher.publishMessageProtoEvent(messageBytes);
|
||||
}
|
||||
// public void sendProtoMessageToMq(byte[] messageBytes) {
|
||||
// // log.debug("sendMessageToMq: {}", messageBytes);
|
||||
// bytedeskEventPublisher.publishMessageProtoEvent(messageBytes);
|
||||
// }
|
||||
|
||||
public void publishMqttConnectedEvent(String client) {
|
||||
bytedeskEventPublisher.publishMqttConnectedEvent(client);
|
||||
@@ -8,7 +8,7 @@ import io.netty.util.CharsetUtil;
|
||||
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.bytedesk.core.socket.MqService;
|
||||
import com.bytedesk.core.socket.mqtt.MqService;
|
||||
import com.bytedesk.core.socket.mqtt.MqttAuthService;
|
||||
import com.bytedesk.core.socket.mqtt.MqttSession;
|
||||
import com.bytedesk.core.socket.mqtt.MqttSessionService;
|
||||
|
||||
@@ -6,7 +6,7 @@ package com.bytedesk.core.socket.mqtt.protocol;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.mqtt.MqttMessage;
|
||||
|
||||
import com.bytedesk.core.socket.MqService;
|
||||
import com.bytedesk.core.socket.mqtt.MqService;
|
||||
import com.bytedesk.core.socket.mqtt.MqttSessionService;
|
||||
import com.bytedesk.core.socket.mqtt.util.ChannelUtils;
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.bytedesk.core.socket.mqtt.protocol;
|
||||
|
||||
import com.bytedesk.core.socket.MqService;
|
||||
import com.bytedesk.core.message.IMessageSendService;
|
||||
import com.bytedesk.core.socket.mqtt.MqService;
|
||||
import com.bytedesk.core.socket.mqtt.MqttAuthService;
|
||||
import com.bytedesk.core.socket.mqtt.MqttMessageIdService;
|
||||
import com.bytedesk.core.socket.mqtt.MqttSessionService;
|
||||
@@ -31,6 +32,9 @@ public class ProtocolProcess {
|
||||
@Autowired
|
||||
private MqService mqService;
|
||||
|
||||
@Autowired
|
||||
private IMessageSendService messageSendService;
|
||||
|
||||
private Connect connect;
|
||||
|
||||
private Subscribe subscribe;
|
||||
@@ -78,7 +82,7 @@ public class ProtocolProcess {
|
||||
|
||||
public Publish publish() {
|
||||
if (publish == null) {
|
||||
publish = new Publish(mqService);
|
||||
publish = new Publish(messageSendService);
|
||||
}
|
||||
return publish;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-01-29 16:21:46
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-06-30 10:08:33
|
||||
* @LastEditTime: 2024-10-15 17:41:47
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -17,8 +17,11 @@ package com.bytedesk.core.socket.mqtt.protocol;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.mqtt.*;
|
||||
|
||||
import com.bytedesk.core.socket.MqService;
|
||||
import com.bytedesk.core.message.IMessageSendService;
|
||||
// import com.bytedesk.core.socket.MqService;
|
||||
import com.bytedesk.core.socket.mqtt.util.ChannelUtils;
|
||||
import com.bytedesk.core.socket.protobuf.model.MessageProto;
|
||||
import com.bytedesk.core.utils.MessageConvertUtils;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
// import lombok.extern.slf4j.Slf4j;
|
||||
@@ -27,7 +30,8 @@ import lombok.AllArgsConstructor;
|
||||
@AllArgsConstructor
|
||||
public class Publish {
|
||||
|
||||
private final MqService mqService;
|
||||
// private final MqService mqService;
|
||||
private final IMessageSendService messageSendService;
|
||||
|
||||
//
|
||||
public void processPublish(Channel channel, MqttPublishMessage mqttPublishMessage) {
|
||||
@@ -60,8 +64,16 @@ public class Publish {
|
||||
private void sendMqMessage(MqttPublishMessage publishMessage, byte[] messageBytes) {
|
||||
// 注意:不能去掉,否则无法解析protobuf
|
||||
publishMessage.payload().getBytes(publishMessage.payload().readerIndex(), messageBytes);
|
||||
// publish messsage event, developers can listener to new message
|
||||
mqService.sendProtoMessageToMq(messageBytes);
|
||||
// publish message event, developers can listener to new message
|
||||
// mqService.sendProtoMessageToMq(messageBytes);
|
||||
try {
|
||||
MessageProto.Message messageProto = MessageProto.Message.parseFrom(messageBytes);
|
||||
String messageJson = MessageConvertUtils.toJson(messageProto);
|
||||
// mqService.sendJsonMessageToMq(messageJson);
|
||||
messageSendService.sendMessage(messageJson);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.bytedesk.core.socket.mqtt.protocol;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.mqtt.*;
|
||||
|
||||
import com.bytedesk.core.socket.MqService;
|
||||
import com.bytedesk.core.socket.mqtt.MqService;
|
||||
import com.bytedesk.core.socket.mqtt.util.ChannelUtils;
|
||||
import com.bytedesk.core.socket.mqtt.util.MqttUtil;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package com.bytedesk.core.socket.mqtt.protocol;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.handler.codec.mqtt.*;
|
||||
|
||||
import com.bytedesk.core.socket.MqService;
|
||||
import com.bytedesk.core.socket.mqtt.MqService;
|
||||
// import com.bytedesk.core.topic.TopicService;
|
||||
// import com.bytedesk.core.redis.RedisUserService;
|
||||
// import com.bytedesk.core.socket.mqtt.service.MqttSubscribeService;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-01-29 16:21:46
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-06-29 22:04:07
|
||||
* @LastEditTime: 2024-10-15 16:23:06
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -22,7 +22,8 @@ import org.springframework.messaging.handler.annotation.*;
|
||||
import org.springframework.messaging.simp.SimpMessagingTemplate;
|
||||
import org.springframework.stereotype.Controller;
|
||||
|
||||
import com.bytedesk.core.socket.MqService;
|
||||
import com.bytedesk.core.message.IMessageSendService;
|
||||
// import com.bytedesk.core.socket.MqService;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
@@ -36,10 +37,12 @@ import java.security.Principal;
|
||||
@Controller
|
||||
public class StompController {
|
||||
|
||||
private final MqService mqService;
|
||||
// private final MqService mqService;
|
||||
|
||||
private final SimpMessagingTemplate simpMessagingTemplate;
|
||||
|
||||
private final IMessageSendService messageSendService;
|
||||
|
||||
/**
|
||||
* stompClient.publish('/app/sid.uid', message)
|
||||
* 访客端发送消息
|
||||
@@ -55,16 +58,9 @@ public class StompController {
|
||||
@DestinationVariable(value = "uid") String uid,
|
||||
String message) {
|
||||
log.debug("principal: {}, sid: {}, uid: {}, message: {}", principal, sid, uid, message);
|
||||
// MessageResponse messageResponse = JSON.parseObject(message,
|
||||
// MessageResponse.class);
|
||||
// // 发送回执
|
||||
// JSONObject ackObject = new JSONObject();
|
||||
// ackObject.put("type", MessageTypeConsts.NOTIFICATION_ACK_SUCCESS);
|
||||
// ackObject.put("mid", messageResponse.getMid());
|
||||
// simpMessagingTemplate.convertAndSend(MqConsts.TOPIC_PREFIX + sid + '.' + uid,
|
||||
// ackObject);
|
||||
// 转发给mq
|
||||
mqService.sendJsonMessageToMq(message);
|
||||
// mqService.sendJsonMessageToMq(message);
|
||||
messageSendService.sendMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-01-29 16:21:24
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-20 09:51:27
|
||||
* @LastEditTime: 2024-10-16 15:08:17
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -92,7 +92,8 @@ public class ThreadController extends BaseController<ThreadRequest> {
|
||||
@PostMapping("/close")
|
||||
public ResponseEntity<?> close(@RequestBody ThreadRequest request) {
|
||||
|
||||
request.setStatus(ThreadStatusEnum.AGENT_CLOSED.name());
|
||||
request.setAutoClose(false);
|
||||
request.setState(ThreadStateEnum.CLOSED.name());
|
||||
|
||||
ThreadResponse threadResponse = threadService.close(request);
|
||||
if (threadResponse == null) {
|
||||
|
||||
@@ -23,9 +23,9 @@ import lombok.EqualsAndHashCode;
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
public class ThreadCreateEvent extends ApplicationEvent {
|
||||
|
||||
private Thread thread;
|
||||
private ThreadEntity thread;
|
||||
|
||||
public ThreadCreateEvent(Object source, Thread thread) {
|
||||
public ThreadCreateEvent(Object source, ThreadEntity thread) {
|
||||
super(source);
|
||||
this.thread = thread;
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: jackning 270580156@qq.com
|
||||
* @Date: 2024-01-29 16:21:24
|
||||
* @LastEditors: jackning 270580156@qq.com
|
||||
* @LastEditTime: 2024-09-23 16:07:43
|
||||
* @LastEditTime: 2024-10-18 15:08:43
|
||||
* @Description: bytedesk.com https://github.com/Bytedesk/bytedesk
|
||||
* Please be aware of the BSL license restrictions before installing Bytedesk IM –
|
||||
* selling, reselling, or hosting Bytedesk IM as a service is a breach of the terms and automatically terminates your rights under the license.
|
||||
@@ -48,11 +48,10 @@ import lombok.experimental.Accessors;
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
@EntityListeners({ ThreadEntityListener.class })
|
||||
// 表继承(Table Per Class
|
||||
// Inheritance):在这种策略中,每一个类(父类和每个子类)都映射到一个独立的数据库表中。子类表将只包含子类特有的属性,以及与父类表相关联的主键。
|
||||
// @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
|
||||
@Table(name = "core_thread")
|
||||
public class Thread extends BaseEntity {
|
||||
@Table(name = "core_thread", uniqueConstraints = {
|
||||
@UniqueConstraint(columnNames = {"topic", "owner_id"})
|
||||
})
|
||||
public class ThreadEntity extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@@ -72,11 +71,20 @@ public class Thread extends BaseEntity {
|
||||
@Column(name = "thread_type", nullable = false)
|
||||
private String type = ThreadTypeEnum.WORKGROUP.name();
|
||||
|
||||
// TODO: 标记问题是否解决
|
||||
|
||||
/** closed/open, agent closed/auto closed */
|
||||
@Builder.Default
|
||||
private String status = ThreadStatusEnum.START.name();
|
||||
private String state = ThreadStateEnum.INITIAL.name();
|
||||
|
||||
// 计数器编号,客服咨询首先需要取号,类似银行/医院排队系统
|
||||
@Builder.Default
|
||||
private int serialNumber = 1;
|
||||
|
||||
// 客户端需要此字段,暂时保留,TODO: 需要与真实未读消息数同步
|
||||
@Builder.Default
|
||||
private int unreadCount = 1;
|
||||
|
||||
// 星标
|
||||
@Builder.Default
|
||||
private int star = 0;
|
||||
|
||||
// 置顶
|
||||
@Builder.Default
|
||||
@@ -88,10 +96,6 @@ public class Thread extends BaseEntity {
|
||||
@Column(name = "is_unread")
|
||||
private boolean unread = false;
|
||||
|
||||
// 客户端需要此字段,暂时保留,TODO: 需要与真实未读消息数同步
|
||||
@Builder.Default
|
||||
private int unreadCount = 1;
|
||||
|
||||
// 免打扰
|
||||
@Builder.Default
|
||||
@Column(name = "is_mute")
|
||||
@@ -101,19 +105,33 @@ public class Thread extends BaseEntity {
|
||||
@Builder.Default
|
||||
@Column(name = "is_hide")
|
||||
private boolean hide = false;
|
||||
|
||||
// 星标
|
||||
@Builder.Default
|
||||
private int star = 0;
|
||||
|
||||
|
||||
// 类似微信折叠会话
|
||||
@Builder.Default
|
||||
@Column(name = "is_folded")
|
||||
private boolean folded = false;
|
||||
|
||||
// 已解决
|
||||
@Builder.Default
|
||||
@Column(name = "is_solved")
|
||||
private boolean solved = false;
|
||||
|
||||
// 已评价
|
||||
@Builder.Default
|
||||
@Column(name = "is_rated")
|
||||
private boolean rated = false;
|
||||
|
||||
// 自动关闭
|
||||
@Builder.Default
|
||||
@Column(name = "is_auto_close")
|
||||
private boolean autoClose = false;
|
||||
|
||||
// 机器人
|
||||
@Builder.Default
|
||||
@Column(name = "is_robot")
|
||||
private boolean robot = false;
|
||||
|
||||
@Builder.Default
|
||||
// @Enumerated(EnumType.STRING)
|
||||
// private ClientEnum client;
|
||||
private String client = ClientEnum.WEB.name();
|
||||
|
||||
@Builder.Default
|
||||
@@ -161,10 +179,23 @@ public class Thread extends BaseEntity {
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
private User owner;
|
||||
|
||||
public void reInit() {
|
||||
this.state = ThreadStateEnum.INITIAL.name();
|
||||
this.unread = false;
|
||||
this.unreadCount = 1;
|
||||
this.mute = false;
|
||||
this.hide = false;
|
||||
this.star = 0;
|
||||
this.folded = false;
|
||||
this.solved = false;
|
||||
this.rated = false;
|
||||
this.autoClose = false;
|
||||
this.robot = false;
|
||||
}
|
||||
|
||||
//
|
||||
public Boolean isClosed() {
|
||||
return this.status.equals(ThreadStatusEnum.AGENT_CLOSED.name())
|
||||
|| this.status.equals(ThreadStatusEnum.AUTO_CLOSED.name());
|
||||
return this.state.equals(ThreadStateEnum.CLOSED.name());
|
||||
}
|
||||
|
||||
public Boolean isCustomerService() {
|
||||
@@ -35,10 +35,10 @@ public class ThreadEntityListener {
|
||||
// private transient Thread oldThread;
|
||||
|
||||
@PostPersist
|
||||
public void postPersist(Thread thread) {
|
||||
public void postPersist(ThreadEntity thread) {
|
||||
log.info("thread postPersist {}", thread.getUid());
|
||||
// send notifications
|
||||
Thread clonedThread = SerializationUtils.clone(thread);
|
||||
ThreadEntity clonedThread = SerializationUtils.clone(thread);
|
||||
|
||||
BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class);
|
||||
bytedeskEventPublisher.publishThreadCreateEvent(clonedThread);
|
||||
@@ -51,10 +51,10 @@ public class ThreadEntityListener {
|
||||
// }
|
||||
|
||||
@PostUpdate
|
||||
public void postUpdate(Thread thread) {
|
||||
public void postUpdate(ThreadEntity thread) {
|
||||
log.info("postUpdate {}", thread.getUid());
|
||||
// send notifications
|
||||
Thread clonedThread = SerializationUtils.clone(thread);
|
||||
ThreadEntity clonedThread = SerializationUtils.clone(thread);
|
||||
|
||||
BytedeskEventPublisher bytedeskEventPublisher = ApplicationContextHolder.getBean(BytedeskEventPublisher.class);
|
||||
bytedeskEventPublisher.publishThreadUpdateEvent(clonedThread);
|
||||
|
||||
@@ -19,7 +19,7 @@ import java.util.List;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.bytedesk.core.message.Message;
|
||||
import com.bytedesk.core.message.MessageEntity;
|
||||
import com.bytedesk.core.message.MessageCreateEvent;
|
||||
import com.bytedesk.core.message.MessageTypeEnum;
|
||||
import com.bytedesk.core.quartz.event.QuartzOneMinEvent;
|
||||
@@ -46,7 +46,7 @@ public class ThreadEventListener {
|
||||
|
||||
@EventListener
|
||||
public void onThreadCreateEvent(ThreadCreateEvent event) {
|
||||
Thread thread = event.getThread();
|
||||
ThreadEntity thread = event.getThread();
|
||||
User user = thread.getOwner();
|
||||
log.info("thread ThreadCreateEvent: {}", thread.getUid());
|
||||
|
||||
@@ -75,7 +75,7 @@ public class ThreadEventListener {
|
||||
|
||||
@EventListener
|
||||
public void onThreadUpdateEvent(ThreadUpdateEvent event) {
|
||||
Thread thread = event.getThread();
|
||||
ThreadEntity thread = event.getThread();
|
||||
User user = thread.getOwner();
|
||||
log.info("topic onThreadUpdateEvent: {}", thread.getUid());
|
||||
// TODO: 会话关闭之后,需要取消订阅
|
||||
@@ -95,7 +95,7 @@ public class ThreadEventListener {
|
||||
topicService.create(request);
|
||||
} else {
|
||||
// if (thread.getType().equals(ThreadTypeEnum.MEMBER.name())
|
||||
// || thread.getType().equals(ThreadTypeEnum.ASISTANT.name())
|
||||
// || thread.getType().equals(ThreadTypeEnum.ASSISTANT.name())
|
||||
// || thread.getType().equals(ThreadTypeEnum.CHANNEL.name())
|
||||
// || thread.getType().equals(ThreadTypeEnum.LLM.name()))
|
||||
// 文件助手、系统通知会话延迟订阅topic
|
||||
@@ -117,7 +117,7 @@ public class ThreadEventListener {
|
||||
|
||||
@EventListener
|
||||
public void onMessageCreateEvent(MessageCreateEvent event) {
|
||||
Message message = event.getMessage();
|
||||
MessageEntity message = event.getMessage();
|
||||
if (message.getType().equals(MessageTypeEnum.STREAM.name())) {
|
||||
return;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ public class ThreadEventListener {
|
||||
|
||||
@EventListener
|
||||
public void onQuartzOneMinEvent(QuartzOneMinEvent event) {
|
||||
List<Thread> threadList = threadPersistCache.getListForPersist();
|
||||
List<ThreadEntity> threadList = threadPersistCache.getListForPersist();
|
||||
if (threadList != null) {
|
||||
threadList.forEach(thread -> {
|
||||
threadService.save(thread);
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ThreadFlowNode implements Serializable {
|
||||
|
||||
private final static long serialVersionUID = 1L;
|
||||
|
||||
private ThreadStatusEnum status;
|
||||
private ThreadStateEnum status;
|
||||
|
||||
private String content;
|
||||
|
||||
|
||||
@@ -33,16 +33,16 @@ public class ThreadPersistCache {
|
||||
String defaultPersistKey = "threadList";
|
||||
|
||||
// 创建一个缓存实例,设置过期时间为5天
|
||||
private Cache<String, List<Thread>> threadCache;
|
||||
private Cache<String, List<ThreadEntity>> threadCache;
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
// 初始化caffeinecache,设置缓存的最大大小、过期时间等参数
|
||||
threadCache = Caffeine.newBuilder()
|
||||
.expireAfterWrite(1, TimeUnit.DAYS)
|
||||
.build(new CacheLoader<String, List<Thread>>() {
|
||||
.build(new CacheLoader<String, List<ThreadEntity>>() {
|
||||
@Override
|
||||
public List<Thread> load(String key) throws Exception {
|
||||
public List<ThreadEntity> load(String key) throws Exception {
|
||||
// 当缓存中没有找到对应的键时,使用load方法初始化
|
||||
return new ArrayList<>();
|
||||
}
|
||||
@@ -50,10 +50,10 @@ public class ThreadPersistCache {
|
||||
}
|
||||
|
||||
// 模拟 push 操作:向列表中添加元素
|
||||
public void pushForPersist(Thread thread) {
|
||||
public void pushForPersist(ThreadEntity thread) {
|
||||
// 通过thread.uid判断defaultPersistKey中是否已经存在 则替换掉,不存在,则插入
|
||||
String uid = thread.getUid();
|
||||
List<Thread> cachedList = threadCache.getIfPresent(defaultPersistKey);
|
||||
List<ThreadEntity> cachedList = threadCache.getIfPresent(defaultPersistKey);
|
||||
if (cachedList == null) {
|
||||
cachedList = new ArrayList<>();
|
||||
}
|
||||
@@ -75,13 +75,13 @@ public class ThreadPersistCache {
|
||||
}
|
||||
|
||||
// 模拟 pop 操作:从列表中移除元素
|
||||
public List<Thread> getListForPersist() {
|
||||
public List<ThreadEntity> getListForPersist() {
|
||||
return getList(defaultPersistKey);
|
||||
}
|
||||
|
||||
// 模拟 push 操作:向列表中添加元素
|
||||
public void push(String listKey, Thread thread) {
|
||||
List<Thread> cachedList = threadCache.getIfPresent(listKey);
|
||||
public void push(String listKey, ThreadEntity thread) {
|
||||
List<ThreadEntity> cachedList = threadCache.getIfPresent(listKey);
|
||||
if (cachedList == null) {
|
||||
// 如果缓存中没有找到对应的键,则使用load方法初始化
|
||||
cachedList = new ArrayList<>();
|
||||
@@ -90,8 +90,8 @@ public class ThreadPersistCache {
|
||||
threadCache.put(listKey, cachedList);
|
||||
}
|
||||
|
||||
public List<Thread> getList(String listKey) {
|
||||
List<Thread> cachedList = threadCache.getIfPresent(listKey);
|
||||
public List<ThreadEntity> getList(String listKey) {
|
||||
List<ThreadEntity> cachedList = threadCache.getIfPresent(listKey);
|
||||
if (cachedList != null && !cachedList.isEmpty()) {
|
||||
// 只需要返回一次即可
|
||||
remove(listKey);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user