mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/per-boe/java-servers.git
synced 2025-12-12 04:16:51 +08:00
Compare commits
21 Commits
250321-bug
...
test-gx
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5fe9019d87 | ||
|
|
500fb090fb | ||
|
|
be8c4464dc | ||
|
|
ee95435d01 | ||
|
|
c7f1a1e810 | ||
|
|
76f0d1933a | ||
|
|
87350c74f9 | ||
|
|
67f55c51b8 | ||
|
|
58d6f49006 | ||
|
|
645c58e8c4 | ||
|
|
c8ffdd561f | ||
|
|
98611edcaa | ||
|
|
dd6e64d6ac | ||
|
|
8aea21bde7 | ||
|
|
754d41e087 | ||
|
|
fedf8ec527 | ||
|
|
a79f6b43b2 | ||
|
|
e2ac6a5b96 | ||
|
|
66320dab97 | ||
|
|
81ea19f0f3 | ||
|
|
5312d9f5f4 |
@@ -8,9 +8,11 @@ import cn.hutool.json.JSONUtil;
|
|||||||
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSON;
|
||||||
import com.boe.feign.api.courseweb.entity.ExamTestDto;
|
import com.boe.feign.api.courseweb.entity.ExamTestDto;
|
||||||
import com.boe.feign.api.courseweb.entity.ProjectStudyDto;
|
import com.boe.feign.api.courseweb.entity.ProjectStudyDto;
|
||||||
|
import com.boe.feign.api.courseweb.remote.ExternalRemoteClient;
|
||||||
import com.boe.feign.api.courseweb.remote.OffCourseRemoteClient;
|
import com.boe.feign.api.courseweb.remote.OffCourseRemoteClient;
|
||||||
import com.boe.feign.api.courseweb.remote.ProjectAdminRemoteClient;
|
import com.boe.feign.api.courseweb.remote.ProjectAdminRemoteClient;
|
||||||
import com.boe.feign.api.courseweb.remote.ProjectRemoteClient;
|
import com.boe.feign.api.courseweb.remote.ProjectRemoteClient;
|
||||||
|
import com.boe.feign.api.courseweb.reps.ExamStudyRecordParam;
|
||||||
import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
|
import com.boe.feign.api.infrastructure.entity.CommonSearchVo;
|
||||||
import com.boe.feign.api.infrastructure.entity.Dict;
|
import com.boe.feign.api.infrastructure.entity.Dict;
|
||||||
import com.boe.feign.api.infrastructure.remote.DictRemoteClient;
|
import com.boe.feign.api.infrastructure.remote.DictRemoteClient;
|
||||||
@@ -73,6 +75,8 @@ public class ThirdApi {
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private ProjectRemoteClient projectRemoteClient;
|
private ProjectRemoteClient projectRemoteClient;
|
||||||
|
@Resource
|
||||||
|
ExternalRemoteClient externalRemoteClient;
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private DictRemoteClient dictRemoteClient;
|
private DictRemoteClient dictRemoteClient;
|
||||||
@@ -262,11 +266,19 @@ public class ThirdApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<StudyCourse> getStudyCourseList(String studyId, String courseId, String token) {
|
public List<StudyCourse> getStudyCourseList(String studyId, String courseId, String token) {
|
||||||
|
log.info(" 1 studyId = "+ studyId + " ,courseId = " + courseId );
|
||||||
|
if ( studyId == null || courseId == null ){
|
||||||
|
log.error(" 在线课学习记录 参数不能为空 ");
|
||||||
|
return new ArrayList<>();
|
||||||
|
}
|
||||||
StudyCourseVo studyCourseVo = new StudyCourseVo();
|
StudyCourseVo studyCourseVo = new StudyCourseVo();
|
||||||
studyCourseVo.setStudyId(studyId);
|
studyCourseVo.setStudyId(studyId);
|
||||||
studyCourseVo.setCourseId(courseId);
|
studyCourseVo.setCourseId(courseId);
|
||||||
ProjectStudyDto projectStudyDto = new ProjectStudyDto();
|
ProjectStudyDto projectStudyDto = new ProjectStudyDto();
|
||||||
BeanUtil.copyProperties(studyCourseVo, studyCourseVo);
|
// BeanUtil.copyProperties(studyCourseVo, studyCourseVo);
|
||||||
|
projectStudyDto.setStudyId(Long.parseLong(studyId));
|
||||||
|
projectStudyDto.setCourseId(Long.parseLong(courseId));
|
||||||
|
log.info(" 12 在线课学习记录 studyId = "+ projectStudyDto.getStudyId() + " ,courseId = " + projectStudyDto.getCourseId() );
|
||||||
projectRemoteClient.updateStudyStatus(projectStudyDto);
|
projectRemoteClient.updateStudyStatus(projectStudyDto);
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -382,4 +394,8 @@ public class ThirdApi {
|
|||||||
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
|
.body()).orElseThrow(() -> new RuntimeException("token校验失败"));
|
||||||
log.info("updateOrSaveCourse = " + resp);
|
log.info("updateOrSaveCourse = " + resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void syncExamStudyRecord(ExamStudyRecordParam param) {
|
||||||
|
externalRemoteClient.syncExamStudyRecord(param);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -314,10 +314,8 @@ public class CoursePortalApi extends ApiBaseController{
|
|||||||
User user = userService.get(ct.getTeacherId());
|
User user = userService.get(ct.getTeacherId());
|
||||||
if(t!=null) {
|
if(t!=null) {
|
||||||
ct.setRemark(t.getDescription());
|
ct.setRemark(t.getDescription());
|
||||||
ct.setSupplier(t.getSupplier());
|
|
||||||
ct.setTeacherType(t.getTeacherType());
|
|
||||||
if(redisTemplate.opsForValue().get(ct.getTeacherId())!=null){
|
if(redisTemplate.opsForValue().get(ct.getTeacherId())!=null){
|
||||||
if(Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1") && ( t==null || t.getTeacherType() == 1)){
|
if(Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1")){
|
||||||
ct.setTeacherName("BOE教师");
|
ct.setTeacherName("BOE教师");
|
||||||
}
|
}
|
||||||
teacherCourseDto.setCourseId(ct.getCourseId());
|
teacherCourseDto.setCourseId(ct.getCourseId());
|
||||||
@@ -337,7 +335,7 @@ public class CoursePortalApi extends ApiBaseController{
|
|||||||
List<String> list=new ArrayList<>();
|
List<String> list=new ArrayList<>();
|
||||||
list.add(ct.getTeacherId());
|
list.add(ct.getTeacherId());
|
||||||
getTeacherInfo(request.getHeader("Xboe-Access-Token"),list);
|
getTeacherInfo(request.getHeader("Xboe-Access-Token"),list);
|
||||||
if(Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1") && ( t==null || t.getTeacherType() == 1)){
|
if(Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1")){
|
||||||
ct.setTeacherName("BOE教师");
|
ct.setTeacherName("BOE教师");
|
||||||
}
|
}
|
||||||
teacherCourseDto.setCourseId(ct.getCourseId());
|
teacherCourseDto.setCourseId(ct.getCourseId());
|
||||||
|
|||||||
@@ -56,4 +56,5 @@ public class CourseTeacher extends IdBaseEntity {
|
|||||||
/**讲师类型 1 内部讲师 2外部讲师*/
|
/**讲师类型 1 内部讲师 2外部讲师*/
|
||||||
@Transient
|
@Transient
|
||||||
private Integer teacherType;
|
private Integer teacherType;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -480,7 +480,7 @@ public class CourseServiceImpl implements ICourseService {
|
|||||||
String sql = "SELECT DISTINCT\n" +
|
String sql = "SELECT DISTINCT\n" +
|
||||||
"rt.course_id\n" +
|
"rt.course_id\n" +
|
||||||
"FROM\n" +
|
"FROM\n" +
|
||||||
"boe_new.student s INNER JOIN boe_new.router_task rt on s.pid=rt.router_id inner join boe_course c on c.id=rt.course_id\n" +
|
"boe.student s INNER JOIN boe.router_task rt on s.pid=rt.router_id inner join boe_course c on c.id=rt.course_id\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"WHERE\n" +
|
"WHERE\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
@@ -503,7 +503,7 @@ public class CourseServiceImpl implements ICourseService {
|
|||||||
String sql = "SELECT DISTINCT\n" +
|
String sql = "SELECT DISTINCT\n" +
|
||||||
"pt.course_id\n" +
|
"pt.course_id\n" +
|
||||||
"FROM\n" +
|
"FROM\n" +
|
||||||
"boe_new.student s INNER JOIN boe_new.project_task pt on s.pid=pt.project_id inner join boe_course c on c.id=pt.course_id\n" +
|
"boe.student s INNER JOIN boe.project_task pt on s.pid=pt.project_id inner join boe_course c on c.id=pt.course_id\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
"WHERE\n" +
|
"WHERE\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
@@ -560,8 +560,8 @@ public class CourseServiceImpl implements ICourseService {
|
|||||||
String sql = "SELECT DISTINCT\n" +
|
String sql = "SELECT DISTINCT\n" +
|
||||||
"\tc.id \n" +
|
"\tc.id \n" +
|
||||||
"FROM\n" +
|
"FROM\n" +
|
||||||
"\tboe_new.student s\n" +
|
"\tboe.student s\n" +
|
||||||
"\tINNER JOIN boe_new.grow_task gt ON s.pid = gt.grow_id\n" +
|
"\tINNER JOIN boe.grow_task gt ON s.pid = gt.grow_id\n" +
|
||||||
"\tINNER JOIN boe_course c ON gt.course_id = c.id \n" +
|
"\tINNER JOIN boe_course c ON gt.course_id = c.id \n" +
|
||||||
"WHERE\n" +
|
"WHERE\n" +
|
||||||
"\ts.type = 14 \n" +
|
"\ts.type = 14 \n" +
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import java.util.Map;
|
|||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
|
|
||||||
|
import com.boe.feign.api.courseweb.reps.ExamStudyRecordParam;
|
||||||
|
import com.xboe.api.ThirdApi;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
@@ -37,6 +39,9 @@ public class AloneExamServiceImpl implements IAloneExamService{
|
|||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
AloneExamDao aeDao;
|
AloneExamDao aeDao;
|
||||||
|
@Resource
|
||||||
|
private ThirdApi thirdApi;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
@@ -101,7 +106,18 @@ public class AloneExamServiceImpl implements IAloneExamService{
|
|||||||
// //这种情况汶是不存在的
|
// //这种情况汶是不存在的
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
try {
|
||||||
|
ExamStudyRecordParam param = new ExamStudyRecordParam();
|
||||||
|
param.setTestId(aea.getTestId());
|
||||||
|
param.setAid(aea.getAid());
|
||||||
|
thirdApi.syncExamStudyRecord(param);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
|
|||||||
@@ -214,11 +214,11 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
redisTemplate.opsForValue().set(teacherVo.get(0).getTeacherId(), teacherVo.get(0).getStatus());
|
redisTemplate.opsForValue().set(teacherVo.get(0).getTeacherId(), teacherVo.get(0).getStatus());
|
||||||
//设置过期时间为1天
|
//设置过期时间为1天
|
||||||
redisTemplate.expire(teacherVo.get(0).getTeacherId(), 24 * 60 * 60, TimeUnit.SECONDS);
|
redisTemplate.expire(teacherVo.get(0).getTeacherId(), 24 * 60 * 60, TimeUnit.SECONDS);
|
||||||
if (Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1") && ( t==null || t.getTeacherType() == 1)){
|
if (Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1") && t.getTeacherType() == 1 ){
|
||||||
ct.setTeacherName("BOE教师");
|
ct.setTeacherName("BOE教师");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1") && ( t==null || t.getTeacherType() == 1)){
|
if (Objects.equals(redisTemplate.opsForValue().get(ct.getTeacherId()), "1") && t.getTeacherType() == 1 ){
|
||||||
ct.setTeacherName("BOE教师");
|
ct.setTeacherName("BOE教师");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -345,6 +345,8 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
}
|
}
|
||||||
//追加学习时长
|
//追加学习时长
|
||||||
studyService.appendStudyDuration(sci.getStudyId(),item.getId(),sci.getContentId(),sci.getDuration());
|
studyService.appendStudyDuration(sci.getStudyId(),item.getId(),sci.getContentId(),sci.getDuration());
|
||||||
|
|
||||||
|
log.info(" 1 在线课学习记录 sci.getStudyId() = "+ sci.getStudyId() + " , sci.getCourseId() = " + sci.getCourseId() );
|
||||||
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(sci.getStudyId() ,sci.getCourseId(), token);
|
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(sci.getStudyId() ,sci.getCourseId(), token);
|
||||||
log.info("在线课学习记录"+allUserList);
|
log.info("在线课学习记录"+allUserList);
|
||||||
return success(item.getId());
|
return success(item.getId());
|
||||||
@@ -365,6 +367,8 @@ public class StudyCourseApi extends ApiBaseController{
|
|||||||
studyService.saveStudyInfo(sci,token);
|
studyService.saveStudyInfo(sci,token);
|
||||||
//学习记录成功后处理
|
//学习记录成功后处理
|
||||||
studyService.appendStudyDuration(sci.getStudyId(),sci.getStudyItemId(),sci.getContentId(),sci.getDuration());
|
studyService.appendStudyDuration(sci.getStudyId(),sci.getStudyItemId(),sci.getContentId(),sci.getDuration());
|
||||||
|
|
||||||
|
log.info("在线课学习记录 sci.getStudyId() = "+ sci.getStudyId() + " , sci.getCourseId() = " + sci.getCourseId() );
|
||||||
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(sci.getStudyId() ,sci.getCourseId(), token);
|
List<StudyCourse> allUserList = thirdApi.getStudyCourseList(sci.getStudyId() ,sci.getCourseId(), token);
|
||||||
log.info("在线课学习记录"+allUserList);
|
log.info("在线课学习记录"+allUserList);
|
||||||
//System.out.println("在线课学习记录"+allUserList);
|
//System.out.println("在线课学习记录"+allUserList);
|
||||||
|
|||||||
@@ -1,18 +1,9 @@
|
|||||||
package com.xboe.school.study.api;
|
package com.xboe.school.study.api;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollectionUtil;
|
|
||||||
import com.alibaba.fastjson2.JSON;
|
|
||||||
import com.xboe.core.orm.FieldFilters;
|
|
||||||
import com.xboe.core.orm.QueryBuilder;
|
|
||||||
import com.xboe.module.course.dao.CourseDao;
|
|
||||||
import com.xboe.module.course.dto.RankingDto;
|
|
||||||
import com.xboe.module.course.entity.Course;
|
|
||||||
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;
|
||||||
@@ -51,9 +42,6 @@ public class StudyCourseESApi extends ApiBaseController{
|
|||||||
@Autowired
|
@Autowired
|
||||||
IStudyCourseService service;
|
IStudyCourseService service;
|
||||||
|
|
||||||
@Resource
|
|
||||||
private CourseDao courseDao;
|
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private PhpOnlineStudyRecordScheduledTasks phpOnlineStudyRecordScheduledTasks;
|
private PhpOnlineStudyRecordScheduledTasks phpOnlineStudyRecordScheduledTasks;
|
||||||
|
|
||||||
@@ -66,58 +54,6 @@ public class StudyCourseESApi extends ApiBaseController{
|
|||||||
try {
|
try {
|
||||||
dto.setAccountId(getCurrent().getAccountId());
|
dto.setAccountId(getCurrent().getAccountId());
|
||||||
PageList<CourseStudyDto> rs=search.search(page.getStartRow(),page.getPageSize(), dto);
|
PageList<CourseStudyDto> rs=search.search(page.getStartRow(),page.getPageSize(), dto);
|
||||||
List<CourseStudyDto> list = rs.getList();
|
|
||||||
List<String> emptyIds = new ArrayList<>();
|
|
||||||
log.info("test data gengxin CourseStudyDto list ==> {}", JSON.toJSONString(list));
|
|
||||||
if(CollectionUtil.isNotEmpty(list)){
|
|
||||||
log.info("test data gengxin CourseStudyDto isNotEmpty list ==> {}", JSON.toJSONString(list));
|
|
||||||
//todo 过滤数据
|
|
||||||
for(CourseStudyDto courseStudyDto : list){
|
|
||||||
log.info("test data gengxin CourseStudyDto isNotEmpty item ==> {}", JSON.toJSONString(courseStudyDto));
|
|
||||||
//在线课 录播课
|
|
||||||
if(courseStudyDto.getCourseType() == 20 || courseStudyDto.getCourseType() == 21){
|
|
||||||
if(StringUtils.isBlank(courseStudyDto.getCourseImage())){
|
|
||||||
emptyIds.add(courseStudyDto.getCourseId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//todo 图片空返回结果
|
|
||||||
List<CourseStudyDto> emptyImgCourseStudyDtos = new ArrayList();
|
|
||||||
|
|
||||||
//在线课查询
|
|
||||||
if(CollectionUtil.isNotEmpty(emptyIds)){
|
|
||||||
QueryBuilder query = QueryBuilder.from(Course.class);
|
|
||||||
query.addFields("id","name","type","coverImg");
|
|
||||||
//todo 确认下 是否是这个字段
|
|
||||||
query.addFilter(FieldFilters.in("id",emptyIds));
|
|
||||||
query.addFilter(FieldFilters.eq("enabled",true));
|
|
||||||
query.addFilter(FieldFilters.eq("deleted",false));
|
|
||||||
List<Object[]> listFields = courseDao.findListFields(query.builder());
|
|
||||||
log.info("test data gengxin CourseStudyDto isNotEmpty listFields ==> {}", JSON.toJSONString(listFields));
|
|
||||||
if(CollectionUtil.isNotEmpty(listFields)){
|
|
||||||
for(Object[] objs : listFields) {
|
|
||||||
CourseStudyDto CourseStudyDtoResult=new CourseStudyDto();
|
|
||||||
CourseStudyDtoResult.setId((String) objs[0]);
|
|
||||||
CourseStudyDtoResult.setCourseName((String)objs[1]);
|
|
||||||
CourseStudyDtoResult.setCourseType((Integer) objs[2]);
|
|
||||||
CourseStudyDtoResult.setCourseImage((String)objs[3]);
|
|
||||||
emptyImgCourseStudyDtos.add(CourseStudyDtoResult);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.info("test data gengxin CourseStudyDto isNotEmpty emptyImgCourseStudyDtos ==> {}", JSON.toJSONString(emptyImgCourseStudyDtos));
|
|
||||||
|
|
||||||
//todo 进行赋值处理 最外层
|
|
||||||
emptyImgCourseStudyDtos.forEach(item -> {
|
|
||||||
list.forEach(subjectItem -> {
|
|
||||||
if(item.getCourseId().equals(subjectItem.getCourseId())){
|
|
||||||
//赋值
|
|
||||||
subjectItem.setCourseImage(item.getCourseImage());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
log.info("test data gengxin CourseStudyDto isNotEmpty result ==> {}", JSON.toJSONString(list));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return success(rs);
|
return success(rs);
|
||||||
}catch(Exception e) {
|
}catch(Exception e) {
|
||||||
log.error("查询报名学习ES失败",e);
|
log.error("查询报名学习ES失败",e);
|
||||||
|
|||||||
@@ -0,0 +1,99 @@
|
|||||||
|
package com.xboe.school.study.api;
|
||||||
|
|
||||||
|
import com.xboe.school.study.service.IStudyService;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import org.springframework.data.redis.connection.RedisConnection;
|
||||||
|
import org.springframework.data.redis.core.Cursor;
|
||||||
|
import org.springframework.data.redis.core.ScanOptions;
|
||||||
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author by lyc
|
||||||
|
* @date 2025/3/3
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class StudyCourseTask {
|
||||||
|
|
||||||
|
private final IStudyService studyService;
|
||||||
|
private final StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 定时任务
|
||||||
|
* 获取redis 中学习结束的数据更新入库
|
||||||
|
* */
|
||||||
|
@XxlJob("saveStudyCourseItemLastTime")
|
||||||
|
public void saveStudyCourseItemLastTime() {
|
||||||
|
// 1. 定义匹配模式(匹配所有目标key)
|
||||||
|
final String KEY_PATTERN = "studyContentId:*:last_active";
|
||||||
|
|
||||||
|
// 2. 使用SCAN安全遍历(避免阻塞)
|
||||||
|
ScanOptions options = ScanOptions.scanOptions()
|
||||||
|
.match(KEY_PATTERN)
|
||||||
|
.count(100) // 分页大小
|
||||||
|
.build();
|
||||||
|
|
||||||
|
try (RedisConnection connection = Objects.requireNonNull(redisTemplate.getConnectionFactory()).getConnection()) {
|
||||||
|
Cursor<byte[]> cursor = connection.scan(options);
|
||||||
|
// 3. 遍历处理符合条件的key
|
||||||
|
while (cursor.hasNext()) {
|
||||||
|
String redisKey = new String(cursor.next());
|
||||||
|
// 4. 获取剩余TTL(秒)
|
||||||
|
Long ttl = redisTemplate.getExpire(redisKey, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
// 5. 过滤条件:剩余时间 >= 29天23小时30分钟(转换为秒)
|
||||||
|
// 总需时间 = (30天 - 30分钟) = 29天23小时30分钟 = 2590200秒
|
||||||
|
// 5分钟 300秒 || 2592000 - 300 = 2591700
|
||||||
|
if (ttl <= 2590200) {
|
||||||
|
try {
|
||||||
|
// 6. 提取studyContentId
|
||||||
|
String[] parts = redisKey.split(":");
|
||||||
|
if (parts.length < 2) continue;
|
||||||
|
String studyContentId = parts[1];
|
||||||
|
|
||||||
|
// 7. 获取存储的时间点(示例逻辑)
|
||||||
|
String lastStudyTimeStr = redisTemplate.opsForValue().get(redisKey);
|
||||||
|
if (lastStudyTimeStr == null) continue;
|
||||||
|
int lastStudyTime = Integer.parseInt(lastStudyTimeStr);
|
||||||
|
|
||||||
|
// 8. 更新数据库(调用已有服务方法)
|
||||||
|
studyService.updateStudyCourseItemLastTime(studyContentId, lastStudyTime, "system_job");
|
||||||
|
|
||||||
|
// 9. 删除Redis键(原子操作)
|
||||||
|
redisTemplate.delete(redisKey);
|
||||||
|
|
||||||
|
log.info("处理成功 key: {}, lastStudyTime: {}", redisKey, lastStudyTime);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("处理失败 key: {}", redisKey, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
cursor.close();
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("定时任务执行异常", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* // 新增日志逻辑
|
||||||
|
if (ttl <= 172800) {
|
||||||
|
studyService.saveCourseExpireLog(
|
||||||
|
studyContentId,
|
||||||
|
lastStudyTime,
|
||||||
|
redisKey,
|
||||||
|
ttl,
|
||||||
|
"system_job"
|
||||||
|
);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -99,4 +99,5 @@ public interface IStudyService {
|
|||||||
|
|
||||||
List<StudyCourseItem> getList(String courseId, String contentId, String name, Integer status);
|
List<StudyCourseItem> getList(String courseId, String contentId, String name, Integer status);
|
||||||
|
|
||||||
|
void updateStudyCourseItemLastTime(String studyContentId, int lastStudyTime, String systemJob);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.xboe.school.study.service.impl;
|
package com.xboe.school.study.service.impl;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
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.ArrayList;
|
||||||
@@ -15,6 +16,7 @@ import com.xboe.school.study.entity.StudyCourse;
|
|||||||
import com.xboe.system.user.entity.User;
|
import com.xboe.system.user.entity.User;
|
||||||
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.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import com.xboe.common.OrderCondition;
|
import com.xboe.common.OrderCondition;
|
||||||
@@ -51,6 +53,9 @@ public class StudyServiceImpl implements IStudyService{
|
|||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
UserDao userDao;
|
UserDao userDao;
|
||||||
|
@Autowired
|
||||||
|
StringRedisTemplate redisTemplate;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public StudyCourseItem checkHas(String studyId,String contentId) {
|
public StudyCourseItem checkHas(String studyId,String contentId) {
|
||||||
@@ -324,8 +329,20 @@ public class StudyServiceImpl implements IStudyService{
|
|||||||
|
|
||||||
// 更新 前端传输已学习时长
|
// 更新 前端传输已学习时长
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
|
||||||
public void updateLastTime(String studyContentId, int lastStudyTime,String aid) {
|
public void updateLastTime(String studyContentId, int lastStudyTime,String aid) {
|
||||||
|
// 20250303 优化 多次更新改一次更新
|
||||||
|
// 更新Redis中的最后活跃时间(带30秒过期)
|
||||||
|
redisTemplate.opsForValue().set(
|
||||||
|
"studyContentId:" + studyContentId + ":last_active",
|
||||||
|
String.valueOf(lastStudyTime),
|
||||||
|
Duration.ofSeconds(2592000)
|
||||||
|
);
|
||||||
|
// Duration.ofDays(30) 也就是 2592000秒
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void updateStudyCourseItemLastTime(String studyContentId, int lastStudyTime,String aid) {
|
||||||
// 更新最后的学习时间点
|
// 更新最后的学习时间点
|
||||||
LocalDateTime now=LocalDateTime.now();
|
LocalDateTime now=LocalDateTime.now();
|
||||||
UpdateBuilder update=UpdateBuilder.from(StudyCourseItem.class);
|
UpdateBuilder update=UpdateBuilder.from(StudyCourseItem.class);
|
||||||
@@ -335,7 +352,6 @@ public class StudyServiceImpl implements IStudyService{
|
|||||||
update.addUpdateField("lastStudyTime", lastStudyTime);
|
update.addUpdateField("lastStudyTime", lastStudyTime);
|
||||||
update.addUpdateField("lastTime", now);
|
update.addUpdateField("lastTime", now);
|
||||||
scItemDao.update(update.builder());
|
scItemDao.update(update.builder());
|
||||||
//增加用户的学习时长,在api中调用
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user