mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-09 02:46:50 +08:00
Compare commits
26 Commits
release-20
...
SZX-1194-2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4e7e529f74 | ||
|
|
d6dcbdfcac | ||
|
|
44f4309930 | ||
|
|
64a3b26e77 | ||
|
|
9f4475dd05 | ||
|
|
ec3d8c57ac | ||
|
|
aa9b24de1f | ||
|
|
4450e1b13a | ||
|
|
7efd586fdc | ||
|
|
385c3d1472 | ||
|
|
e3c94c97d2 | ||
|
|
186fc6e56f | ||
|
|
3cbfccf806 | ||
|
|
e513b08205 | ||
|
|
2191db1c95 | ||
|
|
6e2ffc9eaf | ||
|
|
6a33194818 | ||
|
|
5942a7dcd4 | ||
|
|
3ddc9d58f0 | ||
|
|
8112aea110 | ||
|
|
e8b31f4216 | ||
|
|
e83f3adb94 | ||
|
|
a14639283e | ||
|
|
8d9f400a7a | ||
|
|
933e7a018a | ||
|
|
4de8556802 |
@@ -60,6 +60,9 @@ public class ThirdApi {
|
|||||||
@Value("${orgTree.orgChildTreeList}")
|
@Value("${orgTree.orgChildTreeList}")
|
||||||
private String orgChildTreeListUrl;
|
private String orgChildTreeListUrl;
|
||||||
|
|
||||||
|
@Value("${userBasic.getUserBasicInfo}")
|
||||||
|
private String getUserBasicInfo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
UserDao userDao;
|
UserDao userDao;
|
||||||
|
|
||||||
@@ -366,6 +369,62 @@ 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 List<UserBasicInfoVo> getUserBasicInfoByWorkNums2(String workNum, String token) {
|
||||||
|
try {
|
||||||
|
// 参数校验
|
||||||
|
if (StringUtils.isBlank(workNum)) {
|
||||||
|
log.warn("getUserBasicInfoByWorkNums2 workNum为空");
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 构建URL参数,将单个workNum作为列表参数传递
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
params.put("workNums", Collections.singletonList(workNum));
|
||||||
|
|
||||||
|
log.info("getUserBasicInfoByWorkNums2 请求参数: workNum={}, url={}", workNum, getUserBasicInfo);
|
||||||
|
|
||||||
|
// 发送HTTP GET请求
|
||||||
|
String responseStr = HttpRequest.get(getUserBasicInfo)
|
||||||
|
.form(params)
|
||||||
|
.header("token", token)
|
||||||
|
.execute()
|
||||||
|
.body();
|
||||||
|
|
||||||
|
log.info("getUserBasicInfoByWorkNums2 响应结果: {}", responseStr);
|
||||||
|
|
||||||
|
// 解析响应
|
||||||
|
UserBasicInfoResultVo resultVo = JSONUtil.parseObj(responseStr).toBean(UserBasicInfoResultVo.class);
|
||||||
|
log.info("getUserBasicInfoByWorkNums2 解析结果: {}", resultVo);
|
||||||
|
if (resultVo != null && resultVo.getStatus() == 200 && resultVo.getResult() != null) {
|
||||||
|
return resultVo.getResult();
|
||||||
|
} else {
|
||||||
|
log.error("getUserBasicInfoByWorkNums2 请求失败: status={}, message={}",
|
||||||
|
resultVo != null ? resultVo.getStatus() : "null",
|
||||||
|
resultVo != null ? resultVo.getMessage() : "响应为空");
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("getUserBasicInfoByWorkNums2 HTTP请求异常: workNum={}", workNum, e);
|
||||||
|
return Collections.emptyList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void updateOrSaveCourse(CourseParam param, String token){
|
public void updateOrSaveCourse(CourseParam param, String token){
|
||||||
log.info("---------------准备同步在线课到讲师管理完毕 ------- param " + param);
|
log.info("---------------准备同步在线课到讲师管理完毕 ------- param " + param);
|
||||||
String resp = Optional.ofNullable(
|
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 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")
|
@Bean(name = "customDispatcher")
|
||||||
public Dispatcher customDispatcher(@Qualifier("eventStreamExecutor") ThreadPoolTaskExecutor eventStreamExecutor) {
|
public Dispatcher customDispatcher(@Qualifier("eventStreamExecutor") ThreadPoolTaskExecutor eventStreamExecutor) {
|
||||||
return new Dispatcher(eventStreamExecutor.getThreadPoolExecutor());
|
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_UPLOAD_INTERFACE_NAME = "文档上传";
|
||||||
|
|
||||||
public static final String CASE_DOC_DELETE_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 = "网络异常,请稍后再试。";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import com.xboe.module.boecase.service.ICaseAiChatService;
|
|||||||
import com.xboe.module.boecase.service.ICaseAiPermissionService;
|
import com.xboe.module.boecase.service.ICaseAiPermissionService;
|
||||||
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
import com.xboe.module.boecase.service.IElasticSearchIndexService;
|
||||||
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
import com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||||
import com.xboe.module.excel.ExportsExcelSenderUtil;
|
|
||||||
import lombok.Data;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.MediaType;
|
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 org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* AI对话管理API
|
* AI对话管理API
|
||||||
*/
|
*/
|
||||||
@Slf4j
|
@Slf4j(topic = "caseAiChatLogger")
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(value = "/xboe/m/boe/case/ai")
|
@RequestMapping(value = "/xboe/m/boe/case/ai")
|
||||||
public class CaseAiChatApi extends ApiBaseController {
|
public class CaseAiChatApi extends ApiBaseController {
|
||||||
@@ -64,6 +60,26 @@ public class CaseAiChatApi extends ApiBaseController {
|
|||||||
return caseAiChatService.chat(caseAiChatDto, getCurrent());
|
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查看会话内消息记录
|
* 根据conversationId查看会话内消息记录
|
||||||
* @param conversationId 会话ID
|
* @param conversationId 会话ID
|
||||||
@@ -90,32 +106,10 @@ public class CaseAiChatApi extends ApiBaseController {
|
|||||||
public void downloadConversationExcel(@RequestParam String startTime,
|
public void downloadConversationExcel(@RequestParam String startTime,
|
||||||
@RequestParam String endTime,
|
@RequestParam String endTime,
|
||||||
HttpServletResponse response) {
|
HttpServletResponse response) {
|
||||||
try {
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
LocalDate startDate = LocalDate.parse(startTime, formatter);
|
||||||
LocalDateTime start = LocalDateTime.parse(startTime, formatter);
|
LocalDate endDate = LocalDate.parse(endTime, formatter);
|
||||||
LocalDateTime end = LocalDateTime.parse(endTime, formatter);
|
caseAiChatService.getConversationExcel(startDate.atStartOfDay(), endDate.atTime(23, 59, 59), response);
|
||||||
|
|
||||||
// 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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -171,16 +165,4 @@ public class CaseAiChatApi extends ApiBaseController {
|
|||||||
}
|
}
|
||||||
return error("创建失败");
|
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);
|
private final AtomicInteger currentTaskCount = new AtomicInteger(0);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 限流,默认QPS 40
|
||||||
|
*/
|
||||||
|
private final TokenBucketRateLimiter rateLimiter = new TokenBucketRateLimiter(40);
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("aiDocExecutor")
|
@Qualifier("aiDocExecutor")
|
||||||
private ThreadPoolTaskExecutor aiDocExecutor;
|
private ThreadPoolTaskExecutor aiDocExecutor;
|
||||||
@@ -27,7 +32,7 @@ public class CaseAiDocumentAsyncHandler {
|
|||||||
public void process(CaseDocumentLogOptTypeEnum optTypeEnum, Cases... caseList) {
|
public void process(CaseDocumentLogOptTypeEnum optTypeEnum, Cases... caseList) {
|
||||||
for (Cases cases : caseList) {
|
for (Cases cases : caseList) {
|
||||||
// 控制并发数量
|
// 控制并发数量
|
||||||
while (currentTaskCount.get() >= 15) {
|
while (currentTaskCount.get() >= 5) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(100);
|
Thread.sleep(100);
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
@@ -39,8 +44,13 @@ public class CaseAiDocumentAsyncHandler {
|
|||||||
currentTaskCount.incrementAndGet();
|
currentTaskCount.incrementAndGet();
|
||||||
|
|
||||||
aiDocExecutor.submit(() -> {
|
aiDocExecutor.submit(() -> {
|
||||||
processCases(cases, optTypeEnum);
|
try {
|
||||||
currentTaskCount.decrementAndGet();
|
// 限流
|
||||||
|
rateLimiter.acquire();
|
||||||
|
processCases(cases, optTypeEnum);
|
||||||
|
} finally {
|
||||||
|
currentTaskCount.decrementAndGet();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 com.xboe.module.boecase.vo.CaseAiMessageVo;
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ public interface ICaseAiChatService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 聊天
|
* 聊天
|
||||||
|
*
|
||||||
* @param caseAiChatDto
|
* @param caseAiChatDto
|
||||||
* @param currentUser
|
* @param currentUser
|
||||||
* @return
|
* @return
|
||||||
@@ -24,7 +26,8 @@ public interface ICaseAiChatService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建新的AI对话会话
|
* 创建新的AI对话会话
|
||||||
* @param userId 用户ID
|
*
|
||||||
|
* @param userId 用户ID
|
||||||
* @param conversationName 对话名称
|
* @param conversationName 对话名称
|
||||||
* @return 创建的会话信息
|
* @return 创建的会话信息
|
||||||
*/
|
*/
|
||||||
@@ -32,6 +35,7 @@ public interface ICaseAiChatService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 根据conversationId查看会话内消息记录
|
* 根据conversationId查看会话内消息记录
|
||||||
|
*
|
||||||
* @param conversationId 会话ID
|
* @param conversationId 会话ID
|
||||||
* @return 消息记录列表
|
* @return 消息记录列表
|
||||||
*/
|
*/
|
||||||
@@ -41,6 +45,23 @@ public interface ICaseAiChatService {
|
|||||||
* 导出会话记录为Excel
|
* 导出会话记录为Excel
|
||||||
* @param startTime 开始时间
|
* @param startTime 开始时间
|
||||||
* @param endTime 结束时间
|
* @param endTime 结束时间
|
||||||
|
* @param response
|
||||||
|
*/
|
||||||
|
void getConversationExcel(LocalDateTime startTime, LocalDateTime endTime, HttpServletResponse response);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出会话记录为Excel
|
||||||
|
*
|
||||||
|
* @param startTime 开始时间
|
||||||
|
* @param endTime 结束时间
|
||||||
*/
|
*/
|
||||||
void downloadConversationExcel(LocalDateTime startTime, LocalDateTime 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})
|
@EnableConfigurationProperties({CaseAiProperties.class})
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j(topic = "caseAiChatLogger")
|
||||||
public class AiAccessTokenServiceImpl implements IAiAccessTokenService {
|
public class AiAccessTokenServiceImpl implements IAiAccessTokenService {
|
||||||
|
|
||||||
private static final String ACCESS_TOKEN_CACHE_KEY = "case_ai_access_token";
|
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.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.xboe.constants.CaseAiConstants;
|
||||||
import com.xboe.core.CurrentUser;
|
import com.xboe.core.CurrentUser;
|
||||||
import com.xboe.core.orm.FieldFilters;
|
import com.xboe.core.orm.FieldFilters;
|
||||||
import com.xboe.enums.CaseAiChatStatusEnum;
|
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.module.boecase.vo.ConversationExcelVo;
|
||||||
import com.xboe.system.organization.vo.OrgSimpleVo;
|
import com.xboe.system.organization.vo.OrgSimpleVo;
|
||||||
import com.xboe.system.user.service.IUserService;
|
import com.xboe.system.user.service.IUserService;
|
||||||
import lombok.Data;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
import okhttp3.sse.EventSource;
|
import okhttp3.sse.EventSource;
|
||||||
import okhttp3.sse.EventSourceListener;
|
import okhttp3.sse.EventSourceListener;
|
||||||
import okhttp3.sse.EventSources;
|
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.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
import org.apache.http.entity.StringEntity;
|
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.usermodel.Workbook;
|
||||||
import org.apache.poi.ss.util.CellRangeAddress;
|
import org.apache.poi.ss.util.CellRangeAddress;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
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.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||||
|
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
import org.springframework.util.StringUtils;
|
|
||||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
@@ -71,16 +62,21 @@ import java.nio.file.Paths;
|
|||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@EnableConfigurationProperties({CaseAiProperties.class})
|
@EnableConfigurationProperties({CaseAiProperties.class})
|
||||||
@Service
|
@Service
|
||||||
@Slf4j
|
@Slf4j(topic = "caseAiChatLogger")
|
||||||
public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CaseAiProperties caseAiProperties;
|
private CaseAiProperties caseAiProperties;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
@Qualifier("esChatExecutor")
|
||||||
|
private ThreadPoolTaskExecutor esChatExecutor;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@Qualifier("customDispatcher")
|
@Qualifier("customDispatcher")
|
||||||
private Dispatcher dispatcher;
|
private Dispatcher dispatcher;
|
||||||
@@ -102,6 +98,9 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private CasesDao casesDao;
|
private CasesDao casesDao;
|
||||||
|
|
||||||
|
// 用于存储会话ID与EventSource的映射关系,以便能够中断特定会话
|
||||||
|
private final Map<String, EventSource> conversationEventSourceMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -114,7 +113,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
|
conversationId = getOrCreateConversationId(caseAiChatDto, currentUser);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("获取会话ID失败", e);
|
log.error("获取会话ID失败", e);
|
||||||
errMessage(sseEmitter, "服务繁忙,请稍后再试。");
|
errMessage(sseEmitter, null, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||||
sseEmitter.complete();
|
sseEmitter.complete();
|
||||||
return sseEmitter;
|
return sseEmitter;
|
||||||
}
|
}
|
||||||
@@ -124,6 +123,13 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
// 3. 构建请求参数
|
// 3. 构建请求参数
|
||||||
String userId = currentUser.getCode();
|
String userId = currentUser.getCode();
|
||||||
|
|
||||||
|
// 6. 用于收集对话数据的容器
|
||||||
|
AiChatConversationData conversationData = new AiChatConversationData();
|
||||||
|
conversationData.setQuery(caseAiChatDto.getQuery());
|
||||||
|
conversationData.setConversationId(conversationId);
|
||||||
|
conversationData.setUserId(userId);
|
||||||
|
|
||||||
String kId = caseAiProperties.getCaseKnowledgeId();
|
String kId = caseAiProperties.getCaseKnowledgeId();
|
||||||
JSONObject chatParam = new JSONObject();
|
JSONObject chatParam = new JSONObject();
|
||||||
chatParam.put("userId", userId);
|
chatParam.put("userId", userId);
|
||||||
@@ -154,10 +160,21 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
String accessToken;
|
String accessToken;
|
||||||
try {
|
try {
|
||||||
accessToken = aiAccessTokenService.getAccessToken();
|
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) {
|
} catch (Exception e) {
|
||||||
log.error("获取access_token失败", e);
|
log.error("获取access_token失败", e);
|
||||||
errMessage(sseEmitter, "服务繁忙,请稍后再试。");
|
errMessage(sseEmitter, conversationId, CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||||
|
// 先响应给前端
|
||||||
sseEmitter.complete();
|
sseEmitter.complete();
|
||||||
|
conversationData.appendAnswer(CaseAiConstants.CHAT_SYS_ERR_MSG);
|
||||||
|
saveConversationData(conversationData);
|
||||||
return sseEmitter;
|
return sseEmitter;
|
||||||
}
|
}
|
||||||
String apiCode = caseAiProperties.getChatApiCode();
|
String apiCode = caseAiProperties.getChatApiCode();
|
||||||
@@ -168,26 +185,62 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
RequestBody bodyRequestBody = RequestBody.create(chatParamStr, MediaType.parse("application/json"));
|
RequestBody bodyRequestBody = RequestBody.create(chatParamStr, MediaType.parse("application/json"));
|
||||||
builder.post(bodyRequestBody);
|
builder.post(bodyRequestBody);
|
||||||
Request request = builder.build();
|
Request request = builder.build();
|
||||||
|
|
||||||
|
|
||||||
// 6. 用于收集对话数据的容器
|
|
||||||
AiChatConversationData conversationData = new AiChatConversationData();
|
|
||||||
conversationData.setQuery(caseAiChatDto.getQuery());
|
|
||||||
conversationData.setConversationId(conversationId);
|
|
||||||
conversationData.setUserId(userId);
|
|
||||||
|
|
||||||
// 7. 创建事件监听器
|
// 7. 创建事件监听器
|
||||||
EventSourceListener listener = new EventSourceListener() {
|
EventSourceListener listener = new EventSourceListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onOpen(@NotNull EventSource eventSource, @NotNull Response response) {
|
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());
|
log.info("调用接口 [{}] 接口开始监听", request.url());
|
||||||
|
// 将EventSource存储到Map中,以便后续可以中断
|
||||||
|
conversationEventSourceMap.put(conversationId, eventSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClosed(@NotNull EventSource eventSource) {
|
public void onClosed(@NotNull EventSource eventSource) {
|
||||||
log.info("调用接口 [{}] 接口关闭", request.url());
|
log.info("调用接口 [{}] 接口关闭", request.url());
|
||||||
// 对话完成,保存到ES
|
// 对话完成,保存到ES
|
||||||
elasticSearchIndexService.createData(conversationData);
|
saveConversationData(conversationData);
|
||||||
|
// 从Map中移除已完成的会话
|
||||||
|
conversationEventSourceMap.remove(conversationId);
|
||||||
sseEmitter.complete();
|
sseEmitter.complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -224,7 +277,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
} else {
|
} else {
|
||||||
// 异常问题,取message内容
|
// 异常问题,取message内容
|
||||||
String message = jsonData.getString("message");
|
String message = jsonData.getString("message");
|
||||||
errMessage(sseEmitter, message);
|
errMessage(sseEmitter, conversationId, message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,20 +299,45 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(@NotNull EventSource eventSource, @Nullable Throwable e, @Nullable Response response) {
|
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) {
|
if (e != null) {
|
||||||
sseEmitter.completeWithError(e);
|
log.error("调用接口 [{}] 时发生错误,捕获到异常", request.url(), e);
|
||||||
} else {
|
} 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);
|
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
|
@Override
|
||||||
public void downloadConversationExcel(LocalDateTime startTime, LocalDateTime endTime) {
|
public void downloadConversationExcel(LocalDateTime startTime, LocalDateTime endTime) {
|
||||||
// 1. 根据startTime和endTime,查询在这个时间区间内的CaseAiConversations数据
|
Workbook workbook = getChatMessageExcel(startTime, endTime);
|
||||||
List<CaseAiConversations> conversations = caseAiConversationsDao.getGenericDao().findList(
|
// 创建Excel文件并保存
|
||||||
CaseAiConversations.class,
|
|
||||||
FieldFilters.ge("sysCreateTime", startTime),
|
|
||||||
FieldFilters.le("sysCreateTime", endTime)
|
|
||||||
);
|
|
||||||
|
|
||||||
// 准备Excel数据
|
|
||||||
List<ConversationExcelVo> excelDataList = new ArrayList<>();
|
|
||||||
|
|
||||||
// 2. 遍历这组数据,根据aiConversationId从es中查询数据(可调用getConversationMessages()方法)
|
|
||||||
for (CaseAiConversations conversation : conversations) {
|
|
||||||
String aiConversationId = conversation.getAiConversationId();
|
|
||||||
String conversationName = conversation.getConversationName();
|
|
||||||
String conversationUser = conversation.getConversationUser();
|
|
||||||
|
|
||||||
List<CaseAiMessageVo> messages = getConversationMessages(aiConversationId);
|
|
||||||
|
|
||||||
// 计算会话时长
|
|
||||||
long duration = 0; // 默认为0,如果需要精确计算,需要从消息中提取时间信息
|
|
||||||
|
|
||||||
// 3. 写入Excel,包括每个会话的用户,会话标题,会话内的问答记录,每次对话时长等
|
|
||||||
ConversationExcelVo excelData = new ConversationExcelVo();
|
|
||||||
excelData.setConversationId(aiConversationId);
|
|
||||||
excelData.setConversationName(conversationName);
|
|
||||||
excelData.setUser(conversationUser);
|
|
||||||
excelData.setMessages(messages);
|
|
||||||
|
|
||||||
excelDataList.add(excelData);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 写入Excel文件
|
|
||||||
Workbook workbook = new XSSFWorkbook();
|
|
||||||
Sheet sheet = workbook.createSheet("AI会话数据");
|
|
||||||
// 标题行
|
|
||||||
Row headerRow = sheet.createRow(0);
|
|
||||||
headerRow.createCell(0).setCellValue("会话ID");
|
|
||||||
headerRow.createCell(1).setCellValue("会话名称");
|
|
||||||
headerRow.createCell(2).setCellValue("用户");
|
|
||||||
headerRow.createCell(3).setCellValue("提问");
|
|
||||||
headerRow.createCell(4).setCellValue("回答");
|
|
||||||
headerRow.createCell(5).setCellValue("开始时间");
|
|
||||||
headerRow.createCell(6).setCellValue("问答时长(秒)");
|
|
||||||
|
|
||||||
// 内容行
|
|
||||||
if (!excelDataList.isEmpty()) {
|
|
||||||
int rowNum = 1; // 从第二行开始写入数据
|
|
||||||
for (ConversationExcelVo excelData : excelDataList) {
|
|
||||||
List<CaseAiMessageVo> messages = excelData.getMessages();
|
|
||||||
|
|
||||||
if (messages != null && !messages.isEmpty()) {
|
|
||||||
// 记录起始行号,用于后续合并单元格
|
|
||||||
int startRow = rowNum;
|
|
||||||
|
|
||||||
// 遍历每个消息
|
|
||||||
for (CaseAiMessageVo message : messages) {
|
|
||||||
Row row = sheet.createRow(rowNum++);
|
|
||||||
// 填充每行数据
|
|
||||||
row.createCell(0).setCellValue(excelData.getConversationId());
|
|
||||||
row.createCell(1).setCellValue(excelData.getConversationName());
|
|
||||||
row.createCell(2).setCellValue(excelData.getUser());
|
|
||||||
row.createCell(3).setCellValue(message.getQuery() != null ? message.getQuery() : "");
|
|
||||||
row.createCell(4).setCellValue(message.getAnswer() != null ? message.getAnswer() : "");
|
|
||||||
row.createCell(5).setCellValue(""); // 开始时间字段暂留空
|
|
||||||
row.createCell(6).setCellValue(message.getDurationSeconds() != null ? message.getDurationSeconds() : 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 合并单元格(会话ID、会话名称、用户三列)
|
|
||||||
// 参数说明:起始行号,结束行号,起始列号,结束列号
|
|
||||||
if (rowNum > startRow + 1) { // 只有当有多行时才合并
|
|
||||||
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 0, 0));
|
|
||||||
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 1, 1));
|
|
||||||
sheet.addMergedRegion(new CellRangeAddress(startRow, rowNum - 1, 2, 2));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// 如果没有消息,则仍然创建一行显示基本信息
|
|
||||||
Row row = sheet.createRow(rowNum++);
|
|
||||||
row.createCell(0).setCellValue(excelData.getConversationId());
|
|
||||||
row.createCell(1).setCellValue(excelData.getConversationName());
|
|
||||||
row.createCell(2).setCellValue(excelData.getUser());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// 3. 创建Excel文件并保存
|
|
||||||
if (caseAiProperties.isAiChatDataSendEmail()) {
|
if (caseAiProperties.isAiChatDataSendEmail()) {
|
||||||
// TODO 发送邮件附件
|
// TODO 发送邮件附件
|
||||||
} else {
|
} else {
|
||||||
@@ -471,9 +481,13 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从 ES 数据中解析消息对象
|
* 从 ES 数据中解析消息对象
|
||||||
|
* 已迁移
|
||||||
|
* @see IElasticSearchIndexService
|
||||||
|
*
|
||||||
* @param sourceMap ES数据
|
* @param sourceMap ES数据
|
||||||
* @return 消息对象
|
* @return 消息对象
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private CaseAiMessageVo parseMessageFromES(Map<String, Object> sourceMap) {
|
private CaseAiMessageVo parseMessageFromES(Map<String, Object> sourceMap) {
|
||||||
try {
|
try {
|
||||||
CaseAiMessageVo messageVo = new CaseAiMessageVo();
|
CaseAiMessageVo messageVo = new CaseAiMessageVo();
|
||||||
@@ -595,6 +609,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
/**
|
/**
|
||||||
* 处理文件引用(原方法,保留用于数据收集)
|
* 处理文件引用(原方法,保留用于数据收集)
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private void handleFileRefer(JSONObject responseData, AiChatConversationData conversationData) {
|
private void handleFileRefer(JSONObject responseData, AiChatConversationData conversationData) {
|
||||||
try {
|
try {
|
||||||
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
|
JSONObject fileRefer = responseData.getJSONObject("fileRefer");
|
||||||
@@ -682,7 +697,9 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 当 SSE 失败时,作为普通 HTTP 请求处理
|
* 当 SSE 失败时,作为普通 HTTP 请求处理
|
||||||
|
* 不再使用
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private void handleAsRegularHttpRequest(Request request, SseEmitter sseEmitter, AiChatConversationData conversationData) {
|
private void handleAsRegularHttpRequest(Request request, SseEmitter sseEmitter, AiChatConversationData conversationData) {
|
||||||
try {
|
try {
|
||||||
OkHttpClient client = new OkHttpClient.Builder()
|
OkHttpClient client = new OkHttpClient.Builder()
|
||||||
@@ -699,7 +716,7 @@ public class CaseAiChatServiceImpl implements ICaseAiChatService {
|
|||||||
// 将响应内容原封不动地推送到 SseEmitter
|
// 将响应内容原封不动地推送到 SseEmitter
|
||||||
JSONObject responseData = JSONObject.parseObject(responseBody);
|
JSONObject responseData = JSONObject.parseObject(responseBody);
|
||||||
if (responseBody.contains("message")) {
|
if (responseBody.contains("message")) {
|
||||||
errMessage(sseEmitter, responseData.getString("message"));
|
errMessage(sseEmitter, conversationData.getConversationId(), responseData.getString("message"));
|
||||||
sseEmitter.complete();
|
sseEmitter.complete();
|
||||||
return;
|
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();
|
JSONObject jsonData = new JSONObject();
|
||||||
jsonData.put("status", 1);
|
jsonData.put("status", 1);
|
||||||
jsonData.put("content", message);
|
jsonData.put("content", message);
|
||||||
|
|
||||||
|
JSONObject finishData = new JSONObject();
|
||||||
|
jsonData.put("status", 4);
|
||||||
|
jsonData.put("content", "");
|
||||||
try {
|
try {
|
||||||
|
sseEmitter.send(conversationData.toJSONString());
|
||||||
sseEmitter.send(jsonData.toJSONString());
|
sseEmitter.send(jsonData.toJSONString());
|
||||||
|
sseEmitter.send(finishData.toJSONString());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
log.error("发送错误信息异常", e);
|
log.error("发送错误信息异常", e);
|
||||||
sseEmitter.completeWithError(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));
|
messageVo.setStartTime(LocalDateTime.parse(startTimeStr));
|
||||||
}
|
}
|
||||||
if (sourceMap.containsKey("durationSeconds")) {
|
if (sourceMap.containsKey("durationSeconds")) {
|
||||||
messageVo.setDurationSeconds((Long) sourceMap.get("durationSeconds"));
|
messageVo.setDurationSeconds((Integer) sourceMap.get("durationSeconds"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析 suggestions
|
// 解析 suggestions
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 旧案例上传
|
* 旧案例上传
|
||||||
@@ -46,6 +47,7 @@ public class CaseUploadTask {
|
|||||||
|
|
||||||
@XxlJob("oldDataUploadJob")
|
@XxlJob("oldDataUploadJob")
|
||||||
public void oldDataUploadJob() {
|
public void oldDataUploadJob() {
|
||||||
|
String currentLastId = null;
|
||||||
try {
|
try {
|
||||||
// log.info("开始执行旧案例上传任务");
|
// log.info("开始执行旧案例上传任务");
|
||||||
|
|
||||||
@@ -61,6 +63,7 @@ public class CaseUploadTask {
|
|||||||
// log.info("没有需要处理的案例数据");
|
// log.info("没有需要处理的案例数据");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
currentLastId = casesToProcess.get(casesToProcess.size() - 1).getId();
|
||||||
|
|
||||||
// 批量检查这些案例是否已在CaseDocumentLog中存在记录,提升性能
|
// 批量检查这些案例是否已在CaseDocumentLog中存在记录,提升性能
|
||||||
List<String> caseIds = new ArrayList<>();
|
List<String> caseIds = new ArrayList<>();
|
||||||
@@ -76,18 +79,37 @@ public class CaseUploadTask {
|
|||||||
// 过滤出未在CaseDocumentLog中存在的案例
|
// 过滤出未在CaseDocumentLog中存在的案例
|
||||||
List<Cases> casesList = new ArrayList<>();
|
List<Cases> casesList = new ArrayList<>();
|
||||||
for (Cases cases : casesToProcess) {
|
for (Cases cases : casesToProcess) {
|
||||||
boolean exists = false;
|
// boolean exists = false;
|
||||||
for (CaseDocumentLog log : existingLogs) {
|
// for (CaseDocumentLog log : existingLogs) {
|
||||||
if (cases.getId().equals(log.getCaseId())
|
// if (cases.getId().equals(log.getCaseId())
|
||||||
&& StringUtils.equals(log.getRequestUrl(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME)
|
// && StringUtils.equals(log.getRequestUrl(), CaseAiConstants.CASE_DOC_UPLOAD_INTERFACE_NAME)
|
||||||
&& Objects.equals(log.getRunStatus(), CaseDocumentLogRunStatusEnum.COMPLETED.getCode())
|
// && Objects.equals(log.getRunStatus(), CaseDocumentLogRunStatusEnum.COMPLETED.getCode())
|
||||||
&& Objects.equals(log.getOptStatus(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode())
|
// && Objects.equals(log.getOptStatus(), CaseDocumentLogOptStatusEnum.SUCCESS.getCode())
|
||||||
&& Objects.equals(log.getRunStatus(), CaseDocumentLogCaseStatusEnum.SUCCESS.getCode())) {
|
// && Objects.equals(log.getRunStatus(), CaseDocumentLogCaseStatusEnum.SUCCESS.getCode())) {
|
||||||
exists = true;
|
// exists = true;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
if (!exists) {
|
// 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);
|
casesList.add(cases);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -98,17 +120,18 @@ public class CaseUploadTask {
|
|||||||
// 调用异步处理方法
|
// 调用异步处理方法
|
||||||
caseAiDocumentAsyncHandler.process(CaseDocumentLogOptTypeEnum.CREATE, casesList.toArray(new Cases[0]));
|
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 {
|
} else {
|
||||||
log.info("没有新的案例需要处理");
|
log.info("没有新的案例需要处理");
|
||||||
}
|
}
|
||||||
|
// 将当前处理的最后一条数据ID存入Redis
|
||||||
|
|
||||||
// log.info("旧案例上传任务执行完成");
|
// log.info("旧案例上传任务执行完成");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("执行旧案例上传任务时发生异常", e);
|
log.error("执行旧案例上传任务时发生异常", e);
|
||||||
|
} finally {
|
||||||
|
if (currentLastId != null) {
|
||||||
|
fixOnLastCase(currentLastId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -137,4 +160,9 @@ public class CaseUploadTask {
|
|||||||
|
|
||||||
return casesDao.findList(queryBuilder.builder());
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 案例引用列表
|
* 案例引用列表
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import java.util.stream.Collectors;
|
|||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
|
import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
|
||||||
import com.boe.feign.api.infrastructure.entity.Dict;
|
import com.boe.feign.api.infrastructure.entity.Dict;
|
||||||
import com.xboe.api.ThirdApi;
|
import com.xboe.api.ThirdApi;
|
||||||
|
import com.xboe.api.vo.UserBasicInfoVo;
|
||||||
import com.xboe.module.course.dto.*;
|
import com.xboe.module.course.dto.*;
|
||||||
import com.xboe.module.course.entity.*;
|
import com.xboe.module.course.entity.*;
|
||||||
import com.xboe.module.course.service.*;
|
import com.xboe.module.course.service.*;
|
||||||
|
import org.apache.commons.collections4.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
@@ -92,7 +93,7 @@ public class CourseManageApi extends ApiBaseController{
|
|||||||
IDataUserSyncService userSyncService;
|
IDataUserSyncService userSyncService;
|
||||||
@Resource
|
@Resource
|
||||||
private ThirdApi thirdApi;
|
private ThirdApi thirdApi;
|
||||||
|
|
||||||
// @PostMapping("/test")
|
// @PostMapping("/test")
|
||||||
// public JsonResponse<PageList<Course>> findTest(Pagination pager,CourseQueryDto dto){
|
// public JsonResponse<PageList<Course>> findTest(Pagination pager,CourseQueryDto dto){
|
||||||
// //dto.setOrgAid("7003708665807110150");
|
// //dto.setOrgAid("7003708665807110150");
|
||||||
@@ -464,7 +465,7 @@ public class CourseManageApi extends ApiBaseController{
|
|||||||
|
|
||||||
@PostMapping("/submit")
|
@PostMapping("/submit")
|
||||||
@AutoLog(module = "课程",action = "提交课程",info = "")
|
@AutoLog(module = "课程",action = "提交课程",info = "")
|
||||||
public JsonResponse<CourseFullDto> submitCourseFull(@RequestBody CourseFullDto dto){
|
public JsonResponse<CourseFullDto> submitCourseFull(HttpServletRequest request, @RequestBody CourseFullDto dto){
|
||||||
if(dto.getCourse()==null){
|
if(dto.getCourse()==null){
|
||||||
return badRequest("无课程信息");
|
return badRequest("无课程信息");
|
||||||
}
|
}
|
||||||
@@ -585,7 +586,10 @@ public class CourseManageApi extends ApiBaseController{
|
|||||||
dto.getCourse().getOrgName(),
|
dto.getCourse().getOrgName(),
|
||||||
dto.getCourse().getSysCreateBy(),dto.getCourse().getName());
|
dto.getCourse().getSysCreateBy(),dto.getCourse().getName());
|
||||||
//邮件发送
|
//邮件发送
|
||||||
String email=dto.getAuditUser().getEmail();
|
String email= this.getEmail(dto.getAuditUser().getCode(), request);
|
||||||
|
if (StringUtils.isBlank( email)) {
|
||||||
|
email=dto.getAuditUser().getEmail();
|
||||||
|
}
|
||||||
if(!isLocalDevelopment()) {
|
if(!isLocalDevelopment()) {
|
||||||
//只是非开发模式下才可以发送
|
//只是非开发模式下才可以发送
|
||||||
service.sendMail(email,"《"+dto.getCourse().getName()+"》课程审核提醒", htmlEmail,"数字化学习平台");
|
service.sendMail(email,"《"+dto.getCourse().getName()+"》课程审核提醒", htmlEmail,"数字化学习平台");
|
||||||
@@ -603,7 +607,39 @@ public class CourseManageApi extends ApiBaseController{
|
|||||||
return error("提交课程处理失败",e.getMessage());
|
return error("提交课程处理失败",e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getEmail(String code, HttpServletRequest request) {
|
||||||
|
|
||||||
|
String token = request.getHeader("Xboe-Access-Token");
|
||||||
|
if (StringUtils.isEmpty(token)) {
|
||||||
|
token = request.getHeader("token");
|
||||||
|
}
|
||||||
|
if (StringUtils.isEmpty(token)) {
|
||||||
|
token = request.getHeader("x-access-token");
|
||||||
|
}
|
||||||
|
|
||||||
|
log.info("审批获取邮箱新 code:{}", code);
|
||||||
|
if (StringUtils.isBlank( code)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
log.info("审批获取邮箱 workNums:{}", code);
|
||||||
|
List<UserBasicInfoVo> userBasicInfoVoList = thirdApi.getUserBasicInfoByWorkNums2(code, token);
|
||||||
|
log.info("审批获取邮箱 userBasicInfoVoList:{}", userBasicInfoVoList);
|
||||||
|
if (CollectionUtils.isEmpty(userBasicInfoVoList)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
String email = userBasicInfoVoList.get(0).getEmail();
|
||||||
|
log.info("审批获取邮箱 userBasicInfoVoList.get(0).getEmail():{}", email);
|
||||||
|
|
||||||
|
|
||||||
|
return email;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取用户邮箱错误",e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private String createEmailHtml(String name,String orgId, String orgName,String createBy,String courseName) throws Exception {
|
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\">");
|
StringBuffer htmlMsg=new StringBuffer("<div style=\"line-height:30px;border:2px solid #2990ca;padding:20px\">");
|
||||||
|
|
||||||
@@ -714,6 +750,10 @@ public class CourseManageApi extends ApiBaseController{
|
|||||||
//邮件发送
|
//邮件发送
|
||||||
if(!isLocalDevelopment()) {
|
if(!isLocalDevelopment()) {
|
||||||
//只是非高度环境上才会发送
|
//只是非高度环境上才会发送
|
||||||
|
String newEmail = getEmail(ucode,request);
|
||||||
|
if (StringUtils.isNotBlank(newEmail)) {
|
||||||
|
email = newEmail;
|
||||||
|
}
|
||||||
service.sendMail(email,"《"+course.getName()+"》课程审核提醒",htmlEmail,"数字化学习平台");
|
service.sendMail(email,"《"+course.getName()+"》课程审核提醒",htmlEmail,"数字化学习平台");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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,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;
|
||||||
|
}
|
||||||
@@ -363,7 +363,8 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
*/
|
*/
|
||||||
@PostMapping("/study")
|
@PostMapping("/study")
|
||||||
public JsonResponse<String> study(@RequestBody StudyContentDto sci, HttpServletRequest request){
|
public JsonResponse<String> study(@RequestBody StudyContentDto sci, HttpServletRequest request){
|
||||||
|
|
||||||
|
log.info("study已进入");
|
||||||
if(StringUtils.isBlank(sci.getStudyId())){
|
if(StringUtils.isBlank(sci.getStudyId())){
|
||||||
return error("参数错误");
|
return error("参数错误");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,11 @@ import java.time.LocalDateTime;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.xboe.api.ThirdApi;
|
import com.xboe.api.ThirdApi;
|
||||||
import com.xboe.constants.CacheName;
|
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 lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -32,7 +35,8 @@ public class StudyCourseDao extends BaseDao<StudyCourse> {
|
|||||||
StudyCourseItemDao scItemDao;
|
StudyCourseItemDao scItemDao;
|
||||||
@Autowired
|
@Autowired
|
||||||
StringRedisTemplate redisTemplate;
|
StringRedisTemplate redisTemplate;
|
||||||
|
@Autowired
|
||||||
|
private ThreadLogDao threadLogDao;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ThirdApi thirdApi;
|
private ThirdApi thirdApi;
|
||||||
@@ -45,6 +49,8 @@ public class StudyCourseDao extends BaseDao<StudyCourse> {
|
|||||||
public void finishCheck(String studyId,String courseId,Integer total,String token){
|
public void finishCheck(String studyId,String courseId,Integer total,String token){
|
||||||
|
|
||||||
if(StringUtils.isNotEmpty(redisTemplate.opsForValue().get(studyId + "_" + courseId + "_" + total))){
|
if(StringUtils.isNotEmpty(redisTemplate.opsForValue().get(studyId + "_" + courseId + "_" + total))){
|
||||||
|
log.info("进入埋点finishCheck");
|
||||||
|
saveThreadLog(studyId, courseId, total, token);
|
||||||
return ;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,6 +79,8 @@ public class StudyCourseDao extends BaseDao<StudyCourse> {
|
|||||||
UpdateBuilder.create("finishTime",now),
|
UpdateBuilder.create("finishTime",now),
|
||||||
UpdateBuilder.create("status",StudyCourse.STATUS_FINISH));
|
UpdateBuilder.create("status",StudyCourse.STATUS_FINISH));
|
||||||
redisTemplate.opsForValue().set(studyId + "_" + courseId + "_" + total, "100", 24, TimeUnit.HOURS);
|
redisTemplate.opsForValue().set(studyId + "_" + courseId + "_" + total, "100", 24, TimeUnit.HOURS);
|
||||||
|
log.info("进入埋点finishCheck");
|
||||||
|
saveThreadLog(studyId, courseId, total, token);
|
||||||
}else {
|
}else {
|
||||||
super.updateMultiFieldById(studyId,
|
super.updateMultiFieldById(studyId,
|
||||||
UpdateBuilder.create("progress",percent),
|
UpdateBuilder.create("progress",percent),
|
||||||
@@ -85,6 +93,41 @@ public class StudyCourseDao extends BaseDao<StudyCourse> {
|
|||||||
log.info("在线课学习记录"+allUserList);
|
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){
|
public void finishCheck1(String studyId,String courseId,Integer total){
|
||||||
LocalDateTime now=LocalDateTime.now();
|
LocalDateTime now=LocalDateTime.now();
|
||||||
//已完成的内容
|
//已完成的内容
|
||||||
|
|||||||
@@ -10,11 +10,13 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.transaction.Transactional;
|
import javax.transaction.Transactional;
|
||||||
|
|
||||||
|
import com.xboe.module.course.dao.ThreadLogDao;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.xboe.common.OrderCondition;
|
import com.xboe.common.OrderCondition;
|
||||||
import com.xboe.common.PageList;
|
import com.xboe.common.PageList;
|
||||||
import com.xboe.core.orm.FieldFilters;
|
import com.xboe.core.orm.FieldFilters;
|
||||||
@@ -52,6 +54,8 @@ public class StudyServiceImpl implements IStudyService{
|
|||||||
@Autowired
|
@Autowired
|
||||||
StringRedisTemplate redisTemplate;
|
StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ThreadLogDao threadLogDao;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StudyCourseItem checkHas(String studyId,String contentId) {
|
public StudyCourseItem checkHas(String studyId,String contentId) {
|
||||||
@@ -82,6 +86,8 @@ public class StudyServiceImpl implements IStudyService{
|
|||||||
sci.setStudyDuration(0);
|
sci.setStudyDuration(0);
|
||||||
sci.setCourseId(dto.getCourseId());
|
sci.setCourseId(dto.getCourseId());
|
||||||
sci.setCsectionId(dto.getCsectionId());
|
sci.setCsectionId(dto.getCsectionId());
|
||||||
|
log.info("saveStudyInfo进入埋点");
|
||||||
|
saveThreadLog(dto);
|
||||||
}
|
}
|
||||||
//进度状态
|
//进度状态
|
||||||
if(dto.getProgress()==null) {
|
if(dto.getProgress()==null) {
|
||||||
@@ -494,4 +500,52 @@ public class StudyServiceImpl implements IStudyService{
|
|||||||
scDao.finishCheck(studyId,courseId,cnum,token);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -111,6 +111,203 @@ xboe:
|
|||||||
- "10827857"
|
- "10827857"
|
||||||
- "11339772"
|
- "11339772"
|
||||||
- "pctest06"
|
- "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:
|
alert-email-recipients:
|
||||||
- chengmeng@boe.com.cn
|
- chengmeng@boe.com.cn
|
||||||
- liyubing@boe.com.cn
|
- liyubing@boe.com.cn
|
||||||
|
|||||||
@@ -31,26 +31,42 @@
|
|||||||
</encoder>
|
</encoder>
|
||||||
</appender>
|
</appender>
|
||||||
|
|
||||||
<!-- Log file error output -->
|
<appender name="caseAiChat"
|
||||||
<appender name="error" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
class="ch.qos.logback.core.rolling.RollingFileAppender">
|
||||||
<file>${log.path}/error.log</file>
|
|
||||||
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
|
|
||||||
<fileNamePattern>${log.path}/%d{yyyy-MM}/error.%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
|
|
||||||
<maxFileSize>50MB</maxFileSize>
|
|
||||||
<maxHistory>30</maxHistory>
|
|
||||||
</rollingPolicy>
|
|
||||||
<encoder>
|
<encoder>
|
||||||
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
<pattern>%date [%thread] %-5level [%logger{50}] %file:%line - %msg%n</pattern>
|
||||||
|
<charset>UTF-8</charset>
|
||||||
</encoder>
|
</encoder>
|
||||||
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
|
<file>${log.path}/caseAiChat.log</file>
|
||||||
<level>ERROR</level>
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
||||||
</filter>
|
<fileNamePattern>${log.path}/caseAiChat.%d{yyyy-MM-dd}.log</fileNamePattern>
|
||||||
|
</rollingPolicy>
|
||||||
</appender>
|
</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 -->
|
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="info"/>
|
<appender-ref ref="info"/>
|
||||||
<!-- <appender-ref ref="console"/>-->
|
<!-- <appender-ref ref="console"/>-->
|
||||||
<!-- <appender-ref ref="error"/> -->
|
<!-- <appender-ref ref="error"/> -->
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
|
<logger name="caseAiChatLogger" additivity="false" level="INFO">
|
||||||
|
<appender-ref ref="caseAiChat"/>
|
||||||
|
</logger>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -47,10 +47,26 @@
|
|||||||
</filter>
|
</filter>
|
||||||
</appender>
|
</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 -->
|
<!-- Level: FATAL 0 ERROR 3 WARN 4 INFO 6 DEBUG 7 -->
|
||||||
<root level="INFO">
|
<root level="INFO">
|
||||||
<appender-ref ref="debug"/>
|
<appender-ref ref="debug"/>
|
||||||
<appender-ref ref="error"/>
|
<appender-ref ref="error"/>
|
||||||
<appender-ref ref="console"/>
|
<appender-ref ref="console"/>
|
||||||
</root>
|
</root>
|
||||||
|
|
||||||
|
<logger name="caseAiChatLogger" additivity="false" level="INFO">
|
||||||
|
<appender-ref ref="caseAiChat"/>
|
||||||
|
</logger>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
Reference in New Issue
Block a user