Compare commits

..

108 Commits

Author SHA1 Message Date
liu.zixi
770f467523 [DAT] 配合业务处理挡板 2025-10-31 10:37:28 +08:00
liu.zixi
70a537781c [DAT] 对话接口加新的apiCode 2025-10-31 10:37:27 +08:00
liu.zixi
918d444f36 [DAT] 数据挡板:业务处理失败 2025-10-31 10:37:25 +08:00
liu.zixi
ef28650966 [DAT] 数据挡板:更新时,删除成功新增失败 2025-10-31 10:37:24 +08:00
liu.zixi
8188810f5d [DAT] 重试时根据上一次执行步骤来决定 2025-10-31 10:37:23 +08:00
liu.zixi
ad981eb49d [DAT] 数据挡板:接口调用失败挡板去除 2025-10-31 10:37:21 +08:00
liu.zixi
dae2e29b93 [DAT] 数据挡板:更改时新增失败 2025-10-31 10:37:20 +08:00
liu.zixi
6a73dc60dd [DAT] 数据挡板:新增、删除、更改全挡 2025-10-31 10:37:19 +08:00
liu.zixi
66cbf57387 [DAT] from改为带@的全称 2025-10-31 10:37:18 +08:00
liu.zixi
fafb584213 [DAT] 告警邮件配置 2025-10-31 10:37:17 +08:00
liu.zixi
50cf9fa4fb [DAT] 增加白名单配置 2025-10-31 10:37:15 +08:00
liu.zixi
e4ada3e3c5 [DAT] email更换 2025-10-31 10:37:14 +08:00
liu.zixi
7eb98eece4 [DAT] 去挡板 2025-10-31 10:37:13 +08:00
liu.zixi
c103ea2605 [DAT] 接口失败时,业务状态设为null 2025-10-31 10:37:12 +08:00
liu.zixi
9616c819b3 [DAT] upload时应当为接口失败 2025-10-31 10:37:11 +08:00
liu.zixi
93d5b30489 [DAT] upload加挡板 2025-10-31 10:37:09 +08:00
liu.zixi
cd3bb38390 [DAT] 文档去重 2025-10-31 10:37:08 +08:00
liu.zixi
dab0efb010 [DAT] 显示摘要 2025-10-31 10:37:07 +08:00
liu.zixi
d7acd100b5 [DAT] 去挡板 2025-10-31 10:37:06 +08:00
liu.zixi
abb6cf5516 [DAT] 修复时间错误的问题;尝试修复发邮件 2025-10-31 10:37:04 +08:00
liu.zixi
4fab87998d [DAT] 接口调用失败的数据挡板2 2025-10-31 10:37:03 +08:00
liu.zixi
ceaeda8614 [DAT] 接口调用失败的数据挡板 2025-10-31 10:37:02 +08:00
liu.zixi
636d67165d [DAT] 发邮件增加日志打印 2025-10-31 10:37:01 +08:00
liu.zixi
253eb4ee2e [DAT] 放开重试挡板 2025-10-31 10:36:59 +08:00
liu.zixi
a811b675e7 [DAT] 打日志查看 2025-10-31 10:36:58 +08:00
liu.zixi
1f28daedc5 [DAT] 新增失败时发邮件 2025-10-31 10:36:57 +08:00
liu.zixi
147b74d99c [DAT] 批处理更改responseBody 2025-10-31 10:36:56 +08:00
liu.zixi
4b0a5a8761 [DAT] 去掉com.sun.mail依赖 2025-10-31 10:36:54 +08:00
liu.zixi
b90da03486 [DAT] 发送邮件实现方式再次修改 2025-10-31 10:36:53 +08:00
liu.zixi
4c8e228fa2 [DAT] 发送邮件实现方式修改 2025-10-31 10:36:51 +08:00
liu.zixi
a0a22ead1b [DAT] 调用时间查询逻辑修改 2025-10-31 10:36:50 +08:00
liu.zixi
8a03b3a983 [DAT] 修改update方法调试 2025-10-31 10:36:49 +08:00
liu.zixi
f864e8ba66 [DAT] 删除时修改数据查询条件 2025-10-31 10:36:48 +08:00
liu.zixi
5c4234a3b7 [DAT] 修改update方法只删除不上传的错误 2025-10-31 10:36:46 +08:00
liu.zixi
27c84faa48 [DAT] 照原型数据更新 2025-10-31 10:36:45 +08:00
liu.zixi
0304fc10f1 DAT测试配合 2025-10-31 10:36:44 +08:00
liu.zixi
a12c1f410b 案例专家:增加部分情况下的日志记录 2025-10-31 10:36:42 +08:00
liu.zixi
7b08d26da6 案例专家:修正调用逻辑 2025-10-31 10:36:41 +08:00
liu.zixi
d143ceeb4c 案例专家:新数据处理 2025-10-31 10:36:40 +08:00
liu.zixi
45192a3140 换日志级别,调试 2025-10-31 10:36:38 +08:00
liu.zixi
98f4356a49 延长 Spring Boot 异步请求超时 2025-10-31 10:36:37 +08:00
liu.zixi
8f0b579f6b okhttp的超时时长调到300秒 2025-10-31 10:36:36 +08:00
liu.zixi
6a8a9e5c87 整理es相关代码;增加手动调试用接口 2025-10-31 10:36:34 +08:00
liu.zixi
1898252fc1 案例专家:是否深度思考做成入参,先关闭思考 2025-10-31 10:36:33 +08:00
liu.zixi
cb448a09a3 案例专家:es修改索引格式、添加event-stream专属线程池 2025-10-31 10:36:32 +08:00
liu.zixi
c48c0a0f86 案例专家:yml中的用户列表加双引号 2025-10-31 10:36:31 +08:00
liu.zixi
cb103442e7 案例专家:修改白名单校验逻辑 2025-10-31 10:36:29 +08:00
liu.zixi
24bc40b6ec 案例专家:修改yml文件一个配置的写法 2025-10-31 10:36:28 +08:00
liu.zixi
d75dc2b7b5 案例专家:日志等级修改 2025-10-31 10:36:26 +08:00
liu.zixi
75478cbda7 案例专家:增加手动刷新索引功能 2025-10-31 10:36:25 +08:00
liu.zixi
bf555b1070 案例专家:userId更换成code 2025-10-31 10:36:24 +08:00
liu.zixi
8ae8a650fd 案例专家:userId更换成code 2025-10-31 10:36:23 +08:00
liu.zixi
f7f7a928b2 案例专家:打印入参,调试用 2025-10-31 10:36:22 +08:00
liu.zixi
f465c39b83 案例专家:修改log等级,观察联调 2025-10-31 10:36:20 +08:00
liu.zixi
a2f65a8a29 案例专家:修改批处理问题 2025-10-31 10:36:18 +08:00
liu.zixi
28c3812260 案例专家:邮件告警逻辑 2025-10-31 10:36:17 +08:00
liu.zixi
fa125b29cc 批处理:JobHandler开发 2025-10-31 10:36:15 +08:00
liu.zixi
f35ab10bd2 批处理:JobHandler开发 2025-10-31 10:36:14 +08:00
liu.zixi
d0af06b572 案例助手:代码整理和部分问题修复 2025-10-31 10:36:12 +08:00
liu.zixi
5610289893 案例助手:修复找不到旧会话的bug 2025-10-31 10:36:11 +08:00
liu.zixi
b4103bd4e5 案例助手:聊天接口兼容application/json 2025-10-31 10:36:10 +08:00
liu.zixi
72399eff18 案例助手:增加@Transactional注解 2025-10-31 10:36:08 +08:00
liu.zixi
952301b095 案例助手:增加字段,增加白名单机制等 2025-10-31 10:36:07 +08:00
liu.zixi
0eff0123ca 案例助手:聊天增加上传时间和企业信息 2025-10-31 10:36:05 +08:00
liu.zixi
4d3d4978aa 修复清空日志的bug 2025-10-31 10:36:03 +08:00
liu.zixi
abb036d769 三方接口异步处理 2025-10-31 10:36:02 +08:00
liu.zixi
fe2422574c 返回conversationId 2025-10-31 10:36:00 +08:00
liu.zixi
efe17f3b72 文件读取逻辑纠正 2025-10-31 10:35:58 +08:00
liu.zixi
1aa804118e 修正AI接口的数据入库逻辑 2025-10-31 10:35:56 +08:00
liu.zixi
bd2b372333 修改不同环境回调地址 2025-10-31 10:35:54 +08:00
liu.zixi
8ba8651988 修正编译错误 2025-10-31 10:35:53 +08:00
liu.zixi
ece950fddc 修正编译错误;
增加临时接口
2025-10-31 10:35:52 +08:00
liu.zixi
622c3bdd5b AI调用日志 重试功能补完 2025-10-31 10:35:50 +08:00
liu.zixi
278336c9f7 案例专家功能提交 2025-10-31 10:35:49 +08:00
670788339
264a581df8 Merge branch 'master-20251023-tag' into test1031
# Conflicts:
#	servers/boe-server-all/src/main/java/com/xboe/module/course/api/CourseManageApi.java
#	servers/boe-server-all/src/main/java/com/xboe/module/course/service/impl/CourseServiceImpl.java
2025-10-31 10:20:09 +08:00
670788339
0979d26160 提审加日志 2025-10-31 09:37:25 +08:00
670788339
ddd8875b11 查询标签加日志 2025-10-30 20:20:10 +08:00
670788339
d5a1d65769 查询标签加日志 2025-10-30 19:55:40 +08:00
670788339
612410e863 合并标签 2025-10-30 18:37:50 +08:00
670788339
11628b35e2 合并标签 2025-10-30 18:18:54 +08:00
670788339
f799b6065e 合并标签 2025-10-30 18:06:14 +08:00
670788339
61e753e6db 合并标签 2025-10-30 17:59:01 +08:00
670788339
841aa47b4a 标签加status 2025-10-30 16:08:51 +08:00
Caojr
20e3b001d5 szx-1277 增加boe_course_teacher删除记录逻辑 2025-10-30 14:37:40 +08:00
670788339
2527e081d9 创建标签添加日志 2025-10-30 14:34:41 +08:00
670788339
9c529a061e 创建标签 2025-10-30 14:01:37 +08:00
670788339
15e0cedf74 创建标签 2025-10-30 13:23:51 +08:00
Caojr
a37f90aeaa szx-1277 增加参数 2025-10-30 12:08:59 +08:00
Caojr
e767345c1e szx-1277 hrbp审核接口修改course服务调用接 2025-10-30 11:45:21 +08:00
670788339
46fefd3fe0 searchTags调试 2025-10-29 17:20:18 +08:00
670788339
448bc0f1e4 searchTags调整 2025-10-29 16:29:15 +08:00
670788339
5d3745680a searchTags调整 2025-10-29 16:17:58 +08:00
670788339
c7c92a3173 searchTags调整 2025-10-29 15:58:01 +08:00
670788339
0819502afa searchTags调整 2025-10-29 15:40:58 +08:00
Caojr
6fe6f7c6e5 临时注释多余的completeStatus接口调用 2025-10-10 10:15:11 +08:00
王卓煜
8c02b77724 标签管理解绑标签 2025-09-16 13:51:52 +08:00
王卓煜
e7036e04b0 修复标签管理三级分类搜索不到标签 2025-09-12 11:13:31 +08:00
王卓煜
95d1b90717 修复标签管理课程类型展示对应的标签 2025-09-12 10:07:37 +08:00
王卓煜
4d320ea855 修复缺少tags属性 2025-09-02 13:34:57 +08:00
王卓煜
acb58cf9d6 修复标签不开启公共化 2025-08-27 17:03:37 +08:00
王卓煜
6a04e5d58c 修复标签模块查询不显示以及新建标签 2025-08-22 15:11:14 +08:00
王卓煜
0e60251121 修复目前先按照精准匹配的逻辑,未来将开放语义匹配(向量搜索)等高级搜索功能。 2025-08-21 13:32:21 +08:00
王卓煜
9588235f87 修复前台热点标签10个位置,从热点池中选取前10,筛选和排序规则:1)手动标记热点的标签按标记时间倒序排列 2)关联课程数量>4门的标签,按关联课程数量多少倒序排列。如1)和2)合计不足10个,则前台根据实际数量显示。 2025-08-21 09:36:49 +08:00
王卓煜
7074255e94 修复管理端在线课程添加标签没有传递数据 2025-08-20 17:40:50 +08:00
王卓煜
f821112715 修复管理端在线课程添加标签没有传递数据 2025-08-20 17:26:25 +08:00
王卓煜
41649aa32d 修复管理端在线课程添加标签没有传递数据 2025-08-20 17:22:08 +08:00
王卓煜
6dc4e36222 修复当同一标签被3个及以上课管创建时,默认开启这个标签的公共化,同时标签管理员也可以手动关闭 2025-08-20 14:44:31 +08:00
zhengsongbo
5aba4ef45f zhengsongbo:标签管理第一次提测 on 2025-08-02 2025-08-02 12:48:57 +08:00
56 changed files with 2350 additions and 2206 deletions

View File

@@ -1,39 +0,0 @@
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;
}
}

View File

@@ -65,24 +65,6 @@ public class ThreadPoolConfig {
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());

View File

@@ -7,8 +7,4 @@ public class CaseAiConstants {
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 = "网络异常,请稍后再试。";
}

View File

@@ -1,33 +0,0 @@
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);
}
}

View File

@@ -1,7 +1,6 @@
package com.xboe.module.assistance.service.impl;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import javax.mail.Authenticator;
@@ -23,13 +22,12 @@ import com.xboe.module.assistance.service.ISmtpEmailService;
@Slf4j
public class SmtpEmailServiceImpl implements ISmtpEmailService {
//region 默认SMTP服务器配置信息
// 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_PASSWORD = "boeLms20250814Syse";
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 {
@@ -45,7 +43,6 @@ public class SmtpEmailServiceImpl implements ISmtpEmailService {
if (StringUtils.isBlank(htmlMsg)) {
throw new Exception("发送邮件失败,未指定邮件内容");
}
// 初始化配置项
// 设置SMTP属性
Properties props = new Properties();

View File

@@ -3,9 +3,6 @@ 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;
@@ -19,14 +16,12 @@ 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")
@Slf4j
@RestController
@RequestMapping(value = "/xboe/m/boe/case/ai")
public class CaseAiChatApi extends ApiBaseController {
@@ -61,84 +56,7 @@ public class CaseAiChatApi extends ApiBaseController {
// 获取当前用户
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
@@ -155,22 +73,6 @@ public class CaseAiChatApi extends ApiBaseController {
}
}
/**
* 导出会话记录为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 是否显示功能入口
@@ -180,10 +82,7 @@ public class CaseAiChatApi extends ApiBaseController {
try {
String currentUserCode = getCurrent().getCode();
boolean shouldShow = caseAiPermissionService.shouldShowCaseAiEntrance(currentUserCode);
// return success(shouldShow);
JsonResponse<Boolean> result = success(shouldShow);
result.setMessage(currentUserCode);
return result;
return success(shouldShow);
} catch (Exception e) {
log.error("判断案例专家功能入口显示权限异常", e);
return error("判断失败", e.getMessage());
@@ -208,17 +107,6 @@ public class CaseAiChatApi extends ApiBaseController {
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,
@@ -235,4 +123,4 @@ public class CaseAiChatApi extends ApiBaseController {
}
return error("创建失败");
}
}
}

View File

@@ -1,6 +1,5 @@
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;
@@ -21,21 +20,14 @@ public class CaseUploadTaskApi {
@Autowired
private StringRedisTemplate stringRedisTemplate;
private static final String CASE_UPLOAD_LAST_ID_KEY = "case:upload:last:id";
/**
* 清除处理位置标记,使下次任务从头开始执行
*/
@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);
stringRedisTemplate.delete(CASE_UPLOAD_LAST_ID_KEY);
log.info("已清除上次处理位置标记");
}
}

View File

@@ -17,11 +17,6 @@ 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;
@@ -32,7 +27,7 @@ public class CaseAiDocumentAsyncHandler {
public void process(CaseDocumentLogOptTypeEnum optTypeEnum, Cases... caseList) {
for (Cases cases : caseList) {
// 控制并发数量
while (currentTaskCount.get() >= 5) {
while (currentTaskCount.get() >= 15) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
@@ -44,13 +39,8 @@ public class CaseAiDocumentAsyncHandler {
currentTaskCount.incrementAndGet();
aiDocExecutor.submit(() -> {
try {
// 限流
rateLimiter.acquire();
processCases(cases, optTypeEnum);
} finally {
currentTaskCount.decrementAndGet();
}
processCases(cases, optTypeEnum);
currentTaskCount.decrementAndGet();
});
}
}

View File

@@ -1,55 +0,0 @@
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;
}
}

View File

@@ -1,32 +0,0 @@
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;
}

View File

@@ -1,49 +0,0 @@
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;
}
}

View File

@@ -1,16 +0,0 @@
package com.xboe.module.boecase.dto;
import lombok.Data;
@Data
public class GetCaseAiMsgDto {
/**
* 会话Id
*/
private String conversationId;
/**
* ES DocId
*/
private String docId;
}

View File

@@ -34,19 +34,6 @@ public class AiChatConversationData {
*/
private StringBuilder answer = new StringBuilder();
/**
* 状态
* 0-正常
* 1-系统错误
* 2-AIoT平台错误
*/
private Integer status;
/**
* 错误信息
*/
private String errorMsg;
/**
* 案例引用列表
*/
@@ -57,20 +44,6 @@ public class AiChatConversationData {
*/
private List<String> suggestions = new ArrayList<>();
/**
* 用户点赞状态
* -1: 踩
* 1
* 0/null 无操作
*/
private String likeStatus;
/**
* 用户踩的时候, 可以填写反馈意见
* 反馈意见
*/
private String feedback;
/**
* 用户ID
*/
@@ -81,27 +54,28 @@ public class AiChatConversationData {
*/
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();
this.timestamp = LocalDateTime.now();
}
public AiChatConversationData(String conversationId, String query, String answer,
List<CaseReferVo> caseRefers, List<String> suggestions,
String userId) {
this.conversationId = conversationId;
this.query = query;
this.answer = new StringBuilder(answer != null ? answer : "");
this.caseRefers = caseRefers != null ? caseRefers : new ArrayList<>();
this.suggestions = suggestions != null ? suggestions : new ArrayList<>();
this.userId = userId;
this.timestamp = LocalDateTime.now();
}
// ================== 便捷方法 ==================

View File

@@ -93,12 +93,4 @@ public class CaseDocumentLog extends BaseEntity {
*/
@Column(name = "execute_duration")
private Long executeDuration;
/**
* 元数据处理状态
* 0-未处理
* 1-已处理
*/
@Column(name = "metadata_status")
private Integer metadataStatus;
}

View File

@@ -1,27 +0,0 @@
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);
}
}

View File

@@ -48,11 +48,6 @@ public class CaseAiProperties {
*/
private String defaultUploadUser;
/**
* 案例详情页面地址
*/
private String caseDetailUrlBase;
/**
* 文件上传是否使用回调接口
*/
@@ -77,14 +72,4 @@ public class CaseAiProperties {
* AI处理失败告警邮件收件人列表
*/
private List<String> alertEmailRecipients;
/**
* 是否发送AI对话记录到邮箱
*/
private boolean aiChatDataSendEmail;
/**
* AI对话记录保存根路径
*/
private String aiChatRootPath;
}

View File

@@ -2,14 +2,10 @@ 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;
/**
@@ -19,7 +15,6 @@ public interface ICaseAiChatService {
/**
* 聊天
*
* @param caseAiChatDto
* @param currentUser
* @return
@@ -28,8 +23,7 @@ public interface ICaseAiChatService {
/**
* 创建新的AI对话会话
*
* @param userId 用户ID
* @param userId 用户ID
* @param conversationName 对话名称
* @return 创建的会话信息
*/
@@ -37,56 +31,8 @@ public interface ICaseAiChatService {
/**
* 根据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);
}

View File

@@ -4,7 +4,6 @@ import com.xboe.module.boecase.entity.AiChatConversationData;
import com.xboe.module.boecase.vo.CaseAiMessageVo;
import java.util.List;
import java.util.Map;
/**
* es索引
@@ -13,29 +12,24 @@ public interface IElasticSearchIndexService {
/**
* 查看索引是否存在
* @param indexName
* @return
*/
boolean checkIndexExists();
/**
* 创建索引
* @param indexName
*/
boolean createIndex();
/**
* 删除索引
* @param indexName
* @return
*/
boolean deleteIndex();
/**
* 更新索引:添加索引字段
* @param fieldName
* @param fieldProperties
* @return
*/
boolean updateIndex(String fieldName, Map<String, Object> fieldProperties);
/**
* 新增数据
* @param data
@@ -49,20 +43,4 @@ public interface IElasticSearchIndexService {
* @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);
}

View File

@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
@EnableConfigurationProperties({CaseAiProperties.class})
@Service
@Slf4j(topic = "caseAiChatLogger")
@Slf4j
public class AiAccessTokenServiceImpl implements IAiAccessTokenService {
private static final String ACCESS_TOKEN_CACHE_KEY = "case_ai_access_token";

View File

@@ -2,18 +2,12 @@ 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.core.CurrentUser;
import com.xboe.core.orm.FieldFilters;
import com.xboe.enums.CaseAiChatErrCodeEnum;
import com.xboe.enums.CaseAiChatStatusEnum;
import com.xboe.module.boecase.dao.CaseAiConversationsDao;
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
import com.xboe.module.boecase.dao.CasesDao;
import com.xboe.module.boecase.dto.CaseAiChatDto;
import com.xboe.module.boecase.dto.GetCaseAiMsgDto;
import com.xboe.module.boecase.entity.AiChatConversationData;
import com.xboe.module.boecase.dto.CaseAiMsgLikeDto;
import com.xboe.module.boecase.entity.CaseAiConversations;
import com.xboe.module.boecase.entity.CaseDocumentLog;
import com.xboe.module.boecase.entity.Cases;
@@ -23,7 +17,7 @@ import com.xboe.module.boecase.service.ICaseAiChatService;
import com.xboe.module.boecase.service.IElasticSearchIndexService;
import com.xboe.module.boecase.vo.CaseAiMessageVo;
import com.xboe.module.boecase.vo.CaseReferVo;
import com.xboe.module.boecase.vo.ConversationExcelVo;
import com.xboe.module.boecase.entity.AiChatConversationData;
import com.xboe.system.organization.vo.OrgSimpleVo;
import com.xboe.system.user.service.IUserService;
import lombok.extern.slf4j.Slf4j;
@@ -31,57 +25,49 @@ import okhttp3.*;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;
import okhttp3.sse.EventSources;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
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.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.SearchHit;
import org.elasticsearch.search.SearchHits;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.jms.JmsException;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import javax.jms.Topic;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
@EnableConfigurationProperties({CaseAiProperties.class})
@Service
@Slf4j(topic = "caseAiChatLogger")
@Slf4j
public class CaseAiChatServiceImpl implements ICaseAiChatService {
@Autowired
private CaseAiProperties caseAiProperties;
@Autowired
@Qualifier("esChatExecutor")
private ThreadPoolTaskExecutor esChatExecutor;
@Autowired
@Qualifier("customDispatcher")
private Dispatcher dispatcher;
@@ -104,44 +90,14 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
@Autowired
private CasesDao casesDao;
@Autowired
private JmsTemplate jmsTemplate;
@Autowired
private Topic topic;
// 用于存储会话ID与EventSource的映射关系以便能够中断特定会话
private final Map<String, EventSource> conversationEventSourceMap = new ConcurrentHashMap<>();
@Override
@Transactional
public SseEmitter chat(CaseAiChatDto caseAiChatDto, CurrentUser currentUser) {
// 创建SSE响应器
SseEmitter sseEmitter = new SseEmitter();
// 1. 获取conversationId
String conversationId;
try {
conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
} catch (Exception e) {
log.error("获取会话ID失败", e);
errMessage(sseEmitter, null, CaseAiConstants.CHAT_SYS_ERR_MSG);
sseEmitter.complete();
return sseEmitter;
}
// 2. 查询历史
List<CaseAiMessageVo> historyMessages = elasticSearchIndexService.queryData(conversationId);
String conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
// 3. 构建请求参数
String userId = currentUser.getCode();
// 6. 用于收集对话数据的容器
AiChatConversationData conversationData = new AiChatConversationData();
conversationData.setQuery(caseAiChatDto.getQuery());
conversationData.setConversationId(conversationId);
conversationData.setUserId(userId);
conversationData.setStatus(CaseAiChatErrCodeEnum.SUCCESS.getCode());
String kId = caseAiProperties.getCaseKnowledgeId();
JSONObject chatParam = new JSONObject();
chatParam.put("userId", userId);
@@ -151,48 +107,11 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
chatParam.put("query", caseAiChatDto.getQuery());
chatParam.put("conversationId", conversationId);
chatParam.put("enableThinking", Objects.equals(caseAiChatDto.getEnableThinking(), 1));
if (historyMessages != null && !historyMessages.isEmpty()) {
// 最多10条历史从后往前
JSONArray historyList = new JSONArray();
int size = historyMessages.size();
int startIndex = Math.max(0, size - 10);
for (int i = startIndex; i < size; i++) {
JSONObject conversationDetail = new JSONObject();
CaseAiMessageVo message = historyMessages.get(i);
conversationDetail.put("query", message.getQuery());
conversationDetail.put("content", message.getAnswer());
historyList.add(conversationDetail);
}
chatParam.put("historyList", historyList);
}
String chatParamStr = chatParam.toJSONString();
log.info("案例问答接口请求参数: [{}]", chatParamStr);
// 4. 设置请求头
String accessToken;
try {
accessToken = aiAccessTokenService.getAccessToken();
if (org.apache.commons.lang3.StringUtils.isBlank(accessToken)) {
errMessage(sseEmitter, conversationId, CaseAiConstants.CHAT_SYS_ERR_MSG);
// 先响应给前端
sseEmitter.complete();
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
conversationData.setErrorMsg("获取AccessToken时发生异常");
conversationData.appendAnswer(CaseAiConstants.CHAT_SYS_ERR_MSG);
saveConversationData(conversationData);
return sseEmitter;
}
} catch (Exception e) {
log.error("获取access_token失败", e);
errMessage(sseEmitter, conversationId, CaseAiConstants.CHAT_SYS_ERR_MSG);
// 先响应给前端
sseEmitter.complete();
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
conversationData.setErrorMsg("获取AccessToken时发生异常" + e.getMessage());
conversationData.appendAnswer(CaseAiConstants.CHAT_SYS_ERR_MSG);
saveConversationData(conversationData);
return sseEmitter;
}
String accessToken = aiAccessTokenService.getAccessToken();
String apiCode = caseAiProperties.getChatApiCode();
Request.Builder builder = new Request.Builder();
builder.url(caseAiProperties.getBaseUrl() + "/apigateway/chat/knowledge/v1/chat/completions");
@@ -201,104 +120,68 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
RequestBody bodyRequestBody = RequestBody.create(chatParamStr, MediaType.parse("application/json"));
builder.post(bodyRequestBody);
Request request = builder.build();
// 5. 创建SSE响应器
SseEmitter sseEmitter = new SseEmitter();
// 6. 用于收集对话数据的容器
AiChatConversationData conversationData = new AiChatConversationData();
conversationData.setQuery(caseAiChatDto.getQuery());
conversationData.setConversationId(conversationId);
conversationData.setUserId(userId);
// 7. 创建事件监听器
EventSourceListener listener = new EventSourceListener() {
@Override
public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
log.info("调用接口 [{}] 接口开始监听", request.url());
// 检查contentType
String contentType = response.header("Content-Type");
if (contentType == null || !contentType.contains("text/event-stream")) {
// 服务器返回的不是SSE流需要额外处理
log.error("调用接口 [{}] 返回的Content-Type不是text/event-stream实际ContentType: {}", request.url(), contentType);
String sseContent;
try {
ResponseBody responseBody = response.body();
if (responseBody == null) {
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
} else {
String responseBodyStr = responseBody.string();
log.error("调用 [{}] 返回值: {}", request.url(), responseBodyStr);
// 判断是否为json
if (contentType != null && contentType.contains("application/json")) {
JSONObject responseData = JSONObject.parseObject(responseBodyStr);
if (responseData.containsKey("message") && StringUtils.isNotBlank(responseData.getString("message"))) {
sseContent = responseData.getString("message");
} else {
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
}
} else {
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
}
}
} catch (IOException e) {
log.error("解析接口响应失败", e);
// 处理失败的情况
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
}
errMessage(sseEmitter, conversationId, sseContent);
sseEmitter.complete();
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
conversationData.setErrorMsg(sseContent);
conversationData.appendAnswer(sseContent);
saveConversationData(conversationData);
// 关闭eventSource
eventSource.cancel();
return;
}
// 将EventSource存储到Map中以便后续可以中断
conversationEventSourceMap.put(conversationId, eventSource);
}
@Override
public void onClosed(@NotNull EventSource eventSource) {
log.info("调用接口 [{}] 接口关闭", request.url());
// 对话完成保存到ES
saveConversationData(conversationData);
// 从Map中移除已完成的会话
conversationEventSourceMap.remove(conversationId);
elasticSearchIndexService.createData(conversationData);
sseEmitter.complete();
}
@Override
public void onEvent(@NotNull EventSource eventSource, @Nullable String id, @Nullable String type, @NotNull String data) {
log.info("调用接口 [{}] 监听数据 id: [{}] type: [{}] data: [{}]", request.url(), id, type, data);
try {
// 解析返回的数据
JSONObject jsonData = JSONObject.parseObject(data);
if (jsonData.getBooleanValue("success") && jsonData.getIntValue("code") == 0) {
JSONObject responseData = jsonData.getJSONObject("data");
Integer status = responseData.getInteger("status");
if (status != null) {
CaseAiChatStatusEnum statusEnum = CaseAiChatStatusEnum.getByCode(status);
if (statusEnum == CaseAiChatStatusEnum.REFERS) { // 返回引用文件
// 处理文件引用并构建返给前端的数据
JSONObject modifiedData = handleFileReferAndBuildResponse(responseData, conversationData);
if (modifiedData != null) {
// 发送修改后的数据给前端
sseEmitter.send(modifiedData.toJSONString());
return; // 早期返回,不发送原始数据
}
} else if (statusEnum == CaseAiChatStatusEnum.CHAT) { // 流式对话中
String content = responseData.getString("content");
if (content != null) {
conversationData.appendAnswer(content);
}
} else if (statusEnum == CaseAiChatStatusEnum.SUGGESTIONS) { // 返回建议
handleSuggestions(responseData, conversationData);
} else if (statusEnum == CaseAiChatStatusEnum.CHAT_COMPLETED || statusEnum == CaseAiChatStatusEnum.API_COMPLETED) { // 接口交互完成
// 不做特殊处理
} else {
// 异常问题取message内容
String message = jsonData.getString("message");
errMessage(sseEmitter, conversationId, message);
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
conversationData.setErrorMsg(jsonData.toJSONString());
return;
switch (statusEnum) {
case REFERS: // 返回引用文件
// 处理文件引用并构建返给前端的数据
JSONObject modifiedData = handleFileReferAndBuildResponse(responseData, conversationData);
if (modifiedData != null) {
// 发送修改后的数据给前端
sseEmitter.send(modifiedData.toJSONString());
return; // 早期返回,不发送原始数据
}
break;
case CHAT: // 流式对话中
String content = responseData.getString("content");
if (content != null) {
conversationData.appendAnswer(content);
}
break;
case SUGGESTIONS: // 返回建议
handleSuggestions(responseData, conversationData);
break;
case CHAT_COMPLETED:
case API_COMPLETED: // 接口交互完成
default:
// 不做特殊处理
break;
}
}
sseEmitter.send(responseData.toJSONString());
@@ -319,53 +202,26 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
@Override
public void onFailure(@NotNull EventSource eventSource, @Nullable Throwable e, @Nullable Response response) {
// 只要有异常,必打日志
log.error("调用接口 [{}] 接口异常", request.url(), e);
// 如果是 content-type 错误,尝试作为普通 HTTP 请求处理
if (e instanceof IllegalStateException && e.getMessage() != null && e.getMessage().contains("Invalid content-type")) {
log.warn("服务器返回的 Content-Type 不是 text/event-stream尝试作为普通 HTTP 请求处理");
CaseAiChatServiceImpl.this.handleAsRegularHttpRequest(request, sseEmitter, conversationData);
return;
}
if (e != null) {
log.error("调用接口 [{}] 时发生错误,捕获到异常", request.url(), e);
sseEmitter.completeWithError(e);
} else {
log.error("调用接口 [{}] 时发生错误,未捕获到异常", request.url());
sseEmitter.completeWithError(new RuntimeException("调用接口异常, 异常未捕获"));
}
String errorMessage = CaseAiConstants.CHAT_SYS_ERR_MSG;
// 优先处理错误响应
if (response != null) {
try {
log.error("调用接口 [{}] 时发生错误,响应码: {}", request.url(), response.code());
if (response.body() != null) {
String body = response.body().string();
log.error("调用接口 [{}] 时的错误响应内容: {}", request.url(), body);
// 将错误内容发送至SseEmitter
if (StringUtils.contains(response.header("Content-Type"), "application/json")) {
// json解析
JSONObject jsonData = JSONObject.parseObject(body);
if (jsonData.containsKey("message") && StringUtils.isNotBlank(jsonData.getString("message"))) {
errorMessage = jsonData.getString("message");
}
}
}
} catch (IOException ex) {
log.error("解析异常请求时错误", ex);
}
} else if (e != null) {
if (isTimeoutException(e)) {
errorMessage = CaseAiConstants.CHAT_NET_ERR_MSG;
}
}
errMessage(sseEmitter, conversationId, errorMessage);
sseEmitter.complete();
// 从Map中移除失败的会话
conversationEventSourceMap.remove(conversationId);
// 即使失败也要将已有的对话数据保存到ES
conversationData.setStatus(CaseAiChatErrCodeEnum.AIOT_ERROR.getCode());
conversationData.setErrorMsg(errorMessage);
conversationData.appendAnswer(errorMessage);
saveConversationData(conversationData);
}
};
// 8. 执行HTTP请求
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(600, TimeUnit.SECONDS)
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(600, TimeUnit.SECONDS)
.readTimeout(600, TimeUnit.SECONDS)
.callTimeout(600, TimeUnit.SECONDS)
@@ -373,16 +229,16 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
.build();
EventSource.Factory factory = EventSources.createFactory(client);
factory.newEventSource(request, listener);
return sseEmitter;
}
/**
* 获取或创建会话ID
*/
private String getOrCreateConversationId(CaseAiChatDto caseAiChatDto, CurrentUser currentUser) {
String conversationId = caseAiChatDto.getConversationId();
if (StringUtils.isEmpty(conversationId)) {
// 新会话,调用创建会话接口
String conversationName = "AI案例咨询-" + LocalDateTime.now().toString();
@@ -400,39 +256,39 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
String url = caseAiProperties.getBaseUrl() + "/apigateway/knowledge/v1/conversation";
HttpPost httpPost = new HttpPost(url);
// 设置请求头
String accessToken = aiAccessTokenService.getAccessToken();
String apiCode = caseAiProperties.getChatApiCode();
httpPost.setHeader("access_token", accessToken);
httpPost.setHeader("X-AI-ApiCode", apiCode);
httpPost.setHeader("Content-Type", "application/json");
// 设置请求体
JSONObject requestBody = new JSONObject();
requestBody.put("userId", userId);
requestBody.put("name", conversationName);
StringEntity entity = new StringEntity(requestBody.toJSONString(), StandardCharsets.UTF_8);
httpPost.setEntity(entity);
try (CloseableHttpResponse response = httpClient.execute(httpPost)) {
int statusCode = response.getStatusLine().getStatusCode();
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
if (statusCode == 200) {
JSONObject result = JSONObject.parseObject(responseBody);
if (result.getIntValue("code") == 0 && result.getBooleanValue("success")) {
JSONObject data = result.getJSONObject("data");
String aiConversationId = data.getString("id");
String name = data.getString("name");
// 保存到数据库
CaseAiConversations conversation = new CaseAiConversations();
conversation.setAiConversationId(aiConversationId);
conversation.setConversationName(name);
conversation.setConversationUser(userId);
caseAiConversationsDao.save(conversation);
log.info("创建AI会话成功aiConversationId: {}, name: {}", aiConversationId, name);
return conversation;
} else {
@@ -458,101 +314,55 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
}
return elasticSearchIndexService.queryData(conversationId);
}
@Override
public void getConversationExcel(LocalDateTime startTime, LocalDateTime endTime, HttpServletResponse response) {
Workbook workbook = getChatMessageExcel(startTime, endTime);
// 写入response.getOutputStream()
try (OutputStream out = response.getOutputStream()) {
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=chat_message.xlsx");
workbook.write(out);
out.flush();
} catch (Exception e) {
log.error("导出Excel异常", e);
}
}
@Override
public void downloadConversationExcel(LocalDateTime startTime, LocalDateTime endTime) {
Workbook workbook = getChatMessageExcel(startTime, endTime);
// 创建Excel文件并保存
if (caseAiProperties.isAiChatDataSendEmail()) {
// TODO 发送邮件附件
} else {
// 保存文件
String dirPath = caseAiProperties.getAiChatRootPath() + File.separator + startTime.format(DateTimeFormatter.ofPattern("yyyyMM"));
Path dir = Paths.get(dirPath);
if (!Files.exists(dir)) {
try {
Files.createDirectories(dir);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
String fileName = "AI会话数据-" + startTime.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + "-" + System.currentTimeMillis() + ".xlsx";
Path filePath = dir.resolve(fileName);
try (OutputStream out = Files.newOutputStream(filePath)) {
workbook.write(out);
out.flush();
} catch (IOException e) {
log.error("保存文件错误", e);
}
}
}
/**
* 从 ES 数据中解析消息对象
* 已迁移
* @see IElasticSearchIndexService
*
* @param sourceMap ES数据
* @return 消息对象
*/
@Deprecated
private CaseAiMessageVo parseMessageFromES(Map<String, Object> sourceMap) {
try {
CaseAiMessageVo messageVo = new CaseAiMessageVo();
messageVo.setQuery((String) sourceMap.get("query"));
messageVo.setAnswer((String) sourceMap.get("answer"));
// 解析 suggestions
Object suggestionsObj = sourceMap.get("suggestions");
if (suggestionsObj instanceof List) {
messageVo.setSuggestions((List<String>) suggestionsObj);
}
// 解析 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);
}
return messageVo;
} catch (Exception e) {
log.error("解析ES消息数据异常", e);
return null;
}
}
/**
* 处理文件引用并构建返给前端的响应数据
*/
@@ -561,7 +371,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
// 先处理文件引用收集CaseReferVo数据
List<CaseReferVo> currentCaseRefers = new ArrayList<>();
Set<String> docIds = new HashSet<>();
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
if (fileRefer != null && fileRefer.containsKey("files")) {
JSONArray files = fileRefer.getJSONArray("files");
@@ -579,13 +389,13 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
}
}
}
// 构建返给前端的数据结构
JSONObject data = new JSONObject();
data.put("status", 0);
data.put("conversationId", conversationData.getConversationId());
data.put("content", responseData.getString("content"));
// 添加处理后的案例引用数据
JSONArray caseReferArray = new JSONArray();
for (CaseReferVo caseRefer : currentCaseRefers) {
@@ -601,11 +411,11 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
caseReferArray.add(caseReferObj);
}
// 构建新的fileRefer结构包含案例引用
JSONObject newFileRefer = new JSONObject();
newFileRefer.put("caseRefers", caseReferArray);
// 保留原始的docs和files信息如果需要
if (fileRefer != null) {
if (fileRefer.containsKey("docs")) {
@@ -615,23 +425,22 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
newFileRefer.put("files", fileRefer.get("files"));
}
}
data.put("fileRefer", newFileRefer);
data.put("suggestions", responseData.get("suggestions"));
log.info("处理文件引用成功,返回 {} 个案例引用", currentCaseRefers.size());
return data;
} catch (Exception e) {
log.error("处理文件引用并构建响应数据异常", e);
return null;
}
}
/**
* 处理文件引用(原方法,保留用于数据收集)
*/
@Deprecated
private void handleFileRefer(JSONObject responseData, AiChatConversationData conversationData) {
try {
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
@@ -653,7 +462,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
log.error("处理文件引用异常", e);
}
}
/**
* 处理建议
*/
@@ -672,7 +481,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
log.error("处理建议异常", e);
}
}
/**
* 根据docId查询案例引用信息
*/
@@ -683,7 +492,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
if (docLog == null) {
return null;
}
// 根据 case_id 查询案例详情
Cases caseEntity = casesDao.get(docLog.getCaseId());
if (caseEntity == null) {
@@ -700,7 +509,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
caseRefer.setContent(caseEntity.getSummary());
caseRefer.setUploadTime(caseEntity.getSysCreateTime());
caseRefer.setOrgInfo(authorOrg.getName());
// 构建关键词列表
List<String> keywords = new ArrayList<>();
if (caseEntity.getKeyword1() != null) keywords.add(caseEntity.getKeyword1());
@@ -709,19 +518,17 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
if (caseEntity.getKeyword4() != null) keywords.add(caseEntity.getKeyword4());
if (caseEntity.getKeyword5() != null) keywords.add(caseEntity.getKeyword5());
caseRefer.setKeywords(keywords);
return caseRefer;
} catch (Exception e) {
log.error("根据docId查询案例引用信息异常", e);
return null;
}
}
/**
* 当 SSE 失败时,作为普通 HTTP 请求处理
* 不再使用
*/
@Deprecated
private void handleAsRegularHttpRequest(Request request, SseEmitter sseEmitter, AiChatConversationData conversationData) {
try {
OkHttpClient client = new OkHttpClient.Builder()
@@ -729,19 +536,13 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.build();
Response response = client.newCall(request).execute();
if (response.isSuccessful()) {
String responseBody = response.body().string();
log.info("作为普通 HTTP 请求处理成功,将响应原封不动推送给前端");
// 将响应内容原封不动地推送到 SseEmitter
JSONObject responseData = JSONObject.parseObject(responseBody);
if (responseBody.contains("message")) {
errMessage(sseEmitter, conversationData.getConversationId(), responseData.getString("message"));
sseEmitter.complete();
return;
}
sseEmitter.send(responseBody);
sseEmitter.complete();
} else {
@@ -753,259 +554,9 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
sseEmitter.completeWithError(e);
}
}
/**
* 发送错误信息
* 对话数据容器
*/
private void errMessage(SseEmitter sseEmitter, String conversationId, String message) {
JSONObject conversationData = new JSONObject();
conversationData.put("conversationId", conversationId);
conversationData.put("content", "");
conversationData.put("status", 0);
JSONObject jsonData = new JSONObject();
jsonData.put("status", 1);
jsonData.put("content", message);
JSONObject finishData = new JSONObject();
finishData.put("status", 4);
finishData.put("content", "");
try {
sseEmitter.send(conversationData.toJSONString());
sseEmitter.send(jsonData.toJSONString());
sseEmitter.send(finishData.toJSONString());
} catch (IOException e) {
log.error("发送错误信息异常", e);
sseEmitter.completeWithError(e);
}
}
@Override
public boolean stopChatOutput(String conversationId) {
log.info("收到停止会话 {} 的指令", conversationId);
// 发送广播消息,通知中断连接
try {
jmsTemplate.convertAndSend(topic, conversationId);
} catch (JmsException e) {
log.error("发送停止会话 {} 输出时发生异常", conversationId, e);
return false;
}
return true;
}
/**
* 取消eventSource
*/
@Override
public void eventSourceCancel(String conversationId) {
EventSource eventSource = conversationEventSourceMap.get(conversationId);
if (eventSource != null) {
try {
// 取消事件源,中断连接
eventSource.cancel();
// 注意cancel()会触发onFailure回调在onFailure中会清理资源
log.info("成功发送停止会话 {} 的指令", conversationId);
} catch (Exception e) {
log.error("停止会话 {} 输出时发生异常", conversationId, e);
// 即使出现异常也从Map中移除避免内存泄漏
conversationEventSourceMap.remove(conversationId);
}
} else {
log.info("未找到会话 {} 对应的事件源,可能已经完成或不存在", conversationId);
}
}
@Override
public boolean msgFeedback(CaseAiMsgLikeDto caseAiMsgLikeDto) {
AiChatConversationData aiChatConversationData = new AiChatConversationData();
if (StringUtils.isBlank(caseAiMsgLikeDto.getDocId())) {
log.error("操作失败docId为空");
return false;
}
if (Boolean.TRUE.equals(caseAiMsgLikeDto.getOperation())) {
String likeStatus = caseAiMsgLikeDto.getLikeStatus();
if (!StringUtils.equals(likeStatus, "1") && !StringUtils.equals(likeStatus, "0") && !StringUtils.equals(likeStatus, "-1")) {
log.error("操作失败,参数错误");
return false;
}
} else if (Boolean.FALSE.equals(caseAiMsgLikeDto.getOperation())) {
if (StringUtils.isBlank(caseAiMsgLikeDto.getFeedback())) {
log.error("操作失败,参数错误");
return false;
}
}
aiChatConversationData.setLikeStatus(caseAiMsgLikeDto.getLikeStatus());
aiChatConversationData.setFeedback(caseAiMsgLikeDto.getFeedback());
return elasticSearchIndexService.updateData(caseAiMsgLikeDto.getDocId() ,aiChatConversationData);
}
/**
* 获取消息详情
*
* @param getCaseAiMsgDto
*/
@Override
public List<CaseAiMessageVo> getCaseAiMsg(GetCaseAiMsgDto getCaseAiMsgDto) {
String conversationId = getCaseAiMsgDto.getConversationId();
String docId = getCaseAiMsgDto.getDocId();
if (StringUtils.isBlank(conversationId) && StringUtils.isBlank(docId)) {
log.error("获取消息详情失败会话id与docId不可同时为空");
throw new RuntimeException("获取消息详情失败会话id与docId不可同时为空");
}
List<CaseAiMessageVo> list = new ArrayList<>();
if (StringUtils.isNotBlank(conversationId)) {
return elasticSearchIndexService.queryData(conversationId);
}
if (StringUtils.isNotBlank(docId)) {
return elasticSearchIndexService.queryDataByDocId(conversationId);
}
return list;
}
/**
* 判断Throwable是否为超时类异常
* @param e
* @return
*/
private boolean isTimeoutException(@Nullable Throwable e) {
if (e == null) {
return false;
}
// ConnectException SocketTimeoutException
if (e instanceof java.net.ConnectException || e instanceof java.net.SocketTimeoutException) {
return true;
}
// 可能是包装后的异常,递归检查 cause
Throwable cause = e.getCause();
while (cause != null) {
if (cause instanceof java.net.ConnectException || cause instanceof java.net.SocketTimeoutException) {
return true;
}
cause = cause.getCause();
}
// 有些情况下 OkHttp 会抛出 IOException 并包含 "timeout" 字样
if (e instanceof java.io.IOException) {
String msg = e.getMessage();
if (msg != null && msg.toLowerCase().contains("timeout")) {
return true;
}
}
return false;
}
private Workbook getChatMessageExcel(LocalDateTime startTime, LocalDateTime endTime) {
// 1. 根据startTime和endTime查询在这个时间区间内的CaseAiConversations数据
List<CaseAiConversations> conversations = caseAiConversationsDao.getGenericDao().findList(
CaseAiConversations.class,
FieldFilters.ge("sysCreateTime", startTime),
FieldFilters.le("sysCreateTime", endTime)
);
// 准备Excel数据
List<ConversationExcelVo> excelDataList = new ArrayList<>();
// 2. 遍历这组数据根据aiConversationId从es中查询数据可调用getConversationMessages()方法)
for (CaseAiConversations conversation : conversations) {
String aiConversationId = conversation.getAiConversationId();
String conversationName = conversation.getConversationName();
String conversationUser = conversation.getConversationUser();
List<CaseAiMessageVo> messages = getConversationMessages(aiConversationId);
// 计算会话时长
long duration = 0; // 默认为0如果需要精确计算需要从消息中提取时间信息
// 3. 写入Excel包括每个会话的用户会话标题会话内的问答记录每次对话时长等
ConversationExcelVo excelData = new ConversationExcelVo();
excelData.setConversationId(aiConversationId);
excelData.setConversationName(conversationName);
excelData.setUser(conversationUser);
excelData.setMessages(messages);
excelDataList.add(excelData);
}
// 写入Excel文件
Workbook workbook = new XSSFWorkbook();
Sheet sheet = workbook.createSheet("AI会话数据");
// 标题行
Row headerRow = sheet.createRow(0);
headerRow.createCell(0).setCellValue("会话ID");
headerRow.createCell(1).setCellValue("会话名称");
headerRow.createCell(2).setCellValue("用户");
headerRow.createCell(3).setCellValue("提问");
headerRow.createCell(4).setCellValue("回答");
headerRow.createCell(5).setCellValue("开始时间");
headerRow.createCell(6).setCellValue("问答时长(秒)");
headerRow.createCell(7).setCellValue("消息状态");
headerRow.createCell(8).setCellValue("错误信息");
// 内容行
if (!excelDataList.isEmpty()) {
int rowNum = 1; // 从第二行开始写入数据
for (ConversationExcelVo excelData : excelDataList) {
List<CaseAiMessageVo> messages = excelData.getMessages();
if (messages != null && !messages.isEmpty()) {
// 记录起始行号,用于后续合并单元格
int startRow = rowNum;
// 遍历每个消息
for (CaseAiMessageVo message : messages) {
Row row = sheet.createRow(rowNum++);
// 填充每行数据
row.createCell(0).setCellValue(excelData.getConversationId());
row.createCell(1).setCellValue(excelData.getConversationName());
row.createCell(2).setCellValue(excelData.getUser());
row.createCell(3).setCellValue(message.getQuery() != null ? message.getQuery() : "");
row.createCell(4).setCellValue(message.getAnswer() != null ? message.getAnswer() : "");
LocalDateTime messageStartTime = message.getStartTime();
if (messageStartTime != null) {
String startTimeStr = messageStartTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
row.createCell(5).setCellValue(startTimeStr);
} else {
row.createCell(5).setCellValue("");
}
row.createCell(6).setCellValue(message.getDurationSeconds() != null ? message.getDurationSeconds() : 0);
if (message.getStatus() != null) {
int status = message.getStatus();
CaseAiChatErrCodeEnum errCodeEnum = CaseAiChatErrCodeEnum.getByCode(status);
row.createCell(7).setCellValue(errCodeEnum.getLabel());
}
if (StringUtils.isNotBlank(message.getErrorMsg())) {
row.createCell(8).setCellValue(message.getErrorMsg());
}
}
// 合并单元格会话ID、会话名称、用户三列
// 参数说明:起始行号,结束行号,起始列号,结束列号
if (rowNum > startRow + 1) { // 只有当有多行时才合并
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 0, 0));
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 1, 1));
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 2, 2));
}
} else {
// 如果没有消息,则仍然创建一行显示基本信息
Row row = sheet.createRow(rowNum++);
row.createCell(0).setCellValue(excelData.getConversationId());
row.createCell(1).setCellValue(excelData.getConversationName());
row.createCell(2).setCellValue(excelData.getUser());
}
}
}
return workbook;
}
/**
* 异步存储会话数据
* @param conversationData
*/
private void saveConversationData(AiChatConversationData conversationData) {
esChatExecutor.execute(() -> elasticSearchIndexService.createData(conversationData));
}
// ConversationData 已移动到独立的Entity类AiChatConversationData
}

View File

@@ -17,15 +17,11 @@ import com.xboe.enums.CaseDocumentLogRunStatusEnum;
import com.xboe.module.assistance.service.ISmtpEmailService;
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
import com.xboe.module.boecase.dao.CasesDao;
import com.xboe.module.boecase.dao.CasesMajorTypeDao;
import com.xboe.module.boecase.entity.CaseDocumentLog;
import com.xboe.module.boecase.entity.Cases;
import com.xboe.module.boecase.entity.CasesMajorType;
import com.xboe.module.boecase.properties.CaseAiProperties;
import com.xboe.module.boecase.service.IAiAccessTokenService;
import com.xboe.module.boecase.service.ICaseKnowledgeService;
import com.xboe.module.dict.entity.DictItem;
import com.xboe.module.dict.service.ISysDictionaryService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
@@ -48,8 +44,6 @@ import java.io.File;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
/**
* 案例-知识库Service实现类
@@ -69,15 +63,9 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
@Resource
private CaseDocumentLogDao caseDocumentLogDao;
@Resource
private CasesMajorTypeDao casesMajorTypeDao;
@Resource
private XFileUploader fileUploader;
@Autowired
private ISysDictionaryService sysDictionaryService;
@Autowired
private IAiAccessTokenService aiAccessTokenService;
@@ -137,7 +125,10 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
}
// 4. 构建上传参数
String fileName = file.getName();
String fileName = cases.getFileName();
if (StringUtil.isBlank(fileName)) {
fileName = file.getName();
}
String fileType = getFileType(fileName);
@@ -154,60 +145,6 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
builder.addTextBody("fileType", fileType, ContentType.TEXT_PLAIN);
requestBody.put("fileType", fileType);
builder.addTextBody("parseType", "AUTO", ContentType.TEXT_PLAIN);
String url = caseAiProperties.getCaseDetailUrlBase() + caseId;
requestBody.put("url", url);
String downloadUrl = fileUploader.getHttpPath() + cases.getFilePath();
requestBody.put("downloadUrl", downloadUrl);
builder.addTextBody("url", url, ContentType.TEXT_PLAIN);
builder.addTextBody("downloadUrl", downloadUrl, ContentType.TEXT_PLAIN);
// metadata
JSONObject fileMetaData = new JSONObject();
fileMetaData.put("标题", cases.getTitle());
fileMetaData.put("作者", cases.getAuthorName());
fileMetaData.put("年份", String.valueOf(cases.getSysCreateTime().getYear()));
fileMetaData.put("摘要", cases.getSummary());
// 组织领域orgDomainParent
String orgDomainParent = cases.getOrgDomainParent();
List<DictItem> orgDomainParentItems = sysDictionaryService.findByKey("org_domain");
Optional<DictItem> orgDomainParentItem = orgDomainParentItems.stream()
.filter(item -> StringUtils.equals(orgDomainParent, item.getCode()))
.findFirst();
if (orgDomainParentItem.isPresent()) {
StringBuilder sb = new StringBuilder();
sb.append(orgDomainParentItem.get().getName());
if (StringUtils.isNotBlank(cases.getOrgDomainParent2())) {
Optional<DictItem> orgDomainParent2Item = orgDomainParentItems.stream()
.filter(item -> StringUtils.equals(cases.getOrgDomainParent2(), item.getCode()))
.findFirst();
orgDomainParent2Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
if (StringUtils.isNotBlank(cases.getOrgDomainParent3())) {
Optional<DictItem> orgDomainParent3Item = orgDomainParentItems.stream()
.filter(item -> StringUtils.equals(cases.getOrgDomainParent3(), item.getCode()))
.findFirst();
orgDomainParent3Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
}
}
fileMetaData.put("组织领域", sb.toString());
}
// 分类majorIds
List<CasesMajorType> cmtList = casesMajorTypeDao.findList(FieldFilters.eq("caseId", cases.getId()));
if (cmtList != null && !cmtList.isEmpty()) {
List<String> majorIds = cmtList.stream().map(CasesMajorType::getMajorId).collect(Collectors.toList());
List<DictItem> majorItems = sysDictionaryService.findByKey("major_type");
if (majorItems != null && !majorItems.isEmpty()) {
List<String> majorNames = majorItems.stream()
.filter(item -> majorIds.contains(item.getCode()))
.map(DictItem::getName)
.collect(Collectors.toList());
fileMetaData.put("组织领域", String.join(", ", majorNames));
}
}
ContentType contentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), contentType);
requestBody.put("fileMetaData", fileMetaData);
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
if (caseAiProperties.isFileUploadUseCallback()) {
builder.addTextBody("callbackUrl", caseAiProperties.getFileUploadCallbackUrl(), ContentType.TEXT_PLAIN);
@@ -246,9 +183,12 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
String taskId = data.getString("taskId");
// 保存成功的CaseDocumentLog记录
// saveCaseDocumentLog(caseId, cases.getTitle(), CaseDocumentLogOptTypeEnum.CREATE.getCode(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME,
// requestBody.toJSONString(), responseBody,
// CaseDocumentLogRunStatusEnum.RUNNING.getCode(), null, null, taskId);
saveCaseDocumentLog(caseId, cases.getTitle(), CaseDocumentLogOptTypeEnum.CREATE.getCode(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME,
requestBody.toJSONString(), responseBody,
CaseDocumentLogRunStatusEnum.RUNNING.getCode(), null, null, taskId);
CaseDocumentLogRunStatusEnum.COMPLETED.getCode(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), taskId);
log.info("上传案例文档成功,等待文档状态变更. caseId: {}, taskId: {}, 尝试次数: {}", caseId, taskId, attempt);
return true;
@@ -381,8 +321,9 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
// 接口调用成功,检查业务处理结果
JSONObject data = result.getJSONObject("data");
Boolean deleteSuccess = data.getBoolean(taskId);
int caseStatus = (deleteSuccess != null && deleteSuccess) ?
CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
// int caseStatus = (deleteSuccess != null && deleteSuccess) ?
// CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
int caseStatus = CaseDocumentLogCaseStatusEnum.FAILED.getCode();
saveCaseDocumentLog(caseId, cases.getTitle(), CaseDocumentLogOptTypeEnum.DELETE.getCode(), CaseAiConstants.CASE_DOC_DELETE_INTERFACE_NAME,
params, responseBody,
@@ -475,7 +416,10 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
}
// 4. 构建上传参数
String fileName = file.getName();
String fileName = cases.getFileName();
if (StringUtil.isBlank(fileName)) {
fileName = file.getName();
}
String fileType = getFileType(fileName);
@@ -492,60 +436,6 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
builder.addTextBody("fileType", fileType, ContentType.TEXT_PLAIN);
requestBody.put("fileType", fileType);
builder.addTextBody("parseType", "AUTO", ContentType.TEXT_PLAIN);
String url = caseAiProperties.getCaseDetailUrlBase() + caseId;
requestBody.put("url", url);
String downloadUrl = fileUploader.getHttpPath() + cases.getFilePath();
requestBody.put("downloadUrl", downloadUrl);
builder.addTextBody("url", url, ContentType.TEXT_PLAIN);
builder.addTextBody("downloadUrl", downloadUrl, ContentType.TEXT_PLAIN);
// metadata
JSONObject fileMetaData = new JSONObject();
fileMetaData.put("标题", cases.getTitle());
fileMetaData.put("作者", cases.getAuthorName());
fileMetaData.put("年份", String.valueOf(cases.getSysCreateTime().getYear()));
fileMetaData.put("摘要", cases.getSummary());
// 组织领域orgDomainParent
String orgDomainParent = cases.getOrgDomainParent();
List<DictItem> orgDomainParentItems = sysDictionaryService.findByKey("org_domain");
Optional<DictItem> orgDomainParentItem = orgDomainParentItems.stream()
.filter(item -> StringUtils.equals(orgDomainParent, item.getCode()))
.findFirst();
if (orgDomainParentItem.isPresent()) {
StringBuilder sb = new StringBuilder();
sb.append(orgDomainParentItem.get().getName());
if (StringUtils.isNotBlank(cases.getOrgDomainParent2())) {
Optional<DictItem> orgDomainParent2Item = orgDomainParentItems.stream()
.filter(item -> StringUtils.equals(cases.getOrgDomainParent2(), item.getCode()))
.findFirst();
orgDomainParent2Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
if (StringUtils.isNotBlank(cases.getOrgDomainParent3())) {
Optional<DictItem> orgDomainParent3Item = orgDomainParentItems.stream()
.filter(item -> StringUtils.equals(cases.getOrgDomainParent3(), item.getCode()))
.findFirst();
orgDomainParent3Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
}
}
fileMetaData.put("组织领域", sb.toString());
}
// 分类majorIds
List<CasesMajorType> cmtList = casesMajorTypeDao.findList(FieldFilters.eq("caseId", cases.getId()));
if (cmtList != null && !cmtList.isEmpty()) {
List<String> majorIds = cmtList.stream().map(CasesMajorType::getMajorId).collect(Collectors.toList());
List<DictItem> majorItems = sysDictionaryService.findByKey("major_type");
if (majorItems != null && !majorItems.isEmpty()) {
List<String> majorNames = majorItems.stream()
.filter(item -> majorIds.contains(item.getCode()))
.map(DictItem::getName)
.collect(Collectors.toList());
fileMetaData.put("组织领域", String.join(", ", majorNames));
}
}
ContentType contentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), contentType);
requestBody.put("fileMetaData", fileMetaData);
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
if (caseAiProperties.isFileUploadUseCallback()) {
builder.addTextBody("callbackUrl", caseAiProperties.getFileUploadCallbackUrl(), ContentType.TEXT_PLAIN);
@@ -652,8 +542,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
.findList(CaseDocumentLog.class, 1,
OrderCondition.desc("sysCreateTime"),
FieldFilters.eq("caseId", caseId),
FieldFilters.eq("requestUrl", CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME),
FieldFilters.eq("caseStatus", CaseDocumentLogCaseStatusEnum.SUCCESS.getCode()));
FieldFilters.eq("requestUrl", CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME));
if (logList.isEmpty()) {
log.info("删除案例文档失败未找到相关的日志记录caseId: {}", caseId);
@@ -713,21 +602,22 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
// 接口调用成功,检查业务处理结果
JSONObject data = result.getJSONObject("data");
Boolean deleteSuccess = data.getBoolean(deleteTaskId);
int caseStatus = (deleteSuccess != null && deleteSuccess) ?
CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
// int caseStatus = (deleteSuccess != null && deleteSuccess) ?
// CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
int caseStatus = CaseDocumentLogCaseStatusEnum.FAILED.getCode();
saveCaseDocumentLog(caseId, cases.getTitle(), CaseDocumentLogOptTypeEnum.UPDATE.getCode(), CaseAiConstants.CASE_DOC_DELETE_INTERFACE_NAME,
params, responseBody,
CaseDocumentLogRunStatusEnum.COMPLETED.getCode(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode(), caseStatus, null);
if (deleteSuccess != null && deleteSuccess) {
log.info("删除案例文档成功caseId: {}, taskId: {}, 尝试次数: {}", caseId, deleteTaskId, attempt);
break; // 删除成功,跳出重试循环
} else {
// 业务处理失败,不重试
log.error("删除案例文档业务处理失败不重试caseId: {}, taskId: {}", caseId, deleteTaskId);
// if (deleteSuccess != null && deleteSuccess) {
// log.info("删除案例文档成功caseId: {}, taskId: {}, 尝试次数: {}", caseId, deleteTaskId, attempt);
// break; // 删除成功,跳出重试循环
// } else {
// // 业务处理失败,不重试
// log.error("删除案例文档业务处理失败不重试caseId: {}, taskId: {}", caseId, deleteTaskId);
return false;
}
// }
} else {
// 业务处理失败,不重试
log.error("删除案例文档业务处理失败不重试response: {}", responseBody);
@@ -791,7 +681,10 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
}
// 4. 构建上传参数
String fileName = file.getName();
String fileName = cases.getFileName();
if (StringUtil.isBlank(fileName)) {
fileName = file.getName();
}
String fileType = getFileType(fileName);
@@ -808,60 +701,6 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
builder.addTextBody("fileType", fileType, ContentType.TEXT_PLAIN);
requestBody.put("fileType", fileType);
builder.addTextBody("parseType", "AUTO", ContentType.TEXT_PLAIN);
String url = caseAiProperties.getCaseDetailUrlBase() + caseId;
requestBody.put("url", url);
String downloadUrl = fileUploader.getHttpPath() + cases.getFilePath();
requestBody.put("downloadUrl", downloadUrl);
builder.addTextBody("url", url, ContentType.TEXT_PLAIN);
builder.addTextBody("downloadUrl", downloadUrl, ContentType.TEXT_PLAIN);
// metadata
JSONObject fileMetaData = new JSONObject();
fileMetaData.put("标题", cases.getTitle());
fileMetaData.put("作者", cases.getAuthorName());
fileMetaData.put("年份", String.valueOf(cases.getSysCreateTime().getYear()));
fileMetaData.put("摘要", cases.getSummary());
// 组织领域orgDomainParent
String orgDomainParent = cases.getOrgDomainParent();
List<DictItem> orgDomainParentItems = sysDictionaryService.findByKey("org_domain");
Optional<DictItem> orgDomainParentItem = orgDomainParentItems.stream()
.filter(item -> StringUtils.equals(orgDomainParent, item.getCode()))
.findFirst();
if (orgDomainParentItem.isPresent()) {
StringBuilder sb = new StringBuilder();
sb.append(orgDomainParentItem.get().getName());
if (StringUtils.isNotBlank(cases.getOrgDomainParent2())) {
Optional<DictItem> orgDomainParent2Item = orgDomainParentItems.stream()
.filter(item -> StringUtils.equals(cases.getOrgDomainParent2(), item.getCode()))
.findFirst();
orgDomainParent2Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
if (StringUtils.isNotBlank(cases.getOrgDomainParent3())) {
Optional<DictItem> orgDomainParent3Item = orgDomainParentItems.stream()
.filter(item -> StringUtils.equals(cases.getOrgDomainParent3(), item.getCode()))
.findFirst();
orgDomainParent3Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
}
}
fileMetaData.put("组织领域", sb.toString());
}
// 分类majorIds
List<CasesMajorType> cmtList = casesMajorTypeDao.findList(FieldFilters.eq("caseId", cases.getId()));
if (cmtList != null && !cmtList.isEmpty()) {
List<String> majorIds = cmtList.stream().map(CasesMajorType::getMajorId).collect(Collectors.toList());
List<DictItem> majorItems = sysDictionaryService.findByKey("major_type");
if (majorItems != null && !majorItems.isEmpty()) {
List<String> majorNames = majorItems.stream()
.filter(item -> majorIds.contains(item.getCode()))
.map(DictItem::getName)
.collect(Collectors.toList());
fileMetaData.put("组织领域", String.join(", ", majorNames));
}
}
ContentType contentType = ContentType.create("text/plain", StandardCharsets.UTF_8);
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), contentType);
requestBody.put("fileMetaData", fileMetaData);
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
if (caseAiProperties.isFileUploadUseCallback()) {
builder.addTextBody("callbackUrl", caseAiProperties.getFileUploadCallbackUrl(), ContentType.TEXT_PLAIN);
@@ -1028,7 +867,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
@Override
public void batchCheckFileStatus() {
// log.info("开始批量检查文件状态");
log.info("开始批量检查文件状态");
// 1. 查询CaseDocumentLog表中前10条run_status等于0的数据并按创建时间升序排序
PageList<CaseDocumentLog> runningLogPage = caseDocumentLogDao.getGenericDao()
@@ -1038,11 +877,11 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
// 2. 如果没有符合条件的数据,完成
if (runningLogs == null || runningLogs.isEmpty()) {
// log.info("没有需要检查状态的文档,批量检查完成");
log.info("没有需要检查状态的文档,批量检查完成");
return;
}
// log.info("找到{}条需要检查状态的文档记录", runningLogs.size());
log.info("找到{}条需要检查状态的文档记录", runningLogs.size());
// 3. 把这些数据的taskId聚合成一个List<String>
List<String> taskIds = runningLogs.stream()
@@ -1052,11 +891,11 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
.collect(java.util.stream.Collectors.toList());
if (taskIds.isEmpty()) {
// log.error("所有运行中的记录都没有有效的taskId");
log.error("所有运行中的记录都没有有效的taskId");
return;
}
// log.info("需要检查状态的taskId数量: {}", taskIds.size());
log.info("需要检查状态的taskId数量: {}", taskIds.size());
// 4. 获取access_token
String accessToken = aiAccessTokenService.getAccessToken();
@@ -1096,7 +935,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
log.error("批量检查文件状态异常", e);
}
// log.info("批量检查文件状态完成");
log.info("批量检查文件状态完成");
}
/**
@@ -1362,9 +1201,8 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
caseLog.setRunStatus(CaseDocumentLogRunStatusEnum.COMPLETED.getCode());
caseLog.setOptStatus(CaseDocumentLogOptStatusEnum.SUCCESS.getCode());
caseLog.setCaseStatus(CaseDocumentLogCaseStatusEnum.SUCCESS.getCode());
caseLog.setMetadataStatus(1);
needUpdate = true;
// log.info("文档向量化成功更新状态taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
log.info("文档向量化成功更新状态taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
} else if ("failed".equals(fileStatus)) {
// 状态为failedrun_status、opt_status变更为1case_status变更为2
caseLog.setRunStatus(CaseDocumentLogRunStatusEnum.COMPLETED.getCode());
@@ -1372,20 +1210,20 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
caseLog.setCaseStatus(CaseDocumentLogCaseStatusEnum.FAILED.getCode());
needUpdate = true;
needToSendEmail = true;
// log.error("文档处理失败需要发送邮件更新状态taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
log.error("文档处理失败需要发送邮件更新状态taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
} else {
// 其他状态uploaded、texted、vectoring不做数据变更
// log.info("文档状态为{}暂不更新数据库taskId: {}", fileStatus, caseLog.getTaskId());
log.info("文档状态为{}暂不更新数据库taskId: {}", fileStatus, caseLog.getTaskId());
}
// 如果需要更新执行update操作
if (needUpdate) {
caseLog.setSysUpdateTime(LocalDateTime.now());
caseDocumentLogDao.save(caseLog);
// log.info("更新CaseDocumentLog成功logId: {}, taskId: {}, fileStatus: {}",
// caseLog.getId(), caseLog.getTaskId(), fileStatus);
// } else {
// log.info("无需更新CaseDocumentLogtaskId: {}, fileStatus: {}", caseLog.getTaskId(), fileStatus);
log.info("更新CaseDocumentLog成功logId: {}, taskId: {}, fileStatus: {}",
caseLog.getId(), caseLog.getTaskId(), fileStatus);
} else {
log.info("无需更新CaseDocumentLogtaskId: {}, fileStatus: {}", caseLog.getTaskId(), fileStatus);
}
} catch (Exception e) {
log.error("更新日志状态异常taskId: {}, fileStatus: {}", caseLog.getTaskId(), fileStatus, e);
@@ -1402,7 +1240,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
// 使用配置的收件人列表
List<String> recipients = caseAiProperties.getAlertEmailRecipients();
// log.info("使用配置的收件人列表:{}", recipients);
log.info("使用配置的收件人列表:{}", recipients);
if (recipients != null && !recipients.isEmpty()) {
try {
String to = String.join(",", recipients);

View File

@@ -8,43 +8,31 @@ 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
@@ -132,36 +120,6 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
}
}
@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) {
@@ -176,14 +134,7 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
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());
esData.put("timestamp", LocalDateTime.now().toString());
// 构建 caseRefer 数据
JSONArray caseReferArray = new JSONArray();
@@ -238,7 +189,6 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
Map<String, Object> sourceMap = hit.getSourceAsMap();
CaseAiMessageVo data = parseMessageFromES(sourceMap);
if (data != null) {
data.setDocId(hit.getId());
list.add(data);
}
}
@@ -254,72 +204,37 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
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());
}
Object suggestionsObj = sourceMap.get("suggestions");
if (suggestionsObj instanceof List) {
messageVo.setSuggestions((List<String>) suggestionsObj);
}
// 解析 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;
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"));
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);
// 解析 keywords
Object keywordsObj = caseReferMap.get("keywords");
if (keywordsObj instanceof List) {
caseRefer.setKeywords((List<String>) keywordsObj);
}
messageVo.setCaseRefer(caseReferList);
}
}
// 解析点赞状态
if (sourceMap.containsKey("likeStatus")) {
messageVo.setLikeStatus((String) sourceMap.get("likeStatus"));
}
// 解析反馈信息
if (sourceMap.containsKey("feedback")) {
messageVo.setFeedback((String) sourceMap.get("feedback"));
caseReferList.add(caseRefer);
}
messageVo.setCaseRefer(caseReferList);
}
return messageVo;
@@ -329,79 +244,6 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
}
}
@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索引的字段映射配置
* 根据项目中的会话消息数据结构规范定义映射
@@ -409,15 +251,70 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
* @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");
return "{\n" +
" \"properties\": {\n" +
" \"conversationId\": {\n" +
" \"type\": \"keyword\",\n" +
" \"index\": true\n" +
" },\n" +
" \"query\": {\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\",\n" +
" \"search_analyzer\": \"ik_smart\",\n" +
" \"fields\": {\n" +
" \"keyword\": {\n" +
" \"type\": \"keyword\",\n" +
" \"ignore_above\": 256\n" +
" }\n" +
" }\n" +
" },\n" +
" \"answer\": {\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\",\n" +
" \"search_analyzer\": \"ik_smart\"\n" +
" },\n" +
" \"caseRefer\": {\n" +
" \"type\": \"nested\",\n" +
" \"properties\": {\n" +
" \"caseId\": {\n" +
" \"type\": \"keyword\",\n" +
" \"index\": true\n" +
" },\n" +
" \"title\": {\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\",\n" +
" \"search_analyzer\": \"ik_smart\"\n" +
" },\n" +
" \"authorName\": {\n" +
" \"type\": \"keyword\",\n" +
" \"index\": true\n" +
" },\n" +
" \"keywords\": {\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\",\n" +
" \"search_analyzer\": \"ik_smart\"\n" +
" },\n" +
" \"content\": {\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\",\n" +
" \"search_analyzer\": \"ik_smart\"\n" +
" }\n" +
" }\n" +
" },\n" +
" \"suggestions\": {\n" +
" \"type\": \"text\",\n" +
" \"analyzer\": \"ik_max_word\",\n" +
" \"search_analyzer\": \"ik_smart\"\n" +
" },\n" +
" \"userId\": {\n" +
" \"type\": \"keyword\",\n" +
" \"index\": true\n" +
" },\n" +
" \"timestamp\": {\n" +
" \"type\": \"date\",\n" +
" \"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\"\n" +
" }\n" +
" }\n" +
"}";
}
}

View File

@@ -1,77 +0,0 @@
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);
}
}

View File

@@ -20,8 +20,8 @@ public class CaseDocumentLogTask {
*/
@XxlJob("batchCheckFileStatusJob")
public void batchCheckFileStatusJob() {
// log.info("开始批量查询文件状态");
log.info("开始批量查询文件状态");
caseKnowledgeService.batchCheckFileStatus();
// log.info("结束批量查询文件状态");
log.info("结束批量查询文件状态");
}
}

View File

@@ -1,13 +1,6 @@
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;
@@ -15,7 +8,6 @@ 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;
@@ -24,8 +16,6 @@ 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;
/**
* 旧案例上传
@@ -46,59 +36,25 @@ public class CaseUploadTask {
@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);
}
}
}
private static final String CASE_UPLOAD_LAST_ID_KEY = "case:upload:last:id";
@XxlJob("oldDataUploadJob")
public void oldDataUploadJob() {
String currentLastId = null;
try {
// log.info("开始执行旧案例上传任务");
log.info("开始执行旧案例上传任务");
// 从Redis获取上次处理的最后一条记录ID
String lastProcessedId = stringRedisTemplate.opsForValue().get(CASE_UPLOAD_LAST_ID_KEY);
// log.info("上次处理的最后一条记录ID: {}", lastProcessedId);
log.info("上次处理的最后一条记录ID: {}", lastProcessedId);
// 查询符合条件的案例数据
List<Cases> casesToProcess = findCasesToProcess(lastProcessedId);
// log.info("查询到待处理案例数量: {}", casesToProcess.size());
log.info("查询到待处理案例数量: {}", casesToProcess.size());
if (casesToProcess.isEmpty()) {
// log.info("没有需要处理的案例数据");
log.info("没有需要处理的案例数据");
return;
}
currentLastId = casesToProcess.get(casesToProcess.size() - 1).getId();
// 批量检查这些案例是否已在CaseDocumentLog中存在记录提升性能
List<String> caseIds = new ArrayList<>();
@@ -114,59 +70,35 @@ public class CaseUploadTask {
// 过滤出未在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;
})) {
boolean exists = false;
for (CaseDocumentLog log : existingLogs) {
if (cases.getId().equals(log.getCaseId())) {
exists = true;
break;
}
}
if (!exists) {
casesList.add(cases);
}
}
// log.info("过滤后需要处理的案例数量: {}", casesList.size());
log.info("过滤后需要处理的案例数量: {}", casesList.size());
if (!casesList.isEmpty()) {
// 调用异步处理方法
caseAiDocumentAsyncHandler.process(CaseDocumentLogOptTypeEnum.CREATE, casesList.toArray(new Cases[0]));
// 将当前处理的最后一条数据ID存入Redis
String currentLastId = casesList.get(casesList.size() - 1).getId();
stringRedisTemplate.opsForValue().set(CASE_UPLOAD_LAST_ID_KEY, currentLastId);
log.info("已处理案例最后一条记录ID已更新为: {}", currentLastId);
} else {
log.info("没有新的案例需要处理");
}
// 将当前处理的最后一条数据ID存入Redis
// log.info("旧案例上传任务执行完成");
log.info("旧案例上传任务执行完成");
} catch (Exception e) {
log.error("执行旧案例上传任务时发生异常", e);
} finally {
if (currentLastId != null) {
fixOnLastCase(currentLastId);
}
}
}
@@ -177,46 +109,22 @@ public class CaseUploadTask {
* @return 案例列表
*/
private List<Cases> findCasesToProcess(String lastProcessedId) {
QueryBuilder queryBuilder = QueryBuilder.from(Cases.class);
queryBuilder.addFilter(FieldFilters.eq("deleted", false));
com.xboe.core.orm.QueryBuilder queryBuilder = com.xboe.core.orm.QueryBuilder.from(Cases.class);
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.eq("deleted", false));
// 只处理有文件路径的案例
queryBuilder.addFilter(FieldFilters.isNotNull("filePath"));
queryBuilder.addFilter(FieldFilters.ne("filePath", ""));
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.isNotNull("filePath"));
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.ne("filePath", ""));
// 如果有上次处理的ID则从该ID之后开始查询
if (lastProcessedId != null && !lastProcessedId.isEmpty()) {
queryBuilder.addFilter(FieldFilters.gt("id", lastProcessedId));
queryBuilder.addFilter(com.xboe.core.orm.FieldFilters.gt("id", lastProcessedId));
}
// 按创建时间升序排序
queryBuilder.addOrder(OrderCondition.asc("id"));
queryBuilder.addOrder(com.xboe.common.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);
}
}

View File

@@ -2,7 +2,6 @@ package com.xboe.module.boecase.vo;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
/**
@@ -10,15 +9,6 @@ import java.util.List;
*/
@Data
public class CaseAiMessageVo {
/**
* ES docId
*/
private String docId;
/**
* 会话ID
*/
private String conversationId;
/**
* 用户提问内容
@@ -30,16 +20,6 @@ public class CaseAiMessageVo {
*/
private String answer;
/**
* 会话开始时间
*/
private LocalDateTime startTime;
/**
* 会话时长(秒)
*/
private Integer durationSeconds;
/**
* 案例引用列表
*/
@@ -49,31 +29,4 @@ public class CaseAiMessageVo {
* 建议列表
*/
private List<String> suggestions;
/**
* 状态
* 0-正常
* 1-系统错误
* 2-AIoT平台错误
*/
private Integer status;
/**
* 错误信息
*/
private String errorMsg;
/**
* 用户点赞状态
* -1: 踩
* 1
* 0/null 无操作
*/
private String likeStatus;
/**
* 用户踩的时候, 可以填写反馈意见
* 反馈意见
*/
private String feedback;
}

View File

@@ -1,31 +0,0 @@
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;
}

View File

@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
import com.xboe.api.ThirdApi;
import com.xboe.module.course.dto.CourseParam;
import com.xboe.module.course.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -28,10 +29,6 @@ import com.xboe.module.course.entity.Course;
import com.xboe.module.course.entity.CourseAudit;
import com.xboe.module.course.entity.CourseContent;
import com.xboe.module.course.entity.CourseHRBPAudit;
import com.xboe.module.course.service.ICourseAuditService;
import com.xboe.module.course.service.ICourseContentService;
import com.xboe.module.course.service.ICourseHRBPAuditService;
import com.xboe.module.course.service.ICourseService;
import com.xboe.standard.enums.BoedxContentType;
import com.xboe.standard.enums.BoedxCourseType;
@@ -60,7 +57,8 @@ public class CourseAuditApi extends ApiBaseController{
private ICourseContentService ccontentService;
@Resource
private ThirdApi thirdApi;
@Resource
private ICourseTagService tagService;
/**
* 教师需要审核的课程
@@ -358,8 +356,10 @@ public class CourseAuditApi extends ApiBaseController{
//修改在线课开课状态=已开课
String token = request.getHeader("Xboe-Access-Token");
CourseParam param = new CourseParam();
param.setId(courseId);
thirdApi.updateOnLineStatua(param,token);
param.setId(c.getId());
param.setOrgId(c.getOrgId());
param.setOrgName(c.getOrgName());
thirdApi.updateOrSaveCourse(param,token);
}
return success(true);
} catch (Exception e) {
@@ -424,6 +424,10 @@ public class CourseAuditApi extends ApiBaseController{
dto.getCourse().setEnabled(true);//设置启用状态问题
dto.getCourse().setPublished(false);//重新提交审核设置为未发布状态
try {
// log.info("-------- 标签相关开始 ------- 课程ID = {} " , dto.getCourse().getId());
// Course oldCourse = StringUtils.isBlank(dto.getCourse().getId()) ? null : courseService.get(dto.getCourse().getId());
// tagService.updateTags(oldCourse,dto.getCourse(),cuser);
// log.info("-------- 标签相关结束 -------");
courseService.submitAndPublish(dto,cuser.getAccountId(),cuser.getName());
log.info("---------------在线课开始同步到讲师管理 ------- token = " + token);

View File

@@ -12,6 +12,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.xboe.api.ThirdApi;
import com.xboe.data.outside.IOutSideDataService;
import com.xboe.module.course.entity.CourseTag;
import com.xboe.module.course.service.*;
import com.xboe.module.course.vo.TeacherVo;
import com.xboe.school.study.entity.StudyCourse;
import com.xboe.school.study.service.IStudyCourseService;
@@ -34,11 +36,6 @@ import com.xboe.module.course.dto.CourseTeacherDto;
import com.xboe.module.course.entity.Course;
import com.xboe.module.course.entity.CourseCrowd;
import com.xboe.module.course.entity.CourseTeacher;
import com.xboe.module.course.service.CourseToCourseFullText;
import com.xboe.module.course.service.ICourseContentService;
import com.xboe.module.course.service.ICourseFullTextSearch;
import com.xboe.module.course.service.ICourseService;
import com.xboe.module.course.service.ICourseTeacherService;
import lombok.extern.slf4j.Slf4j;
@@ -63,7 +60,8 @@ public class CourseFullTextApi extends ApiBaseController{
ICourseFullTextSearch fullTextSearch;
@Resource
IOrganizationService organizationService;
@Autowired
ICourseTagService courseTagService;
@Resource
IStudyCourseService IStudyCourseService;
@@ -76,6 +74,8 @@ public class CourseFullTextApi extends ApiBaseController{
@Autowired
StringRedisTemplate redisTemplate;
/**
* 课程的初始化
* @return
@@ -310,7 +310,18 @@ public class CourseFullTextApi extends ApiBaseController{
}
paras.setDevice(dto.getDevice());
String tagIds = dto.getTags();
if (tagIds != null && tagIds != ""){
paras.setTags(tagIds);
}else {
String tagName = paras.getKeywords();
if (tagName != null && tagName != ""){
CourseTag courseTag = courseTagService.getTagByName(tagName);
if (courseTag != null){
paras.setTags(courseTag.getId().toString()+",");
}
}
}
try {
//后续会根据当前用户的资源归属查询
PageList<CourseFullText> coursePageList = fullTextSearch.search(ICourseFullTextSearch.DEFAULT_INDEX_NAME,pager.getStartRow(), pager.getPageSize(),paras);
@@ -402,6 +413,12 @@ public class CourseFullTextApi extends ApiBaseController{
c.setKeywordsList(keywordsList);
}
}
if (StringUtils.isNotBlank(c.getTags()) ){
List<CourseTag> tagList = courseTagService.getTagsByIds(c.getTags());
List<String> tags = tagList.stream().map(CourseTag::getTagName).collect(Collectors.toList());
c.setTagsList(tags);
}
}

View File

@@ -12,6 +12,8 @@ import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
import com.boe.feign.api.infrastructure.entity.Dict;
import com.xboe.api.ThirdApi;
import com.xboe.module.course.dto.*;
import com.xboe.module.course.entity.*;
import com.xboe.module.course.service.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
@@ -94,7 +96,8 @@ public class CourseManageApi extends ApiBaseController{
@Resource
private ICourseHRBPAuditService hrbpAuditService;
@Resource
private ICourseTagService tagService;
@Resource
IOutSideDataService outSideDataService;
@@ -184,6 +187,12 @@ public class CourseManageApi extends ApiBaseController{
rs.put("dicts",dicts);
}
log.error("-------是否仅内网查看 = " + isPermission);
if (StringUtils.isNotBlank(course.getTags())){
List<CourseTag> tagList = tagService.getTagsByIds(course.getTags());
rs.put("tagList", tagList);
}
rs.put("course",course);
rs.put("contents",cclist);
rs.put("sections",sectionlist);
@@ -213,7 +222,7 @@ public class CourseManageApi extends ApiBaseController{
}
return success(rs);
}
/**
* 管理员审核列表教师的审核不在这里此审核也应该移动CourseAuditApi中去
* @param pager
@@ -322,6 +331,12 @@ public class CourseManageApi extends ApiBaseController{
//填充必要的信息
try {
// log.info("-------- 标签相关开始 ------- 课程ID = {} " , dto.getCourse().getId());
// CurrentUser userInfo = getCurrent();
// Course oldCourse = StringUtils.isBlank(dto.getCourse().getId()) ? null : courseService.get(dto.getCourse().getId());
// tagService.updateTags(oldCourse,dto.getCourse(),userInfo);
// log.info("-------- 标签相关结束 -------");
if(StringUtils.isBlank(dto.getCourse().getId())) {
//只有在第一次添加保存时才会这样
fillCourseData(dto.getCourse());

View File

@@ -0,0 +1,188 @@
package com.xboe.module.course.api;
import com.xboe.common.OrderCondition;
import com.xboe.common.PageList;
import com.xboe.common.Pagination;
import com.xboe.core.CurrentUser;
import com.xboe.core.JsonResponse;
import com.xboe.core.api.ApiBaseController;
import com.xboe.core.orm.FieldFilters;
import com.xboe.core.orm.IFieldFilter;
import com.xboe.module.article.entity.Article;
import com.xboe.module.article.service.IArticleService;
import com.xboe.module.course.dto.CourseTagQueryDto;
import com.xboe.module.course.dto.CourseTagRelationDto;
import com.xboe.module.course.entity.CourseTag;
import com.xboe.module.course.entity.CourseTagRelation;
import com.xboe.module.course.service.ICourseTagService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
/**
* @ClassName:CourseTagApi
* @author:zhengge@oracle.com
* @since:2025/7/2614:27
*/
@Slf4j
@RestController
@RequestMapping(value="/xboe/m/coursetag")
public class CourseTagApi extends ApiBaseController {
@Resource
ICourseTagService courseTagService;
/**
* 标签列表:分页查询
* @param pager
* @param courseTagQueryDto
* @return
*/
/* @RequestMapping(value="/page",method= {RequestMethod.GET,RequestMethod.POST})
public JsonResponse<PageList<CourseTag>> find(Pagination pager, CourseTagQueryDto courseTagQueryDto){
log.info("标签列表:分页查询 pager = " + pager);
log.info("标签列表:分页查询 courseTagQueryDto = " + courseTagQueryDto);
List<IFieldFilter> filters=new ArrayList<IFieldFilter>();
OrderCondition order = null;
if (courseTagQueryDto != null){
String tagId = courseTagQueryDto.getId();
String tagName = courseTagQueryDto.getTagName();
Boolean isHot = courseTagQueryDto.getIsHot();
String orderField = courseTagQueryDto.getOrderField();
Boolean isAsc = courseTagQueryDto.getOrderAsc();
if (StringUtils.isNotBlank(tagId)){
filters.add(FieldFilters.eq("id",tagId));
}
//课程标签名称:模糊查询
if (StringUtils.isNotBlank(tagName)){
filters.add(FieldFilters.like("tagName",tagName));
}
// 构建排序条件支持先按lastSetHotTime降序再按动态字段升/降序排列‌
if (isHot !=null ){
filters.add(FieldFilters.eq("isHot",isHot));
//order = OrderCondition.desc("lastSetHotTime");//固定降序
}
// 动态排序处理
if (StringUtils.isNotBlank(orderField)) {
if (order == null) {
order = isAsc ? OrderCondition.asc(orderField) : OrderCondition.desc(orderField);
} else {
order = isAsc ? order.asc(orderField) : order.desc(orderField); // 链式追加排序条件
}
}
}
log.info("标签列表:分页查询 调用接口 filters = " + filters);
log.info("标签列表:分页查询 调用接口 order = " + order);
PageList<CourseTag> list=courseTagService.query(pager.getPageIndex(),pager.getPageSize(),filters,order);
return success(list);
}
*/
/**
* 修改指定id的课程标签的公共属性
* @param id
* @param isPublic
* @return
*/
/*
@RequestMapping(value="/changePublicStatus",method= RequestMethod.POST)
public JsonResponse<Void> changePublicStatus(Long id,Boolean isPublic){
courseTagService.changePublicStatus(id,isPublic);
return success(null);
}
*/
/**
* 修改指定id的课程标签的热点属性
* @param id
* @param isHot
* @return
*/
/* @RequestMapping(value="/changeHotStatus",method= RequestMethod.POST)
public JsonResponse<Void> changeHotStatus(Long id,Boolean isHot){
courseTagService.changeHotStatus(id,isHot);
return success(null);
}*/
/**
* 分页查询指定id的标签关联的所有课程
* @param courseTagQueryDto
* @return
*/
/*
@RequestMapping(value="/showCourseByTag",method= RequestMethod.POST)
public JsonResponse<PageList<CourseTagRelationDto>> showCourseByTag(Pagination pager, CourseTagQueryDto courseTagQueryDto){
PageList<CourseTagRelationDto> list=null;
if (courseTagQueryDto != null) {
Long tagId = Long.valueOf(courseTagQueryDto.getId());
Boolean isAsc = courseTagQueryDto.getOrderAsc()!=null?courseTagQueryDto.getOrderAsc():false;
list=courseTagService.getCourseByTag(pager.getPageIndex(),pager.getPageSize(),tagId,isAsc);
}
return success(list);
}
*/
/**
* 解除指定id的课程和某个标签之间的关联关系
* @return
*/
/*
@RequestMapping(value="/unbind",method= RequestMethod.POST)
public JsonResponse<Void> unbindCourseTagRelation(CourseTagRelationDto courseTagRelationDto){
if (courseTagRelationDto!=null){
courseTagService.unbind(courseTagRelationDto.getId());
return success(null);
}
return error("解绑失败!");
}
*/
/**
* 模糊检索标签
* @return 符合检索条件的所有公共标签
*/
@RequestMapping(value="/searchTags",method= RequestMethod.POST)
public JsonResponse<List<CourseTag>> searchTags(String tagName,String typeId ,HttpServletRequest request){
CurrentUser cuser = getCurrent();
String aid = cuser.getAccountId();
log.info(" searchTags cuser name = " + cuser.getName() + " , NickName = " + cuser.getNickName() + " , LoginName = " + cuser.getLoginName());
log.info(" 参数 tagName = " + tagName + " , typeId = " + typeId + " , aid = " + aid);
log.info(" searchTags aid = " + aid);
List<CourseTag> courseTagList = courseTagService.searchTags(tagName,aid,typeId);
return success(courseTagList);
}
/**
* 创建新标签,并与当前课程绑定
* @param courseTagRelationDto
* @return
*/
@RequestMapping(value="/createTag",method= RequestMethod.POST)
public JsonResponse<CourseTag> createTag(CourseTagRelationDto courseTagRelationDto){
if (courseTagRelationDto!=null){
CourseTag courseTag = courseTagService.createTag(courseTagRelationDto);
return success(courseTag);
}
return error("创建标签失败!");
}
/**
* 创建新标签,并与当前课程绑定
* @param courseTagRelationDto
* @return
*/
@RequestMapping(value="/getHotTagList",method= RequestMethod.POST)
public JsonResponse<List<CourseTag>> getHotTagList(CourseTagRelationDto courseTagRelationDto){
List<CourseTag> hotTagList = courseTagService.getHotTagList(courseTagRelationDto);
return success(hotTagList);
}
}

View File

@@ -0,0 +1,207 @@
package com.xboe.module.course.dao;
import com.xboe.common.OrderCondition;
import com.xboe.common.PageList;
import com.xboe.core.SysConstant;
import com.xboe.core.orm.BaseDao;
import com.xboe.core.orm.FieldFilters;
import com.xboe.core.orm.IFieldFilter;
import com.xboe.core.orm.IQuery;
import com.xboe.module.course.entity.Course;
import com.xboe.module.course.entity.CourseFile;
import com.xboe.module.course.entity.CourseTag;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.ArrayList;
import java.util.List;
/**
* @ClassName:CourseTagDao
* @author:zhengge@oracle.com
* @since:2025/7/2516:50
*/
@Slf4j
@Repository
public class CourseTagDao extends BaseDao<CourseTag> {
@PersistenceContext
private EntityManager entityManager;
/**
* 获取热门标签列表(前10条)
* @return 热门标签列表
*/
public List<CourseTag> getHotTagList() {
// 原生SQL注意表名和列名需与数据库实际一致
String sql = "select t.*,COUNT(r.tag_id) AS relation_count\n" +
"from boe_course_tag t\n" +
"left join boe_course_tag_relation r\n" +
"on t.id = r.tag_id\n" +
"where t.deleted =0 and t.is_hot = true and t.status =0 \n" +
"GROUP BY t.id\n" +
"order by t.last_set_hot_time desc,relation_count desc"; // 数据库字段为last_set_hot_time
// 创建原生查询并指定结果映射到CourseTag实体
javax.persistence.Query query = entityManager.createNativeQuery(sql, CourseTag.class);
// 分页取前10条
query.setFirstResult(0);
query.setMaxResults(10);
// 执行查询并返回结果已映射为CourseTag类型
return query.getResultList();
}
/**
* 根据课程类型获取热门标签列表(前10条)
* @param sysType1 系统类型1
* @param sysType2 系统类型2
* @param sysType3 系统类型3
* @return 热门标签列表
*/
public List<CourseTag> getHotTagListBySysTypes(String sysType1, String sysType2, String sysType3) {
// 原生SQL注意表名和列名需与数据库实际一致此处假设表名为course_tag、course_type_tag_relation
String sql = "SELECT DISTINCT c.* FROM boe_course_tag c " +
"JOIN boe_course_type_tag_relation r ON c.id = r.tag_id " +
"WHERE r.deleted = 0 and c.status =0 " +
"AND c.is_hot = true "; // 假设数据库字段为is_hot与实体属性isHot对应
if (StringUtils.isNotBlank(sysType1)){
sql += "AND r.sys_type1 = ?1 ORDER BY c.last_set_hot_time DESC";
}else if(StringUtils.isNotBlank(sysType2)){
sql += "AND r.sys_type2 = ?1 ORDER BY c.last_set_hot_time DESC";
}else {
sql += "AND r.sys_type3 = ?1 ORDER BY c.last_set_hot_time DESC";
}
// 创建原生查询并指定结果映射到CourseTag实体
javax.persistence.Query query = entityManager.createNativeQuery(sql, CourseTag.class);
// 绑定参数注意参数索引从1开始
if (StringUtils.isNotBlank(sysType1)){
query.setParameter(1, sysType1);
} else if (StringUtils.isNotBlank(sysType2)) {
query.setParameter(1, sysType2);
}else {
query.setParameter(1, sysType3);
}
// 分页取前10条
query.setFirstResult(0);
query.setMaxResults(10);
// 执行查询并返回结果已映射为CourseTag类型
return query.getResultList();
}
public List<CourseTag> getTagsByIds(String id) {
String sql = "select * from " + SysConstant.TABLE_PRE + "course_tag where id in (" + id + "0)";
// 创建原生查询并指定结果映射到CourseTag实体
javax.persistence.Query query = entityManager.createNativeQuery(sql, CourseTag.class);
return query.getResultList();
}
public CourseTag getTagByName(String tagName) {
CourseTag courseTag = this.findOne((FieldFilters.eq("tag_name", tagName)));
return courseTag;
}
public PageList<CourseTag> getList() {
log.info("------- getList ----------- ");
String sql = "select * from boe_course_tag order by sys_create_time desc limit 10";
javax.persistence.Query query = entityManager.createNativeQuery(sql, CourseTag.class);
log.info("------- getList -----------getResultList = " + query.getResultList() );
PageList<CourseTag> pageList = new PageList<>();
pageList.setCount(query.getResultList().size());
pageList.setPageSize(1);
pageList.setList(query.getResultList());
return pageList;
}
public List<CourseTag> searchTags(String tagName, String userId, String typeId) {
StringBuilder sql = new StringBuilder();
List<Object> parameters = new ArrayList<>();
// 只查询实际存在的字段
sql.append("SELECT id, tag_name, is_public, is_hot, use_count, last_set_public_time, last_set_hot_time, deleted, sys_create_time ");
sql.append("FROM ( ");
sql.append(" SELECT id, tag_name, is_public, is_hot, use_count, last_set_public_time, last_set_hot_time, deleted, sys_create_time ");
sql.append(" FROM boe_course_tag ");
sql.append(" WHERE deleted = 0 AND is_public = 0 AND status = 0 ");
if (StringUtils.isNotBlank(tagName)) {
sql.append(" AND tag_name LIKE ? ");
parameters.add("%" + tagName + "%");
}
sql.append(" UNION ALL ");
sql.append(" SELECT t.id, t.tag_name, t.is_public, t.is_hot, t.use_count, t.last_set_public_time, t.last_set_hot_time, t.deleted, t.sys_create_time ");
sql.append(" FROM boe_course_tag_relation r ");
sql.append(" INNER JOIN boe_course_tag t ON r.tag_id = t.id ");
sql.append(" WHERE r.deleted = 0 AND t.deleted = 0 AND t.is_public = 1 AND t.status = 0 ");
if (StringUtils.isNotBlank(userId)) {
sql.append(" AND r.sys_create_aid = ? ");
parameters.add(Long.valueOf(userId));
}
if (StringUtils.isNotBlank(tagName)) {
sql.append(" AND t.tag_name LIKE ? ");
parameters.add("%" + tagName + "%");
}
sql.append(" GROUP BY t.id, t.tag_name, t.is_public, t.is_hot, t.use_count, t.last_set_public_time, t.last_set_hot_time, t.deleted, t.sys_create_time ");
sql.append(") AS all_tags ");
sql.append("ORDER BY ");
if (StringUtils.isNotBlank(typeId)) {
sql.append(" CASE WHEN id IN ( ");
sql.append(" SELECT tag_id ");
sql.append(" FROM boe_course_type_tag_relation ");
sql.append(" WHERE deleted = 0 ");
sql.append(" AND (sys_type1 = ? ");
sql.append(" OR sys_type2 = ? ");
sql.append(" OR sys_type3 = ?) ");
sql.append(" GROUP BY tag_id ");
sql.append(" ) THEN 0 ELSE 1 END, ");
parameters.add(Long.valueOf(typeId));
parameters.add(Long.valueOf(typeId));
parameters.add(Long.valueOf(typeId));
}
sql.append(" sys_create_time DESC");
log.info("查询标签 searchTags sql = {} ", sql);
// 不使用实体类映射,手动处理结果集
Query query = entityManager.createNativeQuery(sql.toString());
for (int i = 0; i < parameters.size(); i++) {
query.setParameter(i + 1, parameters.get(i));
}
@SuppressWarnings("unchecked")
List<Object[]> results = query.getResultList();
List<CourseTag> courseTags = new ArrayList<>();
for (Object[] result : results) {
CourseTag tag = new CourseTag();
// 设置基本字段
if (result[0] != null) tag.setId(String.valueOf(result[0]));
if (result[1] != null) tag.setTagName(String.valueOf(result[1]));
if (result[2] != null) tag.setIsPublic(Boolean.valueOf(String.valueOf(result[2])));
if (result[3] != null) tag.setIsHot(Boolean.valueOf(String.valueOf(result[3])));
if (result[4] != null) tag.setUseCount(Integer.valueOf(String.valueOf(result[4])));
courseTags.add(tag);
}
return courseTags;
}
}

View File

@@ -0,0 +1,116 @@
package com.xboe.module.course.dao;
import com.xboe.common.PageList;
import com.xboe.core.orm.BaseDao;
import com.xboe.module.course.dto.CourseTagRelationDto;
import com.xboe.module.course.entity.CourseTagRelation;
import org.springframework.stereotype.Repository;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;
/**
* @ClassName:CourseTagRelationDao
* @author:zhengge@oracle.com
* @since:2025/7/2815:09
*/
@Repository
public class CourseTagRelationDao extends BaseDao<CourseTagRelation> {
@PersistenceContext
private EntityManager entityManager;
private String sqlStr = "SELECT " +
" r1.id as id, " +
" c.id as courseId, " +
" r1.tag_id as tagId, " +
" c.`name` as courseName, " +
" r1.sys_create_by as sysCreateBy, " +
" r1.sys_create_time as sysCreateTime, " +
" COALESCE(GROUP_CONCAT(DISTINCT t.tag_name ORDER BY t.tag_name), '') AS otherTags " +
"FROM " +
" boe_course c " +
"JOIN " +
" boe_course_tag_relation r1 ON c.id = r1.course_id " +
"LEFT JOIN " +
" ( " +
" boe_course_tag_relation r2 " +
" JOIN boe_course_tag t ON r2.tag_id = t.id AND t.deleted = 0 " +
" ) " +
" ON c.id = r2.course_id AND r2.tag_id != r1.tag_id " +
"WHERE " +
" r1.tag_id = :tagId AND r1.deleted = 0 " +
" AND c.id IN ( " +
" SELECT course_id " +
" FROM boe_course_tag_relation " +
" WHERE tag_id = :tagId " +
" ) " +
"GROUP BY " +
" c.id, c.`name` ";
public PageList<CourseTagRelationDto> findCoursesWithRelatedTagsDesc(Integer pageIndex, Integer pageSize, Long tagId){
String sql = sqlStr + " ORDER BY r1.sys_create_time DESC";
Query query = entityManager.createNativeQuery(sql);
query.setParameter("tagId", tagId);
query.setFirstResult((pageIndex - 1) * pageSize); // 设置起始位置
query.setMaxResults(pageSize); // 设置每页大小
Query countQuery = entityManager.createNativeQuery(sql);
countQuery.setParameter("tagId", tagId);
List<Object[]> totalresults = countQuery.getResultList();
List<Object[]> results = query.getResultList();
List<CourseTagRelationDto> list = results.stream()
.map(row -> {
String id = String.valueOf(row[0]);
String courseId = String.valueOf(row[1]);
String tagId2 = String.valueOf(row[2]);
return new CourseTagRelationDto(
id,
courseId,
tagId2,
(String) row[3],
(String) row[4],
(Date) row[5],
(String) row[6]
);
})
.collect(Collectors.toList());
return new PageList<CourseTagRelationDto>(list,totalresults!=null?totalresults.size():0);
}
public PageList<CourseTagRelationDto> findCoursesWithRelatedTagsAsc(Integer pageIndex, Integer pageSize, Long tagId) {
String sql = sqlStr + " ORDER BY r1.sys_create_time ASC";
Query query = entityManager.createNativeQuery(sql);
query.setParameter("tagId", tagId);
query.setFirstResult((pageIndex - 1) * pageSize); // 设置起始位置
query.setMaxResults(pageSize); // 设置每页大小
Query countQuery = entityManager.createNativeQuery(sql);
countQuery.setParameter("tagId", tagId);
List<Object[]> totalresults = countQuery.getResultList();
List<Object[]> results = query.getResultList();
List<CourseTagRelationDto> list = results.stream()
.map(row ->{
String id = String.valueOf(row[0]);
String courseId = String.valueOf(row[1]);
String tagId2 = String.valueOf(row[2]);
return new CourseTagRelationDto(
id,
courseId,
tagId2,
(String) row[3],
(String) row[4],
(Date) row[5],
(String) row[6]
);
})
.collect(Collectors.toList());
return new PageList<CourseTagRelationDto>(list,totalresults!=null?totalresults.size():0);
}
}

View File

@@ -0,0 +1,9 @@
package com.xboe.module.course.dao;
import com.xboe.core.orm.BaseDao;
import com.xboe.module.course.entity.CourseTeacherDeletedRecord;
import org.springframework.stereotype.Repository;
@Repository
public class CourseTeacherDeletedRecordDao extends BaseDao<CourseTeacherDeletedRecord> {
}

View File

@@ -0,0 +1,17 @@
package com.xboe.module.course.dao;
import com.xboe.core.orm.BaseDao;
import com.xboe.module.course.entity.CourseTagRelation;
import com.xboe.module.course.entity.CourseTypeTagRelation;
import org.springframework.stereotype.Repository;
/**
* @ClassName:CourseTypeTagRelationDao
* @author:zhengge@oracle.com
* @since:2025/8/113:42
*/
@Repository
public class CourseTypeTagRelationDao extends BaseDao<CourseTypeTagRelation> {
}

View File

@@ -1,5 +1,6 @@
package com.xboe.module.course.dto;
import com.xboe.module.course.entity.CourseTag;
import lombok.Data;
import java.util.List;
@@ -140,4 +141,6 @@ public class CourseQueryDto {
*/
private String userId;
private String tags;
}

View File

@@ -0,0 +1,40 @@
package com.xboe.module.course.dto;
import lombok.Data;
/**
* 课程标签查询的条件对象
* @ClassName:CourseTagQueryDto
* @author:zhengge@oracle.com
* @since:2025/7/2517:02
*/
@Data
public class CourseTagQueryDto {
/**
* 标签id
*/
private String id;
/**
* 标签名称
*/
private String tagName;
/**
* 是否热点标签( 0-否(默认) 1-是)
*/
private Boolean isHot;
/**
* 排序字段
*/
private String orderField;
/**
* 排序顺序
*/
private Boolean orderAsc;
}

View File

@@ -0,0 +1,49 @@
package com.xboe.module.course.dto;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.Column;
import java.time.LocalDateTime;
import java.util.Date;
/**
* @ClassName:CourseTagRelationDto
* @author:zhengge@oracle.com
* @since:2025/7/2815:00
*/
@Data
@NoArgsConstructor
public class CourseTagRelationDto{
private String id;
private String courseId;
private String tagId;
private String tagName;
private String courseName;
private String sysCreateBy;
private Date sysCreateTime;
private String otherTags; // 改为字符串类型,与 GROUP_CONCAT 结果匹配
private String sysType1;
private String sysType2;
private String sysType3;
// 添加匹配查询字段顺序的构造函数
public CourseTagRelationDto(
String id,
String courseId,
String tagId,
String courseName,
String sysCreateBy,
Date sysCreateTime,
String otherTags
) {
this.id = id;
this.courseId = courseId;
this.tagId = tagId;
this.courseName = courseName;
this.sysCreateBy = sysCreateBy;
this.sysCreateTime = sysCreateTime;
this.otherTags = otherTags;
}
}

View File

@@ -0,0 +1,98 @@
package com.xboe.module.course.entity;
import com.fasterxml.jackson.annotation.JsonFormat;
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;
/**
* 在线课程的标签类
* @ClassName:CourseTag
* @author:zhengge@oracle.com
* @since:2025/7/25 16:37
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = SysConstant.TABLE_PRE+"course_tag")
public class CourseTag extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 标签名称
*/
@Column(name = "tag_name",nullable=false, length = 50)
private String tagName;
/**
* 是否设置为公共标签
*/
@Column(name = "is_public",length = 1)
private Boolean isPublic;
/**
* 是否设置为热点标签
*/
@Column(name = "is_hot",length = 1)
private Boolean isHot;
/**
* 使用次数(关联课程数)
*/
@Column(name = "use_count",length = 1)
private Integer useCount;
/**
* 1临时 0正式
*/
@Column(name = "status",length = 1)
private Integer status;
/**
* 最近设置为公共标签的时间
*/
@Column(name = "last_set_public_time", nullable = true)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime lastSetPublicTime;
/**
* 最近设置为热点标签的时间
*/
@Column(name = "last_set_hot_time", nullable = true)
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime lastSetHotTime;
public CourseTag() {
}
public CourseTag(Long id, Boolean isPublic,Boolean isHot) {
this.setId(String.valueOf(id));
this.isPublic=isPublic;
this.isHot=isHot;
}
public CourseTag(String id,String tagName,String sysCreateBy,String sysCreateAid,LocalDateTime sysCreateTime,
Boolean isPublic,Boolean isHot,Integer useCount,LocalDateTime lastSetPublicTime,LocalDateTime lastSetHotTime,Boolean deleted){
this.setId(id);
this.setTagName(tagName);
super.setSysCreateBy(sysCreateBy);
super.setSysCreateAid(sysCreateAid);
super.setSysCreateTime(sysCreateTime);
this.isPublic = isPublic;
this.isHot = isHot;
this.useCount = useCount;
this.lastSetPublicTime = lastSetPublicTime;
this.lastSetHotTime = lastSetHotTime;
super.setDeleted(deleted);
}
}

View File

@@ -0,0 +1,37 @@
package com.xboe.module.course.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;
/**
* @ClassName:CourseTagRelation
* @author:zhengge@oracle.com
* @since:2025/7/2814:54
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = SysConstant.TABLE_PRE+"course_tag_relation")
public class CourseTagRelation extends BaseEntity {
private static final long serialVersionUID = 1L;
/**
* 课程Id
*/
@Column(name = "course_id",length = 20)
private Long courseId;
/**
* 标签id
*/
@Column(name = "tag_id",length = 20)
private Long tagId;
}

View File

@@ -0,0 +1,43 @@
package com.xboe.module.course.entity;
import com.xboe.core.SysConstant;
import com.xboe.core.orm.IdBaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* 课程任课教师删除记录
*/
@Data
@Entity
@EqualsAndHashCode(callSuper = false)
@Table(name = SysConstant.TABLE_PRE + "course_teacher_deleted_record")
public class CourseTeacherDeletedRecord extends IdBaseEntity {
private static final long serialVersionUID = 1L;
/**
* 课程id
*/
@Column(name = "course_id", nullable = false, length = 20)
private String courseId;
/**
* 教师id实际上就是aid
*
*/
@Column(name = "teacher_id", nullable = false, length = 20)
private String teacherId;
/**
* 教师姓名
*
*/
@Column(name = "teacher_name", length = 30)
private String teacherName;
}

View File

@@ -0,0 +1,39 @@
package com.xboe.module.course.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;
/**
* @ClassName:CourseTypeTagRelation
* @author:zhengge@oracle.com
* @since:2025/8/111:02
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Entity
@Table(name = SysConstant.TABLE_PRE+"course_type_tag_relation")
public class CourseTypeTagRelation extends BaseEntity {
private static final long serialVersionUID = 1L;
@Column(name = "sys_type1",length = 20)
private String sysType1;
@Column(name = "sys_type2",length = 20)
private String sysType2;
@Column(name = "sys_type3",length = 20)
private String sysType3;
@Column(name = "tag_id",length = 20)
private String tagId;
}

View File

@@ -52,6 +52,7 @@ public class CourseToCourseFullText {
cft.setTeacher("");
cft.setTeacherCode("");
cft.setType(c.getType());
cft.setTags(c.getTags());
if(c.getOpenCourse()==null) {
cft.setOpenCourse(0);
}else {

View File

@@ -343,4 +343,6 @@ public interface ICourseService {
List<Course> findByIds(List<String> courseIds);
void deletedStudyResourceBatchByCourseIdAndType(String courseId,Integer courseType);
void getPhpCourseData();
}

View File

@@ -0,0 +1,95 @@
package com.xboe.module.course.service;
import com.xboe.common.OrderCondition;
import com.xboe.common.PageList;
import com.xboe.core.CurrentUser;
import com.xboe.core.JsonResponse;
import com.xboe.core.orm.IFieldFilter;
import com.xboe.module.article.entity.Article;
import com.xboe.module.course.dto.CourseTagQueryDto;
import com.xboe.module.course.dto.CourseTagRelationDto;
import com.xboe.module.course.entity.Course;
import com.xboe.module.course.entity.CourseTag;
import com.xboe.module.course.entity.CourseTagRelation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.util.List;
/**
* @InterfaceName:ICourseTagService
* @author:zhengge@oracle.com
* @since:2025/7/2516:53
*/
public interface ICourseTagService {
/**
* 分页查询标签列表,使用自定义filter
* @param pageIndex
* @param pageSize
* @return
*/
PageList<CourseTag> query(Integer pageIndex, Integer pageSize, List<IFieldFilter> filters, OrderCondition order);
/**
* 分页查询指定id标签关联的课程列表,使用自定义filter
* @param pageIndex
* @param pageSize
* @return
*/
PageList<CourseTagRelationDto> getCourseByTag(Integer pageIndex, Integer pageSize, Long tagId, Boolean isAsc);
/**
* 修改指定id的课程标签的公共属性
* @param id
* @param isPublic
* @return
*/
void changePublicStatus(Long id,Boolean isPublic);
/**
* 修改指定id的课程标签的热点属性
* @param id
* @param isHot
* @return
*/
void changeHotStatus(Long id,Boolean isHot);
/**
* 解除指定id的课程和某个标签之间的关联关系
* @return
*/
void unbind(String id);
/**
* 根据标签名称进行检索(模糊查询)
* @param tagName
* @return 符合检索条件的所有公共标签
*/
List<CourseTag> searchTags(String tagName,String userId,String typeId);
/**
* 创建新标签,并与当前课程绑定
* @param courseTagRelationDto
* @return
*/
CourseTag createTag(CourseTagRelationDto courseTagRelationDto);
/**
* 根据课程类型获取热点标签
* @param courseTagRelationDto
* @return
*/
List<CourseTag> getHotTagList(CourseTagRelationDto courseTagRelationDto);
/**
* 根据多个id获取标签
* @param id
* @return
*/
List<CourseTag> getTagsByIds(String id);
CourseTag getTagByName(String tagName);
void updateTags(Course oldCourse,Course newCourse,CurrentUser userInfo);
}

View File

@@ -15,12 +15,25 @@ import java.util.stream.Stream;
import javax.annotation.Resource;
import javax.management.Query;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson2.JSON;
import com.xboe.api.ThirdApi;
import com.xboe.core.orm.*;
import com.xboe.module.course.dao.*;
import com.xboe.module.course.entity.*;
import com.xboe.module.course.dto.CourseTagRelationDto;
import com.xboe.module.course.entity.*;
import com.xboe.module.course.service.ICourseTagService;
import com.xboe.school.study.dao.StudyCourseDao;
import com.xboe.school.study.entity.StudyCourse;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.HttpClient;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
@@ -41,24 +54,9 @@ import com.xboe.common.beans.KeyValue;
import com.xboe.common.utils.IDGenerator;
import com.xboe.common.utils.StringUtil;
import com.xboe.core.event.IEventDataSender;
import com.xboe.module.course.dao.CourseContentDao;
import com.xboe.module.course.dao.CourseCrowdDao;
import com.xboe.module.course.dao.CourseDao;
import com.xboe.module.course.dao.CourseExamDao;
import com.xboe.module.course.dao.CourseHRBPAuditDao;
import com.xboe.module.course.dao.CourseHomeWorkDao;
import com.xboe.module.course.dao.CourseSectionDao;
import com.xboe.module.course.dao.CourseTeacherDao;
import com.xboe.module.course.dao.CourseUpdateLogDao;
import com.xboe.module.course.dto.CourseFullDto;
import com.xboe.module.course.dto.CourseQueryDto;
import com.xboe.module.course.dto.RankingDto;
import com.xboe.module.course.entity.Course;
import com.xboe.module.course.entity.CourseCrowd;
import com.xboe.module.course.entity.CourseHRBPAudit;
import com.xboe.module.course.entity.CourseSection;
import com.xboe.module.course.entity.CourseTeacher;
import com.xboe.module.course.entity.CourseUpdateLog;
import com.xboe.module.course.service.ICourseFullTextSearch;
import com.xboe.module.course.service.ICourseService;
import com.xboe.module.interaction.service.ICourseGradeService;
@@ -98,7 +96,8 @@ public class CourseServiceImpl implements ICourseService {
@Resource
private CourseHRBPAuditDao courseHRBPAuditDao;
@Resource
private ICourseTagService courseTagService;
@Resource
private SysLogAuditDao logAuditDao;//审核日志记录
@@ -125,8 +124,9 @@ public class CourseServiceImpl implements ICourseService {
@Resource
RestHighLevelClient restHighLevelClient;
@Resource
private CourseTeacherDeletedRecordDao courseTeacherDeletedRecordDao;
/**
* 生成过滤条件
*
@@ -183,7 +183,7 @@ public class CourseServiceImpl implements ICourseService {
filters.add(FieldFilters.in("device", Course.DEVICE_MOBILE, Course.DEVICE_ALL));
} else if (dto.getDevice() == Course.DEVICE_ALL) {
filters.add(FieldFilters.eq("device", Course.DEVICE_ALL));
}else if (dto.getDevice() == Course.DEVICE_INTERNAL) {
} else if (dto.getDevice() == Course.DEVICE_INTERNAL) {
filters.add(FieldFilters.eq("device", Course.DEVICE_INTERNAL));
}
@@ -425,15 +425,15 @@ public class CourseServiceImpl implements ICourseService {
if (TempFilterConfig.Manager_CourseFile_ByOrgIds) {
if (dto.getIsSystemAdmin() == null || !dto.getIsSystemAdmin()) {
List<String> finalStrings = strings;
log.info("dto为"+dto);
if(dto.getIsCreateCourse()!=null&&dto.getIsCreateCourse()){
log.info("dto为" + dto);
if (dto.getIsCreateCourse() != null && dto.getIsCreateCourse()) {
listByFilters2.removeIf(e -> {
//去掉未发布的课程
if (!e.getPublished() && seache.contains(e.getId()) && !finalStrings.contains(e.getOrgId()) && !dto.getOrgAid().equals(e.getSysCreateAid())) {
return true;
}
//去掉所有条件都不符合的课程
if(!seache.contains(e.getId())&&!dto.getReadIds().contains(e.getId())&& !finalStrings.contains(e.getOrgId()) && !dto.getOrgAid().equals(e.getSysCreateAid())){
if (!seache.contains(e.getId()) && !dto.getReadIds().contains(e.getId()) && !finalStrings.contains(e.getOrgId()) && !dto.getOrgAid().equals(e.getSysCreateAid())) {
return true;
}
return false;
@@ -868,7 +868,7 @@ public class CourseServiceImpl implements ICourseService {
}
// 删除ES数据
deletedStudyResourceBatchByCourseIdAndType(id,c.getType());
deletedStudyResourceBatchByCourseIdAndType(id, c.getType());
} else {
//彻底删除,课件设置为无课程状态
courseDao.setDeleted(id);
@@ -998,10 +998,27 @@ public class CourseServiceImpl implements ICourseService {
if (c.getVisible() == null) {
c.setVisible(true);
}
if (c.getTags() != null && !c.getTags().isEmpty()){
CourseTagRelationDto courseTagRelationDto = new CourseTagRelationDto();
courseTagRelationDto.setCourseId(c.getId());
courseTagRelationDto.setSysType1(c.getSysType1());
courseTagRelationDto.setSysType2(c.getSysType2());
courseTagRelationDto.setSysType3(c.getSysType3());
String tags = c.getTags();
List<CourseTag> tagList = courseTagService.getTagsByIds(tags);
if (ObjectUtil.isNotEmpty(tagList)){
for (CourseTag tag : tagList) {
courseTagRelationDto.setTagName(tag.getTagName());
courseTagService.createTag(courseTagRelationDto);
}
}
}
courseDao.update(c);
c.setSysVersion(courseDao.getVersion(c.getId()));
full.getCourse().setSysVersion(c.getSysVersion());
// 兼容处理,记录下删除的关联数据
createCourseTeacherDeletedRecord(c.getId());
//先清空教师信息, 教师信息如果不一样了,也要加入到日志中
courseTeacherDao.deleteByField("courseId", c.getId());
if (full.getTeachers() != null && !full.getTeachers().isEmpty()) {
@@ -1056,6 +1073,8 @@ public class CourseServiceImpl implements ICourseService {
c.setSysVersion(courseDao.getVersion(c.getId()));
full.getCourse().setSysVersion(c.getSysVersion());
// 兼容处理,记录下删除的关联数据
createCourseTeacherDeletedRecord(c.getId());
//先清空教师信息, 教师信息如果不一样了,也要加入到日志中
courseTeacherDao.deleteByField("courseId", c.getId());
if (full.getTeachers() != null && !full.getTeachers().isEmpty()) {
@@ -1087,10 +1106,15 @@ public class CourseServiceImpl implements ICourseService {
public void submitAndPublish(CourseFullDto full, String aid, String aname) throws Exception {
Course c = full.getCourse();//当前的课程信息
log.info(" 课程 c = " + c.getId());
log.info(" 课程 c = " + c);
c.setPublished(true);
c.setPublishTime(LocalDateTime.now());
courseDao.update(c);
log.info(" 课程 c = " + c.getId());
// 兼容处理,记录下删除的关联数据
createCourseTeacherDeletedRecord(c.getId());
//先清空教师信息, 教师信息如果不一样了,也要加入到日志中
courseTeacherDao.deleteByField("courseId", c.getId());
if (full.getTeachers() != null && !full.getTeachers().isEmpty()) {
@@ -1999,7 +2023,108 @@ public class CourseServiceImpl implements ICourseService {
return courseDao.findListByHql("Select new Course(id,studys,score) from Course where id in(?1)", ids);
}
private class Result{
private Boolean success;
private Data data;
private class Data{
private List<Map<String,Object>> result;
public List<Map<String, Object>> getResult() {
return result;
}
public void setResult(List<Map<String, Object>> result) {
this.result = result;
}
}
public void setData(Data data) {
this.data = data;
}
public Boolean getSuccess() {
return success;
}
public void setSuccess(Boolean success) {
this.success = success;
}
public Data getData() {
return data;
}
}
@Override
public void getPhpCourseData() {
HttpRequest request = HttpUtil.createGet("https://u.boe.com/api/b1/new-employee/course-list");
HttpResponse response = request.execute();
String body = response.body();
Result result = JSON.parseObject(body,Result.class);
log.info("php课程数据获取成功");
List<Map<String,Object>> phpCourseDataList = result.getData().getResult();
for (Map<String, Object> phpCourseData : phpCourseDataList){
log.info("开始同步数据:"+phpCourseData.get("course_name"));
}
List<Map<String,Object>> phpStudyCourseList = null;
// 查询数据库中是否存在php课程数据
for (int i = 0; i < phpCourseDataList.size(); i++) {
// 查询php的课程数据在数据库中是否已经存在
String phpCourseName = (String) phpCourseDataList.get(i).get("course_name");
Boolean exist = isCourseName(phpCourseName,"");
if (!exist){
log.info(phpCourseName+"不存在,开始同步");
Course newCourse = new Course();
// 设置学习人数
int studys = Integer.parseInt(phpCourseDataList.get(i).get("learned_number").toString());
newCourse.setStudys(studys);
// 设置系统版本
int version = Integer.parseInt(phpCourseDataList.get(i).get("version").toString());
newCourse.setSysVersion(version);
// 设置电脑端还是手机端可见
int pcDevice = Integer.parseInt(phpCourseDataList.get(i).get("is_display_pc").toString());
int mobileDevice = Integer.parseInt(phpCourseDataList.get(i).get("is_display_mobile").toString());
if (pcDevice == 1 && mobileDevice == 1){
newCourse.setDevice(3);
} else if (pcDevice == 0 && mobileDevice == 1) {
newCourse.setDevice(2);
}else if(pcDevice == 1 && mobileDevice == 0){
newCourse.setDevice(1);
}
// 判断是否按照顺序学习
int orderStudy = Integer.parseInt(phpCourseDataList.get(i).get("mod_type").toString());
newCourse.setOrderStudy(orderStudy == 1 ? true : false);
// 设置课程简介
String summary = (String) phpCourseDataList.get(i).get("course_desc_nohtml");
newCourse.setSummary(summary);
// 设置课程类型
int courseType = Integer.parseInt(phpCourseDataList.get(i).get("course_type").toString());
newCourse.setType(courseType == 0 ? 20 : 30);
// 设置学习时长
int courseTime = Integer.parseInt(phpCourseDataList.get(i).get("course_period").toString());
newCourse.setStudyTime(courseTime);
// 设置课程封面
newCourse.setCoverImg("https://u.boe.com/pc/images/bgimg/course.png");
newCourse.setName(phpCourseName);
newCourse.setStatus(5);
newCourse.setComments(0);
newCourse.setDeleted(false);
newCourse.setEnabled(true);
newCourse.setFavorites(0);
newCourse.setIsTop(false);
newCourse.setViews(0);
newCourse.setPraises(0);
newCourse.setTrampleCount(0);
newCourse.setShares(0);
newCourse.setScore(0f);
courseDao.save(newCourse);
}else {
log.info(phpCourseName+"存在");
}
}
}
@Override
public void deletedStudyResourceBatchByCourseIdAndType(String courseId, Integer courseType) {
DeleteByQueryRequest request = new DeleteByQueryRequest("new_study_resource");
@@ -2013,4 +2138,25 @@ public class CourseServiceImpl implements ICourseService {
e.printStackTrace();
}
}
/**
* 删除boe_course_teacher数据时把删除的数据储存到boe_course_teacher_deleted_record表
* boe_course_teacher表没有deleted字段兼容处理
*
* @param courseId 课程ID
*/
private void createCourseTeacherDeletedRecord(String courseId) {
List<CourseTeacherDeletedRecord> courseTeacherList = courseTeacherDao.findList(FieldFilters.eq("courseId", courseId)).stream().map(ct -> {
CourseTeacherDeletedRecord courseTeacherDeletedRecord = new CourseTeacherDeletedRecord();
courseTeacherDeletedRecord.setCourseId(ct.getCourseId());
courseTeacherDeletedRecord.setTeacherId(ct.getTeacherId());
courseTeacherDeletedRecord.setTeacherName(ct.getTeacherName());
return courseTeacherDeletedRecord;
}).collect(Collectors.toList());
if (CollUtil.isNotEmpty(courseTeacherList)) {
courseTeacherDeletedRecordDao.saveList(courseTeacherList);
}
}
}

View File

@@ -0,0 +1,864 @@
package com.xboe.module.course.service.impl;
import com.xboe.common.OrderCondition;
import com.xboe.common.PageList;
import com.xboe.core.CurrentUser;
import com.xboe.core.orm.BaseEntity;
import com.xboe.core.orm.FieldFilters;
import com.xboe.core.orm.IFieldFilter;
import com.xboe.core.orm.QueryBuilder;
import com.xboe.module.course.dao.CourseDao;
import com.xboe.module.course.dao.CourseTagDao;
import com.xboe.module.course.dao.CourseTagRelationDao;
import com.xboe.module.course.dao.CourseTypeTagRelationDao;
import com.xboe.module.course.dto.CourseTagRelationDto;
import com.xboe.module.course.entity.Course;
import com.xboe.module.course.entity.CourseTag;
import com.xboe.module.course.entity.CourseTagRelation;
import com.xboe.module.course.entity.CourseTypeTagRelation;
import com.xboe.module.course.service.ICourseService;
import com.xboe.module.course.service.ICourseTagService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
/**
* @ClassName:CourseTagServiceImpl
* @author:zhengge@oracle.com
* @since:2025/7/2516:55
*/
@Slf4j
@Service
@Transactional
public class CourseTagServiceImpl implements ICourseTagService {
@Resource
private CourseTagDao courseTagDao;
@Resource
PublishCourseUtil publishUtil;
@Resource
private CourseTagRelationDao courseTagRelationDao;
@Resource
private CourseTypeTagRelationDao courseTypeTagRelationDao;
@Resource
private CourseDao courseDao;
/**
* 课程标签分页查询
* @param pageIndex
* @param pageSize
* @param filters
* @param order
* @return
*/
@Override
public PageList<CourseTag> query(Integer pageIndex, Integer pageSize, List<IFieldFilter> filters, OrderCondition order) {
try {
/* QueryBuilder query=QueryBuilder.from(CourseTag.class);
query.setPageIndex(pageIndex);
query.setPageSize(pageSize);
filters.add(FieldFilters.eq("deleted",false));
query.addFilters(filters);
if(order!=null) {
query.addOrder(order);
}else {
query.addOrder(OrderCondition.desc("sysCreateTime"));
}
log.info("标签列表:分页查询 调用接口IMPL query = " + query.builder().toString());
return courseTagDao.findPage(query.builder());*/
if(pageSize==100){
log.info("--- 11 ----------------------");
return courseTagDao.getList();
}else{
log.info("--- 22 ----------------------");
QueryBuilder query = QueryBuilder.from(CourseTag.class);
query.setPageIndex(pageIndex);
query.setPageSize(pageSize);
filters.add(FieldFilters.eq("deleted", false));
// query.addFilters(filters);
query.addOrder(OrderCondition.desc("sysCreateTime"));
return courseTagDao.findPage(query.builder());
}
} catch (Exception e) {
log.error("课程标签分页查询异常 = " + e.getMessage());
throw new RuntimeException(e);
}
}
/**
* 分页查询指定id标签关联的课程
* @param pageIndex
* @param pageSize
* @param tagId
* @param isAsc
* @return
*/
@Override
public PageList<CourseTagRelationDto> getCourseByTag(Integer pageIndex, Integer pageSize, Long tagId, Boolean isAsc) {
PageList<CourseTagRelationDto> list = null;
if(isAsc) {
list = courseTagRelationDao.findCoursesWithRelatedTagsAsc(pageIndex,pageSize,tagId);
}else {
list = courseTagRelationDao.findCoursesWithRelatedTagsDesc(pageIndex,pageSize,tagId);
}
return list;
}
/**
* 修改指定id的课程标签的公共属性
* @param id
* @param isPublic
* @return
*/
@Override
public void changePublicStatus(Long id, Boolean isPublic) {
CourseTag courseTag = courseTagDao.findOne(FieldFilters.eq("id", String.valueOf(id)));
if (courseTag!=null){
courseTag.setIsPublic(isPublic);
courseTag.setLastSetPublicTime(isPublic?LocalDateTime.now():null);
courseTagDao.update(courseTag);
}
}
/**
* 修改指定id的课程标签的热点属性
* @param id
* @param isHot
* @return
*/
@Override
public void changeHotStatus(Long id, Boolean isHot) {
CourseTag courseTag = courseTagDao.findOne(FieldFilters.eq("id", String.valueOf(id)));
if (courseTag!=null){
courseTag.setIsHot(isHot);
courseTag.setLastSetHotTime(isHot?LocalDateTime.now():null);
courseTagDao.update(courseTag);
}
}
/**
* 解除指定id的课程和某个标签之间的关联关系
* @return
*/
@Override
public void unbind(String id) {
//根据主键查询关联关系
CourseTagRelation courseTagRelation = courseTagRelationDao.findOne(FieldFilters.eq("id", id));
if (courseTagRelation != null){
//修改该标签关联课程数
CourseTag courseTag = courseTagDao.findOne(FieldFilters.eq("id", String.valueOf(courseTagRelation.getTagId())));
if (courseTag != null){
courseTag.setUseCount(courseTag.getUseCount()>1?courseTag.getUseCount()-1:0);
courseTagDao.updateFieldById(courseTag.getId(),"useCount",courseTag.getUseCount());
}
//解绑(删除关联关系)
courseTagRelationDao.setDeleted(id);
Course course = courseDao.get(courseTagRelation.getCourseId().toString());
String tags = course.getTags();
if (StringUtils.isNotBlank(tags)){
String[] tagIds = tags.split(",");
List<String> tagIdList = new ArrayList<>();
for (String tagId : tagIds){
if (!tagId.equals(courseTagRelation.getTagId().toString())){
tagIdList.add(tagId);
}
}
// 数据格式:1,2,3
String s = StringUtils.join(tagIdList, ",");
if (!"".equals(s)){
s+=",";
}
course.setTags(s);
}
// 同步ES
publishUtil.fullTextPublish(course);
}
}
/**
* 根据标签名称进行检索(模糊查询)
* @param tagName
* @return 符合检索条件的所有公共标签
*/
public List<CourseTag> searchTags(String tagName){
QueryBuilder query=QueryBuilder.from(CourseTag.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("deleted",false));//未删除
filters.add(FieldFilters.eq("isPublic",true));//公共标签
filters.add(FieldFilters.like("tagName",tagName));//模糊检索
query.addFilters(filters);
List<CourseTag> courseTagList = courseTagDao.findList(query.builder());
return courseTagList;
}
@Override
public List<CourseTag> searchTags(String tagName,String userId,String typeId){
List<CourseTag> tagList = courseTagDao.searchTags(tagName,userId,typeId);
return tagList;
}
/**
* 创建新标签,并与指定课程绑定
* @return
*/
/*@Override
public CourseTag createTag(CourseTagRelationDto courseTagRelationDto) {
CourseTag courseTag = null;
String tagName = courseTagRelationDto.getTagName();
Long courseId = Long.valueOf(courseTagRelationDto.getCourseId());
//1.创建标签:先判断是否已经存在该标签
QueryBuilder query=QueryBuilder.from(CourseTag.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("tagName",tagName));//精确匹配
query.addFilters(filters);
List<CourseTag> courseTagList = courseTagDao.findList(query.builder());
if (courseTagList==null || courseTagList.size()==0){//1.1 如果该标签不存在,则新建标签
courseTag = new CourseTag();
courseTag.setTagName(tagName);
courseTag.setIsPublic(false);
courseTag.setIsHot(false);
courseTag.setUseCount(1);
courseTagDao.save(courseTag);
//新建一条标签和课程的关联关系
CourseTagRelation courseTagRelation = new CourseTagRelation();
courseTagRelation.setTagId(Long.valueOf(courseTag.getId()));
courseTagRelation.setCourseId(courseId);
courseTagRelationDao.save(courseTagRelation);
}else {//1.2 否则修改标签
courseTag=courseTagList.get(0);
// 当同一标签被3个及以上课管创建时默认开启这个标签的公共化
if(courseTag.getUseCount() >= 3){
courseTag.setIsPublic(true);
}
courseTag.setDeleted(false);//有可能是之前被删除的标签,这里恢复为有效
//查找改课程与这个标签是否已经建立关联关系
query=QueryBuilder.from(CourseTagRelation.class);
filters = new ArrayList<>();
filters.add(FieldFilters.eq("tagId",Long.valueOf(courseTag.getId())));//精确匹配
filters.add(FieldFilters.eq("courseId",courseId));//精确匹配
query.addFilters(filters);
List<CourseTagRelation> courseTagRelationList = courseTagRelationDao.findList(query.builder());
//1.2.1 如果还未建立关联关系,则新建一条标签和课程的关联关系
if (courseTagRelationList==null || courseTagRelationList.size()==0){
CourseTagRelation courseTagRelation = new CourseTagRelation();
courseTagRelation.setTagId(Long.valueOf(courseTag.getId()));
courseTagRelation.setCourseId(courseId);
courseTagRelationDao.save(courseTagRelation);
//更新该标签的关联课程数量
courseTag.setUseCount(courseTag.getUseCount()+1);
}else {//1.2.2 否则修改该标签和课程的关联关系
CourseTagRelation courseTagRelation = courseTagRelationList.get(0);
if (courseTagRelation.getDeleted()){//之前"解绑",这里恢复为有效
courseTagRelation.setDeleted(false);
courseTagRelationDao.saveOrUpdate(courseTagRelation);
//更新该标签的关联课程数量
courseTag.setUseCount(courseTag.getUseCount()+1);
}
}
courseTagDao.saveOrUpdate(courseTag);
}
//2.创建该标签和课程分类之间的关联关系
courseTagRelationDto.setTagId(courseTag.getId());
createCourseTypeAndTagRelation(courseTagRelationDto);
return courseTag;
}
*/
@Override
public CourseTag getTagByName(String tagName) {
CourseTag courseTag = courseTagDao.getTagByName(tagName);
return courseTag;
}
@Override
public List<CourseTag> getTagsByIds(String id) {
// id=17,18
List<CourseTag> courseTagList = courseTagDao.getTagsByIds(id);
return courseTagList;
}
/**
* 获取热门标签
* @param courseTagRelationDto
* @return
*/
@Override
public List<CourseTag> getHotTagList(CourseTagRelationDto courseTagRelationDto) {
List<CourseTag> hotTagList = null;
if (StringUtils.isNotBlank(courseTagRelationDto.getSysType1()) ||
StringUtils.isNotBlank(courseTagRelationDto.getSysType2()) ||
StringUtils.isNotBlank(courseTagRelationDto.getSysType3())){
String sysType1 = courseTagRelationDto.getSysType1();
String sysType2 = courseTagRelationDto.getSysType2();
String sysType3 = courseTagRelationDto.getSysType3();
hotTagList = courseTagDao.getHotTagListBySysTypes(sysType1,sysType2,sysType3);
}else {
hotTagList = courseTagDao.getHotTagList();
}
return hotTagList;
}
/**
* 创建标签和课程分类之间的关联关系
* @param courseTagRelationDto
*/
private void createCourseTypeAndTagRelation(CourseTagRelationDto courseTagRelationDto){
String sysType1 = courseTagRelationDto!=null?courseTagRelationDto.getSysType1():null;
String tagId = courseTagRelationDto!=null?courseTagRelationDto.getTagId():null;
if (StringUtils.isNotBlank(sysType1) && StringUtils.isNotBlank(tagId)){
String sysType2 = courseTagRelationDto.getSysType2();
String sysType3 = courseTagRelationDto.getSysType3();
//判断数据库中该课程分类和标签是否已经存在关联关系
if (!isHadCourseTypeAndTagRelation(courseTagRelationDto,true)){//不存在,则新建
CourseTypeTagRelation courseTypeTagRelation = new CourseTypeTagRelation();
courseTypeTagRelation.setSysType1(sysType1);
courseTypeTagRelation.setSysType2(StringUtils.isNotBlank(sysType2)?sysType2:"0");
courseTypeTagRelation.setSysType3(StringUtils.isNotBlank(sysType3)?sysType3:"0");
courseTypeTagRelation.setTagId(tagId);
courseTypeTagRelationDao.save(courseTypeTagRelation);
}
}
}
/**
* 判断数据库制定的课程分类和标签是否已经存在关联关系
* @param courseTagRelationDto
* @param clearFlag 清理标识 true清理已存在的数据只保留一条有效数据
* @return true:已存在false:不存在
*/
private Boolean isHadCourseTypeAndTagRelation(CourseTagRelationDto courseTagRelationDto,Boolean clearFlag){
QueryBuilder query=QueryBuilder.from(CourseTypeTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("sysType1",courseTagRelationDto.getSysType1()));//一级分类
filters.add(FieldFilters.eq("sysType2",courseTagRelationDto.getSysType1()));//二级分类
filters.add(FieldFilters.eq("sysType3",courseTagRelationDto.getSysType1()));//三级分类
filters.add(FieldFilters.eq("tagId",courseTagRelationDto.getTagId()));
List<CourseTypeTagRelation> courseTypeTagRelList = courseTypeTagRelationDao.findList(query.addFilters(filters).builder());
Boolean isExist = (courseTypeTagRelList!=null && courseTypeTagRelList.size()>0)?true:false;
if (isExist && clearFlag ){
List<CourseTypeTagRelation> toRemove = new ArrayList<>();
for (CourseTypeTagRelation courseTypeTagRel : courseTypeTagRelList) {
if (courseTypeTagRel.getDeleted()) {//如果是逻辑删的本次物理删除
courseTypeTagRelationDao.getGenericDao().delete(courseTypeTagRel);
toRemove.add(courseTypeTagRel);
}
}
courseTypeTagRelList.removeAll(toRemove);//移除逻辑删的数据
//如果还存在有效数据
if (courseTypeTagRelList!=null && courseTypeTagRelList.size()>0){
//只保留一条有效数据,其余物理删除
for (int i = courseTypeTagRelList.size() - 1; i >= 1; i--) {
CourseTypeTagRelation courseTypeTagRel = courseTypeTagRelList.get(i);
if (courseTypeTagRel.getDeleted()) {
courseTypeTagRelationDao.getGenericDao().delete(courseTypeTagRel);
courseTypeTagRelList.remove(i); // 倒序删除不影响未遍历的索引
}
}
isExist = true;//存在一条有效数据
}else {
isExist = false;//不存在有效数据了
}
}
return isExist;
}
/**
* 创建新标签
* @param courseTagRelationDto
* @return
*/
@Override
public CourseTag createTag(CourseTagRelationDto courseTagRelationDto) {
CourseTag courseTag = null;
String tagName = courseTagRelationDto.getTagName();
//1.创建标签:先判断是否已经存在该标签
QueryBuilder query=QueryBuilder.from(CourseTag.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("tagName",tagName));//精确匹配
filters.add(FieldFilters.eq("status",0));//正式
filters.add(FieldFilters.eq("deleted",false));//未删除的
query.addFilters(filters);
List<CourseTag> courseTagList = courseTagDao.findList(query.builder());
if (courseTagList==null || courseTagList.isEmpty()){//1.1 如果该标签不存在,则新建标签
courseTag = new CourseTag();
courseTag.setTagName(tagName);
courseTag.setIsPublic(false);
courseTag.setIsHot(false);
courseTag.setStatus(1);
courseTag.setUseCount(1);
courseTagDao.save(courseTag);
}
return courseTag;
}
@Override
public void updateTags(Course oldCourse, Course newCourse, CurrentUser userInfo) {
log.info(" --- 标签修改 --- 在线课参数 oldCourse = {} " , oldCourse);
log.info(" --- 标签修改 --- 在线课参数 newCourse = {} " , newCourse);
log.info(" --- 标签修改 --- 用户信息 userInfo = {} " , userInfo);
// 获取新旧课程的标签ID列表
List<String> oldTagIds = getTagIdsFromCourse(oldCourse);
List<String> newTagIds = getTagIdsFromCourse(newCourse);
log.info(" --- 旧标签 oldTagIds = {} " , oldTagIds);
log.info(" --- 新修改 newTagIds = {} " , newTagIds);
if (oldCourse == null) {
// 新增课程 - 处理所有新标签
handleNewCourseTags(newCourse, newTagIds, userInfo);
} else {
// 编辑课程 - 比较差异并处理
handleEditCourseTags(oldCourse, newCourse, oldTagIds, newTagIds, userInfo);
}
log.info("完成课程标签更新: courseId={}", newCourse != null ? newCourse.getId() : "null");
}
/**
* 从课程对象中提取标签ID列表
*/
private List<String> getTagIdsFromCourse(Course course) {
if (course == null || StringUtils.isBlank(course.getTags())) {
return new ArrayList<>();
}
String tags = course.getTags();
// 去除结尾的逗号并分割
if (tags.endsWith(",")) {
tags = tags.substring(0, tags.length() - 1);
}
if (StringUtils.isBlank(tags)) {
return new ArrayList<>();
}
return Arrays.asList(tags.split(","));
}
/**
* 处理新增课程的标签逻辑
*/
private void handleNewCourseTags(Course newCourse, List<String> newTagIds, CurrentUser userInfo) {
log.info("处理新增课程的标签逻辑: courseId={}, tagCount={}", newCourse != null ? newCourse.getId() : "null", newTagIds.size());
String courseId = newCourse.getId();
for (String tagId : newTagIds) {
if (StringUtils.isBlank(tagId)) {
continue;
}
// 获取标签信息
CourseTag tag = courseTagDao.findOne(FieldFilters.eq("id", tagId.trim()));
if (tag == null) {
log.warn("标签不存在: {}", tagId);
continue;
}
//合并临时标签
tag = mergeTag(tag);
// 创建课程-标签关联关系
createCourseTagRelation(courseId, tag, userInfo);
// 创建分类-标签关联关系
createCourseTypeTagRelations(newCourse, tag, userInfo);
// 更新标签使用计数并检查是否设置为公共标签
updateTagUseCountAndPublicStatus(tag, userInfo);
}
log.info("完成新增课程标签处理: courseId={}", newCourse != null ? newCourse.getId() : "null");
}
/**
* 处理编辑课程的标签逻辑
*/
private void handleEditCourseTags(Course oldCourse, Course newCourse,
List<String> oldTagIds, List<String> newTagIds, CurrentUser userInfo) {
log.info("处理编辑课程的标签逻辑: courseId={}, oldTagCount={}, newTagCount={}, toRemove={}, toAdd={}",
newCourse != null ? newCourse.getId() : "null",
oldTagIds.size(), newTagIds.size(),
oldTagIds.stream().filter(tagId -> !newTagIds.contains(tagId)).count(),
newTagIds.stream().filter(tagId -> !oldTagIds.contains(tagId)).count());
String courseId = newCourse.getId();
// 找出需要删除的标签(存在于旧课程但不在新课程中)
List<String> tagsToRemove = oldTagIds.stream()
.filter(tagId -> !newTagIds.contains(tagId))
.collect(Collectors.toList());
// 找出需要新增的标签(存在于新课程但不在旧课程中)
List<String> tagsToAdd = newTagIds.stream()
.filter(tagId -> !oldTagIds.contains(tagId))
.collect(Collectors.toList());
// 处理标签删除
for (String tagId : tagsToRemove) {
removeCourseTagRelation(courseId, tagId, userInfo);
}
// 处理标签新增
for (String tagId : tagsToAdd) {
CourseTag tag = courseTagDao.findOne(FieldFilters.eq("id", tagId.trim()));
if (tag == null) {
log.warn("标签不存在: {}", tagId);
continue;
}
//如果已有同名的正式标签 则需要合并
//合并临时标签
tag = mergeTag(tag);
// 创建课程-标签关联关系
createCourseTagRelation(courseId, tag, userInfo);
// 创建分类-标签关联关系
createCourseTypeTagRelations(newCourse, tag, userInfo);
// 更新标签使用计数并检查是否设置为公共标签
updateTagUseCountAndPublicStatus(tag, userInfo);
}
// 处理分类变化导致的标签关联关系更新
if (hasCourseTypeChanged(oldCourse, newCourse)) {
updateCourseTypeTagRelations(oldCourse, newCourse, newTagIds, userInfo);
}
log.info("完成编辑课程标签处理: courseId={}", newCourse != null ? newCourse.getId() : "null");
}
/**
* 合并标签
*/
private CourseTag mergeTag(CourseTag tag){
//只处理临时标签 正式的忽略
if (tag.getStatus()==1){
QueryBuilder query=QueryBuilder.from(CourseTag.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("tagName",tag.getTagName()));//精确匹配
filters.add(FieldFilters.eq("status",0));//正式
filters.add(FieldFilters.eq("deleted",false));//未删除的
query.addFilters(filters);
List<CourseTag> courseTagList = courseTagDao.findList(query.builder());
log.info("标签合并 createTag courseTagList = {} " , courseTagList);
//如果无同名正式标签 则转正
//有同名正式标签 则合并
if (courseTagList != null && !courseTagList.isEmpty()) {
//删除临时标签
tag.setSysUpdateBy("系统合并删除");
tag.setSysUpdateTime(LocalDateTime.now());
courseTagDao.setDeleted(tag.getId());
//返回同名正式标签
tag = courseTagList.get(0);
}
}
return tag;
}
/**
* 创建课程-标签关联关系
*/
private void createCourseTagRelation(String courseId, CourseTag tag, CurrentUser userInfo) {
log.debug("创建课程-标签关联关系: courseId={}, tagId={}, tagName={}",
courseId, tag != null ? tag.getId() : "null", tag != null ? tag.getTagName() : "null");
// 检查是否已存在关联关系
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("courseId", Long.valueOf(courseId)));
filters.add(FieldFilters.eq("tagId", Long.valueOf(tag.getId())));
query.addFilters(filters);
List<CourseTagRelation> existingRelations = courseTagRelationDao.findList(query.builder());
LocalDateTime now = LocalDateTime.now();
if (existingRelations.isEmpty()) {
// 新建关联关系
CourseTagRelation relation = new CourseTagRelation();
relation.setCourseId(Long.valueOf(courseId));
relation.setTagId(Long.valueOf(tag.getId()));
// 设置创建信息
relation.setSysCreateAid(userInfo.getAccountId());
relation.setSysCreateBy(userInfo.getName());
relation.setSysCreateTime(now);
// 设置更新信息
relation.setSysUpdateBy(userInfo.getName());
relation.setSysUpdateTime(now);
courseTagRelationDao.save(relation);
} else {
// 恢复已删除的关联关系
CourseTagRelation relation = existingRelations.get(0);
if (relation.getDeleted()) {
relation.setDeleted(false);
// 设置更新信息
relation.setSysUpdateBy(userInfo.getName());
relation.setSysUpdateTime(now);
courseTagRelationDao.saveOrUpdate(relation);
}
}
log.debug("完成课程-标签关联关系创建: courseId={}, tagId={}", courseId, tag != null ? tag.getId() : "null");
}
/**
* 创建分类-标签关联关系
*/
private void createCourseTypeTagRelations(Course course, CourseTag tag, CurrentUser userInfo) {
log.debug("创建分类-标签关联关系: courseId={}, tagId={}, sysType1={}, sysType2={}, sysType3={}",
course != null ? course.getId() : "null",
tag != null ? tag.getId() : "null",
course != null ? course.getSysType1() : "null",
course != null ? course.getSysType2() : "null",
course != null ? course.getSysType3() : "null");
String sysType1 = course.getSysType1();
String sysType2 = course.getSysType2();
String sysType3 = course.getSysType3();
// 根据分类级别创建相应的关联关系
if (StringUtils.isNotBlank(sysType3)) {
createSingleCourseTypeTagRelation(sysType1, sysType2, sysType3, tag.getId(), userInfo);
}else if (StringUtils.isNotBlank(sysType2)) {
createSingleCourseTypeTagRelation(sysType1, sysType2, "0", tag.getId(), userInfo);
}else if (StringUtils.isNotBlank(sysType1)) {
createSingleCourseTypeTagRelation(sysType1, "0", "0", tag.getId(), userInfo);
}
}
/**
* 创建单个分类-标签关联关系
*/
private void createSingleCourseTypeTagRelation(String sysType1, String sysType2, String sysType3,
String tagId, CurrentUser userInfo) {
// 检查是否已存在关联关系
QueryBuilder query = QueryBuilder.from(CourseTypeTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("sysType1", sysType1));
filters.add(FieldFilters.eq("sysType2", sysType2));
filters.add(FieldFilters.eq("sysType3", sysType3));
filters.add(FieldFilters.eq("tagId", tagId));
query.addFilters(filters);
List<CourseTypeTagRelation> existingRelations = courseTypeTagRelationDao.findList(query.builder());
LocalDateTime now = LocalDateTime.now();
if (existingRelations.isEmpty()) {
// 新建关联关系
CourseTypeTagRelation relation = new CourseTypeTagRelation();
relation.setSysType1(sysType1);
relation.setSysType2(sysType2);
relation.setSysType3(sysType3);
relation.setTagId(tagId);
// 设置创建信息
relation.setSysCreateAid(userInfo.getAccountId());
relation.setSysCreateBy(userInfo.getName());
relation.setSysCreateTime(now);
// 设置更新信息
relation.setSysUpdateBy(userInfo.getName());
relation.setSysUpdateTime(now);
courseTypeTagRelationDao.save(relation);
} else {
// 恢复已删除的关联关系
CourseTypeTagRelation relation = existingRelations.get(0);
if (relation.getDeleted()) {
relation.setDeleted(false);
// 设置更新信息
relation.setSysUpdateBy(userInfo.getName());
relation.setSysUpdateTime(now);
courseTypeTagRelationDao.saveOrUpdate(relation);
}
}
}
/**
* 移除课程-标签关联关系
*/
private void removeCourseTagRelation(String courseId, String tagId, CurrentUser userInfo) {
log.debug("移除课程-标签关联关系: courseId={}, tagId={}", courseId, tagId);
// 查找关联关系
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("courseId", Long.valueOf(courseId)));
filters.add(FieldFilters.eq("tagId", Long.valueOf(tagId)));
query.addFilters(filters);
List<CourseTagRelation> relations = courseTagRelationDao.findList(query.builder());
if (!relations.isEmpty()) {
CourseTagRelation relation = relations.get(0);
// 设置更新信息
relation.setSysUpdateBy(userInfo.getName());
relation.setSysUpdateTime(LocalDateTime.now());
// 逻辑删除关联关系
courseTagRelationDao.setDeleted(relation.getId());
// 更新标签使用计数
CourseTag tag = courseTagDao.findOne(FieldFilters.eq("id", tagId));
if (tag != null) {
tag.setUseCount(Math.max(0, tag.getUseCount() - 1));
// 设置更新信息
tag.setSysUpdateBy(userInfo.getName());
tag.setSysUpdateTime(LocalDateTime.now());
courseTagDao.update(tag);
}
// 检查是否需要删除分类-标签关联关系
checkAndRemoveCourseTypeTagRelation(tagId, userInfo);
}
log.debug("完成课程-标签关联关系移除: courseId={}, tagId={}", courseId, tagId);
}
/**
* 检查并删除分类-标签关联关系(如果没有其他课程使用)
*/
private void checkAndRemoveCourseTypeTagRelation(String tagId, CurrentUser userInfo) {
// 检查是否还有其他课程使用这个标签
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("tagId", Long.valueOf(tagId)));
filters.add(FieldFilters.eq("deleted", false));
query.addFilters(filters);
List<CourseTagRelation> activeRelations = courseTagRelationDao.findList(query.builder());
// 如果没有其他活跃的关联关系,删除分类-标签关联
if (activeRelations.isEmpty()) {
QueryBuilder typeQuery = QueryBuilder.from(CourseTypeTagRelation.class);
List<IFieldFilter> typeFilters = new ArrayList<>();
typeFilters.add(FieldFilters.eq("tagId", tagId));
typeQuery.addFilters(typeFilters);
List<CourseTypeTagRelation> typeRelations = courseTypeTagRelationDao.findList(typeQuery.builder());
LocalDateTime now = LocalDateTime.now();
for (CourseTypeTagRelation relation : typeRelations) {
// 设置更新信息
relation.setSysUpdateBy(userInfo.getName());
relation.setSysUpdateTime(now);
courseTypeTagRelationDao.setDeleted(relation.getId());
}
}
}
/**
* 更新标签使用计数并检查公共标签状态
*/
private void updateTagUseCountAndPublicStatus(CourseTag tag, CurrentUser userInfo) {
log.debug("更新标签使用计数和公共状态: tagId={}, tagName={}, beforeUseCount={}",
tag != null ? tag.getId() : "null",
tag != null ? tag.getTagName() : "null",
tag != null ? tag.getUseCount() : "null");
// 将标签状态设置为正式(status=0)
if (tag != null && tag.getStatus() == 1) {
tag.setStatus(0); // 正式标签
}
// 统计当前活跃的关联关系数量
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("tagId", Long.valueOf(tag.getId())));
filters.add(FieldFilters.eq("deleted", false));
query.addFilters(filters);
List<CourseTagRelation> activeRelations = courseTagRelationDao.findList(query.builder());
int activeCount = activeRelations.size();
tag.setUseCount(activeCount);
LocalDateTime now = LocalDateTime.now();
// 检查是否满足设置为公共标签的条件
if (activeCount >= 3 && tag.getLastSetPublicTime() == null) {
// 只有从未手动关闭过公共标签的才自动开启
tag.setIsPublic(true);
tag.setLastSetPublicTime(now);
}
// 设置更新信息
tag.setSysUpdateBy(userInfo.getName());
tag.setSysUpdateTime(now);
courseTagDao.update(tag);
log.debug("完成标签使用计数和公共状态更新: tagId={}, tagName={}, afterUseCount={}, isPublic={}",
tag != null ? tag.getId() : "null",
tag != null ? tag.getTagName() : "null",
tag != null ? tag.getUseCount() : "null",
tag != null ? tag.getIsPublic() : "null");
}
/**
* 检查课程分类是否发生变化
*/
private boolean hasCourseTypeChanged(Course oldCourse, Course newCourse) {
return !Objects.equals(oldCourse.getSysType1(), newCourse.getSysType1()) ||
!Objects.equals(oldCourse.getSysType2(), newCourse.getSysType2()) ||
!Objects.equals(oldCourse.getSysType3(), newCourse.getSysType3());
}
/**
* 更新分类-标签关联关系(当分类变化时)
*/
private void updateCourseTypeTagRelations(Course oldCourse, Course newCourse,
List<String> tagIds, CurrentUser userInfo) {
// 移除旧的分类-标签关联关系
for (String tagId : tagIds) {
checkAndRemoveCourseTypeTagRelation(tagId, userInfo);
}
// 创建新的分类-标签关联关系
for (String tagId : tagIds) {
CourseTag tag = courseTagDao.findOne(FieldFilters.eq("id", tagId.trim()));
if (tag != null) {
createCourseTypeTagRelations(newCourse, tag, userInfo);
}
}
}
/**
* 设置实体的创建信息(新增时使用)
*/
private void setCreateInfo(BaseEntity entity, CurrentUser userInfo) {
LocalDateTime now = LocalDateTime.now();
entity.setSysCreateAid(userInfo.getAccountId());
entity.setSysCreateBy(userInfo.getName());
entity.setSysCreateTime(now);
entity.setSysUpdateBy(userInfo.getName());
entity.setSysUpdateTime(now);
}
/**
* 设置实体的更新信息(编辑时使用)
*/
private void setUpdateInfo(BaseEntity entity, CurrentUser userInfo) {
entity.setSysUpdateBy(userInfo.getName());
entity.setSysUpdateTime(LocalDateTime.now());
}
}

View File

@@ -592,8 +592,8 @@ public class StudyCourseApi extends ApiBaseController{
}
try {
studyService.finishVideoStudyItem(itemId, studyId,courseId,cnum,token);
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(studyId ,courseId, token);
log.info("在线课学习记录"+allUserList);
// List<StudyCourse> allUserList = thirdApi.getStudyCourseList(studyId ,courseId, token);
// log.info("在线课学习记录"+allUserList);
return success(true);
}catch(Exception e) {
log.error("记录内容学习完成错误",e);

View File

@@ -11,22 +11,22 @@ spring:
cloud:
nacos:
discovery:
server-addr: 192.168.10.74:8848
server-addr: 192.168.0.253:8848
config:
server-addr: 192.168.10.74:8848
server-addr: 192.168.0.253:8848
redis:
database: 2
host: 39.104.123.58
password: Ebiz2020
port: 6378
database: 1
host: 192.168.0.253
password: boe@123
port: 6379
jpa:
hibernate:
ddl-auto: none
datasource:
driverClassName: com.mysql.jdbc.Driver
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
url: jdbc:mysql://192.168.0.253:3306/boe_base?useSSL=false&useUnicode=true&characterEncoding=UTF8&zeroDateTimeBehavior=convertToNull
username: root
password: boe#1234A
type: com.zaxxer.hikari.HikariDataSource
hikari:
auto-commit: true
@@ -35,12 +35,6 @@ 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:
@@ -113,7 +107,7 @@ aop-log-record:
#不进行拦截的包或者类
excludeClassNames:
activemq:
broker-url: tcp://192.168.10.74:61616
broker-url: tcp://192.168.0.253:61616
user: admin
password: admin
elasticsearch:

View File

@@ -40,12 +40,6 @@ 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:

View File

@@ -33,12 +33,6 @@ 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:
@@ -85,17 +79,13 @@ xboe:
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
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: 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
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
file-upload-callback-url: http://10.251.113.95:9090/xboe/m/boe/caseDocumentLog/uploadCallback
use-white-list: true
white-user-code-list:
- "00004409"
@@ -118,210 +108,10 @@ xboe:
- "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
@@ -345,11 +135,4 @@ aop-log-record:
password: admin
elasticsearch:
host: 10.251.88.218
port: 9200
ok:
http:
connect-timeout: 300
read-timeout: 300
write-timeout: 300
max-idle-connections: 200
keep-alive-duration: 300
port: 9200

View File

@@ -40,12 +40,6 @@ 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:
@@ -125,7 +119,6 @@ xboe:
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:
@@ -151,7 +144,6 @@ xboe:
- "11339772"
alert-email-recipients:
- chengmeng@boe.com.cn
ai-chat-root-path: /home/www/elearning/upload/ai/chat
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES

View File

@@ -50,9 +50,6 @@ ok:
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:

View File

@@ -1,82 +0,0 @@
{
"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"
}
}
}

View File

@@ -31,42 +31,26 @@
</encoder>
</appender>
<appender name="caseAiChat"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 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>
<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>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
</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>

View File

@@ -47,26 +47,10 @@
</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>