mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-23 20:42:42 +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.service.*;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.response.UserLatestLearn;
|
||||
import xyz.playedu.api.util.PrivacyUtil;
|
||||
|
||||
import java.util.*;
|
||||
@ -39,6 +40,9 @@ public class UserController {
|
||||
@Autowired
|
||||
private UserCourseRecordService userCourseRecordService;
|
||||
|
||||
@Autowired
|
||||
private UserCourseHourRecordService userCourseHourRecordService;
|
||||
|
||||
@Autowired
|
||||
private UserLearnDurationStatsService userLearnDurationStatsService;
|
||||
|
||||
@ -159,4 +163,37 @@ public class UserController {
|
||||
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,15 +4,17 @@ import org.apache.ibatis.annotations.Mapper;
|
||||
import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【user_course_hour_records】的数据库操作Mapper
|
||||
* @createDate 2023-03-20 16:41:08
|
||||
* @Entity xyz.playedu.api.domain.UserCourseHourRecord
|
||||
*/
|
||||
* @author tengteng
|
||||
* @description 针对表【user_course_hour_records】的数据库操作Mapper
|
||||
* @createDate 2023-03-20 16:41:08
|
||||
* @Entity xyz.playedu.api.domain.UserCourseHourRecord
|
||||
*/
|
||||
@Mapper
|
||||
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);
|
||||
|
||||
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) {
|
||||
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;
|
||||
}
|
@ -5,23 +5,31 @@
|
||||
<mapper namespace="xyz.playedu.api.mapper.UserCourseHourRecordMapper">
|
||||
|
||||
<resultMap id="BaseResultMap" type="xyz.playedu.api.domain.UserCourseHourRecord">
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="userId" column="user_id" jdbcType="INTEGER"/>
|
||||
<result property="courseId" column="course_id" jdbcType="INTEGER"/>
|
||||
<result property="hourId" column="hour_id" jdbcType="INTEGER"/>
|
||||
<result property="totalDuration" column="total_duration" jdbcType="INTEGER"/>
|
||||
<result property="finishedDuration" column="finished_duration" jdbcType="INTEGER"/>
|
||||
<result property="realDuration" column="real_duration" jdbcType="INTEGER"/>
|
||||
<result property="isFinished" column="is_finished" jdbcType="TINYINT"/>
|
||||
<result property="finishedAt" column="finished_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||||
<id property="id" column="id" jdbcType="INTEGER"/>
|
||||
<result property="userId" column="user_id" jdbcType="INTEGER"/>
|
||||
<result property="courseId" column="course_id" jdbcType="INTEGER"/>
|
||||
<result property="hourId" column="hour_id" jdbcType="INTEGER"/>
|
||||
<result property="totalDuration" column="total_duration" jdbcType="INTEGER"/>
|
||||
<result property="finishedDuration" column="finished_duration" jdbcType="INTEGER"/>
|
||||
<result property="realDuration" column="real_duration" jdbcType="INTEGER"/>
|
||||
<result property="isFinished" column="is_finished" jdbcType="TINYINT"/>
|
||||
<result property="finishedAt" column="finished_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="createdAt" column="created_at" jdbcType="TIMESTAMP"/>
|
||||
<result property="updatedAt" column="updated_at" jdbcType="TIMESTAMP"/>
|
||||
</resultMap>
|
||||
|
||||
<sql id="Base_Column_List">
|
||||
id,user_id,course_id,
|
||||
hour_id,total_duration,finished_duration,
|
||||
real_duration,is_finished,finished_at,
|
||||
id
|
||||
,user_id,course_id,
|
||||
hour_id,total_duration,finished_duration,
|
||||
real_duration,is_finished,finished_at,
|
||||
created_at,updated_at
|
||||
</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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user