mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-24 21:32:43 +08:00
added: 最近学习api
This commit is contained in:
parent
b2f72644e0
commit
c8182447ba
@ -13,6 +13,7 @@ import xyz.playedu.api.exception.ServiceException;
|
|||||||
import xyz.playedu.api.request.frontend.ChangePasswordRequest;
|
import xyz.playedu.api.request.frontend.ChangePasswordRequest;
|
||||||
import xyz.playedu.api.service.*;
|
import xyz.playedu.api.service.*;
|
||||||
import xyz.playedu.api.types.JsonResponse;
|
import xyz.playedu.api.types.JsonResponse;
|
||||||
|
import xyz.playedu.api.types.response.UserLatestLearn;
|
||||||
import xyz.playedu.api.util.PrivacyUtil;
|
import xyz.playedu.api.util.PrivacyUtil;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -39,6 +40,9 @@ public class UserController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private UserCourseRecordService userCourseRecordService;
|
private UserCourseRecordService userCourseRecordService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserCourseHourRecordService userCourseHourRecordService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private UserLearnDurationStatsService userLearnDurationStatsService;
|
private UserLearnDurationStatsService userLearnDurationStatsService;
|
||||||
|
|
||||||
@ -159,4 +163,37 @@ public class UserController {
|
|||||||
return JsonResponse.data(data);
|
return JsonResponse.data(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@GetMapping("/latest-learn")
|
||||||
|
public JsonResponse latestLearn() {
|
||||||
|
// 读取当前学员最近100条学习的线上课
|
||||||
|
List<Integer> courseIds = userCourseHourRecordService.getLatestCourseIds(FCtx.getId(), 100);
|
||||||
|
if (courseIds == null || courseIds.size() == 0) {
|
||||||
|
return JsonResponse.data(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 线上课
|
||||||
|
Map<Integer, Course> courses = courseService.chunks(courseIds, new ArrayList<>() {{
|
||||||
|
add("id");
|
||||||
|
add("title");
|
||||||
|
add("thumb");
|
||||||
|
add("short_desc");
|
||||||
|
add("class_hour");
|
||||||
|
add("is_required");
|
||||||
|
}}).stream().collect(Collectors.toMap(Course::getId, e -> e));
|
||||||
|
|
||||||
|
// 获取学员的线上课进度
|
||||||
|
Map<Integer, UserCourseRecord> records = userCourseRecordService.chunk(FCtx.getId(), courseIds).stream().collect(Collectors.toMap(UserCourseRecord::getCourseId, e -> e));
|
||||||
|
List<UserLatestLearn> userLatestLearns = new ArrayList<>();
|
||||||
|
for (Integer courseId : courseIds) {
|
||||||
|
UserCourseRecord record = records.get(courseId);
|
||||||
|
Course tmpCourse = courses.get(courseId);
|
||||||
|
userLatestLearns.add(new UserLatestLearn() {{
|
||||||
|
setCourse(tmpCourse);
|
||||||
|
setUserCourseRecord(record);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
return JsonResponse.data(userLatestLearns);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -4,6 +4,8 @@ import org.apache.ibatis.annotations.Mapper;
|
|||||||
import xyz.playedu.api.domain.UserCourseHourRecord;
|
import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
* @description 针对表【user_course_hour_records】的数据库操作Mapper
|
* @description 针对表【user_course_hour_records】的数据库操作Mapper
|
||||||
@ -12,7 +14,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||||||
*/
|
*/
|
||||||
@Mapper
|
@Mapper
|
||||||
public interface UserCourseHourRecordMapper extends BaseMapper<UserCourseHourRecord> {
|
public interface UserCourseHourRecordMapper extends BaseMapper<UserCourseHourRecord> {
|
||||||
|
List<Integer> getLatestCourseIds(Integer userId, Integer size);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,4 +18,6 @@ public interface UserCourseHourRecordService extends IService<UserCourseHourReco
|
|||||||
Integer getFinishedHourCount(Integer userId, Integer courseId);
|
Integer getFinishedHourCount(Integer userId, Integer courseId);
|
||||||
|
|
||||||
List<UserCourseHourRecord> getRecords(Integer userId, Integer courseId);
|
List<UserCourseHourRecord> getRecords(Integer userId, Integer courseId);
|
||||||
|
|
||||||
|
List<Integer> getLatestCourseIds(Integer userId, Integer size);
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,11 @@ public class UserCourseHourRecordServiceImpl extends ServiceImpl<UserCourseHourR
|
|||||||
public List<UserCourseHourRecord> getRecords(Integer userId, Integer courseId) {
|
public List<UserCourseHourRecord> getRecords(Integer userId, Integer courseId) {
|
||||||
return list(query().getWrapper().eq("user_id", userId).eq("course_id", courseId));
|
return list(query().getWrapper().eq("user_id", userId).eq("course_id", courseId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Integer> getLatestCourseIds(Integer userId, Integer size) {
|
||||||
|
return getBaseMapper().getLatestCourseIds(userId, size);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,18 @@
|
|||||||
|
package xyz.playedu.api.types.response;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import xyz.playedu.api.domain.Course;
|
||||||
|
import xyz.playedu.api.domain.UserCourseRecord;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/3/27 15:29
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class UserLatestLearn {
|
||||||
|
@JsonProperty("course")
|
||||||
|
private Course course;
|
||||||
|
@JsonProperty("record")
|
||||||
|
private UserCourseRecord userCourseRecord;
|
||||||
|
}
|
@ -19,9 +19,17 @@
|
|||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="Base_Column_List">
|
<sql id="Base_Column_List">
|
||||||
id,user_id,course_id,
|
id
|
||||||
|
,user_id,course_id,
|
||||||
hour_id,total_duration,finished_duration,
|
hour_id,total_duration,finished_duration,
|
||||||
real_duration,is_finished,finished_at,
|
real_duration,is_finished,finished_at,
|
||||||
created_at,updated_at
|
created_at,updated_at
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<select id="getLatestCourseIds" resultType="java.lang.Integer">
|
||||||
|
select distinct `user_course_hour_records`.`course_id`
|
||||||
|
from `user_course_hour_records`
|
||||||
|
where `user_course_hour_records`.`user_id` = #{userId}
|
||||||
|
order by `user_course_hour_records`.`updated_at` desc limit #{size};
|
||||||
|
</select>
|
||||||
</mapper>
|
</mapper>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user