mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-08 02:16:49 +08:00
Compare commits
98 Commits
release-20
...
SZX-1194-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
aa9b24de1f | ||
|
|
4450e1b13a | ||
|
|
7efd586fdc | ||
|
|
385c3d1472 | ||
|
|
e3c94c97d2 | ||
|
|
186fc6e56f | ||
|
|
3cbfccf806 | ||
|
|
e513b08205 | ||
|
|
2191db1c95 | ||
|
|
6e2ffc9eaf | ||
|
|
6a33194818 | ||
|
|
5942a7dcd4 | ||
|
|
3ddc9d58f0 | ||
|
|
8112aea110 | ||
|
|
e8b31f4216 | ||
|
|
e83f3adb94 | ||
|
|
a14639283e | ||
|
|
8d9f400a7a | ||
|
|
933e7a018a | ||
|
|
4de8556802 | ||
|
|
757279e7ba | ||
|
|
0b9db10c04 | ||
|
|
a6335abcc7 | ||
|
|
7fd02ac25f | ||
|
|
344110fa1f | ||
|
|
6945b30828 | ||
|
|
347421ded4 | ||
|
|
2efe56ecda | ||
|
|
d47c0a891c | ||
|
|
fcce12aa0e | ||
|
|
064356a788 | ||
|
|
64034e6b04 | ||
|
|
71faee28da | ||
|
|
48d82cb7eb | ||
|
|
5848f431a4 | ||
|
|
d30853db33 | ||
|
|
8cf20e9681 | ||
|
|
ed7ca71434 | ||
|
|
437fc51c15 | ||
|
|
b9cf8de52a | ||
|
|
dc2cdf8b85 | ||
|
|
31eec36b00 | ||
|
|
b628eeae55 | ||
|
|
f4d5dd03df | ||
|
|
dcfb929aaf | ||
|
|
a50a29e33a | ||
|
|
10098e2e84 | ||
|
|
16712cc020 | ||
|
|
91cf87c8de | ||
|
|
2a3640b6e8 | ||
|
|
f5fc56c2d1 | ||
|
|
001106043c | ||
|
|
17999213cf | ||
|
|
9baa4c3595 | ||
|
|
9119aa8579 | ||
|
|
0b11c2ad9a | ||
|
|
cb4eb1b1b6 | ||
|
|
f9528a5705 | ||
|
|
28d84bd484 | ||
|
|
7f7279daa0 | ||
|
|
99042619d2 | ||
|
|
fb29e2b95c | ||
|
|
6bb4b6c4d5 | ||
|
|
264f31a69f | ||
|
|
7f3b50b45c | ||
|
|
f315a94c81 | ||
|
|
beeb3688a1 | ||
|
|
5cffd908f5 | ||
|
|
4d0f311bea | ||
|
|
0979d26160 | ||
|
|
ddd8875b11 | ||
|
|
d5a1d65769 | ||
|
|
612410e863 | ||
|
|
11628b35e2 | ||
|
|
f799b6065e | ||
|
|
61e753e6db | ||
|
|
841aa47b4a | ||
|
|
2527e081d9 | ||
|
|
9c529a061e | ||
|
|
15e0cedf74 | ||
|
|
46fefd3fe0 | ||
|
|
448bc0f1e4 | ||
|
|
5d3745680a | ||
|
|
c7c92a3173 | ||
|
|
0819502afa | ||
|
|
8c02b77724 | ||
|
|
e7036e04b0 | ||
|
|
95d1b90717 | ||
|
|
4d320ea855 | ||
|
|
acb58cf9d6 | ||
|
|
6a04e5d58c | ||
|
|
0e60251121 | ||
|
|
9588235f87 | ||
|
|
7074255e94 | ||
|
|
f821112715 | ||
|
|
41649aa32d | ||
|
|
6dc4e36222 | ||
|
|
5aba4ef45f |
@@ -366,6 +366,22 @@ public class ThirdApi {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 虽然当前已存在接口查询用户基本信息,目前仅仅包括用户名、工号、用户ID
|
||||
*/
|
||||
public List<UserBasicInfoVo> getUserBasicInfoByWorkNums(List<String> workNums) {
|
||||
|
||||
UserBasicInfoDto userBasicInfoDto = new UserBasicInfoDto();
|
||||
userBasicInfoDto.setWorkNums(workNums);
|
||||
Response<List<UserAccount>> response = userRemoteClient.getUserBasicInfo(userBasicInfoDto);
|
||||
String respStr = JSON.toJSONString(response);
|
||||
|
||||
UserBasicInfoResultVo userBasicInfoResult = JSONUtil.parseObj(respStr).toBean(UserBasicInfoResultVo.class);
|
||||
List<UserBasicInfoVo> basicInfos = userBasicInfoResult.getResult();
|
||||
return basicInfos;
|
||||
|
||||
}
|
||||
|
||||
public void updateOrSaveCourse(CourseParam param, String token){
|
||||
log.info("---------------准备同步在线课到讲师管理完毕 ------- param " + param);
|
||||
String resp = Optional.ofNullable(
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.xboe.api.vo;
|
||||
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@Data
|
||||
@Slf4j
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class UserBasicInfoResultVo {
|
||||
|
||||
private String error;
|
||||
private String message;
|
||||
private String permissions;
|
||||
private List<UserBasicInfoVo> result;
|
||||
private int status;
|
||||
private Date timestamp;
|
||||
|
||||
public UserBasicInfoResultVo success() {
|
||||
if (this.status != 200) {
|
||||
log.error("获取用户基本信息失败----{}", JSONUtil.toJsonPrettyStr(this));
|
||||
return null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.xboe.api.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UserBasicInfoVo {
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
/**
|
||||
* 用户名。
|
||||
*/
|
||||
private String userName;
|
||||
|
||||
/**
|
||||
* 工号。
|
||||
*/
|
||||
private String workNum;
|
||||
|
||||
/**
|
||||
* 邮箱
|
||||
*/
|
||||
private String email;
|
||||
}
|
||||
@@ -65,6 +65,24 @@ public class ThreadPoolConfig {
|
||||
return executor;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步存会话数据线程池
|
||||
* @return
|
||||
*/
|
||||
@Bean(name = "esChatExecutor")
|
||||
public ThreadPoolTaskExecutor esChatExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(10);
|
||||
executor.setMaxPoolSize(500);
|
||||
executor.setQueueCapacity(10);
|
||||
executor.setThreadNamePrefix("es-chat-");
|
||||
executor.setKeepAliveSeconds(300);
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
executor.setWaitForTasksToCompleteOnShutdown(true);
|
||||
executor.initialize();
|
||||
return executor;
|
||||
}
|
||||
|
||||
@Bean(name = "customDispatcher")
|
||||
public Dispatcher customDispatcher(@Qualifier("eventStreamExecutor") ThreadPoolTaskExecutor eventStreamExecutor) {
|
||||
return new Dispatcher(eventStreamExecutor.getThreadPoolExecutor());
|
||||
|
||||
@@ -7,4 +7,8 @@ public class CaseAiConstants {
|
||||
public static final String CASE_DOC_UPLOAD_INTERFACE_NAME = "文档上传";
|
||||
|
||||
public static final String CASE_DOC_DELETE_INTERFACE_NAME = "文档删除";
|
||||
|
||||
public static final String CHAT_SYS_ERR_MSG = "服务繁忙,请稍后再试。";
|
||||
|
||||
public static final String CHAT_NET_ERR_MSG = "网络异常,请稍后再试。";
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.xboe.module.assistance.service.impl;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
@@ -22,12 +23,13 @@ import com.xboe.module.assistance.service.ISmtpEmailService;
|
||||
@Slf4j
|
||||
public class SmtpEmailServiceImpl implements ISmtpEmailService {
|
||||
|
||||
// SMTP服务器配置信息
|
||||
//region 默认SMTP服务器配置信息
|
||||
private static final String SMTP_HOST = "mail.boe.com.cn";
|
||||
private static final String SMTP_USERNAME = "boeu_learning@boe.com.cn";
|
||||
private static final String SMTP_PASSWORD = "boeLms20250814Syse";
|
||||
private static final String SMTP_PASSWORD = "boeLms20251112Syse";
|
||||
private static final String SMTP_PORT = "465";
|
||||
private static final String SMTP_ENCRYPTION = "ssl";
|
||||
//endregion
|
||||
|
||||
@Override
|
||||
public void sendMailBySmtp(String to, String subject, String htmlMsg, String from) throws Exception {
|
||||
@@ -43,6 +45,7 @@ public class SmtpEmailServiceImpl implements ISmtpEmailService {
|
||||
if (StringUtils.isBlank(htmlMsg)) {
|
||||
throw new Exception("发送邮件失败,未指定邮件内容");
|
||||
}
|
||||
// 初始化配置项
|
||||
|
||||
// 设置SMTP属性
|
||||
Properties props = new Properties();
|
||||
|
||||
@@ -8,8 +8,6 @@ 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;
|
||||
@@ -17,18 +15,16 @@ 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.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* AI对话管理API
|
||||
*/
|
||||
@Slf4j
|
||||
@Slf4j(topic = "caseAiChatLogger")
|
||||
@RestController
|
||||
@RequestMapping(value = "/xboe/m/boe/case/ai")
|
||||
public class CaseAiChatApi extends ApiBaseController {
|
||||
@@ -64,6 +60,26 @@ public class CaseAiChatApi extends ApiBaseController {
|
||||
return caseAiChatService.chat(caseAiChatDto, getCurrent());
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止当前聊天输出
|
||||
* @param conversationId 会话ID
|
||||
* @return 是否成功停止
|
||||
*/
|
||||
@PostMapping("/stop")
|
||||
public JsonResponse<Boolean> stopChat(@RequestParam String conversationId) {
|
||||
try {
|
||||
boolean result = caseAiChatService.stopChatOutput(conversationId);
|
||||
if (result) {
|
||||
return success(true, "成功停止输出");
|
||||
} else {
|
||||
return success(false, "未找到对应的会话或会话已结束");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("停止聊天输出异常", e);
|
||||
return error("停止输出失败", e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据conversationId查看会话内消息记录
|
||||
* @param conversationId 会话ID
|
||||
@@ -90,32 +106,10 @@ public class CaseAiChatApi extends ApiBaseController {
|
||||
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);
|
||||
}
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||
LocalDate startDate = LocalDate.parse(startTime, formatter);
|
||||
LocalDate endDate = LocalDate.parse(endTime, formatter);
|
||||
caseAiChatService.getConversationExcel(startDate.atStartOfDay(), endDate.atTime(23, 59, 59), response);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -127,7 +121,10 @@ public class CaseAiChatApi extends ApiBaseController {
|
||||
try {
|
||||
String currentUserCode = getCurrent().getCode();
|
||||
boolean shouldShow = caseAiPermissionService.shouldShowCaseAiEntrance(currentUserCode);
|
||||
return success(shouldShow);
|
||||
// return success(shouldShow);
|
||||
JsonResponse<Boolean> result = success(shouldShow);
|
||||
result.setMessage(currentUserCode);
|
||||
return result;
|
||||
} catch (Exception e) {
|
||||
log.error("判断案例专家功能入口显示权限异常", e);
|
||||
return error("判断失败", e.getMessage());
|
||||
@@ -168,16 +165,4 @@ 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;
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,11 @@ public class CaseAiDocumentAsyncHandler {
|
||||
|
||||
private final AtomicInteger currentTaskCount = new AtomicInteger(0);
|
||||
|
||||
/**
|
||||
* 限流,默认QPS 40
|
||||
*/
|
||||
private final TokenBucketRateLimiter rateLimiter = new TokenBucketRateLimiter(40);
|
||||
|
||||
@Autowired
|
||||
@Qualifier("aiDocExecutor")
|
||||
private ThreadPoolTaskExecutor aiDocExecutor;
|
||||
@@ -27,7 +32,7 @@ public class CaseAiDocumentAsyncHandler {
|
||||
public void process(CaseDocumentLogOptTypeEnum optTypeEnum, Cases... caseList) {
|
||||
for (Cases cases : caseList) {
|
||||
// 控制并发数量
|
||||
while (currentTaskCount.get() >= 15) {
|
||||
while (currentTaskCount.get() >= 5) {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {
|
||||
@@ -39,8 +44,13 @@ public class CaseAiDocumentAsyncHandler {
|
||||
currentTaskCount.incrementAndGet();
|
||||
|
||||
aiDocExecutor.submit(() -> {
|
||||
processCases(cases, optTypeEnum);
|
||||
currentTaskCount.decrementAndGet();
|
||||
try {
|
||||
// 限流
|
||||
rateLimiter.acquire();
|
||||
processCases(cases, optTypeEnum);
|
||||
} finally {
|
||||
currentTaskCount.decrementAndGet();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -59,7 +69,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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
package com.xboe.module.boecase.async;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
/**
|
||||
* 令牌桶限流算法实现
|
||||
*/
|
||||
public class TokenBucketRateLimiter {
|
||||
|
||||
private final double permitsPerSecond; // 每秒生成的令牌数(即 TPS)
|
||||
private final AtomicLong nextFreeTicketMicros = new AtomicLong(0); // 下一个令牌可用的时间(微秒)
|
||||
private final AtomicLong storedPermits = new AtomicLong(0); // 当前桶中存储的令牌数(本简化版不支持突发,可省略)
|
||||
private static final long MICROSECONDS_PER_SECOND = 1_000_000L;
|
||||
|
||||
public TokenBucketRateLimiter(double permitsPerSecond) {
|
||||
this.permitsPerSecond = permitsPerSecond;
|
||||
this.nextFreeTicketMicros.set(System.nanoTime() / 1000); // 初始化为当前时间(微秒)
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一个令牌,阻塞直到可用
|
||||
*/
|
||||
public void acquire() {
|
||||
long waitMicros = reserve(1);
|
||||
if (waitMicros > 0) {
|
||||
try {
|
||||
long waitNanos = waitMicros * 1000; // 转为纳秒
|
||||
TimeUnit.NANOSECONDS.sleep(waitNanos);
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 预留 1 个令牌,返回需要等待的微秒数
|
||||
*/
|
||||
private long reserve(int permits) {
|
||||
long nowMicros = System.nanoTime() / 1000;
|
||||
long nextFreeTicket = nextFreeTicketMicros.get();
|
||||
long waitMicros = Math.max(0, nextFreeTicket - nowMicros);
|
||||
|
||||
long newNextFreeTicket = nowMicros + waitMicros + (long) (permits * MICROSECONDS_PER_SECOND / permitsPerSecond);
|
||||
while (!nextFreeTicketMicros.compareAndSet(nextFreeTicket, newNextFreeTicket)) {
|
||||
// CAS 失败,说明其他线程修改了时间,重试
|
||||
nowMicros = System.nanoTime() / 1000;
|
||||
nextFreeTicket = nextFreeTicketMicros.get();
|
||||
waitMicros = Math.max(0, nextFreeTicket - nowMicros);
|
||||
newNextFreeTicket = nowMicros + waitMicros + (long) (permits * MICROSECONDS_PER_SECOND / permitsPerSecond);
|
||||
}
|
||||
|
||||
return waitMicros;
|
||||
}
|
||||
}
|
||||
@@ -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 javax.servlet.http.HttpServletResponse;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
@@ -16,6 +17,7 @@ public interface ICaseAiChatService {
|
||||
|
||||
/**
|
||||
* 聊天
|
||||
*
|
||||
* @param caseAiChatDto
|
||||
* @param currentUser
|
||||
* @return
|
||||
@@ -24,7 +26,8 @@ public interface ICaseAiChatService {
|
||||
|
||||
/**
|
||||
* 创建新的AI对话会话
|
||||
* @param userId 用户ID
|
||||
*
|
||||
* @param userId 用户ID
|
||||
* @param conversationName 对话名称
|
||||
* @return 创建的会话信息
|
||||
*/
|
||||
@@ -32,6 +35,7 @@ public interface ICaseAiChatService {
|
||||
|
||||
/**
|
||||
* 根据conversationId查看会话内消息记录
|
||||
*
|
||||
* @param conversationId 会话ID
|
||||
* @return 消息记录列表
|
||||
*/
|
||||
@@ -41,6 +45,23 @@ public interface ICaseAiChatService {
|
||||
* 导出会话记录为Excel
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
* @param response
|
||||
*/
|
||||
void getConversationExcel(LocalDateTime startTime, LocalDateTime endTime, HttpServletResponse response);
|
||||
|
||||
/**
|
||||
* 导出会话记录为Excel
|
||||
*
|
||||
* @param startTime 开始时间
|
||||
* @param endTime 结束时间
|
||||
*/
|
||||
void downloadConversationExcel(LocalDateTime startTime, LocalDateTime endTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* 停止当前聊天输出
|
||||
*
|
||||
* @param conversationId 会话ID
|
||||
* @return 是否成功停止
|
||||
*/
|
||||
boolean stopChatOutput(String conversationId);
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
@EnableConfigurationProperties({CaseAiProperties.class})
|
||||
@Service
|
||||
@Slf4j
|
||||
@Slf4j(topic = "caseAiChatLogger")
|
||||
public class AiAccessTokenServiceImpl implements IAiAccessTokenService {
|
||||
|
||||
private static final String ACCESS_TOKEN_CACHE_KEY = "case_ai_access_token";
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.xboe.module.boecase.service.impl;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xboe.constants.CaseAiConstants;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.enums.CaseAiChatStatusEnum;
|
||||
@@ -22,13 +23,12 @@ 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;
|
||||
import okhttp3.sse.EventSourceListener;
|
||||
import okhttp3.sse.EventSources;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
@@ -40,30 +40,21 @@ import org.apache.poi.ss.usermodel.Sheet;
|
||||
import org.apache.poi.ss.usermodel.Workbook;
|
||||
import org.apache.poi.ss.util.CellRangeAddress;
|
||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||
import org.elasticsearch.action.index.IndexRequest;
|
||||
import org.elasticsearch.action.index.IndexResponse;
|
||||
import org.elasticsearch.action.search.SearchRequest;
|
||||
import org.elasticsearch.action.search.SearchResponse;
|
||||
import org.elasticsearch.client.RequestOptions;
|
||||
import org.elasticsearch.client.RestHighLevelClient;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.search.SearchHit;
|
||||
import org.elasticsearch.search.SearchHits;
|
||||
import org.elasticsearch.search.builder.SearchSourceBuilder;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
@@ -71,16 +62,21 @@ import java.nio.file.Paths;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@EnableConfigurationProperties({CaseAiProperties.class})
|
||||
@Service
|
||||
@Slf4j
|
||||
@Slf4j(topic = "caseAiChatLogger")
|
||||
public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
@Autowired
|
||||
private CaseAiProperties caseAiProperties;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("esChatExecutor")
|
||||
private ThreadPoolTaskExecutor esChatExecutor;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("customDispatcher")
|
||||
private Dispatcher dispatcher;
|
||||
@@ -102,6 +98,9 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
@Autowired
|
||||
private CasesDao casesDao;
|
||||
|
||||
// 用于存储会话ID与EventSource的映射关系,以便能够中断特定会话
|
||||
private final Map<String, EventSource> conversationEventSourceMap = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
@@ -114,7 +113,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
|
||||
} catch (Exception e) {
|
||||
log.error("获取会话ID失败", e);
|
||||
errMessage(sseEmitter, "服务繁忙,请稍后再试。");
|
||||
errMessage(sseEmitter, null, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||
sseEmitter.complete();
|
||||
return sseEmitter;
|
||||
}
|
||||
@@ -124,6 +123,13 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
// 3. 构建请求参数
|
||||
String userId = currentUser.getCode();
|
||||
|
||||
// 6. 用于收集对话数据的容器
|
||||
AiChatConversationData conversationData = new AiChatConversationData();
|
||||
conversationData.setQuery(caseAiChatDto.getQuery());
|
||||
conversationData.setConversationId(conversationId);
|
||||
conversationData.setUserId(userId);
|
||||
|
||||
String kId = caseAiProperties.getCaseKnowledgeId();
|
||||
JSONObject chatParam = new JSONObject();
|
||||
chatParam.put("userId", userId);
|
||||
@@ -154,10 +160,21 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
String accessToken;
|
||||
try {
|
||||
accessToken = aiAccessTokenService.getAccessToken();
|
||||
if (org.apache.commons.lang3.StringUtils.isBlank(accessToken)) {
|
||||
errMessage(sseEmitter, conversationId, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||
// 先响应给前端
|
||||
sseEmitter.complete();
|
||||
conversationData.appendAnswer(CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||
saveConversationData(conversationData);
|
||||
return sseEmitter;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("获取access_token失败", e);
|
||||
errMessage(sseEmitter, "服务繁忙,请稍后再试。");
|
||||
errMessage(sseEmitter, conversationId, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||
// 先响应给前端
|
||||
sseEmitter.complete();
|
||||
conversationData.appendAnswer(CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||
saveConversationData(conversationData);
|
||||
return sseEmitter;
|
||||
}
|
||||
String apiCode = caseAiProperties.getChatApiCode();
|
||||
@@ -168,26 +185,62 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
RequestBody bodyRequestBody = RequestBody.create(chatParamStr, MediaType.parse("application/json"));
|
||||
builder.post(bodyRequestBody);
|
||||
Request request = builder.build();
|
||||
|
||||
|
||||
// 6. 用于收集对话数据的容器
|
||||
AiChatConversationData conversationData = new AiChatConversationData();
|
||||
conversationData.setQuery(caseAiChatDto.getQuery());
|
||||
conversationData.setConversationId(conversationId);
|
||||
conversationData.setUserId(userId);
|
||||
|
||||
// 7. 创建事件监听器
|
||||
EventSourceListener listener = new EventSourceListener() {
|
||||
@Override
|
||||
public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
|
||||
// 检查contentType
|
||||
String contentType = response.header("Content-Type");
|
||||
if (contentType == null || !contentType.contains("text/event-stream")) {
|
||||
// 服务器返回的不是SSE流,需要额外处理
|
||||
log.error("调用接口 [{}] 返回的Content-Type不是text/event-stream,实际ContentType: {}", request.url(), contentType);
|
||||
String sseContent;
|
||||
try {
|
||||
ResponseBody responseBody = response.body();
|
||||
if (responseBody == null) {
|
||||
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||
} else {
|
||||
String responseBodyStr = responseBody.string();
|
||||
log.error("调用 [{}] 返回值: {}", request.url(), responseBodyStr);
|
||||
// 判断是否为json
|
||||
if (contentType != null && contentType.contains("application/json")) {
|
||||
JSONObject responseData = JSONObject.parseObject(responseBodyStr);
|
||||
if (responseData.containsKey("message") && StringUtils.isNotBlank(responseData.getString("message"))) {
|
||||
sseContent = responseData.getString("message");
|
||||
} else {
|
||||
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||
}
|
||||
} else {
|
||||
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("解析接口响应失败", e);
|
||||
// 处理失败的情况
|
||||
sseContent = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||
}
|
||||
|
||||
errMessage(sseEmitter, conversationId, sseContent);
|
||||
sseEmitter.complete();
|
||||
conversationData.appendAnswer(sseContent);
|
||||
saveConversationData(conversationData);
|
||||
// 关闭eventSource
|
||||
eventSource.cancel();
|
||||
return;
|
||||
}
|
||||
log.info("调用接口 [{}] 接口开始监听", request.url());
|
||||
// 将EventSource存储到Map中,以便后续可以中断
|
||||
conversationEventSourceMap.put(conversationId, eventSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClosed(@NotNull EventSource eventSource) {
|
||||
log.info("调用接口 [{}] 接口关闭", request.url());
|
||||
// 对话完成,保存到ES
|
||||
elasticSearchIndexService.createData(conversationData);
|
||||
saveConversationData(conversationData);
|
||||
// 从Map中移除已完成的会话
|
||||
conversationEventSourceMap.remove(conversationId);
|
||||
sseEmitter.complete();
|
||||
}
|
||||
|
||||
@@ -224,7 +277,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
} else {
|
||||
// 异常问题,取message内容
|
||||
String message = jsonData.getString("message");
|
||||
errMessage(sseEmitter, message);
|
||||
errMessage(sseEmitter, conversationId, message);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -246,20 +299,45 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
@Override
|
||||
public void onFailure(@NotNull EventSource eventSource, @Nullable Throwable e, @Nullable Response response) {
|
||||
log.error("调用接口 [{}] 接口异常", request.url(), e);
|
||||
|
||||
// 如果是 content-type 错误,尝试作为普通 HTTP 请求处理
|
||||
if (e instanceof IllegalStateException && e.getMessage() != null && e.getMessage().contains("Invalid content-type")) {
|
||||
log.warn("服务器返回的 Content-Type 不是 text/event-stream,尝试作为普通 HTTP 请求处理");
|
||||
handleAsRegularHttpRequest(request, sseEmitter, conversationData);
|
||||
return;
|
||||
}
|
||||
|
||||
// 只要有异常,必打日志
|
||||
if (e != null) {
|
||||
sseEmitter.completeWithError(e);
|
||||
log.error("调用接口 [{}] 时发生错误,捕获到异常", request.url(), e);
|
||||
} else {
|
||||
sseEmitter.completeWithError(new RuntimeException("调用接口异常, 异常未捕获"));
|
||||
log.error("调用接口 [{}] 时发生错误,未捕获到异常", request.url());
|
||||
}
|
||||
String errorMessage = CaseAiConstants.CHAT_SYS_ERR_MSG;
|
||||
// 优先处理错误响应
|
||||
if (response != null) {
|
||||
try {
|
||||
log.error("调用接口 [{}] 时发生错误,响应码: {}", request.url(), response.code());
|
||||
if (response.body() != null) {
|
||||
String body = response.body().string();
|
||||
log.error("调用接口 [{}] 时的错误响应内容: {}", request.url(), body);
|
||||
// 将错误内容发送至SseEmitter
|
||||
if (StringUtils.contains(response.header("Content-Type"), "application/json")) {
|
||||
// json解析
|
||||
JSONObject jsonData = JSONObject.parseObject(body);
|
||||
if (jsonData.containsKey("message") && StringUtils.isNotBlank(jsonData.getString("message"))) {
|
||||
errorMessage = jsonData.getString("message");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (IOException ex) {
|
||||
log.error("解析异常请求时错误", ex);
|
||||
}
|
||||
} else if (e != null) {
|
||||
if (isTimeoutException(e)) {
|
||||
errorMessage = CaseAiConstants.CHAT_NET_ERR_MSG;
|
||||
}
|
||||
}
|
||||
|
||||
errMessage(sseEmitter, conversationId, errorMessage);
|
||||
sseEmitter.complete();
|
||||
// 从Map中移除失败的会话
|
||||
conversationEventSourceMap.remove(conversationId);
|
||||
// 即使失败,也要将已有的对话数据保存到ES
|
||||
conversationData.appendAnswer(errorMessage);
|
||||
saveConversationData(conversationData);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -359,92 +437,24 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
return elasticSearchIndexService.queryData(conversationId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getConversationExcel(LocalDateTime startTime, LocalDateTime endTime, HttpServletResponse response) {
|
||||
Workbook workbook = getChatMessageExcel(startTime, endTime);
|
||||
// 写入response.getOutputStream()
|
||||
try (OutputStream out = response.getOutputStream()) {
|
||||
response.setContentType("application/octet-stream");
|
||||
response.setHeader("Content-Disposition", "attachment;filename=chat_message.xlsx");
|
||||
workbook.write(out);
|
||||
out.flush();
|
||||
} catch (Exception e) {
|
||||
log.error("导出Excel异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void downloadConversationExcel(LocalDateTime startTime, LocalDateTime endTime) {
|
||||
// 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文件并保存
|
||||
Workbook workbook = getChatMessageExcel(startTime, endTime);
|
||||
// 创建Excel文件并保存
|
||||
if (caseAiProperties.isAiChatDataSendEmail()) {
|
||||
// TODO 发送邮件附件
|
||||
} else {
|
||||
@@ -471,9 +481,13 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
/**
|
||||
* 从 ES 数据中解析消息对象
|
||||
* 已迁移
|
||||
* @see IElasticSearchIndexService
|
||||
*
|
||||
* @param sourceMap ES数据
|
||||
* @return 消息对象
|
||||
*/
|
||||
@Deprecated
|
||||
private CaseAiMessageVo parseMessageFromES(Map<String, Object> sourceMap) {
|
||||
try {
|
||||
CaseAiMessageVo messageVo = new CaseAiMessageVo();
|
||||
@@ -595,6 +609,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
/**
|
||||
* 处理文件引用(原方法,保留用于数据收集)
|
||||
*/
|
||||
@Deprecated
|
||||
private void handleFileRefer(JSONObject responseData, AiChatConversationData conversationData) {
|
||||
try {
|
||||
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
|
||||
@@ -682,7 +697,9 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
|
||||
/**
|
||||
* 当 SSE 失败时,作为普通 HTTP 请求处理
|
||||
* 不再使用
|
||||
*/
|
||||
@Deprecated
|
||||
private void handleAsRegularHttpRequest(Request request, SseEmitter sseEmitter, AiChatConversationData conversationData) {
|
||||
try {
|
||||
OkHttpClient client = new OkHttpClient.Builder()
|
||||
@@ -699,7 +716,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
// 将响应内容原封不动地推送到 SseEmitter
|
||||
JSONObject responseData = JSONObject.parseObject(responseBody);
|
||||
if (responseBody.contains("message")) {
|
||||
errMessage(sseEmitter, responseData.getString("message"));
|
||||
errMessage(sseEmitter, conversationData.getConversationId(), responseData.getString("message"));
|
||||
sseEmitter.complete();
|
||||
return;
|
||||
}
|
||||
@@ -715,15 +732,182 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||
}
|
||||
}
|
||||
|
||||
private void errMessage(SseEmitter sseEmitter, String message) {
|
||||
/**
|
||||
* 发送错误信息
|
||||
*/
|
||||
private void errMessage(SseEmitter sseEmitter, String conversationId, String message) {
|
||||
JSONObject conversationData = new JSONObject();
|
||||
conversationData.put("conversationId", conversationId);
|
||||
conversationData.put("content", "");
|
||||
conversationData.put("status", 0);
|
||||
|
||||
JSONObject jsonData = new JSONObject();
|
||||
jsonData.put("status", 1);
|
||||
jsonData.put("content", message);
|
||||
|
||||
JSONObject finishData = new JSONObject();
|
||||
jsonData.put("status", 4);
|
||||
jsonData.put("content", "");
|
||||
try {
|
||||
sseEmitter.send(conversationData.toJSONString());
|
||||
sseEmitter.send(jsonData.toJSONString());
|
||||
sseEmitter.send(finishData.toJSONString());
|
||||
} catch (IOException e) {
|
||||
log.error("发送错误信息异常", e);
|
||||
sseEmitter.completeWithError(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean stopChatOutput(String conversationId) {
|
||||
EventSource eventSource = conversationEventSourceMap.get(conversationId);
|
||||
if (eventSource != null) {
|
||||
try {
|
||||
// 取消事件源,中断连接
|
||||
eventSource.cancel();
|
||||
// 注意:cancel()会触发onFailure回调,在onFailure中会清理资源
|
||||
log.info("成功发送停止会话 {} 的指令", conversationId);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
log.error("停止会话 {} 输出时发生异常", conversationId, e);
|
||||
// 即使出现异常,也从Map中移除,避免内存泄漏
|
||||
conversationEventSourceMap.remove(conversationId);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
log.warn("未找到会话 {} 对应的事件源,可能已经完成或不存在", conversationId);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断Throwable是否为超时类异常
|
||||
* @param e
|
||||
* @return
|
||||
*/
|
||||
private boolean isTimeoutException(@Nullable Throwable e) {
|
||||
if (e == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ConnectException SocketTimeoutException
|
||||
if (e instanceof java.net.ConnectException || e instanceof java.net.SocketTimeoutException) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 可能是包装后的异常,递归检查 cause
|
||||
Throwable cause = e.getCause();
|
||||
while (cause != null) {
|
||||
if (cause instanceof java.net.ConnectException || cause instanceof java.net.SocketTimeoutException) {
|
||||
return true;
|
||||
}
|
||||
cause = cause.getCause();
|
||||
}
|
||||
|
||||
// 有些情况下 OkHttp 会抛出 IOException 并包含 "timeout" 字样
|
||||
if (e instanceof java.io.IOException) {
|
||||
String msg = e.getMessage();
|
||||
if (msg != null && msg.toLowerCase().contains("timeout")) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private Workbook getChatMessageExcel(LocalDateTime startTime, LocalDateTime endTime) {
|
||||
// 1. 根据startTime和endTime,查询在这个时间区间内的CaseAiConversations数据
|
||||
List<CaseAiConversations> conversations = caseAiConversationsDao.getGenericDao().findList(
|
||||
CaseAiConversations.class,
|
||||
FieldFilters.ge("sysCreateTime", startTime),
|
||||
FieldFilters.le("sysCreateTime", endTime)
|
||||
);
|
||||
|
||||
// 准备Excel数据
|
||||
List<ConversationExcelVo> excelDataList = new ArrayList<>();
|
||||
|
||||
// 2. 遍历这组数据,根据aiConversationId从es中查询数据(可调用getConversationMessages()方法)
|
||||
for (CaseAiConversations conversation : conversations) {
|
||||
String aiConversationId = conversation.getAiConversationId();
|
||||
String conversationName = conversation.getConversationName();
|
||||
String conversationUser = conversation.getConversationUser();
|
||||
|
||||
List<CaseAiMessageVo> messages = getConversationMessages(aiConversationId);
|
||||
|
||||
// 计算会话时长
|
||||
long duration = 0; // 默认为0,如果需要精确计算,需要从消息中提取时间信息
|
||||
|
||||
// 3. 写入Excel,包括每个会话的用户,会话标题,会话内的问答记录,每次对话时长等
|
||||
ConversationExcelVo excelData = new ConversationExcelVo();
|
||||
excelData.setConversationId(aiConversationId);
|
||||
excelData.setConversationName(conversationName);
|
||||
excelData.setUser(conversationUser);
|
||||
excelData.setMessages(messages);
|
||||
|
||||
excelDataList.add(excelData);
|
||||
}
|
||||
|
||||
// 写入Excel文件
|
||||
Workbook workbook = new XSSFWorkbook();
|
||||
Sheet sheet = workbook.createSheet("AI会话数据");
|
||||
// 标题行
|
||||
Row headerRow = sheet.createRow(0);
|
||||
headerRow.createCell(0).setCellValue("会话ID");
|
||||
headerRow.createCell(1).setCellValue("会话名称");
|
||||
headerRow.createCell(2).setCellValue("用户");
|
||||
headerRow.createCell(3).setCellValue("提问");
|
||||
headerRow.createCell(4).setCellValue("回答");
|
||||
headerRow.createCell(5).setCellValue("开始时间");
|
||||
headerRow.createCell(6).setCellValue("问答时长(秒)");
|
||||
|
||||
// 内容行
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return workbook;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步存储会话数据
|
||||
* @param conversationData
|
||||
*/
|
||||
private void saveConversationData(AiChatConversationData conversationData) {
|
||||
esChatExecutor.execute(() -> elasticSearchIndexService.createData(conversationData));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class ElasticSearchIndexServiceImpl implements IElasticSearchIndexService
|
||||
messageVo.setStartTime(LocalDateTime.parse(startTimeStr));
|
||||
}
|
||||
if (sourceMap.containsKey("durationSeconds")) {
|
||||
messageVo.setDurationSeconds((Long) sourceMap.get("durationSeconds"));
|
||||
messageVo.setDurationSeconds((Integer) sourceMap.get("durationSeconds"));
|
||||
}
|
||||
|
||||
// 解析 suggestions
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package com.xboe.module.boecase.task;
|
||||
|
||||
import com.xboe.constants.CaseAiConstants;
|
||||
import com.xboe.enums.CaseDocumentLogCaseStatusEnum;
|
||||
import com.xboe.enums.CaseDocumentLogOptStatusEnum;
|
||||
import com.xboe.enums.CaseDocumentLogOptTypeEnum;
|
||||
import com.xboe.enums.CaseDocumentLogRunStatusEnum;
|
||||
import com.xboe.module.boecase.async.CaseAiDocumentAsyncHandler;
|
||||
import com.xboe.module.boecase.dao.CaseDocumentLogDao;
|
||||
import com.xboe.module.boecase.dao.CasesDao;
|
||||
@@ -8,6 +12,7 @@ import com.xboe.module.boecase.entity.CaseDocumentLog;
|
||||
import com.xboe.module.boecase.entity.Cases;
|
||||
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -16,6 +21,8 @@ import javax.annotation.Resource;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* 旧案例上传
|
||||
@@ -40,6 +47,7 @@ public class CaseUploadTask {
|
||||
|
||||
@XxlJob("oldDataUploadJob")
|
||||
public void oldDataUploadJob() {
|
||||
String currentLastId = null;
|
||||
try {
|
||||
// log.info("开始执行旧案例上传任务");
|
||||
|
||||
@@ -55,6 +63,7 @@ public class CaseUploadTask {
|
||||
// log.info("没有需要处理的案例数据");
|
||||
return;
|
||||
}
|
||||
currentLastId = casesToProcess.get(casesToProcess.size() - 1).getId();
|
||||
|
||||
// 批量检查这些案例是否已在CaseDocumentLog中存在记录,提升性能
|
||||
List<String> caseIds = new ArrayList<>();
|
||||
@@ -70,14 +79,37 @@ public class CaseUploadTask {
|
||||
// 过滤出未在CaseDocumentLog中存在的案例
|
||||
List<Cases> casesList = new ArrayList<>();
|
||||
for (Cases cases : casesToProcess) {
|
||||
boolean exists = false;
|
||||
for (CaseDocumentLog log : existingLogs) {
|
||||
if (cases.getId().equals(log.getCaseId())) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!exists) {
|
||||
// boolean exists = false;
|
||||
// for (CaseDocumentLog log : existingLogs) {
|
||||
// if (cases.getId().equals(log.getCaseId())
|
||||
// && StringUtils.equals(log.getRequestUrl(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME)
|
||||
// && Objects.equals(log.getRunStatus(), CaseDocumentLogRunStatusEnum.COMPLETED.getCode())
|
||||
// && Objects.equals(log.getOptStatus(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode())
|
||||
// && Objects.equals(log.getRunStatus(), CaseDocumentLogCaseStatusEnum.SUCCESS.getCode())) {
|
||||
// exists = true;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// if (!exists) {
|
||||
// casesList.add(cases);
|
||||
// }
|
||||
List<CaseDocumentLog> thisCaseLogs = existingLogs.stream()
|
||||
.filter(log -> cases.getId().equals(log.getCaseId()))
|
||||
.collect(Collectors.toList());
|
||||
if (thisCaseLogs == null || thisCaseLogs.isEmpty()) {
|
||||
casesList.add(cases);
|
||||
} else if (thisCaseLogs.stream()
|
||||
.noneMatch(caseLog -> {
|
||||
// 1. 是否存在已上传完成的案例
|
||||
boolean hasCompleted = StringUtils.equals(caseLog.getRequestUrl(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME)
|
||||
&& Objects.equals(caseLog.getRunStatus(), CaseDocumentLogRunStatusEnum.COMPLETED.getCode())
|
||||
&& Objects.equals(caseLog.getOptStatus(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode())
|
||||
&& Objects.equals(caseLog.getRunStatus(), CaseDocumentLogCaseStatusEnum.SUCCESS.getCode());
|
||||
// 2. 是否存在上传中的案例
|
||||
boolean hasUploading = StringUtils.equals(caseLog.getRequestUrl(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME)
|
||||
&& Objects.equals(caseLog.getRunStatus(), CaseDocumentLogRunStatusEnum.RUNNING.getCode());
|
||||
return hasCompleted || hasUploading;
|
||||
})) {
|
||||
casesList.add(cases);
|
||||
}
|
||||
}
|
||||
@@ -88,17 +120,18 @@ public class CaseUploadTask {
|
||||
// 调用异步处理方法
|
||||
caseAiDocumentAsyncHandler.process(CaseDocumentLogOptTypeEnum.CREATE, casesList.toArray(new Cases[0]));
|
||||
|
||||
// 将当前处理的最后一条数据ID存入Redis
|
||||
String currentLastId = casesList.get(casesList.size() - 1).getId();
|
||||
stringRedisTemplate.opsForValue().set(CASE_UPLOAD_LAST_ID_KEY, currentLastId);
|
||||
// log.info("已处理案例,最后一条记录ID已更新为: {}", currentLastId);
|
||||
// } else {
|
||||
// log.info("没有新的案例需要处理");
|
||||
} else {
|
||||
log.info("没有新的案例需要处理");
|
||||
}
|
||||
// 将当前处理的最后一条数据ID存入Redis
|
||||
|
||||
// log.info("旧案例上传任务执行完成");
|
||||
} catch (Exception e) {
|
||||
log.error("执行旧案例上传任务时发生异常", e);
|
||||
} finally {
|
||||
if (currentLastId != null) {
|
||||
fixOnLastCase(currentLastId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,4 +160,9 @@ public class CaseUploadTask {
|
||||
|
||||
return casesDao.findList(queryBuilder.builder());
|
||||
}
|
||||
|
||||
private void fixOnLastCase(String currentLastId) {
|
||||
stringRedisTemplate.opsForValue().set(CASE_UPLOAD_LAST_ID_KEY, currentLastId);
|
||||
log.info("已处理案例,最后一条记录ID已更新为: {}", currentLastId);
|
||||
}
|
||||
}
|
||||
@@ -29,7 +29,7 @@ public class CaseAiMessageVo {
|
||||
/**
|
||||
* 会话时长(秒)
|
||||
*/
|
||||
private Long durationSeconds;
|
||||
private Integer durationSeconds;
|
||||
|
||||
/**
|
||||
* 案例引用列表
|
||||
|
||||
@@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.module.course.dto.CourseParam;
|
||||
import com.xboe.module.course.service.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
@@ -28,10 +29,6 @@ import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseAudit;
|
||||
import com.xboe.module.course.entity.CourseContent;
|
||||
import com.xboe.module.course.entity.CourseHRBPAudit;
|
||||
import com.xboe.module.course.service.ICourseAuditService;
|
||||
import com.xboe.module.course.service.ICourseContentService;
|
||||
import com.xboe.module.course.service.ICourseHRBPAuditService;
|
||||
import com.xboe.module.course.service.ICourseService;
|
||||
import com.xboe.standard.enums.BoedxContentType;
|
||||
import com.xboe.standard.enums.BoedxCourseType;
|
||||
|
||||
@@ -60,7 +57,8 @@ public class CourseAuditApi extends ApiBaseController{
|
||||
private ICourseContentService ccontentService;
|
||||
@Resource
|
||||
private ThirdApi thirdApi;
|
||||
|
||||
@Resource
|
||||
private ICourseTagService tagService;
|
||||
|
||||
/**
|
||||
* 教师需要审核的课程
|
||||
@@ -426,6 +424,21 @@ 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());
|
||||
if(oldCourse!=null && StringUtils.isNotEmpty(oldCourse.getTags())){
|
||||
String[] tagArray = oldCourse.getTags().split(",");
|
||||
// 检查每个元素是否为纯数字
|
||||
for (String tag : tagArray) {
|
||||
if (!tag.matches("\\d+")) { // 使用正则表达式检查是否为纯数字
|
||||
log.info("-------- 不是纯数字 ------- tag = {} " , tag);
|
||||
oldCourse.setTags(null); // 兼容
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
tagService.updateTags(oldCourse,dto.getCourse(),cuser);
|
||||
log.info("-----课程提审--- 标签相关结束 -------");
|
||||
|
||||
courseService.submitAndPublish(dto,cuser.getAccountId(),cuser.getName());
|
||||
log.info("---------------在线课开始同步到讲师管理 ------- token = " + token);
|
||||
|
||||
@@ -11,7 +11,12 @@ import com.boe.feign.api.serverall.entity.UserData;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
import com.xboe.core.orm.IFieldFilter;
|
||||
import com.xboe.core.orm.QueryBuilder;
|
||||
import com.xboe.data.outside.IOutSideDataService;
|
||||
import com.xboe.module.course.entity.CourseTag;
|
||||
import com.xboe.module.course.service.*;
|
||||
import com.xboe.module.course.vo.TeacherVo;
|
||||
import com.xboe.school.study.entity.StudyCourse;
|
||||
import com.xboe.school.study.service.IStudyCourseService;
|
||||
@@ -34,11 +39,6 @@ import com.xboe.module.course.dto.CourseTeacherDto;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseCrowd;
|
||||
import com.xboe.module.course.entity.CourseTeacher;
|
||||
import com.xboe.module.course.service.CourseToCourseFullText;
|
||||
import com.xboe.module.course.service.ICourseContentService;
|
||||
import com.xboe.module.course.service.ICourseFullTextSearch;
|
||||
import com.xboe.module.course.service.ICourseService;
|
||||
import com.xboe.module.course.service.ICourseTeacherService;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -63,7 +63,8 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
ICourseFullTextSearch fullTextSearch;
|
||||
@Resource
|
||||
IOrganizationService organizationService;
|
||||
|
||||
@Autowired
|
||||
ICourseTagService courseTagService;
|
||||
@Resource
|
||||
IStudyCourseService IStudyCourseService;
|
||||
|
||||
@@ -76,6 +77,8 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
@Autowired
|
||||
StringRedisTemplate redisTemplate;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 课程的初始化
|
||||
* @return
|
||||
@@ -310,7 +313,34 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
}
|
||||
|
||||
paras.setDevice(dto.getDevice());
|
||||
|
||||
String tagIds = dto.getTags();
|
||||
log.info("课程查询 tagIds = " + tagIds);
|
||||
if (tagIds != null && tagIds != ""){
|
||||
paras.setTags(tagIds);
|
||||
}else {
|
||||
String tagName = dto.getKeyword();
|
||||
log.info("课程查询 关键字 = " + tagName);
|
||||
if (StringUtils.isNotEmpty(tagName)){
|
||||
//精准查询
|
||||
// CourseTag courseTag = courseTagService.getTagByName(tagName);
|
||||
// log.info("课程查询 关键字对应标签 = " + courseTag);
|
||||
// if (courseTag != null){
|
||||
// paras.setTags(courseTag.getId());
|
||||
// }
|
||||
// 获取所有标签并进行模糊匹配
|
||||
List<CourseTag> allTags = courseTagService.getAllTags();
|
||||
List<String> matchedTagIds = new ArrayList<>();
|
||||
for (CourseTag tag : allTags) {
|
||||
// 使用模糊匹配(不区分大小写)
|
||||
if (tag.getTagName() != null && tag.getTagName().toLowerCase().contains(tagName.toLowerCase())) {
|
||||
matchedTagIds.add(tag.getId());
|
||||
}
|
||||
}
|
||||
if (!matchedTagIds.isEmpty()) {
|
||||
paras.setTags(String.join(",", matchedTagIds));
|
||||
}
|
||||
}
|
||||
}
|
||||
try {
|
||||
//后续会根据当前用户的资源归属查询
|
||||
PageList<CourseFullText> coursePageList = fullTextSearch.search(ICourseFullTextSearch.DEFAULT_INDEX_NAME,pager.getStartRow(), pager.getPageSize(),paras);
|
||||
@@ -402,6 +432,12 @@ public class CourseFullTextApi extends ApiBaseController{
|
||||
c.setKeywordsList(keywordsList);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isNotBlank(c.getTags()) && c.getTags().matches("[0-9,]+")) {
|
||||
List<CourseTag> tagList = courseTagService.getTagsByIds(c.getTags());
|
||||
List<String> tags = tagList.stream().map(CourseTag::getTagName).collect(Collectors.toList());
|
||||
c.setTagsList(tags);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -11,7 +11,11 @@ import javax.servlet.http.HttpServletResponse;
|
||||
import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
|
||||
import com.boe.feign.api.infrastructure.entity.Dict;
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.api.vo.UserBasicInfoVo;
|
||||
import com.xboe.module.course.dto.*;
|
||||
import com.xboe.module.course.entity.*;
|
||||
import com.xboe.module.course.service.*;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -31,19 +35,6 @@ import com.xboe.data.dto.UserOrgIds;
|
||||
import com.xboe.data.outside.IOutSideDataService;
|
||||
import com.xboe.data.service.IDataUserSyncService;
|
||||
import com.xboe.module.assistance.service.IEmailService;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseContent;
|
||||
import com.xboe.module.course.entity.CourseCrowd;
|
||||
import com.xboe.module.course.entity.CourseHRBPAudit;
|
||||
import com.xboe.module.course.entity.CourseSection;
|
||||
import com.xboe.module.course.entity.CourseTeacher;
|
||||
import com.xboe.module.course.entity.CourseUpdateLog;
|
||||
import com.xboe.module.course.service.ICourseContentService;
|
||||
import com.xboe.module.course.service.ICourseCrowdService;
|
||||
import com.xboe.module.course.service.ICourseHRBPAuditService;
|
||||
import com.xboe.module.course.service.ICourseSectionService;
|
||||
import com.xboe.module.course.service.ICourseService;
|
||||
import com.xboe.module.course.service.ICourseTeacherService;
|
||||
import com.xboe.module.excel.ExportsExcelSenderUtil;
|
||||
import com.xboe.standard.enums.BoedxContentType;
|
||||
import com.xboe.standard.enums.BoedxCourseType;
|
||||
@@ -94,7 +85,8 @@ public class CourseManageApi extends ApiBaseController{
|
||||
|
||||
@Resource
|
||||
private ICourseHRBPAuditService hrbpAuditService;
|
||||
|
||||
@Resource
|
||||
private ICourseTagService tagService;
|
||||
@Resource
|
||||
IOutSideDataService outSideDataService;
|
||||
|
||||
@@ -184,6 +176,12 @@ public class CourseManageApi extends ApiBaseController{
|
||||
rs.put("dicts",dicts);
|
||||
}
|
||||
log.error("-------是否仅内网查看 = " + isPermission);
|
||||
if (StringUtils.isNotBlank(course.getTags()) && course.getTags().matches("[0-9,]+")){
|
||||
List<CourseTag> tagList = tagService.getTagsByIds(course.getTags());
|
||||
rs.put("tagList", tagList);
|
||||
}
|
||||
|
||||
|
||||
rs.put("course",course);
|
||||
rs.put("contents",cclist);
|
||||
rs.put("sections",sectionlist);
|
||||
@@ -213,7 +211,7 @@ public class CourseManageApi extends ApiBaseController{
|
||||
}
|
||||
return success(rs);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 管理员审核列表,教师的审核不在这里,此审核也应该移动CourseAuditApi中去
|
||||
* @param pager
|
||||
@@ -302,6 +300,7 @@ public class CourseManageApi extends ApiBaseController{
|
||||
@PostMapping("/save")
|
||||
@AutoLog(module = "课程",action = "保存课程基本信息",info = "")
|
||||
public JsonResponse<CourseFullDto> saveCourseFull(@RequestBody CourseFullDto dto, HttpServletRequest request){
|
||||
log.info("-------- 保存课程的全部信息 ------- 课程信息 = {} " , dto.getCourse());
|
||||
if(dto.getCourse()==null){
|
||||
return badRequest("无课程信息");
|
||||
}
|
||||
@@ -322,6 +321,27 @@ public class CourseManageApi extends ApiBaseController{
|
||||
|
||||
//填充必要的信息
|
||||
try {
|
||||
log.info("-------- 标签相关开始 ------- 课程ID = {} " , dto.getCourse().getId());
|
||||
log.info("-------- 标签相关开始 ------- 课程TAG = {} " , dto.getCourse().getTags());
|
||||
CurrentUser userInfo = getCurrent();
|
||||
Course oldCourse = StringUtils.isBlank(dto.getCourse().getId()) ? null : courseService.get(dto.getCourse().getId());
|
||||
log.info("-------- 标签相关 ------- oldtags = {} " , oldCourse.getTags());
|
||||
if(oldCourse!=null && StringUtils.isNotEmpty(oldCourse.getTags())){
|
||||
String[] tagArray = oldCourse.getTags().split(",");
|
||||
// 检查每个元素是否为纯数字
|
||||
for (String tag : tagArray) {
|
||||
if (!tag.matches("\\d+")) { // 使用正则表达式检查是否为纯数字
|
||||
log.info("-------- 不是纯数字 -------oldtags tag = {} " , tag);
|
||||
oldCourse.setTags(null); // 兼容
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("-------- 标签相关 updateTags ------- oldtags = {} " , oldCourse.getTags());
|
||||
log.info("-------- 标签相关 updateTags ------- newtags = {} " , dto.getCourse().getTags());
|
||||
tagService.updateTags(oldCourse,dto.getCourse(),userInfo);
|
||||
log.info("-------- 标签相关结束 ------newtags = {} " , dto.getCourse().getTags());
|
||||
|
||||
if(StringUtils.isBlank(dto.getCourse().getId())) {
|
||||
//只有在第一次添加保存时才会这样
|
||||
fillCourseData(dto.getCourse());
|
||||
@@ -349,8 +369,6 @@ public class CourseManageApi extends ApiBaseController{
|
||||
|
||||
/***
|
||||
* 仅仅是保存
|
||||
* @param dto
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/save-only-course")
|
||||
@AutoLog(module = "课程",action = "保存课程基本信息",info = "")
|
||||
@@ -377,6 +395,10 @@ public class CourseManageApi extends ApiBaseController{
|
||||
//修改后重置,重新提交审核,重新发布
|
||||
courseService.update(course,true);
|
||||
}
|
||||
//查询是否需要标签提示
|
||||
String aid=getCurrent().getAccountId();
|
||||
Boolean isTip = courseService.getCourseTip(aid);
|
||||
course.setIsTip(isTip);
|
||||
return success(course);
|
||||
} catch (Exception e) {
|
||||
log.error("整体保存课程信息错误",e);
|
||||
@@ -565,7 +587,10 @@ public class CourseManageApi extends ApiBaseController{
|
||||
dto.getCourse().getOrgName(),
|
||||
dto.getCourse().getSysCreateBy(),dto.getCourse().getName());
|
||||
//邮件发送
|
||||
String email=dto.getAuditUser().getEmail();
|
||||
String email= this.getEmail(dto.getAuditUser().getCode());
|
||||
if (StringUtils.isBlank( email)) {
|
||||
email=dto.getAuditUser().getEmail();
|
||||
}
|
||||
if(!isLocalDevelopment()) {
|
||||
//只是非开发模式下才可以发送
|
||||
service.sendMail(email,"《"+dto.getCourse().getName()+"》课程审核提醒", htmlEmail,"数字化学习平台");
|
||||
@@ -583,7 +608,26 @@ public class CourseManageApi extends ApiBaseController{
|
||||
return error("提交课程处理失败",e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getEmail(String code) {
|
||||
if (StringUtils.isBlank( code)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
List<String> workNums = new ArrayList(1){{
|
||||
add(code);
|
||||
}};
|
||||
List<UserBasicInfoVo> userBasicInfoVoList = thirdApi.getUserBasicInfoByWorkNums(workNums);
|
||||
if (CollectionUtils.isEmpty(userBasicInfoVoList)) {
|
||||
return null;
|
||||
}
|
||||
return userBasicInfoVoList.get(0).getEmail();
|
||||
} catch (Exception e) {
|
||||
log.error("获取用户邮箱错误",e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String createEmailHtml(String name,String orgId, String orgName,String createBy,String courseName) throws Exception {
|
||||
StringBuffer htmlMsg=new StringBuffer("<div style=\"line-height:30px;border:2px solid #2990ca;padding:20px\">");
|
||||
|
||||
@@ -694,6 +738,10 @@ public class CourseManageApi extends ApiBaseController{
|
||||
//邮件发送
|
||||
if(!isLocalDevelopment()) {
|
||||
//只是非高度环境上才会发送
|
||||
String newEmail = getEmail(ucode);
|
||||
if (StringUtils.isNotBlank(newEmail)) {
|
||||
email = newEmail;
|
||||
}
|
||||
service.sendMail(email,"《"+course.getName()+"》课程审核提醒",htmlEmail,"数字化学习平台");
|
||||
}
|
||||
|
||||
@@ -727,7 +775,6 @@ public class CourseManageApi extends ApiBaseController{
|
||||
|
||||
/**
|
||||
* 审核课程,这个是管理人员的审核。老师审核不在这里处理.
|
||||
* @param id
|
||||
* @param title
|
||||
* @param pass
|
||||
* @param remark
|
||||
@@ -761,7 +808,6 @@ public class CourseManageApi extends ApiBaseController{
|
||||
|
||||
/**
|
||||
* 审核并发布,未完成的处理,
|
||||
* @param id
|
||||
* @param title
|
||||
* @param pass
|
||||
* @param remark
|
||||
@@ -805,10 +851,6 @@ public class CourseManageApi extends ApiBaseController{
|
||||
|
||||
/**
|
||||
* 发布课程信息,已经没有单独的发布了
|
||||
* @param id
|
||||
* @param title
|
||||
* @param pass
|
||||
* @param remark
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
@@ -1206,5 +1248,10 @@ public class CourseManageApi extends ApiBaseController{
|
||||
return success(courses);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("/saveTip")
|
||||
public JsonResponse<Boolean> saveTip(){
|
||||
String aid=getCurrent().getAccountId();
|
||||
courseService.saveTip(aid);
|
||||
return success(true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,10 +13,7 @@ import com.xboe.module.course.dto.CourseTeacherDto;
|
||||
import com.xboe.module.course.dto.RankingDto;
|
||||
import com.xboe.module.course.dto.TeacherCourseDto;
|
||||
import com.xboe.module.course.entity.*;
|
||||
import com.xboe.module.course.service.ICourseContentService;
|
||||
import com.xboe.module.course.service.ICourseSectionService;
|
||||
import com.xboe.module.course.service.ICourseService;
|
||||
import com.xboe.module.course.service.ICourseTeacherService;
|
||||
import com.xboe.module.course.service.*;
|
||||
import com.xboe.module.course.vo.CourseStudyVo;
|
||||
import com.xboe.module.course.vo.TeacherVo;
|
||||
import com.xboe.module.teacher.entity.Teacher;
|
||||
@@ -33,6 +30,7 @@ import com.xboe.system.user.entity.User;
|
||||
import com.xboe.system.user.service.IUserService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
@@ -97,6 +95,8 @@ public class CoursePortalApi extends ApiBaseController{
|
||||
|
||||
@Autowired
|
||||
StringRedisTemplate redisTemplate;
|
||||
@Resource
|
||||
private ICourseTagService courseTagService;
|
||||
|
||||
/**
|
||||
* 根据多个课程id返回对应的课程的图片.返回结果如下,
|
||||
@@ -261,7 +261,14 @@ public class CoursePortalApi extends ApiBaseController{
|
||||
if(course==null || course.getDeleted()){
|
||||
return badRequest("课程不存在或已被删除");
|
||||
}
|
||||
rs.put("course",course);
|
||||
Course course1 = new Course();
|
||||
BeanUtils.copyProperties(course,course1);
|
||||
if (StringUtils.isNotBlank(course.getTags()) && course.getTags().matches("[0-9,]+")) {
|
||||
List<CourseTag> tagList = courseTagService.getTagsByIds(course.getTags());
|
||||
String tags = tagList.stream().map(CourseTag::getTagName).collect(Collectors.joining(","));
|
||||
course1.setTags(tags);
|
||||
}
|
||||
rs.put("course",course1);
|
||||
|
||||
List<CourseCrowd> courseCrowdList = courseService.findCrowdByCourseId(id);
|
||||
if(crowd!=null && crowd) {
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
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;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @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();
|
||||
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 (StringUtils.isNotBlank(courseTagRelationDto.getTagName()) && !Pattern.matches("^[\\u4e00-\\u9fa5a-zA-Z0-9_-]+$", courseTagRelationDto.getTagName())) {
|
||||
return error("标签名称只能包含中文、英文、数字、下划线和中横线");
|
||||
}
|
||||
if (courseTagRelationDto!=null){
|
||||
CourseTag courseTag = courseTagService.createTag(courseTagRelationDto);
|
||||
if (courseTag == null ){
|
||||
return error("创建标签失败!");
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
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 AND r.deleted =0 \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"; // 数据库字段为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),FieldFilters.eq("deleted", false),FieldFilters.eq("status", 0));
|
||||
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 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 = 0 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(" UNION ALL ");
|
||||
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 = 1 AND status = 0 ");
|
||||
if (StringUtils.isNotBlank(tagName)) {
|
||||
sql.append(" AND tag_name LIKE ? ");
|
||||
parameters.add("%" + tagName + "%");
|
||||
}
|
||||
sql.append(") AS all_tags ");
|
||||
|
||||
if (StringUtils.isNotBlank(typeId)) {
|
||||
sql.append("ORDER BY ");
|
||||
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_update_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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package com.xboe.module.course.dao;
|
||||
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.core.orm.BaseDao;
|
||||
import com.xboe.module.course.dto.CourseTagRelationDto;
|
||||
import com.xboe.module.course.entity.CourseTagRelation;
|
||||
import org.springframework.stereotype.Repository;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
import javax.persistence.Query;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @ClassName:CourseTagRelationDao
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/2815:09
|
||||
*/
|
||||
@Repository
|
||||
public class CourseTagRelationDao extends BaseDao<CourseTagRelation> {
|
||||
|
||||
@PersistenceContext
|
||||
private EntityManager entityManager;
|
||||
|
||||
private String sqlStr = "SELECT " +
|
||||
" r1.id as id, " +
|
||||
" c.id as courseId, " +
|
||||
" r1.tag_id as tagId, " +
|
||||
" c.`name` as courseName, " +
|
||||
" r1.sys_create_by as sysCreateBy, " +
|
||||
" r1.sys_create_time as sysCreateTime, " +
|
||||
" COALESCE(GROUP_CONCAT(DISTINCT t.tag_name ORDER BY t.tag_name), '') AS otherTags " +
|
||||
"FROM " +
|
||||
" boe_course c " +
|
||||
"JOIN " +
|
||||
" boe_course_tag_relation r1 ON c.id = r1.course_id " +
|
||||
"LEFT JOIN " +
|
||||
" ( " +
|
||||
" boe_course_tag_relation r2 " +
|
||||
" JOIN boe_course_tag t ON r2.tag_id = t.id AND t.deleted = 0 " +
|
||||
" ) " +
|
||||
" ON c.id = r2.course_id AND r2.tag_id != r1.tag_id " +
|
||||
"WHERE " +
|
||||
" r1.tag_id = :tagId AND r1.deleted = 0 " +
|
||||
" AND c.id IN ( " +
|
||||
" SELECT course_id " +
|
||||
" FROM boe_course_tag_relation " +
|
||||
" WHERE tag_id = :tagId " +
|
||||
" ) " +
|
||||
"GROUP BY " +
|
||||
" c.id, c.`name` ";
|
||||
|
||||
public PageList<CourseTagRelationDto> findCoursesWithRelatedTagsDesc(Integer pageIndex, Integer pageSize, Long tagId){
|
||||
String sql = sqlStr + " ORDER BY r1.sys_create_time DESC";
|
||||
Query query = entityManager.createNativeQuery(sql);
|
||||
query.setParameter("tagId", tagId);
|
||||
query.setFirstResult((pageIndex - 1) * pageSize); // 设置起始位置
|
||||
query.setMaxResults(pageSize); // 设置每页大小
|
||||
|
||||
Query countQuery = entityManager.createNativeQuery(sql);
|
||||
countQuery.setParameter("tagId", tagId);
|
||||
List<Object[]> totalresults = countQuery.getResultList();
|
||||
|
||||
List<Object[]> results = query.getResultList();
|
||||
List<CourseTagRelationDto> list = results.stream()
|
||||
.map(row -> {
|
||||
String id = String.valueOf(row[0]);
|
||||
String courseId = String.valueOf(row[1]);
|
||||
String tagId2 = String.valueOf(row[2]);
|
||||
return new CourseTagRelationDto(
|
||||
id,
|
||||
courseId,
|
||||
tagId2,
|
||||
(String) row[3],
|
||||
(String) row[4],
|
||||
(Date) row[5],
|
||||
(String) row[6]
|
||||
);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return new PageList<CourseTagRelationDto>(list,totalresults!=null?totalresults.size():0);
|
||||
}
|
||||
|
||||
public PageList<CourseTagRelationDto> findCoursesWithRelatedTagsAsc(Integer pageIndex, Integer pageSize, Long tagId) {
|
||||
String sql = sqlStr + " ORDER BY r1.sys_create_time ASC";
|
||||
Query query = entityManager.createNativeQuery(sql);
|
||||
query.setParameter("tagId", tagId);
|
||||
query.setFirstResult((pageIndex - 1) * pageSize); // 设置起始位置
|
||||
query.setMaxResults(pageSize); // 设置每页大小
|
||||
|
||||
Query countQuery = entityManager.createNativeQuery(sql);
|
||||
countQuery.setParameter("tagId", tagId);
|
||||
List<Object[]> totalresults = countQuery.getResultList();
|
||||
|
||||
List<Object[]> results = query.getResultList();
|
||||
List<CourseTagRelationDto> list = results.stream()
|
||||
.map(row ->{
|
||||
String id = String.valueOf(row[0]);
|
||||
String courseId = String.valueOf(row[1]);
|
||||
String tagId2 = String.valueOf(row[2]);
|
||||
return new CourseTagRelationDto(
|
||||
id,
|
||||
courseId,
|
||||
tagId2,
|
||||
(String) row[3],
|
||||
(String) row[4],
|
||||
(Date) row[5],
|
||||
(String) row[6]
|
||||
);
|
||||
})
|
||||
.collect(Collectors.toList());
|
||||
return new PageList<CourseTagRelationDto>(list,totalresults!=null?totalresults.size():0);
|
||||
}
|
||||
|
||||
public void reTagRelDelStatus(String id,String name) {
|
||||
String sql = "UPDATE boe_course_tag_relation SET deleted = FALSE, sys_update_by = '" + name +
|
||||
"', sys_update_time = NOW() WHERE id = " + id;
|
||||
Query query = entityManager.createNativeQuery(sql);
|
||||
query.executeUpdate();
|
||||
}
|
||||
|
||||
public void reTypeTagRelDelStatus(String id,String name) {
|
||||
String sql = "UPDATE boe_course_type_tag_relation SET deleted = FALSE, sys_update_by = '" + name +
|
||||
"', sys_update_time = NOW() WHERE id = " + id;
|
||||
Query query = entityManager.createNativeQuery(sql);
|
||||
query.executeUpdate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.xboe.module.course.dao;
|
||||
|
||||
import com.xboe.core.orm.BaseDao;
|
||||
import com.xboe.module.course.entity.CourseTagRelation;
|
||||
import com.xboe.module.course.entity.CourseTypeTagRelation;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
/**
|
||||
* @ClassName:CourseTypeTagRelationDao
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/8/113:42
|
||||
*/
|
||||
@Repository
|
||||
public class CourseTypeTagRelationDao extends BaseDao<CourseTypeTagRelation> {
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package com.xboe.module.course.dao;
|
||||
|
||||
import com.xboe.core.orm.BaseDao;
|
||||
import com.xboe.module.course.entity.ThreadLog;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public class ThreadLogDao extends BaseDao<ThreadLog> {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.xboe.module.course.dao;
|
||||
|
||||
import com.xboe.core.orm.BaseDao;
|
||||
import com.xboe.module.course.entity.Tip;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
|
||||
@Slf4j
|
||||
@Repository
|
||||
public class TipDao extends BaseDao<Tip> {
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.xboe.module.course.dto;
|
||||
|
||||
import com.xboe.module.course.entity.CourseTag;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
@@ -140,4 +141,6 @@ public class CourseQueryDto {
|
||||
*/
|
||||
private String userId;
|
||||
|
||||
private String tags;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.xboe.module.course.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 课程标签查询的条件对象
|
||||
* @ClassName:CourseTagQueryDto
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/2517:02
|
||||
*/
|
||||
@Data
|
||||
public class CourseTagQueryDto {
|
||||
|
||||
/**
|
||||
* 标签id
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
private String tagName;
|
||||
|
||||
|
||||
/**
|
||||
* 是否热点标签( 0-否(默认) 1-是)
|
||||
*/
|
||||
private Boolean isHot;
|
||||
|
||||
/**
|
||||
* 排序字段
|
||||
*/
|
||||
private String orderField;
|
||||
|
||||
/**
|
||||
* 排序顺序
|
||||
*/
|
||||
private Boolean orderAsc;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.xboe.module.course.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @ClassName:CourseTagRelationDto
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/2815:00
|
||||
*/
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
public class CourseTagRelationDto{
|
||||
|
||||
private String id;
|
||||
private String courseId;
|
||||
private String tagId;
|
||||
private String tagName;
|
||||
private String courseName;
|
||||
private String sysCreateBy;
|
||||
private Date sysCreateTime;
|
||||
private String otherTags; // 改为字符串类型,与 GROUP_CONCAT 结果匹配
|
||||
private String sysType1;
|
||||
private String sysType2;
|
||||
private String sysType3;
|
||||
|
||||
// 添加匹配查询字段顺序的构造函数
|
||||
public CourseTagRelationDto(
|
||||
String id,
|
||||
String courseId,
|
||||
String tagId,
|
||||
String courseName,
|
||||
String sysCreateBy,
|
||||
Date sysCreateTime,
|
||||
String otherTags
|
||||
) {
|
||||
this.id = id;
|
||||
this.courseId = courseId;
|
||||
this.tagId = tagId;
|
||||
this.courseName = courseName;
|
||||
this.sysCreateBy = sysCreateBy;
|
||||
this.sysCreateTime = sysCreateTime;
|
||||
this.otherTags = otherTags;
|
||||
}
|
||||
}
|
||||
@@ -399,7 +399,13 @@ public class Course extends BaseEntity {
|
||||
|
||||
@Transient
|
||||
private String teacher;
|
||||
|
||||
|
||||
/**
|
||||
* 新增在线课时是否需要标签提示
|
||||
*/
|
||||
@Transient
|
||||
private Boolean isTip;
|
||||
|
||||
public Course(String id,String name,String summary,String coverImg,String sysCreateAid,String sysCreateBy,Integer type,LocalDateTime publishTime){
|
||||
super.setId(id);
|
||||
this.name=name;
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
package com.xboe.module.course.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.orm.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 在线课程的标签类
|
||||
* @ClassName:CourseTag
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/25 16:37
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Entity
|
||||
@Table(name = SysConstant.TABLE_PRE+"course_tag")
|
||||
public class CourseTag extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 标签名称
|
||||
*/
|
||||
@Column(name = "tag_name",nullable=false, length = 50)
|
||||
private String tagName;
|
||||
|
||||
/**
|
||||
* 是否设置为公共标签
|
||||
*/
|
||||
@Column(name = "is_public",length = 1)
|
||||
private Boolean isPublic;
|
||||
|
||||
/**
|
||||
* 是否设置为热点标签
|
||||
*/
|
||||
@Column(name = "is_hot",length = 1)
|
||||
private Boolean isHot;
|
||||
|
||||
/**
|
||||
* 使用次数(关联课程数)
|
||||
*/
|
||||
@Column(name = "use_count",length = 1)
|
||||
private Integer useCount;
|
||||
|
||||
/**
|
||||
* 1临时, 0正式
|
||||
*/
|
||||
@Column(name = "status",length = 1)
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 最近设置为公共标签的时间
|
||||
*/
|
||||
@Column(name = "last_set_public_time", nullable = true)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime lastSetPublicTime;
|
||||
|
||||
/**
|
||||
* 最近设置为热点标签的时间
|
||||
*/
|
||||
@Column(name = "last_set_hot_time", nullable = true)
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
private LocalDateTime lastSetHotTime;
|
||||
|
||||
public CourseTag() {
|
||||
|
||||
}
|
||||
public CourseTag(Long id, Boolean isPublic,Boolean isHot) {
|
||||
this.setId(String.valueOf(id));
|
||||
this.isPublic=isPublic;
|
||||
this.isHot=isHot;
|
||||
}
|
||||
|
||||
|
||||
public CourseTag(String id,String tagName,String sysCreateBy,String sysCreateAid,LocalDateTime sysCreateTime,
|
||||
Boolean isPublic,Boolean isHot,Integer useCount,LocalDateTime lastSetPublicTime,LocalDateTime lastSetHotTime,Boolean deleted){
|
||||
this.setId(id);
|
||||
this.setTagName(tagName);
|
||||
super.setSysCreateBy(sysCreateBy);
|
||||
super.setSysCreateAid(sysCreateAid);
|
||||
super.setSysCreateTime(sysCreateTime);
|
||||
this.isPublic = isPublic;
|
||||
this.isHot = isHot;
|
||||
this.useCount = useCount;
|
||||
this.lastSetPublicTime = lastSetPublicTime;
|
||||
this.lastSetHotTime = lastSetHotTime;
|
||||
super.setDeleted(deleted);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.xboe.module.course.entity;
|
||||
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.orm.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @ClassName:CourseTagRelation
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/7/2814:54
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Entity
|
||||
@Table(name = SysConstant.TABLE_PRE+"course_tag_relation")
|
||||
public class CourseTagRelation extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 课程Id
|
||||
*/
|
||||
@Column(name = "course_id",length = 20)
|
||||
private Long courseId;
|
||||
|
||||
/**
|
||||
* 标签id
|
||||
*/
|
||||
@Column(name = "tag_id",length = 20)
|
||||
private Long tagId;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.xboe.module.course.entity;
|
||||
|
||||
import com.xboe.core.SysConstant;
|
||||
import com.xboe.core.orm.BaseEntity;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Table;
|
||||
|
||||
/**
|
||||
* @ClassName:CourseTypeTagRelation
|
||||
* @author:zhengge@oracle.com
|
||||
* @since:2025/8/111:02
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Entity
|
||||
@Table(name = SysConstant.TABLE_PRE+"course_type_tag_relation")
|
||||
public class CourseTypeTagRelation extends BaseEntity {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Column(name = "sys_type1",length = 20)
|
||||
private String sysType1;
|
||||
|
||||
@Column(name = "sys_type2",length = 20)
|
||||
private String sysType2;
|
||||
|
||||
@Column(name = "sys_type3",length = 20)
|
||||
private String sysType3;
|
||||
|
||||
@Column(name = "tag_id",length = 20)
|
||||
private String tagId;
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
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.GeneratedValue;
|
||||
import javax.persistence.GenerationType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.Table;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 线程日志表实体
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = SysConstant.TABLE_PRE + "thread_log")
|
||||
public class ThreadLog {
|
||||
|
||||
/**
|
||||
* 主键ID
|
||||
*/
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", columnDefinition = "BIGINT UNSIGNED COMMENT '主键'")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 系统/子系统标识
|
||||
*/
|
||||
@Column(name = "system_name", nullable = false, length = 64)
|
||||
private String systemName;
|
||||
|
||||
/**
|
||||
* 功能模块
|
||||
*/
|
||||
@Column(name = "module_name", nullable = false, length = 64)
|
||||
private String moduleName;
|
||||
|
||||
/**
|
||||
* 具体动作/事件
|
||||
*/
|
||||
@Column(name = "action_name", nullable = false, length = 64)
|
||||
private String actionName;
|
||||
|
||||
/**
|
||||
* 日志级别(INFO/WARN/ERROR/DEBUG等)
|
||||
*/
|
||||
@Column(name = "level", nullable = false, length = 16)
|
||||
private String level;
|
||||
|
||||
/**
|
||||
* 日志正文/描述
|
||||
*/
|
||||
@Column(name = "content", columnDefinition = "TEXT COMMENT '日志正文/描述'")
|
||||
private String content;
|
||||
|
||||
/**
|
||||
* 线程名称
|
||||
*/
|
||||
@Column(name = "thread_name", length = 64)
|
||||
private String threadName;
|
||||
|
||||
/**
|
||||
* 结构化扩展信息(JSON)
|
||||
* 注:用String接收JSON字符串,如需反序列化可自行处理(如使用ObjectMapper转换为Map/自定义DTO)
|
||||
*/
|
||||
@Column(name = "extra_data", columnDefinition = "JSON COMMENT '结构化扩展信息(JSON)'")
|
||||
private String extraData;
|
||||
|
||||
/**
|
||||
* 备注
|
||||
*/
|
||||
@Column(name = "remark", length = 255)
|
||||
private String remark;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Column(name = "create_time", nullable = false)
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 创建人ID
|
||||
*/
|
||||
@Column(name = "create_id", columnDefinition = "BIGINT COMMENT '创建人ID'")
|
||||
private Long createId;
|
||||
|
||||
/**
|
||||
* 创建人姓名
|
||||
*/
|
||||
@Column(name = "create_name", length = 128)
|
||||
private String createName;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Column(name = "update_time", nullable = false)
|
||||
private LocalDateTime updateTime;
|
||||
|
||||
/**
|
||||
* 更新人ID
|
||||
*/
|
||||
@Column(name = "update_id", columnDefinition = "BIGINT COMMENT '更新人ID'")
|
||||
private Long updateId;
|
||||
|
||||
/**
|
||||
* 更新人姓名
|
||||
*/
|
||||
@Column(name = "update_name", length = 128)
|
||||
private String updateName;
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.xboe.module.course.entity;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||
import com.xboe.core.SysConstant;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* @author by lyc
|
||||
* @date 2025/11/10
|
||||
*/
|
||||
@Data
|
||||
@Entity
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Table(name = "tip")
|
||||
public class Tip {
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@Column(name = "id", length = 20)
|
||||
private Long id;
|
||||
|
||||
@Column(name = "aid", length = 30)
|
||||
private String aid;
|
||||
|
||||
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||
@Column(name = "create_time", length = 30)
|
||||
private LocalDateTime create_time;
|
||||
|
||||
// 0 标签提示
|
||||
@Column(name = "type", length = 3)
|
||||
private Integer type;
|
||||
|
||||
}
|
||||
@@ -52,6 +52,7 @@ public class CourseToCourseFullText {
|
||||
cft.setTeacher("");
|
||||
cft.setTeacherCode("");
|
||||
cft.setType(c.getType());
|
||||
cft.setTags(c.getTags());
|
||||
if(c.getOpenCourse()==null) {
|
||||
cft.setOpenCourse(0);
|
||||
}else {
|
||||
|
||||
@@ -343,4 +343,12 @@ public interface ICourseService {
|
||||
|
||||
List<Course> findByIds(List<String> courseIds);
|
||||
void deletedStudyResourceBatchByCourseIdAndType(String courseId,Integer courseType);
|
||||
|
||||
void saveTip(String aid);
|
||||
|
||||
Boolean getCourseTip(String aid);
|
||||
|
||||
void rePublish(String courseId);
|
||||
|
||||
// void getPhpCourseData();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
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);
|
||||
|
||||
List<CourseTag> getAllTags();
|
||||
}
|
||||
@@ -18,13 +18,24 @@ import javax.management.Query;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import cn.hutool.http.HttpRequest;
|
||||
import cn.hutool.http.HttpResponse;
|
||||
import cn.hutool.http.HttpUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.core.orm.*;
|
||||
import com.xboe.module.course.dao.*;
|
||||
import com.xboe.module.course.entity.*;
|
||||
import com.xboe.module.course.dao.*;
|
||||
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;
|
||||
@@ -87,7 +98,8 @@ public class CourseServiceImpl implements ICourseService {
|
||||
|
||||
@Resource
|
||||
private CourseHRBPAuditDao courseHRBPAuditDao;
|
||||
|
||||
@Resource
|
||||
private ICourseTagService courseTagService;
|
||||
|
||||
@Resource
|
||||
private SysLogAuditDao logAuditDao;//审核日志记录
|
||||
@@ -113,6 +125,8 @@ public class CourseServiceImpl implements ICourseService {
|
||||
|
||||
@Resource
|
||||
RestHighLevelClient restHighLevelClient;
|
||||
@Resource
|
||||
private TipDao tipDao;
|
||||
|
||||
@Resource
|
||||
private CourseTeacherDeletedRecordDao courseTeacherDeletedRecordDao;
|
||||
@@ -274,13 +288,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) {
|
||||
@@ -360,9 +374,8 @@ 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()){
|
||||
// //去掉未发布的课程
|
||||
@@ -993,6 +1006,29 @@ 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);
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
if (!nowCourse.getSysVersion().equals(c.getSysVersion())) {
|
||||
log.warn(" - 课程ID: {}, 期望版本: {}, 实际版本: {}",
|
||||
c.getId(), c.getSysVersion(), nowCourse.getSysVersion());
|
||||
// 基本无概率同时修改同一课程 如有 以最后提交为准
|
||||
c.setSysVersion(courseDao.getVersion(c.getId()));
|
||||
}
|
||||
log.info("-------- 课程保存 update ------- tag = {} " , c.getTags());
|
||||
courseDao.update(c);
|
||||
c.setSysVersion(courseDao.getVersion(c.getId()));
|
||||
full.getCourse().setSysVersion(c.getSysVersion());
|
||||
@@ -1090,6 +1126,13 @@ public class CourseServiceImpl implements ICourseService {
|
||||
Course c = full.getCourse();//当前的课程信息
|
||||
c.setPublished(true);
|
||||
c.setPublishTime(LocalDateTime.now());
|
||||
Course nowCourse = courseDao.get(c.getId());
|
||||
if (!nowCourse.getSysVersion().equals(c.getSysVersion())) {
|
||||
log.warn(" - 课程ID: {}, 期望版本: {}, 实际版本: {}",
|
||||
c.getId(), c.getSysVersion(), nowCourse.getSysVersion());
|
||||
// 基本无概率同时修改同一课程 如有 以最后提交为准
|
||||
c.setSysVersion(courseDao.getVersion(c.getId()));
|
||||
}
|
||||
courseDao.update(c);
|
||||
|
||||
// 兼容处理,记录下删除的关联数据
|
||||
@@ -1160,7 +1203,7 @@ public class CourseServiceImpl implements ICourseService {
|
||||
|
||||
/***
|
||||
* 发布全文索引
|
||||
* @param c
|
||||
* @param
|
||||
*/
|
||||
// private void fullTextPublish(Course c) {
|
||||
// if(fullTextSearch==null) {
|
||||
@@ -2054,4 +2097,30 @@ public class CourseServiceImpl implements ICourseService {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void saveTip(String aid) {
|
||||
Tip item = new Tip();
|
||||
item.setAid(aid);
|
||||
item.setType(0);
|
||||
item.setCreate_time(LocalDateTime.now());
|
||||
tipDao.save(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Boolean getCourseTip(String aid) {
|
||||
log.info("getCourseTip aid = {} ",aid);
|
||||
List<Tip> list = tipDao.findList(FieldFilters.eq("aid", aid));
|
||||
log.info("getCourseTip list = {} ",list);
|
||||
if (list != null && !list.isEmpty()){
|
||||
return false;//已提示
|
||||
}
|
||||
return true; //用户需要提示
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rePublish(String courseId) {
|
||||
Course c = courseDao.get(courseId);
|
||||
publishUtil.fullTextPublish(c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,879 @@
|
||||
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() || !courseTagList.get(0).getIsPublic()){//1.1 如果该标签不存在 或私有标签,则新建标签
|
||||
courseTag = new CourseTag();
|
||||
courseTag.setTagName(tagName);
|
||||
courseTag.setIsPublic(false);
|
||||
courseTag.setIsHot(false);
|
||||
courseTag.setStatus(1);
|
||||
courseTag.setUseCount(1);
|
||||
//初始给个时间, 变更公共会更新时间 关闭公共会设置null 后续不在自动变更为公共
|
||||
courseTag.setLastSetPublicTime(LocalDateTime.now());
|
||||
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列表
|
||||
log.info(" --- 旧标签1 oldTagIds = {} " , oldCourse.getTags());
|
||||
log.info(" --- 新修改1 newTagIds = {} " , newCourse.getTags());
|
||||
List<String> oldTagIds = getTagIdsFromCourse(oldCourse);
|
||||
List<String> newTagIds = getTagIdsFromCourse(newCourse);
|
||||
log.info(" --- 旧标签2 oldTagIds = {} " , oldTagIds);
|
||||
log.info(" --- 新修改2 newTagIds = {} " , newTagIds);
|
||||
if (oldCourse == null || oldTagIds.isEmpty()) {
|
||||
// 新增课程 - 处理所有新标签
|
||||
handleNewCourseTags(newCourse, newTagIds, userInfo);
|
||||
} else {
|
||||
// 编辑课程 - 比较差异并处理
|
||||
handleEditCourseTags(oldCourse, newCourse, oldTagIds, newTagIds, userInfo);
|
||||
}
|
||||
log.info("完成课程标签更新: courseId={}", newCourse != null ? newCourse.getId() : "null");
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CourseTag> getAllTags() {
|
||||
QueryBuilder query=QueryBuilder.from(CourseTag.class);
|
||||
List<IFieldFilter> filters = new ArrayList<>();
|
||||
filters.add(FieldFilters.eq("deleted",false));//未删除
|
||||
filters.add(FieldFilters.eq("status",0));//正式标签
|
||||
query.addFilters(filters);
|
||||
List<CourseTag> courseTagList = courseTagDao.findList(query.builder());
|
||||
return courseTagList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从课程对象中提取标签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())));
|
||||
// filters.add(FieldFilters.eq("deleted", false));
|
||||
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()) {
|
||||
courseTagRelationDao.reTagRelDelStatus(relation.getId(),userInfo.getName());
|
||||
// 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));
|
||||
// filters.add(FieldFilters.eq("deleted", false));
|
||||
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()) {
|
||||
courseTagRelationDao.reTypeTagRelDelStatus(relation.getId(),userInfo.getName());
|
||||
// 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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package com.xboe.module.course.vo;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @date 2025/11/17
|
||||
*/
|
||||
@Data
|
||||
public class RePublishVo {
|
||||
/**
|
||||
* 课程id
|
||||
* */
|
||||
private String courseId;
|
||||
}
|
||||
@@ -14,12 +14,15 @@ import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
|
||||
import com.boe.feign.api.infrastructure.entity.Dict;
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.constants.CacheName;
|
||||
import com.xboe.module.course.entity.*;
|
||||
import com.xboe.module.course.service.ICourseTagService;
|
||||
import com.xboe.module.course.vo.TeacherVo;
|
||||
import com.xboe.module.usergroup.service.IUserGroupService;
|
||||
import com.xboe.school.study.dao.StudyCourseDao;
|
||||
import com.xboe.school.vo.StudyTimeVo;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
@@ -36,11 +39,6 @@ import com.xboe.common.utils.StringUtil;
|
||||
import com.xboe.core.CurrentUser;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
import com.xboe.module.course.entity.Course;
|
||||
import com.xboe.module.course.entity.CourseContent;
|
||||
import com.xboe.module.course.entity.CourseCrowd;
|
||||
import com.xboe.module.course.entity.CourseSection;
|
||||
import com.xboe.module.course.entity.CourseTeacher;
|
||||
import com.xboe.module.course.service.ICourseContentService;
|
||||
import com.xboe.module.course.service.ICourseSectionService;
|
||||
import com.xboe.module.course.service.ICourseService;
|
||||
@@ -102,6 +100,8 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
|
||||
@Autowired
|
||||
StringRedisTemplate redisTemplate;
|
||||
@Resource
|
||||
private ICourseTagService courseTagService;
|
||||
|
||||
/**
|
||||
* 用于查询课程的学习记录
|
||||
@@ -169,7 +169,14 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
if(course==null || course.getDeleted()){
|
||||
return badRequest("课程不存在或已被删除");
|
||||
}
|
||||
rs.put("course",course);
|
||||
Course course1 = new Course();
|
||||
BeanUtils.copyProperties(course,course1);
|
||||
if (StringUtils.isNotBlank(course.getTags()) && course.getTags().matches("[0-9,]+")) {
|
||||
List<CourseTag> tagList = courseTagService.getTagsByIds(course.getTags());
|
||||
String tags = tagList.stream().map(CourseTag::getTagName).collect(Collectors.joining(","));
|
||||
course1.setTags(tags);
|
||||
}
|
||||
rs.put("course",course1);
|
||||
|
||||
List<CourseCrowd> courseCrowdList = courseService.findCrowdByCourseId(cid);
|
||||
if(crowd!=null && crowd) {
|
||||
@@ -356,7 +363,8 @@ public class StudyCourseApi extends ApiBaseController{
|
||||
*/
|
||||
@PostMapping("/study")
|
||||
public JsonResponse<String> study(@RequestBody StudyContentDto sci, HttpServletRequest request){
|
||||
|
||||
|
||||
log.info("study已进入");
|
||||
if(StringUtils.isBlank(sci.getStudyId())){
|
||||
return error("参数错误");
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import com.xboe.common.beans.IdName;
|
||||
import com.xboe.common.beans.KeyValue;
|
||||
import com.xboe.core.JsonResponse;
|
||||
import com.xboe.core.api.ApiBaseController;
|
||||
import com.xboe.module.course.service.ICourseService;
|
||||
import com.xboe.module.course.vo.RePublishVo;
|
||||
import com.xboe.school.study.dto.BatchSignup;
|
||||
import com.xboe.school.study.entity.StudySignup;
|
||||
import com.xboe.school.study.service.IStudySignupService;
|
||||
@@ -32,7 +34,8 @@ public class StudySignupRpcController extends ApiBaseController {
|
||||
|
||||
@Resource
|
||||
IStudySignupService signupService;
|
||||
|
||||
@Resource
|
||||
ICourseService courseService;
|
||||
/**
|
||||
* 批量添加学员
|
||||
*
|
||||
@@ -106,4 +109,18 @@ public class StudySignupRpcController extends ApiBaseController {
|
||||
return StringUtils.isBlank(string);
|
||||
}
|
||||
|
||||
@PostMapping("/rePublish")
|
||||
public JsonResponse<Boolean> rePublish(@RequestBody RePublishVo vo) {
|
||||
if(vo==null || StringUtils.isBlank(vo.getCourseId())) {
|
||||
return error("未指定id");
|
||||
}
|
||||
try {
|
||||
courseService.rePublish(vo.getCourseId());
|
||||
} catch (Exception e) {
|
||||
log.error("解绑重新发布", e);
|
||||
return error("解绑重新发布失败,请与管理员联系", e.getMessage());
|
||||
}
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,8 +4,11 @@ import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xboe.api.ThirdApi;
|
||||
import com.xboe.constants.CacheName;
|
||||
import com.xboe.module.course.dao.ThreadLogDao;
|
||||
import com.xboe.school.study.dto.StudyContentDto;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -32,7 +35,8 @@ public class StudyCourseDao extends BaseDao<StudyCourse> {
|
||||
StudyCourseItemDao scItemDao;
|
||||
@Autowired
|
||||
StringRedisTemplate redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private ThreadLogDao threadLogDao;
|
||||
|
||||
@Resource
|
||||
private ThirdApi thirdApi;
|
||||
@@ -45,6 +49,8 @@ public class StudyCourseDao extends BaseDao<StudyCourse> {
|
||||
public void finishCheck(String studyId,String courseId,Integer total,String token){
|
||||
|
||||
if(StringUtils.isNotEmpty(redisTemplate.opsForValue().get(studyId + "_" + courseId + "_" + total))){
|
||||
log.info("进入埋点finishCheck");
|
||||
saveThreadLog(studyId, courseId, total, token);
|
||||
return ;
|
||||
}
|
||||
|
||||
@@ -73,6 +79,8 @@ public class StudyCourseDao extends BaseDao<StudyCourse> {
|
||||
UpdateBuilder.create("finishTime",now),
|
||||
UpdateBuilder.create("status",StudyCourse.STATUS_FINISH));
|
||||
redisTemplate.opsForValue().set(studyId + "_" + courseId + "_" + total, "100", 24, TimeUnit.HOURS);
|
||||
log.info("进入埋点finishCheck");
|
||||
saveThreadLog(studyId, courseId, total, token);
|
||||
}else {
|
||||
super.updateMultiFieldById(studyId,
|
||||
UpdateBuilder.create("progress",percent),
|
||||
@@ -85,6 +93,41 @@ public class StudyCourseDao extends BaseDao<StudyCourse> {
|
||||
log.info("在线课学习记录"+allUserList);
|
||||
}
|
||||
|
||||
private void saveThreadLog(String studyId,String courseId,Integer total,String token) {
|
||||
try {
|
||||
JSONObject extraData = new JSONObject();
|
||||
extraData.put("studyId", studyId);
|
||||
extraData.put("courseId", courseId);
|
||||
extraData.put("total", total);
|
||||
extraData.put("token", token);
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
String threadName = Thread.currentThread().getName();
|
||||
|
||||
String sql = "INSERT INTO boe_thread_log (system_name,module_name,action_name,level,content,thread_name,extra_data,remark,create_time,create_id,create_name,update_time,update_id,update_name) "
|
||||
+ "VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14)";
|
||||
|
||||
threadLogDao.sqlUpdate(sql,
|
||||
"学习",
|
||||
"学习进度更新",
|
||||
"更新StudyCourse进度完成",
|
||||
"info",
|
||||
null,
|
||||
threadName,
|
||||
extraData.toJSONString(),
|
||||
null,
|
||||
now,
|
||||
null,
|
||||
null,
|
||||
now,
|
||||
null,
|
||||
null);
|
||||
log.info("saveThreadLog插入成功");
|
||||
} catch (Exception ex) {
|
||||
log.error("保存线程日志失败", ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void finishCheck1(String studyId,String courseId,Integer total){
|
||||
LocalDateTime now=LocalDateTime.now();
|
||||
//已完成的内容
|
||||
|
||||
@@ -10,11 +10,13 @@ import java.util.Map;
|
||||
|
||||
import javax.transaction.Transactional;
|
||||
|
||||
import com.xboe.module.course.dao.ThreadLogDao;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.xboe.common.OrderCondition;
|
||||
import com.xboe.common.PageList;
|
||||
import com.xboe.core.orm.FieldFilters;
|
||||
@@ -52,6 +54,8 @@ public class StudyServiceImpl implements IStudyService{
|
||||
@Autowired
|
||||
StringRedisTemplate redisTemplate;
|
||||
|
||||
@Autowired
|
||||
private ThreadLogDao threadLogDao;
|
||||
|
||||
@Override
|
||||
public StudyCourseItem checkHas(String studyId,String contentId) {
|
||||
@@ -82,6 +86,8 @@ public class StudyServiceImpl implements IStudyService{
|
||||
sci.setStudyDuration(0);
|
||||
sci.setCourseId(dto.getCourseId());
|
||||
sci.setCsectionId(dto.getCsectionId());
|
||||
log.info("saveStudyInfo进入埋点");
|
||||
saveThreadLog(dto);
|
||||
}
|
||||
//进度状态
|
||||
if(dto.getProgress()==null) {
|
||||
@@ -494,4 +500,52 @@ public class StudyServiceImpl implements IStudyService{
|
||||
scDao.finishCheck(studyId,courseId,cnum,token);
|
||||
}
|
||||
|
||||
private void saveThreadLog(StudyContentDto dto) {
|
||||
try {
|
||||
JSONObject extraData = new JSONObject();
|
||||
extraData.put("studyId", dto.getStudyId());
|
||||
extraData.put("contentId", dto.getContentId());
|
||||
extraData.put("aid", dto.getAid());
|
||||
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
Long creatorId = parseLong(dto.getAid());
|
||||
String creatorName = dto.getAname();
|
||||
String threadName = Thread.currentThread().getName();
|
||||
|
||||
String sql = "INSERT INTO boe_thread_log (system_name,module_name,action_name,level,content,thread_name,extra_data,remark,create_time,create_id,create_name,update_time,update_id,update_name) "
|
||||
+ "VALUES (?1,?2,?3,?4,?5,?6,?7,?8,?9,?10,?11,?12,?13,?14)";
|
||||
|
||||
threadLogDao.sqlUpdate(sql,
|
||||
"学习",
|
||||
"学习进度更新",
|
||||
"新增StudyCourseItem",
|
||||
"info",
|
||||
null,
|
||||
threadName,
|
||||
extraData.toJSONString(),
|
||||
null,
|
||||
now,
|
||||
creatorId,
|
||||
creatorName,
|
||||
now,
|
||||
creatorId,
|
||||
creatorName);
|
||||
log.info("saveStudyInfo埋点插入成功");
|
||||
} catch (Exception ex) {
|
||||
log.error("保存线程日志失败 studyId={}, contentId={}, aid={}", dto.getStudyId(), dto.getContentId(), dto.getAid(), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Long parseLong(String value) {
|
||||
if(StringUtils.isBlank(value)) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
return Long.valueOf(value);
|
||||
}catch (NumberFormatException ex){
|
||||
log.warn("无法解析为数字的aid: {}", value);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -80,6 +80,7 @@ xboe:
|
||||
case:
|
||||
ai:
|
||||
base-url: https://gateway-internal.boe.com
|
||||
# base-url: https://gateway-pro.boe.com
|
||||
app-key: 3edef300b25642da949ccddf58441a0f
|
||||
secret-key: 43bc8003a811a7f9c89cbecbfe4bbb22
|
||||
ai-api-code: 30800
|
||||
@@ -110,6 +111,203 @@ xboe:
|
||||
- "10827857"
|
||||
- "11339772"
|
||||
- "pctest06"
|
||||
# 20251202 新增天使用户
|
||||
- "30103141"
|
||||
- "60001391"
|
||||
- "61001278"
|
||||
- "30101301"
|
||||
- "10444837"
|
||||
- "50102190"
|
||||
- "10745030"
|
||||
- "11417101"
|
||||
- "11305432"
|
||||
- "10103037"
|
||||
- "10035168"
|
||||
- "30118060"
|
||||
- "11490910"
|
||||
- "11402931"
|
||||
- "50102196"
|
||||
- "00004896"
|
||||
- "98050025"
|
||||
- "15014359"
|
||||
- "98000758"
|
||||
- "10111538"
|
||||
- "62000137"
|
||||
- "10621476"
|
||||
- "11698996"
|
||||
- "10626304"
|
||||
- "1215826"
|
||||
- "30101887"
|
||||
- "10111915"
|
||||
- "11456852"
|
||||
- "126458"
|
||||
- "30141438"
|
||||
- "10209179"
|
||||
- "22BT15420"
|
||||
- "21BB2053"
|
||||
- "10449861"
|
||||
- "130325"
|
||||
- "11331818"
|
||||
- "10117022"
|
||||
- "10105891"
|
||||
- "121649"
|
||||
- "110338"
|
||||
- "1217784"
|
||||
- "30105038"
|
||||
- "98000792"
|
||||
- "60001146"
|
||||
- "11698607"
|
||||
- "11493629"
|
||||
- "10164819"
|
||||
- "11463452"
|
||||
- "10412122"
|
||||
- "11677116"
|
||||
- "98000780"
|
||||
- "61004269"
|
||||
- "1218902"
|
||||
- "111038"
|
||||
- "10056775"
|
||||
- "50125311"
|
||||
- "50100445"
|
||||
- "00003320"
|
||||
- "11672602"
|
||||
- "30129421"
|
||||
- "11433296"
|
||||
- "11759796"
|
||||
- "10063656"
|
||||
- "10829939"
|
||||
- "98050190"
|
||||
- "10061076"
|
||||
- "60001460"
|
||||
- "10415155"
|
||||
- "60000626"
|
||||
- "110791"
|
||||
- "60000984"
|
||||
- "62000025"
|
||||
- "11794394"
|
||||
- "11681568"
|
||||
- "00002915"
|
||||
- "1210874"
|
||||
- "132046"
|
||||
- "10157955"
|
||||
- "00004409"
|
||||
- "10773520"
|
||||
- "102403"
|
||||
- "10119108"
|
||||
- "10062300"
|
||||
- "10334899"
|
||||
- "10111689"
|
||||
- "10258267"
|
||||
- "60000327"
|
||||
- "50100096"
|
||||
- "10075741"
|
||||
- "1000477"
|
||||
- "1218405"
|
||||
- "132666"
|
||||
- "10183064"
|
||||
- "50101990"
|
||||
- "120869"
|
||||
- "11291711"
|
||||
- "11670020"
|
||||
- "11321710"
|
||||
- "10855714"
|
||||
- "11331449"
|
||||
- "50108923"
|
||||
- "66001553"
|
||||
- "81011081"
|
||||
- "11098405"
|
||||
- "10158509"
|
||||
- "11327800"
|
||||
- "10065717"
|
||||
- "10897206"
|
||||
- "30135784"
|
||||
- "1200373"
|
||||
- "10048566"
|
||||
- "10059710"
|
||||
- "11834720"
|
||||
- "1200384"
|
||||
- "60000973"
|
||||
- "11282207"
|
||||
- "40865"
|
||||
- "10811920"
|
||||
- "00003324"
|
||||
- "00003937"
|
||||
- "10031853"
|
||||
- "1201730"
|
||||
- "00004615"
|
||||
- "10613607"
|
||||
- "10166435"
|
||||
- "11407507"
|
||||
- "21BB0031"
|
||||
- "00002198"
|
||||
- "30104243"
|
||||
- "10840493"
|
||||
- "10046158"
|
||||
- "132164"
|
||||
- "11257354"
|
||||
- "11753398"
|
||||
- "10230265"
|
||||
- "11293165"
|
||||
- "10114925"
|
||||
- "S638"
|
||||
- "10833174"
|
||||
- "10926203"
|
||||
- "124046"
|
||||
- "201181"
|
||||
- "11319329"
|
||||
- "10884794"
|
||||
- "10331955"
|
||||
- "60000847"
|
||||
- "1411"
|
||||
- "126581"
|
||||
- "00003375"
|
||||
- "132539"
|
||||
- "98050455"
|
||||
- "10053666"
|
||||
- "11697194"
|
||||
- "61002398"
|
||||
- "00002971"
|
||||
- "14157"
|
||||
- "132989"
|
||||
- "50103467"
|
||||
- "37315"
|
||||
- "10088583"
|
||||
- "11048954"
|
||||
- "110202"
|
||||
- "30141433"
|
||||
- "1000079"
|
||||
- "11783149"
|
||||
- "10025448"
|
||||
- "98000579"
|
||||
- "10614158"
|
||||
- "30104381"
|
||||
- "60000122"
|
||||
- "11074875"
|
||||
- "10009047"
|
||||
- "10228087"
|
||||
- "10875722"
|
||||
- "10041401"
|
||||
- "110679"
|
||||
- "11167945"
|
||||
- "11288196"
|
||||
- "00003111"
|
||||
- "11780879"
|
||||
- "10836255"
|
||||
- "10753364"
|
||||
- "50102132"
|
||||
- "10711537"
|
||||
- "15001329"
|
||||
- "11733703"
|
||||
- "10450632"
|
||||
- "98050011"
|
||||
- "10224644"
|
||||
- "120931"
|
||||
- "10743223"
|
||||
- "107873"
|
||||
- "11141942"
|
||||
- "120434"
|
||||
- "126466"
|
||||
- "98050020"
|
||||
alert-email-recipients:
|
||||
- chengmeng@boe.com.cn
|
||||
- liyubing@boe.com.cn
|
||||
|
||||
@@ -31,26 +31,42 @@
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<!-- Log file error output -->
|
||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<file>${log.path}/error.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
||||
<maxFileSize>50MB</maxFileSize>
|
||||
<maxHistory>30</maxHistory>
|
||||
</rollingPolicy>
|
||||
<appender name="caseAiChat"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
||||
<level>ERROR</level>
|
||||
</filter>
|
||||
<file>${log.path}/caseAiChat.log</file>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<fileNamePattern>${log.path}/caseAiChat.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<!-- Log file error output -->
|
||||
<!-- <appender name="caseAiChat" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
|
||||
<!-- <file>${log.path}/caseAiChat.log</file>-->
|
||||
<!-- <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">-->
|
||||
<!-- <fileNamePattern>${log.path}/%d{yyyy-MM}/caseAiChat.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>-->
|
||||
<!-- <maxFileSize>50MB</maxFileSize>-->
|
||||
<!-- <maxHistory>30</maxHistory>-->
|
||||
<!-- </rollingPolicy>-->
|
||||
<!-- <encoder>-->
|
||||
<!-- <pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>-->
|
||||
<!-- </encoder>-->
|
||||
<!-- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">-->
|
||||
<!-- <level>ERROR</level>-->
|
||||
<!-- </filter>-->
|
||||
<!-- </appender>-->
|
||||
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="info"/>
|
||||
<!-- <appender-ref ref="console"/>-->
|
||||
<!-- <appender-ref ref="error"/> -->
|
||||
</root>
|
||||
|
||||
<logger name="caseAiChatLogger" additivity="false" level="INFO">
|
||||
<appender-ref ref="caseAiChat"/>
|
||||
</logger>
|
||||
</configuration>
|
||||
|
||||
@@ -47,10 +47,26 @@
|
||||
</filter>
|
||||
</appender>
|
||||
|
||||
<appender name="caseAiChat"
|
||||
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||
<encoder>
|
||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||
<charset>UTF-8</charset>
|
||||
</encoder>
|
||||
<File>${log.path}/caseAiChat.log</File>
|
||||
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||
<FileNamePattern>${log.path}/caseAiChat.%d{yyyy-MM-dd}.log</FileNamePattern>
|
||||
</rollingPolicy>
|
||||
</appender>
|
||||
|
||||
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||
<root level="INFO">
|
||||
<appender-ref ref="debug"/>
|
||||
<appender-ref ref="error"/>
|
||||
<appender-ref ref="console"/>
|
||||
</root>
|
||||
|
||||
<logger name="caseAiChatLogger" additivity="false" level="INFO">
|
||||
<appender-ref ref="caseAiChat"/>
|
||||
</logger>
|
||||
</configuration>
|
||||
|
||||
Reference in New Issue
Block a user