mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-19 14:19:31 +08:00
user/courses返回学员的线上课学习课时数量
This commit is contained in:
parent
4fd067b68c
commit
67c0dc7ae3
@ -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.mapper.UserCourseHourRecordCountMapper;
|
||||
import xyz.playedu.api.types.response.UserLatestLearn;
|
||||
import xyz.playedu.api.util.PrivacyUtil;
|
||||
|
||||
@ -121,10 +122,12 @@ public class UserController {
|
||||
|
||||
data.put("courses", courses);
|
||||
|
||||
List<Integer> courseIds = courses.stream().map(Course::getId).toList();
|
||||
|
||||
// -------- 读取学习进度 ----------
|
||||
Map<Integer, UserCourseRecord> learnCourseRecords = new HashMap<>();
|
||||
if (courses.size() > 0) {
|
||||
learnCourseRecords = userCourseRecordService.chunk(FCtx.getId(), courses.stream().map(Course::getId).toList()).stream().collect(Collectors.toMap(UserCourseRecord::getCourseId, e -> e));
|
||||
learnCourseRecords = userCourseRecordService.chunk(FCtx.getId(), courseIds).stream().collect(Collectors.toMap(UserCourseRecord::getCourseId, e -> e));
|
||||
}
|
||||
data.put("learn_course_records", learnCourseRecords);
|
||||
|
||||
@ -167,18 +170,21 @@ public class UserController {
|
||||
}
|
||||
}
|
||||
HashMap<String, Integer> stats = new HashMap<>();
|
||||
stats.put("required_course_count", requiredCourseCount);
|
||||
stats.put("nun_required_course_count", nunRequiredCourseCount);
|
||||
stats.put("required_finished_course_count", requiredFinishedCourseCount);
|
||||
stats.put("nun_required_finished_course_count", nunRequiredFinishedCourseCount);
|
||||
stats.put("required_hour_count", requiredHourCount);
|
||||
stats.put("nun_required_hour_count", nunRequiredHourCount);
|
||||
stats.put("required_finished_hour_count", requiredFinishedHourCount);
|
||||
stats.put("nun_required_finished_hour_count", nunRequiredFinishedHourCount);
|
||||
stats.put("today_learn_duration", todayLearnDuration);
|
||||
stats.put("learn_duration", learnDuration);
|
||||
stats.put("required_course_count", requiredCourseCount);//必修课数量
|
||||
stats.put("nun_required_course_count", nunRequiredCourseCount);//选修课数量
|
||||
stats.put("required_finished_course_count", requiredFinishedCourseCount);//必修已完成线上课数
|
||||
stats.put("nun_required_finished_course_count", nunRequiredFinishedCourseCount);//选修已完成线上课数
|
||||
stats.put("required_hour_count", requiredHourCount);//必修课时总数
|
||||
stats.put("nun_required_hour_count", nunRequiredHourCount);//选修课时总数
|
||||
stats.put("required_finished_hour_count", requiredFinishedHourCount);//必修已完成课时数
|
||||
stats.put("nun_required_finished_hour_count", nunRequiredFinishedHourCount);//选修已完成课时数
|
||||
stats.put("today_learn_duration", todayLearnDuration);//今日学习时长[单位:毫秒]
|
||||
stats.put("learn_duration", learnDuration);//学习总时长[单位:毫秒]
|
||||
data.put("stats", stats);
|
||||
|
||||
// 当前学员每个线上课的学习课时数量(只要学习了就算,不一定需要完成)
|
||||
data.put("user_course_hour_count", userCourseHourRecordService.getUserCourseHourCount(FCtx.getId(), courseIds, null).stream().collect(Collectors.toMap(UserCourseHourRecordCountMapper::getCourseId, UserCourseHourRecordCountMapper::getTotal)));
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
|
@ -3,6 +3,7 @@ package xyz.playedu.api.mapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCountMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -15,6 +16,8 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface UserCourseHourRecordMapper extends BaseMapper<UserCourseHourRecord> {
|
||||
List<UserCourseHourRecord> getUserLatestRecords(Integer userId, Integer size);
|
||||
|
||||
List<UserCourseHourRecordCountMapper> getUserCourseHourCount(Integer userId, List<Integer> courseIds, Integer isFinished);
|
||||
}
|
||||
|
||||
|
||||
|
@ -2,6 +2,7 @@ package xyz.playedu.api.service;
|
||||
|
||||
import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCountMapper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -22,4 +23,6 @@ public interface UserCourseHourRecordService extends IService<UserCourseHourReco
|
||||
List<UserCourseHourRecord> getLatestCourseIds(Integer userId, Integer size);
|
||||
|
||||
void removeByCourseId(Integer courseId);
|
||||
|
||||
List<UserCourseHourRecordCountMapper> getUserCourseHourCount(Integer userId, List<Integer> courseIds, Integer isFinished);
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import xyz.playedu.api.event.UserCourseHourFinishedEvent;
|
||||
import xyz.playedu.api.service.UserCourseHourRecordService;
|
||||
import xyz.playedu.api.mapper.UserCourseHourRecordMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCountMapper;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -89,6 +90,11 @@ public class UserCourseHourRecordServiceImpl extends ServiceImpl<UserCourseHourR
|
||||
public void removeByCourseId(Integer courseId) {
|
||||
remove(query().getWrapper().eq("course_id", courseId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCourseHourRecordCountMapper> getUserCourseHourCount(Integer userId, List<Integer> courseIds, Integer isFinished) {
|
||||
return getBaseMapper().getUserCourseHourCount(userId, courseIds, isFinished);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,15 @@
|
||||
package xyz.playedu.api.types.mapper;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/3/29 10:01
|
||||
*/
|
||||
@Data
|
||||
public class UserCourseHourRecordCountMapper {
|
||||
@JsonProperty("course_id")
|
||||
private Integer courseId;
|
||||
private Integer total;
|
||||
}
|
@ -34,9 +34,9 @@ spring:
|
||||
task:
|
||||
execution:
|
||||
pool:
|
||||
max-size: 8 #最大线程数量
|
||||
core-size: 4 #初始化线程数量
|
||||
queue-capacity: 1000 #队列最大长度
|
||||
max-size: 4 #最大线程数量
|
||||
core-size: 2 #初始化线程数量
|
||||
queue-capacity: 10000 #队列最大长度
|
||||
keep-alive: 60s #线程终止前允许保存的最大时间
|
||||
shutdown:
|
||||
await-termination: true
|
||||
|
@ -39,4 +39,17 @@
|
||||
order by `t1`.`updated_at` desc
|
||||
limit #{size};
|
||||
</select>
|
||||
<select id="getUserCourseHourCount"
|
||||
resultType="xyz.playedu.api.types.mapper.UserCourseHourRecordCountMapper">
|
||||
SELECT `course_id`, count(1) AS `total`
|
||||
FROM `user_course_hour_records`
|
||||
WHERE `user_id` = #{userId}
|
||||
<if test="courseIds != null and #{courseIds}.size() > 0">
|
||||
AND `course_id` IN (<foreach collection="courseIds" item="courseId" separator=",">#{courseId}</foreach>)
|
||||
</if>
|
||||
<if test="isFinished != null">
|
||||
AND `is_finisehd` = #{isFinished}
|
||||
</if>
|
||||
GROUP BY `course_id`;
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
x
Reference in New Issue
Block a user