mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-24 10:19:31 +08:00
课程详情api返回学员的课时学习记录
This commit is contained in:
parent
4514adb9d0
commit
2b89ed310a
@ -35,11 +35,11 @@ public class FCtx {
|
||||
THREAD_LOCAL.remove();
|
||||
}
|
||||
|
||||
public static void setUserId(Integer id) {
|
||||
public static void setId(Integer id) {
|
||||
put(KEY_USER_ID, id);
|
||||
}
|
||||
|
||||
public static Integer getUserId() {
|
||||
public static Integer getId() {
|
||||
return (Integer) get(KEY_USER_ID);
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ public class UserBus {
|
||||
Long curTime = System.currentTimeMillis();
|
||||
|
||||
// 最近一次学习时间
|
||||
Long lastTime = userLastLearnTimeCache.get(FCtx.getUserId());
|
||||
Long lastTime = userLastLearnTimeCache.get(FCtx.getId());
|
||||
// 最大周期为10s
|
||||
if (lastTime == null || curTime - lastTime > 10000) {
|
||||
lastTime = curTime - 10000;
|
||||
|
@ -7,11 +7,9 @@ import org.springframework.web.bind.annotation.*;
|
||||
import xyz.playedu.api.FCtx;
|
||||
import xyz.playedu.api.domain.Course;
|
||||
import xyz.playedu.api.domain.CourseHour;
|
||||
import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.service.CourseChapterService;
|
||||
import xyz.playedu.api.service.CourseHourService;
|
||||
import xyz.playedu.api.service.CourseService;
|
||||
import xyz.playedu.api.service.UserCourseRecordService;
|
||||
import xyz.playedu.api.service.*;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.paginate.CoursePaginateFiler;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
@ -39,6 +37,9 @@ public class CourseController {
|
||||
@Autowired
|
||||
private UserCourseRecordService userCourseRecordService;
|
||||
|
||||
@Autowired
|
||||
private UserCourseHourRecordService userCourseHourRecordService;
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
|
||||
Integer page = MapUtils.getInteger(params, "page", 1);
|
||||
@ -63,7 +64,8 @@ public class CourseController {
|
||||
data.put("course", course);
|
||||
data.put("chapters", chapterService.getChaptersByCourseId(course.getId()));
|
||||
data.put("hours", hourService.getHoursByCourseId(course.getId()).stream().collect(Collectors.groupingBy(CourseHour::getChapterId)));
|
||||
data.put("learn_record", userCourseRecordService.find(FCtx.getUserId(), course.getId()));
|
||||
data.put("learn_record", userCourseRecordService.find(FCtx.getId(), course.getId()));
|
||||
data.put("learn_hour_records", userCourseHourRecordService.getRecords(FCtx.getId(), course.getId()).stream().collect(Collectors.toMap(UserCourseHourRecord::getHourId, e -> e)));
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class LoginController {
|
||||
@PostMapping("/logout")
|
||||
public JsonResponse logout() throws JwtLogoutException {
|
||||
jwtService.userLogout(RequestUtil.token());
|
||||
ctx.publishEvent(new UserLogoutEvent(this, FCtx.getUserId(), FCtx.getJwtJti()));
|
||||
ctx.publishEvent(new UserLogoutEvent(this, FCtx.getId(), FCtx.getJwtJti()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -58,8 +58,8 @@ public class UserController {
|
||||
|
||||
@PutMapping("/avatar")
|
||||
public JsonResponse changeAvatar(MultipartFile file) {
|
||||
UserUploadImageLog log = uploadService.userAvatar(FCtx.getUserId(), file, FrontendConstant.USER_UPLOAD_IMAGE_TYPE_AVATAR, FrontendConstant.USER_UPLOAD_IMAGE_SCENE_AVATAR);
|
||||
userService.changeAvatar(FCtx.getUserId(), log.getUrl());
|
||||
UserUploadImageLog log = uploadService.userAvatar(FCtx.getId(), file, FrontendConstant.USER_UPLOAD_IMAGE_TYPE_AVATAR, FrontendConstant.USER_UPLOAD_IMAGE_SCENE_AVATAR);
|
||||
userService.changeAvatar(FCtx.getId(), log.getUrl());
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@ -76,7 +76,7 @@ public class UserController {
|
||||
return JsonResponse.error("请选择部门");
|
||||
}
|
||||
|
||||
List<Integer> userJoinDepIds = userService.getDepIdsByUserId(FCtx.getUserId());
|
||||
List<Integer> userJoinDepIds = userService.getDepIdsByUserId(FCtx.getId());
|
||||
if (userJoinDepIds == null) {
|
||||
return JsonResponse.error("当前学员未加入任何部门");
|
||||
}
|
||||
@ -112,7 +112,7 @@ public class UserController {
|
||||
// -------- 读取学习进度 ----------
|
||||
Map<Integer, UserCourseRecord> learnCourseRecords = new HashMap<>();
|
||||
if (courses.size() > 0) {
|
||||
learnCourseRecords = userCourseRecordService.chunk(FCtx.getUserId(), courses.stream().map(Course::getId).toList()).stream().collect(Collectors.toMap(UserCourseRecord::getCourseId, e -> e));
|
||||
learnCourseRecords = userCourseRecordService.chunk(FCtx.getId(), courses.stream().map(Course::getId).toList()).stream().collect(Collectors.toMap(UserCourseRecord::getCourseId, e -> e));
|
||||
}
|
||||
data.put("learn_course_records", learnCourseRecords);
|
||||
|
||||
@ -120,8 +120,8 @@ public class UserController {
|
||||
Integer nunRequiredHourCount = 0;//选修课时
|
||||
Integer requiredFinishedHourCount = 0;//已完成必修课时
|
||||
Integer nunRequiredFinishedHourCount = 0;//已完成选修课时
|
||||
Integer todayLearnDuration = userLearnDurationStatsService.todayUserDuration(FCtx.getUserId());//今日学习时长
|
||||
Integer learnDuration = userLearnDurationStatsService.userDuration(FCtx.getUserId());//学习总时长
|
||||
Integer todayLearnDuration = userLearnDurationStatsService.todayUserDuration(FCtx.getId());//今日学习时长
|
||||
Integer learnDuration = userLearnDurationStatsService.userDuration(FCtx.getId());//学习总时长
|
||||
|
||||
// -------- 学习数据统计 ----------
|
||||
if (courses.size() > 0) {
|
||||
|
@ -60,7 +60,7 @@ public class FrontMiddleware implements HandlerInterceptor {
|
||||
}
|
||||
|
||||
FCtx.setUser(user);
|
||||
FCtx.setUserId(user.getId());
|
||||
FCtx.setId(user.getId());
|
||||
FCtx.setJWtJti(payload.getJti());
|
||||
|
||||
return HandlerInterceptor.super.preHandle(request, response, handler);
|
||||
|
@ -3,6 +3,8 @@ package xyz.playedu.api.service;
|
||||
import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_course_hour_records】的数据库操作Service
|
||||
@ -14,4 +16,6 @@ public interface UserCourseHourRecordService extends IService<UserCourseHourReco
|
||||
UserCourseHourRecord storeOrUpdate(Integer userId, Integer courseId, Integer hourId, Integer duration, Integer totalDuration);
|
||||
|
||||
Integer getFinishedHourCount(Integer userId, Integer courseId);
|
||||
|
||||
List<UserCourseHourRecord> getRecords(Integer userId, Integer courseId);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import xyz.playedu.api.mapper.UserCourseHourRecordMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -81,6 +82,11 @@ public class UserCourseHourRecordServiceImpl extends ServiceImpl<UserCourseHourR
|
||||
public Integer getFinishedHourCount(Integer userId, Integer courseId) {
|
||||
return Math.toIntExact(count(query().getWrapper().eq("user_id", userId).eq("course_id", courseId).eq("is_finished", 1)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCourseHourRecord> getRecords(Integer userId, Integer courseId) {
|
||||
return list(query().getWrapper().eq("user_id", userId).eq("course_id", courseId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user