mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-10 11:26:50 +08:00
合并
This commit is contained in:
@@ -660,8 +660,8 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
/**
|
/**
|
||||||
* appendtime 于 study-video-time 合并
|
* appendtime 于 study-video-time 合并
|
||||||
* */
|
* */
|
||||||
@RequestMapping(value="/updateStudyVideoTime",method = {RequestMethod.GET,RequestMethod.POST})
|
/*@RequestMapping(value="/updateStudyVideoTime1",method = {RequestMethod.GET,RequestMethod.POST})
|
||||||
public JsonResponse<String> updateStudyVideoTime(StudyTimeVo studyTime, HttpServletRequest request){
|
public JsonResponse<String> updateStudyVideoTime1(StudyTimeVo studyTime, HttpServletRequest request){
|
||||||
|
|
||||||
// 0 study-video-time , 1 appendtime
|
// 0 study-video-time , 1 appendtime
|
||||||
if (studyTime.getType() == 0){
|
if (studyTime.getType() == 0){
|
||||||
@@ -698,7 +698,7 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
token = request.getHeader("token");
|
token = request.getHeader("token");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
studyService.updateStudyDuration(studyTime.getStudyId(),null,studyTime.getContentId(),studyTime.getDuration(),studyTime.getCourseId());
|
studyService.updateStudyDuration(studyTime.getStudyId(),null,studyTime.getContentId(),studyTime.getVideoTime(),studyTime.getCourseId());
|
||||||
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(studyTime.getStudyId() ,studyTime.getCourseId(), token);
|
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(studyTime.getStudyId() ,studyTime.getCourseId(), token);
|
||||||
log.info("updateStudyVideoTime type =1 在线课学习记录 = " + allUserList);
|
log.info("updateStudyVideoTime type =1 在线课学习记录 = " + allUserList);
|
||||||
return success(studyTime.getId());
|
return success(studyTime.getId());
|
||||||
@@ -709,8 +709,37 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
}else{
|
}else{
|
||||||
return error("type不能为空");
|
return error("type不能为空");
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
@RequestMapping(value="/updateStudyVideoTime",method = {RequestMethod.GET,RequestMethod.POST})
|
||||||
|
public JsonResponse<String> updateStudyVideoTime(StudyTimeVo studyTime, HttpServletRequest request){
|
||||||
|
try {
|
||||||
|
if(StringUtils.isBlank(studyTime.getItemId())){
|
||||||
|
return error("参数错误");
|
||||||
|
}
|
||||||
|
if(studyTime.getVideoTime()==null){
|
||||||
|
return error("无时间点");
|
||||||
|
}
|
||||||
|
if(StringUtils.isBlank(studyTime.getStudyId())){
|
||||||
|
return error("参数错误");
|
||||||
|
}
|
||||||
|
if(StringUtils.isBlank(studyTime.getCourseId())){
|
||||||
|
return error("未指定课程");
|
||||||
|
}
|
||||||
|
if(StringUtils.isBlank(studyTime.getContentId())){
|
||||||
|
return error("未指定资源内容");
|
||||||
|
}
|
||||||
|
studyService.updateStudyDuration(studyTime.getStudyId(),null,studyTime.getContentId(),studyTime.getDuration(),studyTime.getCourseId());
|
||||||
|
if (studyTime.getContentId() != null && studyTime.getCourseId() != null && studyTime.getProgressVideo() != null){
|
||||||
|
contentService.updateProcessVideo(studyTime.getContentId(), studyTime.getCourseId(), studyTime.getProgressVideo());
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("updateStudyVideoTime",e);
|
||||||
|
return error("学习时长记录失败",e.getMessage(),null);
|
||||||
|
}
|
||||||
|
return success("true");
|
||||||
|
}
|
||||||
|
|
||||||
/**获取最后一次的学习内容*/
|
/**获取最后一次的学习内容*/
|
||||||
@GetMapping("/last-study")
|
@GetMapping("/last-study")
|
||||||
|
|||||||
@@ -103,9 +103,11 @@ public class StudyCourseTask {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void saveStudyCourseItemLastTime1() {
|
|
||||||
|
@XxlJob("saveStudyCourseItemLastTime")
|
||||||
|
public void saveStudyCourseItemLastTime() {
|
||||||
// 1. 定义匹配模式(匹配所有目标key)
|
// 1. 定义匹配模式(匹配所有目标key)
|
||||||
final String KEY_PATTERN = "studyId:*:courseId:*:courseContentId:*";
|
final String KEY_PATTERN = "studyId:*:courseId:*:courseContentId:*:studyItemId:*";
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
// 2. 使用SCAN安全遍历(避免阻塞)
|
// 2. 使用SCAN安全遍历(避免阻塞)
|
||||||
ScanOptions options = ScanOptions.scanOptions()
|
ScanOptions options = ScanOptions.scanOptions()
|
||||||
@@ -128,27 +130,30 @@ public class StudyCourseTask {
|
|||||||
try {
|
try {
|
||||||
// 6. 提取studyContentId
|
// 6. 提取studyContentId
|
||||||
String[] parts = redisKey.split(":");
|
String[] parts = redisKey.split(":");
|
||||||
if (parts.length < 6) continue;
|
if (parts.length < 7) continue;
|
||||||
String studyId = parts[1];
|
String studyId = parts[1];
|
||||||
String courseId = parts[3];
|
String courseId = parts[3];
|
||||||
String courseContentId = parts[5];
|
String courseContentId = parts[5];
|
||||||
|
String studyItemId = parts[7];
|
||||||
// 7. 获取存储的时间点(示例逻辑)
|
// 7. 获取存储的时间点(示例逻辑)
|
||||||
String redisValue = redisTemplate.opsForValue().get(redisKey);
|
String redisValue = redisTemplate.opsForValue().get(redisKey);
|
||||||
if (redisValue == null) continue;
|
if (redisValue == null) continue;
|
||||||
String[] partValues = redisValue.split("&");
|
String[] partValues = redisValue.split("&");
|
||||||
int duration = Integer.parseInt(partValues[0]);
|
int studyVideoTtime = Integer.parseInt(partValues[0]);
|
||||||
|
int appendtime = Integer.parseInt(partValues[1]);
|
||||||
LocalDateTime timestamp = null;
|
LocalDateTime timestamp = null;
|
||||||
if (partValues.length >= 2){
|
if (partValues.length >= 2){
|
||||||
timestamp = LocalDateTime.parse(partValues[1], formatter);
|
timestamp = LocalDateTime.parse(partValues[2], formatter);
|
||||||
}
|
}
|
||||||
// 8. 更新数据库(调用已有服务方法)
|
// 8. 更新数据库(调用已有服务方法)
|
||||||
studyService.newAppendStudyDuration(studyId,null,courseContentId,duration,timestamp);
|
studyService.newAppendStudyDuration(studyId,null,courseContentId,appendtime,timestamp);
|
||||||
|
// 8. 更新数据库(调用已有服务方法)
|
||||||
|
studyService.updateStudyCourseItemLastTime(studyItemId, studyVideoTtime, timestamp);
|
||||||
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(studyId , courseId, null);
|
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(studyId , courseId, null);
|
||||||
log.info("处理成功 allUserList: {}", allUserList);
|
log.info("处理成功 allUserList: {}", allUserList);
|
||||||
// 9. 删除Redis键(原子操作)
|
// 9. 删除Redis键(原子操作)
|
||||||
redisTemplate.delete(redisKey);
|
redisTemplate.delete(redisKey);
|
||||||
log.info("处理成功 key: {}, lastStudyTime: {}", redisKey, duration);
|
log.info("处理成功 key: {}, lastStudyTime: {}", redisKey, appendtime);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("处理失败 key: {}", redisKey, e);
|
log.error("处理失败 key: {}", redisKey, e);
|
||||||
}
|
}
|
||||||
@@ -163,8 +168,8 @@ public class StudyCourseTask {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@XxlJob("saveStudyCourseItemLastTime")
|
@XxlJob("saveStudyCourseItemLastTime1")
|
||||||
public void saveStudyCourseItemLastTime() {
|
public void saveStudyCourseItemLastTime1() {
|
||||||
// 定义需要处理的键模式集合
|
// 定义需要处理的键模式集合
|
||||||
processKeys("studyContentId:*:last_active", this::handleLastActiveKey);
|
processKeys("studyContentId:*:last_active", this::handleLastActiveKey);
|
||||||
processKeys("studyId:*:courseId:*:courseContentId:*", this::handleDurationKey);
|
processKeys("studyId:*:courseId:*:courseContentId:*", this::handleDurationKey);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ public interface IStudyService {
|
|||||||
|
|
||||||
void updateStudyCourseItemLastTime(String studyContentId, int lastStudyTime, LocalDateTime timestamp);
|
void updateStudyCourseItemLastTime(String studyContentId, int lastStudyTime, LocalDateTime timestamp);
|
||||||
|
|
||||||
void updateStudyDuration(String studyId,String studyItemId, String contentId, Integer duration,String courseId);
|
void updateStudyDuration(String studyId,String studyItemId, String contentId, Integer videoTime,String courseId);
|
||||||
|
|
||||||
void newAppendStudyDuration(String studyId, String studyItemId, String courseContentId, int duration, LocalDateTime timestamp);
|
void newAppendStudyDuration(String studyId, String studyItemId, String courseContentId, int duration, LocalDateTime timestamp);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -149,22 +149,22 @@ public class StudyServiceImpl implements IStudyService{
|
|||||||
|
|
||||||
// 更新 前端传输已学习时长
|
// 更新 前端传输已学习时长
|
||||||
@Override
|
@Override
|
||||||
public void updateStudyDuration(String studyId,String studyItemId,String courseContentId, Integer duration,String courseId) {
|
public void updateStudyDuration(String studyId,String studyItemId,String courseContentId, Integer videoTime,String courseId) {
|
||||||
|
|
||||||
LocalDateTime now = LocalDateTime.now();
|
LocalDateTime now = LocalDateTime.now();
|
||||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
|
||||||
String key = "studyId:" + studyId + ":courseId:" + courseId + ":courseContentId:" + courseContentId;
|
String key = "studyId:" + studyId + ":courseId:" + courseId + ":courseContentId:" + courseContentId + ":studyItemId:" + studyItemId;
|
||||||
String currentValue = redisTemplate.opsForValue().get(key);
|
String currentValue = redisTemplate.opsForValue().get(key);
|
||||||
int lastDuration = 0;
|
int lastDuration = 0;
|
||||||
int sum = duration;
|
int sum = 10; // 原appendtime改为固定10秒调用一次接口
|
||||||
if (currentValue != null) {
|
if (currentValue != null) {
|
||||||
String[] partValues = currentValue.split("&");
|
String[] partValues = currentValue.split("&");
|
||||||
lastDuration = Integer.parseInt(partValues[0]);
|
lastDuration = Integer.parseInt(partValues[1]);
|
||||||
sum += lastDuration;
|
sum += lastDuration;
|
||||||
};
|
};
|
||||||
|
|
||||||
String value = sum + "&" + now.format(formatter); // 使用ISO8601时间格式
|
String value = videoTime + "&" + sum + "&" + now.format(formatter); // study_video_time & appendtime & time
|
||||||
log.info("-study-video-time-----value = " + value);
|
log.info("-study-video-time-----value = " + value);
|
||||||
|
|
||||||
// 20250303 优化 多次更新改一次更新
|
// 20250303 优化 多次更新改一次更新
|
||||||
|
|||||||
Reference in New Issue
Block a user