Compare commits

...

65 Commits

Author SHA1 Message Date
王卓煜
46fef22fa1 Revert "标签关联课程下面展示标签"
This reverts commit fa9d80d4a5.
2025-09-25 11:00:57 +08:00
王卓煜
6bea2431f0 Merge remote-tracking branch 'origin/121-20250912-tag-add' into 121-20250912-tag-add 2025-09-25 09:56:21 +08:00
王卓煜
5497c21735 去除 2025-09-25 09:55:46 +08:00
liu.zixi
ff27d7a283 AI调用日志 重试功能补完 2025-09-24 09:22:51 +08:00
liu.zixi
7825a219b1 案例专家功能提交 2025-09-24 09:22:50 +08:00
liguoxu
16c1972ad3 事务测试 2025-09-22 19:32:10 +08:00
joshen
a94f3e72d9 Merge branch '20250912-tag-add' into 121-20250912-tag-add 2025-09-22 09:59:03 +08:00
王卓煜
fa9d80d4a5 标签关联课程下面展示标签 2025-09-19 17:27:22 +08:00
王卓煜
9e5571297f Merge remote-tracking branch 'origin/20250912-tag-add' into 121-20250912-tag-add
# Conflicts:
#	servers/boe-server-all/src/main/java/com/xboe/module/course/service/impl/CourseTagServiceImpl.java
2025-09-18 13:26:42 +08:00
王卓煜
fb9377d0fa 标签管理关联课程数+1 2025-09-18 13:21:13 +08:00
王卓煜
2da2112993 标签管理选择标签没有进行关联,以及热点标签超过十个没有判断 2025-09-18 09:44:51 +08:00
王卓煜
28e688f487 标签管理选择标签没有进行关联 2025-09-18 09:39:44 +08:00
王卓煜
8aae653da8 Merge branch '20250912-tag-add' into 121-20250912-tag-add 2025-09-16 13:59:35 +08:00
王卓煜
29a296577d 标签管理解绑标签 2025-09-16 13:54:00 +08:00
王卓煜
de028f8d0e 标签管理测试环境没有boe_new数据库 2025-09-15 14:47:49 +08:00
joshen
02ff9474bc 测试环境没有boe_new数据库暂时先切换 2025-09-15 14:29:48 +08:00
王卓煜
d0ed822189 标签管理缺失tags字段 2025-09-15 14:14:20 +08:00
王卓煜
06015e90c7 标签管理 2025-09-12 15:25:31 +08:00
joshen
618b0b3f62 Merge remote-tracking branch 'yx/master-20250414-lyc' into release-20250328-master 2025-05-13 15:37:05 +08:00
670788339
5836b147c4 在线删除同步授课记录 2025-04-29 15:58:37 +08:00
670788339
fb1d11ebab 取消lastStudyTime更新条件 2025-04-21 15:18:48 +08:00
670788339
add1d6abb2 取消lastStudyTime更新条件 2025-04-21 13:59:06 +08:00
670788339
eafe17b99a studyindex 日志 2025-04-21 13:46:55 +08:00
670788339
d1b6573c25 studyindex调试 2025-04-21 11:40:22 +08:00
670788339
1039f80aec 调试 2025-04-18 11:15:36 +08:00
670788339
efc0605115 调试 2025-04-18 11:05:18 +08:00
670788339
d938425151 日志 2025-04-18 10:54:36 +08:00
670788339
00510562ca 日志 2025-04-18 10:40:50 +08:00
670788339
3e70e71e5a 合并影响的其他接口 2025-04-18 10:19:06 +08:00
670788339
24011a4470 合并影响的其他接口 2025-04-18 10:06:53 +08:00
670788339
8948165296 合并影响的其他接口 2025-04-18 09:49:59 +08:00
670788339
076b1828ad 合并 2025-04-18 09:16:47 +08:00
670788339
95312696f6 studyindex缓存获取duration 2025-04-17 13:36:30 +08:00
670788339
1aca002b8f 合并测试 2025-04-14 16:10:18 +08:00
670788339
50bdc39ce8 appendtime 于 study-video-time 合并 2025-04-14 14:08:01 +08:00
joshen
4fff780970 Merge branch '250408-bugfix-shl' into release-20250328-master
# Conflicts:
#	servers/boe-server-all/src/main/java/com/xboe/module/course/service/ICourseService.java
2025-04-09 18:16:07 +08:00
sunhonglai
47813ea565 增加面授课删除 2025-04-08 17:43:37 +08:00
670788339
5aa62de3cb @Transient 2025-04-03 09:09:58 +08:00
joshen
a309bc1ddf Merge branch '250331-bugfix-shl-newmaster' into release-20250328-master 2025-04-02 16:57:24 +08:00
sunhonglai
6af4cdfc75 修改测试环境配置 2025-04-01 13:52:20 +08:00
sunhonglai
2a2759768b 修改个人中心我的报名图片不显示问题 2025-04-01 12:42:32 +08:00
sunhonglai
74bcec72bc 修改学习时长取值 2025-04-01 09:59:59 +08:00
sunhonglai
b8c171bf86 Merge branch '250331-bugfix-shl-newmaster' into 250331-bugfix-shl
# Conflicts:
#	servers/boe-server-all/src/main/java/com/xboe/school/study/service/impl/StudyServiceImpl.java
2025-04-01 09:51:14 +08:00
sunhonglai
175e7f6c28 查询课程和修改课程学习上报进度,增加视频播放进度的处理 2025-04-01 08:32:41 +08:00
sunhonglai
5705bb8529 查询课程和修改课程学习上报进度,增加视频播放进度的处理 2025-03-31 13:14:14 +08:00
sunhonglai
87e5dd81f8 查询课程和修改课程学习上报进度,增加视频播放进度的处理 2025-03-31 11:27:13 +08:00
joshen
9924769bc8 Merge remote-tracking branch 'yx/master-20250227-lyc' into release-20250328-master 2025-03-29 12:38:10 +08:00
670788339
d4964ca7f1 日志 2025-03-29 12:22:11 +08:00
670788339
efdfa6f00c study-video-time 最后修改时间调整 2025-03-29 10:51:08 +08:00
joshen
ceb30f7f1d Merge remote-tracking branch 'yx/master-20250227-lyc' into release-20250328-master
# Conflicts:
#	servers/boe-server-all/src/main/java/com/xboe/module/course/entity/CourseTeacher.java
#	servers/boe-server-all/src/main/java/com/xboe/school/study/api/StudyCourseApi.java
2025-03-28 15:32:27 +08:00
joshen
60d891edcf Merge remote-tracking branch 'yx/250324-casebugfix-zsh' 2025-03-26 16:54:25 +08:00
emcchui
b9f00f2602 SZX-927:学员端-个人设置-手机号未同步到 2025-03-25 08:47:19 +08:00
emcchui
77884d3e7e SZX-927:学员端-个人设置-手机号未同步到 2025-03-25 08:39:48 +08:00
emcchui
3a9a8d86af SZX-927:学员端-个人设置-手机号未同步到 2025-03-24 18:10:41 +08:00
emcchui
3a139925c9 SZX-927:学员端-个人设置-手机号未同步到 2025-03-24 17:41:22 +08:00
emcchui
fdc0c7959e SZX-927:学员端-个人设置-手机号未同步到 2025-03-24 16:27:50 +08:00
670788339
500fb090fb 在线课-外部讲师报错 添加讲师类型 2025-03-19 13:17:06 +08:00
670788339
ee95435d01 在线课-外部讲师报错 添加供应商 2025-03-19 13:08:54 +08:00
670788339
76f0d1933a 在线课-外部讲师报错 2025-03-19 11:56:48 +08:00
670788339
58d6f49006 考试提交调用加catch 2025-03-13 10:03:21 +08:00
670788339
c8ffdd561f 考试提交调用course项目同步 2025-03-10 16:03:10 +08:00
670788339
98611edcaa 考试提交调用course项目同步 2025-03-10 16:02:19 +08:00
670788339
8aea21bde7 参数转换 2025-03-10 14:32:21 +08:00
670788339
a79f6b43b2 日志 2025-03-10 14:22:03 +08:00
670788339
81ea19f0f3 study-video-time redis优化 2025-03-03 17:49:49 +08:00
58 changed files with 4607 additions and 78 deletions

View File

@@ -161,6 +161,11 @@
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.13</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>javax.mail-api</artifactId>
@@ -227,6 +232,23 @@
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.9.0</version> <!-- 请根据实际需求选择合适的版本 -->
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp-sse</artifactId>
<version>4.2.0</version>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.31</version>
</dependency>
<dependency>
<groupId>com.xboe</groupId>

View File

@@ -8,9 +8,11 @@ import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.boe.feign.api.courseweb.entity.ExamTestDto;
import com.boe.feign.api.courseweb.entity.ProjectStudyDto;
import com.boe.feign.api.courseweb.remote.ExternalRemoteClient;
import com.boe.feign.api.courseweb.remote.OffCourseRemoteClient;
import com.boe.feign.api.courseweb.remote.ProjectAdminRemoteClient;
import com.boe.feign.api.courseweb.remote.ProjectRemoteClient;
import com.boe.feign.api.courseweb.reps.ExamStudyRecordParam;
import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
import com.boe.feign.api.infrastructure.entity.Dict;
import com.boe.feign.api.infrastructure.remote.DictRemoteClient;
@@ -73,6 +75,8 @@ public class ThirdApi {
@Resource
private ProjectRemoteClient projectRemoteClient;
@Resource
ExternalRemoteClient externalRemoteClient;
@Resource
private DictRemoteClient dictRemoteClient;
@@ -94,7 +98,8 @@ public class ThirdApi {
private String syncOnLineScore;
@Value("${coursesuilt.updateOnLineStatua}")
private String updateOnLineStatua;
@Value("${coursesuilt.delOnLineById}")
private String delOnLineById;
//获取例外人员的id
public List<String> getUserId() {
@@ -262,11 +267,19 @@ public class ThirdApi {
}
public List<StudyCourse> getStudyCourseList(String studyId, String courseId, String token) {
log.info(" 1 studyId = "+ studyId + " ,courseId = " + courseId );
if ( studyId == null || courseId == null ){
log.error(" 在线课学习记录 参数不能为空 ");
return new ArrayList<>();
}
StudyCourseVo studyCourseVo = new StudyCourseVo();
studyCourseVo.setStudyId(studyId);
studyCourseVo.setCourseId(courseId);
ProjectStudyDto projectStudyDto = new ProjectStudyDto();
BeanUtil.copyProperties(studyCourseVo, studyCourseVo);
// BeanUtil.copyProperties(studyCourseVo, studyCourseVo);
projectStudyDto.setStudyId(Long.parseLong(studyId));
projectStudyDto.setCourseId(Long.parseLong(courseId));
log.info(" 12 在线课学习记录 studyId = "+ projectStudyDto.getStudyId() + " ,courseId = " + projectStudyDto.getCourseId() );
projectRemoteClient.updateStudyStatus(projectStudyDto);
return new ArrayList<>();
}
@@ -382,4 +395,16 @@ public class ThirdApi {
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
log.info("updateOrSaveCourse = " + resp);
}
public void syncExamStudyRecord(ExamStudyRecordParam param) {
externalRemoteClient.syncExamStudyRecord(param);
}
public void delOnLineById(CourseParam param, String token) {
log.info("---------------同步在线课删除 ------- param " + param);
String resp = Optional.ofNullable(
HttpRequest.post(delOnLineById).body(JSONUtil.toJsonStr(param)).header("token", token).execute()
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
log.info("-------delOnLineById = " + resp);
}
}

View File

@@ -2,11 +2,16 @@ package com.xboe.data.service.impl;
import java.time.LocalDateTime;
import javax.annotation.Resource;
import javax.transaction.Transactional;
import com.boe.feign.api.serverall.entity.UserData;
import com.xboe.constants.CacheName;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
@@ -39,6 +44,9 @@ public class DataUserSyncServiceImpl implements IDataUserSyncService {
@Autowired
TeacherDao teacherDao;
@Resource
private CacheManager cacheManager;
@Override
@Transactional
@@ -59,6 +67,8 @@ public class DataUserSyncServiceImpl implements IDataUserSyncService {
a.setDeleted(user.getDeleted());
}
a.setLoginName(user.getCode());
a.setMobile(user.getMobile());
a.setEmail(user.getEmail());
log.info("更新账号code");
accountDao.update(a);
} else {
@@ -71,14 +81,18 @@ public class DataUserSyncServiceImpl implements IDataUserSyncService {
a.setRegTime(LocalDateTime.now());
a.setSysId(user.getKid());
a.setStatus(1);
a.setMobile(user.getMobile());
a.setEmail(user.getEmail());
accountDao.save(a);
log.info("账号不存在,新添加账号【" + user.getId() + "");
}
if (u != null) {
//更新部分用户字段
u.setDepartId(user.getDepartId());
u.setDepartName(user.getDepartName());
u.setName(user.getName());
u.setMobileNo(user.getMobile());
//2022-12-8 去掉用户类型的更新,因为返回的数据都是学员,
//u.setUserType(user.getUserType());
if (user.getLearningDuration() > 0) { //不大于0才会更新
@@ -106,9 +120,17 @@ public class DataUserSyncServiceImpl implements IDataUserSyncService {
} else {
u.setShowHome(true);//band16以下及其它无bandLevel的信息
}
u.setMobileNo(user.getMobile());
userDao.save(u);
log.info("添加新用户");
}
Cache cache = cacheManager.getCache(CacheName.NAME_USER);
if(cache != null) {
cache.evict(CacheName.KEY_ACCOUNT + user.getId());
cache.evict(CacheName.KEY_USER + user.getId());
}
//对机构的判断,不为空时才会处理,为空时不处理
if (StringUtils.isNotBlank(user.getDepartId())) {
org = orgDao.get(user.getDepartId());

View File

@@ -0,0 +1,50 @@
package com.xboe.enums;
/**
* AI调用日志业务处理状态枚举
*/
public enum CaseDocumentLogCaseStatusEnum {
SUCCESS(1, "处理成功"),
FAILED(2, "处理失败");
private final Integer code;
private final String desc;
CaseDocumentLogCaseStatusEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
public Integer getCode() {
return code;
}
public String getDesc() {
return desc;
}
/**
* 根据code获取描述
*/
public static String getDescByCode(Integer code) {
for (CaseDocumentLogCaseStatusEnum statusEnum : values()) {
if (statusEnum.getCode().equals(code)) {
return statusEnum.getDesc();
}
}
return "";
}
/**
* 根据code获取枚举
*/
public static CaseDocumentLogCaseStatusEnum getByCode(Integer code) {
for (CaseDocumentLogCaseStatusEnum statusEnum : values()) {
if (statusEnum.getCode().equals(code)) {
return statusEnum;
}
}
return null;
}
}

View File

@@ -0,0 +1,51 @@
package com.xboe.enums;
/**
* AI调用日志接口调用状态枚举
*/
public enum CaseDocumentLogOptStatusEnum {
CALLING(0, "调用中"),
SUCCESS(1, "调用成功"),
FAILED(2, "调用失败");
private final Integer code;
private final String desc;
CaseDocumentLogOptStatusEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
public Integer getCode() {
return code;
}
public String getDesc() {
return desc;
}
/**
* 根据code获取描述
*/
public static String getDescByCode(Integer code) {
for (CaseDocumentLogOptStatusEnum statusEnum : values()) {
if (statusEnum.getCode().equals(code)) {
return statusEnum.getDesc();
}
}
return "";
}
/**
* 根据code获取枚举
*/
public static CaseDocumentLogOptStatusEnum getByCode(Integer code) {
for (CaseDocumentLogOptStatusEnum statusEnum : values()) {
if (statusEnum.getCode().equals(code)) {
return statusEnum;
}
}
return null;
}
}

View File

@@ -0,0 +1,39 @@
package com.xboe.enums;
/**
* AI调用日志操作类型枚举
*/
public enum CaseDocumentLogOptTypeEnum {
CREATE("create", "新增"),
DELETE("delete", "删除"),
UPDATE("update", "更改");
private final String code;
private final String desc;
CaseDocumentLogOptTypeEnum(String code, String desc) {
this.code = code;
this.desc = desc;
}
public String getCode() {
return code;
}
public String getDesc() {
return desc;
}
/**
* 根据code获取描述
*/
public static String getDescByCode(String code) {
for (CaseDocumentLogOptTypeEnum typeEnum : values()) {
if (typeEnum.getCode().equals(code)) {
return typeEnum.getDesc();
}
}
return "";
}
}

View File

@@ -0,0 +1,66 @@
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.service.ICaseAiChatService;
import com.xboe.module.boecase.vo.CaseAiMessageVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import javax.servlet.http.HttpServletResponse;
import java.nio.charset.StandardCharsets;
import java.util.List;
/**
* AI对话管理API
*/
@Slf4j
@RestController
@RequestMapping(value = "/xboe/m/boe/case/ai")
public class CaseAiChatApi extends ApiBaseController {
/**
* 聊天
* @param caseAiChatDto
* @param response
* @return
*/
@Autowired
private ICaseAiChatService caseAiChatService;
/**
* 聊天
* @param caseAiChatDto
* @param response
* @return
*/
@PostMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter chat(@RequestBody CaseAiChatDto caseAiChatDto,
HttpServletResponse response) {
response.setContentType("text/event-stream");
response.setCharacterEncoding(StandardCharsets.UTF_8.name());
// 获取当前用户
return caseAiChatService.chat(caseAiChatDto, getCurrent());
}
/**
* 根据conversationId查看会话内消息记录
* @param conversationId 会话ID
* @return 消息记录列表
*/
@GetMapping("/messages")
public JsonResponse<List<CaseAiMessageVo>> getConversationMessages(@RequestParam String conversationId) {
try {
List<CaseAiMessageVo> messages = caseAiChatService.getConversationMessages(conversationId);
return success(messages);
} catch (Exception e) {
log.error("查询会话消息记录异常", e);
return error("查询失败", e.getMessage());
}
}
}

View File

@@ -0,0 +1,206 @@
package com.xboe.module.boecase.api;
import com.xboe.common.PageList;
import com.xboe.core.JsonResponse;
import com.xboe.core.api.ApiBaseController;
import com.xboe.core.log.AutoLog;
import com.xboe.module.boecase.dto.CaseDocumentLogQueryDto;
import com.xboe.module.boecase.service.ICaseDocumentLogService;
import com.xboe.module.boecase.service.ICaseKnowledgeService;
import com.xboe.module.boecase.vo.CaseDocumentLogVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
/**
* AI调用日志管理API
*/
@Slf4j
@RestController
@RequestMapping(value = "/xboe/m/boe/caseDocumentLog")
public class CaseDocumentLogApi extends ApiBaseController {
@Resource
private ICaseDocumentLogService caseDocumentLogService;
@Resource
private ICaseKnowledgeService caseKnowledgeService;
/**
* AI调用日志分页查询
*
* @param queryDto 查询条件
* @return 分页结果
*/
@PostMapping("/pageQuery")
@AutoLog(module = "AI调用日志", action = "分页查询", info = "AI调用日志分页查询")
public JsonResponse<PageList<CaseDocumentLogVo>> pageQuery(@RequestBody CaseDocumentLogQueryDto queryDto) {
try {
PageList<CaseDocumentLogVo> result = caseDocumentLogService.pageQuery(
queryDto.getPageIndex(),
queryDto.getPageSize(),
queryDto
);
return success(result);
} catch (Exception e) {
log.error("AI调用日志分页查询失败", e);
return error("查询失败", e.getMessage());
}
}
/**
* 清空日志(根据筛选条件)
*
* @param queryDto 查询条件
* @return 删除结果
*/
@PostMapping("/clearLogs")
@AutoLog(module = "AI调用日志", action = "清空日志", info = "AI调用日志清空操作")
public JsonResponse<Integer> clearLogs(@RequestBody CaseDocumentLogQueryDto queryDto) {
try {
int deletedCount = caseDocumentLogService.clearLogsByCondition(queryDto);
return success(deletedCount);
} catch (Exception e) {
log.error("AI调用日志清空失败", e);
return error("清空失败", e.getMessage());
}
}
/**
* 重试AI调用
*
* @param request 重试请求参数
* @return 重试结果
*/
@PostMapping("/retry")
@AutoLog(module = "AI调用日志", action = "重试调用", info = "AI调用日志重试操作")
public JsonResponse<Boolean> retry(@RequestBody RetryRequest request) {
try {
boolean result = caseDocumentLogService.retryByLogId(request.getLogId());
return success(result);
} catch (Exception e) {
log.error("AI调用重试失败", e);
return error("重试失败", e.getMessage());
}
}
/**
* 重试请求参数
*/
public static class RetryRequest {
private String logId;
public String getLogId() {
return logId;
}
public void setLogId(String logId) {
this.logId = logId;
}
}
/**
* 文档上传回调接口
*
* @param request 回调请求参数
* @return 回调结果
*/
@PostMapping("/uploadCallback")
@AutoLog(module = "AI调用日志", action = "文档上传回调", info = "文档上传回调接口")
public CallbackResponse uploadCallback(@RequestBody CallbackRequest request) {
try {
log.info("收到文档上传回调taskId: {}, fileStatus: {}, message: {}",
request.getTaskId(), request.getFileStatus(), request.getMessage());
boolean result = caseKnowledgeService.handleUploadCallback(
request.getTaskId(),
request.getMessage(),
request.getFileStatus()
);
CallbackResponse response = new CallbackResponse();
response.setSuccess(result);
response.setCode(result ? 0 : -1);
response.setMessage(result ? "回调处理成功" : "回调处理失败");
return response;
} catch (Exception e) {
log.error("文档上传回调处理失败", e);
CallbackResponse response = new CallbackResponse();
response.setSuccess(false);
response.setCode(-1);
response.setMessage("回调处理异常: " + e.getMessage());
return response;
}
}
/**
* 回调请求参数
*/
public static class CallbackRequest {
private String taskId;
private String message;
private String fileStatus;
public String getTaskId() {
return taskId;
}
public void setTaskId(String taskId) {
this.taskId = taskId;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getFileStatus() {
return fileStatus;
}
public void setFileStatus(String fileStatus) {
this.fileStatus = fileStatus;
}
}
/**
* 回调响应参数
*/
public static class CallbackResponse {
private boolean success;
private int code;
private String message;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
public int getCode() {
return code;
}
public void setCode(int code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
}

View File

@@ -0,0 +1,24 @@
package com.xboe.module.boecase.dao;
import com.xboe.core.orm.BaseDao;
import com.xboe.core.orm.FieldFilters;
import com.xboe.module.boecase.entity.CaseAiConversations;
import org.springframework.stereotype.Repository;
/**
* 案例AI会话信息DAO
*/
@Repository
public class CaseAiConversationsDao extends BaseDao<CaseAiConversations> {
/**
* 根据主键ID查询AI会话ID
* @param conversationId 主键ID
* @return AI会话ID
*/
public String findAiConversationIdById(String conversationId) {
CaseAiConversations conversation = this.getGenericDao().findOne(CaseAiConversations.class,
FieldFilters.eq("id", conversationId));
return conversation != null ? conversation.getAiConversationId() : null;
}
}

View File

@@ -0,0 +1,24 @@
package com.xboe.module.boecase.dao;
import com.xboe.core.orm.BaseDao;
import com.xboe.module.boecase.entity.CaseDocumentLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;
/**
* AI调用日志DAO
*/
@Repository
@Slf4j
public class CaseDocumentLogDao extends BaseDao<CaseDocumentLog> {
/**
* 根据taskId查询文档日志
* @param taskId 任务ID
* @return 文档日志
*/
public CaseDocumentLog findByTaskId(String taskId) {
return this.getGenericDao().findOne(CaseDocumentLog.class,
FieldFilters.eq("taskId", taskId));
}
}

View File

@@ -0,0 +1,21 @@
package com.xboe.module.boecase.dto;
import lombok.Data;
/**
* AI对话入参
*/
@Data
public class CaseAiChatDto {
/**
* 对话id
* 如果是新对话,传空
*/
private String conversationId;
/**
* 提问内容
*/
private String query;
}

View File

@@ -0,0 +1,48 @@
package com.xboe.module.boecase.dto;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.time.LocalDateTime;
import java.util.List;
/**
* AI调用日志查询条件DTO
*/
@Data
public class CaseDocumentLogQueryDto extends PageDto {
/**
* 案例标题(模糊查询)
*/
private String caseTitle;
/**
* 操作类型create-新增delete-删除update-更改)
*/
private String optType;
/**
* 调用时间开始
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime optTimeStart;
/**
* 调用时间结束
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime optTimeEnd;
/**
* 接口调用状态
* 0-调用中, 1-调用成功, 2-调用失败
*/
private Integer optStatus;
/**
* 业务处理状态
* 1-处理成功, 2-处理失败
*/
private Integer caseStatus;
}

View File

@@ -0,0 +1,38 @@
package com.xboe.module.boecase.entity;
import com.xboe.core.SysConstant;
import com.xboe.core.orm.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* 案例AI会话信息表
*/
@Data
@Entity
@EqualsAndHashCode(callSuper = false)
@Table(name = SysConstant.TABLE_PRE + "case_ai_conversations")
public class CaseAiConversations extends BaseEntity {
/**
* 会话ID由AI平台提供
*/
@Column(name = "ai_conversation_id", length = 100)
private String aiConversationId;
/**
* 会话名称
*/
@Column(name = "conversation_name", length = 200)
private String conversationName;
/**
* 会话对应用户ID
*/
@Column(name = "conversation_user", length = 50)
private String conversationUser;
}

View File

@@ -0,0 +1,89 @@
package com.xboe.module.boecase.entity;
import com.xboe.core.SysConstant;
import com.xboe.core.orm.BaseEntity;
import lombok.Data;
import lombok.EqualsAndHashCode;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.time.LocalDateTime;
/**
* 案例文档日志信息表
*/
@Data
@Entity
@EqualsAndHashCode(callSuper = false)
@Table(name = SysConstant.TABLE_PRE + "case_document_log")
public class CaseDocumentLog extends BaseEntity {
/**
* 任务ID
*/
@Column(name = "task_id", length = 20)
private String taskId;
/**
* 案例id
*/
@Column(name = "case_id", length = 20)
private String caseId;
/**
* 案例标题
*/
@Column(name = "case_title", length = 200)
private String caseTitle;
/**
* 操作类型
*/
@Column(name = "opt_type")
private String optType;
/**
* 请求地址
*/
@Column(name = "request_url", length = 500)
private String requestUrl;
/**
* 请求参数
*/
@Column(name = "request_body", length = 4000)
private String requestBody;
/**
* 响应参数
*/
@Column(name = "response_body", length = 4000)
private String responseBody;
/**
* 调用时间
*/
@Column(name = "opt_time")
private LocalDateTime optTime;
/**
* 接口调用状态
* 0-调用中, 1-调用成功, 2-调用失败
*/
@Column(name = "opt_status")
private Integer optStatus;
/**
* 业务处理状态
* 1-处理成功, 2-处理失败
*/
@Column(name = "case_status")
private Integer caseStatus;
/**
* 执行时间(ms)
*/
@Column(name = "execute_duration")
private Long executeDuration;
}

View File

@@ -0,0 +1,42 @@
package com.xboe.module.boecase.properties;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
/**
* 案例专家AI相关配置项
*/
@ConfigurationProperties(prefix = "xboe.case.ai")
@Data
public class CaseAiProperties {
/**
* 接口地址
*/
private String baseUrl;
/**
* appKey
*/
private String appKey;
/**
* appSecret
*/
private String secretKey;
/**
* ai接口的apiCode
*/
private String aiApiCode;
/**
* 案例知识库id
*/
private String caseKnowledgeId;
/**
* 文档上传回调接口地址
*/
private String fileUploadCallbackUrl;
}

View File

@@ -0,0 +1,13 @@
package com.xboe.module.boecase.service;
/**
* 获取accesstoken
*/
public interface IAiAccessTokenService {
/**
* 获取accesstoken
* @return
*/
String getAccessToken();
}

View File

@@ -0,0 +1,38 @@
package com.xboe.module.boecase.service;
import com.xboe.core.CurrentUser;
import com.xboe.module.boecase.dto.CaseAiChatDto;
import com.xboe.module.boecase.entity.CaseAiConversations;
import com.xboe.module.boecase.vo.CaseAiMessageVo;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.util.List;
/**
* AI案例对话
*/
public interface ICaseAiChatService {
/**
* 聊天
* @param caseAiChatDto
* @param currentUser
* @return
*/
SseEmitter chat(CaseAiChatDto caseAiChatDto, CurrentUser currentUser);
/**
* 创建新的AI对话会话
* @param userId 用户ID
* @param conversationName 对话名称
* @return 创建的会话信息
*/
CaseAiConversations createNewConversation(String userId, String conversationName);
/**
* 根据conversationId查看会话内消息记录
* @param conversationId 会话ID
* @return 消息记录列表
*/
List<CaseAiMessageVo> getConversationMessages(String conversationId);
}

View File

@@ -0,0 +1,40 @@
package com.xboe.module.boecase.service;
import com.xboe.common.PageList;
import com.xboe.module.boecase.dto.CaseDocumentLogQueryDto;
import com.xboe.module.boecase.vo.CaseDocumentLogVo;
/**
* AI调用日志Service接口
*/
public interface ICaseDocumentLogService {
/**
* 分页查询AI调用日志
*
* @param pageIndex 页码
* @param pageSize 每页大小
* @param queryDto 查询条件
* @return 分页结果
*/
PageList<CaseDocumentLogVo> pageQuery(int pageIndex, int pageSize, CaseDocumentLogQueryDto queryDto);
/**
* 根据查询条件清空日志
* 仅删除当前筛选条件下的日志记录,非筛选范围内的日志不受影响
*
* @param queryDto 查询条件
* @return 删除的记录数
*/
int clearLogsByCondition(CaseDocumentLogQueryDto queryDto);
/**
* 根据logId重试AI调用
* 查询原始日志数据,重试执行后添加新的日志记录
*
* @param logId 日志ID
* @return 是否成功
*/
boolean retryByLogId(String logId);
}

View File

@@ -0,0 +1,41 @@
package com.xboe.module.boecase.service;
/**
* 案例-知识库
*/
public interface ICaseKnowledgeService {
/**
* 上传案例文档
*
* @param caseId 案例ID
* @return 是否成功
*/
boolean uploadCaseDocument(String caseId);
/**
* 删除案例文档
*
* @param caseId 案例ID
* @return 是否成功
*/
boolean deleteCaseDocument(String caseId);
/**
* 更新案例文档
*
* @param caseId 案例ID
* @return 是否成功
*/
boolean updateCaseDocument(String caseId);
/**
* 处理文档上传回调
*
* @param taskId 任务ID
* @param message 回调信息
* @param fileStatus 文件状态vectored: 成功, failed: 失败)
* @return 是否处理成功
*/
boolean handleUploadCallback(String taskId, String message, String fileStatus);
}

View File

@@ -0,0 +1,88 @@
package com.xboe.module.boecase.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xboe.common.utils.StringUtil;
import com.xboe.module.boecase.properties.CaseAiProperties;
import com.xboe.module.boecase.service.IAiAccessTokenService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeUnit;
@EnableConfigurationProperties({CaseAiProperties.class})
@Service
@Slf4j
public class AiAccessTokenServiceImpl implements IAiAccessTokenService {
private static final String ACCESS_TOKEN_CACHE_KEY = "case_ai_access_token";
@Autowired
private CaseAiProperties caseAiProperties;
@Autowired
private StringRedisTemplate stringRedisTemplate;
@Override
public String getAccessToken() {
// 1. 先从Redis缓存中获取
String cachedToken = stringRedisTemplate.opsForValue().get(ACCESS_TOKEN_CACHE_KEY);
if (StringUtil.isNotBlank(cachedToken)) {
return cachedToken;
}
// 2. 缓存中没有,重新获取
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
String tokenUrl = caseAiProperties.getBaseUrl() + "/apigateway/secret/getAppAccessToken" +
"?appKey=" + URLEncoder.encode(caseAiProperties.getAppKey(), StandardCharsets.UTF_8.name()) +
"&secretKey=" + URLEncoder.encode(caseAiProperties.getSecretKey(), StandardCharsets.UTF_8.name());
HttpGet httpGet = new HttpGet(tokenUrl);
try (CloseableHttpResponse response = httpClient.execute(httpGet)) {
int statusCode = response.getStatusLine().getStatusCode();
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
if (statusCode == 200) {
JSONObject result = JSON.parseObject(responseBody);
if (result.getIntValue("code") == 0 && result.getBooleanValue("success")) {
JSONObject data = result.getJSONObject("data");
String accessToken = data.getString("accessToken");
Integer expiresIn = data.getInteger("expiresIn");
if (expiresIn == null) {
expiresIn = 7200;
}
// 3. 存储到Redis设置过期时间提前5分钟过期
int cacheSeconds = Math.max(expiresIn - 300, 60);
stringRedisTemplate.opsForValue().set(ACCESS_TOKEN_CACHE_KEY, accessToken,
cacheSeconds, TimeUnit.SECONDS);
log.info("获取access_token成功过期时间: {}秒", expiresIn);
return accessToken;
} else {
log.error("获取access_token失败接口返回失败response: {}", responseBody);
return null;
}
} else {
log.error("获取access_token失败HTTP请求失败status: {}, response: {}",
statusCode, responseBody);
return null;
}
}
} catch (Exception e) {
log.error("获取access_token异常", e);
return null;
}
}
}

View File

@@ -0,0 +1,602 @@
package com.xboe.module.boecase.service.impl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.xboe.core.CurrentUser;
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.entity.CaseAiConversations;
import com.xboe.module.boecase.entity.CaseDocumentLog;
import com.xboe.module.boecase.entity.Cases;
import com.xboe.module.boecase.properties.CaseAiProperties;
import com.xboe.module.boecase.service.IAiAccessTokenService;
import com.xboe.module.boecase.service.ICaseAiChatService;
import com.xboe.module.boecase.vo.CaseAiMessageVo;
import com.xboe.module.boecase.vo.CaseReferVo;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import okhttp3.sse.EventSource;
import okhttp3.sse.EventSourceListener;
import okhttp3.sse.EventSources;
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.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.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
@EnableConfigurationProperties({CaseAiProperties.class})
@Service
@Slf4j
public class CaseAiChatServiceImpl implements ICaseAiChatService {
@Autowired
private CaseAiProperties caseAiProperties;
@Autowired
private IAiAccessTokenService aiAccessTokenService;
@Autowired
private CaseAiConversationsDao caseAiConversationsDao;
@Autowired(required = false)
private RestHighLevelClient elasticsearchClient;
@Autowired
private CaseDocumentLogDao caseDocumentLogDao;
@Autowired
private CasesDao casesDao;
@Override
public SseEmitter chat(CaseAiChatDto caseAiChatDto, CurrentUser currentUser) {
// 1. 获取conversationId
String conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
// 2. 检查是否为新会话,如果是则保存会话记录
boolean isNewConversation = StringUtils.isEmpty(caseAiChatDto.getConversationId());
CaseAiConversations conversation = null;
if (isNewConversation) {
// 新会话,需要保存到数据库
conversation = new CaseAiConversations();
conversation.setAiConversationId(conversationId);
conversation.setConversationName("AI案例咨询-" + LocalDateTime.now());
conversation.setConversationUser(currentUser.getAccountId());
// 由于编译问题,这里先注释,实际部署时需要取消注释
caseAiConversationsDao.save(conversation);
}
// 3. 构建请求参数
String userId = currentUser.getAccountId();
String kId = caseAiProperties.getCaseKnowledgeId();
JSONObject chatParam = new JSONObject();
chatParam.put("userId", userId);
JSONArray kIds = new JSONArray();
kIds.add(kId);
chatParam.put("kIds", kIds);
chatParam.put("query", caseAiChatDto.getQuery());
chatParam.put("conversationId", conversationId);
// 4. 设置请求头
String accessToken = aiAccessTokenService.getAccessToken();
String apiCode = caseAiProperties.getAiApiCode();
Request.Builder builder = new Request.Builder();
builder.url(caseAiProperties.getBaseUrl() + "/apigateway/chat/knowledge/v1/chat/completions");
builder.addHeader("access_token", accessToken);
builder.addHeader("X-AI-ApiCode", apiCode);
RequestBody bodyRequestBody = RequestBody.create(chatParam.toJSONString(), MediaType.parse("application/json"));
builder.post(bodyRequestBody);
Request request = builder.build();
// 5. 创建SSE响应器
SseEmitter sseEmitter = new SseEmitter();
// 6. 用于收集对话数据的容器
ConversationData conversationData = new ConversationData();
conversationData.query = caseAiChatDto.getQuery();
conversationData.conversationId = conversationId;
conversationData.userId = userId;
// 7. 创建事件监听器
EventSourceListener listener = new EventSourceListener() {
@Override
public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
log.info("调用接口 [{}] 接口开始监听", request.url());
}
@Override
public void onClosed(@NotNull EventSource eventSource) {
log.info("调用接口 [{}] 接口关闭", request.url());
// 对话完成保存到ES
saveConversationToES(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) {
switch (status) {
case 0: // 返回引用文件
// 处理文件引用并构建返给前端的数据
JSONObject modifiedData = handleFileReferAndBuildResponse(responseData, conversationData);
if (modifiedData != null) {
// 发送修改后的数据给前端
sseEmitter.send(modifiedData.toJSONString());
return; // 早期返回,不发送原始数据
}
break;
case 1: // 流式对话中
String content = responseData.getString("content");
if (content != null) {
conversationData.answer.append(content);
}
break;
case 2: // 回答完成
// 不做特殊处理
break;
case 3: // 返回建议
handleSuggestions(responseData, conversationData);
break;
case 4: // 接口交互完成
// 不做特殊处理
break;
}
}
}
// 发送给前端
sseEmitter.send(data);
} catch (IOException e) {
log.error("调用接口处理监听数据时发生异常", e);
} catch (Exception e) {
log.error("解析EventStream数据异常", e);
try {
sseEmitter.send(data); // 即使解析失败也要发送原始数据
} catch (IOException ioException) {
log.error("发送数据到前端失败", ioException);
}
}
}
@Override
public void onFailure(@NotNull EventSource eventSource, @Nullable Throwable e, @Nullable Response response) {
log.error("调用接口 [{}] 接口异常", request.url(), e);
if (e != null) {
sseEmitter.completeWithError(e);
} else {
sseEmitter.completeWithError(new RuntimeException("调用接口异常, 异常未捕获"));
}
}
};
// 8. 执行HTTP请求
OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
.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();
CaseAiConversations newConversation = createNewConversation(currentUser.getAccountId(), conversationName);
return newConversation.getAiConversationId();
} else {
// 已存在会话,从数据库查询
return caseAiConversationsDao.findAiConversationIdById(conversationId);
}
}
@Override
public CaseAiConversations createNewConversation(String userId, String conversationName) {
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.getAiApiCode();
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 {
log.error("创建AI会话失败接口返回失败response: {}", responseBody);
throw new RuntimeException("创建AI会话失败: " + result.getString("message"));
}
} else {
log.error("创建AI会话失败HTTP请求失败status: {}, response: {}", statusCode, responseBody);
throw new RuntimeException("创建AI会话失败HTTP状态码: " + statusCode);
}
}
} catch (Exception e) {
log.error("创建AI会话异常", e);
throw new RuntimeException("创建AI会话异常", e);
}
}
@Override
public List<CaseAiMessageVo> getConversationMessages(String conversationId) {
List<CaseAiMessageVo> messages = new ArrayList<>();
if (elasticsearchClient == null) {
log.warn("未配置Elasticsearch客户端无法查询消息记录");
return messages;
}
try {
// 根据conversationId从数据库查询AI会话ID
String aiConversationId = caseAiConversationsDao.findAiConversationIdById(conversationId);
if (StringUtils.isEmpty(aiConversationId)) {
log.warn("未找到conversationId: {}对应的AI会话ID", conversationId);
return messages;
}
// 从 ES 中查询消息记录
SearchRequest searchRequest = new SearchRequest("ai_chat_messages"); // ES索引名可以根据实际情况调整
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
searchSourceBuilder.query(QueryBuilders.termQuery("conversationId", aiConversationId));
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 messageVo = parseMessageFromES(sourceMap);
if (messageVo != null) {
messages.add(messageVo);
}
}
log.info("从 ES 中查询到 {} 条消息记录", messages.size());
} catch (Exception e) {
log.error("从 ES 查询会话消息记录异常", e);
}
return messages;
}
/**
* 从 ES 数据中解析消息对象
* @param sourceMap ES数据
* @return 消息对象
*/
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;
}
}
/**
* 处理文件引用并构建返给前端的响应数据
*/
private JSONObject handleFileReferAndBuildResponse(JSONObject responseData, ConversationData conversationData) {
try {
// 先处理文件引用收集CaseReferVo数据
List<CaseReferVo> currentCaseRefers = new ArrayList<>();
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
if (fileRefer != null && fileRefer.containsKey("files")) {
JSONArray files = fileRefer.getJSONArray("files");
for (int i = 0; i < files.size(); i++) {
JSONObject file = files.getJSONObject(i);
String docId = file.getString("docId");
if (docId != null) {
// 根据docId从 case_document_log 表查询案例数据
CaseReferVo caseRefer = getCaseReferByDocId(docId);
if (caseRefer != null) {
currentCaseRefers.add(caseRefer);
conversationData.caseRefers.add(caseRefer); // 也添加到总的收集器中
}
}
}
}
// 构建返给前端的数据结构
JSONObject modifiedResponse = new JSONObject();
modifiedResponse.put("success", true);
modifiedResponse.put("code", 0);
modifiedResponse.put("message", "业务处理成功");
JSONObject data = new JSONObject();
data.put("status", 0);
data.put("content", responseData.getString("content"));
// 添加处理后的案例引用数据
JSONArray caseReferArray = new JSONArray();
for (CaseReferVo caseRefer : currentCaseRefers) {
JSONObject caseReferObj = new JSONObject();
caseReferObj.put("caseId", caseRefer.getCaseId());
caseReferObj.put("title", caseRefer.getTitle());
caseReferObj.put("authorName", caseRefer.getAuthorName());
caseReferObj.put("keywords", caseRefer.getKeywords());
caseReferObj.put("content", caseRefer.getContent());
caseReferArray.add(caseReferObj);
}
// 构建新的fileRefer结构包含案例引用
JSONObject newFileRefer = new JSONObject();
newFileRefer.put("caseRefers", caseReferArray);
// 保留原始的docs和files信息如果需要
if (fileRefer != null) {
if (fileRefer.containsKey("docs")) {
newFileRefer.put("docs", fileRefer.get("docs"));
}
if (fileRefer.containsKey("files")) {
newFileRefer.put("files", fileRefer.get("files"));
}
}
data.put("fileRefer", newFileRefer);
data.put("suggestions", responseData.get("suggestions"));
modifiedResponse.put("data", data);
log.info("处理文件引用成功,返回 {} 个案例引用", currentCaseRefers.size());
return modifiedResponse;
} catch (Exception e) {
log.error("处理文件引用并构建响应数据异常", e);
return null;
}
}
/**
* 处理文件引用(原方法,保留用于数据收集)
*/
private void handleFileRefer(JSONObject responseData, ConversationData conversationData) {
try {
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
if (fileRefer != null && fileRefer.containsKey("files")) {
JSONArray files = fileRefer.getJSONArray("files");
for (int i = 0; i < files.size(); i++) {
JSONObject file = files.getJSONObject(i);
String docId = file.getString("docId");
if (docId != null) {
// 根据docId从 case_document_log 表查询案例数据
CaseReferVo caseRefer = getCaseReferByDocId(docId);
if (caseRefer != null) {
conversationData.caseRefers.add(caseRefer);
}
}
}
}
} catch (Exception e) {
log.error("处理文件引用异常", e);
}
}
/**
* 处理建议
*/
private void handleSuggestions(JSONObject responseData, ConversationData conversationData) {
try {
JSONArray suggestions = responseData.getJSONArray("suggestions");
if (suggestions != null) {
for (int i = 0; i < suggestions.size(); i++) {
String suggestion = suggestions.getString(i);
if (suggestion != null) {
conversationData.suggestions.add(suggestion);
}
}
}
} catch (Exception e) {
log.error("处理建议异常", e);
}
}
/**
* 根据docId查询案例引用信息
*/
private CaseReferVo getCaseReferByDocId(String docId) {
try {
// 从 case_document_log 表查询案例信息docId对应task_id
CaseDocumentLog docLog = caseDocumentLogDao.findByTaskId(docId);
if (docLog == null) {
return null;
}
// 根据 case_id 查询案例详情
Cases caseEntity = casesDao.get(docLog.getCaseId());
if (caseEntity == null) {
return null;
}
// 构建 CaseReferVo
CaseReferVo caseRefer = new CaseReferVo();
caseRefer.setCaseId(caseEntity.getId());
caseRefer.setTitle(caseEntity.getTitle());
caseRefer.setAuthorName(caseEntity.getAuthorName());
caseRefer.setContent(caseEntity.getContent());
// 构建关键词列表
List<String> keywords = new ArrayList<>();
if (caseEntity.getKeyword1() != null) keywords.add(caseEntity.getKeyword1());
if (caseEntity.getKeyword2() != null) keywords.add(caseEntity.getKeyword2());
if (caseEntity.getKeyword3() != null) keywords.add(caseEntity.getKeyword3());
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;
}
}
/**
* 保存对话记录到ES
*/
private void saveConversationToES(ConversationData conversationData) {
if (elasticsearchClient == null) {
log.warn("未配置Elasticsearch客户端无法保存对话记录");
return;
}
try {
// 构建要保存的数据
JSONObject esData = new JSONObject();
esData.put("query", conversationData.query);
esData.put("answer", conversationData.answer.toString());
esData.put("conversationId", conversationData.conversationId);
esData.put("userId", conversationData.userId);
esData.put("timestamp", LocalDateTime.now().toString());
// 构建 caseRefer 数据
JSONArray caseReferArray = new JSONArray();
for (CaseReferVo caseRefer : conversationData.caseRefers) {
JSONObject caseReferObj = new JSONObject();
caseReferObj.put("caseId", caseRefer.getCaseId());
caseReferObj.put("title", caseRefer.getTitle());
caseReferObj.put("authorName", caseRefer.getAuthorName());
caseReferObj.put("keywords", caseRefer.getKeywords());
caseReferObj.put("content", caseRefer.getContent());
caseReferArray.add(caseReferObj);
}
esData.put("caseRefer", caseReferArray);
// 添加建议
esData.put("suggestions", conversationData.suggestions);
// 保存到ES
IndexRequest indexRequest = new IndexRequest("ai_chat_messages");
indexRequest.source(esData.toJSONString(), XContentType.JSON);
IndexResponse indexResponse = elasticsearchClient.index(indexRequest, RequestOptions.DEFAULT);
log.info("保存对话记录到ES成功文档ID: {}", indexResponse.getId());
} catch (Exception e) {
log.error("保存对话记录到ES异常", e);
}
}
/**
* 对话数据容器
*/
private static class ConversationData {
public String query;
public StringBuilder answer = new StringBuilder();
public List<CaseReferVo> caseRefers = new ArrayList<>();
public List<String> suggestions = new ArrayList<>();
public String conversationId;
public String userId;
}
}

View File

@@ -0,0 +1,279 @@
package com.xboe.module.boecase.service.impl;
import com.xboe.common.utils.StringUtil;
import com.xboe.common.utils.IDGenerator;
import com.xboe.common.OrderCondition;
import com.xboe.common.PageList;
import com.xboe.core.orm.FieldFilters;
import com.xboe.core.orm.IFieldFilter;
import com.xboe.core.orm.LikeMatchMode;
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
import com.xboe.module.boecase.dto.CaseDocumentLogQueryDto;
import com.xboe.module.boecase.entity.CaseDocumentLog;
import com.xboe.module.boecase.service.ICaseDocumentLogService;
import com.xboe.module.boecase.service.ICaseKnowledgeService;
import com.xboe.module.boecase.vo.CaseDocumentLogVo;
import com.xboe.enums.CaseDocumentLogOptTypeEnum;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* AI调用日志Service实现类
*/
@Slf4j
@Service
@Transactional
public class CaseDocumentLogServiceImpl implements ICaseDocumentLogService {
@Resource
private CaseDocumentLogDao caseDocumentLogDao;
@Resource
private ICaseKnowledgeService caseKnowledgeService;
@Override
public PageList<CaseDocumentLogVo> pageQuery(int pageIndex, int pageSize, CaseDocumentLogQueryDto queryDto) {
// 构建查询条件
List<IFieldFilter> filters = new ArrayList<>();
// 删除标识过滤
filters.add(FieldFilters.eq("deleted", false));
// 接口调用状态
if (queryDto.getOptStatus() != null) {
filters.add(FieldFilters.eq("optStatus", queryDto.getOptStatus()));
} else {
filters.add(FieldFilters.ge("optStatus", 1));
}
// 案例标题模糊查询
if (StringUtil.isNotBlank(queryDto.getCaseTitle())) {
filters.add(FieldFilters.like("caseTitle", LikeMatchMode.ANYWHERE, queryDto.getCaseTitle()));
}
// 操作类型精确查询
if (StringUtil.isNotBlank(queryDto.getOptType())) {
filters.add(FieldFilters.eq("optType", queryDto.getOptType()));
}
// 调用时间区间查询
if (queryDto.getOptTimeStart() != null) {
filters.add(FieldFilters.ge("optTime", queryDto.getOptTimeStart()));
}
if (queryDto.getOptTimeEnd() != null) {
filters.add(FieldFilters.le("optTime", queryDto.getOptTimeEnd()));
}
// 业务处理状态
if (queryDto.getCaseStatus() != null) {
filters.add(FieldFilters.eq("caseStatus", queryDto.getCaseStatus()));
}
// 按创建时间降序排序
OrderCondition order = OrderCondition.desc("sysCreateTime");
// 执行分页查询
PageList<CaseDocumentLog> pageResult = caseDocumentLogDao.getGenericDao()
.findPage(pageIndex, pageSize, CaseDocumentLog.class, filters, order);
// 转换为VO对象
List<CaseDocumentLogVo> voList = pageResult.getList().stream()
.map(this::convertToVo)
.collect(Collectors.toList());
// 构建返回结果
PageList<CaseDocumentLogVo> result = new PageList<>();
result.setList(voList);
result.setCount(pageResult.getCount());
result.setPageSize(pageResult.getPageSize());
return result;
}
@Override
public int clearLogsByCondition(CaseDocumentLogQueryDto queryDto) {
// 构建查询条件(与分页查询相同的逻辑)
List<IFieldFilter> filters = new ArrayList<>();
// 删除标识过滤
filters.add(FieldFilters.eq("deleted", false));
// 接口调用状态
if (queryDto.getOptStatus() != null) {
filters.add(FieldFilters.eq("optStatus", queryDto.getOptStatus()));
} else {
filters.add(FieldFilters.ge("optStatus", 1));
}
// 案例标题模糊查询
if (StringUtil.isNotBlank(queryDto.getCaseTitle())) {
filters.add(FieldFilters.like("caseTitle", LikeMatchMode.ANYWHERE, queryDto.getCaseTitle()));
}
// 操作类型精确查询
if (StringUtil.isNotBlank(queryDto.getOptType())) {
filters.add(FieldFilters.eq("optType", queryDto.getOptType()));
}
// 调用时间区间查询
if (queryDto.getOptTimeStart() != null) {
filters.add(FieldFilters.ge("optTime", queryDto.getOptTimeStart()));
}
if (queryDto.getOptTimeEnd() != null) {
filters.add(FieldFilters.le("optTime", queryDto.getOptTimeEnd()));
}
// 业务处理状态
if (queryDto.getCaseStatus() != null) {
filters.add(FieldFilters.eq("caseStatus", queryDto.getCaseStatus()));
}
// 查询符合条件的所有记录
List<CaseDocumentLog> logsToDelete = caseDocumentLogDao.getGenericDao()
.findList(CaseDocumentLog.class, (IFieldFilter) filters);
if (logsToDelete.isEmpty()) {
return 0;
}
// 批量设置删除标识为true逻辑删除
int deletedCount = 0;
for (CaseDocumentLog log : logsToDelete) {
log.setDeleted(true);
caseDocumentLogDao.update(log);
deletedCount++;
}
log.info("清空日志操作完成,共删除{}条记录", deletedCount);
return deletedCount;
}
@Override
public boolean retryByLogId(String logId) {
if (StringUtil.isBlank(logId)) {
log.error("重试失败logId不能为空");
return false;
}
// 1. 根据logId查询原始日志数据
CaseDocumentLog originalLog = caseDocumentLogDao.get(logId);
if (originalLog == null || originalLog.getDeleted()) {
log.error("重试失败未找到有效的日志记录logId: {}", logId);
return false;
}
log.info("开始重试AI调用原始日志ID: {}, 案例标题: {}, 操作类型: {}",
logId, originalLog.getCaseTitle(), originalLog.getOptType());
// 2. 执行AI调用重试逻辑
boolean retrySuccess = false;
try {
// 根据操作类型调用对应的接口方法
String optType = originalLog.getOptType();
String caseId = originalLog.getCaseId();
if (StringUtil.isBlank(caseId)) {
throw new IllegalArgumentException("案例ID不能为空");
}
log.info("正在执行AI调用重试操作类型: {}, caseId: {}", optType, caseId);
// 根据操作类型执行对应的方法(这些方法内部会自动创建日志记录)
if (CaseDocumentLogOptTypeEnum.CREATE.getCode().equals(optType)) {
// 上传案例文档
retrySuccess = caseKnowledgeService.uploadCaseDocument(caseId);
log.info("执行上传案例文档重试caseId: {}, 结果: {}", caseId, retrySuccess);
} else if (CaseDocumentLogOptTypeEnum.DELETE.getCode().equals(optType)) {
// 删除案例文档
retrySuccess = caseKnowledgeService.deleteCaseDocument(caseId);
log.info("执行删除案例文档重试caseId: {}, 结果: {}", caseId, retrySuccess);
} else if (CaseDocumentLogOptTypeEnum.UPDATE.getCode().equals(optType)) {
// 更新案例文档
retrySuccess = caseKnowledgeService.updateCaseDocument(caseId);
log.info("执行更新案例文档重试caseId: {}, 结果: {}", caseId, retrySuccess);
} else {
throw new IllegalArgumentException("不支持的操作类型: " + optType);
}
if (retrySuccess) {
log.info("AI调用重试成功操作类型: {}, caseId: {}", optType, caseId);
} else {
log.warn("AI调用重试失败操作类型: {}, caseId: {}", optType, caseId);
}
} catch (Exception e) {
log.error("AI调用重试异常操作类型: {}, caseId: {}",
originalLog.getOptType(), originalLog.getCaseId(), e);
retrySuccess = false;
}
return retrySuccess;
}
/**
* 实体转换为VO
*/
private CaseDocumentLogVo convertToVo(CaseDocumentLog entity) {
CaseDocumentLogVo vo = new CaseDocumentLogVo();
BeanUtils.copyProperties(entity, vo);
// 操作类型转换为中文描述
vo.setOptType(CaseDocumentLogOptTypeEnum.getDescByCode(entity.getOptType()));
// 接口调用状态转换
vo.setOptStatusText(getOptStatusText(entity.getOptStatus()));
// 业务处理状态转换
vo.setCaseStatusText(getCaseStatusText(entity.getCaseStatus()));
return vo;
}
/**
* 获取接口调用状态描述
*/
private String getOptStatusText(Integer optStatus) {
if (optStatus == null) {
return "";
}
switch (optStatus) {
case 0:
return "调用中";
case 1:
return "调用成功";
case 2:
return "调用失败";
default:
return "";
}
}
/**
* 获取业务处理状态描述
*/
private String getCaseStatusText(Integer caseStatus) {
if (caseStatus == null) {
return "";
}
switch (caseStatus) {
case 1:
return "处理成功";
case 2:
return "处理失败";
default:
return "";
}
}
}

View File

@@ -0,0 +1,687 @@
package com.xboe.module.boecase.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.xboe.common.utils.IDGenerator;
import com.xboe.common.utils.StringUtil;
import com.xboe.common.OrderCondition;
import com.xboe.core.orm.FieldFilters;
import com.xboe.enums.CaseDocumentLogCaseStatusEnum;
import com.xboe.enums.CaseDocumentLogOptStatusEnum;
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
import com.xboe.module.boecase.dao.CasesDao;
import com.xboe.module.boecase.entity.CaseDocumentLog;
import com.xboe.module.boecase.entity.Cases;
import com.xboe.module.boecase.properties.CaseAiProperties;
import com.xboe.module.boecase.service.IAiAccessTokenService;
import com.xboe.module.boecase.service.ICaseKnowledgeService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntityBuilder;
import org.apache.http.entity.ContentType;
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.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.TimeUnit;
/**
* 案例-知识库Service实现类
*/
@Slf4j
@Service
@Transactional
@EnableConfigurationProperties({CaseAiProperties.class})
public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
@Autowired
private CaseAiProperties caseAiProperties;
@Resource
private CasesDao casesDao;
@Resource
private CaseDocumentLogDao caseDocumentLogDao;
@Autowired
private IAiAccessTokenService aiAccessTokenService;
private static final String ACCESS_TOKEN_CACHE_KEY = "case:ai:access_token";
@Override
public boolean uploadCaseDocument(String caseId) {
if (StringUtil.isBlank(caseId)) {
log.error("上传案例文档失败案例ID不能为空");
return false;
}
// 1. 查询案例信息
Cases caseEntity = casesDao.findOne(FieldFilters.eq("id", caseId));
if (caseEntity == null || caseEntity.getDeleted()) {
log.error("上传案例文档失败未找到有效的案例记录caseId: {}", caseId);
return false;
}
// 2. 检查文件路径
if (StringUtil.isBlank(caseEntity.getFilePath())) {
log.error("上传案例文档失败案例文件路径为空caseId: {}", caseId);
return false;
}
File file = new File(caseEntity.getFilePath());
if (!file.exists()) {
log.error("上传案例文档失败案例文件不存在filePath: {}", caseEntity.getFilePath());
return false;
}
// 3. 获取access_token
String accessToken = aiAccessTokenService.getAccessToken();
if (StringUtil.isBlank(accessToken)) {
log.error("上传案例文档失败获取access_token失败");
return false;
}
// 4. 构建上传参数
String fileName = caseEntity.getFileName();
if (StringUtil.isBlank(fileName)) {
fileName = file.getName();
}
String fileType = getFileType(fileName);
String userId = getCurrentUserId();
String uploadUrl = caseAiProperties.getBaseUrl() + "/apigateway/knowledge/v1/file/upload";
// 5. 重试逻辑最多3次机会
int maxRetries = 3;
for (int attempt = 1; attempt <= maxRetries; attempt++) {
log.info("上传案例文档第{}次尝试caseId: {}", attempt, caseId);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(uploadUrl);
httpPost.setHeader("X-AI-ApiCode", caseAiProperties.getAiApiCode());
httpPost.setHeader("access_token", accessToken);
// 构建multipart/form-data请求体
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("file", file);
builder.addTextBody("userId", userId, ContentType.TEXT_PLAIN);
builder.addTextBody("kId", caseAiProperties.getCaseKnowledgeId(), ContentType.TEXT_PLAIN);
builder.addTextBody("fileName", fileName, ContentType.TEXT_PLAIN);
builder.addTextBody("fileType", fileType, ContentType.TEXT_PLAIN);
builder.addTextBody("parseType", "AUTO", ContentType.TEXT_PLAIN);
builder.addTextBody("callbackUrl", caseAiProperties.getFileUploadCallbackUrl(), ContentType.TEXT_PLAIN);
HttpEntity multipart = builder.build();
httpPost.setEntity(multipart);
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 = JSON.parseObject(responseBody);
if (result.getBooleanValue("success")) {
// 业务处理成功
JSONObject data = result.getJSONObject("data");
String taskId = data.getString("taskId");
// 保存成功的CaseDocumentLog记录
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "create", uploadUrl,
"上传案例文档", responseBody, CaseDocumentLogOptStatusEnum.SUCCESS.getCode(), CaseDocumentLogCaseStatusEnum.SUCCESS.getCode(), taskId);
log.info("上传案例文档成功caseId: {}, taskId: {}, 尝试次数: {}", caseId, taskId, attempt);
return true;
} else {
// 业务处理失败,不重试
log.error("上传案例文档业务处理失败不重试response: {}", responseBody);
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "create", uploadUrl,
"上传案例文档", responseBody, CaseDocumentLogOptStatusEnum.SUCCESS.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), null);
return false;
}
} else {
// 接口调用失败
log.warn("上传案例文档接口调用失败,第{}次尝试status: {}, response: {}", attempt, statusCode, responseBody);
if (attempt == maxRetries) {
// 最后一次尝试仍然失败
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "create", uploadUrl,
"上传案例文档", responseBody, CaseDocumentLogOptStatusEnum.FAILED.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), null);
return false;
}
// 继续下一次重试
}
}
} catch (Exception e) {
// 接口调用异常
log.warn("上传案例文档接口调用异常,第{}次尝试", attempt, e);
if (attempt == maxRetries) {
// 最后一次尝试仍然异常
log.error("上传案例文档最终失败,已重试{}次", maxRetries);
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "create", uploadUrl,
"上传案例文档", "接口调用异常: " + e.getMessage(), CaseDocumentLogOptStatusEnum.FAILED.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), null);
return false;
}
// 继续下一次重试
}
}
return false;
}
@Override
public boolean deleteCaseDocument(String caseId) {
if (StringUtil.isBlank(caseId)) {
log.error("删除案例文档失败案例ID不能为空");
return false;
}
// 1. 查询案例信息
Cases caseEntity = casesDao.findOne(FieldFilters.eq("id", caseId));
if (caseEntity == null) {
log.error("删除案例文档失败未找到案例记录caseId: {}", caseId);
return false;
}
// 2. 根据案例ID查询最新一条CaseDocumentLog数据
List<CaseDocumentLog> logList = caseDocumentLogDao.getGenericDao()
.findList(CaseDocumentLog.class,
FieldFilters.eq("caseId", caseId),
OrderCondition.desc("sysCreateTime"));
if (logList.isEmpty()) {
log.error("删除案例文档失败未找到相关的日志记录caseId: {}", caseId);
return false;
}
CaseDocumentLog latestLog = logList.get(0);
String taskId = latestLog.getTaskId();
if (StringUtil.isBlank(taskId)) {
log.error("删除案例文档失败日志记录中taskId为空caseId: {}", caseId);
return false;
}
// 3. 获取access_token
String accessToken = aiAccessTokenService.getAccessToken();
if (StringUtil.isBlank(accessToken)) {
log.error("删除案例文档失败获取access_token失败");
return false;
}
String deleteUrl = caseAiProperties.getBaseUrl() + "/apigateway/knowledge/v1/file/delete";
// 4. 重试逻辑最多3次机会
int maxRetries = 3;
for (int attempt = 1; attempt <= maxRetries; attempt++) {
log.info("删除案例文档第{}次尝试caseId: {}, taskId: {}", attempt, caseId, taskId);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpDelete httpDelete = new HttpDelete(deleteUrl);
httpDelete.setHeader("X-AI-ApiCode", caseAiProperties.getAiApiCode());
httpDelete.setHeader("access_token", accessToken);
httpDelete.setHeader("Content-Type", "application/x-www-form-urlencoded");
// 构建请求参数
String params = "kId=" + URLEncoder.encode(caseAiProperties.getCaseKnowledgeId(), StandardCharsets.UTF_8.name()) +
"&taskIds=" + URLEncoder.encode(taskId, StandardCharsets.UTF_8.name());
StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8);
entity.setContentType("application/x-www-form-urlencoded");
httpDelete.setEntity(entity);
try (CloseableHttpResponse response = httpClient.execute(httpDelete)) {
int statusCode = response.getStatusLine().getStatusCode();
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
if (statusCode == 200) {
JSONObject result = JSON.parseObject(responseBody);
if (result.getBooleanValue("success")) {
// 接口调用成功,检查业务处理结果
JSONObject data = result.getJSONObject("data");
Boolean deleteSuccess = data.getBoolean(taskId);
int optStatus = CaseDocumentLogOptStatusEnum.SUCCESS.getCode();
int caseStatus = (deleteSuccess != null && deleteSuccess) ?
CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "delete", deleteUrl,
"删除案例文档", responseBody, optStatus, caseStatus, null);
if (deleteSuccess != null && deleteSuccess) {
log.info("删除案例文档成功caseId: {}, taskId: {}, 尝试次数: {}", caseId, taskId, attempt);
return true;
} else {
// 业务处理失败,不重试
log.error("删除案例文档业务处理失败不重试caseId: {}, taskId: {}", caseId, taskId);
return false;
}
} else {
// 业务处理失败,不重试
log.error("删除案例文档业务处理失败不重试response: {}", responseBody);
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "delete", deleteUrl,
"删除案例文档", responseBody, CaseDocumentLogOptStatusEnum.SUCCESS.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), null);
return false;
}
} else {
// 接口调用失败
log.warn("删除案例文档接口调用失败,第{}次尝试status: {}, response: {}", attempt, statusCode, responseBody);
if (attempt == maxRetries) {
// 最后一次尝试仍然失败
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "delete", deleteUrl,
"删除案例文档", responseBody, CaseDocumentLogOptStatusEnum.FAILED.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), null);
return false;
}
// 继续下一次重试
}
}
} catch (Exception e) {
// 接口调用异常
log.warn("删除案例文档接口调用异常,第{}次尝试", attempt, e);
if (attempt == maxRetries) {
// 最后一次尝试仍然异常
log.error("删除案例文档最终失败,已重试{}次", maxRetries);
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "delete", deleteUrl,
"删除案例文档", "接口调用异常: " + e.getMessage(), CaseDocumentLogOptStatusEnum.FAILED.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), null);
return false;
}
// 继续下一次重试
}
}
return false;
}
@Override
public boolean updateCaseDocument(String caseId) {
if (StringUtil.isBlank(caseId)) {
log.error("更新案例文档失败案例ID不能为空");
return false;
}
// 1. 查询案例信息
Cases caseEntity = casesDao.findOne(FieldFilters.eq("id", caseId));
if (caseEntity == null) {
log.error("更新案例文档失败未找到案例记录caseId: {}", caseId);
return false;
}
log.info("开始更新案例文档caseId: {}", caseId);
// 获取access_token
String accessToken = aiAccessTokenService.getAccessToken();
if (StringUtil.isBlank(accessToken)) {
log.error("更新案例文档失败获取access_token失败");
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "update", "",
"更新案例文档", "获取access_token失败", CaseDocumentLogOptStatusEnum.FAILED.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), null);
return false;
}
try {
// 2. 先调用删除接口
boolean deleteSuccess = callDeleteInterface(caseId, caseEntity, accessToken);
if (!deleteSuccess) {
log.error("更新案例文档失败删除接口调用失败不继续执行上传操作caseId: {}", caseId);
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "update", "",
"更新案例文档", "删除接口:失败,上传接口:未执行", CaseDocumentLogOptStatusEnum.FAILED.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), null);
return false;
}
// 3. 删除成功后,再调用上传接口
String taskId = callUploadInterface(caseId, caseEntity, accessToken);
boolean uploadSuccess = StringUtil.isNotBlank(taskId);
// 4. 根据结果保存一条CaseDocumentLog数据
int optStatus = uploadSuccess ? CaseDocumentLogOptStatusEnum.SUCCESS.getCode() : CaseDocumentLogOptStatusEnum.FAILED.getCode();
int caseStatus = uploadSuccess ? CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
String result = String.format("删除接口:成功,上传接口:%s",
uploadSuccess ? "成功" : "失败");
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "update", "",
"更新案例文档", result, optStatus, caseStatus, taskId);
if (uploadSuccess) {
log.info("更新案例文档成功caseId: {}, taskId: {}", caseId, taskId);
} else {
log.error("更新案例文档失败上传接口调用失败caseId: {}", caseId);
}
return uploadSuccess;
} catch (Exception e) {
log.error("更新案例文档异常", e);
saveCaseDocumentLog(caseId, caseEntity.getTitle(), "update", "",
"更新案例文档", "更新异常: " + e.getMessage(), CaseDocumentLogOptStatusEnum.FAILED.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), null);
return false;
}
}
@Override
public boolean handleUploadCallback(String taskId, String message, String fileStatus) {
if (StringUtil.isBlank(taskId)) {
log.error("处理上传回调失败taskId不能为空");
return false;
}
if (StringUtil.isBlank(fileStatus)) {
log.error("处理上传回调失败fileStatus不能为空taskId: {}", taskId);
return false;
}
try {
// 1. 根据taskId查询最新一条CaseDocumentLog数据
List<CaseDocumentLog> logList = caseDocumentLogDao.getGenericDao()
.findList(CaseDocumentLog.class,
FieldFilters.eq("taskId", taskId),
OrderCondition.desc("sysCreateTime"));
if (logList.isEmpty()) {
log.error("处理上传回调失败未找到对应的日志记录taskId: {}", taskId);
return false;
}
CaseDocumentLog latestLog = logList.get(0);
log.info("找到对应的日志记录logId: {}, taskId: {}, 原状态 - optStatus: {}, caseStatus: {}",
latestLog.getId(), taskId, latestLog.getOptStatus(), latestLog.getCaseStatus());
// 2. 根据fileStatus更新状态
int newOptStatus;
int newCaseStatus;
if ("vectored".equals(fileStatus)) {
// 文档上传成功(向量化成功)
newOptStatus = CaseDocumentLogOptStatusEnum.SUCCESS.getCode();
newCaseStatus = CaseDocumentLogCaseStatusEnum.SUCCESS.getCode();
log.info("文档上传成功向量化成功taskId: {}", taskId);
} else if ("failed".equals(fileStatus)) {
// 业务处理失败
newOptStatus = CaseDocumentLogOptStatusEnum.SUCCESS.getCode(); // 接口调用成功
newCaseStatus = CaseDocumentLogCaseStatusEnum.FAILED.getCode(); // 业务处理失败
log.warn("文档上传业务处理失败taskId: {}, message: {}", taskId, message);
} else {
log.error("未知的fileStatus: {}, taskId: {}", fileStatus, taskId);
return false;
}
// 3. 更新日志记录状态
latestLog.setOptStatus(newOptStatus);
latestLog.setCaseStatus(newCaseStatus);
latestLog.setResponseBody(StringUtil.isNotBlank(message) ? message : latestLog.getResponseBody());
latestLog.setSysUpdateTime(LocalDateTime.now());
caseDocumentLogDao.save(latestLog);
log.info("更新日志记录成功logId: {}, taskId: {}, 新状态 - optStatus: {}, caseStatus: {}",
latestLog.getId(), taskId, newOptStatus, newCaseStatus);
return true;
} catch (Exception e) {
log.error("处理上传回调异常taskId: {}", taskId, e);
return false;
}
}
/**
* 根据文件名获取文件类型
*/
private String getFileType(String fileName) {
if (StringUtil.isBlank(fileName)) {
return "txt";
}
String extension = fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
switch (extension) {
case "doc":
case "docx":
return "word";
case "pdf":
return "pdf";
case "md":
return "md";
case "txt":
return "txt";
case "xls":
case "xlsx":
return "excel";
case "xml":
return "xml";
case "ppt":
case "pptx":
return "ppt";
default:
return "txt";
}
}
/**
* 获取当前用户ID
*/
private String getCurrentUserId() {
// TODO: 实现获取当前登录用户ID的逻辑
// 这里需要根据实际的用户认证系统来实现
return "defaultUserId";
}
/**
* 调用删除接口(仅调用接口,不记录日志)
*/
private boolean callDeleteInterface(String caseId, Cases caseEntity, String accessToken) {
// 1. 根据案例ID查询最新一条CaseDocumentLog数据
List<CaseDocumentLog> logList = caseDocumentLogDao.getGenericDao()
.findList(CaseDocumentLog.class,
FieldFilters.eq("caseId", caseId),
OrderCondition.desc("sysCreateTime"));
if (logList.isEmpty()) {
log.warn("调用删除接口时未找到相关的日志记录caseId: {}", caseId);
return false;
}
CaseDocumentLog latestLog = logList.get(0);
String taskId = latestLog.getTaskId();
if (StringUtil.isBlank(taskId)) {
log.warn("调用删除接口时日志记录中taskId为空caseId: {}", caseId);
return false;
}
String deleteUrl = caseAiProperties.getBaseUrl() + "/apigateway/knowledge/v1/file/delete";
// 2. 重试逻辑最多3次机会
int maxRetries = 3;
for (int attempt = 1; attempt <= maxRetries; attempt++) {
log.info("调用删除接口第{}次尝试caseId: {}, taskId: {}", attempt, caseId, taskId);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpDelete httpDelete = new HttpDelete(deleteUrl);
httpDelete.setHeader("X-AI-ApiCode", caseAiProperties.getAiApiCode());
httpDelete.setHeader("access_token", accessToken);
httpDelete.setHeader("Content-Type", "application/x-www-form-urlencoded");
// 构建请求参数
String params = "kId=" + URLEncoder.encode(caseAiProperties.getCaseKnowledgeId(), StandardCharsets.UTF_8.name()) +
"&taskIds=" + URLEncoder.encode(taskId, StandardCharsets.UTF_8.name());
StringEntity entity = new StringEntity(params, StandardCharsets.UTF_8);
entity.setContentType("application/x-www-form-urlencoded");
httpDelete.setEntity(entity);
try (CloseableHttpResponse response = httpClient.execute(httpDelete)) {
int statusCode = response.getStatusLine().getStatusCode();
String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
if (statusCode == 200) {
JSONObject result = JSON.parseObject(responseBody);
if (result.getBooleanValue("success")) {
JSONObject data = result.getJSONObject("data");
Boolean deleteSuccess = data.getBoolean(taskId);
if (deleteSuccess != null && deleteSuccess) {
log.info("调用删除接口成功caseId: {}, taskId: {}, 尝试次数: {}", caseId, taskId, attempt);
return true;
} else {
// 业务处理失败,不重试
log.warn("调用删除接口业务处理失败不重试caseId: {}, taskId: {}", caseId, taskId);
return false;
}
} else {
// 业务处理失败,不重试
log.warn("调用删除接口业务处理失败不重试response: {}", responseBody);
return false;
}
} else {
// 接口调用失败
log.warn("调用删除接口失败,第{}次尝试status: {}, response: {}", attempt, statusCode, responseBody);
if (attempt == maxRetries) {
log.warn("调用删除接口最终失败,已重试{}次", maxRetries);
return false;
}
// 继续下一次重试
}
}
} catch (Exception e) {
// 接口调用异常
log.warn("调用删除接口异常,第{}次尝试", attempt, e);
if (attempt == maxRetries) {
log.warn("调用删除接口最终失败,已重试{}次", maxRetries);
return false;
}
// 继续下一次重试
}
}
return false;
}
/**
* 调用上传接口(仅调用接口,不记录日志)
*/
private String callUploadInterface(String caseId, Cases caseEntity, String accessToken) {
// 1. 检查文件路径
if (StringUtil.isBlank(caseEntity.getFilePath())) {
log.warn("调用上传接口失败案例文件路径为空caseId: {}", caseId);
return null;
}
File file = new File(caseEntity.getFilePath());
if (!file.exists()) {
log.warn("调用上传接口失败案例文件不存在filePath: {}", caseEntity.getFilePath());
return null;
}
// 2. 构建上传参数
String fileName = caseEntity.getFileName();
if (StringUtil.isBlank(fileName)) {
fileName = file.getName();
}
String fileType = getFileType(fileName);
String userId = getCurrentUserId();
String uploadUrl = caseAiProperties.getBaseUrl() + "/apigateway/knowledge/v1/file/upload";
// 3. 重试逻辑最多3次机会
int maxRetries = 3;
for (int attempt = 1; attempt <= maxRetries; attempt++) {
log.info("调用上传接口第{}次尝试caseId: {}", attempt, caseId);
try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
HttpPost httpPost = new HttpPost(uploadUrl);
httpPost.setHeader("X-AI-ApiCode", caseAiProperties.getAiApiCode());
httpPost.setHeader("access_token", accessToken);
// 构建multipart/form-data请求体
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.addBinaryBody("file", file);
builder.addTextBody("userId", userId, ContentType.TEXT_PLAIN);
builder.addTextBody("kId", caseAiProperties.getCaseKnowledgeId(), ContentType.TEXT_PLAIN);
builder.addTextBody("fileName", fileName, ContentType.TEXT_PLAIN);
builder.addTextBody("fileType", fileType, ContentType.TEXT_PLAIN);
builder.addTextBody("parseType", "AUTO", ContentType.TEXT_PLAIN);
builder.addTextBody("callbackUrl", caseAiProperties.getFileUploadCallbackUrl(), ContentType.TEXT_PLAIN);
HttpEntity multipart = builder.build();
httpPost.setEntity(multipart);
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 = JSON.parseObject(responseBody);
if (result.getBooleanValue("success")) {
JSONObject data = result.getJSONObject("data");
String taskId = data.getString("taskId");
log.info("调用上传接口成功caseId: {}, taskId: {}, 尝试次数: {}", caseId, taskId, attempt);
return taskId;
} else {
// 业务处理失败,不重试
log.warn("调用上传接口业务处理失败不重试response: {}", responseBody);
return null;
}
} else {
// 接口调用失败
log.warn("调用上传接口失败,第{}次尝试status: {}, response: {}", attempt, statusCode, responseBody);
if (attempt == maxRetries) {
log.warn("调用上传接口最终失败,已重试{}次", maxRetries);
return null;
}
// 继续下一次重试
}
}
} catch (Exception e) {
// 接口调用异常
log.warn("调用上传接口异常,第{}次尝试", attempt, e);
if (attempt == maxRetries) {
log.warn("调用上传接口最终失败,已重试{}次", maxRetries);
return null;
}
// 继续下一次重试
}
}
return null;
}
/**
* 保存CaseDocumentLog记录
*/
private void saveCaseDocumentLog(String caseId, String caseTitle, String optType,
String requestUrl, String requestBody, String responseBody,
Integer optStatus, Integer caseStatus, String taskId) {
try {
CaseDocumentLog caseDocumentLog = new CaseDocumentLog();
caseDocumentLog.setId(IDGenerator.generate());
caseDocumentLog.setTaskId(taskId);
caseDocumentLog.setCaseId(caseId);
caseDocumentLog.setCaseTitle(caseTitle);
caseDocumentLog.setOptType(optType);
caseDocumentLog.setRequestUrl(requestUrl);
caseDocumentLog.setRequestBody(requestBody);
caseDocumentLog.setResponseBody(responseBody);
caseDocumentLog.setOptTime(LocalDateTime.now());
caseDocumentLog.setOptStatus(optStatus);
caseDocumentLog.setCaseStatus(caseStatus);
caseDocumentLog.setExecuteDuration(0L);
caseDocumentLogDao.save(caseDocumentLog);
log.info("保存CaseDocumentLog成功logId: {}", caseDocumentLog.getId());
} catch (Exception e) {
log.error("保存CaseDocumentLog失败", e);
}
}
}

View File

@@ -0,0 +1,10 @@
package com.xboe.module.boecase.vo;
import lombok.Data;
/**
* AI会话记录
*/
@Data
public class CaseAiConversationVo {
}

View File

@@ -0,0 +1,32 @@
package com.xboe.module.boecase.vo;
import lombok.Data;
import java.util.List;
/**
* AI会话消息记录VO
*/
@Data
public class CaseAiMessageVo {
/**
* 用户提问内容
*/
private String query;
/**
* AI回答内容
*/
private String answer;
/**
* 案例引用列表
*/
private List<CaseReferVo> caseRefer;
/**
* 建议列表
*/
private List<String> suggestions;
}

View File

@@ -0,0 +1,76 @@
package com.xboe.module.boecase.vo;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import java.time.LocalDateTime;
/**
* AI调用日志列表展示VO
*/
@Data
public class CaseDocumentLogVo {
/**
* 日志ID
*/
private String id;
/**
* 案例标题
*/
private String caseTitle;
/**
* 操作类型
*/
private String optType;
/**
* 调用接口名称
*/
private String requestUrl;
/**
* 调用时间
*/
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
private LocalDateTime optTime;
/**
* 请求参数
*/
private String requestBody;
/**
* 响应参数
*/
private String responseBody;
/**
* 接口调用结果
* 0-调用中, 1-调用成功, 2-调用失败
*/
private Integer optStatus;
/**
* 接口调用结果描述
*/
private String optStatusText;
/**
* 业务处理结果
* 1-处理成功, 2-处理失败
*/
private Integer caseStatus;
/**
* 业务处理结果描述
*/
private String caseStatusText;
/**
* 执行时间(ms)
*/
private Long executeDuration;
}

View File

@@ -0,0 +1,37 @@
package com.xboe.module.boecase.vo;
import lombok.Data;
import java.util.List;
/**
* 案例引用信息VO
*/
@Data
public class CaseReferVo {
/**
* 案例ID
*/
private String caseId;
/**
* 案例标题
*/
private String title;
/**
* 作者姓名
*/
private String authorName;
/**
* 关键词列表
*/
private List<String> keywords;
/**
* 案例内容
*/
private String content;
}

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;
@@ -310,7 +308,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);

View File

@@ -9,6 +9,8 @@ import javax.servlet.http.HttpServletResponse;
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;
@@ -28,19 +30,6 @@ import com.xboe.data.dto.UserOrgIds;
import com.xboe.data.outside.IOutSideDataService;
import com.xboe.data.service.IDataUserSyncService;
import com.xboe.module.assistance.service.IEmailService;
import com.xboe.module.course.entity.Course;
import com.xboe.module.course.entity.CourseContent;
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.ICourseContentService;
import com.xboe.module.course.service.ICourseCrowdService;
import com.xboe.module.course.service.ICourseHRBPAuditService;
import com.xboe.module.course.service.ICourseSectionService;
import com.xboe.module.course.service.ICourseService;
import com.xboe.module.course.service.ICourseTeacherService;
import com.xboe.module.excel.ExportsExcelSenderUtil;
import com.xboe.standard.enums.BoedxContentType;
import com.xboe.standard.enums.BoedxCourseType;
@@ -91,10 +80,10 @@ public class CourseManageApi extends ApiBaseController{
@Resource
private ICourseHRBPAuditService hrbpAuditService;
@Resource
private ICourseTagService tagService;
@Resource
IOutSideDataService outSideDataService;
@Autowired
IDataUserSyncService userSyncService;
@Resource
@@ -169,14 +158,18 @@ public class CourseManageApi extends ApiBaseController{
List<CourseSection> sectionlist=sectionService.getByCourseId(id);
List<CourseTeacher> teachers=courseService.findTeachersByCourseId(id);
List<CourseCrowd> crowds=courseService.findCrowdByCourseId(id);
//
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);
rs.put("teachers",teachers);
rs.put("crowds",crowds);
return success(rs);
@@ -886,7 +879,7 @@ public class CourseManageApi extends ApiBaseController{
* @return
*/
@PostMapping("/delete")
public JsonResponse<Boolean> delete(String id,Boolean erasable,String title,String remark){
public JsonResponse<Boolean> delete(String id,Boolean erasable,String title,String remark, HttpServletRequest request){
if(StringUtils.isBlank(id)){
return badRequest("参数错误");
}
@@ -901,6 +894,11 @@ public class CourseManageApi extends ApiBaseController{
try {
CurrentUser cu=getCurrent();
courseService.delete(id, erasable,cu.getAccountId(), cu.getName(), remark);
String token = request.getHeader("Xboe-Access-Token");
CourseParam param = new CourseParam();
param.setId(id);
thirdApi.delOnLineById(param,token);
return success(true);
} catch (Exception e) {
log.error("管理员删除课程错误",e);

View File

@@ -0,0 +1,173 @@
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 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){
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); // 链式追加排序条件
}
}
}
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<Boolean> changeHotStatus(Long id,Boolean isHot){
return courseTagService.changeHotStatus(id,isHot);
}
/**
* 分页查询指定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){
if (StringUtils.isNotBlank(tagName)){
List<CourseTag> courseTagList = courseTagService.searchTags(tagName);
return success(courseTagList);
}
return error("服务器端异常!");
}
/**
* 创建新标签,并与当前课程绑定
* @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,107 @@
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 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.List;
/**
* @ClassName:CourseTagDao
* @author:zhengge@oracle.com
* @since:2025/7/2516:50
*/
@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.is_hot = true\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.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;
}
}

View File

@@ -0,0 +1,124 @@
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);
}
public boolean countHotTags() {
String sql = "SELECT COUNT(*) FROM boe_course_tag WHERE is_hot = 1";
Query query = entityManager.createNativeQuery(sql);
Object result = query.getSingleResult();
long count = Long.parseLong(result.toString());
return count >= 10;
}
}

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

@@ -140,4 +140,5 @@ 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,92 @@
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;
/**
* 最近设置为公共标签的时间
*/
@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

@@ -56,4 +56,5 @@ public class CourseTeacher extends IdBaseEntity {
/**讲师类型 1 内部讲师 2外部讲师*/
@Transient
private Integer teacherType;
}

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

@@ -341,8 +341,6 @@ public interface ICourseService {
List<Course> mobiledelList(Integer num,CourseQueryDto courseQueryDto);
List<Course> findByIds(List<String> courseIds);
void deletedStudyResourceBatchByCourseIdAndType(String courseId,Integer courseType);
}

View File

@@ -0,0 +1,89 @@
package com.xboe.module.course.service;
import com.xboe.common.OrderCondition;
import com.xboe.common.PageList;
import com.xboe.core.JsonResponse;
import com.xboe.core.orm.IFieldFilter;
import com.xboe.module.course.dto.CourseTagRelationDto;
import com.xboe.module.course.entity.CourseTag;
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
*/
JsonResponse<Boolean> changeHotStatus(Long id, Boolean isHot);
/**
* 解除指定id的课程和某个标签之间的关联关系
* @return
*/
void unbind(String id);
/**
* 根据标签名称进行检索(模糊查询)
* @param tagName
* @return 符合检索条件的所有公共标签
*/
List<CourseTag> searchTags(String tagName);
/**
* 创建新标签,并与当前课程绑定
* @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 bindTag(String id, String tags);
}

View File

@@ -1,5 +1,6 @@
package com.xboe.module.course.service.impl;
import java.io.IOException;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
@@ -14,11 +15,18 @@ import java.util.stream.Stream;
import javax.annotation.Resource;
import javax.management.Query;
import cn.hutool.core.collection.CollectionUtil;
import com.xboe.api.ThirdApi;
import com.xboe.core.orm.*;
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.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.reindex.DeleteByQueryRequest;
import org.hibernate.mapping.IdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
@@ -91,7 +99,8 @@ public class CourseServiceImpl implements ICourseService {
@Resource
private CourseHRBPAuditDao courseHRBPAuditDao;
@Resource
private ICourseTagService courseTagService;
@Resource
private SysLogAuditDao logAuditDao;//审核日志记录
@@ -115,6 +124,9 @@ public class CourseServiceImpl implements ICourseService {
@Autowired(required = false)
private IEventDataSender eventSender;
@Resource
RestHighLevelClient restHighLevelClient;
/**
@@ -481,7 +493,7 @@ public class CourseServiceImpl implements ICourseService {
String sql = "SELECT DISTINCT\n" +
"rt.course_id\n" +
"FROM\n" +
"boe_new.student s INNER JOIN boe_new.router_task rt on s.pid=rt.router_id inner join boe_course c on c.id=rt.course_id\n" +
"boe.student s INNER JOIN boe.router_task rt on s.pid=rt.router_id inner join boe_course c on c.id=rt.course_id\n" +
"\n" +
"WHERE\n" +
"\n" +
@@ -504,7 +516,7 @@ public class CourseServiceImpl implements ICourseService {
String sql = "SELECT DISTINCT\n" +
"pt.course_id\n" +
"FROM\n" +
"boe_new.student s INNER JOIN boe_new.project_task pt on s.pid=pt.project_id inner join boe_course c on c.id=pt.course_id\n" +
"boe.student s INNER JOIN boe.project_task pt on s.pid=pt.project_id inner join boe_course c on c.id=pt.course_id\n" +
"\n" +
"WHERE\n" +
"\n" +
@@ -561,8 +573,8 @@ public class CourseServiceImpl implements ICourseService {
String sql = "SELECT DISTINCT\n" +
"\tc.id \n" +
"FROM\n" +
"\tboe_new.student s\n" +
"\tINNER JOIN boe_new.grow_task gt ON s.pid = gt.grow_id\n" +
"\tboe.student s\n" +
"\tINNER JOIN boe.grow_task gt ON s.pid = gt.grow_id\n" +
"\tINNER JOIN boe_course c ON gt.course_id = c.id \n" +
"WHERE\n" +
"\ts.type = 14 \n" +
@@ -854,12 +866,14 @@ public class CourseServiceImpl implements ICourseService {
log.error("未配置事件消息发送的实现");
}
}
// 删除ES数据
deletedStudyResourceBatchByCourseIdAndType(id,c.getType());
} else {
//彻底删除,课件设置为无课程状态
courseDao.setDeleted(id);
}
//记录删除日志信息
}
@Override
@@ -914,6 +928,7 @@ public class CourseServiceImpl implements ICourseService {
courseCrowdDao.save(cc);
}
}
}
/**
@@ -1010,7 +1025,9 @@ public class CourseServiceImpl implements ICourseService {
publishUtil.removeByDocId(c.getFullTextId());
}
// 添加课程对应的标签
String tags = full.getCourse().getTags();
courseTagService.bindTag(c.getId(), tags);
}
@Override
@@ -1568,6 +1585,13 @@ public class CourseServiceImpl implements ICourseService {
return list;
}
@Override
public List<Course> findByIds(List<String> courseIds) {
QueryBuilder query = QueryBuilder.from(Course.class);
query.addFilter(FieldFilters.in("id", courseIds));
return courseDao.findList(query.builder());
}
@Override
public int countWaitAudit(String aid) {
@@ -1979,5 +2003,17 @@ public class CourseServiceImpl implements ICourseService {
return courseDao.findListByHql("Select new Course(id,studys,score) from Course where id in(?1)", ids);
}
@Override
public void deletedStudyResourceBatchByCourseIdAndType(String courseId, Integer courseType) {
DeleteByQueryRequest request = new DeleteByQueryRequest("new_study_resource");
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolQueryBuilder.must(QueryBuilders.matchQuery("courseId", courseId));
boolQueryBuilder.must(QueryBuilders.matchQuery("courseType", courseType));
request.setQuery(boolQueryBuilder);
try {
restHighLevelClient.deleteByQuery(request, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@@ -0,0 +1,393 @@
package com.xboe.module.course.service.impl;
import com.xboe.common.OrderCondition;
import com.xboe.common.PageList;
import com.xboe.core.JsonResponse;
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.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.*;
/**
* @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) {
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"));
}
return courseTagDao.findPage(query.builder());
}
/**
* 分页查询指定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 JsonResponse<Boolean> changeHotStatus(Long id, Boolean isHot) {
// 当标签切换为热点标签时才会判断,超过十个热点标签则禁止设置
JsonResponse<Boolean> objectJsonResponse = new JsonResponse<>();
if (isHot){
if (courseTagRelationDao.countHotTags()){
objectJsonResponse.setStatus(400);
objectJsonResponse.setMessage("超过十个热点标签,无法进行设置");
objectJsonResponse.setResult(false);
return objectJsonResponse;
}
}
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);
}
objectJsonResponse.setStatus(200);
objectJsonResponse.setMessage("修改成功");
return objectJsonResponse;
}
/**
* 解除指定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 符合检索条件的所有公共标签
*/
@Override
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;
}
/**
* 创建新标签,并与指定课程绑定
* @param courseTagRelationDto
* @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 void bindTag(String id, String tags) {
// 将tags转换为数组
String[] tagIds = tags.split(",");
List<Long> tagIdList = new ArrayList<>();
for (String tagId : tagIds){
tagIdList.add(Long.valueOf(tagId));
}
for (Long tagId : tagIdList){
QueryBuilder courseTagQuery=QueryBuilder.from(CourseTag.class);
List<IFieldFilter> courseTagFilters = new ArrayList<>();
courseTagFilters.add(FieldFilters.eq("id",tagId.toString()));//精确匹配
courseTagQuery.addFilters(courseTagFilters);
//修改该标签关联课程数
CourseTag courseTag = courseTagDao.findOne(FieldFilters.eq("id", String.valueOf(tagId)));
if (courseTag!=null){
//更新该标签的关联课程数量
courseTag.setUseCount(courseTag.getUseCount()+1);
courseTagDao.saveOrUpdate(courseTag);
}
// 查询课程是否绑定了标签
QueryBuilder query=QueryBuilder.from(CourseTagRelation.class);
List<IFieldFilter> filters = new ArrayList<>();
filters.add(FieldFilters.eq("courseId",Long.valueOf(id)));
filters.add(FieldFilters.eq("tagId",Long.valueOf(tagId)));
query.addFilters(filters);
List<CourseTagRelation> courseTagRelationList = courseTagRelationDao.findList(query.builder());
// 如果没有绑定标签,那么就进行绑定
if (courseTagRelationList==null || courseTagRelationList.size()==0){
CourseTagRelation courseTagRelation = new CourseTagRelation();
courseTagRelation.setTagId(Long.valueOf(tagId));
courseTagRelation.setCourseId(Long.valueOf(id));
courseTagRelationDao.save(courseTagRelation);
}
}
}
@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;
}
}

View File

@@ -8,6 +8,8 @@ import java.util.Map;
import javax.annotation.Resource;
import com.boe.feign.api.courseweb.reps.ExamStudyRecordParam;
import com.xboe.api.ThirdApi;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -37,7 +39,10 @@ public class AloneExamServiceImpl implements IAloneExamService{
@Resource
AloneExamDao aeDao;
@Resource
private ThirdApi thirdApi;
@Override
@Transactional
public void save(AloneExamAnswer aea){
@@ -101,7 +106,18 @@ public class AloneExamServiceImpl implements IAloneExamService{
// //这种情况汶是不存在的
// }
}
}
try {
ExamStudyRecordParam param = new ExamStudyRecordParam();
param.setTestId(aea.getTestId());
param.setAid(aea.getAid());
thirdApi.syncExamStudyRecord(param);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
@Override
@Transactional

View File

@@ -1,15 +1,21 @@
package com.xboe.school.study.api;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDateTime;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.function.Function;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.nacos.shaded.com.google.common.util.concurrent.RateLimiter;
import com.xboe.api.ThirdApi;
import com.xboe.constants.CacheName;
import com.xboe.module.course.vo.TeacherVo;
import com.xboe.module.usergroup.service.IUserGroupService;
import com.xboe.school.study.dao.StudyCourseDao;
import com.xboe.school.vo.StudyTimeVo;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -253,6 +259,36 @@ public class StudyCourseApi extends ApiBaseController{
rs.put("progress", sc.getProgress());
//查询上次学习的是什么资源。查询用户的学习情况
List<StudyCourseItem> items=studyService.findByStudyId(sc.getId());
// 和内容匹配,根据内容的视频时长,计算学习进度
if(CollectionUtil.isNotEmpty(items) && CollectionUtil.isNotEmpty(cclist)){
// 根据ID转换map
Map<String, CourseContent> contentMap = cclist.stream().collect(Collectors.toMap(CourseContent::getId, Function.identity()));
for (StudyCourseItem item : items) {
CourseContent content = contentMap.get(item.getContentId());
if(null == content){
continue;
}
if(null==item.getLastStudyTime()
|| item.getLastStudyTime()<=0
|| null==content.getDuration()
|| content.getDuration()<=0){
continue;
}
BigDecimal lastStudyTime = new BigDecimal(item.getLastStudyTime());
BigDecimal duration = new BigDecimal(content.getDuration());
BigDecimal progress = lastStudyTime.divide(duration, 10, RoundingMode.HALF_UP);
if(progress.compareTo(BigDecimal.ZERO) < 0){
progress = BigDecimal.ZERO;
}else if(progress.compareTo(BigDecimal.ONE) > 0){
progress = BigDecimal.ONE;
}
item.setProgressVideo(progress);
}
}
rs.put("contentStudys",items);//学习的内容
}
@@ -345,6 +381,8 @@ public class StudyCourseApi extends ApiBaseController{
}
//追加学习时长
studyService.appendStudyDuration(sci.getStudyId(),item.getId(),sci.getContentId(),sci.getDuration());
log.info(" 1 在线课学习记录 sci.getStudyId() = "+ sci.getStudyId() + " , sci.getCourseId() = " + sci.getCourseId() );
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(sci.getStudyId() ,sci.getCourseId(), token);
log.info("在线课学习记录"+allUserList);
return success(item.getId());
@@ -575,7 +613,7 @@ public class StudyCourseApi extends ApiBaseController{
@Deprecated
@RequestMapping(value="/appendtime",method = {RequestMethod.GET,RequestMethod.POST})
public JsonResponse<String> appendTime(StudyTime studyTime, HttpServletRequest request){
if(StringUtils.isBlank(studyTime.getStudyId())){
return error("参数错误");
}
@@ -605,7 +643,91 @@ public class StudyCourseApi extends ApiBaseController{
return error("记录学习时长错误",e.getMessage());
}
}
/**
* appendtime 于 study-video-time 合并
* */
/*@RequestMapping(value="/updateStudyVideoTime1",method = {RequestMethod.GET,RequestMethod.POST})
public JsonResponse<String> updateStudyVideoTime1(StudyTimeVo studyTime, HttpServletRequest request){
// 0 study-video-time , 1 appendtime
if (studyTime.getType() == 0){
if(StringUtils.isBlank(studyTime.getItemId())){
return error("参数错误");
}
if(studyTime.getVideoTime()==null){
return error("无时间点");
}
//检查是否已存在
try {
studyService.updateLastTime(studyTime.getItemId(),studyTime.getVideoTime(), getCurrent().getAccountId());
if (studyTime.getContentId() != null && studyTime.getCourseId() != null && studyTime.getProgressVideo() != null){
contentService.updateProcessVideo(studyTime.getContentId(), studyTime.getCourseId(), studyTime.getProgressVideo());
}
return success("true");
}catch(Exception e) {
log.error("updateStudyVideoTime type =0 记录最后学习时间错误",e);
return error("updateStudyVideoTime type =0 记录最后学习时间失败 ",e.getMessage());
}
}else if(studyTime.getType() == 1){
if(StringUtils.isBlank(studyTime.getStudyId())){
return error("参数错误");
}
if(StringUtils.isBlank(studyTime.getCourseId())){
return error("未指定课程");
}
if(StringUtils.isBlank(studyTime.getContentId())){
return error("未指定资源内容");
}
String token = request.getHeader("Xboe-Access-Token");
if (StringUtils.isEmpty(token)) {
token = request.getHeader("token");
}
try {
studyService.updateStudyDuration(studyTime.getStudyId(),null,studyTime.getContentId(),studyTime.getVideoTime(),studyTime.getCourseId());
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(studyTime.getStudyId() ,studyTime.getCourseId(), token);
log.info("updateStudyVideoTime type =1 在线课学习记录 = " + allUserList);
return success(studyTime.getId());
}catch(Exception e) {
log.error("updateStudyVideoTime type =1 记录学习时长错误",e);
return error("updateStudyVideoTime type =1 记录学习时长错误 ",e.getMessage());
}
}else{
return error("type不能为空");
}
}*/
@RequestMapping(value="/updateStudyVideoTime",method = {RequestMethod.GET,RequestMethod.POST})
public JsonResponse<String> updateStudyVideoTime(StudyTimeVo studyTime, HttpServletRequest request){
try {
if(StringUtils.isBlank(studyTime.getItemId())){
return error("参数错误");
}
if(studyTime.getVideoTime()==null){
return error("无时间点");
}
if(StringUtils.isBlank(studyTime.getStudyId())){
return error("参数错误");
}
if(StringUtils.isBlank(studyTime.getCourseId())){
return error("未指定课程");
}
if(StringUtils.isBlank(studyTime.getContentId())){
return error("未指定资源内容");
}
studyService.updateStudyDuration(studyTime.getStudyId(),studyTime.getItemId(),studyTime.getContentId(),studyTime.getVideoTime(),studyTime.getCourseId());
if (studyTime.getContentId() != null && studyTime.getCourseId() != null && studyTime.getProgressVideo() != null){
contentService.updateProcessVideo(studyTime.getContentId(), studyTime.getCourseId(), studyTime.getProgressVideo());
}
} catch (Exception e) {
log.error("updateStudyVideoTime",e);
return error("学习时长记录失败",e.getMessage(),null);
}
return success("true");
}
/**获取最后一次的学习内容*/
@GetMapping("/last-study")
public JsonResponse<Map<String,Object>> lastStudy(){

View File

@@ -3,9 +3,16 @@ package com.xboe.school.study.api;
import java.io.IOException;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import cn.hutool.core.collection.CollectionUtil;
import com.xboe.module.course.entity.Course;
import com.xboe.module.course.service.ICourseService;
import org.apache.commons.compress.utils.Lists;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
@@ -42,6 +49,15 @@ public class StudyCourseESApi extends ApiBaseController{
@Autowired
IStudyCourseService service;
@Autowired
ICourseService courseService;
@Value("${xboe.upload.file.http_path}")
private String httpPath;
@Value("${xboe.image.course.default}")
private String defaultCourseImage;
@Resource
private PhpOnlineStudyRecordScheduledTasks phpOnlineStudyRecordScheduledTasks;
@@ -54,13 +70,61 @@ public class StudyCourseESApi extends ApiBaseController{
try {
dto.setAccountId(getCurrent().getAccountId());
PageList<CourseStudyDto> rs=search.search(page.getStartRow(),page.getPageSize(), dto);
handleCourseImage(rs);
return success(rs);
}catch(Exception e) {
log.error("查询报名学习ES失败",e);
return error("查询失败",e.getMessage());
}
}
private void handleCourseImage(PageList<CourseStudyDto> rs) {
if (rs == null || CollectionUtil.isEmpty(rs.getList())) {
return;
}
List<String> emptyImageCourseIds = Lists.newArrayList();
for(CourseStudyDto courseStudyDto : rs.getList()) {
if(StringUtils.isBlank(courseStudyDto.getCourseImage())) {
// 过滤课程类型
if(courseStudyDto.getCourseType()==10
|| courseStudyDto.getCourseType()==20){
emptyImageCourseIds.add(courseStudyDto.getCourseId());
}else{
log.warn("课程图片为空课程id为{},课程类型:{}",courseStudyDto.getCourseId(),courseStudyDto.getCourseType());
}
}
}
if(CollectionUtil.isEmpty(emptyImageCourseIds)){
return;
}
List<Course> courseList = courseService.findByIds(emptyImageCourseIds);
if(CollectionUtil.isNotEmpty(courseList)){
// courseList转换成map
Map<String, Course> courseMap = courseList.stream().collect(Collectors.toMap(Course::getId, course -> course));
// 赋值ES图片
for(CourseStudyDto courseStudyDto : rs.getList()) {
if(emptyImageCourseIds.contains(courseStudyDto.getCourseId())) {
Course currentCourse = courseMap.get(courseStudyDto.getCourseId());
if(null!=currentCourse){
if(StringUtils.isNotBlank(currentCourse.getCoverImg())){
// 拼接域名
courseStudyDto.setCourseImage(httpPath + currentCourse.getCoverImg());
}else{
// 赋值默认图片
courseStudyDto.setCourseImage(defaultCourseImage);
}
}
}
}
}
}
@RequestMapping(value="/list-by-ids",method = {RequestMethod.POST})
public JsonResponse<List<StudyCourse>> search(@RequestBody List<String> ids){
if(ids.isEmpty()) {

View File

@@ -0,0 +1,262 @@
package com.xboe.school.study.api;
import com.xboe.api.ThirdApi;
import com.xboe.school.study.entity.StudyCourse;
import com.xboe.school.study.service.IStudyService;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;
/**
* @author by lyc
* @date 2025/3/3
*/
@Component
@Slf4j
@RequiredArgsConstructor
public class StudyCourseTask {
private final IStudyService studyService;
private final StringRedisTemplate redisTemplate;
@Resource
private ThirdApi thirdApi;
/**
* 定时任务
* 获取redis 中学习结束的数据更新入库
* */
@XxlJob("saveStudyCourseItemLastTime2")
public void saveStudyCourseItemLastTime2() {
// 1. 定义匹配模式匹配所有目标key
final String KEY_PATTERN = "studyContentId:*:last_active";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
// 2. 使用SCAN安全遍历避免阻塞
ScanOptions options = ScanOptions.scanOptions()
.match(KEY_PATTERN)
.count(100) // 分页大小
.build();
try (RedisConnection connection = Objects.requireNonNull(redisTemplate.getConnectionFactory()).getConnection()) {
Cursor<byte[]> cursor = connection.scan(options);
// 3. 遍历处理符合条件的key
while (cursor.hasNext()) {
String redisKey = new String(cursor.next());
// 4. 获取剩余TTL
Long ttl = redisTemplate.getExpire(redisKey, TimeUnit.SECONDS);
// 5. 过滤条件:剩余时间 >= 29天23小时30分钟转换为秒
// 总需时间 = (30天 - 30分钟) = 29天23小时30分钟 = 2590200秒
// 5分钟 300秒 || 2592000 - 300 = 2591700
if (ttl <= 2590200) {
try {
// 6. 提取studyContentId
String[] parts = redisKey.split(":");
if (parts.length < 2) continue;
String studyContentId = parts[1];
// 7. 获取存储的时间点(示例逻辑)
String redisValue = redisTemplate.opsForValue().get(redisKey);
if (redisValue == null) continue;
String[] partValues = redisValue.split("&");
int lastStudyTime = Integer.parseInt(partValues[0]);
LocalDateTime timestamp = null;
if (partValues.length >= 2){
timestamp = LocalDateTime.parse(partValues[1], formatter);
}
// 8. 更新数据库(调用已有服务方法)
studyService.updateStudyCourseItemLastTime(studyContentId, lastStudyTime, timestamp);
// 9. 删除Redis键原子操作
redisTemplate.delete(redisKey);
log.info("处理成功 key: {}, lastStudyTime: {}", redisKey, lastStudyTime);
} catch (Exception e) {
log.error("处理失败 key: {}", redisKey, e);
}
}
}
cursor.close();
} catch (Exception e) {
log.error("定时任务执行异常", e);
}
/* // 新增日志逻辑
if (ttl <= 172800) {
studyService.saveCourseExpireLog(
studyContentId,
lastStudyTime,
redisKey,
ttl,
"system_job"
);
}*/
}
@XxlJob("saveStudyCourseItemLastTime")
public void saveStudyCourseItemLastTime() {
// 1. 定义匹配模式匹配所有目标key
final String KEY_PATTERN = "studyId:*:courseId:*:courseContentId:*:studyItemId:*";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
// 2. 使用SCAN安全遍历避免阻塞
ScanOptions options = ScanOptions.scanOptions()
.match(KEY_PATTERN)
.count(100) // 分页大小
.build();
try (RedisConnection connection = Objects.requireNonNull(redisTemplate.getConnectionFactory()).getConnection()) {
Cursor<byte[]> cursor = connection.scan(options);
// 3. 遍历处理符合条件的key
while (cursor.hasNext()) {
String redisKey = new String(cursor.next());
log.info("-定时任务 saveStudyCourseItemLastTime ---redisKey = " + redisKey);
// 4. 获取剩余TTL
Long ttl = redisTemplate.getExpire(redisKey, TimeUnit.SECONDS);
// 5. 过滤条件:剩余时间 >= 29天23小时30分钟转换为秒
// 总需时间 = (30天 - 30分钟) = 29天23小时30分钟 = 2590200秒
// 5分钟 300秒 || 2592000 - 300 = 2591700
if (ttl <= 2590200) {
try {
// 6. 提取studyContentId
String[] parts = redisKey.split(":");
if (parts.length < 7) continue;
String studyId = parts[1];
String courseId = parts[3];
String courseContentId = parts[5];
String studyItemId = parts[7];
// 7. 获取存储的时间点(示例逻辑)
String redisValue = redisTemplate.opsForValue().get(redisKey);
log.info("-定时任务 saveStudyCourseItemLastTime ---redisValue = " + redisValue);
if (redisValue == null) continue;
String[] partValues = redisValue.split("&");
int studyVideoTtime = Integer.parseInt(partValues[0]);
int appendtime = Integer.parseInt(partValues[1]);
LocalDateTime timestamp = null;
if (partValues.length >= 2){
timestamp = LocalDateTime.parse(partValues[2], formatter);
}
// 8. 更新数据库(调用已有服务方法)
studyService.newAppendStudyDuration(studyId,null,courseContentId,appendtime,timestamp);
log.info("-定时任务 saveStudyCourseItemLastTime ---studyItemId = " + studyItemId);
if (studyItemId != null && !studyItemId.equals("null")){
log.info("-定时任务 saveStudyCourseItemLastTime --- boolean studyItemId = " + (studyItemId != null));
// 8. 更新数据库(调用已有服务方法)
studyService.updateStudyCourseItemLastTime(studyItemId, studyVideoTtime, timestamp);
}
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(studyId , courseId, null);
log.info("处理成功 allUserList: {}", allUserList);
// 9. 删除Redis键原子操作
redisTemplate.delete(redisKey);
log.info("处理成功 key: {}, lastStudyTime: {}", redisKey, appendtime);
} catch (Exception e) {
log.error("处理失败 key: {}", redisKey, e);
}
}
}
cursor.close();
} catch (Exception e) {
log.error("定时任务执行异常", e);
}
}
@XxlJob("saveStudyCourseItemLastTime1")
public void saveStudyCourseItemLastTime1() {
// 定义需要处理的键模式集合
processKeys("studyContentId:*:last_active", this::handleLastActiveKey);
processKeys("studyId:*:courseId:*:courseContentId:*", this::handleDurationKey);
}
private void processKeys(String keyPattern, BiConsumer<String, String> keyHandler) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
ScanOptions options = ScanOptions.scanOptions()
.match(keyPattern)
.count(100)
.build();
try (RedisConnection connection = Objects.requireNonNull(redisTemplate.getConnectionFactory()).getConnection()) {
Cursor<byte[]> cursor = connection.scan(options);
while (cursor.hasNext()) {
String redisKey = new String(cursor.next());
Long ttl = redisTemplate.getExpire(redisKey, TimeUnit.SECONDS);
if (ttl != null && ttl <= 2590200) {
try {
String redisValue = redisTemplate.opsForValue().get(redisKey);
if (redisValue != null) {
// 调用对应的处理方法
keyHandler.accept(redisKey, redisValue);
}
redisTemplate.delete(redisKey);
log.info("Key processed: {}", redisKey);
} catch (Exception e) {
log.error("Process failed [{}]", redisKey, e);
}
}
}
cursor.close();
} catch (Exception e) {
log.error("Key processing error: {}", keyPattern, e);
}
}
// 处理 last_active 类型键
private void handleLastActiveKey(String redisKey, String redisValue) {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
String[] parts = redisKey.split(":");
String studyContentId = parts[1];
String[] values = redisValue.split("&");
int lastStudyTime = Integer.parseInt(values[0]);
LocalDateTime timestamp = values.length >= 2 ?
LocalDateTime.parse(values[1], formatter) : null;
studyService.updateStudyCourseItemLastTime(studyContentId, lastStudyTime, timestamp);
}
// 处理 duration 类型键
private void handleDurationKey(String redisKey, String redisValue) {
String[] parts = redisKey.split(":");
String studyId = parts[1];
String courseId = parts[3];
String courseContentId = parts[5];
String[] values = redisValue.split("&");
int duration = Integer.parseInt(values[0]);
LocalDateTime timestamp = values.length >= 2 ?
LocalDateTime.parse(values[1], DateTimeFormatter.ISO_LOCAL_DATE_TIME) : null;
studyService.newAppendStudyDuration(studyId, null, courseContentId, duration, timestamp);
// 保留第三方调用
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(studyId, courseId, null);
log.info("Study records synced: {}", allUserList.size());
}
}

View File

@@ -1,10 +1,12 @@
package com.xboe.school.study.entity;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Transient;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.xboe.core.SysConstant;
@@ -128,5 +130,12 @@ public class StudyCourseItem extends IdEntity {
*/
@Column(name = "status",length=1)
private Integer status;
/**
* 视频播放进度
* */
// @Column(name = "progress_video")
@Transient
private BigDecimal progressVideo;
}

View File

@@ -1,5 +1,6 @@
package com.xboe.school.study.service;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@@ -7,7 +8,6 @@ import com.xboe.common.PageList;
import com.xboe.school.study.dto.StudyContentDto;
import com.xboe.school.study.entity.StudyCourseItem;
import com.xboe.school.study.entity.StudyTime;
import com.xboe.system.user.entity.User;
/**
* 学习情况处理,比较综合一个处理类
@@ -35,11 +35,12 @@ public interface IStudyService {
/**
* 更新最后的学习时间,及学习时间点
*
* @param studyContentId
* @param lastStudyTime
* @param aid
*/
void updateLastTime(String studyContentId,int lastStudyTime,String aid);
void updateLastTime(String studyContentId, int lastStudyTime, String aid);
/**
* 资源学习记录
@@ -99,4 +100,9 @@ public interface IStudyService {
List<StudyCourseItem> getList(String courseId, String contentId, String name, Integer status);
void updateStudyCourseItemLastTime(String studyContentId, int lastStudyTime, LocalDateTime timestamp);
void updateStudyDuration(String studyId,String studyItemId, String contentId, Integer videoTime,String courseId);
void newAppendStudyDuration(String studyId, String studyItemId, String courseContentId, int duration, LocalDateTime timestamp);
}

View File

@@ -1,5 +1,6 @@
package com.xboe.school.study.service.impl;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
@@ -9,12 +10,9 @@ import java.util.Map;
import javax.transaction.Transactional;
import com.xboe.module.article.entity.Article;
import com.xboe.module.interaction.entity.Shares;
import com.xboe.school.study.entity.StudyCourse;
import com.xboe.system.user.entity.User;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import com.xboe.common.OrderCondition;
@@ -51,7 +49,10 @@ public class StudyServiceImpl implements IStudyService{
@Autowired
UserDao userDao;
@Autowired
StringRedisTemplate redisTemplate;
@Override
public StudyCourseItem checkHas(String studyId,String contentId) {
List<StudyCourseItem> items = scItemDao.findList(FieldFilters.eq("studyId", studyId),FieldFilters.eq("contentId", contentId));
@@ -115,34 +116,74 @@ public class StudyServiceImpl implements IStudyService{
//增加内容的学习时长
if(StringUtils.isNotBlank(studyItemId)) {
//直接根据id更新
// String hql="Update StudyCourseItem set studyDuration=studyDuration+"+duration+",status=(case when status<2 then 2 else status end) where id=?1";
// scItemDao.update(hql,studyItemId);
String sql="Update boe_study_course_item set study_duration=study_duration+"+duration+",status=(case when status<2 then 2 else status end) where id=?1";
scItemDao.sqlUpdate(sql,studyItemId);
//scItemDao.updateMultiFieldById(studyItemId, UpdateBuilder.create("studyDuration", "studyDuration+"+duration,FieldUpdateType.EXPRESSION));
}else {
//根据学习id和课程内容id更新
// scItemDao.update(UpdateBuilder.from(StudyCourseItem.class)
// .addUpdateField("studyDuration", "studyDuration+"+duration,FieldUpdateType.EXPRESSION)
// .addFilter(FieldFilters.eq("studyId", studyId))
// .addFilter(FieldFilters.eq("contentId", courseContentId))
// .builder());
//
// String hql="Update StudyCourseItem set studyDuration=studyDuration+"+duration+",status=(case when status<2 then 2 else status end) where studyId=?1 and contentId=?2";
// scItemDao.update(hql,studyId,courseContentId);
String sql="Update boe_study_course_item set study_duration=study_duration+"+duration+",status=(case when status<2 then 2 else status end) where study_id=?1 and content_id=?2";
scItemDao.sqlUpdate(sql,studyId,courseContentId);
}
//追加课程的学习时长
//scDao.updateMultiFieldById(studyId, UpdateBuilder.create("totalDuration", "totalDuration+"+duration,FieldUpdateType.EXPRESSION));
String sql="Update boe_study_course set total_duration=total_duration+"+duration+",status=(case when status<2 then 2 else status end),progress=(case when progress=0 then 1 else progress end),last_time = '"+LocalDateTime.now()+"' where id=?1";
scDao.sqlUpdate(sql,studyId);
}
@Override
@Transactional
public void newAppendStudyDuration(String studyId,String studyItemId,String courseContentId, int duration,LocalDateTime timestamp) {
//增加内容的学习时长
if(StringUtils.isNotBlank(studyItemId)) {
//直接根据id更新
String sql="Update boe_study_course_item set study_duration=study_duration+"+duration+",status=(case when status<2 then 2 else status end) where id=?1";
scItemDao.sqlUpdate(sql,studyItemId);
}else {
String sql="Update boe_study_course_item set study_duration=study_duration+"+duration+",status=(case when status<2 then 2 else status end) where study_id=?1 and content_id=?2";
scItemDao.sqlUpdate(sql,studyId,courseContentId);
}
String sql="Update boe_study_course set total_duration=total_duration+"+duration+",status=(case when status<2 then 2 else status end),progress=(case when progress=0 then 1 else progress end),last_time = '"+timestamp+"' where id=?1";
scDao.sqlUpdate(sql,studyId);
}
// 更新 前端传输已学习时长
@Override
public void updateStudyDuration(String studyId,String studyItemId,String courseContentId, Integer videoTime,String courseId) {
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
String key = "studyId:" + studyId + ":courseId:" + courseId + ":courseContentId:" + courseContentId + ":studyItemId:" + studyItemId;
String currentValue = redisTemplate.opsForValue().get(key);
Integer lastDuration = 0;
Integer oldVideoTime = 0;
Integer sum = 10; // 原appendtime改为固定10秒调用一次接口
if (currentValue != null) {
String[] partValues = currentValue.split("&");
oldVideoTime = Integer.parseInt(partValues[0]);
lastDuration = Integer.parseInt(partValues[1]);
sum += lastDuration;
if(oldVideoTime > videoTime){
videoTime = oldVideoTime;// 取最大值最终入库
}
};
String value = videoTime + "&" + sum + "&" + now.format(formatter); // study_video_time & appendtime & time
log.info("-study-video-time-----value = " + value);
// 20250303 优化 多次更新改一次更新
// 更新Redis中的最后活跃时间带30秒过期
redisTemplate.opsForValue().set(
key,
value,
Duration.ofSeconds(2592000)
);
log.info("- 合并 updateStudyDuration -redis保存---value = " + value);
// Duration.ofDays(30) 也就是 2592000秒
}
@Override
@Transactional
public void appendStudyDuration(StudyTime st) {
@@ -165,7 +206,21 @@ public class StudyServiceImpl implements IStudyService{
@Override
public List<StudyCourseItem> findByStudyId(String studyId) {
return scItemDao.findList(OrderCondition.desc("lastTime"),FieldFilters.eq("studyId", studyId));
List<StudyCourseItem> list = scItemDao.findList(OrderCondition.desc("lastTime"),FieldFilters.eq("studyId", studyId));
for (StudyCourseItem item : list){
log.info("-- studyIndex -查询上次学习的是什么资源。mysql查询---------------- item = " + item);
String redisKey = "studyId:" + studyId + ":courseId:" + item.getCourseId() + ":courseContentId:" + item.getContentId() + ":studyItemId:" + item.getId();
log.info("-- studyIndex -查询上次学习的是什么资源。查询用户的学习情况---------------- redisKey = " + redisKey);
String redisValue = redisTemplate.opsForValue().get(redisKey);
log.info("-- studyIndex -查询上次学习的是什么资源。查询用户的学习情况---------------- redisValue = " + redisValue);
if (redisValue != null) {
String[] values = redisValue.split("&");
int duration = Integer.parseInt(values[0]);
item.setLastStudyTime(duration);
log.info("-- studyIndex -----set 结果---------------- LastStudyTime = " + item.getLastStudyTime());
}
}
return list;
}
@Override
@@ -324,8 +379,26 @@ public class StudyServiceImpl implements IStudyService{
// 更新 前端传输已学习时长
@Override
@Transactional
public void updateLastTime(String studyContentId, int lastStudyTime,String aid) {
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
String value = lastStudyTime + "&" + now.format(formatter); // 使用ISO8601时间格式
log.info("-study-video-time-----value = " + value);
// 20250303 优化 多次更新改一次更新
// 更新Redis中的最后活跃时间带30秒过期
redisTemplate.opsForValue().set(
"studyContentId:" + studyContentId + ":last_active",
value,
Duration.ofSeconds(2592000)
);
log.info("-study-video-time-redis保存---value = " + value);
// Duration.ofDays(30) 也就是 2592000秒
}
@Override
@Transactional
public void updateStudyCourseItemLastTime(String studyContentId, int lastStudyTime,LocalDateTime timestamp) {
log.info("-study-video-time-定时---studyContentId = " + studyContentId + ",lastStudyTime = " + lastStudyTime + ", timestamp = " + timestamp);
// 更新最后的学习时间点
LocalDateTime now=LocalDateTime.now();
UpdateBuilder update=UpdateBuilder.from(StudyCourseItem.class);
@@ -333,11 +406,12 @@ public class StudyServiceImpl implements IStudyService{
//只记录时间长的时候的处理
update.addFilter(FieldFilters.lt("lastStudyTime", lastStudyTime));
update.addUpdateField("lastStudyTime", lastStudyTime);
update.addUpdateField("lastTime", now);
update.addUpdateField("lastTime", timestamp==null ? now : timestamp);
scItemDao.update(update.builder());
//增加用户的学习时长,在api中调用
log.info("-study-video-time-mysql保存---studyContentId = " + studyContentId);
}
@Override
public Map<String,Object> getLast(String aid) {
//按lastTime排序第一条,只是课件内容

View File

@@ -0,0 +1,19 @@
package com.xboe.school.vo;
import com.xboe.school.study.entity.StudyTime;
import lombok.Data;
/** appendtime 于 study-video-time 合并
* appendtime 参数 StudyTime
* study-video-time 参数 是 StudyTimeVo
*/
@Data
public class StudyTimeVo extends StudyTime {
private String itemId;
private Integer videoTime;
// private String contentId; // 已继承
// private String courseId; // 已继承
private Float progressVideo;
private Integer type; // 0 study-video-time , 1 appendtime
}

View File

@@ -76,6 +76,17 @@ xboe:
encryptor:
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
image:
course:
default: http://192.168.0.253/pc/images/bgimg/course.png
case:
ai:
base-url: http://10.10.181.114:30003
app-key: 6e9be45319184ac793aa127c362b0f0b
secret-key: db4d24279e3d6dbf1524af42cd0bedd2
ai-api-code: 30800
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
file-upload-callback-url: http://192.168.0.253:9090/xboe/m/boe/caseDocumentLog/uploadCallback
xxl:
job:
accessToken: 65ddc683-22f5-83b4-de3a-3c97a0a29af0

View File

@@ -108,7 +108,17 @@ xboe:
from: boeu_learning@boe.com.cn
user:
security:
image:
course:
default: http://10.251.132.75/pc/images/bgimg/course.png
case:
ai:
base-url: http://10.10.181.114:30003
app-key: 6e9be45319184ac793aa127c362b0f0b
secret-key: db4d24279e3d6dbf1524af42cd0bedd2
ai-api-code: 30800
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
file-upload-callback-url: http://192.168.0.253:9090/xboe/m/boe/caseDocumentLog/uploadCallback
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES

View File

@@ -74,6 +74,17 @@ xboe:
encryptor:
algorithm: PBEWithMD5AndDES
iv-generator-classname: org.jasypt.iv.NoIvGenerator
image:
course:
default: https://u.boe.com/pc/images/bgimg/course.png
case:
ai:
base-url: http://10.10.181.114:30003
app-key: 6e9be45319184ac793aa127c362b0f0b
secret-key: db4d24279e3d6dbf1524af42cd0bedd2
ai-api-code: 30800
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
file-upload-callback-url: http://192.168.0.253:9090/xboe/m/boe/caseDocumentLog/uploadCallback
xxl:
job:
accessToken: 65ddc683-22f5-83b4-de3a-3c97a0a29af0

View File

@@ -84,7 +84,7 @@ xboe:
file:
temp_path: /tmp
save_path: /home/www/elearning/upload
http_path: http://10.251.186.27/upload
http_path: https://u-pre.boe.com/upload
externalinterface:
url:
system: http://localhost:9091
@@ -108,7 +108,17 @@ xboe:
from: boeu_learning@boe.com.cn
user:
security:
image:
course:
default: https://u-pre.boe.com/pc/images/bgimg/course.png
case:
ai:
base-url: http://10.10.181.114:30003
app-key: 6e9be45319184ac793aa127c362b0f0b
secret-key: db4d24279e3d6dbf1524af42cd0bedd2
ai-api-code: 30800
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
file-upload-callback-url: http://192.168.0.253:9090/xboe/m/boe/caseDocumentLog/uploadCallback
jasypt:
encryptor:
algorithm: PBEWithMD5AndDES

View File

@@ -73,4 +73,5 @@ coursesuilt:
updateOrSaveCourse: ${boe.domain}/manageApi/admin/teacherRecord/updateOrSaveCourse
syncCourseStudent: ${boe.domain}/manageApi/admin/teacherRecord/syncCourseStudent
syncOnLineScore: ${boe.domain}/manageApi/admin/teacherRecord/syncOnLineScore
updateOnLineStatua: ${boe.domain}/manageApi/admin/teacherRecord/updateOnLineStatua
updateOnLineStatua: ${boe.domain}/manageApi/admin/teacherRecord/updateOnLineStatua
delOnLineById: ${boe.domain}/manageApi/admin/teacherRecord/delOnLineById