mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-07 01:46:47 +08:00
Compare commits
130 Commits
player-202
...
250930-fea
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
300fa7ab06 | ||
|
|
784fe062bf | ||
|
|
c233260250 | ||
|
|
4015e461b2 | ||
|
|
b07b620d14 | ||
|
|
e54f184a16 | ||
|
|
3abe5365b4 | ||
|
|
e5cb156e64 | ||
|
|
68e610c222 | ||
|
|
457339a385 | ||
|
|
b9fc27f4fb | ||
|
|
ee0a853b1b | ||
|
|
b128187e31 | ||
|
|
4412563208 | ||
|
|
7bee2e3c45 | ||
|
|
5c43dffb4f | ||
|
|
a045f470e6 | ||
|
|
92aaf2bed7 | ||
|
|
cc9d4b7bb9 | ||
|
|
dd0760a32b | ||
|
|
38c2784f51 | ||
|
|
49d3ad5999 | ||
|
|
4f4fd64a6d | ||
|
|
07bf665220 | ||
|
|
8a3899dfd1 | ||
|
|
c17a594393 | ||
|
|
09d61ceb9d | ||
|
|
106fde8e6b | ||
|
|
3bf0534d77 | ||
|
|
dd0e10539f | ||
|
|
fceb6ac805 | ||
|
|
24576a4fd1 | ||
|
|
8d7cfac081 | ||
|
|
1d5447cff5 | ||
|
|
ddf3f277cd | ||
|
|
48c6090fb1 | ||
|
|
46f8668cb8 | ||
|
|
09c10e3af6 | ||
|
|
dfba210890 | ||
|
|
f04660d8a3 | ||
|
|
c30283979a | ||
|
|
649f512887 | ||
|
|
56d1a6a509 | ||
|
|
456f7ec061 | ||
|
|
8d31d63be5 | ||
|
|
c592a29ad4 | ||
|
|
b54d78d17b | ||
|
|
30efbd5610 | ||
|
|
1043b7d404 | ||
|
|
d480a53a26 | ||
|
|
d8b2869d80 | ||
|
|
8ee866bf39 | ||
|
|
3bb1f619bf | ||
|
|
4be26921d8 | ||
|
|
748ec8c072 | ||
|
|
e9682dcb61 | ||
|
|
67aa312d2f | ||
|
|
770dc684cd | ||
|
|
aa5c13598d | ||
|
|
a4f67d99ff | ||
|
|
95cb5ba656 | ||
|
|
23f72e7702 | ||
|
|
b9728993ce | ||
|
|
70ad3020d4 | ||
|
|
425611a106 | ||
|
|
9de9eaea7e | ||
|
|
ce05b67039 | ||
|
|
7f905d21a4 | ||
|
|
a27e0eb6c5 | ||
|
|
cf069a9700 | ||
|
|
0e2e0861de | ||
|
|
b55e2fa6e0 | ||
|
|
6feef59a72 | ||
|
|
4900383c98 | ||
|
|
873c3c300a | ||
|
|
26c08631a0 | ||
|
|
e20a20ec43 | ||
|
|
c29dcd5966 | ||
|
|
ceaa0adbf0 | ||
|
|
c671ae5bab | ||
|
|
14aa8a17c6 | ||
|
|
67dfee1f07 | ||
|
|
fe688de8aa | ||
|
|
4e3ce2d762 | ||
|
|
42946fed80 | ||
|
|
079b64d0fd | ||
|
|
d95bf6ee6c | ||
|
|
96342f1170 | ||
|
|
f226f209e9 | ||
|
|
7ef5af09db | ||
|
|
e7558c5526 | ||
|
|
ac12e04a58 | ||
|
|
957ac93a98 | ||
|
|
80b6135534 | ||
|
|
2639936128 | ||
|
|
c244290d1a | ||
|
|
b862128a79 | ||
|
|
58f9cdc5d6 | ||
|
|
cf8237819b | ||
|
|
bc5d78e7cc | ||
|
|
fa740f8f40 | ||
|
|
0a55fbd08f | ||
|
|
bb8bf5e979 | ||
|
|
5a4a560d10 | ||
|
|
08b4feb00c | ||
|
|
16b2d90417 | ||
|
|
bad129a0a1 | ||
|
|
08bd7f155f | ||
|
|
5e20e21e86 | ||
|
|
5666cfeaaa | ||
|
|
9c4cef9dca | ||
|
|
0207826a07 | ||
|
|
11ebb2e38b | ||
|
|
176d2cb800 | ||
|
|
66f437427c | ||
|
|
5f32b8a6fc | ||
|
|
2358c2e881 | ||
|
|
660cee2112 | ||
|
|
7376ea21c7 | ||
|
|
5e02e3ef5f | ||
|
|
12168ff725 | ||
|
|
a3647aa190 | ||
|
|
af503efefc | ||
|
|
9188bcdf30 | ||
|
|
a6eb3b519e | ||
|
|
e8a787e2a3 | ||
|
|
720031c648 | ||
|
|
7d6243e16e | ||
|
|
0c4dbecd79 | ||
|
|
fdfd834ce9 |
@@ -161,11 +161,21 @@
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpclient</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.httpcomponents</groupId>
|
||||
<artifactId>httpmime</artifactId>
|
||||
<version>4.5.13</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>javax.mail-api</artifactId>
|
||||
<version>1.5.6</version>
|
||||
</dependency>
|
||||
<!-- <dependency>-->
|
||||
<!-- <groupId>com.sun.mail</groupId>-->
|
||||
<!-- <artifactId>javax.mail</artifactId>-->
|
||||
<!-- <version>1.5.6</version>-->
|
||||
<!-- </dependency>-->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
@@ -227,6 +237,23 @@
|
||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||
<version>7.9.0</version> <!-- 请根据实际需求选择合适的版本 -->
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp-sse</artifactId>
|
||||
<version>4.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>2.0.31</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.xboe</groupId>
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.xboe.config;
|
||||
|
||||
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* ElasticSearch索引初始化器
|
||||
* 在Spring Boot启动完成并监听到配置文件加载完毕后,检查并创建所需的ES索引
|
||||
*
|
||||
* @author AI Assistant
|
||||
*/
|
||||
@Slf4j
|
||||
@Component
|
||||
public class ElasticSearchIndexInitializer {
|
||||
|
||||
@Autowired
|
||||
private IElasticSearchIndexService elasticSearchIndexService;
|
||||
|
||||
/**
|
||||
* 监听Spring Boot应用启动完成事件
|
||||
* ApplicationReadyEvent在应用启动完成、所有配置加载完毕后触发
|
||||
*/
|
||||
@EventListener(ApplicationReadyEvent.class)
|
||||
public void initializeElasticSearchIndices() {
|
||||
if (elasticSearchIndexService.checkIndexExists()) {
|
||||
log.info("ElasticSearch索引 ai_chat_messages 已存在");
|
||||
} else {
|
||||
log.info("ElasticSearch索引 ai_chat_messages 不存在,开始创建...");
|
||||
elasticSearchIndexService.createIndex();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.xboe.config;
|
||||
|
||||
import org.apache.activemq.command.ActiveMQTopic;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
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 javax.jms.ConnectionFactory;
|
||||
import javax.jms.Topic;
|
||||
|
||||
@EnableJms
|
||||
@Configuration
|
||||
public class MqConfig {
|
||||
|
||||
@Value("${activemq.topic.name}")
|
||||
private String topicName;
|
||||
|
||||
|
||||
/**
|
||||
* 配置topic
|
||||
*/
|
||||
@Bean
|
||||
public Topic broadcastTopic() {
|
||||
return new ActiveMQTopic(topicName);
|
||||
}
|
||||
|
||||
// 配置JmsListenerContainerFactory为发布/订阅模式
|
||||
@Bean
|
||||
public JmsListenerContainerFactory<?> jmsListenerContainerFactory(ConnectionFactory connectionFactory) {
|
||||
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
|
||||
factory.setConnectionFactory(connectionFactory);
|
||||
factory.setPubSubDomain(true); // 设置为发布/订阅模式
|
||||
factory.setSubscriptionDurable(false); // 非持久订阅
|
||||
return factory;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.xboe.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.Dispatcher;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
/**
|
||||
* 线程池配置类
|
||||
*/
|
||||
@Configuration
|
||||
@Slf4j
|
||||
public class ThreadPoolConfig {
|
||||
|
||||
/**
|
||||
* 执行AI文档接口的的线程池
|
||||
* 策略:单线程等待队列
|
||||
*/
|
||||
@Bean(name = "aiDocExecutor")
|
||||
public ThreadPoolTaskExecutor aiDocExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
// 设置核心线程数
|
||||
int corePoolSize = Runtime.getRuntime().availableProcessors();
|
||||
executor.setCorePoolSize(Math.max(4, corePoolSize));
|
||||
// 设置最大线程数
|
||||
executor.setMaxPoolSize(Math.max(16, corePoolSize * 2));
|
||||
// 设置队列容量(确保任务排队)
|
||||
executor.setQueueCapacity(100);
|
||||
// keepalive
|
||||
executor.setKeepAliveSeconds(30);
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
executor.setAwaitTerminationSeconds(30);
|
||||
// 设置线程名称前缀
|
||||
executor.setThreadNamePrefix("ai_doc_task-");
|
||||
// 设置拒绝策略(当队列满时,由调用线程处理该任务)
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
// 初始化线程池
|
||||
executor.initialize();
|
||||
log.info("AI文档线程池初始化完成 - 核心线程: {}, 最大线程: {}, 队列容量: {}",
|
||||
executor.getCorePoolSize(),
|
||||
executor.getMaxPoolSize(),
|
||||
executor.getQueueCapacity());
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* event-stream线程池
|
||||
* @return
|
||||
*/
|
||||
@Bean(name = "eventStreamExecutor")
|
||||
public ThreadPoolTaskExecutor eventStreamExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(10);
|
||||
executor.setMaxPoolSize(500);
|
||||
executor.setQueueCapacity(10);
|
||||
executor.setThreadNamePrefix("event-stream-");
|
||||
executor.setKeepAliveSeconds(300);
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步存会话数据线程池
|
||||
* @return
|
||||
*/
|
||||
@Bean(name = "esChatExecutor")
|
||||
public ThreadPoolTaskExecutor esChatExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(10);
|
||||
executor.setMaxPoolSize(500);
|
||||
executor.setQueueCapacity(10);
|
||||
executor.setThreadNamePrefix("es-chat-");
|
||||
executor.setKeepAliveSeconds(300);
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Bean(name = "customDispatcher")
|
||||
public Dispatcher customDispatcher(@Qualifier("eventStreamExecutor") ThreadPoolTaskExecutor eventStreamExecutor) {
|
||||
return new Dispatcher(eventStreamExecutor.getThreadPoolExecutor());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.xboe.constants;
|
||||
|
||||
public class CaseAiConstants {
|
||||
|
||||
public static final String CASE_AI_INDEX_NAME = "ai_chat_messages";
|
||||
|
||||
public static final String CASE_DOC_UPLOAD_INTERFACE_NAME = "文档上传";
|
||||
|
||||
public static final String CASE_DOC_DELETE_INTERFACE_NAME = "文档删除";
|
||||
|
||||
public static final String CHAT_SYS_ERR_MSG = "服务繁忙,请稍后再试。";
|
||||
|
||||
public static final String CHAT_NET_ERR_MSG = "网络异常,请稍后再试。";
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package com.xboe.enums;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* 错误码枚举
|
||||
*/
|
||||
@Getter
|
||||
public enum CaseAiChatErrCodeEnum {
|
||||
|
||||
SUCCESS(0, "成功"),
|
||||
|
||||
INTERNAL_ERROR(1, "内部错误"),
|
||||
|
||||
AIOT_ERROR(2, "AIoT平台错误"),
|
||||
;
|
||||
|
||||
private final int code;
|
||||
|
||||
private final String label;
|
||||
|
||||
CaseAiChatErrCodeEnum(int code, String label) {
|
||||
this.code = code;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static CaseAiChatErrCodeEnum getByCode(int code) {
|
||||
return Arrays.stream(values()).filter(e -> e.code == code)
|
||||
.findFirst().orElse(SUCCESS);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.xboe.enums;
|
||||
|
||||
public enum CaseAiChatStatusEnum {
|
||||
|
||||
REFERS(0, "引用文档"),
|
||||
|
||||
CHAT(1, "聊天中"),
|
||||
|
||||
CHAT_COMPLETED(2, "聊天完成"),
|
||||
|
||||
SUGGESTIONS(3, "建议"),
|
||||
|
||||
API_COMPLETED(4, "接口完成"),
|
||||
;
|
||||
|
||||
private final int code;
|
||||
|
||||
private final String label;
|
||||
|
||||
CaseAiChatStatusEnum(int code, String label) {
|
||||
this.code = code;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public static CaseAiChatStatusEnum getByCode(int code) {
|
||||
for (CaseAiChatStatusEnum value : values()) {
|
||||
if (value.code == code) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return API_COMPLETED;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.xboe.enums;
|
||||
|
||||
/**
|
||||
* AI调用日志业务处理状态枚举
|
||||
*/
|
||||
public enum CaseDocumentLogCaseStatusEnum {
|
||||
|
||||
SUCCESS(1, "处理成功"),
|
||||
FAILED(2, "处理失败");
|
||||
|
||||
private final Integer code;
|
||||
private final String desc;
|
||||
|
||||
CaseDocumentLogCaseStatusEnum(Integer code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取描述
|
||||
*/
|
||||
public static String getDescByCode(Integer code) {
|
||||
for (CaseDocumentLogCaseStatusEnum statusEnum : values()) {
|
||||
if (statusEnum.getCode().equals(code)) {
|
||||
return statusEnum.getDesc();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*/
|
||||
public static CaseDocumentLogCaseStatusEnum getByCode(Integer code) {
|
||||
for (CaseDocumentLogCaseStatusEnum statusEnum : values()) {
|
||||
if (statusEnum.getCode().equals(code)) {
|
||||
return statusEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package com.xboe.enums;
|
||||
|
||||
/**
|
||||
* AI调用日志接口调用状态枚举
|
||||
*/
|
||||
public enum CaseDocumentLogOptStatusEnum {
|
||||
|
||||
CALLING(0, "调用中"),
|
||||
SUCCESS(1, "调用成功"),
|
||||
FAILED(2, "调用失败");
|
||||
|
||||
private final Integer code;
|
||||
private final String desc;
|
||||
|
||||
CaseDocumentLogOptStatusEnum(Integer code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取描述
|
||||
*/
|
||||
public static String getDescByCode(Integer code) {
|
||||
for (CaseDocumentLogOptStatusEnum statusEnum : values()) {
|
||||
if (statusEnum.getCode().equals(code)) {
|
||||
return statusEnum.getDesc();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*/
|
||||
public static CaseDocumentLogOptStatusEnum getByCode(Integer code) {
|
||||
for (CaseDocumentLogOptStatusEnum statusEnum : values()) {
|
||||
if (statusEnum.getCode().equals(code)) {
|
||||
return statusEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.xboe.enums;
|
||||
|
||||
/**
|
||||
* AI调用日志操作类型枚举
|
||||
*/
|
||||
public enum CaseDocumentLogOptTypeEnum {
|
||||
|
||||
CREATE("create", "新增"),
|
||||
DELETE("delete", "删除"),
|
||||
UPDATE("update", "更改");
|
||||
|
||||
private final String code;
|
||||
private final String desc;
|
||||
|
||||
CaseDocumentLogOptTypeEnum(String code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取描述
|
||||
*/
|
||||
public static String getDescByCode(String code) {
|
||||
for (CaseDocumentLogOptTypeEnum typeEnum : values()) {
|
||||
if (typeEnum.getCode().equals(code)) {
|
||||
return typeEnum.getDesc();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package com.xboe.enums;
|
||||
|
||||
/**
|
||||
* AI调用日志接口运行状态枚举
|
||||
*/
|
||||
public enum CaseDocumentLogRunStatusEnum {
|
||||
|
||||
RUNNING(0, "运行中"),
|
||||
COMPLETED(1, "运行完成");
|
||||
|
||||
private final Integer code;
|
||||
private final String desc;
|
||||
|
||||
CaseDocumentLogRunStatusEnum(Integer code, String desc) {
|
||||
this.code = code;
|
||||
this.desc = desc;
|
||||
}
|
||||
|
||||
public Integer getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getDesc() {
|
||||
return desc;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取描述
|
||||
*/
|
||||
public static String getDescByCode(Integer code) {
|
||||
for (CaseDocumentLogRunStatusEnum statusEnum : values()) {
|
||||
if (statusEnum.getCode().equals(code)) {
|
||||
return statusEnum.getDesc();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据code获取枚举
|
||||
*/
|
||||
public static CaseDocumentLogRunStatusEnum getByCode(Integer code) {
|
||||
for (CaseDocumentLogRunStatusEnum statusEnum : values()) {
|
||||
if (statusEnum.getCode().equals(code)) {
|
||||
return statusEnum;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.xboe.module.assistance.service;
|
||||
|
||||
/**
|
||||
* SMTP邮件服务接口
|
||||
*/
|
||||
public interface ISmtpEmailService {
|
||||
|
||||
/**
|
||||
* 使用SMTP直接发送邮件
|
||||
* @param to 收件人邮箱
|
||||
* @param subject 邮件主题
|
||||
* @param htmlMsg 邮件内容(HTML格式)
|
||||
* @param from 发件人邮箱
|
||||
* @throws Exception 发送异常
|
||||
*/
|
||||
void sendMailBySmtp(String to, String subject, String htmlMsg, String from) throws Exception;
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
package com.xboe.module.assistance.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.xboe.module.assistance.service.ISmtpEmailService;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class SmtpEmailServiceImpl implements ISmtpEmailService {
|
||||
|
||||
//region 默认SMTP服务器配置信息
|
||||
private static final String SMTP_HOST = "mail.boe.com.cn";
|
||||
private static final String SMTP_USERNAME = "boeu_learning@boe.com.cn";
|
||||
private static final String SMTP_PASSWORD = "boeLms20251112Syse";
|
||||
private static final String SMTP_PORT = "465";
|
||||
private static final String SMTP_ENCRYPTION = "ssl";
|
||||
//endregion
|
||||
|
||||
@Override
|
||||
public void sendMailBySmtp(String to, String subject, String htmlMsg, String from) throws Exception {
|
||||
// 检查参数
|
||||
if (StringUtils.isBlank(to)) {
|
||||
throw new Exception("发送邮件失败,未指定收件人");
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(subject)) {
|
||||
throw new Exception("发送邮件失败,未指定邮件主题");
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(htmlMsg)) {
|
||||
throw new Exception("发送邮件失败,未指定邮件内容");
|
||||
}
|
||||
// 初始化配置项
|
||||
|
||||
// 设置SMTP属性
|
||||
Properties props = new Properties();
|
||||
props.put("mail.smtp.host", SMTP_HOST);
|
||||
props.put("mail.smtp.port", SMTP_PORT);
|
||||
props.put("mail.smtp.auth", "true");
|
||||
|
||||
if ("ssl".equalsIgnoreCase(SMTP_ENCRYPTION)) {
|
||||
props.put("mail.smtp.ssl.enable", "true");
|
||||
props.put("mail.smtp.ssl.trust", SMTP_HOST);
|
||||
// props.put("mail.smtp.ssl.protocols", "TLSv1.2");
|
||||
} else if ("tls".equalsIgnoreCase(SMTP_ENCRYPTION)) {
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
}
|
||||
|
||||
Authenticator authenticator = new Authenticator() {
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication() {
|
||||
return new PasswordAuthentication(SMTP_USERNAME, SMTP_PASSWORD);
|
||||
}
|
||||
};
|
||||
// 创建会话
|
||||
Session session = Session.getInstance(props, authenticator);
|
||||
session.setDebug(true); // 查看调试信息
|
||||
|
||||
try {
|
||||
// 创建邮件消息
|
||||
Message message = new MimeMessage(session);
|
||||
|
||||
// 设置发件人
|
||||
message.setFrom(new InternetAddress(SMTP_USERNAME));
|
||||
|
||||
// 设置收件人
|
||||
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
|
||||
|
||||
// 设置邮件主题
|
||||
message.setSubject(subject);
|
||||
|
||||
// 设置邮件内容
|
||||
message.setContent(htmlMsg, "text/html;charset=UTF-8");
|
||||
|
||||
// 发送日期
|
||||
message.setSentDate(new Date());
|
||||
|
||||
// 发送邮件
|
||||
log.info("发送邮件. 发件人: {}, 收件人: {}, 标题: {}", SMTP_USERNAME, to, subject);
|
||||
Transport.send(message);
|
||||
|
||||
} catch (MessagingException e) {
|
||||
throw new Exception("发送邮件失败", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,238 @@
|
||||
package com.xboe.module.boecase.api;
|
||||
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.module.boecase.dto.CaseAiChatDto;
|
||||
import com.xboe.module.boecase.dto.CaseAiMsgLikeDto;
|
||||
import com.xboe.module.boecase.dto.EsFieldDTO;
|
||||
import com.xboe.module.boecase.dto.GetCaseAiMsgDto;
|
||||
import com.xboe.module.boecase.entity.AiChatConversationData;
|
||||
import com.xboe.module.boecase.service.ICaseAiChatService;
|
||||
import com.xboe.module.boecase.service.ICaseAiPermissionService;
|
||||
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI对话管理API
|
||||
*/
|
||||
@Slf4j(topic = "caseAiChatLogger")
|
||||
@RestController
|
||||
@RequestMapping(value = "/xboe/m/boe/case/ai")
|
||||
public class CaseAiChatApi extends ApiBaseController {
|
||||
|
||||
/**
|
||||
* 聊天
|
||||
* @param caseAiChatDto
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@Autowired
|
||||
private ICaseAiChatService caseAiChatService;
|
||||
|
||||
@Autowired
|
||||
private ICaseAiPermissionService caseAiPermissionService;
|
||||
|
||||
@Autowired
|
||||
private IElasticSearchIndexService elasticSearchIndexService;
|
||||
|
||||
/**
|
||||
* 聊天
|
||||
* @param caseAiChatDto
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
@PostMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
|
||||
public SseEmitter chat(@RequestBody CaseAiChatDto caseAiChatDto,
|
||||
HttpServletResponse response) {
|
||||
response.setContentType("text/event-stream");
|
||||
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
|
||||
|
||||
// 获取当前用户
|
||||
return caseAiChatService.chat(caseAiChatDto, getCurrent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止当前聊天输出
|
||||
* @param conversationId 会话ID
|
||||
* @return 是否成功停止
|
||||
*/
|
||||
@GetMapping("/stop")
|
||||
public JsonResponse<Boolean> stopChat(@RequestParam String conversationId) {
|
||||
try {
|
||||
boolean result = caseAiChatService.stopChatOutput(conversationId);
|
||||
if (result) {
|
||||
return success(true, "成功停止输出");
|
||||
} else {
|
||||
return success(false, "未找到对应的会话或会话已结束");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("停止聊天输出异常", e);
|
||||
return error("停止输出失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 赞消息
|
||||
* @param caseAiMsgLikeDto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/likeMsg")
|
||||
public JsonResponse<Boolean> likeMsg(@RequestBody CaseAiMsgLikeDto caseAiMsgLikeDto) {
|
||||
try {
|
||||
caseAiMsgLikeDto.setOperation(true);
|
||||
if (caseAiChatService.msgFeedback(caseAiMsgLikeDto)) {
|
||||
return success(true, "保存成功");
|
||||
} else {
|
||||
return success(false, "保存失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("消息赞/踩操作保存异常", e);
|
||||
return error("保存失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 消息问题反馈保存
|
||||
* @param caseAiMsgLikeDto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/msgFeedback")
|
||||
public JsonResponse<Boolean> msgFeedback(@RequestBody CaseAiMsgLikeDto caseAiMsgLikeDto) {
|
||||
try {
|
||||
caseAiMsgLikeDto.setOperation(false);
|
||||
if (caseAiChatService.msgFeedback(caseAiMsgLikeDto)) {
|
||||
return success(true, "保存成功");
|
||||
} else {
|
||||
return success(false, "保存失败");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("消息问题反馈保存异常", e);
|
||||
return error("保存失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取消息
|
||||
*
|
||||
* @param getCaseAiMsgDto
|
||||
*/
|
||||
@PostMapping("/getCaseAiMsg")
|
||||
public JsonResponse<List<CaseAiMessageVo>> getCaseAiMsgDetail(@RequestBody GetCaseAiMsgDto getCaseAiMsgDto) {
|
||||
try {
|
||||
List<CaseAiMessageVo> caseAiMessageVoList = caseAiChatService.getCaseAiMsg(getCaseAiMsgDto);
|
||||
return success(caseAiMessageVoList);
|
||||
} catch (Exception e) {
|
||||
log.error("获取消息详情异常", e);
|
||||
return error("获取失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据conversationId查看会话内消息记录
|
||||
* @param conversationId 会话ID
|
||||
* @return 消息记录列表
|
||||
*/
|
||||
@GetMapping("/messages")
|
||||
public JsonResponse<List<CaseAiMessageVo>> getConversationMessages(@RequestParam String conversationId) {
|
||||
try {
|
||||
List<CaseAiMessageVo> messages = caseAiChatService.getConversationMessages(conversationId);
|
||||
return success(messages);
|
||||
} catch (Exception e) {
|
||||
log.error("查询会话消息记录异常", e);
|
||||
return error("查询失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出会话记录为Excel
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param response HTTP响应
|
||||
*/
|
||||
@GetMapping("/export-conversations")
|
||||
public void downloadConversationExcel(@RequestParam String startTime,
|
||||
@RequestParam String endTime,
|
||||
HttpServletResponse response) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
LocalDate startDate = LocalDate.parse(startTime, formatter);
|
||||
LocalDate endDate = LocalDate.parse(endTime, formatter);
|
||||
caseAiChatService.getConversationExcel(startDate.atStartOfDay(), endDate.atTime(23, 59, 59), response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前登录用户是否显示"案例专家"功能入口
|
||||
* @return 是否显示功能入口
|
||||
*/
|
||||
@GetMapping("/show-entrance")
|
||||
public JsonResponse<Boolean> showCaseAiEntrance() {
|
||||
try {
|
||||
String currentUserCode = getCurrent().getCode();
|
||||
boolean shouldShow = caseAiPermissionService.shouldShowCaseAiEntrance(currentUserCode);
|
||||
// return success(shouldShow);
|
||||
JsonResponse<Boolean> result = success(shouldShow);
|
||||
result.setMessage(currentUserCode);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("判断案例专家功能入口显示权限异常", e);
|
||||
return error("判断失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 手动刷新索引
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/index/refresh")
|
||||
public JsonResponse<String> deleteAndCreateEsIndex() {
|
||||
if (elasticSearchIndexService.checkIndexExists()) {
|
||||
boolean deleteResult = elasticSearchIndexService.deleteIndex();
|
||||
if (deleteResult) {
|
||||
elasticSearchIndexService.createIndex();
|
||||
return success("刷新成功");
|
||||
}
|
||||
} else {
|
||||
elasticSearchIndexService.createIndex();
|
||||
}
|
||||
return error("刷新失败");
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加索引字段
|
||||
* @param esFieldDTO
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/index/add_field")
|
||||
public JsonResponse<String> addField(@RequestBody EsFieldDTO esFieldDTO) {
|
||||
boolean result = elasticSearchIndexService.updateIndex(esFieldDTO.getFieldName(), esFieldDTO.getIndexProperties());
|
||||
return result ? success("添加成功") : error("添加失败");
|
||||
}
|
||||
|
||||
@PostMapping("/es/create")
|
||||
public JsonResponse<String> createNewConversation(@RequestBody CaseAiMessageVo caseAiMessageVo,
|
||||
@RequestParam String conversationId,
|
||||
@RequestParam String userId) {
|
||||
AiChatConversationData aiChatConversationData = new AiChatConversationData();
|
||||
aiChatConversationData.setConversationId(conversationId);
|
||||
aiChatConversationData.setQuery(caseAiMessageVo.getQuery());
|
||||
aiChatConversationData.appendAnswer(caseAiMessageVo.getAnswer());
|
||||
aiChatConversationData.setCaseRefers(caseAiMessageVo.getCaseRefer());
|
||||
aiChatConversationData.setSuggestions(caseAiMessageVo.getSuggestions());
|
||||
aiChatConversationData.setUserId(userId);
|
||||
if (elasticSearchIndexService.createData(aiChatConversationData)) {
|
||||
return success("创建成功");
|
||||
}
|
||||
return error("创建失败");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,331 @@
|
||||
package com.xboe.module.boecase.api;
|
||||
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
import com.xboe.core.log.AutoLog;
|
||||
import com.xboe.module.boecase.dto.CaseDocumentLogQueryDto;
|
||||
import com.xboe.module.boecase.service.ICaseDocumentLogService;
|
||||
import com.xboe.module.boecase.service.ICaseKnowledgeService;
|
||||
import com.xboe.module.boecase.service.ICasesService;
|
||||
import com.xboe.module.boecase.entity.Cases;
|
||||
import com.xboe.module.boecase.entity.CaseDocumentLog;
|
||||
import com.xboe.common.utils.IDGenerator;
|
||||
import com.xboe.common.utils.StringUtil;
|
||||
import java.time.LocalDateTime;
|
||||
import com.xboe.module.boecase.vo.CaseDocumentLogVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* AI调用日志管理API
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping(value = "/xboe/m/boe/caseDocumentLog")
|
||||
public class CaseDocumentLogApi extends ApiBaseController {
|
||||
|
||||
@Resource
|
||||
private ICaseDocumentLogService caseDocumentLogService;
|
||||
|
||||
@Resource
|
||||
private ICaseKnowledgeService caseKnowledgeService;
|
||||
|
||||
@Resource
|
||||
private ICasesService casesService;
|
||||
|
||||
/**
|
||||
* AI调用日志分页查询
|
||||
*
|
||||
* @param queryDto 查询条件
|
||||
* @return 分页结果
|
||||
*/
|
||||
@PostMapping("/pageQuery")
|
||||
@AutoLog(module = "AI调用日志", action = "分页查询", info = "AI调用日志分页查询")
|
||||
public JsonResponse<PageList<CaseDocumentLogVo>> pageQuery(@RequestBody CaseDocumentLogQueryDto queryDto) {
|
||||
try {
|
||||
PageList<CaseDocumentLogVo> result = caseDocumentLogService.pageQuery(
|
||||
queryDto.getPageIndex(),
|
||||
queryDto.getPageSize(),
|
||||
queryDto
|
||||
);
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("AI调用日志分页查询失败", e);
|
||||
return error("查询失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空日志(根据筛选条件)
|
||||
*
|
||||
* @param queryDto 查询条件
|
||||
* @return 删除结果
|
||||
*/
|
||||
@PostMapping("/clearLogs")
|
||||
@AutoLog(module = "AI调用日志", action = "清空日志", info = "AI调用日志清空操作")
|
||||
public JsonResponse<Integer> clearLogs(@RequestBody CaseDocumentLogQueryDto queryDto) {
|
||||
try {
|
||||
int deletedCount = caseDocumentLogService.clearLogsByCondition(queryDto);
|
||||
return success(deletedCount);
|
||||
} catch (Exception e) {
|
||||
log.error("AI调用日志清空失败", e);
|
||||
return error("清空失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试AI调用
|
||||
*
|
||||
* @param request 重试请求参数
|
||||
* @return 重试结果
|
||||
*/
|
||||
@PostMapping("/retry")
|
||||
@AutoLog(module = "AI调用日志", action = "重试调用", info = "AI调用日志重试操作")
|
||||
public JsonResponse<Boolean> retry(@RequestBody RetryRequest request) {
|
||||
try {
|
||||
boolean result = caseDocumentLogService.retryByLogId(request.getLogId());
|
||||
return success(result);
|
||||
} catch (Exception e) {
|
||||
log.error("AI调用重试失败", e);
|
||||
return error("重试失败", e.getMessage());
|
||||
}
|
||||
// 先走挡板
|
||||
// return success(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据案例ID上传案例文档到知识库
|
||||
*
|
||||
* @param request 上传请求参数
|
||||
* @return 上传结果
|
||||
*/
|
||||
@PostMapping("/uploadCaseByID")
|
||||
@AutoLog(module = "案例文档管理", action = "根据案例ID上传文档", info = "根据案例ID查询案例信息并上传文档到知识库")
|
||||
public JsonResponse<Boolean> uploadCaseById(@RequestBody UploadCaseRequest request) {
|
||||
try {
|
||||
String caseId = request.getCaseId();
|
||||
if (StringUtil.isBlank(caseId)) {
|
||||
return badRequest("案例ID不能为空");
|
||||
}
|
||||
|
||||
// 查询案例信息
|
||||
Cases caseInfo = casesService.selectById(caseId, false);
|
||||
if (caseInfo == null || caseInfo.getDeleted()) {
|
||||
return badRequest("案例不存在或已删除");
|
||||
}
|
||||
|
||||
log.info("开始上传案例文档到知识库,案例ID: {}, 案例标题: {}", caseId, caseInfo.getTitle());
|
||||
|
||||
// 调用ICaseKnowledgeService的uploadCaseDocument方法
|
||||
boolean result = caseKnowledgeService.uploadCaseDocument(caseId);
|
||||
|
||||
if (result) {
|
||||
log.info("案例文档上传成功,案例ID: {}", caseId);
|
||||
return success(result, "案例文档上传成功");
|
||||
} else {
|
||||
log.warn("案例文档上传失败,案例ID: {}", caseId);
|
||||
return success(result, "案例文档上传失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("根据案例ID上传文档失败", e);
|
||||
return error("上传失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 直接创建CaseDocumentLog数据
|
||||
*
|
||||
* @param logData 日志数据
|
||||
* @return 创建结果
|
||||
*/
|
||||
@PostMapping("/createLog")
|
||||
@AutoLog(module = "案例文档日志", action = "创建日志记录", info = "直接创建一条CaseDocumentLog数据")
|
||||
public JsonResponse<String> createLog(@RequestBody CaseDocumentLog logData) {
|
||||
try {
|
||||
// 参数校验
|
||||
if (StringUtil.isBlank(logData.getCaseId())) {
|
||||
return badRequest("案例ID不能为空");
|
||||
}
|
||||
if (StringUtil.isBlank(logData.getOptType())) {
|
||||
return badRequest("操作类型不能为空");
|
||||
}
|
||||
|
||||
// 设置必要的默认值
|
||||
if (StringUtil.isBlank(logData.getId())) {
|
||||
logData.setId(IDGenerator.generate());
|
||||
}
|
||||
if (logData.getOptTime() == null) {
|
||||
logData.setOptTime(LocalDateTime.now());
|
||||
}
|
||||
if (logData.getOptStatus() == null) {
|
||||
logData.setOptStatus(0); // 默认为调用中
|
||||
}
|
||||
if (logData.getDeleted() == null) {
|
||||
logData.setDeleted(false);
|
||||
}
|
||||
|
||||
// 如果提供了案例ID但没有案例标题,尝试查询案例信息补充标题
|
||||
if (StringUtil.isBlank(logData.getCaseTitle()) && StringUtil.isNotBlank(logData.getCaseId())) {
|
||||
try {
|
||||
Cases caseInfo = casesService.selectById(logData.getCaseId(), false);
|
||||
if (caseInfo != null) {
|
||||
logData.setCaseTitle(caseInfo.getTitle());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.warn("查询案例标题失败,案例ID: {}", logData.getCaseId(), e);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("创建CaseDocumentLog记录,案例ID: {}, 操作类型: {}",
|
||||
logData.getCaseId(), logData.getOptType());
|
||||
|
||||
// 保存日志记录
|
||||
caseDocumentLogService.save(logData);
|
||||
|
||||
log.info("CaseDocumentLog记录创建成功,日志ID: {}", logData.getId());
|
||||
return success(logData.getId(), "日志记录创建成功");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("创建CaseDocumentLog记录失败", e);
|
||||
return error("创建失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 文档上传回调接口
|
||||
*
|
||||
* @param request 回调请求参数
|
||||
* @return 回调结果
|
||||
*/
|
||||
@PostMapping("/uploadCallback")
|
||||
@AutoLog(module = "AI调用日志", action = "文档上传回调", info = "文档上传回调接口")
|
||||
public CallbackResponse uploadCallback(@RequestBody CallbackRequest request) {
|
||||
try {
|
||||
log.info("收到文档上传回调,taskId: {}, fileStatus: {}, message: {}",
|
||||
request.getTaskId(), request.getFileStatus(), request.getMessage());
|
||||
|
||||
boolean result = caseKnowledgeService.handleUploadCallback(
|
||||
request.getTaskId(),
|
||||
request.getMessage(),
|
||||
request.getFileStatus()
|
||||
);
|
||||
|
||||
CallbackResponse response = new CallbackResponse();
|
||||
response.setSuccess(result);
|
||||
response.setCode(result ? 0 : -1);
|
||||
response.setMessage(result ? "回调处理成功" : "回调处理失败");
|
||||
|
||||
return response;
|
||||
} catch (Exception e) {
|
||||
log.error("文档上传回调处理失败", e);
|
||||
|
||||
CallbackResponse response = new CallbackResponse();
|
||||
response.setSuccess(false);
|
||||
response.setCode(-1);
|
||||
response.setMessage("回调处理异常: " + e.getMessage());
|
||||
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调请求参数
|
||||
*/
|
||||
public static class CallbackRequest {
|
||||
private String taskId;
|
||||
private String message;
|
||||
private String fileStatus;
|
||||
|
||||
public String getTaskId() {
|
||||
return taskId;
|
||||
}
|
||||
|
||||
public void setTaskId(String taskId) {
|
||||
this.taskId = taskId;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public String getFileStatus() {
|
||||
return fileStatus;
|
||||
}
|
||||
|
||||
public void setFileStatus(String fileStatus) {
|
||||
this.fileStatus = fileStatus;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 回调响应参数
|
||||
*/
|
||||
public static class CallbackResponse {
|
||||
private boolean success;
|
||||
private int code;
|
||||
private String message;
|
||||
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public int getCode() {
|
||||
return code;
|
||||
}
|
||||
|
||||
public void setCode(int code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 上传案例请求参数
|
||||
*/
|
||||
public static class UploadCaseRequest {
|
||||
private String caseId;
|
||||
|
||||
public String getCaseId() {
|
||||
return caseId;
|
||||
}
|
||||
|
||||
public void setCaseId(String caseId) {
|
||||
this.caseId = caseId;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 重试请求参数
|
||||
*/
|
||||
public static class RetryRequest {
|
||||
private String logId;
|
||||
|
||||
public String getLogId() {
|
||||
return logId;
|
||||
}
|
||||
|
||||
public void setLogId(String logId) {
|
||||
this.logId = logId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.xboe.module.boecase.api;
|
||||
|
||||
import com.xboe.module.boecase.task.CaseUploadTask;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
/**
|
||||
* 案例上传任务API
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/xboe/m/boe/caseUpload")
|
||||
public class CaseUploadTaskApi {
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
/**
|
||||
* 清除处理位置标记,使下次任务从头开始执行
|
||||
*/
|
||||
@PostMapping("/reset")
|
||||
public void resetLastProcessedId() {
|
||||
stringRedisTemplate.delete(CaseUploadTask.CASE_UPLOAD_LAST_ID_KEY);
|
||||
log.info("已清除上次处理位置标记");
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除处理位置标记,使下次任务从头开始执行
|
||||
*/
|
||||
@PostMapping("/reload/reset")
|
||||
public void resetReloadProcessedId() {
|
||||
stringRedisTemplate.delete(CaseUploadTask.CASE_RELOAD_LAST_ID_KEY);
|
||||
log.info("已清除上次处理位置标记");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.xboe.module.boecase.async;
|
||||
|
||||
import com.xboe.enums.CaseDocumentLogOptTypeEnum;
|
||||
import com.xboe.module.boecase.entity.Cases;
|
||||
import com.xboe.module.boecase.service.ICaseKnowledgeService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CaseAiDocumentAsyncHandler {
|
||||
|
||||
private final AtomicInteger currentTaskCount = new AtomicInteger(0);
|
||||
|
||||
/**
|
||||
* 限流,默认QPS 40
|
||||
*/
|
||||
private final TokenBucketRateLimiter rateLimiter = new TokenBucketRateLimiter(40);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("aiDocExecutor")
|
||||
private ThreadPoolTaskExecutor aiDocExecutor;
|
||||
|
||||
@Autowired
|
||||
private ICaseKnowledgeService caseKnowledgeService;
|
||||
|
||||
public void process(CaseDocumentLogOptTypeEnum optTypeEnum, Cases... caseList) {
|
||||
for (Cases cases : caseList) {
|
||||
// 控制并发数量
|
||||
while (currentTaskCount.get() >= 5) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
currentTaskCount.incrementAndGet();
|
||||
|
||||
aiDocExecutor.submit(() -> {
|
||||
try {
|
||||
// 限流
|
||||
rateLimiter.acquire();
|
||||
processCases(cases, optTypeEnum);
|
||||
} finally {
|
||||
currentTaskCount.decrementAndGet();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void processCases(Cases cases, CaseDocumentLogOptTypeEnum optTypeEnum) {
|
||||
try {
|
||||
switch (optTypeEnum) {
|
||||
case UPDATE:
|
||||
caseKnowledgeService.updateCaseDocument(cases);
|
||||
break;
|
||||
case DELETE:
|
||||
caseKnowledgeService.deleteCaseDocument(cases);
|
||||
break;
|
||||
case CREATE:
|
||||
default:
|
||||
caseKnowledgeService.uploadCaseDocument(cases);
|
||||
break;
|
||||
}
|
||||
log.info("处理案例成功,caseId: {}, 操作类型: {}", cases.getId(), optTypeEnum.getDesc());
|
||||
} catch (Exception e) {
|
||||
log.error("处理案例失败,caseId: {}, 操作类型: {}", cases.getId(), optTypeEnum.getDesc(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.xboe.module.boecase.async;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* 令牌桶限流算法实现
|
||||
*/
|
||||
public class TokenBucketRateLimiter {
|
||||
|
||||
private final double permitsPerSecond; // 每秒生成的令牌数(即 TPS)
|
||||
private final AtomicLong nextFreeTicketMicros = new AtomicLong(0); // 下一个令牌可用的时间(微秒)
|
||||
private final AtomicLong storedPermits = new AtomicLong(0); // 当前桶中存储的令牌数(本简化版不支持突发,可省略)
|
||||
private static final long MICROSECONDS_PER_SECOND = 1_000_000L;
|
||||
|
||||
public TokenBucketRateLimiter(double permitsPerSecond) {
|
||||
this.permitsPerSecond = permitsPerSecond;
|
||||
this.nextFreeTicketMicros.set(System.nanoTime() / 1000); // 初始化为当前时间(微秒)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个令牌,阻塞直到可用
|
||||
*/
|
||||
public void acquire() {
|
||||
long waitMicros = reserve(1);
|
||||
if (waitMicros > 0) {
|
||||
try {
|
||||
long waitNanos = waitMicros * 1000; // 转为纳秒
|
||||
TimeUnit.NANOSECONDS.sleep(waitNanos);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预留 1 个令牌,返回需要等待的微秒数
|
||||
*/
|
||||
private long reserve(int permits) {
|
||||
long nowMicros = System.nanoTime() / 1000;
|
||||
long nextFreeTicket = nextFreeTicketMicros.get();
|
||||
long waitMicros = Math.max(0, nextFreeTicket - nowMicros);
|
||||
|
||||
long newNextFreeTicket = nowMicros + waitMicros + (long) (permits * MICROSECONDS_PER_SECOND / permitsPerSecond);
|
||||
while (!nextFreeTicketMicros.compareAndSet(nextFreeTicket, newNextFreeTicket)) {
|
||||
// CAS 失败,说明其他线程修改了时间,重试
|
||||
nowMicros = System.nanoTime() / 1000;
|
||||
nextFreeTicket = nextFreeTicketMicros.get();
|
||||
waitMicros = Math.max(0, nextFreeTicket - nowMicros);
|
||||
newNextFreeTicket = nowMicros + waitMicros + (long) (permits * MICROSECONDS_PER_SECOND / permitsPerSecond);
|
||||
}
|
||||
|
||||
return waitMicros;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.xboe.module.boecase.dao;
|
||||
|
||||
import com.xboe.core.orm.BaseDao;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.module.boecase.entity.CaseAiConversations;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* 案例AI会话信息DAO
|
||||
*/
|
||||
@Repository
|
||||
public class CaseAiConversationsDao extends BaseDao<CaseAiConversations> {
|
||||
|
||||
/**
|
||||
* 根据主键ID查询AI会话ID
|
||||
* @param conversationId 主键ID
|
||||
* @return AI会话ID
|
||||
*/
|
||||
public String findAiConversationIdById(String conversationId) {
|
||||
CaseAiConversations conversation = this.getGenericDao().findOne(CaseAiConversations.class,
|
||||
FieldFilters.eq("ai_conversation_id", conversationId));
|
||||
return conversation != null ? conversation.getAiConversationId() : conversationId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.xboe.module.boecase.dao;
|
||||
|
||||
import com.xboe.core.orm.BaseDao;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.module.boecase.entity.CaseDocumentLog;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* AI调用日志DAO
|
||||
*/
|
||||
@Repository
|
||||
@Slf4j
|
||||
public class CaseDocumentLogDao extends BaseDao<CaseDocumentLog> {
|
||||
|
||||
/**
|
||||
* 根据taskId查询文档日志
|
||||
* @param taskId 任务ID
|
||||
* @return 文档日志
|
||||
*/
|
||||
public CaseDocumentLog findByTaskId(String taskId) {
|
||||
return this.getGenericDao().findOne(CaseDocumentLog.class,
|
||||
FieldFilters.eq("taskId", taskId));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.xboe.module.boecase.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* AI对话入参
|
||||
*/
|
||||
@Data
|
||||
public class CaseAiChatDto {
|
||||
|
||||
/**
|
||||
* 对话id
|
||||
* 如果是新对话,传空
|
||||
*/
|
||||
private String conversationId;
|
||||
|
||||
/**
|
||||
* 提问内容
|
||||
*/
|
||||
private String query;
|
||||
|
||||
/**
|
||||
* 是否开启思考
|
||||
* 0-否 1-是
|
||||
*/
|
||||
private Integer enableThinking;
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.xboe.module.boecase.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CaseAiMsgLikeDto {
|
||||
/**
|
||||
* 文档id
|
||||
*/
|
||||
private String docId;
|
||||
|
||||
/**
|
||||
* 点赞状态:
|
||||
* -1 踩
|
||||
* 1 赞
|
||||
* 0/null 无操作
|
||||
*/
|
||||
private String likeStatus;
|
||||
|
||||
/**
|
||||
* 反馈
|
||||
*/
|
||||
private String feedback;
|
||||
|
||||
/**
|
||||
* 操作
|
||||
* true: 点踩
|
||||
* false: 反馈
|
||||
* 为空:其他情况
|
||||
*/
|
||||
private Boolean operation;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
package com.xboe.module.boecase.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI调用日志查询条件DTO
|
||||
*/
|
||||
@Data
|
||||
public class CaseDocumentLogQueryDto extends PageDto {
|
||||
|
||||
/**
|
||||
* 案例标题(模糊查询)
|
||||
*/
|
||||
private String caseTitle;
|
||||
|
||||
/**
|
||||
* 操作类型(create-新增,delete-删除,update-更改)
|
||||
*/
|
||||
private String optType;
|
||||
|
||||
/**
|
||||
* 调用时间开始
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime optTimeStart;
|
||||
|
||||
/**
|
||||
* 调用时间结束
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime optTimeEnd;
|
||||
|
||||
/**
|
||||
* 接口调用状态
|
||||
* 0-调用中, 1-调用成功, 2-调用失败
|
||||
*/
|
||||
private Integer optStatus;
|
||||
|
||||
/**
|
||||
* 业务处理状态
|
||||
* 1-处理成功, 2-处理失败
|
||||
*/
|
||||
private Integer caseStatus;
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.xboe.module.boecase.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
public class EsFieldDTO {
|
||||
|
||||
/**
|
||||
* 字段名称
|
||||
*/
|
||||
private String fieldName;
|
||||
|
||||
/**
|
||||
* 字段属性
|
||||
*/
|
||||
private Properties properties;
|
||||
|
||||
public Map<String, Object> getIndexProperties() {
|
||||
Map<String, Object> indexProperties = new HashMap<>();
|
||||
if (properties != null) {
|
||||
indexProperties.put("type", properties.type);
|
||||
if (properties.index != null) {
|
||||
indexProperties.put("index", properties.index);
|
||||
}
|
||||
if (StringUtils.isNotBlank(properties.analyzer)) {
|
||||
indexProperties.put("analyzer", properties.analyzer);
|
||||
}
|
||||
if (StringUtils.isNotBlank(properties.searchAnalyzer)) {
|
||||
indexProperties.put("search_analyzer", properties.searchAnalyzer);
|
||||
}
|
||||
}
|
||||
return indexProperties;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Properties {
|
||||
private String type;
|
||||
|
||||
private Boolean index;
|
||||
|
||||
private String analyzer;
|
||||
|
||||
private String searchAnalyzer;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.xboe.module.boecase.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GetCaseAiMsgDto {
|
||||
/**
|
||||
* 会话Id
|
||||
*/
|
||||
private String conversationId;
|
||||
|
||||
/**
|
||||
* ES DocId
|
||||
*/
|
||||
private String docId;
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
package com.xboe.module.boecase.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.xboe.module.boecase.vo.CaseReferVo;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI聊天会话数据实体
|
||||
* 纯数据容器,不与数据库交互
|
||||
*
|
||||
* @author AI Assistant
|
||||
*/
|
||||
@Data
|
||||
@Slf4j
|
||||
public class AiChatConversationData {
|
||||
|
||||
/**
|
||||
* 会话ID
|
||||
*/
|
||||
private String conversationId;
|
||||
|
||||
/**
|
||||
* 用户提问内容
|
||||
*/
|
||||
private String query;
|
||||
|
||||
/**
|
||||
* AI回答内容(使用StringBuilder收集流式数据)
|
||||
*/
|
||||
private StringBuilder answer = new StringBuilder();
|
||||
|
||||
/**
|
||||
* 状态
|
||||
* 0-正常
|
||||
* 1-系统错误
|
||||
* 2-AIoT平台错误
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 案例引用列表
|
||||
*/
|
||||
private List<CaseReferVo> caseRefers = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 建议列表
|
||||
*/
|
||||
private List<String> suggestions = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* 用户点赞状态
|
||||
* -1: 踩
|
||||
* 1:赞
|
||||
* 0/null 无操作
|
||||
*/
|
||||
private String likeStatus;
|
||||
|
||||
/**
|
||||
* 用户踩的时候, 可以填写反馈意见
|
||||
* 反馈意见
|
||||
*/
|
||||
private String feedback;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 用户名称
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 消息时间戳
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 消息时间戳
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime timestamp;
|
||||
|
||||
/**
|
||||
* 聊天时长(秒)
|
||||
*/
|
||||
private Integer durationSeconds;
|
||||
|
||||
// ================== 构造函数 ==================
|
||||
|
||||
public AiChatConversationData() {
|
||||
this.startTime = LocalDateTime.now();
|
||||
}
|
||||
|
||||
// ================== 便捷方法 ==================
|
||||
|
||||
/**
|
||||
* 获取回答内容的字符串形式
|
||||
*/
|
||||
public String getAnswerAsString() {
|
||||
return this.answer.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 追加回答内容
|
||||
*/
|
||||
public void appendAnswer(String content) {
|
||||
if (content != null) {
|
||||
this.answer.append(content);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加案例引用
|
||||
*/
|
||||
public void addCaseRefer(CaseReferVo caseRefer) {
|
||||
if (caseRefer != null) {
|
||||
this.caseRefers.add(caseRefer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加建议
|
||||
*/
|
||||
public void addSuggestion(String suggestion) {
|
||||
if (suggestion != null && !suggestion.trim().isEmpty()) {
|
||||
this.suggestions.add(suggestion);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.xboe.module.boecase.entity;
|
||||
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.orm.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* 案例AI会话信息表
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = SysConstant.TABLE_PRE + "case_ai_conversations")
|
||||
public class CaseAiConversations extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 会话ID(由AI平台提供)
|
||||
*/
|
||||
@Column(name = "ai_conversation_id", length = 100)
|
||||
private String aiConversationId;
|
||||
|
||||
/**
|
||||
* 会话名称
|
||||
*/
|
||||
@Column(name = "conversation_name", length = 200)
|
||||
private String conversationName;
|
||||
|
||||
/**
|
||||
* 会话对应用户ID
|
||||
*/
|
||||
@Column(name = "conversation_user", length = 50)
|
||||
private String conversationUser;
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package com.xboe.module.boecase.entity;
|
||||
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.orm.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 案例文档日志信息表
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = SysConstant.TABLE_PRE + "case_document_log")
|
||||
public class CaseDocumentLog extends BaseEntity {
|
||||
|
||||
/**
|
||||
* 任务ID
|
||||
*/
|
||||
@Column(name = "task_id", length = 20)
|
||||
private String taskId;
|
||||
|
||||
/**
|
||||
* 案例id
|
||||
*/
|
||||
@Column(name = "case_id", length = 20)
|
||||
private String caseId;
|
||||
|
||||
/**
|
||||
* 案例标题
|
||||
*/
|
||||
@Column(name = "case_title", length = 200)
|
||||
private String caseTitle;
|
||||
|
||||
/**
|
||||
* 操作类型
|
||||
*/
|
||||
@Column(name = "opt_type")
|
||||
private String optType;
|
||||
|
||||
/**
|
||||
* 请求地址
|
||||
*/
|
||||
@Column(name = "request_url", length = 500)
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
@Column(name = "request_body", length = 4000)
|
||||
private String requestBody;
|
||||
|
||||
/**
|
||||
* 响应参数
|
||||
*/
|
||||
@Column(name = "response_body", length = 4000)
|
||||
private String responseBody;
|
||||
|
||||
/**
|
||||
* 调用时间
|
||||
*/
|
||||
@Column(name = "opt_time")
|
||||
private LocalDateTime optTime;
|
||||
|
||||
/**
|
||||
* 接口运行状态
|
||||
* 0-运行中, 1-运行完毕
|
||||
*/
|
||||
@Column(name = "run_status")
|
||||
private Integer runStatus;
|
||||
|
||||
/**
|
||||
* 接口调用状态
|
||||
* 0-调用中, 1-调用成功, 2-调用失败
|
||||
*/
|
||||
@Column(name = "opt_status")
|
||||
private Integer optStatus;
|
||||
|
||||
/**
|
||||
* 业务处理状态
|
||||
* 1-处理成功, 2-处理失败
|
||||
*/
|
||||
@Column(name = "case_status")
|
||||
private Integer caseStatus;
|
||||
|
||||
/**
|
||||
* 执行时间(ms)
|
||||
*/
|
||||
@Column(name = "execute_duration")
|
||||
private Long executeDuration;
|
||||
|
||||
/**
|
||||
* 元数据处理状态
|
||||
* 0-未处理
|
||||
* 1-已处理
|
||||
*/
|
||||
@Column(name = "metadata_status")
|
||||
private Integer metadataStatus;
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.xboe.module.boecase.mq;
|
||||
|
||||
|
||||
import com.xboe.module.boecase.service.ICaseAiChatService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jms.annotation.JmsListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
public class BroadcastMessageConsumer {
|
||||
|
||||
@Autowired
|
||||
private ICaseAiChatService iCaseAiChatService;
|
||||
|
||||
/**
|
||||
* 接收会话终止广播消息
|
||||
*
|
||||
* @param conversationId 会话ID
|
||||
*/
|
||||
@JmsListener(destination = "${activemq.topic.name}")
|
||||
public void receiveSessionTerminationBroadcastMessage(String conversationId) {
|
||||
log.info("收到会话终止广播消息:{}", conversationId);
|
||||
iCaseAiChatService.eventSourceCancel(conversationId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package com.xboe.module.boecase.properties;
|
||||
|
||||
import lombok.Data;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 案例专家AI相关配置项
|
||||
*/
|
||||
@ConfigurationProperties(prefix = "xboe.case.ai")
|
||||
@Data
|
||||
public class CaseAiProperties {
|
||||
|
||||
/**
|
||||
* 接口地址
|
||||
*/
|
||||
private String baseUrl;
|
||||
|
||||
/**
|
||||
* appKey
|
||||
*/
|
||||
private String appKey;
|
||||
|
||||
/**
|
||||
* appSecret
|
||||
*/
|
||||
private String secretKey;
|
||||
|
||||
/**
|
||||
* ai接口的apiCode
|
||||
*/
|
||||
private String aiApiCode;
|
||||
|
||||
/**
|
||||
* 对话接口的apiCode
|
||||
*/
|
||||
private String chatApiCode;
|
||||
|
||||
/**
|
||||
* 案例知识库id
|
||||
*/
|
||||
private String caseKnowledgeId;
|
||||
|
||||
/**
|
||||
* 默认上传用户
|
||||
* 当获取不到当前登录用户信息时会取这个
|
||||
*/
|
||||
private String defaultUploadUser;
|
||||
|
||||
/**
|
||||
* 案例详情页面地址
|
||||
*/
|
||||
private String caseDetailUrlBase;
|
||||
|
||||
/**
|
||||
* 文件上传是否使用回调接口
|
||||
*/
|
||||
private boolean fileUploadUseCallback;
|
||||
|
||||
/**
|
||||
* 文档上传回调接口地址
|
||||
*/
|
||||
private String fileUploadCallbackUrl;
|
||||
|
||||
/**
|
||||
* 是否启用白名单
|
||||
*/
|
||||
private boolean useWhiteList;
|
||||
|
||||
/**
|
||||
* 白名单用户列表
|
||||
*/
|
||||
private List<String> whiteUserCodeList;
|
||||
|
||||
/**
|
||||
* AI处理失败告警邮件收件人列表
|
||||
*/
|
||||
private List<String> alertEmailRecipients;
|
||||
|
||||
/**
|
||||
* 是否发送AI对话记录到邮箱
|
||||
*/
|
||||
private boolean aiChatDataSendEmail;
|
||||
|
||||
/**
|
||||
* AI对话记录保存根路径
|
||||
*/
|
||||
private String aiChatRootPath;
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.xboe.module.boecase.service;
|
||||
|
||||
/**
|
||||
* 获取accesstoken
|
||||
*/
|
||||
public interface IAiAccessTokenService {
|
||||
|
||||
/**
|
||||
* 获取accesstoken
|
||||
* @return
|
||||
*/
|
||||
String getAccessToken();
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package com.xboe.module.boecase.service;
|
||||
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.module.boecase.dto.CaseAiChatDto;
|
||||
import com.xboe.module.boecase.dto.CaseAiMsgLikeDto;
|
||||
import com.xboe.module.boecase.dto.GetCaseAiMsgDto;
|
||||
import com.xboe.module.boecase.entity.CaseAiConversations;
|
||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI案例对话
|
||||
*/
|
||||
public interface ICaseAiChatService {
|
||||
|
||||
/**
|
||||
* 聊天
|
||||
*
|
||||
* @param caseAiChatDto
|
||||
* @param currentUser
|
||||
* @return
|
||||
*/
|
||||
SseEmitter chat(CaseAiChatDto caseAiChatDto, CurrentUser currentUser);
|
||||
|
||||
/**
|
||||
* 创建新的AI对话会话
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param conversationName 对话名称
|
||||
* @return 创建的会话信息
|
||||
*/
|
||||
CaseAiConversations createNewConversation(String userId, String conversationName);
|
||||
|
||||
/**
|
||||
* 根据conversationId查看会话内消息记录
|
||||
*
|
||||
* @param conversationId 会话ID
|
||||
* @return 消息记录列表
|
||||
*/
|
||||
List<CaseAiMessageVo> getConversationMessages(String conversationId);
|
||||
|
||||
/**
|
||||
* 导出会话记录为Excel
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param response
|
||||
*/
|
||||
void getConversationExcel(LocalDateTime startTime, LocalDateTime endTime, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 导出会话记录为Excel
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
*/
|
||||
void downloadConversationExcel(LocalDateTime startTime, LocalDateTime endTime);
|
||||
|
||||
/**
|
||||
* 停止当前聊天输出
|
||||
*
|
||||
* @param conversationId 会话ID
|
||||
* @return 是否成功停止
|
||||
*/
|
||||
boolean stopChatOutput(String conversationId);
|
||||
|
||||
/**
|
||||
* 取消eventSource
|
||||
*
|
||||
* @param conversationId 会话ID
|
||||
*/
|
||||
void eventSourceCancel(String conversationId);
|
||||
|
||||
/**
|
||||
* 消息反馈保存
|
||||
* likeStatus: 踩/赞
|
||||
* feedBack: 反馈消息内容
|
||||
*
|
||||
* @param caseAiMsgLikeDto
|
||||
*/
|
||||
boolean msgFeedback(CaseAiMsgLikeDto caseAiMsgLikeDto);
|
||||
|
||||
/**
|
||||
* 获取消息
|
||||
*
|
||||
* @param getCaseAiMsgDto
|
||||
*/
|
||||
List<CaseAiMessageVo> getCaseAiMsg(GetCaseAiMsgDto getCaseAiMsgDto);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.xboe.module.boecase.service;
|
||||
|
||||
/**
|
||||
* 案例AI权限服务接口
|
||||
*/
|
||||
public interface ICaseAiPermissionService {
|
||||
|
||||
/**
|
||||
* 判断指定用户是否显示"案例专家"功能入口
|
||||
* @param userCode 用户编码
|
||||
* @return 是否显示功能入口
|
||||
*/
|
||||
boolean shouldShowCaseAiEntrance(String userCode);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.xboe.module.boecase.service;
|
||||
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.module.boecase.dto.CaseDocumentLogQueryDto;
|
||||
import com.xboe.module.boecase.entity.CaseDocumentLog;
|
||||
import com.xboe.module.boecase.vo.CaseDocumentLogVo;
|
||||
|
||||
/**
|
||||
* AI调用日志Service接口
|
||||
*/
|
||||
public interface ICaseDocumentLogService {
|
||||
|
||||
/**
|
||||
* 分页查询AI调用日志
|
||||
*
|
||||
* @param pageIndex 页码
|
||||
* @param pageSize 每页大小
|
||||
* @param queryDto 查询条件
|
||||
* @return 分页结果
|
||||
*/
|
||||
PageList<CaseDocumentLogVo> pageQuery(int pageIndex, int pageSize, CaseDocumentLogQueryDto queryDto);
|
||||
|
||||
/**
|
||||
* 根据查询条件清空日志
|
||||
* 仅删除当前筛选条件下的日志记录,非筛选范围内的日志不受影响
|
||||
*
|
||||
* @param queryDto 查询条件
|
||||
* @return 删除的记录数
|
||||
*/
|
||||
int clearLogsByCondition(CaseDocumentLogQueryDto queryDto);
|
||||
|
||||
/**
|
||||
* 根据logId重试AI调用
|
||||
* 查询原始日志数据,重试执行后添加新的日志记录
|
||||
*
|
||||
* @param logId 日志ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean retryByLogId(String logId);
|
||||
|
||||
/**
|
||||
* 保存日志记录
|
||||
*
|
||||
* @param log 日志对象
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean save(CaseDocumentLog log);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.xboe.module.boecase.service;
|
||||
|
||||
import com.xboe.module.boecase.entity.CaseDocumentLog;
|
||||
import com.xboe.module.boecase.entity.Cases;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* 案例-知识库
|
||||
*/
|
||||
public interface ICaseKnowledgeService {
|
||||
|
||||
/**
|
||||
* 上传案例文档
|
||||
*
|
||||
* @param caseId 案例ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean uploadCaseDocument(String caseId);
|
||||
|
||||
/**
|
||||
* 上传案例文档
|
||||
*
|
||||
* @param cases 案例
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean uploadCaseDocument(Cases cases);
|
||||
|
||||
/**
|
||||
* 删除案例文档
|
||||
*
|
||||
* @param caseId 案例ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteCaseDocument(String caseId);
|
||||
|
||||
/**
|
||||
* 删除案例文档
|
||||
*
|
||||
* @param cases 案例
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean deleteCaseDocument(Cases cases);
|
||||
|
||||
/**
|
||||
* 更新案例文档
|
||||
*
|
||||
* @param caseId 案例ID
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean retryCaseDocument(String caseId, CaseDocumentLog originalLog);
|
||||
|
||||
/**
|
||||
* 更新案例文档
|
||||
*
|
||||
* @param cases 案例
|
||||
* @return 是否成功
|
||||
*/
|
||||
boolean updateCaseDocument(Cases cases);
|
||||
|
||||
/**
|
||||
* 处理文档上传回调
|
||||
*
|
||||
* @param taskId 任务ID
|
||||
* @param message 回调信息
|
||||
* @param fileStatus 文件状态(vectored: 成功, failed: 失败)
|
||||
* @return 是否处理成功
|
||||
*/
|
||||
boolean handleUploadCallback(String taskId, String message, String fileStatus);
|
||||
|
||||
/**
|
||||
* 批量检查文件状态
|
||||
*/
|
||||
@Transactional(rollbackFor = Throwable.class)
|
||||
void batchCheckFileStatus();
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package com.xboe.module.boecase.service;
|
||||
|
||||
import com.xboe.module.boecase.entity.AiChatConversationData;
|
||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* es索引
|
||||
*/
|
||||
public interface IElasticSearchIndexService {
|
||||
|
||||
/**
|
||||
* 查看索引是否存在
|
||||
* @return
|
||||
*/
|
||||
boolean checkIndexExists();
|
||||
|
||||
/**
|
||||
* 创建索引
|
||||
*/
|
||||
boolean createIndex();
|
||||
|
||||
/**
|
||||
* 删除索引
|
||||
* @return
|
||||
*/
|
||||
boolean deleteIndex();
|
||||
|
||||
/**
|
||||
* 更新索引:添加索引字段
|
||||
* @param fieldName
|
||||
* @param fieldProperties
|
||||
* @return
|
||||
*/
|
||||
boolean updateIndex(String fieldName, Map<String, Object> fieldProperties);
|
||||
|
||||
/**
|
||||
* 新增数据
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
boolean createData(AiChatConversationData data);
|
||||
|
||||
/**
|
||||
* 查询数据
|
||||
* @param conversationId
|
||||
* @return
|
||||
*/
|
||||
List<CaseAiMessageVo> queryData(String conversationId);
|
||||
|
||||
/**
|
||||
* 更新数据
|
||||
* @param docId
|
||||
* @param data
|
||||
* @return
|
||||
*/
|
||||
boolean updateData(String docId, AiChatConversationData data);
|
||||
|
||||
/**
|
||||
* 通过docId查询数据
|
||||
*
|
||||
* @param docId ES docId
|
||||
* @return
|
||||
*/
|
||||
List<CaseAiMessageVo> queryDataByDocId(String docId);
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
package com.xboe.module.boecase.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xboe.common.utils.StringUtil;
|
||||
import com.xboe.module.boecase.properties.CaseAiProperties;
|
||||
import com.xboe.module.boecase.service.IAiAccessTokenService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@EnableConfigurationProperties({CaseAiProperties.class})
|
||||
@Service
|
||||
@Slf4j(topic = "caseAiChatLogger")
|
||||
public class AiAccessTokenServiceImpl implements IAiAccessTokenService {
|
||||
|
||||
private static final String ACCESS_TOKEN_CACHE_KEY = "case_ai_access_token";
|
||||
|
||||
@Autowired
|
||||
private CaseAiProperties caseAiProperties;
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
@Override
|
||||
public String getAccessToken() {
|
||||
// 1. 先从Redis缓存中获取
|
||||
String cachedToken = stringRedisTemplate.opsForValue().get(ACCESS_TOKEN_CACHE_KEY);
|
||||
if (StringUtil.isNotBlank(cachedToken)) {
|
||||
return cachedToken;
|
||||
}
|
||||
|
||||
// 2. 缓存中没有,重新获取
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
|
||||
String tokenUrl = caseAiProperties.getBaseUrl() + "/apigateway/secret/getAppAccessToken" +
|
||||
"?appKey=" + URLEncoder.encode(caseAiProperties.getAppKey(), StandardCharsets.UTF_8.name()) +
|
||||
"&secretKey=" + URLEncoder.encode(caseAiProperties.getSecretKey(), StandardCharsets.UTF_8.name());
|
||||
|
||||
HttpGet httpGet = new HttpGet(tokenUrl);
|
||||
|
||||
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
|
||||
|
||||
if (statusCode == 200) {
|
||||
JSONObject result = JSON.parseObject(responseBody);
|
||||
if (result.getIntValue("code") == 0 && result.getBooleanValue("success")) {
|
||||
JSONObject data = result.getJSONObject("data");
|
||||
String accessToken = data.getString("accessToken");
|
||||
Integer expiresIn = data.getInteger("expiresIn");
|
||||
if (expiresIn == null) {
|
||||
expiresIn = 7200;
|
||||
}
|
||||
|
||||
// 3. 存储到Redis,设置过期时间(提前5分钟过期)
|
||||
int cacheSeconds = Math.max(expiresIn - 300, 60);
|
||||
stringRedisTemplate.opsForValue().set(ACCESS_TOKEN_CACHE_KEY, accessToken,
|
||||
cacheSeconds, TimeUnit.SECONDS);
|
||||
|
||||
log.info("获取access_token成功,过期时间: {}秒", expiresIn);
|
||||
return accessToken;
|
||||
} else {
|
||||
log.error("获取access_token失败,接口返回失败,response: {}", responseBody);
|
||||
return null;
|
||||
}
|
||||
} else {
|
||||
log.error("获取access_token失败,HTTP请求失败,status: {}, response: {}",
|
||||
statusCode, responseBody);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取access_token异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,47 @@
|
||||
package com.xboe.module.boecase.service.impl;
|
||||
|
||||
import com.xboe.module.boecase.properties.CaseAiProperties;
|
||||
import com.xboe.module.boecase.service.ICaseAiPermissionService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 案例AI权限服务实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional
|
||||
public class CaseAiPermissionServiceImpl implements ICaseAiPermissionService {
|
||||
|
||||
@Autowired
|
||||
private CaseAiProperties caseAiProperties;
|
||||
|
||||
/**
|
||||
* 判断指定用户是否显示"案例专家"功能入口
|
||||
* @param userCode 用户编码
|
||||
* @return 是否显示功能入口
|
||||
*/
|
||||
@Override
|
||||
public boolean shouldShowCaseAiEntrance(String userCode) {
|
||||
log.info("判断用户[{}]是否显示案例专家功能入口", userCode);
|
||||
|
||||
// 如果不启用白名单,直接返回true
|
||||
if (!caseAiProperties.isUseWhiteList()) {
|
||||
log.info("未启用白名单,所有用户都显示功能入口");
|
||||
return true;
|
||||
}
|
||||
|
||||
// 启用白名单时,判断当前用户是否在白名单中
|
||||
List<String> whiteUserCodeList = caseAiProperties.getWhiteUserCodeList();
|
||||
log.info("白名单列表:{}", whiteUserCodeList);
|
||||
boolean isInWhiteList = whiteUserCodeList != null
|
||||
&& whiteUserCodeList.stream().anyMatch(userCode::equals);
|
||||
|
||||
log.info("用户[{}]{}在白名单中", userCode, isInWhiteList ? "" : "不");
|
||||
return isInWhiteList;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,307 @@
|
||||
package com.xboe.module.boecase.service.impl;
|
||||
|
||||
import com.xboe.common.utils.StringUtil;
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.core.orm.IFieldFilter;
|
||||
import com.xboe.core.orm.LikeMatchMode;
|
||||
import com.xboe.enums.CaseDocumentLogRunStatusEnum;
|
||||
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
|
||||
import com.xboe.module.boecase.dto.CaseDocumentLogQueryDto;
|
||||
import com.xboe.module.boecase.entity.CaseDocumentLog;
|
||||
import com.xboe.module.boecase.service.ICaseDocumentLogService;
|
||||
import com.xboe.module.boecase.service.ICaseKnowledgeService;
|
||||
import com.xboe.module.boecase.vo.CaseDocumentLogVo;
|
||||
import com.xboe.enums.CaseDocumentLogOptTypeEnum;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* AI调用日志Service实现类
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional
|
||||
public class CaseDocumentLogServiceImpl implements ICaseDocumentLogService {
|
||||
|
||||
@Resource
|
||||
private CaseDocumentLogDao caseDocumentLogDao;
|
||||
|
||||
@Resource
|
||||
private ICaseKnowledgeService caseKnowledgeService;
|
||||
|
||||
@Resource(name = "aiDocExecutor")
|
||||
private ThreadPoolTaskExecutor aiDocExecutor;
|
||||
|
||||
@Override
|
||||
public PageList<CaseDocumentLogVo> pageQuery(int pageIndex, int pageSize, CaseDocumentLogQueryDto queryDto) {
|
||||
// 构建查询条件
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
|
||||
// 运行状态过滤
|
||||
filters.add(FieldFilters.eq("runStatus", CaseDocumentLogRunStatusEnum.COMPLETED.getCode()));
|
||||
|
||||
// 案例标题模糊查询
|
||||
if (StringUtil.isNotBlank(queryDto.getCaseTitle())) {
|
||||
filters.add(FieldFilters.like("caseTitle", LikeMatchMode.ANYWHERE, queryDto.getCaseTitle()));
|
||||
}
|
||||
|
||||
// 操作类型精确查询
|
||||
if (StringUtil.isNotBlank(queryDto.getOptType())) {
|
||||
filters.add(FieldFilters.eq("optType", queryDto.getOptType()));
|
||||
}
|
||||
|
||||
// 调用时间区间查询
|
||||
if (queryDto.getOptTimeStart() != null) {
|
||||
filters.add(FieldFilters.ge("optTime", queryDto.getOptTimeStart()));
|
||||
}
|
||||
if (queryDto.getOptTimeEnd() != null) {
|
||||
// 将结束时间调整为当天的23:59:59
|
||||
LocalDateTime optTimeEnd = queryDto.getOptTimeEnd().withHour(23).withMinute(59).withSecond(59);
|
||||
filters.add(FieldFilters.le("optTime", optTimeEnd));
|
||||
}
|
||||
|
||||
// 接口调用状态
|
||||
if (queryDto.getOptStatus() != null) {
|
||||
filters.add(FieldFilters.eq("optStatus", queryDto.getOptStatus()));
|
||||
}
|
||||
|
||||
// 业务处理状态
|
||||
if (queryDto.getCaseStatus() != null) {
|
||||
filters.add(FieldFilters.eq("caseStatus", queryDto.getCaseStatus()));
|
||||
}
|
||||
|
||||
// 删除标识过滤
|
||||
filters.add(FieldFilters.eq("deleted", false));
|
||||
|
||||
// 按创建时间降序排序
|
||||
OrderCondition order = OrderCondition.desc("sysCreateTime");
|
||||
|
||||
// 执行分页查询
|
||||
PageList<CaseDocumentLog> pageResult = caseDocumentLogDao.getGenericDao()
|
||||
.findPage(pageIndex, pageSize, CaseDocumentLog.class, filters, order);
|
||||
|
||||
// 转换为VO对象
|
||||
List<CaseDocumentLogVo> voList = pageResult.getList().stream()
|
||||
.map(this::convertToVo)
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 构建返回结果
|
||||
PageList<CaseDocumentLogVo> result = new PageList<>();
|
||||
result.setList(voList);
|
||||
result.setCount(pageResult.getCount());
|
||||
result.setPageSize(pageResult.getPageSize());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int clearLogsByCondition(CaseDocumentLogQueryDto queryDto) {
|
||||
// 构建查询条件(与分页查询相同的逻辑)
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
|
||||
// 运行状态过滤
|
||||
filters.add(FieldFilters.eq("runStatus", CaseDocumentLogRunStatusEnum.COMPLETED.getCode()));
|
||||
|
||||
// 案例标题模糊查询
|
||||
if (StringUtil.isNotBlank(queryDto.getCaseTitle())) {
|
||||
filters.add(FieldFilters.like("caseTitle", LikeMatchMode.ANYWHERE, queryDto.getCaseTitle()));
|
||||
}
|
||||
|
||||
// 操作类型精确查询
|
||||
if (StringUtil.isNotBlank(queryDto.getOptType())) {
|
||||
filters.add(FieldFilters.eq("optType", queryDto.getOptType()));
|
||||
}
|
||||
|
||||
// 调用时间区间查询
|
||||
if (queryDto.getOptTimeStart() != null) {
|
||||
filters.add(FieldFilters.ge("optTime", queryDto.getOptTimeStart()));
|
||||
}
|
||||
if (queryDto.getOptTimeEnd() != null) {
|
||||
// 将结束时间调整为当天的23:59:59
|
||||
LocalDateTime optTimeEnd = queryDto.getOptTimeEnd().withHour(23).withMinute(59).withSecond(59);
|
||||
filters.add(FieldFilters.le("optTime", optTimeEnd));
|
||||
}
|
||||
|
||||
// 接口调用状态
|
||||
if (queryDto.getOptStatus() != null) {
|
||||
filters.add(FieldFilters.eq("optStatus", queryDto.getOptStatus()));
|
||||
}
|
||||
|
||||
// 业务处理状态
|
||||
if (queryDto.getCaseStatus() != null) {
|
||||
filters.add(FieldFilters.eq("caseStatus", queryDto.getCaseStatus()));
|
||||
}
|
||||
|
||||
// 删除标识过滤
|
||||
filters.add(FieldFilters.eq("deleted", false));
|
||||
|
||||
// 查询符合条件的所有记录
|
||||
IFieldFilter[] filtersArray = filters.toArray(new IFieldFilter[0]);
|
||||
List<CaseDocumentLog> logsToDelete = caseDocumentLogDao.getGenericDao()
|
||||
.findList(CaseDocumentLog.class, filtersArray);
|
||||
|
||||
if (logsToDelete.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 批量设置删除标识为true(逻辑删除)
|
||||
int deletedCount = 0;
|
||||
for (CaseDocumentLog log : logsToDelete) {
|
||||
log.setDeleted(true);
|
||||
caseDocumentLogDao.update(log);
|
||||
deletedCount++;
|
||||
}
|
||||
|
||||
log.info("清空日志操作完成,共删除{}条记录", deletedCount);
|
||||
return deletedCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean retryByLogId(String logId) {
|
||||
if (StringUtil.isBlank(logId)) {
|
||||
log.error("重试失败,logId不能为空");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 1. 根据logId查询原始日志数据
|
||||
CaseDocumentLog originalLog = caseDocumentLogDao.get(logId);
|
||||
if (originalLog == null || originalLog.getDeleted()) {
|
||||
log.error("重试失败,未找到有效的日志记录,logId: {}", logId);
|
||||
return false;
|
||||
}
|
||||
|
||||
log.info("开始异步重试AI调用,原始日志ID: {}, 案例标题: {}, 操作类型: {}",
|
||||
logId, originalLog.getCaseTitle(), originalLog.getOptType());
|
||||
|
||||
// 2. 使用线程池异步执行AI调用重试逻辑
|
||||
String optType = originalLog.getOptType();
|
||||
String caseId = originalLog.getCaseId();
|
||||
|
||||
aiDocExecutor.execute(() -> executeRetryLogic(optType, caseId, originalLog));
|
||||
|
||||
// 立即返回true表示重试请求已接受,具体结果通过日志异步处理
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行AI调用重试逻辑
|
||||
* @param optType 操作类型
|
||||
* @param caseId 案例ID
|
||||
*/
|
||||
private void executeRetryLogic(String optType, String caseId, CaseDocumentLog originalLog) {
|
||||
boolean retrySuccess = false;
|
||||
|
||||
try {
|
||||
if (StringUtil.isBlank(caseId)) {
|
||||
throw new IllegalArgumentException("案例ID不能为空");
|
||||
}
|
||||
|
||||
log.info("[异步任务] 正在执行AI调用重试,操作类型: {}, caseId: {}", optType, caseId);
|
||||
|
||||
// 根据操作类型执行对应的方法(这些方法内部会自动创建日志记录)
|
||||
if (CaseDocumentLogOptTypeEnum.CREATE.getCode().equals(optType)) {
|
||||
// 上传案例文档
|
||||
retrySuccess = caseKnowledgeService.uploadCaseDocument(caseId);
|
||||
log.info("[异步任务] 执行上传案例文档重试,caseId: {}, 结果: {}", caseId, retrySuccess);
|
||||
|
||||
} else if (CaseDocumentLogOptTypeEnum.DELETE.getCode().equals(optType)) {
|
||||
// 删除案例文档
|
||||
retrySuccess = caseKnowledgeService.deleteCaseDocument(caseId);
|
||||
log.info("[异步任务] 执行删除案例文档重试,caseId: {}, 结果: {}", caseId, retrySuccess);
|
||||
|
||||
} else if (CaseDocumentLogOptTypeEnum.UPDATE.getCode().equals(optType)) {
|
||||
// 更新案例文档
|
||||
retrySuccess = caseKnowledgeService.retryCaseDocument(caseId, originalLog);
|
||||
log.info("[异步任务] 执行更新案例文档重试,caseId: {}, 结果: {}", caseId, retrySuccess);
|
||||
|
||||
} else {
|
||||
throw new IllegalArgumentException("不支持的操作类型: " + optType);
|
||||
}
|
||||
|
||||
if (retrySuccess) {
|
||||
log.info("[异步任务] AI调用重试成功,操作类型: {}, caseId: {}", optType, caseId);
|
||||
} else {
|
||||
log.warn("[异步任务] AI调用重试失败,操作类型: {}, caseId: {}", optType, caseId);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("[异步任务] AI调用重试异常,操作类型: {}, caseId: {}",
|
||||
optType, caseId, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean save(CaseDocumentLog caseDocumentLog) {
|
||||
try {
|
||||
caseDocumentLogDao.save(caseDocumentLog);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("保存CaseDocumentLog失败", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 实体转换为VO
|
||||
*/
|
||||
private CaseDocumentLogVo convertToVo(CaseDocumentLog entity) {
|
||||
CaseDocumentLogVo vo = new CaseDocumentLogVo();
|
||||
BeanUtils.copyProperties(entity, vo);
|
||||
|
||||
// 操作类型转换为中文描述
|
||||
vo.setOptType(CaseDocumentLogOptTypeEnum.getDescByCode(entity.getOptType()));
|
||||
|
||||
// 接口调用状态转换
|
||||
vo.setOptStatusText(getOptStatusText(entity.getOptStatus()));
|
||||
|
||||
// 业务处理状态转换
|
||||
vo.setCaseStatusText(getCaseStatusText(entity.getCaseStatus()));
|
||||
|
||||
return vo;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取接口调用状态描述
|
||||
*/
|
||||
private String getOptStatusText(Integer optStatus) {
|
||||
if (optStatus == null) {
|
||||
return "";
|
||||
}
|
||||
switch (optStatus) {
|
||||
case 1:
|
||||
return "调用成功";
|
||||
case 2:
|
||||
return "调用失败";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取业务处理状态描述
|
||||
*/
|
||||
private String getCaseStatusText(Integer caseStatus) {
|
||||
if (caseStatus == null) {
|
||||
return "";
|
||||
}
|
||||
switch (caseStatus) {
|
||||
case 1:
|
||||
return "处理成功";
|
||||
case 2:
|
||||
return "处理失败";
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -19,7 +19,9 @@ import com.xboe.common.utils.IDGenerator;
|
||||
import com.xboe.common.utils.StringUtil;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.core.orm.*;
|
||||
import com.xboe.enums.CaseDocumentLogOptTypeEnum;
|
||||
import com.xboe.enums.CasesRankEnum;
|
||||
import com.xboe.module.boecase.async.CaseAiDocumentAsyncHandler;
|
||||
import com.xboe.module.boecase.dao.*;
|
||||
import com.xboe.module.boecase.dto.*;
|
||||
import com.xboe.module.boecase.entity.*;
|
||||
@@ -90,6 +92,9 @@ public class CasesServiceImpl implements ICasesService {
|
||||
@Resource
|
||||
private ThirdApi thirdApi;
|
||||
|
||||
@Autowired
|
||||
private CaseAiDocumentAsyncHandler caseAiDocumentAsyncHandler;
|
||||
|
||||
/**
|
||||
* 案例分页查询,用于门户的查询
|
||||
*/
|
||||
@@ -799,7 +804,11 @@ public class CasesServiceImpl implements ICasesService {
|
||||
*/
|
||||
@Override
|
||||
public void delete(String id) {
|
||||
Cases cases = casesDao.get(id);
|
||||
// 原删除
|
||||
casesDao.setDeleted(id);
|
||||
// 增加逻辑
|
||||
caseAiDocumentAsyncHandler.process(CaseDocumentLogOptTypeEnum.DELETE, cases);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -986,6 +995,8 @@ public class CasesServiceImpl implements ICasesService {
|
||||
cases.setMajorIds(majorIds);
|
||||
cases.setMajorType(stringBuffer.toString());
|
||||
casesDao.save(cases);
|
||||
// 增加逻辑
|
||||
caseAiDocumentAsyncHandler.process(CaseDocumentLogOptTypeEnum.CREATE, cases);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1009,6 +1020,8 @@ public class CasesServiceImpl implements ICasesService {
|
||||
cases.setMajorIds(majorIds);
|
||||
cases.setMajorType(stringBuffer.toString());
|
||||
casesDao.update(cases);
|
||||
// 增加逻辑
|
||||
caseAiDocumentAsyncHandler.process(CaseDocumentLogOptTypeEnum.UPDATE, cases);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,423 @@
|
||||
package com.xboe.module.boecase.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xboe.constants.CaseAiConstants;
|
||||
import com.xboe.module.boecase.entity.AiChatConversationData;
|
||||
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||
import com.xboe.module.boecase.vo.CaseReferVo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.elasticsearch.ElasticsearchException;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.action.support.master.AcknowledgedResponse;
|
||||
import org.elasticsearch.action.update.UpdateRequest;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.client.indices.CreateIndexRequest;
|
||||
import org.elasticsearch.client.indices.CreateIndexResponse;
|
||||
import org.elasticsearch.client.indices.GetIndexRequest;
|
||||
import org.elasticsearch.client.indices.PutMappingRequest;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.rest.RestStatus;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService {
|
||||
|
||||
@Autowired(required = false)
|
||||
private RestHighLevelClient elasticsearchClient;
|
||||
|
||||
@Override
|
||||
public boolean checkIndexExists() {
|
||||
if (elasticsearchClient == null) {
|
||||
log.error("ElasticSearch客户端未配置");
|
||||
return false;
|
||||
}
|
||||
// 检查索引是否存在
|
||||
GetIndexRequest getIndexRequest = new GetIndexRequest(CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
try {
|
||||
return elasticsearchClient.indices().exists(getIndexRequest, RequestOptions.DEFAULT);
|
||||
} catch (IOException e) {
|
||||
log.error("查询ElasticSearch索引时发生异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createIndex() {
|
||||
if (elasticsearchClient == null) {
|
||||
log.error("ElasticSearch客户端未配置");
|
||||
return false;
|
||||
}
|
||||
// 创建索引
|
||||
CreateIndexRequest createIndexRequest = new CreateIndexRequest(CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
|
||||
// 设置索引配置
|
||||
createIndexRequest.settings(Settings.builder()
|
||||
.put("index.number_of_shards", 1)
|
||||
.put("index.number_of_replicas", 0)
|
||||
.put("index.analysis.analyzer.ik_max_word.tokenizer", "ik_max_word")
|
||||
.put("index.analysis.analyzer.ik_smart.tokenizer", "ik_smart")
|
||||
);
|
||||
|
||||
// 设置字段映射
|
||||
String mapping = getAiChatMessagesMapping();
|
||||
createIndexRequest.mapping(mapping, XContentType.JSON);
|
||||
|
||||
// 执行创建索引请求
|
||||
CreateIndexResponse createIndexResponse = null;
|
||||
try {
|
||||
createIndexResponse = elasticsearchClient.indices()
|
||||
.create(createIndexRequest, RequestOptions.DEFAULT);
|
||||
} catch (IOException e) {
|
||||
log.error("创建ElasticSearch索引时发生异常", e);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (createIndexResponse.isAcknowledged()) {
|
||||
log.info("ElasticSearch索引 [{}] 创建成功", CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
return true;
|
||||
} else {
|
||||
log.error("ElasticSearch索引 [{}] 创建可能失败,响应未确认", CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean deleteIndex() {
|
||||
if (elasticsearchClient == null) {
|
||||
log.error("ElasticSearch客户端未配置");
|
||||
return false;
|
||||
}
|
||||
// 执行删除索引请求
|
||||
DeleteIndexRequest deleteRequest = new DeleteIndexRequest(CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
try {
|
||||
AcknowledgedResponse deleteResponse = elasticsearchClient.indices().delete(deleteRequest, RequestOptions.DEFAULT);
|
||||
if (deleteResponse.isAcknowledged()) {
|
||||
log.info("成功删除Elasticsearch索引: {}", CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
return true;
|
||||
} else {
|
||||
log.error("删除索引 [{}] 未被确认(可能部分节点未响应)", CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
return false;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("删除ElasticSearch索引时发生异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateIndex(String fieldName, Map<String, Object> fieldProperties) {
|
||||
if (elasticsearchClient == null) {
|
||||
log.error("ElasticSearch客户端未配置");
|
||||
return false;
|
||||
}
|
||||
// 执行新增字段请求
|
||||
JSONObject newField = new JSONObject();
|
||||
newField.put(fieldName, fieldProperties);
|
||||
|
||||
JSONObject properties = new JSONObject();
|
||||
properties.put("properties", newField);
|
||||
|
||||
PutMappingRequest request = new PutMappingRequest(CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
request.source(properties.toJSONString(), XContentType.JSON);
|
||||
try {
|
||||
AcknowledgedResponse response = elasticsearchClient.indices().putMapping(request, RequestOptions.DEFAULT);
|
||||
if (response.isAcknowledged()) {
|
||||
log.info("成功更新Elasticsearch索引: {}, 新增字段: {}", CaseAiConstants.CASE_AI_INDEX_NAME, fieldName);
|
||||
return true;
|
||||
} else {
|
||||
log.error("更新索引 [{}] 未被确认(可能部分节点未响应)", CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新ElasticSearch索引时发生异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean createData(AiChatConversationData conversationData) {
|
||||
if (elasticsearchClient == null) {
|
||||
log.error("未配置Elasticsearch客户端,无法保存对话记录");
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建要保存的数据
|
||||
JSONObject esData = new JSONObject();
|
||||
esData.put("query", conversationData.getQuery());
|
||||
esData.put("answer", conversationData.getAnswerAsString());
|
||||
esData.put("conversationId", conversationData.getConversationId());
|
||||
esData.put("userId", conversationData.getUserId());
|
||||
// 持续时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
esData.put("startTime", conversationData.getStartTime().toString());
|
||||
esData.put("timestamp", now.toString());
|
||||
esData.put("durationSeconds", Duration.between(conversationData.getStartTime(), now).getSeconds());
|
||||
|
||||
esData.put("status", conversationData.getStatus());
|
||||
esData.put("errorMsg", conversationData.getErrorMsg());
|
||||
|
||||
// 构建 caseRefer 数据
|
||||
JSONArray caseReferArray = new JSONArray();
|
||||
for (CaseReferVo caseRefer : conversationData.getCaseRefers()) {
|
||||
JSONObject caseReferObj = new JSONObject();
|
||||
caseReferObj.put("caseId", caseRefer.getCaseId());
|
||||
caseReferObj.put("title", caseRefer.getTitle());
|
||||
caseReferObj.put("authorName", caseRefer.getAuthorName());
|
||||
caseReferObj.put("keywords", caseRefer.getKeywords());
|
||||
caseReferObj.put("content", caseRefer.getContent());
|
||||
caseReferArray.add(caseReferObj);
|
||||
}
|
||||
esData.put("caseRefer", caseReferArray);
|
||||
|
||||
// 添加建议
|
||||
esData.put("suggestions", conversationData.getSuggestions());
|
||||
|
||||
// 保存到ES
|
||||
IndexRequest indexRequest = new IndexRequest("ai_chat_messages");
|
||||
String dataStr = esData.toJSONString();
|
||||
log.info("保存对话记录到ES:{}", dataStr);
|
||||
indexRequest.source(dataStr, XContentType.JSON);
|
||||
|
||||
IndexResponse indexResponse = elasticsearchClient.index(indexRequest, RequestOptions.DEFAULT);
|
||||
log.info("保存对话记录到ES成功,文档ID: {}", indexResponse.getId());
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("保存对话记录到ES异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CaseAiMessageVo> queryData(String conversationId) {
|
||||
List<CaseAiMessageVo> list = new ArrayList<>();
|
||||
if (elasticsearchClient == null) {
|
||||
log.error("未配置Elasticsearch客户端,无法查询对话记录");
|
||||
return list;
|
||||
}
|
||||
try {
|
||||
// 从 ES 中查询消息记录
|
||||
SearchRequest searchRequest = new SearchRequest(CaseAiConstants.CASE_AI_INDEX_NAME); // ES索引名,可以根据实际情况调整
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
searchSourceBuilder.query(QueryBuilders.termQuery("conversationId", conversationId));
|
||||
searchSourceBuilder.size(1000); // 设置最大返回数量
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
|
||||
SearchResponse searchResponse = elasticsearchClient.search(searchRequest, RequestOptions.DEFAULT);
|
||||
SearchHits hits = searchResponse.getHits();
|
||||
|
||||
for (SearchHit hit : hits) {
|
||||
Map<String, Object> sourceMap = hit.getSourceAsMap();
|
||||
CaseAiMessageVo data = parseMessageFromES(sourceMap);
|
||||
if (data != null) {
|
||||
data.setDocId(hit.getId());
|
||||
list.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("从 ES 中查询到 {} 条消息记录", list.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("从 ES 查询会话消息记录异常", e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
private CaseAiMessageVo parseMessageFromES(Map<String, Object> sourceMap) {
|
||||
try {
|
||||
CaseAiMessageVo messageVo = new CaseAiMessageVo();
|
||||
messageVo.setConversationId((String) sourceMap.get("conversationId"));
|
||||
messageVo.setQuery((String) sourceMap.get("query"));
|
||||
messageVo.setAnswer((String) sourceMap.get("answer"));
|
||||
if (sourceMap.containsKey("startTime")) {
|
||||
String startTimeStr = (String) sourceMap.get("startTime");
|
||||
messageVo.setStartTime(LocalDateTime.parse(startTimeStr));
|
||||
}
|
||||
if (sourceMap.containsKey("durationSeconds")) {
|
||||
messageVo.setDurationSeconds((Integer) sourceMap.get("durationSeconds"));
|
||||
}
|
||||
|
||||
// 解析 suggestions
|
||||
if (sourceMap.containsKey("suggestions")) {
|
||||
Object suggestionsObj = sourceMap.get("suggestions");
|
||||
if (suggestionsObj instanceof List) {
|
||||
messageVo.setSuggestions((List<String>) suggestionsObj);
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceMap.containsKey("status")) {
|
||||
Object statusObj = sourceMap.get("status");
|
||||
if (statusObj != null) {
|
||||
messageVo.setStatus(Integer.valueOf(statusObj.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
if (sourceMap.containsKey("errorMsg")) {
|
||||
Object errorMsgObj = sourceMap.get("errorMsg");
|
||||
if (errorMsgObj != null) {
|
||||
messageVo.setErrorMsg(errorMsgObj.toString());
|
||||
}
|
||||
}
|
||||
|
||||
// 解析 caseRefer
|
||||
if (sourceMap.containsKey("caseRefer")) {
|
||||
Object caseReferObj = sourceMap.get("caseRefer");
|
||||
if (caseReferObj instanceof List) {
|
||||
List<CaseReferVo> caseReferList = new ArrayList<>();
|
||||
List<Map<String, Object>> caseReferMaps = (List<Map<String, Object>>) caseReferObj;
|
||||
|
||||
for (Map<String, Object> caseReferMap : caseReferMaps) {
|
||||
CaseReferVo caseRefer = new CaseReferVo();
|
||||
caseRefer.setCaseId((String) caseReferMap.get("caseId"));
|
||||
caseRefer.setTitle((String) caseReferMap.get("title"));
|
||||
caseRefer.setAuthorName((String) caseReferMap.get("authorName"));
|
||||
caseRefer.setContent((String) caseReferMap.get("content"));
|
||||
|
||||
// 解析 keywords
|
||||
Object keywordsObj = caseReferMap.get("keywords");
|
||||
if (keywordsObj instanceof List) {
|
||||
caseRefer.setKeywords((List<String>) keywordsObj);
|
||||
}
|
||||
|
||||
caseReferList.add(caseRefer);
|
||||
}
|
||||
messageVo.setCaseRefer(caseReferList);
|
||||
}
|
||||
}
|
||||
|
||||
// 解析点赞状态
|
||||
if (sourceMap.containsKey("likeStatus")) {
|
||||
messageVo.setLikeStatus((String) sourceMap.get("likeStatus"));
|
||||
}
|
||||
// 解析反馈信息
|
||||
if (sourceMap.containsKey("feedback")) {
|
||||
messageVo.setFeedback((String) sourceMap.get("feedback"));
|
||||
}
|
||||
|
||||
return messageVo;
|
||||
} catch (Exception e) {
|
||||
log.error("解析ES消息数据异常", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateData(String docId, AiChatConversationData data) {
|
||||
if (elasticsearchClient == null) {
|
||||
log.error("未配置Elasticsearch客户端,无法更新对话记录");
|
||||
return false;
|
||||
}
|
||||
try{
|
||||
UpdateRequest updateRequest = new UpdateRequest(CaseAiConstants.CASE_AI_INDEX_NAME, docId);
|
||||
JSONObject esData = new JSONObject();
|
||||
// 目前只支持更新点赞状态和反馈信息
|
||||
if (StringUtils.isNotBlank(data.getLikeStatus())) {
|
||||
// 进行点赞/踩或取消操作是, 将feedback字段置空
|
||||
esData.put("likeStatus", data.getLikeStatus());
|
||||
esData.put("feedback", "");
|
||||
}
|
||||
if (StringUtils.isNotBlank(data.getFeedback())) {
|
||||
esData.put("feedback", data.getFeedback());
|
||||
}
|
||||
updateRequest.doc(esData.toJSONString(), XContentType.JSON);
|
||||
elasticsearchClient.update(updateRequest, RequestOptions.DEFAULT);
|
||||
return true;
|
||||
} catch (ElasticsearchException e) {
|
||||
if (e.status() == RestStatus.NOT_FOUND) {
|
||||
log.error("文档不存在", e);
|
||||
}
|
||||
return false;
|
||||
} catch (Exception e) {
|
||||
log.error("更新对话记录异常", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过docId查询数据
|
||||
*
|
||||
* @param docId 会话ID
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<CaseAiMessageVo> queryDataByDocId(String docId) {
|
||||
List<CaseAiMessageVo> list = new ArrayList<>();
|
||||
if (elasticsearchClient == null) {
|
||||
log.error("未配置Elasticsearch客户端,无法查询消息记录");
|
||||
return list;
|
||||
}
|
||||
try {
|
||||
SearchRequest searchRequest = new SearchRequest(CaseAiConstants.CASE_AI_INDEX_NAME);
|
||||
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
|
||||
searchSourceBuilder.query(QueryBuilders.matchQuery("_id", docId));
|
||||
searchSourceBuilder.size(1000); // 设置最大返回数量
|
||||
searchRequest.source(searchSourceBuilder);
|
||||
|
||||
|
||||
SearchResponse searchResponse = elasticsearchClient.search(searchRequest, RequestOptions.DEFAULT);
|
||||
SearchHits hits = searchResponse.getHits();
|
||||
|
||||
for (SearchHit hit : hits) {
|
||||
Map<String, Object> sourceMap = hit.getSourceAsMap();
|
||||
CaseAiMessageVo data = parseMessageFromES(sourceMap);
|
||||
if (data != null) {
|
||||
data.setDocId(hit.getId());
|
||||
list.add(data);
|
||||
}
|
||||
}
|
||||
|
||||
log.info("从 ES 中查询到 {} 条消息记录", list.size());
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("从 ES 查询消息异常", e);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取ai_chat_messages索引的字段映射配置
|
||||
* 根据项目中的会话消息数据结构规范定义映射
|
||||
*
|
||||
* @return JSON格式的映射配置
|
||||
*/
|
||||
private String getAiChatMessagesMapping() {
|
||||
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("case_ai_index.json");
|
||||
if (inputStream != null) {
|
||||
try (InputStreamReader isr = new InputStreamReader(inputStream);
|
||||
BufferedReader reader = new BufferedReader(isr)) {
|
||||
return reader.lines().collect(Collectors.joining(System.lineSeparator()));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Resource read error: case_ai_index.json", e);
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Resource not found: case_ai_index.json");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.xboe.module.boecase.task;
|
||||
|
||||
import com.xboe.module.boecase.service.ICaseAiChatService;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CaseAiChatDataTask {
|
||||
|
||||
@Autowired
|
||||
private ICaseAiChatService caseAiChatService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询上月聊天数据并下载
|
||||
* cron: 0/10 * * * * ?
|
||||
*/
|
||||
@XxlJob("chatDataExcelDownloadJob")
|
||||
public void chatDataExcelDownload(String param) {
|
||||
LocalDateTime startTime;
|
||||
LocalDateTime endTime;
|
||||
|
||||
if (param != null && !param.isEmpty()) {
|
||||
// 解析参数,格式应为 "startTime,endTime",例如 "2023-01-01T00:00:00,2023-01-31T23:59:59"
|
||||
String[] times = param.split(",");
|
||||
if (times.length == 2) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
try {
|
||||
startTime = LocalDateTime.parse(times[0], formatter);
|
||||
endTime = LocalDateTime.parse(times[1], formatter);
|
||||
log.info("使用参数指定的时间范围: {} 到 {}", startTime, endTime);
|
||||
} catch (Exception e) {
|
||||
log.error("解析时间参数失败,使用默认时间范围", e);
|
||||
// 使用默认逻辑
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
|
||||
startTime = now.minusMonths(1)
|
||||
.withDayOfMonth(1)
|
||||
.withHour(0)
|
||||
.withMinute(0)
|
||||
.withSecond(0);
|
||||
endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
|
||||
}
|
||||
} else {
|
||||
// 使用默认逻辑
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
|
||||
startTime = now.minusMonths(1)
|
||||
.withDayOfMonth(1)
|
||||
.withHour(0)
|
||||
.withMinute(0)
|
||||
.withSecond(0);
|
||||
endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
|
||||
}
|
||||
} else {
|
||||
// 使用默认逻辑
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
|
||||
startTime = now.minusMonths(1)
|
||||
.withDayOfMonth(1)
|
||||
.withHour(0)
|
||||
.withMinute(0)
|
||||
.withSecond(0);
|
||||
endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
|
||||
}
|
||||
|
||||
// 执行
|
||||
caseAiChatService.downloadConversationExcel(startTime, endTime);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.xboe.module.boecase.task;
|
||||
|
||||
import com.xboe.module.boecase.service.ICaseKnowledgeService;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CaseDocumentLogTask {
|
||||
|
||||
@Autowired
|
||||
private ICaseKnowledgeService caseKnowledgeService;
|
||||
|
||||
/**
|
||||
* 批量查询文件状态并修改
|
||||
* 目前每次查看10条数据,批处理拟每10秒一次,每分钟可运行6次,60条数据
|
||||
* cron: 0/10 * * * * ?
|
||||
*/
|
||||
@XxlJob("batchCheckFileStatusJob")
|
||||
public void batchCheckFileStatusJob() {
|
||||
// log.info("开始批量查询文件状态");
|
||||
caseKnowledgeService.batchCheckFileStatus();
|
||||
// log.info("结束批量查询文件状态");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,222 @@
|
||||
package com.xboe.module.boecase.task;
|
||||
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.constants.CaseAiConstants;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.core.orm.QueryBuilder;
|
||||
import com.xboe.enums.CaseDocumentLogCaseStatusEnum;
|
||||
import com.xboe.enums.CaseDocumentLogOptStatusEnum;
|
||||
import com.xboe.enums.CaseDocumentLogOptTypeEnum;
|
||||
import com.xboe.enums.CaseDocumentLogRunStatusEnum;
|
||||
import com.xboe.module.boecase.async.CaseAiDocumentAsyncHandler;
|
||||
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
|
||||
import com.xboe.module.boecase.dao.CasesDao;
|
||||
import com.xboe.module.boecase.entity.CaseDocumentLog;
|
||||
import com.xboe.module.boecase.entity.Cases;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 旧案例上传
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CaseUploadTask {
|
||||
|
||||
@Resource
|
||||
private CasesDao casesDao;
|
||||
|
||||
@Resource
|
||||
private CaseDocumentLogDao caseDocumentLogDao;
|
||||
|
||||
@Autowired
|
||||
private CaseAiDocumentAsyncHandler caseAiDocumentAsyncHandler;
|
||||
|
||||
@Autowired
|
||||
private StringRedisTemplate stringRedisTemplate;
|
||||
|
||||
public static final String CASE_UPLOAD_LAST_ID_KEY = "case:upload:last:id";
|
||||
|
||||
public static final String CASE_RELOAD_LAST_ID_KEY = "case:reload:last:id";
|
||||
|
||||
@XxlJob("reloadJob")
|
||||
public void reloadJob() {
|
||||
String currentLastId = null;
|
||||
try {
|
||||
// 从Redis获取上次处理的最后一条记录ID
|
||||
String lastProcessedId = stringRedisTemplate.opsForValue().get(CASE_RELOAD_LAST_ID_KEY);
|
||||
// 查询需要重新加载的案例
|
||||
List<CaseDocumentLog> logsToReload = listToReload(lastProcessedId);
|
||||
if (logsToReload.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
currentLastId = logsToReload.get(logsToReload.size() - 1).getId();
|
||||
for (CaseDocumentLog log : logsToReload) {
|
||||
String caseId = log.getCaseId();
|
||||
Cases cases = casesDao.get(caseId);
|
||||
if (cases != null && StringUtils.isNotBlank(cases.getFilePath())) {
|
||||
// 更新
|
||||
caseAiDocumentAsyncHandler.process(CaseDocumentLogOptTypeEnum.UPDATE, cases);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("[reload]执行重新上传任务时发生异常", e);
|
||||
} finally {
|
||||
if (currentLastId != null) {
|
||||
stringRedisTemplate.opsForValue().set(CASE_RELOAD_LAST_ID_KEY, currentLastId);
|
||||
log.info("[reload] 已重新上传案例,最后一条caseDocumentLogId 已更新为: {}", currentLastId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@XxlJob("oldDataUploadJob")
|
||||
public void oldDataUploadJob() {
|
||||
String currentLastId = null;
|
||||
try {
|
||||
// log.info("开始执行旧案例上传任务");
|
||||
|
||||
// 从Redis获取上次处理的最后一条记录ID
|
||||
String lastProcessedId = stringRedisTemplate.opsForValue().get(CASE_UPLOAD_LAST_ID_KEY);
|
||||
// log.info("上次处理的最后一条记录ID: {}", lastProcessedId);
|
||||
|
||||
// 查询符合条件的案例数据
|
||||
List<Cases> casesToProcess = findCasesToProcess(lastProcessedId);
|
||||
// log.info("查询到待处理案例数量: {}", casesToProcess.size());
|
||||
|
||||
if (casesToProcess.isEmpty()) {
|
||||
// log.info("没有需要处理的案例数据");
|
||||
return;
|
||||
}
|
||||
currentLastId = casesToProcess.get(casesToProcess.size() - 1).getId();
|
||||
|
||||
// 批量检查这些案例是否已在CaseDocumentLog中存在记录,提升性能
|
||||
List<String> caseIds = new ArrayList<>();
|
||||
for (Cases cases : casesToProcess) {
|
||||
caseIds.add(cases.getId());
|
||||
}
|
||||
|
||||
// 一次性查询所有相关案例的记录
|
||||
List<CaseDocumentLog> existingLogs = caseDocumentLogDao.getGenericDao()
|
||||
.findList(CaseDocumentLog.class,
|
||||
com.xboe.core.orm.FieldFilters.in("caseId", caseIds));
|
||||
|
||||
// 过滤出未在CaseDocumentLog中存在的案例
|
||||
List<Cases> casesList = new ArrayList<>();
|
||||
for (Cases cases : casesToProcess) {
|
||||
// boolean exists = false;
|
||||
// for (CaseDocumentLog log : existingLogs) {
|
||||
// if (cases.getId().equals(log.getCaseId())
|
||||
// && StringUtils.equals(log.getRequestUrl(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME)
|
||||
// && Objects.equals(log.getRunStatus(), CaseDocumentLogRunStatusEnum.COMPLETED.getCode())
|
||||
// && Objects.equals(log.getOptStatus(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode())
|
||||
// && Objects.equals(log.getRunStatus(), CaseDocumentLogCaseStatusEnum.SUCCESS.getCode())) {
|
||||
// exists = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!exists) {
|
||||
// casesList.add(cases);
|
||||
// }
|
||||
List<CaseDocumentLog> thisCaseLogs = existingLogs.stream()
|
||||
.filter(log -> cases.getId().equals(log.getCaseId()))
|
||||
.collect(Collectors.toList());
|
||||
if (thisCaseLogs == null || thisCaseLogs.isEmpty()) {
|
||||
casesList.add(cases);
|
||||
} else if (thisCaseLogs.stream()
|
||||
.noneMatch(caseLog -> {
|
||||
// 1. 是否存在已上传完成的案例
|
||||
boolean hasCompleted = StringUtils.equals(caseLog.getRequestUrl(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME)
|
||||
&& Objects.equals(caseLog.getRunStatus(), CaseDocumentLogRunStatusEnum.COMPLETED.getCode())
|
||||
&& Objects.equals(caseLog.getOptStatus(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode())
|
||||
&& Objects.equals(caseLog.getRunStatus(), CaseDocumentLogCaseStatusEnum.SUCCESS.getCode());
|
||||
// 2. 是否存在上传中的案例
|
||||
boolean hasUploading = StringUtils.equals(caseLog.getRequestUrl(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME)
|
||||
&& Objects.equals(caseLog.getRunStatus(), CaseDocumentLogRunStatusEnum.RUNNING.getCode());
|
||||
return hasCompleted || hasUploading;
|
||||
})) {
|
||||
casesList.add(cases);
|
||||
}
|
||||
}
|
||||
|
||||
// log.info("过滤后需要处理的案例数量: {}", casesList.size());
|
||||
|
||||
if (!casesList.isEmpty()) {
|
||||
// 调用异步处理方法
|
||||
caseAiDocumentAsyncHandler.process(CaseDocumentLogOptTypeEnum.CREATE, casesList.toArray(new Cases[0]));
|
||||
|
||||
} else {
|
||||
log.info("没有新的案例需要处理");
|
||||
}
|
||||
// 将当前处理的最后一条数据ID存入Redis
|
||||
|
||||
// log.info("旧案例上传任务执行完成");
|
||||
} catch (Exception e) {
|
||||
log.error("执行旧案例上传任务时发生异常", e);
|
||||
} finally {
|
||||
if (currentLastId != null) {
|
||||
fixOnLastCase(currentLastId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询需要处理的案例数据
|
||||
*
|
||||
* @param lastProcessedId 上次处理的最后一条记录ID
|
||||
* @return 案例列表
|
||||
*/
|
||||
private List<Cases> findCasesToProcess(String lastProcessedId) {
|
||||
QueryBuilder queryBuilder = QueryBuilder.from(Cases.class);
|
||||
queryBuilder.addFilter(FieldFilters.eq("deleted", false));
|
||||
// 只处理有文件路径的案例
|
||||
queryBuilder.addFilter(FieldFilters.isNotNull("filePath"));
|
||||
queryBuilder.addFilter(FieldFilters.ne("filePath", ""));
|
||||
|
||||
// 如果有上次处理的ID,则从该ID之后开始查询
|
||||
if (lastProcessedId != null && !lastProcessedId.isEmpty()) {
|
||||
queryBuilder.addFilter(FieldFilters.gt("id", lastProcessedId));
|
||||
}
|
||||
|
||||
// 按创建时间升序排序
|
||||
queryBuilder.addOrder(OrderCondition.asc("id"));
|
||||
// 限制每次处理的数量,避免一次性处理太多数据
|
||||
queryBuilder.setPageSize(100);
|
||||
|
||||
return casesDao.findList(queryBuilder.builder());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取需要重新加载的案例
|
||||
* @param lastProcessedId
|
||||
* @return
|
||||
*/
|
||||
private List<CaseDocumentLog> listToReload(String lastProcessedId) {
|
||||
QueryBuilder queryBuilder = QueryBuilder.from(CaseDocumentLog.class);
|
||||
queryBuilder.addFilter(FieldFilters.eq("deleted", false));
|
||||
queryBuilder.addFilter(FieldFilters.eq("requestUrl", CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME));
|
||||
queryBuilder.addFilter(FieldFilters.eq("caseStatus", CaseDocumentLogCaseStatusEnum.SUCCESS.getCode()));
|
||||
queryBuilder.addFilter(FieldFilters.eq("metadataStatus", 0));
|
||||
if (lastProcessedId != null && !lastProcessedId.isEmpty()) {
|
||||
queryBuilder.addFilter(FieldFilters.gt("id", lastProcessedId));
|
||||
}
|
||||
queryBuilder.addOrder(OrderCondition.asc("id"));
|
||||
queryBuilder.setPageSize(100);
|
||||
return caseDocumentLogDao.findList(queryBuilder.builder());
|
||||
}
|
||||
|
||||
private void fixOnLastCase(String currentLastId) {
|
||||
stringRedisTemplate.opsForValue().set(CASE_UPLOAD_LAST_ID_KEY, currentLastId);
|
||||
log.info("已处理案例,最后一条记录ID已更新为: {}", currentLastId);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package com.xboe.module.boecase.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* AI会话记录
|
||||
*/
|
||||
@Data
|
||||
public class CaseAiConversationVo {
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.xboe.module.boecase.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI会话消息记录VO
|
||||
*/
|
||||
@Data
|
||||
public class CaseAiMessageVo {
|
||||
/**
|
||||
* ES docId
|
||||
*/
|
||||
private String docId;
|
||||
|
||||
/**
|
||||
* 会话ID
|
||||
*/
|
||||
private String conversationId;
|
||||
|
||||
/**
|
||||
* 用户提问内容
|
||||
*/
|
||||
private String query;
|
||||
|
||||
/**
|
||||
* AI回答内容
|
||||
*/
|
||||
private String answer;
|
||||
|
||||
/**
|
||||
* 会话开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 会话时长(秒)
|
||||
*/
|
||||
private Integer durationSeconds;
|
||||
|
||||
/**
|
||||
* 案例引用列表
|
||||
*/
|
||||
private List<CaseReferVo> caseRefer;
|
||||
|
||||
/**
|
||||
* 建议列表
|
||||
*/
|
||||
private List<String> suggestions;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
* 0-正常
|
||||
* 1-系统错误
|
||||
* 2-AIoT平台错误
|
||||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 错误信息
|
||||
*/
|
||||
private String errorMsg;
|
||||
|
||||
/**
|
||||
* 用户点赞状态
|
||||
* -1: 踩
|
||||
* 1:赞
|
||||
* 0/null 无操作
|
||||
*/
|
||||
private String likeStatus;
|
||||
|
||||
/**
|
||||
* 用户踩的时候, 可以填写反馈意见
|
||||
* 反馈意见
|
||||
*/
|
||||
private String feedback;
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.xboe.module.boecase.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* AI调用日志列表展示VO
|
||||
*/
|
||||
@Data
|
||||
public class CaseDocumentLogVo {
|
||||
|
||||
/**
|
||||
* 日志ID
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 案例标题
|
||||
*/
|
||||
private String caseTitle;
|
||||
|
||||
/**
|
||||
* 操作类型
|
||||
*/
|
||||
private String optType;
|
||||
|
||||
/**
|
||||
* 调用接口名称
|
||||
*/
|
||||
private String requestUrl;
|
||||
|
||||
/**
|
||||
* 调用时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime optTime;
|
||||
|
||||
/**
|
||||
* 请求参数
|
||||
*/
|
||||
private String requestBody;
|
||||
|
||||
/**
|
||||
* 响应参数
|
||||
*/
|
||||
private String responseBody;
|
||||
|
||||
/**
|
||||
* 接口调用结果
|
||||
* 0-调用中, 1-调用成功, 2-调用失败
|
||||
*/
|
||||
private Integer optStatus;
|
||||
|
||||
/**
|
||||
* 接口调用结果描述
|
||||
*/
|
||||
private String optStatusText;
|
||||
|
||||
/**
|
||||
* 业务处理结果
|
||||
* 1-处理成功, 2-处理失败
|
||||
*/
|
||||
private Integer caseStatus;
|
||||
|
||||
/**
|
||||
* 业务处理结果描述
|
||||
*/
|
||||
private String caseStatusText;
|
||||
|
||||
/**
|
||||
* 执行时间(ms)
|
||||
*/
|
||||
private Long executeDuration;
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.xboe.module.boecase.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import lombok.Data;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 案例引用信息VO
|
||||
*/
|
||||
@Data
|
||||
public class CaseReferVo {
|
||||
|
||||
/**
|
||||
* 案例ID
|
||||
*/
|
||||
private String caseId;
|
||||
|
||||
/**
|
||||
* 案例标题
|
||||
*/
|
||||
private String title;
|
||||
|
||||
/**
|
||||
* 作者姓名
|
||||
*/
|
||||
private String authorName;
|
||||
|
||||
/**
|
||||
* 组织信息
|
||||
*/
|
||||
private String orgInfo;
|
||||
|
||||
/**
|
||||
* 上传时间
|
||||
*/
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime uploadTime;
|
||||
|
||||
/**
|
||||
* 关键词列表
|
||||
*/
|
||||
private List<String> keywords;
|
||||
|
||||
/**
|
||||
* 案例内容
|
||||
*/
|
||||
private String content;
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.xboe.module.boecase.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会话Excel导出VO
|
||||
*/
|
||||
@Data
|
||||
public class ConversationExcelVo {
|
||||
/**
|
||||
* 会话ID
|
||||
*/
|
||||
private String conversationId;
|
||||
|
||||
/**
|
||||
* 会话名称
|
||||
*/
|
||||
private String conversationName;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
private String user;
|
||||
|
||||
/**
|
||||
* 问答记录
|
||||
*/
|
||||
private List<CaseAiMessageVo> messages;
|
||||
}
|
||||
@@ -11,22 +11,22 @@ spring:
|
||||
cloud:
|
||||
nacos:
|
||||
discovery:
|
||||
server-addr: 192.168.0.253:8848
|
||||
server-addr: 192.168.10.74:8848
|
||||
config:
|
||||
server-addr: 192.168.0.253:8848
|
||||
server-addr: 192.168.10.74:8848
|
||||
redis:
|
||||
database: 1
|
||||
host: 192.168.0.253
|
||||
password: boe@123
|
||||
port: 6379
|
||||
database: 2
|
||||
host: 39.104.123.58
|
||||
password: Ebiz2020
|
||||
port: 6378
|
||||
jpa:
|
||||
hibernate:
|
||||
ddl-auto: none
|
||||
datasource:
|
||||
driverClassName: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://192.168.0.253:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
|
||||
username: root
|
||||
password: boe#1234A
|
||||
url: jdbc:mysql://rm-hp3cpkk0u50q90eu9vo.mysql.huhehaote.rds.aliyuncs.com:3306/ebiz_doc_manage?characterEncoding=utf8&useUnicode=true&serverTimezone=Asia/Shanghai&useSSL=false&allowMultiQueries=true
|
||||
username: ebiz_ai
|
||||
password: ebiz_ai123
|
||||
type: com.zaxxer.hikari.HikariDataSource
|
||||
hikari:
|
||||
auto-commit: true
|
||||
@@ -35,6 +35,12 @@ spring:
|
||||
connection-timeout: 30000
|
||||
max-lifetime: 1800000
|
||||
maximum-pool-size: 20
|
||||
activemq:
|
||||
broker-url: tcp://192.168.10.74:61616
|
||||
user: admin
|
||||
password: admin
|
||||
jms:
|
||||
pub-sub-domain: true
|
||||
logging:
|
||||
level:
|
||||
org:
|
||||
@@ -79,6 +85,16 @@ xboe:
|
||||
image:
|
||||
course:
|
||||
default: http://192.168.0.253/pc/images/bgimg/course.png
|
||||
case:
|
||||
ai:
|
||||
base-url: http://10.10.181.114:30003
|
||||
app-key: 6e9be45319184ac793aa127c362b0f0b
|
||||
secret-key: db4d24279e3d6dbf1524af42cd0bedd2
|
||||
ai-api-code: 30800
|
||||
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
|
||||
file-upload-callback-url: http://192.168.0.253:9090/xboe/m/boe/caseDocumentLog/uploadCallback
|
||||
alert-email-recipients:
|
||||
- liu.zixi@ebiz-digits.com
|
||||
xxl:
|
||||
job:
|
||||
accessToken: 65ddc683-22f5-83b4-de3a-3c97a0a29af0
|
||||
@@ -97,7 +113,7 @@ aop-log-record:
|
||||
#不进行拦截的包或者类
|
||||
excludeClassNames:
|
||||
activemq:
|
||||
broker-url: tcp://192.168.0.253:61616
|
||||
broker-url: tcp://192.168.10.74:61616
|
||||
user: admin
|
||||
password: admin
|
||||
elasticsearch:
|
||||
|
||||
@@ -40,6 +40,12 @@ spring:
|
||||
web:
|
||||
resources:
|
||||
static-locations: file:E:/Projects/BOE/10/static
|
||||
activemq:
|
||||
broker-url: tcp://10.251.129.51:61616
|
||||
user: admin
|
||||
password: admin
|
||||
jms:
|
||||
pub-sub-domain: true
|
||||
server:
|
||||
port: 9090
|
||||
tomcat:
|
||||
@@ -111,6 +117,16 @@ xboe:
|
||||
image:
|
||||
course:
|
||||
default: http://10.251.132.75/pc/images/bgimg/course.png
|
||||
case:
|
||||
ai:
|
||||
base-url: http://10.10.181.114:30003
|
||||
app-key: 6e9be45319184ac793aa127c362b0f0b
|
||||
secret-key: db4d24279e3d6dbf1524af42cd0bedd2
|
||||
ai-api-code: 30800
|
||||
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
|
||||
file-upload-callback-url: http://10.251.132.75:9090/xboe/m/boe/caseDocumentLog/uploadCallback
|
||||
alert-email-recipients:
|
||||
- liu.zixi@ebiz-digits.com
|
||||
jasypt:
|
||||
encryptor:
|
||||
algorithm: PBEWithMD5AndDES
|
||||
|
||||
@@ -33,6 +33,12 @@ spring:
|
||||
connection-timeout: 30000
|
||||
max-lifetime: 1800000
|
||||
maximum-pool-size: 20
|
||||
activemq:
|
||||
broker-url: tcp://10.251.113.100:61616
|
||||
user: admin
|
||||
password: admin
|
||||
jms:
|
||||
pub-sub-domain: true
|
||||
logging:
|
||||
level:
|
||||
org:
|
||||
@@ -77,6 +83,245 @@ xboe:
|
||||
image:
|
||||
course:
|
||||
default: https://u.boe.com/pc/images/bgimg/course.png
|
||||
case:
|
||||
ai:
|
||||
base-url: https://gateway-internal.boe.com
|
||||
# base-url: https://gateway-pro.boe.com
|
||||
app-key: 3edef300b25642da949ccddf58441a0f
|
||||
secret-key: 43bc8003a811a7f9c89cbecbfe4bbb22
|
||||
ai-api-code: 30800
|
||||
chat-api-code: 32065
|
||||
# case-knowledge-id: f062c9e4-c6ad-437b-b5ca-bbb9fed9b442
|
||||
# 20251117 张娟提供新版kId
|
||||
case-knowledge-id: 0a4d5d9e-0dae-456e-a342-3dfd2046b9e3
|
||||
caseDetailUrlBase: https://u.boe.com/pc/case/detail?id=
|
||||
file-upload-callback-url: https://u.boe.com/systemapi/xboe/m/boe/caseDocumentLog/uploadCallback
|
||||
use-white-list: true
|
||||
white-user-code-list:
|
||||
- "00004409"
|
||||
- "10361430"
|
||||
- "10867319"
|
||||
- "00004746"
|
||||
- "00004701"
|
||||
- "00004471"
|
||||
- "11311660"
|
||||
- "10157955"
|
||||
- "10726944"
|
||||
- "110408"
|
||||
- "10768019"
|
||||
- "137812"
|
||||
- "107863"
|
||||
- "10046607"
|
||||
- "110858"
|
||||
- "98000352"
|
||||
- "101215"
|
||||
- "00005011"
|
||||
- "10827857"
|
||||
- "11339772"
|
||||
- "pctest06"
|
||||
# 20251202 新增天使用户
|
||||
- "30103141"
|
||||
- "60001391"
|
||||
- "61001278"
|
||||
- "30101301"
|
||||
- "10444837"
|
||||
- "50102190"
|
||||
- "10745030"
|
||||
- "11417101"
|
||||
- "11305432"
|
||||
- "10103037"
|
||||
- "10035168"
|
||||
- "30118060"
|
||||
- "11490910"
|
||||
- "11402931"
|
||||
- "50102196"
|
||||
- "00004896"
|
||||
- "98050025"
|
||||
- "15014359"
|
||||
- "98000758"
|
||||
- "10111538"
|
||||
- "62000137"
|
||||
- "10621476"
|
||||
- "11698996"
|
||||
- "10626304"
|
||||
- "1215826"
|
||||
- "30101887"
|
||||
- "10111915"
|
||||
- "11456852"
|
||||
- "126458"
|
||||
- "30141438"
|
||||
- "10209179"
|
||||
- "22BT15420"
|
||||
- "21BB2053"
|
||||
- "10449861"
|
||||
- "130325"
|
||||
- "11331818"
|
||||
- "10117022"
|
||||
- "10105891"
|
||||
- "121649"
|
||||
- "110338"
|
||||
- "1217784"
|
||||
- "30105038"
|
||||
- "98000792"
|
||||
- "60001146"
|
||||
- "11698607"
|
||||
- "11493629"
|
||||
- "10164819"
|
||||
- "11463452"
|
||||
- "10412122"
|
||||
- "11677116"
|
||||
- "98000780"
|
||||
- "61004269"
|
||||
- "1218902"
|
||||
- "111038"
|
||||
- "10056775"
|
||||
- "50125311"
|
||||
- "50100445"
|
||||
- "00003320"
|
||||
- "11672602"
|
||||
- "30129421"
|
||||
- "11433296"
|
||||
- "11759796"
|
||||
- "10063656"
|
||||
- "10829939"
|
||||
- "98050190"
|
||||
- "10061076"
|
||||
- "60001460"
|
||||
- "10415155"
|
||||
- "60000626"
|
||||
- "110791"
|
||||
- "60000984"
|
||||
- "62000025"
|
||||
- "11794394"
|
||||
- "11681568"
|
||||
- "00002915"
|
||||
- "1210874"
|
||||
- "132046"
|
||||
- "10157955"
|
||||
- "00004409"
|
||||
- "10773520"
|
||||
- "102403"
|
||||
- "10119108"
|
||||
- "10062300"
|
||||
- "10334899"
|
||||
- "10111689"
|
||||
- "10258267"
|
||||
- "60000327"
|
||||
- "50100096"
|
||||
- "10075741"
|
||||
- "1000477"
|
||||
- "1218405"
|
||||
- "132666"
|
||||
- "10183064"
|
||||
- "50101990"
|
||||
- "120869"
|
||||
- "11291711"
|
||||
- "11670020"
|
||||
- "11321710"
|
||||
- "10855714"
|
||||
- "11331449"
|
||||
- "50108923"
|
||||
- "66001553"
|
||||
- "81011081"
|
||||
- "11098405"
|
||||
- "10158509"
|
||||
- "11327800"
|
||||
- "10065717"
|
||||
- "10897206"
|
||||
- "30135784"
|
||||
- "1200373"
|
||||
- "10048566"
|
||||
- "10059710"
|
||||
- "11834720"
|
||||
- "1200384"
|
||||
- "60000973"
|
||||
- "11282207"
|
||||
- "40865"
|
||||
- "10811920"
|
||||
- "00003324"
|
||||
- "00003937"
|
||||
- "10031853"
|
||||
- "1201730"
|
||||
- "00004615"
|
||||
- "10613607"
|
||||
- "10166435"
|
||||
- "11407507"
|
||||
- "21BB0031"
|
||||
- "00002198"
|
||||
- "30104243"
|
||||
- "10840493"
|
||||
- "10046158"
|
||||
- "132164"
|
||||
- "11257354"
|
||||
- "11753398"
|
||||
- "10230265"
|
||||
- "11293165"
|
||||
- "10114925"
|
||||
- "S638"
|
||||
- "10833174"
|
||||
- "10926203"
|
||||
- "124046"
|
||||
- "201181"
|
||||
- "11319329"
|
||||
- "10884794"
|
||||
- "10331955"
|
||||
- "60000847"
|
||||
- "1411"
|
||||
- "126581"
|
||||
- "00003375"
|
||||
- "132539"
|
||||
- "98050455"
|
||||
- "10053666"
|
||||
- "11697194"
|
||||
- "61002398"
|
||||
- "00002971"
|
||||
- "14157"
|
||||
- "132989"
|
||||
- "50103467"
|
||||
- "37315"
|
||||
- "10088583"
|
||||
- "11048954"
|
||||
- "110202"
|
||||
- "30141433"
|
||||
- "1000079"
|
||||
- "11783149"
|
||||
- "10025448"
|
||||
- "98000579"
|
||||
- "10614158"
|
||||
- "30104381"
|
||||
- "60000122"
|
||||
- "11074875"
|
||||
- "10009047"
|
||||
- "10228087"
|
||||
- "10875722"
|
||||
- "10041401"
|
||||
- "110679"
|
||||
- "11167945"
|
||||
- "11288196"
|
||||
- "00003111"
|
||||
- "11780879"
|
||||
- "10836255"
|
||||
- "10753364"
|
||||
- "50102132"
|
||||
- "10711537"
|
||||
- "15001329"
|
||||
- "11733703"
|
||||
- "10450632"
|
||||
- "98050011"
|
||||
- "10224644"
|
||||
- "120931"
|
||||
- "10743223"
|
||||
- "107873"
|
||||
- "11141942"
|
||||
- "120434"
|
||||
- "126466"
|
||||
- "98050020"
|
||||
- "10928732"
|
||||
alert-email-recipients:
|
||||
- chengmeng@boe.com.cn
|
||||
- liyubing@boe.com.cn
|
||||
- lijian-hq@boe.com.cn
|
||||
ai-chat-root-path: /home/www/elearning/upload/ai/chat
|
||||
xxl:
|
||||
job:
|
||||
accessToken: 65ddc683-22f5-83b4-de3a-3c97a0a29af0
|
||||
@@ -100,4 +345,11 @@ aop-log-record:
|
||||
password: admin
|
||||
elasticsearch:
|
||||
host: 10.251.88.218
|
||||
port: 9200
|
||||
port: 9200
|
||||
ok:
|
||||
http:
|
||||
connect-timeout: 300
|
||||
read-timeout: 300
|
||||
write-timeout: 300
|
||||
max-idle-connections: 200
|
||||
keep-alive-duration: 300
|
||||
|
||||
@@ -40,6 +40,12 @@ spring:
|
||||
web:
|
||||
resources:
|
||||
static-locations: file:E:/Projects/BOE/10/static
|
||||
activemq:
|
||||
broker-url: tcp://10.251.129.25:61616
|
||||
user: admin
|
||||
password: admin
|
||||
jms:
|
||||
pub-sub-domain: true
|
||||
server:
|
||||
port: 9090
|
||||
tomcat:
|
||||
@@ -111,6 +117,41 @@ xboe:
|
||||
image:
|
||||
course:
|
||||
default: https://u-pre.boe.com/pc/images/bgimg/course.png
|
||||
case:
|
||||
ai:
|
||||
base-url: http://10.10.181.114:30003
|
||||
app-key: 6e9be45319184ac793aa127c362b0f0b
|
||||
secret-key: db4d24279e3d6dbf1524af42cd0bedd2
|
||||
ai-api-code: 30800
|
||||
chat-api-code: 32065
|
||||
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
|
||||
caseDetailUrlBase: https://u-pre.boe.com/pc/case/detail?id=
|
||||
file-upload-callback-url: http://10.251.186.27:9090/xboe/m/boe/caseDocumentLog/uploadCallback
|
||||
use-white-list: true
|
||||
white-user-code-list:
|
||||
- "00004409"
|
||||
- "10361430"
|
||||
- "10867319"
|
||||
- "00004746"
|
||||
- "00004701"
|
||||
- "00004471"
|
||||
- "11311660"
|
||||
- "10157955"
|
||||
- "10726944"
|
||||
- "110408"
|
||||
- "10768019"
|
||||
- "137812"
|
||||
- "107863"
|
||||
- "10046607"
|
||||
- "110858"
|
||||
- "98000352"
|
||||
- "101215"
|
||||
- "00005011"
|
||||
- "10827857"
|
||||
- "11339772"
|
||||
alert-email-recipients:
|
||||
- chengmeng@boe.com.cn
|
||||
ai-chat-root-path: /home/www/elearning/upload/ai/chat
|
||||
jasypt:
|
||||
encryptor:
|
||||
algorithm: PBEWithMD5AndDES
|
||||
@@ -122,8 +163,8 @@ boe:
|
||||
ok:
|
||||
http:
|
||||
connect-timeout: 30
|
||||
read-timeout: 30
|
||||
write-timeout: 30
|
||||
read-timeout: 300
|
||||
write-timeout: 300
|
||||
max-idle-connections: 200
|
||||
keep-alive-duration: 300
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@ spring:
|
||||
time-zone: GMT+8
|
||||
mvc:
|
||||
static-path-pattern: /cdn/**
|
||||
async:
|
||||
request-timeout: 600000
|
||||
jpa:
|
||||
database: MYSQL
|
||||
show-sql: false
|
||||
@@ -44,10 +46,13 @@ server:
|
||||
ok:
|
||||
http:
|
||||
connect-timeout: 30
|
||||
read-timeout: 30
|
||||
write-timeout: 30
|
||||
read-timeout: 300
|
||||
write-timeout: 300
|
||||
max-idle-connections: 200
|
||||
keep-alive-duration: 300
|
||||
activemq:
|
||||
topic:
|
||||
name: case_ai_chat_stop_topic
|
||||
boe:
|
||||
domain: http://127.0.0.1
|
||||
orgTree:
|
||||
|
||||
82
servers/boe-server-all/src/main/resources/case_ai_index.json
Normal file
82
servers/boe-server-all/src/main/resources/case_ai_index.json
Normal file
@@ -0,0 +1,82 @@
|
||||
{
|
||||
"properties": {
|
||||
"conversationId": {
|
||||
"type": "keyword",
|
||||
"index": true
|
||||
},
|
||||
"query": {
|
||||
"type": "text",
|
||||
"analyzer": "ik_max_word",
|
||||
"search_analyzer": "ik_smart",
|
||||
"fields": {
|
||||
"keyword": {
|
||||
"type": "keyword",
|
||||
"ignore_above": 256
|
||||
}
|
||||
}
|
||||
},
|
||||
"answer": {
|
||||
"type": "text",
|
||||
"analyzer": "ik_max_word",
|
||||
"search_analyzer": "ik_smart"
|
||||
},
|
||||
"caseRefer": {
|
||||
"type": "nested",
|
||||
"properties": {
|
||||
"caseId": {
|
||||
"type": "keyword",
|
||||
"index": true
|
||||
},
|
||||
"title": {
|
||||
"type": "text",
|
||||
"analyzer": "ik_max_word",
|
||||
"search_analyzer": "ik_smart"
|
||||
},
|
||||
"authorName": {
|
||||
"type": "keyword",
|
||||
"index": true
|
||||
},
|
||||
"keywords": {
|
||||
"type": "text",
|
||||
"analyzer": "ik_max_word",
|
||||
"search_analyzer": "ik_smart"
|
||||
},
|
||||
"content": {
|
||||
"type": "text",
|
||||
"analyzer": "ik_max_word",
|
||||
"search_analyzer": "ik_smart"
|
||||
}
|
||||
}
|
||||
},
|
||||
"suggestions": {
|
||||
"type": "text",
|
||||
"analyzer": "ik_max_word",
|
||||
"search_analyzer": "ik_smart"
|
||||
},
|
||||
"userId": {
|
||||
"type": "keyword",
|
||||
"index": true
|
||||
},
|
||||
"timestamp": {
|
||||
"type": "date",
|
||||
"format": "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss||yyyy-MM-dd'T'HH:mm:ss.SSS||yyyy-MM-dd'T'HH:mm:ss.SSS'Z'||epoch_millis"
|
||||
},
|
||||
"status": {
|
||||
"type": "integer"
|
||||
},
|
||||
"errorMsg": {
|
||||
"type": "text",
|
||||
"analyzer": "ik_max_word",
|
||||
"search_analyzer": "ik_smart"
|
||||
},
|
||||
"likeStatus": {
|
||||
"type": "keyword",
|
||||
"index": true
|
||||
},
|
||||
"feedback": {
|
||||
"type": "text",
|
||||
"analyzer": "ik_max_word",
|
||||
"search_analyzer": "ik_smart"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,26 +31,42 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file error output -->
|
||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<appender name="caseAiChat"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
<file>${log.path}/caseAiChat.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/caseAiChat.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<!-- Log file error output -->
|
||||
<!-- <appender name="caseAiChat" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
|
||||
<!-- <file>${log.path}/caseAiChat.log</file>-->
|
||||
<!-- <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">-->
|
||||
<!-- <fileNamePattern>${log.path}/%d{yyyy-MM}/caseAiChat.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>-->
|
||||
<!-- <maxFileSize>50MB</maxFileSize>-->
|
||||
<!-- <maxHistory>30</maxHistory>-->
|
||||
<!-- </rollingPolicy>-->
|
||||
<!-- <encoder>-->
|
||||
<!-- <pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>-->
|
||||
<!-- </encoder>-->
|
||||
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">-->
|
||||
<!-- <level>ERROR</level>-->
|
||||
<!-- </filter>-->
|
||||
<!-- </appender>-->
|
||||
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="info"/>
|
||||
<!-- <appender-ref ref="console"/>-->
|
||||
<!-- <appender-ref ref="error"/> -->
|
||||
</root>
|
||||
|
||||
<logger name="caseAiChatLogger" additivity="false" level="INFO">
|
||||
<appender-ref ref="caseAiChat"/>
|
||||
</logger>
|
||||
</configuration>
|
||||
|
||||
@@ -47,10 +47,26 @@
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="caseAiChat"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<File>${log.path}/caseAiChat.log</File>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>${log.path}/caseAiChat.%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="debug"/>
|
||||
<appender-ref ref="error"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<logger name="caseAiChatLogger" additivity="false" level="INFO">
|
||||
<appender-ref ref="caseAiChat"/>
|
||||
</logger>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user