mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-08 18:36:51 +08:00
Compare commits
96 Commits
test1031
...
release-20
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
50a7baa4dd | ||
|
|
99a4f9b12a | ||
|
|
a481dd619f | ||
|
|
a95271ee36 | ||
|
|
db73753c1f | ||
|
|
ce84ea8121 | ||
|
|
89860eb080 | ||
|
|
c701fae5ef | ||
|
|
abf5642154 | ||
|
|
a0bba75f80 | ||
|
|
d0e0115f27 | ||
|
|
33e2313eb0 | ||
|
|
b4ca82ae73 | ||
|
|
bff8ba166f | ||
|
|
b04a14d3f2 | ||
|
|
acb8d08379 | ||
|
|
eafcbf8337 | ||
|
|
4f9f5711f7 | ||
|
|
81aae0af37 | ||
|
|
4303798fac | ||
|
|
0b57f016f5 | ||
|
|
9a04128a23 | ||
|
|
dd6ad3c7e0 | ||
|
|
63e8bd28b3 | ||
|
|
c38c7b9c80 | ||
|
|
45eb2e14b2 | ||
|
|
286dc1e6d6 | ||
|
|
11ed049a6a | ||
|
|
f9d2b8e92f | ||
|
|
7adb7b6152 | ||
|
|
7895b1fee9 | ||
|
|
f4c8e36167 | ||
|
|
16255d5a88 | ||
|
|
12fea5d288 | ||
|
|
e4e10ddb73 | ||
|
|
7284f9cb12 | ||
|
|
f06eb9bc7d | ||
|
|
f2a633958e | ||
|
|
b0eb7796da | ||
|
|
c077123b53 | ||
|
|
c23c9ddf7c | ||
|
|
bcfdf65140 | ||
|
|
e704930bca | ||
|
|
1edb36622f | ||
|
|
ea5c15a290 | ||
|
|
124e7bc1a5 | ||
|
|
69433abc7b | ||
|
|
e75190eef0 | ||
|
|
e8dd77890f | ||
|
|
92a17be2f3 | ||
|
|
a1c718932a | ||
|
|
c6ada98ca1 | ||
|
|
8f1c5d6943 | ||
|
|
4aea688693 | ||
|
|
3056921ba6 | ||
|
|
ca2ff12b03 | ||
|
|
4eeb98d9cd | ||
|
|
6eafd85b9e | ||
|
|
83d6a6419e | ||
|
|
1a7e393710 | ||
|
|
e1572a6629 | ||
|
|
b67c0f811b | ||
|
|
f58c1d4591 | ||
|
|
c21bff226c | ||
|
|
b793c7dec8 | ||
|
|
69a0866fc7 | ||
|
|
ecf39fe624 | ||
|
|
26f3b0bb04 | ||
|
|
f0235d5294 | ||
|
|
53b6a0203f | ||
|
|
cf9ccaa7b9 | ||
|
|
43fe31a4ec | ||
|
|
88709c15a5 | ||
|
|
960de20658 | ||
|
|
7a74f70308 | ||
|
|
b40469aaae | ||
|
|
d652e575f7 | ||
|
|
fd5d3da4b5 | ||
|
|
fb9d31e2ec | ||
|
|
9b5e3c47f5 | ||
|
|
864a5bb797 | ||
|
|
e5d0602e56 | ||
|
|
8ca391de56 | ||
|
|
57dd8b14fb | ||
|
|
d09d55d77b | ||
|
|
07b501742f | ||
|
|
748f7c5913 | ||
|
|
5954d54e44 | ||
|
|
4ede914452 | ||
|
|
00527271b6 | ||
|
|
308a16f4b4 | ||
|
|
302a673515 | ||
|
|
49b69db0bf | ||
|
|
8a0b05079a | ||
|
|
eaab48607d | ||
|
|
309599f43f |
@@ -8,6 +8,8 @@ import com.xboe.module.boecase.service.ICaseAiChatService;
|
||||
import com.xboe.module.boecase.service.ICaseAiPermissionService;
|
||||
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||
import com.xboe.module.excel.ExportsExcelSenderUtil;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.http.MediaType;
|
||||
@@ -15,7 +17,12 @@ import org.springframework.web.bind.annotation.*;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -73,6 +80,44 @@ public class CaseAiChatApi extends ApiBaseController {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出会话记录为Excel
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param response HTTP响应
|
||||
*/
|
||||
@GetMapping("/export-conversations")
|
||||
public void downloadConversationExcel(@RequestParam String startTime,
|
||||
@RequestParam String endTime,
|
||||
HttpServletResponse response) {
|
||||
try {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
||||
LocalDateTime start = LocalDateTime.parse(startTime, formatter);
|
||||
LocalDateTime end = LocalDateTime.parse(endTime, formatter);
|
||||
|
||||
// TODO: 这里需要修改为实际返回数据的方法
|
||||
caseAiChatService.downloadConversationExcel(start, end);
|
||||
|
||||
response.setContentType("application/vnd.ms-excel");
|
||||
response.setHeader("Content-Disposition", "attachment; filename=conversations.xls");
|
||||
|
||||
// 示例数据,实际应该从Service获取
|
||||
LinkedHashMap<String, String> headers = new LinkedHashMap<>();
|
||||
headers.put("会话ID", "conversationId");
|
||||
headers.put("会话名称", "conversationName");
|
||||
headers.put("用户", "user");
|
||||
headers.put("开始时间", "startTime");
|
||||
headers.put("会话时长", "duration");
|
||||
|
||||
List<ConversationExcelVo> dataList = new ArrayList<>();
|
||||
// 这里应该填充实际数据
|
||||
|
||||
ExportsExcelSenderUtil.export(headers, dataList, response.getOutputStream(), "yyyy-MM-dd HH:mm:ss");
|
||||
} catch (Exception e) {
|
||||
log.error("导出会话记录为Excel异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断当前登录用户是否显示"案例专家"功能入口
|
||||
* @return 是否显示功能入口
|
||||
@@ -123,4 +168,16 @@ public class CaseAiChatApi extends ApiBaseController {
|
||||
}
|
||||
return error("创建失败");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 用于Excel导出的VO类
|
||||
*/
|
||||
@Data
|
||||
static class ConversationExcelVo {
|
||||
private String conversationId;
|
||||
private String conversationName;
|
||||
private String user;
|
||||
private String startTime;
|
||||
private String duration;
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ public class CaseAiDocumentAsyncHandler {
|
||||
caseKnowledgeService.uploadCaseDocument(cases);
|
||||
break;
|
||||
}
|
||||
log.info("处理案例成功,caseId: {}, 操作类型: {}", cases.getId(), optTypeEnum.getDesc());
|
||||
// log.info("处理案例成功,caseId: {}, 操作类型: {}", cases.getId(), optTypeEnum.getDesc());
|
||||
} catch (Exception e) {
|
||||
log.error("处理案例失败,caseId: {}, 操作类型: {}", cases.getId(), optTypeEnum.getDesc(), e);
|
||||
}
|
||||
|
||||
@@ -54,28 +54,27 @@ public class AiChatConversationData {
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 消息时间戳
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 消息时间戳
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
|
||||
private LocalDateTime timestamp;
|
||||
|
||||
/**
|
||||
* 聊天时长(秒)
|
||||
*/
|
||||
private Integer durationSeconds;
|
||||
|
||||
// ================== 构造函数 ==================
|
||||
|
||||
public AiChatConversationData() {
|
||||
this.timestamp = LocalDateTime.now();
|
||||
}
|
||||
|
||||
public AiChatConversationData(String conversationId, String query, String answer,
|
||||
List<CaseReferVo> caseRefers, List<String> suggestions,
|
||||
String userId) {
|
||||
this.conversationId = conversationId;
|
||||
this.query = query;
|
||||
this.answer = new StringBuilder(answer != null ? answer : "");
|
||||
this.caseRefers = caseRefers != null ? caseRefers : new ArrayList<>();
|
||||
this.suggestions = suggestions != null ? suggestions : new ArrayList<>();
|
||||
this.userId = userId;
|
||||
this.timestamp = LocalDateTime.now();
|
||||
this.startTime = LocalDateTime.now();
|
||||
}
|
||||
|
||||
// ================== 便捷方法 ==================
|
||||
|
||||
@@ -48,6 +48,11 @@ public class CaseAiProperties {
|
||||
*/
|
||||
private String defaultUploadUser;
|
||||
|
||||
/**
|
||||
* 案例详情页面地址
|
||||
*/
|
||||
private String caseDetailUrlBase;
|
||||
|
||||
/**
|
||||
* 文件上传是否使用回调接口
|
||||
*/
|
||||
@@ -72,4 +77,14 @@ public class CaseAiProperties {
|
||||
* AI处理失败告警邮件收件人列表
|
||||
*/
|
||||
private List<String> alertEmailRecipients;
|
||||
|
||||
/**
|
||||
* 是否发送AI对话记录到邮箱
|
||||
*/
|
||||
private boolean aiChatDataSendEmail;
|
||||
|
||||
/**
|
||||
* AI对话记录保存根路径
|
||||
*/
|
||||
private String aiChatRootPath;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ 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.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -35,4 +36,11 @@ public interface ICaseAiChatService {
|
||||
* @return 消息记录列表
|
||||
*/
|
||||
List<CaseAiMessageVo> getConversationMessages(String conversationId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 导出会话记录为Excel
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
*/
|
||||
void downloadConversationExcel(LocalDateTime startTime, LocalDateTime endTime);
|
||||
}
|
||||
@@ -12,20 +12,17 @@ public interface IElasticSearchIndexService {
|
||||
|
||||
/**
|
||||
* 查看索引是否存在
|
||||
* @param indexName
|
||||
* @return
|
||||
*/
|
||||
boolean checkIndexExists();
|
||||
|
||||
/**
|
||||
* 创建索引
|
||||
* @param indexName
|
||||
*/
|
||||
boolean createIndex();
|
||||
|
||||
/**
|
||||
* 删除索引
|
||||
* @param indexName
|
||||
* @return
|
||||
*/
|
||||
boolean deleteIndex();
|
||||
|
||||
@@ -3,6 +3,7 @@ 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.core.orm.FieldFilters;
|
||||
import com.xboe.enums.CaseAiChatStatusEnum;
|
||||
import com.xboe.module.boecase.dao.CaseAiConversationsDao;
|
||||
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
|
||||
@@ -18,8 +19,10 @@ import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||
import com.xboe.module.boecase.vo.CaseReferVo;
|
||||
import com.xboe.module.boecase.entity.AiChatConversationData;
|
||||
import com.xboe.module.boecase.vo.ConversationExcelVo;
|
||||
import com.xboe.system.organization.vo.OrgSimpleVo;
|
||||
import com.xboe.system.user.service.IUserService;
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.*;
|
||||
import okhttp3.sse.EventSource;
|
||||
@@ -32,6 +35,11 @@ import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.poi.ss.usermodel.Row;
|
||||
import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
@@ -53,8 +61,13 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
@@ -93,8 +106,21 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
@Override
|
||||
@Transactional
|
||||
public SseEmitter chat(CaseAiChatDto caseAiChatDto, CurrentUser currentUser) {
|
||||
// 创建SSE响应器
|
||||
SseEmitter sseEmitter = new SseEmitter();
|
||||
// 1. 获取conversationId
|
||||
String conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
|
||||
String conversationId;
|
||||
try {
|
||||
conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
|
||||
} catch (Exception e) {
|
||||
log.error("获取会话ID失败", e);
|
||||
errMessage(sseEmitter, "服务繁忙,请稍后再试。");
|
||||
sseEmitter.complete();
|
||||
return sseEmitter;
|
||||
}
|
||||
|
||||
// 2. 查询历史
|
||||
List<CaseAiMessageVo> historyMessages = elasticSearchIndexService.queryData(conversationId);
|
||||
|
||||
// 3. 构建请求参数
|
||||
String userId = currentUser.getCode();
|
||||
@@ -107,11 +133,33 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
chatParam.put("query", caseAiChatDto.getQuery());
|
||||
chatParam.put("conversationId", conversationId);
|
||||
chatParam.put("enableThinking", Objects.equals(caseAiChatDto.getEnableThinking(), 1));
|
||||
if (historyMessages != null && !historyMessages.isEmpty()) {
|
||||
// 最多10条历史,从后往前
|
||||
JSONArray historyList = new JSONArray();
|
||||
int size = historyMessages.size();
|
||||
int startIndex = Math.max(0, size - 10);
|
||||
for (int i = startIndex; i < size; i++) {
|
||||
JSONObject conversationDetail = new JSONObject();
|
||||
CaseAiMessageVo message = historyMessages.get(i);
|
||||
conversationDetail.put("query", message.getQuery());
|
||||
conversationDetail.put("content", message.getAnswer());
|
||||
historyList.add(conversationDetail);
|
||||
}
|
||||
chatParam.put("historyList", historyList);
|
||||
}
|
||||
String chatParamStr = chatParam.toJSONString();
|
||||
log.info("案例问答接口请求参数: [{}]", chatParamStr);
|
||||
|
||||
// 4. 设置请求头
|
||||
String accessToken = aiAccessTokenService.getAccessToken();
|
||||
String accessToken;
|
||||
try {
|
||||
accessToken = aiAccessTokenService.getAccessToken();
|
||||
} catch (Exception e) {
|
||||
log.error("获取access_token失败", e);
|
||||
errMessage(sseEmitter, "服务繁忙,请稍后再试。");
|
||||
sseEmitter.complete();
|
||||
return sseEmitter;
|
||||
}
|
||||
String apiCode = caseAiProperties.getChatApiCode();
|
||||
Request.Builder builder = new Request.Builder();
|
||||
builder.url(caseAiProperties.getBaseUrl() + "/apigateway/chat/knowledge/v1/chat/completions");
|
||||
@@ -120,9 +168,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
RequestBody bodyRequestBody = RequestBody.create(chatParamStr, MediaType.parse("application/json"));
|
||||
builder.post(bodyRequestBody);
|
||||
Request request = builder.build();
|
||||
|
||||
// 5. 创建SSE响应器
|
||||
SseEmitter sseEmitter = new SseEmitter();
|
||||
|
||||
|
||||
// 6. 用于收集对话数据的容器
|
||||
AiChatConversationData conversationData = new AiChatConversationData();
|
||||
@@ -158,30 +204,28 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
if (status != null) {
|
||||
CaseAiChatStatusEnum statusEnum = CaseAiChatStatusEnum.getByCode(status);
|
||||
switch (statusEnum) {
|
||||
case REFERS: // 返回引用文件
|
||||
// 处理文件引用并构建返给前端的数据
|
||||
JSONObject modifiedData = handleFileReferAndBuildResponse(responseData, conversationData);
|
||||
if (modifiedData != null) {
|
||||
// 发送修改后的数据给前端
|
||||
sseEmitter.send(modifiedData.toJSONString());
|
||||
return; // 早期返回,不发送原始数据
|
||||
}
|
||||
break;
|
||||
case CHAT: // 流式对话中
|
||||
String content = responseData.getString("content");
|
||||
if (content != null) {
|
||||
conversationData.appendAnswer(content);
|
||||
}
|
||||
break;
|
||||
case SUGGESTIONS: // 返回建议
|
||||
handleSuggestions(responseData, conversationData);
|
||||
break;
|
||||
case CHAT_COMPLETED:
|
||||
case API_COMPLETED: // 接口交互完成
|
||||
default:
|
||||
// 不做特殊处理
|
||||
break;
|
||||
if (statusEnum == CaseAiChatStatusEnum.REFERS) { // 返回引用文件
|
||||
// 处理文件引用并构建返给前端的数据
|
||||
JSONObject modifiedData = handleFileReferAndBuildResponse(responseData, conversationData);
|
||||
if (modifiedData != null) {
|
||||
// 发送修改后的数据给前端
|
||||
sseEmitter.send(modifiedData.toJSONString());
|
||||
return; // 早期返回,不发送原始数据
|
||||
}
|
||||
} else if (statusEnum == CaseAiChatStatusEnum.CHAT) { // 流式对话中
|
||||
String content = responseData.getString("content");
|
||||
if (content != null) {
|
||||
conversationData.appendAnswer(content);
|
||||
}
|
||||
} else if (statusEnum == CaseAiChatStatusEnum.SUGGESTIONS) { // 返回建议
|
||||
handleSuggestions(responseData, conversationData);
|
||||
} else if (statusEnum == CaseAiChatStatusEnum.CHAT_COMPLETED || statusEnum == CaseAiChatStatusEnum.API_COMPLETED) { // 接口交互完成
|
||||
// 不做特殊处理
|
||||
} else {
|
||||
// 异常问题,取message内容
|
||||
String message = jsonData.getString("message");
|
||||
errMessage(sseEmitter, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
sseEmitter.send(responseData.toJSONString());
|
||||
@@ -207,7 +251,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
// 如果是 content-type 错误,尝试作为普通 HTTP 请求处理
|
||||
if (e instanceof IllegalStateException && e.getMessage() != null && e.getMessage().contains("Invalid content-type")) {
|
||||
log.warn("服务器返回的 Content-Type 不是 text/event-stream,尝试作为普通 HTTP 请求处理");
|
||||
CaseAiChatServiceImpl.this.handleAsRegularHttpRequest(request, sseEmitter, conversationData);
|
||||
handleAsRegularHttpRequest(request, sseEmitter, conversationData);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -314,7 +358,117 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
}
|
||||
return elasticSearchIndexService.queryData(conversationId);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void downloadConversationExcel(LocalDateTime startTime, LocalDateTime endTime) {
|
||||
// 1. 根据startTime和endTime,查询在这个时间区间内的CaseAiConversations数据
|
||||
List<CaseAiConversations> conversations = caseAiConversationsDao.getGenericDao().findList(
|
||||
CaseAiConversations.class,
|
||||
FieldFilters.ge("sysCreateTime", startTime),
|
||||
FieldFilters.le("sysCreateTime", endTime)
|
||||
);
|
||||
|
||||
// 准备Excel数据
|
||||
List<ConversationExcelVo> excelDataList = new ArrayList<>();
|
||||
|
||||
// 2. 遍历这组数据,根据aiConversationId从es中查询数据(可调用getConversationMessages()方法)
|
||||
for (CaseAiConversations conversation : conversations) {
|
||||
String aiConversationId = conversation.getAiConversationId();
|
||||
String conversationName = conversation.getConversationName();
|
||||
String conversationUser = conversation.getConversationUser();
|
||||
|
||||
List<CaseAiMessageVo> messages = getConversationMessages(aiConversationId);
|
||||
|
||||
// 计算会话时长
|
||||
long duration = 0; // 默认为0,如果需要精确计算,需要从消息中提取时间信息
|
||||
|
||||
// 3. 写入Excel,包括每个会话的用户,会话标题,会话内的问答记录,每次对话时长等
|
||||
ConversationExcelVo excelData = new ConversationExcelVo();
|
||||
excelData.setConversationId(aiConversationId);
|
||||
excelData.setConversationName(conversationName);
|
||||
excelData.setUser(conversationUser);
|
||||
excelData.setMessages(messages);
|
||||
|
||||
excelDataList.add(excelData);
|
||||
}
|
||||
|
||||
// 写入Excel文件
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("AI会话数据");
|
||||
// 标题行
|
||||
Row headerRow = sheet.createRow(0);
|
||||
headerRow.createCell(0).setCellValue("会话ID");
|
||||
headerRow.createCell(1).setCellValue("会话名称");
|
||||
headerRow.createCell(2).setCellValue("用户");
|
||||
headerRow.createCell(3).setCellValue("提问");
|
||||
headerRow.createCell(4).setCellValue("回答");
|
||||
headerRow.createCell(5).setCellValue("开始时间");
|
||||
headerRow.createCell(6).setCellValue("问答时长(秒)");
|
||||
|
||||
// 内容行
|
||||
if (!excelDataList.isEmpty()) {
|
||||
int rowNum = 1; // 从第二行开始写入数据
|
||||
for (ConversationExcelVo excelData : excelDataList) {
|
||||
List<CaseAiMessageVo> messages = excelData.getMessages();
|
||||
|
||||
if (messages != null && !messages.isEmpty()) {
|
||||
// 记录起始行号,用于后续合并单元格
|
||||
int startRow = rowNum;
|
||||
|
||||
// 遍历每个消息
|
||||
for (CaseAiMessageVo message : messages) {
|
||||
Row row = sheet.createRow(rowNum++);
|
||||
// 填充每行数据
|
||||
row.createCell(0).setCellValue(excelData.getConversationId());
|
||||
row.createCell(1).setCellValue(excelData.getConversationName());
|
||||
row.createCell(2).setCellValue(excelData.getUser());
|
||||
row.createCell(3).setCellValue(message.getQuery() != null ? message.getQuery() : "");
|
||||
row.createCell(4).setCellValue(message.getAnswer() != null ? message.getAnswer() : "");
|
||||
row.createCell(5).setCellValue(""); // 开始时间字段暂留空
|
||||
row.createCell(6).setCellValue(message.getDurationSeconds() != null ? message.getDurationSeconds() : 0);
|
||||
}
|
||||
|
||||
// 合并单元格(会话ID、会话名称、用户三列)
|
||||
// 参数说明:起始行号,结束行号,起始列号,结束列号
|
||||
if (rowNum > startRow + 1) { // 只有当有多行时才合并
|
||||
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 0, 0));
|
||||
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 1, 1));
|
||||
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 2, 2));
|
||||
}
|
||||
} else {
|
||||
// 如果没有消息,则仍然创建一行显示基本信息
|
||||
Row row = sheet.createRow(rowNum++);
|
||||
row.createCell(0).setCellValue(excelData.getConversationId());
|
||||
row.createCell(1).setCellValue(excelData.getConversationName());
|
||||
row.createCell(2).setCellValue(excelData.getUser());
|
||||
}
|
||||
}
|
||||
}
|
||||
// 3. 创建Excel文件并保存
|
||||
if (caseAiProperties.isAiChatDataSendEmail()) {
|
||||
// TODO 发送邮件附件
|
||||
} else {
|
||||
// 保存文件
|
||||
String dirPath = caseAiProperties.getAiChatRootPath() + File.separator + startTime.format(DateTimeFormatter.ofPattern("yyyyMM"));
|
||||
Path dir = Paths.get(dirPath);
|
||||
if (!Files.exists(dir)) {
|
||||
try {
|
||||
Files.createDirectories(dir);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
String fileName = "AI会话数据-" + startTime.format(DateTimeFormatter.ofPattern("yyyyMMdd")) + "-" + System.currentTimeMillis() + ".xlsx";
|
||||
Path filePath = dir.resolve(fileName);
|
||||
try (OutputStream out = Files.newOutputStream(filePath)) {
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
} catch (IOException e) {
|
||||
log.error("保存文件错误", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 从 ES 数据中解析消息对象
|
||||
* @param sourceMap ES数据
|
||||
@@ -543,6 +697,12 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
log.info("作为普通 HTTP 请求处理成功,将响应原封不动推送给前端");
|
||||
|
||||
// 将响应内容原封不动地推送到 SseEmitter
|
||||
JSONObject responseData = JSONObject.parseObject(responseBody);
|
||||
if (responseBody.contains("message")) {
|
||||
errMessage(sseEmitter, responseData.getString("message"));
|
||||
sseEmitter.complete();
|
||||
return;
|
||||
}
|
||||
sseEmitter.send(responseBody);
|
||||
sseEmitter.complete();
|
||||
} else {
|
||||
@@ -554,9 +714,16 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
sseEmitter.completeWithError(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 对话数据容器
|
||||
*/
|
||||
// ConversationData 已移动到独立的Entity类:AiChatConversationData
|
||||
|
||||
private void errMessage(SseEmitter sseEmitter, String message) {
|
||||
JSONObject jsonData = new JSONObject();
|
||||
jsonData.put("status", 1);
|
||||
jsonData.put("content", message);
|
||||
try {
|
||||
sseEmitter.send(jsonData.toJSONString());
|
||||
} catch (IOException e) {
|
||||
log.error("发送错误信息异常", e);
|
||||
sseEmitter.completeWithError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,15 @@ import com.xboe.enums.CaseDocumentLogRunStatusEnum;
|
||||
import com.xboe.module.assistance.service.ISmtpEmailService;
|
||||
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
|
||||
import com.xboe.module.boecase.dao.CasesDao;
|
||||
import com.xboe.module.boecase.dao.CasesMajorTypeDao;
|
||||
import com.xboe.module.boecase.entity.CaseDocumentLog;
|
||||
import com.xboe.module.boecase.entity.Cases;
|
||||
import com.xboe.module.boecase.entity.CasesMajorType;
|
||||
import com.xboe.module.boecase.properties.CaseAiProperties;
|
||||
import com.xboe.module.boecase.service.IAiAccessTokenService;
|
||||
import com.xboe.module.boecase.service.ICaseKnowledgeService;
|
||||
import com.xboe.module.dict.entity.DictItem;
|
||||
import com.xboe.module.dict.service.ISysDictionaryService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.HttpEntity;
|
||||
@@ -44,6 +48,8 @@ import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 案例-知识库Service实现类
|
||||
@@ -63,9 +69,15 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
@Resource
|
||||
private CaseDocumentLogDao caseDocumentLogDao;
|
||||
|
||||
@Resource
|
||||
private CasesMajorTypeDao casesMajorTypeDao;
|
||||
|
||||
@Resource
|
||||
private XFileUploader fileUploader;
|
||||
|
||||
@Autowired
|
||||
private ISysDictionaryService sysDictionaryService;
|
||||
|
||||
@Autowired
|
||||
private IAiAccessTokenService aiAccessTokenService;
|
||||
|
||||
@@ -125,10 +137,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
}
|
||||
|
||||
// 4. 构建上传参数
|
||||
String fileName = cases.getFileName();
|
||||
if (StringUtil.isBlank(fileName)) {
|
||||
fileName = file.getName();
|
||||
}
|
||||
String fileName = file.getName();
|
||||
|
||||
String fileType = getFileType(fileName);
|
||||
|
||||
@@ -145,6 +154,59 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
builder.addTextBody("fileType", fileType, ContentType.TEXT_PLAIN);
|
||||
requestBody.put("fileType", fileType);
|
||||
builder.addTextBody("parseType", "AUTO", ContentType.TEXT_PLAIN);
|
||||
|
||||
String url = caseAiProperties.getCaseDetailUrlBase() + caseId;
|
||||
requestBody.put("url", url);
|
||||
String downloadUrl = fileUploader.getHttpPath() + cases.getFilePath();
|
||||
requestBody.put("downloadUrl", downloadUrl);
|
||||
builder.addTextBody("url", url, ContentType.TEXT_PLAIN);
|
||||
builder.addTextBody("downloadUrl", downloadUrl, ContentType.TEXT_PLAIN);
|
||||
// metadata
|
||||
JSONObject fileMetaData = new JSONObject();
|
||||
fileMetaData.put("标题", cases.getTitle());
|
||||
fileMetaData.put("作者", cases.getAuthorName());
|
||||
fileMetaData.put("年份", String.valueOf(cases.getSysCreateTime().getYear()));
|
||||
fileMetaData.put("摘要", cases.getSummary());
|
||||
// 组织领域:orgDomainParent
|
||||
String orgDomainParent = cases.getOrgDomainParent();
|
||||
List<DictItem> orgDomainParentItems = sysDictionaryService.findByKey("org_domain");
|
||||
Optional<DictItem> orgDomainParentItem = orgDomainParentItems.stream()
|
||||
.filter(item -> StringUtils.equals(orgDomainParent, item.getCode()))
|
||||
.findFirst();
|
||||
if (orgDomainParentItem.isPresent()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(orgDomainParentItem.get().getName());
|
||||
if (StringUtils.isNotBlank(cases.getOrgDomainParent2())) {
|
||||
Optional<DictItem> orgDomainParent2Item = orgDomainParentItems.stream()
|
||||
.filter(item -> StringUtils.equals(cases.getOrgDomainParent2(), item.getCode()))
|
||||
.findFirst();
|
||||
orgDomainParent2Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
|
||||
if (StringUtils.isNotBlank(cases.getOrgDomainParent3())) {
|
||||
Optional<DictItem> orgDomainParent3Item = orgDomainParentItems.stream()
|
||||
.filter(item -> StringUtils.equals(cases.getOrgDomainParent3(), item.getCode()))
|
||||
.findFirst();
|
||||
orgDomainParent3Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
|
||||
}
|
||||
}
|
||||
fileMetaData.put("组织领域", sb.toString());
|
||||
}
|
||||
// 分类:majorIds
|
||||
List<CasesMajorType> cmtList = casesMajorTypeDao.findList(FieldFilters.eq("caseId", cases.getId()));
|
||||
if (cmtList != null && !cmtList.isEmpty()) {
|
||||
List<String> majorIds = cmtList.stream().map(CasesMajorType::getMajorId).collect(Collectors.toList());
|
||||
|
||||
List<DictItem> majorItems = sysDictionaryService.findByKey("major_type");
|
||||
if (majorItems != null && !majorItems.isEmpty()) {
|
||||
List<String> majorNames = majorItems.stream()
|
||||
.filter(item -> majorIds.contains(item.getCode()))
|
||||
.map(DictItem::getName)
|
||||
.collect(Collectors.toList());
|
||||
fileMetaData.put("组织领域", String.join(", ", majorNames));
|
||||
}
|
||||
}
|
||||
|
||||
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), ContentType.TEXT_PLAIN);
|
||||
requestBody.put("fileMetaData", fileMetaData);
|
||||
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
||||
if (caseAiProperties.isFileUploadUseCallback()) {
|
||||
builder.addTextBody("callbackUrl", caseAiProperties.getFileUploadCallbackUrl(), ContentType.TEXT_PLAIN);
|
||||
@@ -183,12 +245,9 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
String taskId = data.getString("taskId");
|
||||
|
||||
// 保存成功的CaseDocumentLog记录
|
||||
// saveCaseDocumentLog(caseId, cases.getTitle(), CaseDocumentLogOptTypeEnum.CREATE.getCode(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME,
|
||||
// requestBody.toJSONString(), responseBody,
|
||||
// CaseDocumentLogRunStatusEnum.RUNNING.getCode(), null, null, taskId);
|
||||
saveCaseDocumentLog(caseId, cases.getTitle(), CaseDocumentLogOptTypeEnum.CREATE.getCode(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME,
|
||||
requestBody.toJSONString(), responseBody,
|
||||
CaseDocumentLogRunStatusEnum.COMPLETED.getCode(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode(), CaseDocumentLogCaseStatusEnum.FAILED.getCode(), taskId);
|
||||
CaseDocumentLogRunStatusEnum.RUNNING.getCode(), null, null, taskId);
|
||||
|
||||
log.info("上传案例文档成功,等待文档状态变更. caseId: {}, taskId: {}, 尝试次数: {}", caseId, taskId, attempt);
|
||||
return true;
|
||||
@@ -321,9 +380,8 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
// 接口调用成功,检查业务处理结果
|
||||
JSONObject data = result.getJSONObject("data");
|
||||
Boolean deleteSuccess = data.getBoolean(taskId);
|
||||
// int caseStatus = (deleteSuccess != null && deleteSuccess) ?
|
||||
// CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
|
||||
int caseStatus = CaseDocumentLogCaseStatusEnum.FAILED.getCode();
|
||||
int caseStatus = (deleteSuccess != null && deleteSuccess) ?
|
||||
CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
|
||||
|
||||
saveCaseDocumentLog(caseId, cases.getTitle(), CaseDocumentLogOptTypeEnum.DELETE.getCode(), CaseAiConstants.CASE_DOC_DELETE_INTERFACE_NAME,
|
||||
params, responseBody,
|
||||
@@ -416,10 +474,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
}
|
||||
|
||||
// 4. 构建上传参数
|
||||
String fileName = cases.getFileName();
|
||||
if (StringUtil.isBlank(fileName)) {
|
||||
fileName = file.getName();
|
||||
}
|
||||
String fileName = file.getName();
|
||||
|
||||
String fileType = getFileType(fileName);
|
||||
|
||||
@@ -436,6 +491,59 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
builder.addTextBody("fileType", fileType, ContentType.TEXT_PLAIN);
|
||||
requestBody.put("fileType", fileType);
|
||||
builder.addTextBody("parseType", "AUTO", ContentType.TEXT_PLAIN);
|
||||
|
||||
String url = caseAiProperties.getCaseDetailUrlBase() + caseId;
|
||||
requestBody.put("url", url);
|
||||
String downloadUrl = fileUploader.getHttpPath() + cases.getFilePath();
|
||||
requestBody.put("downloadUrl", downloadUrl);
|
||||
builder.addTextBody("url", url, ContentType.TEXT_PLAIN);
|
||||
builder.addTextBody("downloadUrl", downloadUrl, ContentType.TEXT_PLAIN);
|
||||
// metadata
|
||||
JSONObject fileMetaData = new JSONObject();
|
||||
fileMetaData.put("标题", cases.getTitle());
|
||||
fileMetaData.put("作者", cases.getAuthorName());
|
||||
fileMetaData.put("年份", String.valueOf(cases.getSysCreateTime().getYear()));
|
||||
fileMetaData.put("摘要", cases.getSummary());
|
||||
// 组织领域:orgDomainParent
|
||||
String orgDomainParent = cases.getOrgDomainParent();
|
||||
List<DictItem> orgDomainParentItems = sysDictionaryService.findByKey("org_domain");
|
||||
Optional<DictItem> orgDomainParentItem = orgDomainParentItems.stream()
|
||||
.filter(item -> StringUtils.equals(orgDomainParent, item.getCode()))
|
||||
.findFirst();
|
||||
if (orgDomainParentItem.isPresent()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(orgDomainParentItem.get().getName());
|
||||
if (StringUtils.isNotBlank(cases.getOrgDomainParent2())) {
|
||||
Optional<DictItem> orgDomainParent2Item = orgDomainParentItems.stream()
|
||||
.filter(item -> StringUtils.equals(cases.getOrgDomainParent2(), item.getCode()))
|
||||
.findFirst();
|
||||
orgDomainParent2Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
|
||||
if (StringUtils.isNotBlank(cases.getOrgDomainParent3())) {
|
||||
Optional<DictItem> orgDomainParent3Item = orgDomainParentItems.stream()
|
||||
.filter(item -> StringUtils.equals(cases.getOrgDomainParent3(), item.getCode()))
|
||||
.findFirst();
|
||||
orgDomainParent3Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
|
||||
}
|
||||
}
|
||||
fileMetaData.put("组织领域", sb.toString());
|
||||
}
|
||||
// 分类:majorIds
|
||||
List<CasesMajorType> cmtList = casesMajorTypeDao.findList(FieldFilters.eq("caseId", cases.getId()));
|
||||
if (cmtList != null && !cmtList.isEmpty()) {
|
||||
List<String> majorIds = cmtList.stream().map(CasesMajorType::getMajorId).collect(Collectors.toList());
|
||||
|
||||
List<DictItem> majorItems = sysDictionaryService.findByKey("major_type");
|
||||
if (majorItems != null && !majorItems.isEmpty()) {
|
||||
List<String> majorNames = majorItems.stream()
|
||||
.filter(item -> majorIds.contains(item.getCode()))
|
||||
.map(DictItem::getName)
|
||||
.collect(Collectors.toList());
|
||||
fileMetaData.put("组织领域", String.join(", ", majorNames));
|
||||
}
|
||||
}
|
||||
|
||||
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), ContentType.TEXT_PLAIN);
|
||||
requestBody.put("fileMetaData", fileMetaData);
|
||||
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
||||
if (caseAiProperties.isFileUploadUseCallback()) {
|
||||
builder.addTextBody("callbackUrl", caseAiProperties.getFileUploadCallbackUrl(), ContentType.TEXT_PLAIN);
|
||||
@@ -602,22 +710,21 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
// 接口调用成功,检查业务处理结果
|
||||
JSONObject data = result.getJSONObject("data");
|
||||
Boolean deleteSuccess = data.getBoolean(deleteTaskId);
|
||||
// int caseStatus = (deleteSuccess != null && deleteSuccess) ?
|
||||
// CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
|
||||
int caseStatus = CaseDocumentLogCaseStatusEnum.FAILED.getCode();
|
||||
int caseStatus = (deleteSuccess != null && deleteSuccess) ?
|
||||
CaseDocumentLogCaseStatusEnum.SUCCESS.getCode() : CaseDocumentLogCaseStatusEnum.FAILED.getCode();
|
||||
|
||||
saveCaseDocumentLog(caseId, cases.getTitle(), CaseDocumentLogOptTypeEnum.UPDATE.getCode(), CaseAiConstants.CASE_DOC_DELETE_INTERFACE_NAME,
|
||||
params, responseBody,
|
||||
CaseDocumentLogRunStatusEnum.COMPLETED.getCode(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode(), caseStatus, null);
|
||||
|
||||
// if (deleteSuccess != null && deleteSuccess) {
|
||||
// log.info("删除案例文档成功,caseId: {}, taskId: {}, 尝试次数: {}", caseId, deleteTaskId, attempt);
|
||||
// break; // 删除成功,跳出重试循环
|
||||
// } else {
|
||||
// // 业务处理失败,不重试
|
||||
// log.error("删除案例文档业务处理失败,不重试,caseId: {}, taskId: {}", caseId, deleteTaskId);
|
||||
if (deleteSuccess != null && deleteSuccess) {
|
||||
log.info("删除案例文档成功,caseId: {}, taskId: {}, 尝试次数: {}", caseId, deleteTaskId, attempt);
|
||||
break; // 删除成功,跳出重试循环
|
||||
} else {
|
||||
// 业务处理失败,不重试
|
||||
log.error("删除案例文档业务处理失败,不重试,caseId: {}, taskId: {}", caseId, deleteTaskId);
|
||||
return false;
|
||||
// }
|
||||
}
|
||||
} else {
|
||||
// 业务处理失败,不重试
|
||||
log.error("删除案例文档业务处理失败,不重试,response: {}", responseBody);
|
||||
@@ -681,10 +788,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
}
|
||||
|
||||
// 4. 构建上传参数
|
||||
String fileName = cases.getFileName();
|
||||
if (StringUtil.isBlank(fileName)) {
|
||||
fileName = file.getName();
|
||||
}
|
||||
String fileName = file.getName();
|
||||
|
||||
String fileType = getFileType(fileName);
|
||||
|
||||
@@ -701,6 +805,59 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
builder.addTextBody("fileType", fileType, ContentType.TEXT_PLAIN);
|
||||
requestBody.put("fileType", fileType);
|
||||
builder.addTextBody("parseType", "AUTO", ContentType.TEXT_PLAIN);
|
||||
|
||||
String url = caseAiProperties.getCaseDetailUrlBase() + caseId;
|
||||
requestBody.put("url", url);
|
||||
String downloadUrl = fileUploader.getHttpPath() + cases.getFilePath();
|
||||
requestBody.put("downloadUrl", downloadUrl);
|
||||
builder.addTextBody("url", url, ContentType.TEXT_PLAIN);
|
||||
builder.addTextBody("downloadUrl", downloadUrl, ContentType.TEXT_PLAIN);
|
||||
// metadata
|
||||
JSONObject fileMetaData = new JSONObject();
|
||||
fileMetaData.put("标题", cases.getTitle());
|
||||
fileMetaData.put("作者", cases.getAuthorName());
|
||||
fileMetaData.put("年份", String.valueOf(cases.getSysCreateTime().getYear()));
|
||||
fileMetaData.put("摘要", cases.getSummary());
|
||||
// 组织领域:orgDomainParent
|
||||
String orgDomainParent = cases.getOrgDomainParent();
|
||||
List<DictItem> orgDomainParentItems = sysDictionaryService.findByKey("org_domain");
|
||||
Optional<DictItem> orgDomainParentItem = orgDomainParentItems.stream()
|
||||
.filter(item -> StringUtils.equals(orgDomainParent, item.getCode()))
|
||||
.findFirst();
|
||||
if (orgDomainParentItem.isPresent()) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(orgDomainParentItem.get().getName());
|
||||
if (StringUtils.isNotBlank(cases.getOrgDomainParent2())) {
|
||||
Optional<DictItem> orgDomainParent2Item = orgDomainParentItems.stream()
|
||||
.filter(item -> StringUtils.equals(cases.getOrgDomainParent2(), item.getCode()))
|
||||
.findFirst();
|
||||
orgDomainParent2Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
|
||||
if (StringUtils.isNotBlank(cases.getOrgDomainParent3())) {
|
||||
Optional<DictItem> orgDomainParent3Item = orgDomainParentItems.stream()
|
||||
.filter(item -> StringUtils.equals(cases.getOrgDomainParent3(), item.getCode()))
|
||||
.findFirst();
|
||||
orgDomainParent3Item.ifPresent(dictItem -> sb.append(" - ").append(dictItem.getName()));
|
||||
}
|
||||
}
|
||||
fileMetaData.put("组织领域", sb.toString());
|
||||
}
|
||||
// 分类:majorIds
|
||||
List<CasesMajorType> cmtList = casesMajorTypeDao.findList(FieldFilters.eq("caseId", cases.getId()));
|
||||
if (cmtList != null && !cmtList.isEmpty()) {
|
||||
List<String> majorIds = cmtList.stream().map(CasesMajorType::getMajorId).collect(Collectors.toList());
|
||||
|
||||
List<DictItem> majorItems = sysDictionaryService.findByKey("major_type");
|
||||
if (majorItems != null && !majorItems.isEmpty()) {
|
||||
List<String> majorNames = majorItems.stream()
|
||||
.filter(item -> majorIds.contains(item.getCode()))
|
||||
.map(DictItem::getName)
|
||||
.collect(Collectors.toList());
|
||||
fileMetaData.put("组织领域", String.join(", ", majorNames));
|
||||
}
|
||||
}
|
||||
|
||||
builder.addTextBody("fileMetaData", fileMetaData.toJSONString(), ContentType.TEXT_PLAIN);
|
||||
requestBody.put("fileMetaData", fileMetaData);
|
||||
// 由于接口权限,目前采用不回调,而是通过批处理的方式,处理文件状态
|
||||
if (caseAiProperties.isFileUploadUseCallback()) {
|
||||
builder.addTextBody("callbackUrl", caseAiProperties.getFileUploadCallbackUrl(), ContentType.TEXT_PLAIN);
|
||||
@@ -867,7 +1024,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
|
||||
@Override
|
||||
public void batchCheckFileStatus() {
|
||||
log.info("开始批量检查文件状态");
|
||||
// log.info("开始批量检查文件状态");
|
||||
|
||||
// 1. 查询CaseDocumentLog表中前10条run_status等于0的数据,并按创建时间升序排序
|
||||
PageList<CaseDocumentLog> runningLogPage = caseDocumentLogDao.getGenericDao()
|
||||
@@ -877,11 +1034,11 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
|
||||
// 2. 如果没有符合条件的数据,完成
|
||||
if (runningLogs == null || runningLogs.isEmpty()) {
|
||||
log.info("没有需要检查状态的文档,批量检查完成");
|
||||
// log.info("没有需要检查状态的文档,批量检查完成");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("找到{}条需要检查状态的文档记录", runningLogs.size());
|
||||
// log.info("找到{}条需要检查状态的文档记录", runningLogs.size());
|
||||
|
||||
// 3. 把这些数据的taskId聚合成一个List<String>
|
||||
List<String> taskIds = runningLogs.stream()
|
||||
@@ -891,11 +1048,11 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
.collect(java.util.stream.Collectors.toList());
|
||||
|
||||
if (taskIds.isEmpty()) {
|
||||
log.error("所有运行中的记录都没有有效的taskId");
|
||||
// log.error("所有运行中的记录都没有有效的taskId");
|
||||
return;
|
||||
}
|
||||
|
||||
log.info("需要检查状态的taskId数量: {}", taskIds.size());
|
||||
// log.info("需要检查状态的taskId数量: {}", taskIds.size());
|
||||
|
||||
// 4. 获取access_token
|
||||
String accessToken = aiAccessTokenService.getAccessToken();
|
||||
@@ -935,7 +1092,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
log.error("批量检查文件状态异常", e);
|
||||
}
|
||||
|
||||
log.info("批量检查文件状态完成");
|
||||
// log.info("批量检查文件状态完成");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1202,7 +1359,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
caseLog.setOptStatus(CaseDocumentLogOptStatusEnum.SUCCESS.getCode());
|
||||
caseLog.setCaseStatus(CaseDocumentLogCaseStatusEnum.SUCCESS.getCode());
|
||||
needUpdate = true;
|
||||
log.info("文档向量化成功,更新状态,taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
|
||||
// log.info("文档向量化成功,更新状态,taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
|
||||
} else if ("failed".equals(fileStatus)) {
|
||||
// 状态为failed,run_status、opt_status变更为1,case_status变更为2
|
||||
caseLog.setRunStatus(CaseDocumentLogRunStatusEnum.COMPLETED.getCode());
|
||||
@@ -1210,20 +1367,20 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
caseLog.setCaseStatus(CaseDocumentLogCaseStatusEnum.FAILED.getCode());
|
||||
needUpdate = true;
|
||||
needToSendEmail = true;
|
||||
log.error("文档处理失败,需要发送邮件,更新状态,taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
|
||||
// log.error("文档处理失败,需要发送邮件,更新状态,taskId: {}, caseId: {}", caseLog.getTaskId(), caseLog.getCaseId());
|
||||
} else {
|
||||
// 其他状态(uploaded、texted、vectoring),不做数据变更
|
||||
log.info("文档状态为{},暂不更新数据库,taskId: {}", fileStatus, caseLog.getTaskId());
|
||||
// log.info("文档状态为{},暂不更新数据库,taskId: {}", fileStatus, caseLog.getTaskId());
|
||||
}
|
||||
|
||||
// 如果需要更新,执行update操作
|
||||
if (needUpdate) {
|
||||
caseLog.setSysUpdateTime(LocalDateTime.now());
|
||||
caseDocumentLogDao.save(caseLog);
|
||||
log.info("更新CaseDocumentLog成功,logId: {}, taskId: {}, fileStatus: {}",
|
||||
caseLog.getId(), caseLog.getTaskId(), fileStatus);
|
||||
} else {
|
||||
log.info("无需更新CaseDocumentLog,taskId: {}, fileStatus: {}", caseLog.getTaskId(), fileStatus);
|
||||
// log.info("更新CaseDocumentLog成功,logId: {}, taskId: {}, fileStatus: {}",
|
||||
// caseLog.getId(), caseLog.getTaskId(), fileStatus);
|
||||
// } else {
|
||||
// log.info("无需更新CaseDocumentLog,taskId: {}, fileStatus: {}", caseLog.getTaskId(), fileStatus);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新日志状态异常,taskId: {}, fileStatus: {}", caseLog.getTaskId(), fileStatus, e);
|
||||
@@ -1240,7 +1397,7 @@ public class CaseKnowledgeServiceImpl implements ICaseKnowledgeService {
|
||||
|
||||
// 使用配置的收件人列表
|
||||
List<String> recipients = caseAiProperties.getAlertEmailRecipients();
|
||||
log.info("使用配置的收件人列表:{}", recipients);
|
||||
// log.info("使用配置的收件人列表:{}", recipients);
|
||||
if (recipients != null && !recipients.isEmpty()) {
|
||||
try {
|
||||
String to = String.join(",", recipients);
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -134,7 +135,11 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
||||
esData.put("answer", conversationData.getAnswerAsString());
|
||||
esData.put("conversationId", conversationData.getConversationId());
|
||||
esData.put("userId", conversationData.getUserId());
|
||||
esData.put("timestamp", LocalDateTime.now().toString());
|
||||
// 持续时间
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
esData.put("startTime", conversationData.getStartTime().toString());
|
||||
esData.put("timestamp", now.toString());
|
||||
esData.put("durationSeconds", Duration.between(conversationData.getStartTime(), now).getSeconds());
|
||||
|
||||
// 构建 caseRefer 数据
|
||||
JSONArray caseReferArray = new JSONArray();
|
||||
@@ -206,35 +211,46 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
||||
CaseAiMessageVo messageVo = new CaseAiMessageVo();
|
||||
messageVo.setQuery((String) sourceMap.get("query"));
|
||||
messageVo.setAnswer((String) sourceMap.get("answer"));
|
||||
if (sourceMap.containsKey("startTime")) {
|
||||
String startTimeStr = (String) sourceMap.get("startTime");
|
||||
messageVo.setStartTime(LocalDateTime.parse(startTimeStr));
|
||||
}
|
||||
if (sourceMap.containsKey("durationSeconds")) {
|
||||
messageVo.setDurationSeconds((Long) sourceMap.get("durationSeconds"));
|
||||
}
|
||||
|
||||
// 解析 suggestions
|
||||
Object suggestionsObj = sourceMap.get("suggestions");
|
||||
if (suggestionsObj instanceof List) {
|
||||
messageVo.setSuggestions((List<String>) suggestionsObj);
|
||||
if (sourceMap.containsKey("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;
|
||||
if (sourceMap.containsKey("caseRefer")) {
|
||||
Object caseReferObj = sourceMap.get("caseRefer");
|
||||
if (caseReferObj instanceof List) {
|
||||
List<CaseReferVo> caseReferList = new ArrayList<>();
|
||||
List<Map<String, Object>> caseReferMaps = (List<Map<String, Object>>) caseReferObj;
|
||||
|
||||
for (Map<String, Object> caseReferMap : caseReferMaps) {
|
||||
CaseReferVo caseRefer = new CaseReferVo();
|
||||
caseRefer.setCaseId((String) caseReferMap.get("caseId"));
|
||||
caseRefer.setTitle((String) caseReferMap.get("title"));
|
||||
caseRefer.setAuthorName((String) caseReferMap.get("authorName"));
|
||||
caseRefer.setContent((String) caseReferMap.get("content"));
|
||||
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);
|
||||
// 解析 keywords
|
||||
Object keywordsObj = caseReferMap.get("keywords");
|
||||
if (keywordsObj instanceof List) {
|
||||
caseRefer.setKeywords((List<String>) keywordsObj);
|
||||
}
|
||||
|
||||
caseReferList.add(caseRefer);
|
||||
}
|
||||
|
||||
caseReferList.add(caseRefer);
|
||||
messageVo.setCaseRefer(caseReferList);
|
||||
}
|
||||
messageVo.setCaseRefer(caseReferList);
|
||||
}
|
||||
|
||||
return messageVo;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.xboe.module.boecase.task;
|
||||
|
||||
import com.xboe.module.boecase.service.ICaseAiChatService;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.YearMonth;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CaseAiChatDataTask {
|
||||
|
||||
@Autowired
|
||||
private ICaseAiChatService caseAiChatService;
|
||||
|
||||
|
||||
/**
|
||||
* 查询上月聊天数据并下载
|
||||
* cron: 0/10 * * * * ?
|
||||
*/
|
||||
@XxlJob("chatDataExcelDownloadJob")
|
||||
public void chatDataExcelDownload(String param) {
|
||||
LocalDateTime startTime;
|
||||
LocalDateTime endTime;
|
||||
|
||||
if (param != null && !param.isEmpty()) {
|
||||
// 解析参数,格式应为 "startTime,endTime",例如 "2023-01-01T00:00:00,2023-01-31T23:59:59"
|
||||
String[] times = param.split(",");
|
||||
if (times.length == 2) {
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||
try {
|
||||
startTime = LocalDateTime.parse(times[0], formatter);
|
||||
endTime = LocalDateTime.parse(times[1], formatter);
|
||||
log.info("使用参数指定的时间范围: {} 到 {}", startTime, endTime);
|
||||
} catch (Exception e) {
|
||||
log.error("解析时间参数失败,使用默认时间范围", e);
|
||||
// 使用默认逻辑
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
|
||||
startTime = now.minusMonths(1)
|
||||
.withDayOfMonth(1)
|
||||
.withHour(0)
|
||||
.withMinute(0)
|
||||
.withSecond(0);
|
||||
endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
|
||||
}
|
||||
} else {
|
||||
// 使用默认逻辑
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
|
||||
startTime = now.minusMonths(1)
|
||||
.withDayOfMonth(1)
|
||||
.withHour(0)
|
||||
.withMinute(0)
|
||||
.withSecond(0);
|
||||
endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
|
||||
}
|
||||
} else {
|
||||
// 使用默认逻辑
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
YearMonth lastMonth = YearMonth.from(now).minusMonths(1);
|
||||
startTime = now.minusMonths(1)
|
||||
.withDayOfMonth(1)
|
||||
.withHour(0)
|
||||
.withMinute(0)
|
||||
.withSecond(0);
|
||||
endTime = lastMonth.atEndOfMonth().atTime(23, 59, 59);
|
||||
}
|
||||
|
||||
// 执行
|
||||
caseAiChatService.downloadConversationExcel(startTime, endTime);
|
||||
}
|
||||
}
|
||||
@@ -20,8 +20,8 @@ public class CaseDocumentLogTask {
|
||||
*/
|
||||
@XxlJob("batchCheckFileStatusJob")
|
||||
public void batchCheckFileStatusJob() {
|
||||
log.info("开始批量查询文件状态");
|
||||
// log.info("开始批量查询文件状态");
|
||||
caseKnowledgeService.batchCheckFileStatus();
|
||||
log.info("结束批量查询文件状态");
|
||||
// log.info("结束批量查询文件状态");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,18 +41,18 @@ public class CaseUploadTask {
|
||||
@XxlJob("oldDataUploadJob")
|
||||
public void oldDataUploadJob() {
|
||||
try {
|
||||
log.info("开始执行旧案例上传任务");
|
||||
// log.info("开始执行旧案例上传任务");
|
||||
|
||||
// 从Redis获取上次处理的最后一条记录ID
|
||||
String lastProcessedId = stringRedisTemplate.opsForValue().get(CASE_UPLOAD_LAST_ID_KEY);
|
||||
log.info("上次处理的最后一条记录ID: {}", lastProcessedId);
|
||||
// log.info("上次处理的最后一条记录ID: {}", lastProcessedId);
|
||||
|
||||
// 查询符合条件的案例数据
|
||||
List<Cases> casesToProcess = findCasesToProcess(lastProcessedId);
|
||||
log.info("查询到待处理案例数量: {}", casesToProcess.size());
|
||||
// log.info("查询到待处理案例数量: {}", casesToProcess.size());
|
||||
|
||||
if (casesToProcess.isEmpty()) {
|
||||
log.info("没有需要处理的案例数据");
|
||||
// log.info("没有需要处理的案例数据");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ public class CaseUploadTask {
|
||||
}
|
||||
}
|
||||
|
||||
log.info("过滤后需要处理的案例数量: {}", casesList.size());
|
||||
// log.info("过滤后需要处理的案例数量: {}", casesList.size());
|
||||
|
||||
if (!casesList.isEmpty()) {
|
||||
// 调用异步处理方法
|
||||
@@ -91,12 +91,12 @@ public class CaseUploadTask {
|
||||
// 将当前处理的最后一条数据ID存入Redis
|
||||
String currentLastId = casesList.get(casesList.size() - 1).getId();
|
||||
stringRedisTemplate.opsForValue().set(CASE_UPLOAD_LAST_ID_KEY, currentLastId);
|
||||
log.info("已处理案例,最后一条记录ID已更新为: {}", currentLastId);
|
||||
} else {
|
||||
log.info("没有新的案例需要处理");
|
||||
// log.info("已处理案例,最后一条记录ID已更新为: {}", currentLastId);
|
||||
// } else {
|
||||
// log.info("没有新的案例需要处理");
|
||||
}
|
||||
|
||||
log.info("旧案例上传任务执行完成");
|
||||
// log.info("旧案例上传任务执行完成");
|
||||
} catch (Exception e) {
|
||||
log.error("执行旧案例上传任务时发生异常", e);
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.xboe.module.boecase.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,16 @@ public class CaseAiMessageVo {
|
||||
*/
|
||||
private String answer;
|
||||
|
||||
/**
|
||||
* 会话开始时间
|
||||
*/
|
||||
private LocalDateTime startTime;
|
||||
|
||||
/**
|
||||
* 会话时长(秒)
|
||||
*/
|
||||
private Long durationSeconds;
|
||||
|
||||
/**
|
||||
* 案例引用列表
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.xboe.module.boecase.vo;
|
||||
|
||||
import lombok.Data;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 会话Excel导出VO
|
||||
*/
|
||||
@Data
|
||||
public class ConversationExcelVo {
|
||||
/**
|
||||
* 会话ID
|
||||
*/
|
||||
private String conversationId;
|
||||
|
||||
/**
|
||||
* 会话名称
|
||||
*/
|
||||
private String conversationName;
|
||||
|
||||
/**
|
||||
* 用户
|
||||
*/
|
||||
private String user;
|
||||
|
||||
/**
|
||||
* 问答记录
|
||||
*/
|
||||
private List<CaseAiMessageVo> messages;
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.module.course.dto.CourseParam;
|
||||
import com.xboe.module.course.service.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -29,6 +28,10 @@ import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseAudit;
|
||||
import com.xboe.module.course.entity.CourseContent;
|
||||
import com.xboe.module.course.entity.CourseHRBPAudit;
|
||||
import com.xboe.module.course.service.ICourseAuditService;
|
||||
import com.xboe.module.course.service.ICourseContentService;
|
||||
import com.xboe.module.course.service.ICourseHRBPAuditService;
|
||||
import com.xboe.module.course.service.ICourseService;
|
||||
import com.xboe.standard.enums.BoedxContentType;
|
||||
import com.xboe.standard.enums.BoedxCourseType;
|
||||
|
||||
@@ -57,8 +60,7 @@ public class CourseAuditApi extends ApiBaseController{
|
||||
private ICourseContentService ccontentService;
|
||||
@Resource
|
||||
private ThirdApi thirdApi;
|
||||
@Resource
|
||||
private ICourseTagService tagService;
|
||||
|
||||
|
||||
/**
|
||||
* 教师需要审核的课程
|
||||
@@ -424,10 +426,6 @@ public class CourseAuditApi extends ApiBaseController{
|
||||
dto.getCourse().setEnabled(true);//设置启用状态问题
|
||||
dto.getCourse().setPublished(false);//重新提交审核设置为未发布状态
|
||||
try {
|
||||
// log.info("-------- 标签相关开始 ------- 课程ID = {} " , dto.getCourse().getId());
|
||||
// Course oldCourse = StringUtils.isBlank(dto.getCourse().getId()) ? null : courseService.get(dto.getCourse().getId());
|
||||
// tagService.updateTags(oldCourse,dto.getCourse(),cuser);
|
||||
// log.info("-------- 标签相关结束 -------");
|
||||
|
||||
courseService.submitAndPublish(dto,cuser.getAccountId(),cuser.getName());
|
||||
log.info("---------------在线课开始同步到讲师管理 ------- token = " + token);
|
||||
|
||||
@@ -15,6 +15,8 @@ import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import it.sauronsoftware.jave.Encoder;
|
||||
import it.sauronsoftware.jave.MultimediaInfo;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.orm.ObjectOptimisticLockingFailureException;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -46,8 +48,6 @@ import com.xboe.module.scorm.SCORMParser;
|
||||
import com.xboe.standard.BaseConstant;
|
||||
import com.xboe.standard.enums.BoedxCourseFileType;
|
||||
|
||||
import it.sauronsoftware.jave.Encoder;
|
||||
import it.sauronsoftware.jave.MultimediaInfo;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
/**
|
||||
@@ -256,7 +256,7 @@ public class CourseFileApi extends ApiBaseController {
|
||||
}
|
||||
String fileFullPath = SysConstant.getConfigValue(BaseConstant.CONFIG_UPLOAD_FILES_SAVEPATH) + file.getFilePath();
|
||||
if ("mp3,mp4".indexOf(file.getFileType()) > -1){
|
||||
log.info("上传 "+file.getFileType()+"文件:"+file.getFilePath());
|
||||
log.info("上传 "+file.getFileType()+"文件:"+file.getFilePath());
|
||||
Encoder encoder = new Encoder();
|
||||
try {
|
||||
//System.out.println(fileFullPath);
|
||||
@@ -278,8 +278,8 @@ public class CourseFileApi extends ApiBaseController {
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("读取视频时长错误");
|
||||
// e.printStackTrace();
|
||||
log.error("读取视频时长错误", e);
|
||||
return error("视频解析失败,尝试重新上传或联系管理员", "视频解析失败,尝试重新上传或联系管理员");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ 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;
|
||||
@@ -36,6 +34,11 @@ 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;
|
||||
|
||||
@@ -60,8 +63,7 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
ICourseFullTextSearch fullTextSearch;
|
||||
@Resource
|
||||
IOrganizationService organizationService;
|
||||
@Autowired
|
||||
ICourseTagService courseTagService;
|
||||
|
||||
@Resource
|
||||
IStudyCourseService IStudyCourseService;
|
||||
|
||||
@@ -74,8 +76,6 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
@Autowired
|
||||
StringRedisTemplate redisTemplate;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 课程的初始化
|
||||
* @return
|
||||
@@ -310,18 +310,7 @@ 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);
|
||||
@@ -413,12 +402,6 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
c.setKeywordsList(keywordsList);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(c.getTags()) ){
|
||||
List<CourseTag> tagList = courseTagService.getTagsByIds(c.getTags());
|
||||
List<String> tags = tagList.stream().map(CourseTag::getTagName).collect(Collectors.toList());
|
||||
c.setTagsList(tags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
|
||||
import com.boe.feign.api.infrastructure.entity.Dict;
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.module.course.dto.*;
|
||||
import com.xboe.module.course.entity.*;
|
||||
import com.xboe.module.course.service.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -96,8 +94,7 @@ public class CourseManageApi extends ApiBaseController{
|
||||
|
||||
@Resource
|
||||
private ICourseHRBPAuditService hrbpAuditService;
|
||||
@Resource
|
||||
private ICourseTagService tagService;
|
||||
|
||||
@Resource
|
||||
IOutSideDataService outSideDataService;
|
||||
|
||||
@@ -150,22 +147,6 @@ public class CourseManageApi extends ApiBaseController{
|
||||
dto.setOrgIds(ids);
|
||||
dto.setReadIds(userOrgIds.getReadIds());
|
||||
PageList<Course> coursePageList = courseService.findPage(pager.getPageIndex(), pager.getPageSize(),dto);
|
||||
// 补充审核人和审核时间(取最近一条审核记录)- 批量查询优化
|
||||
if (coursePageList != null && coursePageList.getList() != null && !coursePageList.getList().isEmpty()) {
|
||||
List<String> courseIds = coursePageList.getList().stream().map(Course::getId).collect(Collectors.toList());
|
||||
Map<String, CourseHRBPAudit> latestAuditMap = hrbpAuditService.findLatestByCourseIds(courseIds);
|
||||
for (Course c : coursePageList.getList()) {
|
||||
try {
|
||||
CourseHRBPAudit latest = latestAuditMap.get(c.getId());
|
||||
if (latest != null) {
|
||||
c.setAuditUser(latest.getAuditUser());
|
||||
c.setAuditTime(latest.getAuditTime());
|
||||
}
|
||||
} catch (Exception ignore) {
|
||||
// ignore single course enrich error
|
||||
}
|
||||
}
|
||||
}
|
||||
return success(coursePageList);
|
||||
}catch(Exception e) {
|
||||
log.error("管理课程列表查询错误",e);
|
||||
@@ -203,12 +184,6 @@ public class CourseManageApi extends ApiBaseController{
|
||||
rs.put("dicts",dicts);
|
||||
}
|
||||
log.error("-------是否仅内网查看 = " + isPermission);
|
||||
if (StringUtils.isNotBlank(course.getTags())){
|
||||
List<CourseTag> tagList = tagService.getTagsByIds(course.getTags());
|
||||
rs.put("tagList", tagList);
|
||||
}
|
||||
|
||||
|
||||
rs.put("course",course);
|
||||
rs.put("contents",cclist);
|
||||
rs.put("sections",sectionlist);
|
||||
@@ -238,7 +213,7 @@ public class CourseManageApi extends ApiBaseController{
|
||||
}
|
||||
return success(rs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 管理员审核列表,教师的审核不在这里,此审核也应该移动CourseAuditApi中去
|
||||
* @param pager
|
||||
@@ -347,12 +322,6 @@ public class CourseManageApi extends ApiBaseController{
|
||||
|
||||
//填充必要的信息
|
||||
try {
|
||||
// log.info("-------- 标签相关开始 ------- 课程ID = {} " , dto.getCourse().getId());
|
||||
// CurrentUser userInfo = getCurrent();
|
||||
// Course oldCourse = StringUtils.isBlank(dto.getCourse().getId()) ? null : courseService.get(dto.getCourse().getId());
|
||||
// tagService.updateTags(oldCourse,dto.getCourse(),userInfo);
|
||||
// log.info("-------- 标签相关结束 -------");
|
||||
|
||||
if(StringUtils.isBlank(dto.getCourse().getId())) {
|
||||
//只有在第一次添加保存时才会这样
|
||||
fillCourseData(dto.getCourse());
|
||||
|
||||
@@ -1,188 +0,0 @@
|
||||
package com.xboe.module.course.api;
|
||||
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.common.Pagination;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.core.orm.IFieldFilter;
|
||||
import com.xboe.module.article.entity.Article;
|
||||
import com.xboe.module.article.service.IArticleService;
|
||||
import com.xboe.module.course.dto.CourseTagQueryDto;
|
||||
import com.xboe.module.course.dto.CourseTagRelationDto;
|
||||
import com.xboe.module.course.entity.CourseTag;
|
||||
import com.xboe.module.course.entity.CourseTagRelation;
|
||||
import com.xboe.module.course.service.ICourseTagService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName:CourseTagApi
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/2614:27
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping(value="/xboe/m/coursetag")
|
||||
public class CourseTagApi extends ApiBaseController {
|
||||
|
||||
@Resource
|
||||
ICourseTagService courseTagService;
|
||||
|
||||
/**
|
||||
* 标签列表:分页查询
|
||||
* @param pager
|
||||
* @param courseTagQueryDto
|
||||
* @return
|
||||
*/
|
||||
/* @RequestMapping(value="/page",method= {RequestMethod.GET,RequestMethod.POST})
|
||||
public JsonResponse<PageList<CourseTag>> find(Pagination pager, CourseTagQueryDto courseTagQueryDto){
|
||||
log.info("标签列表:分页查询 pager = " + pager);
|
||||
log.info("标签列表:分页查询 courseTagQueryDto = " + courseTagQueryDto);
|
||||
List<IFieldFilter> filters=new ArrayList<IFieldFilter>();
|
||||
OrderCondition order = null;
|
||||
if (courseTagQueryDto != null){
|
||||
String tagId = courseTagQueryDto.getId();
|
||||
String tagName = courseTagQueryDto.getTagName();
|
||||
Boolean isHot = courseTagQueryDto.getIsHot();
|
||||
String orderField = courseTagQueryDto.getOrderField();
|
||||
Boolean isAsc = courseTagQueryDto.getOrderAsc();
|
||||
if (StringUtils.isNotBlank(tagId)){
|
||||
filters.add(FieldFilters.eq("id",tagId));
|
||||
}
|
||||
//课程标签名称:模糊查询
|
||||
if (StringUtils.isNotBlank(tagName)){
|
||||
filters.add(FieldFilters.like("tagName",tagName));
|
||||
}
|
||||
// 构建排序条件:支持先按lastSetHotTime降序,再按动态字段升/降序排列
|
||||
if (isHot !=null ){
|
||||
filters.add(FieldFilters.eq("isHot",isHot));
|
||||
//order = OrderCondition.desc("lastSetHotTime");//固定降序
|
||||
}
|
||||
// 动态排序处理
|
||||
if (StringUtils.isNotBlank(orderField)) {
|
||||
if (order == null) {
|
||||
order = isAsc ? OrderCondition.asc(orderField) : OrderCondition.desc(orderField);
|
||||
} else {
|
||||
order = isAsc ? order.asc(orderField) : order.desc(orderField); // 链式追加排序条件
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("标签列表:分页查询 调用接口 filters = " + filters);
|
||||
log.info("标签列表:分页查询 调用接口 order = " + order);
|
||||
PageList<CourseTag> list=courseTagService.query(pager.getPageIndex(),pager.getPageSize(),filters,order);
|
||||
return success(list);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* 修改指定id的课程标签的公共属性
|
||||
* @param id
|
||||
* @param isPublic
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
@RequestMapping(value="/changePublicStatus",method= RequestMethod.POST)
|
||||
public JsonResponse<Void> changePublicStatus(Long id,Boolean isPublic){
|
||||
courseTagService.changePublicStatus(id,isPublic);
|
||||
return success(null);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 修改指定id的课程标签的热点属性
|
||||
* @param id
|
||||
* @param isHot
|
||||
* @return
|
||||
*/
|
||||
/* @RequestMapping(value="/changeHotStatus",method= RequestMethod.POST)
|
||||
public JsonResponse<Void> changeHotStatus(Long id,Boolean isHot){
|
||||
courseTagService.changeHotStatus(id,isHot);
|
||||
return success(null);
|
||||
}*/
|
||||
|
||||
/**
|
||||
* 分页查询:指定id的标签关联的所有课程
|
||||
* @param courseTagQueryDto
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
@RequestMapping(value="/showCourseByTag",method= RequestMethod.POST)
|
||||
public JsonResponse<PageList<CourseTagRelationDto>> showCourseByTag(Pagination pager, CourseTagQueryDto courseTagQueryDto){
|
||||
PageList<CourseTagRelationDto> list=null;
|
||||
if (courseTagQueryDto != null) {
|
||||
Long tagId = Long.valueOf(courseTagQueryDto.getId());
|
||||
Boolean isAsc = courseTagQueryDto.getOrderAsc()!=null?courseTagQueryDto.getOrderAsc():false;
|
||||
list=courseTagService.getCourseByTag(pager.getPageIndex(),pager.getPageSize(),tagId,isAsc);
|
||||
}
|
||||
return success(list);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 解除指定id的课程和某个标签之间的关联关系
|
||||
* @return
|
||||
*/
|
||||
/*
|
||||
@RequestMapping(value="/unbind",method= RequestMethod.POST)
|
||||
public JsonResponse<Void> unbindCourseTagRelation(CourseTagRelationDto courseTagRelationDto){
|
||||
if (courseTagRelationDto!=null){
|
||||
courseTagService.unbind(courseTagRelationDto.getId());
|
||||
return success(null);
|
||||
}
|
||||
return error("解绑失败!");
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 模糊检索标签
|
||||
* @return 符合检索条件的所有公共标签
|
||||
*/
|
||||
@RequestMapping(value="/searchTags",method= RequestMethod.POST)
|
||||
public JsonResponse<List<CourseTag>> searchTags(String tagName,String typeId ,HttpServletRequest request){
|
||||
|
||||
CurrentUser cuser = getCurrent();
|
||||
String aid = cuser.getAccountId();
|
||||
log.info(" searchTags cuser name = " + cuser.getName() + " , NickName = " + cuser.getNickName() + " , LoginName = " + cuser.getLoginName());
|
||||
log.info(" 参数 tagName = " + tagName + " , typeId = " + typeId + " , aid = " + aid);
|
||||
log.info(" searchTags aid = " + aid);
|
||||
List<CourseTag> courseTagList = courseTagService.searchTags(tagName,aid,typeId);
|
||||
return success(courseTagList);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新标签,并与当前课程绑定
|
||||
* @param courseTagRelationDto
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/createTag",method= RequestMethod.POST)
|
||||
public JsonResponse<CourseTag> createTag(CourseTagRelationDto courseTagRelationDto){
|
||||
if (courseTagRelationDto!=null){
|
||||
CourseTag courseTag = courseTagService.createTag(courseTagRelationDto);
|
||||
return success(courseTag);
|
||||
}
|
||||
return error("创建标签失败!");
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新标签,并与当前课程绑定
|
||||
* @param courseTagRelationDto
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value="/getHotTagList",method= RequestMethod.POST)
|
||||
public JsonResponse<List<CourseTag>> getHotTagList(CourseTagRelationDto courseTagRelationDto){
|
||||
List<CourseTag> hotTagList = courseTagService.getHotTagList(courseTagRelationDto);
|
||||
return success(hotTagList);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
package com.xboe.module.course.dao;
|
||||
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.orm.BaseDao;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.core.orm.IFieldFilter;
|
||||
import com.xboe.core.orm.IQuery;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseFile;
|
||||
import com.xboe.module.course.entity.CourseTag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.jdbc.core.BeanPropertyRowMapper;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @ClassName:CourseTagDao
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/2516:50
|
||||
*/
|
||||
|
||||
@Slf4j
|
||||
@Repository
|
||||
public class CourseTagDao extends BaseDao<CourseTag> {
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
/**
|
||||
* 获取热门标签列表(前10条)
|
||||
* @return 热门标签列表
|
||||
*/
|
||||
public List<CourseTag> getHotTagList() {
|
||||
// 原生SQL:注意表名和列名需与数据库实际一致
|
||||
String sql = "select t.*,COUNT(r.tag_id) AS relation_count\n" +
|
||||
"from boe_course_tag t\n" +
|
||||
"left join boe_course_tag_relation r\n" +
|
||||
"on t.id = r.tag_id\n" +
|
||||
"where t.deleted =0 and t.is_hot = true and t.status =0 \n" +
|
||||
"GROUP BY t.id\n" +
|
||||
"order by t.last_set_hot_time desc,relation_count desc"; // 数据库字段为last_set_hot_time
|
||||
|
||||
// 创建原生查询并指定结果映射到CourseTag实体
|
||||
javax.persistence.Query query = entityManager.createNativeQuery(sql, CourseTag.class);
|
||||
|
||||
// 分页:取前10条
|
||||
query.setFirstResult(0);
|
||||
query.setMaxResults(10);
|
||||
|
||||
// 执行查询并返回结果(已映射为CourseTag类型)
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据课程类型获取热门标签列表(前10条)
|
||||
* @param sysType1 系统类型1
|
||||
* @param sysType2 系统类型2
|
||||
* @param sysType3 系统类型3
|
||||
* @return 热门标签列表
|
||||
*/
|
||||
public List<CourseTag> getHotTagListBySysTypes(String sysType1, String sysType2, String sysType3) {
|
||||
// 原生SQL:注意表名和列名需与数据库实际一致(此处假设表名为course_tag、course_type_tag_relation)
|
||||
String sql = "SELECT DISTINCT c.* FROM boe_course_tag c " +
|
||||
"JOIN boe_course_type_tag_relation r ON c.id = r.tag_id " +
|
||||
"WHERE r.deleted = 0 and c.status =0 " +
|
||||
"AND c.is_hot = true "; // 假设数据库字段为is_hot(与实体属性isHot对应)
|
||||
if (StringUtils.isNotBlank(sysType1)){
|
||||
sql += "AND r.sys_type1 = ?1 ORDER BY c.last_set_hot_time DESC";
|
||||
}else if(StringUtils.isNotBlank(sysType2)){
|
||||
sql += "AND r.sys_type2 = ?1 ORDER BY c.last_set_hot_time DESC";
|
||||
}else {
|
||||
sql += "AND r.sys_type3 = ?1 ORDER BY c.last_set_hot_time DESC";
|
||||
}
|
||||
// 创建原生查询并指定结果映射到CourseTag实体
|
||||
javax.persistence.Query query = entityManager.createNativeQuery(sql, CourseTag.class);
|
||||
|
||||
// 绑定参数(注意参数索引从1开始)
|
||||
if (StringUtils.isNotBlank(sysType1)){
|
||||
query.setParameter(1, sysType1);
|
||||
} else if (StringUtils.isNotBlank(sysType2)) {
|
||||
query.setParameter(1, sysType2);
|
||||
}else {
|
||||
query.setParameter(1, sysType3);
|
||||
}
|
||||
// 分页:取前10条
|
||||
query.setFirstResult(0);
|
||||
query.setMaxResults(10);
|
||||
|
||||
// 执行查询并返回结果(已映射为CourseTag类型)
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public List<CourseTag> getTagsByIds(String id) {
|
||||
String sql = "select * from " + SysConstant.TABLE_PRE + "course_tag where id in (" + id + "0)";
|
||||
// 创建原生查询并指定结果映射到CourseTag实体
|
||||
javax.persistence.Query query = entityManager.createNativeQuery(sql, CourseTag.class);
|
||||
return query.getResultList();
|
||||
}
|
||||
|
||||
public CourseTag getTagByName(String tagName) {
|
||||
CourseTag courseTag = this.findOne((FieldFilters.eq("tag_name", tagName)));
|
||||
return courseTag;
|
||||
}
|
||||
|
||||
public PageList<CourseTag> getList() {
|
||||
log.info("------- getList ----------- ");
|
||||
String sql = "select * from boe_course_tag order by sys_create_time desc limit 10";
|
||||
javax.persistence.Query query = entityManager.createNativeQuery(sql, CourseTag.class);
|
||||
log.info("------- getList -----------getResultList = " + query.getResultList() );
|
||||
PageList<CourseTag> pageList = new PageList<>();
|
||||
pageList.setCount(query.getResultList().size());
|
||||
pageList.setPageSize(1);
|
||||
pageList.setList(query.getResultList());
|
||||
|
||||
return pageList;
|
||||
}
|
||||
|
||||
public List<CourseTag> searchTags(String tagName, String userId, String typeId) {
|
||||
StringBuilder sql = new StringBuilder();
|
||||
List<Object> parameters = new ArrayList<>();
|
||||
|
||||
// 只查询实际存在的字段
|
||||
sql.append("SELECT id, tag_name, is_public, is_hot, use_count, last_set_public_time, last_set_hot_time, deleted, sys_create_time ");
|
||||
sql.append("FROM ( ");
|
||||
sql.append(" SELECT id, tag_name, is_public, is_hot, use_count, last_set_public_time, last_set_hot_time, deleted, sys_create_time ");
|
||||
sql.append(" FROM boe_course_tag ");
|
||||
sql.append(" WHERE deleted = 0 AND is_public = 0 AND status = 0 ");
|
||||
|
||||
if (StringUtils.isNotBlank(tagName)) {
|
||||
sql.append(" AND tag_name LIKE ? ");
|
||||
parameters.add("%" + tagName + "%");
|
||||
}
|
||||
|
||||
sql.append(" UNION ALL ");
|
||||
sql.append(" SELECT t.id, t.tag_name, t.is_public, t.is_hot, t.use_count, t.last_set_public_time, t.last_set_hot_time, t.deleted, t.sys_create_time ");
|
||||
sql.append(" FROM boe_course_tag_relation r ");
|
||||
sql.append(" INNER JOIN boe_course_tag t ON r.tag_id = t.id ");
|
||||
sql.append(" WHERE r.deleted = 0 AND t.deleted = 0 AND t.is_public = 1 AND t.status = 0 ");
|
||||
|
||||
if (StringUtils.isNotBlank(userId)) {
|
||||
sql.append(" AND r.sys_create_aid = ? ");
|
||||
parameters.add(Long.valueOf(userId));
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(tagName)) {
|
||||
sql.append(" AND t.tag_name LIKE ? ");
|
||||
parameters.add("%" + tagName + "%");
|
||||
}
|
||||
|
||||
sql.append(" GROUP BY t.id, t.tag_name, t.is_public, t.is_hot, t.use_count, t.last_set_public_time, t.last_set_hot_time, t.deleted, t.sys_create_time ");
|
||||
sql.append(") AS all_tags ");
|
||||
sql.append("ORDER BY ");
|
||||
|
||||
if (StringUtils.isNotBlank(typeId)) {
|
||||
sql.append(" CASE WHEN id IN ( ");
|
||||
sql.append(" SELECT tag_id ");
|
||||
sql.append(" FROM boe_course_type_tag_relation ");
|
||||
sql.append(" WHERE deleted = 0 ");
|
||||
sql.append(" AND (sys_type1 = ? ");
|
||||
sql.append(" OR sys_type2 = ? ");
|
||||
sql.append(" OR sys_type3 = ?) ");
|
||||
sql.append(" GROUP BY tag_id ");
|
||||
sql.append(" ) THEN 0 ELSE 1 END, ");
|
||||
parameters.add(Long.valueOf(typeId));
|
||||
parameters.add(Long.valueOf(typeId));
|
||||
parameters.add(Long.valueOf(typeId));
|
||||
}
|
||||
|
||||
sql.append(" sys_create_time DESC");
|
||||
log.info("查询标签 searchTags sql = {} ", sql);
|
||||
// 不使用实体类映射,手动处理结果集
|
||||
Query query = entityManager.createNativeQuery(sql.toString());
|
||||
|
||||
for (int i = 0; i < parameters.size(); i++) {
|
||||
query.setParameter(i + 1, parameters.get(i));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object[]> results = query.getResultList();
|
||||
List<CourseTag> courseTags = new ArrayList<>();
|
||||
|
||||
for (Object[] result : results) {
|
||||
CourseTag tag = new CourseTag();
|
||||
// 设置基本字段
|
||||
if (result[0] != null) tag.setId(String.valueOf(result[0]));
|
||||
if (result[1] != null) tag.setTagName(String.valueOf(result[1]));
|
||||
if (result[2] != null) tag.setIsPublic(Boolean.valueOf(String.valueOf(result[2])));
|
||||
if (result[3] != null) tag.setIsHot(Boolean.valueOf(String.valueOf(result[3])));
|
||||
if (result[4] != null) tag.setUseCount(Integer.valueOf(String.valueOf(result[4])));
|
||||
courseTags.add(tag);
|
||||
}
|
||||
|
||||
return courseTags;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,116 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,17 +0,0 @@
|
||||
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> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.xboe.module.course.dao;
|
||||
|
||||
import com.xboe.core.orm.BaseDao;
|
||||
import com.xboe.module.course.entity.ModifyLog;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class ModifyLogDao extends BaseDao<ModifyLog> {
|
||||
|
||||
public void insert(String requestId, String location, String body, String remark) {
|
||||
ModifyLog entity = new ModifyLog();
|
||||
entity.setRequestId(requestId);
|
||||
entity.setLocation(location);
|
||||
entity.setBody(body);
|
||||
entity.setRemark(remark);
|
||||
|
||||
save(entity);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.xboe.module.course.dto;
|
||||
|
||||
import com.xboe.module.course.entity.CourseTag;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@@ -141,6 +140,4 @@ public class CourseQueryDto {
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
private String tags;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -400,15 +400,6 @@ public class Course extends BaseEntity {
|
||||
@Transient
|
||||
private String teacher;
|
||||
|
||||
/**审核人名称(列表展示用)*/
|
||||
@Transient
|
||||
private String auditUser;
|
||||
|
||||
/**审核时间(列表展示用)*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Transient
|
||||
private LocalDateTime auditTime;
|
||||
|
||||
public Course(String id,String name,String summary,String coverImg,String sysCreateAid,String sysCreateBy,Integer type,LocalDateTime publishTime){
|
||||
super.setId(id);
|
||||
this.name=name;
|
||||
|
||||
@@ -1,98 +0,0 @@
|
||||
package com.xboe.module.course.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.orm.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 在线课程的标签类
|
||||
* @ClassName:CourseTag
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/25 16:37
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Entity
|
||||
@Table(name = SysConstant.TABLE_PRE+"course_tag")
|
||||
public class CourseTag extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
@Column(name = "tag_name",nullable=false, length = 50)
|
||||
private String tagName;
|
||||
|
||||
/**
|
||||
* 是否设置为公共标签
|
||||
*/
|
||||
@Column(name = "is_public",length = 1)
|
||||
private Boolean isPublic;
|
||||
|
||||
/**
|
||||
* 是否设置为热点标签
|
||||
*/
|
||||
@Column(name = "is_hot",length = 1)
|
||||
private Boolean isHot;
|
||||
|
||||
/**
|
||||
* 使用次数(关联课程数)
|
||||
*/
|
||||
@Column(name = "use_count",length = 1)
|
||||
private Integer useCount;
|
||||
|
||||
/**
|
||||
* 1临时, 0正式
|
||||
*/
|
||||
@Column(name = "status",length = 1)
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 最近设置为公共标签的时间
|
||||
*/
|
||||
@Column(name = "last_set_public_time", nullable = true)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime lastSetPublicTime;
|
||||
|
||||
/**
|
||||
* 最近设置为热点标签的时间
|
||||
*/
|
||||
@Column(name = "last_set_hot_time", nullable = true)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime lastSetHotTime;
|
||||
|
||||
public CourseTag() {
|
||||
|
||||
}
|
||||
public CourseTag(Long id, Boolean isPublic,Boolean isHot) {
|
||||
this.setId(String.valueOf(id));
|
||||
this.isPublic=isPublic;
|
||||
this.isHot=isHot;
|
||||
}
|
||||
|
||||
|
||||
public CourseTag(String id,String tagName,String sysCreateBy,String sysCreateAid,LocalDateTime sysCreateTime,
|
||||
Boolean isPublic,Boolean isHot,Integer useCount,LocalDateTime lastSetPublicTime,LocalDateTime lastSetHotTime,Boolean deleted){
|
||||
this.setId(id);
|
||||
this.setTagName(tagName);
|
||||
super.setSysCreateBy(sysCreateBy);
|
||||
super.setSysCreateAid(sysCreateAid);
|
||||
super.setSysCreateTime(sysCreateTime);
|
||||
this.isPublic = isPublic;
|
||||
this.isHot = isHot;
|
||||
this.useCount = useCount;
|
||||
this.lastSetPublicTime = lastSetPublicTime;
|
||||
this.lastSetHotTime = lastSetHotTime;
|
||||
super.setDeleted(deleted);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
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;
|
||||
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
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;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.xboe.module.course.entity;
|
||||
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.orm.IdBaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* 讲师删除记录表
|
||||
* 为了监控PngCode-SZX-1227问题临时创建的表
|
||||
*
|
||||
* @author guo jia
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Table(name = SysConstant.TABLE_PRE + "modify_log")
|
||||
public class ModifyLog extends IdBaseEntity {
|
||||
|
||||
/**
|
||||
* 请求ID
|
||||
*/
|
||||
private String requestId;
|
||||
|
||||
/**
|
||||
* 位置
|
||||
*/
|
||||
private String location;
|
||||
|
||||
/**
|
||||
* 请求body
|
||||
*/
|
||||
private String body;
|
||||
|
||||
/**
|
||||
* 备注信息
|
||||
*/
|
||||
private String remark;
|
||||
|
||||
}
|
||||
@@ -52,7 +52,6 @@ public class CourseToCourseFullText {
|
||||
cft.setTeacher("");
|
||||
cft.setTeacherCode("");
|
||||
cft.setType(c.getType());
|
||||
cft.setTags(c.getTags());
|
||||
if(c.getOpenCourse()==null) {
|
||||
cft.setOpenCourse(0);
|
||||
}else {
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.xboe.module.course.service;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.module.course.dto.CourseHRBPAuditDto;
|
||||
@@ -57,10 +56,5 @@ public interface ICourseHRBPAuditService {
|
||||
*/
|
||||
PageList<CourseHRBPAudit> pageList(Integer pageIndex, Integer pageSize,int userType, CourseHRBPAudit info);
|
||||
|
||||
/**
|
||||
* 查询一组课程的最近一次审核记录,返回键为courseId的映射。
|
||||
*/
|
||||
Map<String, CourseHRBPAudit> findLatestByCourseIds(List<String> courseIds);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -343,6 +343,4 @@ public interface ICourseService {
|
||||
|
||||
List<Course> findByIds(List<String> courseIds);
|
||||
void deletedStudyResourceBatchByCourseIdAndType(String courseId,Integer courseType);
|
||||
|
||||
void getPhpCourseData();
|
||||
}
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
package com.xboe.module.course.service;
|
||||
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.orm.IFieldFilter;
|
||||
import com.xboe.module.article.entity.Article;
|
||||
import com.xboe.module.course.dto.CourseTagQueryDto;
|
||||
import com.xboe.module.course.dto.CourseTagRelationDto;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseTag;
|
||||
import com.xboe.module.course.entity.CourseTagRelation;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @InterfaceName:ICourseTagService
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/2516:53
|
||||
*/
|
||||
public interface ICourseTagService {
|
||||
|
||||
/**
|
||||
* 分页查询标签列表,使用自定义filter
|
||||
* @param pageIndex
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
PageList<CourseTag> query(Integer pageIndex, Integer pageSize, List<IFieldFilter> filters, OrderCondition order);
|
||||
|
||||
/**
|
||||
* 分页查询指定id标签关联的课程列表,使用自定义filter
|
||||
* @param pageIndex
|
||||
* @param pageSize
|
||||
* @return
|
||||
*/
|
||||
PageList<CourseTagRelationDto> getCourseByTag(Integer pageIndex, Integer pageSize, Long tagId, Boolean isAsc);
|
||||
|
||||
/**
|
||||
* 修改指定id的课程标签的公共属性
|
||||
* @param id
|
||||
* @param isPublic
|
||||
* @return
|
||||
*/
|
||||
void changePublicStatus(Long id,Boolean isPublic);
|
||||
|
||||
/**
|
||||
* 修改指定id的课程标签的热点属性
|
||||
* @param id
|
||||
* @param isHot
|
||||
* @return
|
||||
*/
|
||||
void changeHotStatus(Long id,Boolean isHot);
|
||||
|
||||
/**
|
||||
* 解除指定id的课程和某个标签之间的关联关系
|
||||
* @return
|
||||
*/
|
||||
void unbind(String id);
|
||||
|
||||
/**
|
||||
* 根据标签名称进行检索(模糊查询)
|
||||
* @param tagName
|
||||
* @return 符合检索条件的所有公共标签
|
||||
*/
|
||||
List<CourseTag> searchTags(String tagName,String userId,String typeId);
|
||||
|
||||
/**
|
||||
* 创建新标签,并与当前课程绑定
|
||||
* @param courseTagRelationDto
|
||||
* @return
|
||||
*/
|
||||
CourseTag createTag(CourseTagRelationDto courseTagRelationDto);
|
||||
|
||||
/**
|
||||
* 根据课程类型获取热点标签
|
||||
* @param courseTagRelationDto
|
||||
* @return
|
||||
*/
|
||||
List<CourseTag> getHotTagList(CourseTagRelationDto courseTagRelationDto);
|
||||
|
||||
/**
|
||||
* 根据多个id获取标签
|
||||
* @param id
|
||||
* @return
|
||||
*/
|
||||
List<CourseTag> getTagsByIds(String id);
|
||||
|
||||
CourseTag getTagByName(String tagName);
|
||||
|
||||
void updateTags(Course oldCourse,Course newCourse,CurrentUser userInfo);
|
||||
}
|
||||
@@ -1,9 +1,7 @@
|
||||
package com.xboe.module.course.service.impl;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@@ -265,27 +263,4 @@ public class CourseHRBPAuditServiceImpl implements ICourseHRBPAuditService {
|
||||
return courseHRBPAuditDao.get(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, CourseHRBPAudit> findLatestByCourseIds(List<String> courseIds) {
|
||||
Map<String, CourseHRBPAudit> result = new HashMap<String, CourseHRBPAudit>();
|
||||
if (courseIds == null || courseIds.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
try {
|
||||
// 按 addTime 倒序,使首次出现的courseId即为该课程的最近一条审核记录
|
||||
List<CourseHRBPAudit> audits = courseHRBPAuditDao.findList(
|
||||
OrderCondition.desc("addTime"),
|
||||
FieldFilters.in("courseId", courseIds)
|
||||
);
|
||||
for (CourseHRBPAudit a : audits) {
|
||||
if (!result.containsKey(a.getCourseId())) {
|
||||
result.put(a.getCourseId(), a);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("批量查询课程审核记录错误", e.getMessage());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -17,23 +17,14 @@ import javax.management.Query;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.core.orm.*;
|
||||
import com.xboe.module.course.dao.*;
|
||||
import com.xboe.module.course.entity.*;
|
||||
import com.xboe.module.course.dto.CourseTagRelationDto;
|
||||
import com.xboe.module.course.entity.*;
|
||||
import com.xboe.module.course.service.ICourseTagService;
|
||||
import com.xboe.school.study.dao.StudyCourseDao;
|
||||
import com.xboe.school.study.entity.StudyCourse;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.HttpClient;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.index.query.BoolQueryBuilder;
|
||||
@@ -96,8 +87,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
|
||||
@Resource
|
||||
private CourseHRBPAuditDao courseHRBPAuditDao;
|
||||
@Resource
|
||||
private ICourseTagService courseTagService;
|
||||
|
||||
|
||||
@Resource
|
||||
private SysLogAuditDao logAuditDao;//审核日志记录
|
||||
@@ -127,6 +117,9 @@ public class CourseServiceImpl implements ICourseService {
|
||||
@Resource
|
||||
private CourseTeacherDeletedRecordDao courseTeacherDeletedRecordDao;
|
||||
|
||||
@Resource
|
||||
private ModifyLogDao modifyLogDao;
|
||||
|
||||
/**
|
||||
* 生成过滤条件
|
||||
*
|
||||
@@ -281,13 +274,13 @@ public class CourseServiceImpl implements ICourseService {
|
||||
//// Set<String>list=new HashSet<>();
|
||||
//// if(s!=null&&!s.isEmpty()){
|
||||
//// list=Arrays.stream(s.split(",")).collect(Collectors.toSet());
|
||||
//// }else {
|
||||
//// }else {
|
||||
//// Set<String> ss = getSeache(dto);
|
||||
//// String courseSearch=String.join(",",ss);
|
||||
//// redisTemplate.opsForValue().set("course_search",courseSearch);
|
||||
//// //设置过期时间为1分钟
|
||||
//// redisTemplate.expire("course_search", 1, TimeUnit.MINUTES);
|
||||
//// }
|
||||
//// }
|
||||
// Set<String> list = getSeache(dto);
|
||||
// //有权限的查询,也同时查询出创建人的数据,在权限上
|
||||
// if(TempFilterConfig.Manager_CourseFile_ByOrgIds) {
|
||||
@@ -367,8 +360,9 @@ public class CourseServiceImpl implements ICourseService {
|
||||
// // 使用distinct()配合自定义的去重条件
|
||||
// .filter(distinctByKey(c -> c.getId()))
|
||||
// .collect(Collectors.toList());
|
||||
//// PageList<Course> rs=courseDao.findPage(pageIndex, pageSize, filters, oc);
|
||||
//// long endTime = System.nanoTime();
|
||||
|
||||
/// / PageList<Course> rs=courseDao.findPage(pageIndex, pageSize, filters, oc);
|
||||
/// / long endTime = System.nanoTime();
|
||||
// //log.info("查询出的条数:"+rs.getCount());
|
||||
// if(!mergedList.isEmpty()){
|
||||
// //去掉未发布的课程
|
||||
@@ -440,15 +434,15 @@ public class CourseServiceImpl implements ICourseService {
|
||||
});
|
||||
//将需要隐藏的做标记
|
||||
listByFilters2.forEach(e -> {
|
||||
if ((seache.contains(e.getId())||dto.getReadIds().contains(e.getOrgId())) && !finalStrings.contains(e.getOrgId()) && !dto.getOrgAid().equals(e.getSysCreateAid())) {
|
||||
if ((seache.contains(e.getId()) || dto.getReadIds().contains(e.getOrgId())) && !finalStrings.contains(e.getOrgId()) && !dto.getOrgAid().equals(e.getSysCreateAid())) {
|
||||
e.setIsPermission(false);
|
||||
} else {
|
||||
e.setIsPermission(true);
|
||||
}
|
||||
});
|
||||
listByFilters2.sort(Comparator.comparing(Course::getIsPermission).reversed());
|
||||
}else{
|
||||
List<Course> collect = listByFilters2.stream().filter(e ->dto.getReadIds().contains(e.getOrgId())||dto.getOrgAid().equals(e.getSysCreateAid())||finalStrings.contains(e.getOrgId())).collect(Collectors.toList());
|
||||
} else {
|
||||
List<Course> collect = listByFilters2.stream().filter(e -> dto.getReadIds().contains(e.getOrgId()) || dto.getOrgAid().equals(e.getSysCreateAid()) || finalStrings.contains(e.getOrgId())).collect(Collectors.toList());
|
||||
List<Course> paginate = paginate(collect, pageIndex, pageSize);
|
||||
PageList<Course> rs = new PageList<>();
|
||||
rs.setCount(collect.size());
|
||||
@@ -920,6 +914,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
for (CourseTeacher ct : full.getTeachers()) {
|
||||
ct.setCourseId(c.getId());
|
||||
courseTeacherDao.save(ct);
|
||||
addBoeCourseTeacherModifyLog(ct, "M1位置讲师名修改", JSONUtil.toJsonStr(ct), null);
|
||||
}
|
||||
}
|
||||
if (full.getCrowds() != null && !full.getCrowds().isEmpty()) {
|
||||
@@ -998,21 +993,6 @@ public class CourseServiceImpl implements ICourseService {
|
||||
if (c.getVisible() == null) {
|
||||
c.setVisible(true);
|
||||
}
|
||||
if (c.getTags() != null && !c.getTags().isEmpty()){
|
||||
CourseTagRelationDto courseTagRelationDto = new CourseTagRelationDto();
|
||||
courseTagRelationDto.setCourseId(c.getId());
|
||||
courseTagRelationDto.setSysType1(c.getSysType1());
|
||||
courseTagRelationDto.setSysType2(c.getSysType2());
|
||||
courseTagRelationDto.setSysType3(c.getSysType3());
|
||||
String tags = c.getTags();
|
||||
List<CourseTag> tagList = courseTagService.getTagsByIds(tags);
|
||||
if (ObjectUtil.isNotEmpty(tagList)){
|
||||
for (CourseTag tag : tagList) {
|
||||
courseTagRelationDto.setTagName(tag.getTagName());
|
||||
courseTagService.createTag(courseTagRelationDto);
|
||||
}
|
||||
}
|
||||
}
|
||||
courseDao.update(c);
|
||||
c.setSysVersion(courseDao.getVersion(c.getId()));
|
||||
full.getCourse().setSysVersion(c.getSysVersion());
|
||||
@@ -1025,6 +1005,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
for (CourseTeacher ct : full.getTeachers()) {
|
||||
ct.setCourseId(c.getId());
|
||||
courseTeacherDao.saveOrUpdate(ct);
|
||||
addBoeCourseTeacherModifyLog(ct, "M2位置讲师名修改", JSONUtil.toJsonStr(ct), null);
|
||||
}
|
||||
}
|
||||
//先清空受众信息,受众信息如果不一样了,也要加入到日志中
|
||||
@@ -1081,6 +1062,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
for (CourseTeacher ct : full.getTeachers()) {
|
||||
ct.setCourseId(c.getId());
|
||||
courseTeacherDao.saveOrUpdate(ct);
|
||||
addBoeCourseTeacherModifyLog(ct, "M3位置讲师名修改", JSONUtil.toJsonStr(ct), null);
|
||||
}
|
||||
}
|
||||
//先清空受众信息,受众信息如果不一样了,也要加入到日志中
|
||||
@@ -1106,12 +1088,9 @@ public class CourseServiceImpl implements ICourseService {
|
||||
public void submitAndPublish(CourseFullDto full, String aid, String aname) throws Exception {
|
||||
|
||||
Course c = full.getCourse();//当前的课程信息
|
||||
log.info(" 课程 c = " + c.getId());
|
||||
log.info(" 课程 c = " + c);
|
||||
c.setPublished(true);
|
||||
c.setPublishTime(LocalDateTime.now());
|
||||
courseDao.update(c);
|
||||
log.info(" 课程 c = " + c.getId());
|
||||
|
||||
// 兼容处理,记录下删除的关联数据
|
||||
createCourseTeacherDeletedRecord(c.getId());
|
||||
@@ -1121,6 +1100,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
for (CourseTeacher ct : full.getTeachers()) {
|
||||
ct.setCourseId(c.getId());
|
||||
courseTeacherDao.saveOrUpdate(ct);
|
||||
addBoeCourseTeacherModifyLog(ct, "M4位置讲师名修改", JSONUtil.toJsonStr(ct), null);
|
||||
}
|
||||
}
|
||||
//先清空受众信息,受众信息如果不一样了,也要加入到日志中
|
||||
@@ -2023,108 +2003,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
|
||||
return courseDao.findListByHql("Select new Course(id,studys,score) from Course where id in(?1)", ids);
|
||||
}
|
||||
private class Result{
|
||||
private Boolean success;
|
||||
private Data data;
|
||||
private class Data{
|
||||
private List<Map<String,Object>> result;
|
||||
|
||||
public List<Map<String, Object>> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(List<Map<String, Object>> result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
|
||||
public void setData(Data data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Boolean getSuccess() {
|
||||
return success;
|
||||
}
|
||||
|
||||
public void setSuccess(Boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
public Data getData() {
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getPhpCourseData() {
|
||||
HttpRequest request = HttpUtil.createGet("https://u.boe.com/api/b1/new-employee/course-list");
|
||||
HttpResponse response = request.execute();
|
||||
String body = response.body();
|
||||
Result result = JSON.parseObject(body,Result.class);
|
||||
log.info("php课程数据获取成功");
|
||||
List<Map<String,Object>> phpCourseDataList = result.getData().getResult();
|
||||
for (Map<String, Object> phpCourseData : phpCourseDataList){
|
||||
log.info("开始同步数据:"+phpCourseData.get("course_name"));
|
||||
}
|
||||
List<Map<String,Object>> phpStudyCourseList = null;
|
||||
// 查询数据库中是否存在php课程数据
|
||||
for (int i = 0; i < phpCourseDataList.size(); i++) {
|
||||
// 查询php的课程数据在数据库中是否已经存在
|
||||
String phpCourseName = (String) phpCourseDataList.get(i).get("course_name");
|
||||
Boolean exist = isCourseName(phpCourseName,"");
|
||||
if (!exist){
|
||||
log.info(phpCourseName+"不存在,开始同步");
|
||||
Course newCourse = new Course();
|
||||
// 设置学习人数
|
||||
int studys = Integer.parseInt(phpCourseDataList.get(i).get("learned_number").toString());
|
||||
newCourse.setStudys(studys);
|
||||
// 设置系统版本
|
||||
int version = Integer.parseInt(phpCourseDataList.get(i).get("version").toString());
|
||||
newCourse.setSysVersion(version);
|
||||
// 设置电脑端还是手机端可见
|
||||
int pcDevice = Integer.parseInt(phpCourseDataList.get(i).get("is_display_pc").toString());
|
||||
int mobileDevice = Integer.parseInt(phpCourseDataList.get(i).get("is_display_mobile").toString());
|
||||
if (pcDevice == 1 && mobileDevice == 1){
|
||||
newCourse.setDevice(3);
|
||||
} else if (pcDevice == 0 && mobileDevice == 1) {
|
||||
newCourse.setDevice(2);
|
||||
}else if(pcDevice == 1 && mobileDevice == 0){
|
||||
newCourse.setDevice(1);
|
||||
}
|
||||
// 判断是否按照顺序学习
|
||||
int orderStudy = Integer.parseInt(phpCourseDataList.get(i).get("mod_type").toString());
|
||||
newCourse.setOrderStudy(orderStudy == 1 ? true : false);
|
||||
// 设置课程简介
|
||||
String summary = (String) phpCourseDataList.get(i).get("course_desc_nohtml");
|
||||
newCourse.setSummary(summary);
|
||||
// 设置课程类型
|
||||
int courseType = Integer.parseInt(phpCourseDataList.get(i).get("course_type").toString());
|
||||
newCourse.setType(courseType == 0 ? 20 : 30);
|
||||
// 设置学习时长
|
||||
int courseTime = Integer.parseInt(phpCourseDataList.get(i).get("course_period").toString());
|
||||
newCourse.setStudyTime(courseTime);
|
||||
// 设置课程封面
|
||||
newCourse.setCoverImg("https://u.boe.com/pc/images/bgimg/course.png");
|
||||
newCourse.setName(phpCourseName);
|
||||
newCourse.setStatus(5);
|
||||
newCourse.setComments(0);
|
||||
newCourse.setDeleted(false);
|
||||
newCourse.setEnabled(true);
|
||||
newCourse.setFavorites(0);
|
||||
newCourse.setIsTop(false);
|
||||
newCourse.setViews(0);
|
||||
newCourse.setPraises(0);
|
||||
newCourse.setTrampleCount(0);
|
||||
newCourse.setShares(0);
|
||||
newCourse.setScore(0f);
|
||||
|
||||
courseDao.save(newCourse);
|
||||
}else {
|
||||
log.info(phpCourseName+"存在");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public void deletedStudyResourceBatchByCourseIdAndType(String courseId, Integer courseType) {
|
||||
DeleteByQueryRequest request = new DeleteByQueryRequest("new_study_resource");
|
||||
@@ -2159,4 +2038,20 @@ public class CourseServiceImpl implements ICourseService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加boe_course_teacher的teacher_name字段被改为"BOE教师"的监控
|
||||
*/
|
||||
private void addBoeCourseTeacherModifyLog(CourseTeacher ct, String location, String body, String remark) {
|
||||
try {
|
||||
if (ct == null) {
|
||||
return;
|
||||
}
|
||||
if (Objects.equals(ct.getTeacherName(), "BOE教师")) {
|
||||
modifyLogDao.insert(null, location, body, remark);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("创建boe_course_teacher记录失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,864 +0,0 @@
|
||||
package com.xboe.module.course.service.impl;
|
||||
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.core.orm.BaseEntity;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.core.orm.IFieldFilter;
|
||||
import com.xboe.core.orm.QueryBuilder;
|
||||
import com.xboe.module.course.dao.CourseDao;
|
||||
import com.xboe.module.course.dao.CourseTagDao;
|
||||
import com.xboe.module.course.dao.CourseTagRelationDao;
|
||||
import com.xboe.module.course.dao.CourseTypeTagRelationDao;
|
||||
import com.xboe.module.course.dto.CourseTagRelationDto;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseTag;
|
||||
import com.xboe.module.course.entity.CourseTagRelation;
|
||||
import com.xboe.module.course.entity.CourseTypeTagRelation;
|
||||
import com.xboe.module.course.service.ICourseService;
|
||||
import com.xboe.module.course.service.ICourseTagService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @ClassName:CourseTagServiceImpl
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/2516:55
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
@Transactional
|
||||
public class CourseTagServiceImpl implements ICourseTagService {
|
||||
|
||||
@Resource
|
||||
private CourseTagDao courseTagDao;
|
||||
@Resource
|
||||
PublishCourseUtil publishUtil;
|
||||
@Resource
|
||||
private CourseTagRelationDao courseTagRelationDao;
|
||||
|
||||
@Resource
|
||||
private CourseTypeTagRelationDao courseTypeTagRelationDao;
|
||||
@Resource
|
||||
private CourseDao courseDao;
|
||||
|
||||
/**
|
||||
* 课程标签分页查询
|
||||
* @param pageIndex
|
||||
* @param pageSize
|
||||
* @param filters
|
||||
* @param order
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageList<CourseTag> query(Integer pageIndex, Integer pageSize, List<IFieldFilter> filters, OrderCondition order) {
|
||||
try {
|
||||
/* QueryBuilder query=QueryBuilder.from(CourseTag.class);
|
||||
query.setPageIndex(pageIndex);
|
||||
query.setPageSize(pageSize);
|
||||
filters.add(FieldFilters.eq("deleted",false));
|
||||
query.addFilters(filters);
|
||||
if(order!=null) {
|
||||
query.addOrder(order);
|
||||
}else {
|
||||
query.addOrder(OrderCondition.desc("sysCreateTime"));
|
||||
}
|
||||
log.info("标签列表:分页查询 调用接口IMPL query = " + query.builder().toString());
|
||||
return courseTagDao.findPage(query.builder());*/
|
||||
|
||||
if(pageSize==100){
|
||||
log.info("--- 11 ----------------------");
|
||||
return courseTagDao.getList();
|
||||
}else{
|
||||
log.info("--- 22 ----------------------");
|
||||
QueryBuilder query = QueryBuilder.from(CourseTag.class);
|
||||
query.setPageIndex(pageIndex);
|
||||
query.setPageSize(pageSize);
|
||||
filters.add(FieldFilters.eq("deleted", false));
|
||||
// query.addFilters(filters);
|
||||
query.addOrder(OrderCondition.desc("sysCreateTime"));
|
||||
return courseTagDao.findPage(query.builder());
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("课程标签分页查询异常 = " + e.getMessage());
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询指定id标签关联的课程
|
||||
* @param pageIndex
|
||||
* @param pageSize
|
||||
* @param tagId
|
||||
* @param isAsc
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public PageList<CourseTagRelationDto> getCourseByTag(Integer pageIndex, Integer pageSize, Long tagId, Boolean isAsc) {
|
||||
PageList<CourseTagRelationDto> list = null;
|
||||
if(isAsc) {
|
||||
list = courseTagRelationDao.findCoursesWithRelatedTagsAsc(pageIndex,pageSize,tagId);
|
||||
}else {
|
||||
list = courseTagRelationDao.findCoursesWithRelatedTagsDesc(pageIndex,pageSize,tagId);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改指定id的课程标签的公共属性
|
||||
* @param id
|
||||
* @param isPublic
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void changePublicStatus(Long id, Boolean isPublic) {
|
||||
CourseTag courseTag = courseTagDao.findOne(FieldFilters.eq("id", String.valueOf(id)));
|
||||
if (courseTag!=null){
|
||||
courseTag.setIsPublic(isPublic);
|
||||
courseTag.setLastSetPublicTime(isPublic?LocalDateTime.now():null);
|
||||
courseTagDao.update(courseTag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改指定id的课程标签的热点属性
|
||||
* @param id
|
||||
* @param isHot
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void changeHotStatus(Long id, Boolean isHot) {
|
||||
CourseTag courseTag = courseTagDao.findOne(FieldFilters.eq("id", String.valueOf(id)));
|
||||
if (courseTag!=null){
|
||||
courseTag.setIsHot(isHot);
|
||||
courseTag.setLastSetHotTime(isHot?LocalDateTime.now():null);
|
||||
courseTagDao.update(courseTag);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 解除指定id的课程和某个标签之间的关联关系
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public void unbind(String id) {
|
||||
//根据主键查询关联关系
|
||||
CourseTagRelation courseTagRelation = courseTagRelationDao.findOne(FieldFilters.eq("id", id));
|
||||
if (courseTagRelation != null){
|
||||
//修改该标签关联课程数
|
||||
CourseTag courseTag = courseTagDao.findOne(FieldFilters.eq("id", String.valueOf(courseTagRelation.getTagId())));
|
||||
if (courseTag != null){
|
||||
courseTag.setUseCount(courseTag.getUseCount()>1?courseTag.getUseCount()-1:0);
|
||||
courseTagDao.updateFieldById(courseTag.getId(),"useCount",courseTag.getUseCount());
|
||||
}
|
||||
//解绑(删除关联关系)
|
||||
courseTagRelationDao.setDeleted(id);
|
||||
Course course = courseDao.get(courseTagRelation.getCourseId().toString());
|
||||
String tags = course.getTags();
|
||||
if (StringUtils.isNotBlank(tags)){
|
||||
String[] tagIds = tags.split(",");
|
||||
List<String> tagIdList = new ArrayList<>();
|
||||
for (String tagId : tagIds){
|
||||
if (!tagId.equals(courseTagRelation.getTagId().toString())){
|
||||
tagIdList.add(tagId);
|
||||
}
|
||||
}
|
||||
// 数据格式:1,2,3
|
||||
String s = StringUtils.join(tagIdList, ",");
|
||||
if (!"".equals(s)){
|
||||
s+=",";
|
||||
}
|
||||
course.setTags(s);
|
||||
}
|
||||
// 同步ES
|
||||
publishUtil.fullTextPublish(course);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据标签名称进行检索(模糊查询)
|
||||
* @param tagName
|
||||
* @return 符合检索条件的所有公共标签
|
||||
*/
|
||||
public List<CourseTag> searchTags(String tagName){
|
||||
QueryBuilder query=QueryBuilder.from(CourseTag.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("deleted",false));//未删除
|
||||
filters.add(FieldFilters.eq("isPublic",true));//公共标签
|
||||
filters.add(FieldFilters.like("tagName",tagName));//模糊检索
|
||||
query.addFilters(filters);
|
||||
List<CourseTag> courseTagList = courseTagDao.findList(query.builder());
|
||||
return courseTagList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CourseTag> searchTags(String tagName,String userId,String typeId){
|
||||
List<CourseTag> tagList = courseTagDao.searchTags(tagName,userId,typeId);
|
||||
return tagList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新标签,并与指定课程绑定
|
||||
* @return
|
||||
*/
|
||||
/*@Override
|
||||
public CourseTag createTag(CourseTagRelationDto courseTagRelationDto) {
|
||||
CourseTag courseTag = null;
|
||||
String tagName = courseTagRelationDto.getTagName();
|
||||
Long courseId = Long.valueOf(courseTagRelationDto.getCourseId());
|
||||
//1.创建标签:先判断是否已经存在该标签
|
||||
QueryBuilder query=QueryBuilder.from(CourseTag.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("tagName",tagName));//精确匹配
|
||||
query.addFilters(filters);
|
||||
List<CourseTag> courseTagList = courseTagDao.findList(query.builder());
|
||||
if (courseTagList==null || courseTagList.size()==0){//1.1 如果该标签不存在,则新建标签
|
||||
courseTag = new CourseTag();
|
||||
courseTag.setTagName(tagName);
|
||||
courseTag.setIsPublic(false);
|
||||
courseTag.setIsHot(false);
|
||||
courseTag.setUseCount(1);
|
||||
courseTagDao.save(courseTag);
|
||||
//新建一条标签和课程的关联关系
|
||||
CourseTagRelation courseTagRelation = new CourseTagRelation();
|
||||
courseTagRelation.setTagId(Long.valueOf(courseTag.getId()));
|
||||
courseTagRelation.setCourseId(courseId);
|
||||
courseTagRelationDao.save(courseTagRelation);
|
||||
}else {//1.2 否则修改标签
|
||||
courseTag=courseTagList.get(0);
|
||||
// 当同一标签被3个及以上课管创建时,默认开启这个标签的公共化
|
||||
if(courseTag.getUseCount() >= 3){
|
||||
courseTag.setIsPublic(true);
|
||||
}
|
||||
courseTag.setDeleted(false);//有可能是之前被删除的标签,这里恢复为有效
|
||||
//查找改课程与这个标签是否已经建立关联关系
|
||||
query=QueryBuilder.from(CourseTagRelation.class);
|
||||
filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("tagId",Long.valueOf(courseTag.getId())));//精确匹配
|
||||
filters.add(FieldFilters.eq("courseId",courseId));//精确匹配
|
||||
query.addFilters(filters);
|
||||
List<CourseTagRelation> courseTagRelationList = courseTagRelationDao.findList(query.builder());
|
||||
//1.2.1 如果还未建立关联关系,则新建一条标签和课程的关联关系
|
||||
if (courseTagRelationList==null || courseTagRelationList.size()==0){
|
||||
CourseTagRelation courseTagRelation = new CourseTagRelation();
|
||||
courseTagRelation.setTagId(Long.valueOf(courseTag.getId()));
|
||||
courseTagRelation.setCourseId(courseId);
|
||||
courseTagRelationDao.save(courseTagRelation);
|
||||
//更新该标签的关联课程数量
|
||||
courseTag.setUseCount(courseTag.getUseCount()+1);
|
||||
}else {//1.2.2 否则修改该标签和课程的关联关系
|
||||
CourseTagRelation courseTagRelation = courseTagRelationList.get(0);
|
||||
if (courseTagRelation.getDeleted()){//之前"解绑",这里恢复为有效
|
||||
courseTagRelation.setDeleted(false);
|
||||
courseTagRelationDao.saveOrUpdate(courseTagRelation);
|
||||
//更新该标签的关联课程数量
|
||||
courseTag.setUseCount(courseTag.getUseCount()+1);
|
||||
}
|
||||
}
|
||||
courseTagDao.saveOrUpdate(courseTag);
|
||||
}
|
||||
//2.创建该标签和课程分类之间的关联关系
|
||||
courseTagRelationDto.setTagId(courseTag.getId());
|
||||
createCourseTypeAndTagRelation(courseTagRelationDto);
|
||||
return courseTag;
|
||||
}
|
||||
*/
|
||||
@Override
|
||||
public CourseTag getTagByName(String tagName) {
|
||||
CourseTag courseTag = courseTagDao.getTagByName(tagName);
|
||||
return courseTag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CourseTag> getTagsByIds(String id) {
|
||||
// id=17,18
|
||||
List<CourseTag> courseTagList = courseTagDao.getTagsByIds(id);
|
||||
return courseTagList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取热门标签
|
||||
* @param courseTagRelationDto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public List<CourseTag> getHotTagList(CourseTagRelationDto courseTagRelationDto) {
|
||||
List<CourseTag> hotTagList = null;
|
||||
if (StringUtils.isNotBlank(courseTagRelationDto.getSysType1()) ||
|
||||
StringUtils.isNotBlank(courseTagRelationDto.getSysType2()) ||
|
||||
StringUtils.isNotBlank(courseTagRelationDto.getSysType3())){
|
||||
String sysType1 = courseTagRelationDto.getSysType1();
|
||||
String sysType2 = courseTagRelationDto.getSysType2();
|
||||
String sysType3 = courseTagRelationDto.getSysType3();
|
||||
hotTagList = courseTagDao.getHotTagListBySysTypes(sysType1,sysType2,sysType3);
|
||||
}else {
|
||||
hotTagList = courseTagDao.getHotTagList();
|
||||
}
|
||||
return hotTagList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建标签和课程分类之间的关联关系
|
||||
* @param courseTagRelationDto
|
||||
*/
|
||||
private void createCourseTypeAndTagRelation(CourseTagRelationDto courseTagRelationDto){
|
||||
String sysType1 = courseTagRelationDto!=null?courseTagRelationDto.getSysType1():null;
|
||||
String tagId = courseTagRelationDto!=null?courseTagRelationDto.getTagId():null;
|
||||
if (StringUtils.isNotBlank(sysType1) && StringUtils.isNotBlank(tagId)){
|
||||
String sysType2 = courseTagRelationDto.getSysType2();
|
||||
String sysType3 = courseTagRelationDto.getSysType3();
|
||||
//判断数据库中该课程分类和标签是否已经存在关联关系
|
||||
if (!isHadCourseTypeAndTagRelation(courseTagRelationDto,true)){//不存在,则新建
|
||||
CourseTypeTagRelation courseTypeTagRelation = new CourseTypeTagRelation();
|
||||
courseTypeTagRelation.setSysType1(sysType1);
|
||||
courseTypeTagRelation.setSysType2(StringUtils.isNotBlank(sysType2)?sysType2:"0");
|
||||
courseTypeTagRelation.setSysType3(StringUtils.isNotBlank(sysType3)?sysType3:"0");
|
||||
courseTypeTagRelation.setTagId(tagId);
|
||||
courseTypeTagRelationDao.save(courseTypeTagRelation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断数据库制定的课程分类和标签是否已经存在关联关系
|
||||
* @param courseTagRelationDto
|
||||
* @param clearFlag 清理标识 true:清理已存在的数据,只保留一条有效数据
|
||||
* @return true:已存在;false:不存在
|
||||
*/
|
||||
private Boolean isHadCourseTypeAndTagRelation(CourseTagRelationDto courseTagRelationDto,Boolean clearFlag){
|
||||
QueryBuilder query=QueryBuilder.from(CourseTypeTagRelation.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("sysType1",courseTagRelationDto.getSysType1()));//一级分类
|
||||
filters.add(FieldFilters.eq("sysType2",courseTagRelationDto.getSysType1()));//二级分类
|
||||
filters.add(FieldFilters.eq("sysType3",courseTagRelationDto.getSysType1()));//三级分类
|
||||
filters.add(FieldFilters.eq("tagId",courseTagRelationDto.getTagId()));
|
||||
List<CourseTypeTagRelation> courseTypeTagRelList = courseTypeTagRelationDao.findList(query.addFilters(filters).builder());
|
||||
Boolean isExist = (courseTypeTagRelList!=null && courseTypeTagRelList.size()>0)?true:false;
|
||||
if (isExist && clearFlag ){
|
||||
List<CourseTypeTagRelation> toRemove = new ArrayList<>();
|
||||
for (CourseTypeTagRelation courseTypeTagRel : courseTypeTagRelList) {
|
||||
if (courseTypeTagRel.getDeleted()) {//如果是逻辑删的本次物理删除
|
||||
courseTypeTagRelationDao.getGenericDao().delete(courseTypeTagRel);
|
||||
toRemove.add(courseTypeTagRel);
|
||||
}
|
||||
}
|
||||
courseTypeTagRelList.removeAll(toRemove);//移除逻辑删的数据
|
||||
//如果还存在有效数据
|
||||
if (courseTypeTagRelList!=null && courseTypeTagRelList.size()>0){
|
||||
//只保留一条有效数据,其余物理删除
|
||||
for (int i = courseTypeTagRelList.size() - 1; i >= 1; i--) {
|
||||
CourseTypeTagRelation courseTypeTagRel = courseTypeTagRelList.get(i);
|
||||
if (courseTypeTagRel.getDeleted()) {
|
||||
courseTypeTagRelationDao.getGenericDao().delete(courseTypeTagRel);
|
||||
courseTypeTagRelList.remove(i); // 倒序删除不影响未遍历的索引
|
||||
}
|
||||
}
|
||||
isExist = true;//存在一条有效数据
|
||||
}else {
|
||||
isExist = false;//不存在有效数据了
|
||||
}
|
||||
}
|
||||
return isExist;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建新标签
|
||||
* @param courseTagRelationDto
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public CourseTag createTag(CourseTagRelationDto courseTagRelationDto) {
|
||||
CourseTag courseTag = null;
|
||||
String tagName = courseTagRelationDto.getTagName();
|
||||
//1.创建标签:先判断是否已经存在该标签
|
||||
QueryBuilder query=QueryBuilder.from(CourseTag.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("tagName",tagName));//精确匹配
|
||||
filters.add(FieldFilters.eq("status",0));//正式
|
||||
filters.add(FieldFilters.eq("deleted",false));//未删除的
|
||||
query.addFilters(filters);
|
||||
List<CourseTag> courseTagList = courseTagDao.findList(query.builder());
|
||||
if (courseTagList==null || courseTagList.isEmpty()){//1.1 如果该标签不存在,则新建标签
|
||||
courseTag = new CourseTag();
|
||||
courseTag.setTagName(tagName);
|
||||
courseTag.setIsPublic(false);
|
||||
courseTag.setIsHot(false);
|
||||
courseTag.setStatus(1);
|
||||
courseTag.setUseCount(1);
|
||||
courseTagDao.save(courseTag);
|
||||
}
|
||||
return courseTag;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateTags(Course oldCourse, Course newCourse, CurrentUser userInfo) {
|
||||
log.info(" --- 标签修改 --- 在线课参数 oldCourse = {} " , oldCourse);
|
||||
log.info(" --- 标签修改 --- 在线课参数 newCourse = {} " , newCourse);
|
||||
log.info(" --- 标签修改 --- 用户信息 userInfo = {} " , userInfo);
|
||||
|
||||
// 获取新旧课程的标签ID列表
|
||||
List<String> oldTagIds = getTagIdsFromCourse(oldCourse);
|
||||
List<String> newTagIds = getTagIdsFromCourse(newCourse);
|
||||
log.info(" --- 旧标签 oldTagIds = {} " , oldTagIds);
|
||||
log.info(" --- 新修改 newTagIds = {} " , newTagIds);
|
||||
if (oldCourse == null) {
|
||||
// 新增课程 - 处理所有新标签
|
||||
handleNewCourseTags(newCourse, newTagIds, userInfo);
|
||||
} else {
|
||||
// 编辑课程 - 比较差异并处理
|
||||
handleEditCourseTags(oldCourse, newCourse, oldTagIds, newTagIds, userInfo);
|
||||
}
|
||||
log.info("完成课程标签更新: courseId={}", newCourse != null ? newCourse.getId() : "null");
|
||||
}
|
||||
|
||||
/**
|
||||
* 从课程对象中提取标签ID列表
|
||||
*/
|
||||
private List<String> getTagIdsFromCourse(Course course) {
|
||||
if (course == null || StringUtils.isBlank(course.getTags())) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
String tags = course.getTags();
|
||||
// 去除结尾的逗号并分割
|
||||
if (tags.endsWith(",")) {
|
||||
tags = tags.substring(0, tags.length() - 1);
|
||||
}
|
||||
|
||||
if (StringUtils.isBlank(tags)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
return Arrays.asList(tags.split(","));
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理新增课程的标签逻辑
|
||||
*/
|
||||
private void handleNewCourseTags(Course newCourse, List<String> newTagIds, CurrentUser userInfo) {
|
||||
log.info("处理新增课程的标签逻辑: courseId={}, tagCount={}", newCourse != null ? newCourse.getId() : "null", newTagIds.size());
|
||||
String courseId = newCourse.getId();
|
||||
|
||||
for (String tagId : newTagIds) {
|
||||
if (StringUtils.isBlank(tagId)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 获取标签信息
|
||||
CourseTag tag = courseTagDao.findOne(FieldFilters.eq("id", tagId.trim()));
|
||||
if (tag == null) {
|
||||
log.warn("标签不存在: {}", tagId);
|
||||
continue;
|
||||
}
|
||||
|
||||
//合并临时标签
|
||||
tag = mergeTag(tag);
|
||||
|
||||
// 创建课程-标签关联关系
|
||||
createCourseTagRelation(courseId, tag, userInfo);
|
||||
|
||||
// 创建分类-标签关联关系
|
||||
createCourseTypeTagRelations(newCourse, tag, userInfo);
|
||||
|
||||
// 更新标签使用计数并检查是否设置为公共标签
|
||||
updateTagUseCountAndPublicStatus(tag, userInfo);
|
||||
}
|
||||
log.info("完成新增课程标签处理: courseId={}", newCourse != null ? newCourse.getId() : "null");
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理编辑课程的标签逻辑
|
||||
*/
|
||||
private void handleEditCourseTags(Course oldCourse, Course newCourse,
|
||||
List<String> oldTagIds, List<String> newTagIds, CurrentUser userInfo) {
|
||||
log.info("处理编辑课程的标签逻辑: courseId={}, oldTagCount={}, newTagCount={}, toRemove={}, toAdd={}",
|
||||
newCourse != null ? newCourse.getId() : "null",
|
||||
oldTagIds.size(), newTagIds.size(),
|
||||
oldTagIds.stream().filter(tagId -> !newTagIds.contains(tagId)).count(),
|
||||
newTagIds.stream().filter(tagId -> !oldTagIds.contains(tagId)).count());
|
||||
|
||||
String courseId = newCourse.getId();
|
||||
|
||||
// 找出需要删除的标签(存在于旧课程但不在新课程中)
|
||||
List<String> tagsToRemove = oldTagIds.stream()
|
||||
.filter(tagId -> !newTagIds.contains(tagId))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 找出需要新增的标签(存在于新课程但不在旧课程中)
|
||||
List<String> tagsToAdd = newTagIds.stream()
|
||||
.filter(tagId -> !oldTagIds.contains(tagId))
|
||||
.collect(Collectors.toList());
|
||||
|
||||
// 处理标签删除
|
||||
for (String tagId : tagsToRemove) {
|
||||
removeCourseTagRelation(courseId, tagId, userInfo);
|
||||
}
|
||||
|
||||
// 处理标签新增
|
||||
for (String tagId : tagsToAdd) {
|
||||
CourseTag tag = courseTagDao.findOne(FieldFilters.eq("id", tagId.trim()));
|
||||
if (tag == null) {
|
||||
log.warn("标签不存在: {}", tagId);
|
||||
continue;
|
||||
}
|
||||
//如果已有同名的正式标签 则需要合并
|
||||
//合并临时标签
|
||||
tag = mergeTag(tag);
|
||||
|
||||
// 创建课程-标签关联关系
|
||||
createCourseTagRelation(courseId, tag, userInfo);
|
||||
|
||||
// 创建分类-标签关联关系
|
||||
createCourseTypeTagRelations(newCourse, tag, userInfo);
|
||||
|
||||
// 更新标签使用计数并检查是否设置为公共标签
|
||||
updateTagUseCountAndPublicStatus(tag, userInfo);
|
||||
}
|
||||
|
||||
// 处理分类变化导致的标签关联关系更新
|
||||
if (hasCourseTypeChanged(oldCourse, newCourse)) {
|
||||
updateCourseTypeTagRelations(oldCourse, newCourse, newTagIds, userInfo);
|
||||
}
|
||||
log.info("完成编辑课程标签处理: courseId={}", newCourse != null ? newCourse.getId() : "null");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 合并标签
|
||||
*/
|
||||
private CourseTag mergeTag(CourseTag tag){
|
||||
//只处理临时标签 正式的忽略
|
||||
if (tag.getStatus()==1){
|
||||
QueryBuilder query=QueryBuilder.from(CourseTag.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("tagName",tag.getTagName()));//精确匹配
|
||||
filters.add(FieldFilters.eq("status",0));//正式
|
||||
filters.add(FieldFilters.eq("deleted",false));//未删除的
|
||||
query.addFilters(filters);
|
||||
List<CourseTag> courseTagList = courseTagDao.findList(query.builder());
|
||||
log.info("标签合并 createTag courseTagList = {} " , courseTagList);
|
||||
//如果无同名正式标签 则转正
|
||||
//有同名正式标签 则合并
|
||||
if (courseTagList != null && !courseTagList.isEmpty()) {
|
||||
//删除临时标签
|
||||
tag.setSysUpdateBy("系统合并删除");
|
||||
tag.setSysUpdateTime(LocalDateTime.now());
|
||||
courseTagDao.setDeleted(tag.getId());
|
||||
//返回同名正式标签
|
||||
tag = courseTagList.get(0);
|
||||
}
|
||||
}
|
||||
return tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建课程-标签关联关系
|
||||
*/
|
||||
private void createCourseTagRelation(String courseId, CourseTag tag, CurrentUser userInfo) {
|
||||
log.debug("创建课程-标签关联关系: courseId={}, tagId={}, tagName={}",
|
||||
courseId, tag != null ? tag.getId() : "null", tag != null ? tag.getTagName() : "null");
|
||||
|
||||
// 检查是否已存在关联关系
|
||||
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("courseId", Long.valueOf(courseId)));
|
||||
filters.add(FieldFilters.eq("tagId", Long.valueOf(tag.getId())));
|
||||
query.addFilters(filters);
|
||||
|
||||
List<CourseTagRelation> existingRelations = courseTagRelationDao.findList(query.builder());
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
if (existingRelations.isEmpty()) {
|
||||
// 新建关联关系
|
||||
CourseTagRelation relation = new CourseTagRelation();
|
||||
relation.setCourseId(Long.valueOf(courseId));
|
||||
relation.setTagId(Long.valueOf(tag.getId()));
|
||||
|
||||
// 设置创建信息
|
||||
relation.setSysCreateAid(userInfo.getAccountId());
|
||||
relation.setSysCreateBy(userInfo.getName());
|
||||
relation.setSysCreateTime(now);
|
||||
|
||||
// 设置更新信息
|
||||
relation.setSysUpdateBy(userInfo.getName());
|
||||
relation.setSysUpdateTime(now);
|
||||
|
||||
courseTagRelationDao.save(relation);
|
||||
} else {
|
||||
// 恢复已删除的关联关系
|
||||
CourseTagRelation relation = existingRelations.get(0);
|
||||
if (relation.getDeleted()) {
|
||||
relation.setDeleted(false);
|
||||
|
||||
// 设置更新信息
|
||||
relation.setSysUpdateBy(userInfo.getName());
|
||||
relation.setSysUpdateTime(now);
|
||||
|
||||
courseTagRelationDao.saveOrUpdate(relation);
|
||||
}
|
||||
}
|
||||
log.debug("完成课程-标签关联关系创建: courseId={}, tagId={}", courseId, tag != null ? tag.getId() : "null");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建分类-标签关联关系
|
||||
*/
|
||||
private void createCourseTypeTagRelations(Course course, CourseTag tag, CurrentUser userInfo) {
|
||||
log.debug("创建分类-标签关联关系: courseId={}, tagId={}, sysType1={}, sysType2={}, sysType3={}",
|
||||
course != null ? course.getId() : "null",
|
||||
tag != null ? tag.getId() : "null",
|
||||
course != null ? course.getSysType1() : "null",
|
||||
course != null ? course.getSysType2() : "null",
|
||||
course != null ? course.getSysType3() : "null");
|
||||
|
||||
String sysType1 = course.getSysType1();
|
||||
String sysType2 = course.getSysType2();
|
||||
String sysType3 = course.getSysType3();
|
||||
|
||||
// 根据分类级别创建相应的关联关系
|
||||
if (StringUtils.isNotBlank(sysType3)) {
|
||||
createSingleCourseTypeTagRelation(sysType1, sysType2, sysType3, tag.getId(), userInfo);
|
||||
}else if (StringUtils.isNotBlank(sysType2)) {
|
||||
createSingleCourseTypeTagRelation(sysType1, sysType2, "0", tag.getId(), userInfo);
|
||||
}else if (StringUtils.isNotBlank(sysType1)) {
|
||||
createSingleCourseTypeTagRelation(sysType1, "0", "0", tag.getId(), userInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建单个分类-标签关联关系
|
||||
*/
|
||||
private void createSingleCourseTypeTagRelation(String sysType1, String sysType2, String sysType3,
|
||||
String tagId, CurrentUser userInfo) {
|
||||
// 检查是否已存在关联关系
|
||||
QueryBuilder query = QueryBuilder.from(CourseTypeTagRelation.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("sysType1", sysType1));
|
||||
filters.add(FieldFilters.eq("sysType2", sysType2));
|
||||
filters.add(FieldFilters.eq("sysType3", sysType3));
|
||||
filters.add(FieldFilters.eq("tagId", tagId));
|
||||
query.addFilters(filters);
|
||||
|
||||
List<CourseTypeTagRelation> existingRelations = courseTypeTagRelationDao.findList(query.builder());
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
if (existingRelations.isEmpty()) {
|
||||
// 新建关联关系
|
||||
CourseTypeTagRelation relation = new CourseTypeTagRelation();
|
||||
relation.setSysType1(sysType1);
|
||||
relation.setSysType2(sysType2);
|
||||
relation.setSysType3(sysType3);
|
||||
relation.setTagId(tagId);
|
||||
|
||||
// 设置创建信息
|
||||
relation.setSysCreateAid(userInfo.getAccountId());
|
||||
relation.setSysCreateBy(userInfo.getName());
|
||||
relation.setSysCreateTime(now);
|
||||
|
||||
// 设置更新信息
|
||||
relation.setSysUpdateBy(userInfo.getName());
|
||||
relation.setSysUpdateTime(now);
|
||||
|
||||
courseTypeTagRelationDao.save(relation);
|
||||
} else {
|
||||
// 恢复已删除的关联关系
|
||||
CourseTypeTagRelation relation = existingRelations.get(0);
|
||||
if (relation.getDeleted()) {
|
||||
relation.setDeleted(false);
|
||||
|
||||
// 设置更新信息
|
||||
relation.setSysUpdateBy(userInfo.getName());
|
||||
relation.setSysUpdateTime(now);
|
||||
|
||||
courseTypeTagRelationDao.saveOrUpdate(relation);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除课程-标签关联关系
|
||||
*/
|
||||
private void removeCourseTagRelation(String courseId, String tagId, CurrentUser userInfo) {
|
||||
log.debug("移除课程-标签关联关系: courseId={}, tagId={}", courseId, tagId);
|
||||
// 查找关联关系
|
||||
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("courseId", Long.valueOf(courseId)));
|
||||
filters.add(FieldFilters.eq("tagId", Long.valueOf(tagId)));
|
||||
query.addFilters(filters);
|
||||
|
||||
List<CourseTagRelation> relations = courseTagRelationDao.findList(query.builder());
|
||||
|
||||
if (!relations.isEmpty()) {
|
||||
CourseTagRelation relation = relations.get(0);
|
||||
|
||||
// 设置更新信息
|
||||
relation.setSysUpdateBy(userInfo.getName());
|
||||
relation.setSysUpdateTime(LocalDateTime.now());
|
||||
|
||||
// 逻辑删除关联关系
|
||||
courseTagRelationDao.setDeleted(relation.getId());
|
||||
|
||||
// 更新标签使用计数
|
||||
CourseTag tag = courseTagDao.findOne(FieldFilters.eq("id", tagId));
|
||||
if (tag != null) {
|
||||
tag.setUseCount(Math.max(0, tag.getUseCount() - 1));
|
||||
|
||||
// 设置更新信息
|
||||
tag.setSysUpdateBy(userInfo.getName());
|
||||
tag.setSysUpdateTime(LocalDateTime.now());
|
||||
|
||||
courseTagDao.update(tag);
|
||||
}
|
||||
|
||||
// 检查是否需要删除分类-标签关联关系
|
||||
checkAndRemoveCourseTypeTagRelation(tagId, userInfo);
|
||||
}
|
||||
log.debug("完成课程-标签关联关系移除: courseId={}, tagId={}", courseId, tagId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查并删除分类-标签关联关系(如果没有其他课程使用)
|
||||
*/
|
||||
private void checkAndRemoveCourseTypeTagRelation(String tagId, CurrentUser userInfo) {
|
||||
// 检查是否还有其他课程使用这个标签
|
||||
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("tagId", Long.valueOf(tagId)));
|
||||
filters.add(FieldFilters.eq("deleted", false));
|
||||
query.addFilters(filters);
|
||||
|
||||
List<CourseTagRelation> activeRelations = courseTagRelationDao.findList(query.builder());
|
||||
|
||||
// 如果没有其他活跃的关联关系,删除分类-标签关联
|
||||
if (activeRelations.isEmpty()) {
|
||||
QueryBuilder typeQuery = QueryBuilder.from(CourseTypeTagRelation.class);
|
||||
List<IFieldFilter> typeFilters = new ArrayList<>();
|
||||
typeFilters.add(FieldFilters.eq("tagId", tagId));
|
||||
typeQuery.addFilters(typeFilters);
|
||||
|
||||
List<CourseTypeTagRelation> typeRelations = courseTypeTagRelationDao.findList(typeQuery.builder());
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
for (CourseTypeTagRelation relation : typeRelations) {
|
||||
// 设置更新信息
|
||||
relation.setSysUpdateBy(userInfo.getName());
|
||||
relation.setSysUpdateTime(now);
|
||||
|
||||
courseTypeTagRelationDao.setDeleted(relation.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新标签使用计数并检查公共标签状态
|
||||
*/
|
||||
private void updateTagUseCountAndPublicStatus(CourseTag tag, CurrentUser userInfo) {
|
||||
log.debug("更新标签使用计数和公共状态: tagId={}, tagName={}, beforeUseCount={}",
|
||||
tag != null ? tag.getId() : "null",
|
||||
tag != null ? tag.getTagName() : "null",
|
||||
tag != null ? tag.getUseCount() : "null");
|
||||
|
||||
// 将标签状态设置为正式(status=0)
|
||||
if (tag != null && tag.getStatus() == 1) {
|
||||
tag.setStatus(0); // 正式标签
|
||||
}
|
||||
// 统计当前活跃的关联关系数量
|
||||
QueryBuilder query = QueryBuilder.from(CourseTagRelation.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("tagId", Long.valueOf(tag.getId())));
|
||||
filters.add(FieldFilters.eq("deleted", false));
|
||||
query.addFilters(filters);
|
||||
|
||||
List<CourseTagRelation> activeRelations = courseTagRelationDao.findList(query.builder());
|
||||
int activeCount = activeRelations.size();
|
||||
|
||||
tag.setUseCount(activeCount);
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
|
||||
// 检查是否满足设置为公共标签的条件
|
||||
if (activeCount >= 3 && tag.getLastSetPublicTime() == null) {
|
||||
// 只有从未手动关闭过公共标签的才自动开启
|
||||
tag.setIsPublic(true);
|
||||
tag.setLastSetPublicTime(now);
|
||||
}
|
||||
|
||||
// 设置更新信息
|
||||
tag.setSysUpdateBy(userInfo.getName());
|
||||
tag.setSysUpdateTime(now);
|
||||
|
||||
courseTagDao.update(tag);
|
||||
log.debug("完成标签使用计数和公共状态更新: tagId={}, tagName={}, afterUseCount={}, isPublic={}",
|
||||
tag != null ? tag.getId() : "null",
|
||||
tag != null ? tag.getTagName() : "null",
|
||||
tag != null ? tag.getUseCount() : "null",
|
||||
tag != null ? tag.getIsPublic() : "null");
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查课程分类是否发生变化
|
||||
*/
|
||||
private boolean hasCourseTypeChanged(Course oldCourse, Course newCourse) {
|
||||
return !Objects.equals(oldCourse.getSysType1(), newCourse.getSysType1()) ||
|
||||
!Objects.equals(oldCourse.getSysType2(), newCourse.getSysType2()) ||
|
||||
!Objects.equals(oldCourse.getSysType3(), newCourse.getSysType3());
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新分类-标签关联关系(当分类变化时)
|
||||
*/
|
||||
private void updateCourseTypeTagRelations(Course oldCourse, Course newCourse,
|
||||
List<String> tagIds, CurrentUser userInfo) {
|
||||
// 移除旧的分类-标签关联关系
|
||||
for (String tagId : tagIds) {
|
||||
checkAndRemoveCourseTypeTagRelation(tagId, userInfo);
|
||||
}
|
||||
|
||||
// 创建新的分类-标签关联关系
|
||||
for (String tagId : tagIds) {
|
||||
CourseTag tag = courseTagDao.findOne(FieldFilters.eq("id", tagId.trim()));
|
||||
if (tag != null) {
|
||||
createCourseTypeTagRelations(newCourse, tag, userInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置实体的创建信息(新增时使用)
|
||||
*/
|
||||
private void setCreateInfo(BaseEntity entity, CurrentUser userInfo) {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
entity.setSysCreateAid(userInfo.getAccountId());
|
||||
entity.setSysCreateBy(userInfo.getName());
|
||||
entity.setSysCreateTime(now);
|
||||
entity.setSysUpdateBy(userInfo.getName());
|
||||
entity.setSysUpdateTime(now);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置实体的更新信息(编辑时使用)
|
||||
*/
|
||||
private void setUpdateInfo(BaseEntity entity, CurrentUser userInfo) {
|
||||
entity.setSysUpdateBy(userInfo.getName());
|
||||
entity.setSysUpdateTime(LocalDateTime.now());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -79,13 +79,14 @@ xboe:
|
||||
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
|
||||
base-url: https://gateway-internal.boe.com
|
||||
app-key: 3edef300b25642da949ccddf58441a0f
|
||||
secret-key: 43bc8003a811a7f9c89cbecbfe4bbb22
|
||||
ai-api-code: 30800
|
||||
chat-api-code: 32065
|
||||
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
|
||||
file-upload-callback-url: http://10.251.113.95:9090/xboe/m/boe/caseDocumentLog/uploadCallback
|
||||
case-knowledge-id: f062c9e4-c6ad-437b-b5ca-bbb9fed9b442
|
||||
caseDetailUrlBase: https://u.boe.com/pc/case/detail?id=
|
||||
file-upload-callback-url: https://u.boe.com/systemapi/xboe/m/boe/caseDocumentLog/uploadCallback
|
||||
use-white-list: true
|
||||
white-user-code-list:
|
||||
- "00004409"
|
||||
@@ -108,10 +109,12 @@ xboe:
|
||||
- "00005011"
|
||||
- "10827857"
|
||||
- "11339772"
|
||||
- "pctest06"
|
||||
alert-email-recipients:
|
||||
- chengmeng@boe.com.cn
|
||||
- liyubing@boe.com.cn
|
||||
- lijian-hq@boe.com.cn
|
||||
ai-chat-root-path: /home/www/elearning/upload/ai/chat
|
||||
xxl:
|
||||
job:
|
||||
accessToken: 65ddc683-22f5-83b4-de3a-3c97a0a29af0
|
||||
|
||||
@@ -119,6 +119,7 @@ xboe:
|
||||
ai-api-code: 30800
|
||||
chat-api-code: 32065
|
||||
case-knowledge-id: de2e006e-82fb-4ace-8813-f25c316be4ff
|
||||
caseDetailUrlBase: https://u-pre.boe.com/pc/case/detail?id=
|
||||
file-upload-callback-url: http://10.251.186.27:9090/xboe/m/boe/caseDocumentLog/uploadCallback
|
||||
use-white-list: true
|
||||
white-user-code-list:
|
||||
@@ -144,6 +145,7 @@ xboe:
|
||||
- "11339772"
|
||||
alert-email-recipients:
|
||||
- chengmeng@boe.com.cn
|
||||
ai-chat-root-path: /home/www/elearning/upload/ai/chat
|
||||
jasypt:
|
||||
encryptor:
|
||||
algorithm: PBEWithMD5AndDES
|
||||
|
||||
@@ -1,215 +0,0 @@
|
||||
-- 数据迁移SQL(项目与报名)
|
||||
-- 执行顺序:
|
||||
-- 1.1 查看项目数据量
|
||||
-- 1.2 预览项目数据
|
||||
-- 1.3 迁移项目信息
|
||||
-- 1.4 验证项目迁移结果
|
||||
-- 2.1 查看报名数据量(按项目ID)
|
||||
-- 2.2 预览报名数据
|
||||
-- 2.3 获取新项目ID
|
||||
-- 2.4 写入报名数据(使用新项目ID)
|
||||
-- 2.5 验证报名迁移结果
|
||||
|
||||
-- 任务1:项目数据迁移(eln_boe_mixture_project -> boe_new.project_info),条件:is_deleted='0' AND program_name='社招新员工在线入职学习'
|
||||
-- 步骤1.1:查看符合条件的数据量(执行前验证)
|
||||
SELECT COUNT(*) AS data_count
|
||||
FROM elearninglms.eln_boe_mixture_project
|
||||
WHERE is_deleted = '0'
|
||||
AND program_name = '社招新员工在线入职学习';
|
||||
|
||||
-- 步骤1.2:查看要迁移的数据详情(执行前验证)
|
||||
SELECT *
|
||||
FROM elearninglms.eln_boe_mixture_project
|
||||
WHERE is_deleted = '0'
|
||||
AND program_name = '社招新员工在线入职学习';
|
||||
|
||||
-- 步骤1.3:执行数据迁移(INSERT INTO ... SELECT)
|
||||
INSERT INTO boe_new.project_info (
|
||||
name,
|
||||
pic_url,
|
||||
type,
|
||||
begin_time,
|
||||
end_time,
|
||||
manager_id,
|
||||
remark,
|
||||
status,
|
||||
num_value,
|
||||
introduction,
|
||||
new_type,
|
||||
deleted,
|
||||
unlock_mode,
|
||||
rank_flag,
|
||||
attach_switch,
|
||||
bpm_flag,
|
||||
load_flag,
|
||||
create_time,
|
||||
create_id,
|
||||
update_time,
|
||||
update_id
|
||||
)
|
||||
SELECT
|
||||
p.program_name AS name,
|
||||
p.theme_url AS pic_url,
|
||||
1 AS type, -- 项目类别固定为1
|
||||
CASE
|
||||
WHEN p.open_start_time IS NOT NULL AND p.open_start_time > 0
|
||||
THEN FROM_UNIXTIME(p.open_start_time)
|
||||
WHEN p.start_time IS NOT NULL AND p.start_time > 0
|
||||
THEN FROM_UNIXTIME(p.start_time)
|
||||
ELSE NULL
|
||||
END AS begin_time,
|
||||
CASE
|
||||
WHEN p.open_end_time IS NOT NULL AND p.open_end_time > 0
|
||||
THEN FROM_UNIXTIME(p.open_end_time)
|
||||
WHEN p.end_time IS NOT NULL AND p.end_time > 0
|
||||
THEN FROM_UNIXTIME(p.end_time)
|
||||
ELSE NULL
|
||||
END AS end_time,
|
||||
p.project_manager_id AS manager_id,
|
||||
COALESCE(p.program_desc, p.program_desc_nohtml, '') AS remark,
|
||||
CASE
|
||||
WHEN p.status = '0' THEN 0 -- 临时 → 草稿
|
||||
WHEN p.status = '1' THEN 1 -- 正常 → 已发布
|
||||
WHEN p.status = '2' THEN -1 -- 停用 → 已结束
|
||||
ELSE 0
|
||||
END AS status,
|
||||
p.program_code AS num_value,
|
||||
COALESCE(p.program_desc_nohtml, p.program_desc, '') AS introduction,
|
||||
2 AS new_type, -- 学习项目
|
||||
0 AS deleted, -- 未删除
|
||||
1 AS unlock_mode, -- 自由模式
|
||||
0 AS rank_flag, -- 不显示积分排行榜
|
||||
1 AS attach_switch, -- 共享文档开启
|
||||
0 AS bpm_flag, -- 报名审批关闭
|
||||
0 AS load_flag, -- 下载成绩关闭
|
||||
FROM_UNIXTIME(p.created_at) AS create_time,
|
||||
CAST(p.created_by AS UNSIGNED) AS create_id,
|
||||
FROM_UNIXTIME(COALESCE(p.updated_at, p.created_at)) AS update_time,
|
||||
CAST(COALESCE(p.updated_by, p.created_by) AS UNSIGNED) AS update_id
|
||||
FROM elearninglms.eln_boe_mixture_project p
|
||||
WHERE p.is_deleted = '0'
|
||||
AND p.program_name = '社招新员工在线入职学习'
|
||||
AND NOT EXISTS (
|
||||
-- 防止重复插入:如果项目名称已存在则跳过
|
||||
SELECT 1
|
||||
FROM boe_new.project_info pi
|
||||
WHERE pi.name = p.program_name
|
||||
AND pi.deleted = 0
|
||||
);
|
||||
|
||||
-- 步骤1.4:验证迁移结果
|
||||
SELECT
|
||||
COUNT(*) AS migrated_count,
|
||||
name,
|
||||
status,
|
||||
begin_time,
|
||||
end_time
|
||||
FROM boe_new.project_info
|
||||
WHERE name = '社招新员工在线入职学习'
|
||||
AND deleted = 0
|
||||
GROUP BY name, status, begin_time, end_time;
|
||||
|
||||
-- 任务2:项目报名数据迁移(eln_boe_mixture_project_enroll -> boe_base.boe_study_course)
|
||||
-- 迁移全部报名数据(包括已删除记录,按 is_deleted 映射状态)
|
||||
|
||||
-- 步骤2.1:查看符合条件的数据量(执行前验证)
|
||||
-- 注意:需要先将 '123xxx' 替换为实际的项目ID(kid)
|
||||
SELECT COUNT(*) AS enroll_count
|
||||
FROM elearninglms.eln_boe_mixture_project_enroll
|
||||
WHERE program_id = '123xxx'; -- 请替换为实际的项目ID(kid)
|
||||
|
||||
-- 步骤2.2:查看要迁移的数据详情(执行前验证)
|
||||
SELECT *
|
||||
FROM elearninglms.eln_boe_mixture_project_enroll
|
||||
WHERE program_id = '123xxx' -- 请替换为实际的项目ID(kid)
|
||||
LIMIT 100;
|
||||
|
||||
-- 步骤2.3:获取新项目ID
|
||||
SET @new_project_id = (
|
||||
SELECT id FROM boe_new.project_info
|
||||
WHERE name = '社招新员工在线入职学习' AND deleted = 0
|
||||
ORDER BY id DESC LIMIT 1
|
||||
);
|
||||
|
||||
-- 步骤2.4:写入报名数据(使用新项目ID)
|
||||
INSERT INTO boe_base.boe_study_course (
|
||||
course_id,
|
||||
course_type,
|
||||
course_name,
|
||||
aid,
|
||||
aname,
|
||||
source,
|
||||
add_time,
|
||||
start_time,
|
||||
last_score,
|
||||
status,
|
||||
progress,
|
||||
remark
|
||||
)
|
||||
SELECT
|
||||
pi.id AS course_id, -- 使用新项目表的自增ID
|
||||
90 AS course_type,
|
||||
COALESCE(pi.name, p.program_name, '') AS course_name,
|
||||
e.user_id AS aid,
|
||||
COALESCE(u.real_name, '') AS aname,
|
||||
CASE
|
||||
WHEN e.enroll_method = 'self' THEN 1
|
||||
WHEN e.enroll_method = 'admin' THEN 2
|
||||
WHEN e.enroll_method = 'manager' THEN 3
|
||||
ELSE 1
|
||||
END AS source,
|
||||
FROM_UNIXTIME(e.enroll_time) AS add_time,
|
||||
FROM_UNIXTIME(e.enroll_time) AS start_time,
|
||||
NULL AS last_score,
|
||||
CASE
|
||||
WHEN e.enroll_type = '1' AND e.approved_state = '1' AND e.is_deleted = '0' THEN 2
|
||||
WHEN e.enroll_type = '3' THEN 8
|
||||
WHEN e.cancel_state = '1' THEN 8
|
||||
WHEN e.is_deleted = '1' THEN 8
|
||||
ELSE 1
|
||||
END AS status,
|
||||
0 AS progress,
|
||||
CONCAT('迁移自项目报名表,报名ID:', e.kid) AS remark
|
||||
FROM elearninglms.eln_boe_mixture_project_enroll e
|
||||
LEFT JOIN elearninglms.eln_boe_mixture_project p
|
||||
ON e.program_id = p.kid
|
||||
LEFT JOIN boe_new.project_info pi
|
||||
ON p.program_name = pi.name AND pi.deleted = 0
|
||||
LEFT JOIN elearninglms.eln_fw_user u
|
||||
ON e.user_id = u.kid
|
||||
WHERE e.program_id = '123xxx' -- 请替换为实际的项目ID(kid)
|
||||
AND pi.id = @new_project_id -- 使用新项目ID
|
||||
AND NOT EXISTS (
|
||||
SELECT 1
|
||||
FROM boe_base.boe_study_course sc
|
||||
WHERE sc.course_id = @new_project_id
|
||||
AND sc.aid = e.user_id
|
||||
);
|
||||
|
||||
-- 步骤2.5:验证迁移结果
|
||||
SELECT
|
||||
COUNT(*) AS migrated_count,
|
||||
status,
|
||||
COUNT(CASE WHEN last_score IS NOT NULL THEN 1 END) AS has_score_count
|
||||
FROM boe_base.boe_study_course
|
||||
WHERE course_id = @new_project_id
|
||||
GROUP BY status;
|
||||
|
||||
-- 回滚SQL
|
||||
-- 回滚步骤R1:确认新项目ID(如变量丢失可重新获取)
|
||||
--SET @new_project_id = (
|
||||
-- SELECT id FROM boe_new.project_info
|
||||
-- WHERE name = '社招新员工在线入职学习' AND deleted = 0
|
||||
-- ORDER BY id DESC LIMIT 1
|
||||
--);
|
||||
--
|
||||
---- 回滚步骤R2:回滚报名数据(按备注标记,仅删除本次迁移写入的数据)
|
||||
--DELETE FROM boe_base.boe_study_course
|
||||
--WHERE course_id = @new_project_id
|
||||
-- AND remark LIKE '迁移自项目报名表%';
|
||||
--
|
||||
---- 回滚步骤R3:回滚项目信息(谨慎执行,确认仅影响本次迁移记录)
|
||||
--DELETE FROM boe_new.project_info
|
||||
--WHERE id = @new_project_id
|
||||
-- AND name = '社招新员工在线入职学习'
|
||||
-- AND deleted = 0;
|
||||
@@ -1,187 +0,0 @@
|
||||
# 数据迁移方案文档
|
||||
|
||||
## 一、迁移概述
|
||||
|
||||
本次迁移涉及两个数据迁移任务:
|
||||
1. **项目数据迁移**:从 `elearninglms.eln_boe_mixture_project` 迁移到 `boe_new.project_info`
|
||||
2. **项目报名数据迁移**:从 `elearninglms.eln_boe_mixture_project_enroll` 迁移到 `boe_base.boe_study_course`
|
||||
|
||||
---
|
||||
|
||||
## 二、任务1:项目数据迁移
|
||||
|
||||
### 2.1 迁移信息
|
||||
|
||||
- **源表**:`elearninglms.eln_boe_mixture_project`
|
||||
- **目标表**:`boe_new.project_info`
|
||||
- **迁移条件**:`is_deleted='0'` AND `program_name='社招新员工在线入职学习'`
|
||||
|
||||
### 2.2 字段映射关系
|
||||
|
||||
| 源表字段 | 目标表字段 | 说明 | 转换规则 |
|
||||
|---------|-----------|------|---------|
|
||||
| `kid` | - | 项目ID(varchar) | 不直接映射,目标表id为自增 |
|
||||
| `program_name` | `name` | 项目名称 | 直接映射 |
|
||||
| `program_desc` | `remark` | 项目描述/说明 | 直接映射 |
|
||||
| `theme_url` | `pic_url` | 封面图地址 | 直接映射 |
|
||||
| `start_time` / `open_start_time` | `begin_time` | 开始时间 | 优先使用 `open_start_time`,空则用 `start_time`,需转换为 timestamp |
|
||||
| `end_time` / `open_end_time` | `end_time` | 结束时间 | 优先使用 `open_end_time`,空则用 `end_time`,需转换为 timestamp |
|
||||
| `project_manager_id` | `manager_id` | 项目经理ID | 直接映射 |
|
||||
| `status` | `status` | 状态 | 需要转换:'0'→0(草稿), '1'→1(已发布), '2'→-1(已结束) |
|
||||
| `created_at` | `create_time` | 创建时间 | 需转换为 timestamp |
|
||||
| `created_by` | `create_id` | 创建人ID | 需转换为 bigint |
|
||||
| `updated_at` | `update_time` | 更新时间 | 需转换为 timestamp |
|
||||
| `updated_by` | `update_id` | 更新人ID | 需转换为 bigint |
|
||||
| `program_code` | `num_value` | 项目编号 | 直接映射 |
|
||||
| `program_desc` / `program_desc_nohtml` | `introduction` | 项目介绍 | 优先使用 `program_desc_nohtml` |
|
||||
|
||||
### 2.3 默认值设置
|
||||
|
||||
- `type`: 1(项目类别)
|
||||
- `new_type`: 2(学习项目)
|
||||
- `deleted`: 0(未删除)
|
||||
- `unlock_mode`: 1(自由模式)
|
||||
- `rank_flag`: 0(不显示积分排行榜)
|
||||
- `attach_switch`: 1(共享文档开启)
|
||||
- `bpm_flag`: 0(报名审批关闭)
|
||||
- `load_flag`: 0(下载成绩关闭)
|
||||
|
||||
### 2.4 注意事项
|
||||
|
||||
1. 目标表的 `id` 字段为自增主键,无需手动设置
|
||||
2. 时间字段需要从 int(时间戳)转换为 timestamp
|
||||
3. 状态字段需要根据源表的值进行映射转换
|
||||
4. 如果源表中存在多条符合条件的记录,需要确认是否全部迁移或仅迁移最新的一条
|
||||
|
||||
---
|
||||
|
||||
## 三、任务2:项目报名数据迁移
|
||||
|
||||
### 3.1 迁移信息
|
||||
|
||||
- **源表**:`elearninglms.eln_boe_mixture_project_enroll`
|
||||
- **目标表**:`boe_base.boe_study_course`
|
||||
- **迁移条件**:`program_id='123xxx'`(注意:实际执行时需要替换为真实的项目ID)
|
||||
- **重要说明**:**迁移全部报名数据,包括已删除的记录(is_deleted='1')**。已删除的记录在状态映射时会被标记为"终止"状态(status=8)
|
||||
|
||||
### 3.2 字段映射关系
|
||||
|
||||
| 源表字段 | 目标表字段 | 说明 | 转换规则 |
|
||||
|---------|-----------|------|---------|
|
||||
| `program_id` | `course_id` | 项目ID(作为课程ID) | 直接映射 |
|
||||
| `user_id` | `aid` | 学员ID | 直接映射 |
|
||||
| - | `last_score` | 学习成绩 | 初始设置为 NULL,后续需要从成绩表关联更新 |
|
||||
| `enroll_type` + `approved_state` | `status` | 完成状态 | 根据业务规则映射(见下方) |
|
||||
| `enroll_time` | `add_time` | 加入时间(报名时间) | 需转换为 datetime |
|
||||
| `enroll_time` | `start_time` | 开始学习时间 | 需转换为 datetime |
|
||||
|
||||
### 3.3 状态映射规则
|
||||
|
||||
根据 `boe_study_course` 表的 status 定义:
|
||||
- `STATUS_NOSTUDY = 1`(未开始学习)
|
||||
- `STATUS_STUDYING = 2`(学习中)
|
||||
- `STATUS_ABORTED = 8`(终止)
|
||||
- `STATUS_FINISH = 9`(学习完成)
|
||||
|
||||
**状态映射逻辑**:
|
||||
```sql
|
||||
CASE
|
||||
WHEN enroll_type = '1' AND approved_state = '1' AND is_deleted = '0' THEN 2 -- 报名成功且审批同意 → 学习中
|
||||
WHEN enroll_type = '3' THEN 8 -- 拒绝报名 → 终止
|
||||
WHEN cancel_state = '1' THEN 8 -- 取消审批同意 → 终止
|
||||
WHEN is_deleted = '1' THEN 8 -- 已删除 → 终止
|
||||
ELSE 1 -- 其他情况 → 未开始
|
||||
END AS status
|
||||
```
|
||||
|
||||
### 3.4 其他字段设置
|
||||
|
||||
- `course_type`: 需要根据项目类型设置(默认为项目类型对应的课程类型)
|
||||
- `course_name`: 需要关联项目表获取项目名称
|
||||
- `aname`: 需要关联用户表获取学员姓名
|
||||
- `source`: 根据 `enroll_method` 映射('self'→1, 'admin'→2, 'manager'→3)
|
||||
- `progress`: 初始设置为 0 或 NULL
|
||||
- `last_score`: 初始设置为 NULL,需要后续从成绩表更新
|
||||
|
||||
### 3.5 注意事项
|
||||
|
||||
1. **学习成绩(last_score)**:源表中没有直接的成绩字段,需要:
|
||||
- 方案A:从其他成绩表(如 `eln_ln_examination_result_user`)关联获取
|
||||
- 方案B:先设置为 NULL,后续通过业务逻辑更新
|
||||
|
||||
2. **完成状态(status)**:需要根据业务逻辑判断,当前映射规则仅供参考,实际使用时需要根据业务需求调整
|
||||
|
||||
3. **项目ID替换**:SQL中的 `'123xxx'` 需要替换为实际的项目ID
|
||||
|
||||
4. **数据去重**:确保 `(course_id, aid)` 组合的唯一性,避免重复插入
|
||||
|
||||
5. **关联查询**:可能需要关联用户表获取学员姓名等信息
|
||||
|
||||
6. **全部数据迁移**:本次迁移会包含所有符合条件的报名记录,包括已删除的记录。已删除的记录会根据 `is_deleted='1'` 映射为终止状态(status=8)
|
||||
|
||||
---
|
||||
|
||||
## 四、执行步骤
|
||||
|
||||
### 4.1 执行前准备
|
||||
|
||||
1. **备份数据**:执行迁移前,务必备份源表和目标表
|
||||
2. **验证条件**:确认迁移条件是否正确(特别是项目名称和项目ID)
|
||||
3. **数据检查**:检查源表中符合条件的数据量
|
||||
4. **环境确认**:确认目标数据库连接和权限
|
||||
|
||||
### 4.2 执行顺序
|
||||
|
||||
1. **先执行任务1**:迁移项目数据
|
||||
2. **获取新项目ID**:记录迁移后的项目ID(如果需要)
|
||||
3. **更新任务2的SQL**:将项目ID替换为实际值
|
||||
4. **执行任务2**:迁移项目报名数据
|
||||
|
||||
### 4.3 执行后验证
|
||||
|
||||
1. **数据量核对**:对比源表和目标表的记录数
|
||||
2. **关键字段验证**:抽查关键字段是否正确迁移
|
||||
3. **业务功能验证**:在系统中验证迁移后的数据是否正常
|
||||
|
||||
---
|
||||
|
||||
## 五、风险评估与回滚方案
|
||||
|
||||
### 5.1 风险点
|
||||
|
||||
1. **数据量**:如果数据量较大,可能影响系统性能
|
||||
2. **字段类型不匹配**:时间戳转换、状态值转换可能出错
|
||||
3. **数据完整性**:关联字段可能缺失或无效
|
||||
4. **业务逻辑**:状态映射规则可能与实际业务不符
|
||||
|
||||
### 5.2 回滚方案
|
||||
|
||||
1. **备份恢复**:使用备份数据恢复目标表
|
||||
2. **删除迁移数据**:根据迁移条件删除已迁移的数据
|
||||
3. **数据修复**:手动修复错误的数据
|
||||
|
||||
---
|
||||
|
||||
## 六、附录
|
||||
|
||||
### 6.1 相关表结构
|
||||
|
||||
- `elearninglms.eln_boe_mixture_project`:源项目表
|
||||
- `boe_new.project_info`:目标项目表
|
||||
- `elearninglms.eln_boe_mixture_project_enroll`:源报名表
|
||||
- `boe_base.boe_study_course`:目标课程学习表
|
||||
|
||||
### 6.2 状态值对照表
|
||||
|
||||
**项目状态映射**:
|
||||
- '0'(临时)→ 0(草稿)
|
||||
- '1'(正常)→ 1(已发布)
|
||||
- '2'(停用)→ -1(已结束)
|
||||
|
||||
**学习状态映射**:
|
||||
- 1:未开始学习
|
||||
- 2:学习中
|
||||
- 8:终止
|
||||
- 9:学习完成
|
||||
|
||||
---
|
||||
Reference in New Issue
Block a user