mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-28 08:17:30 +08:00
线上课-学员api返回学员的线上课已学课时数量
This commit is contained in:
parent
72d05b8e16
commit
f0378c832d
2
pom.xml
2
pom.xml
@ -10,7 +10,7 @@
|
||||
</parent>
|
||||
<groupId>xyz.playedu</groupId>
|
||||
<artifactId>playedu-api</artifactId>
|
||||
<version>1.0-beta.4</version>
|
||||
<version>1.0-beta.5</version>
|
||||
<name>playedu-api</name>
|
||||
<description>playedu-api</description>
|
||||
<properties>
|
||||
|
@ -28,9 +28,11 @@ import xyz.playedu.api.event.UserCourseRecordDestroyEvent;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.CourseUserDestroyRequest;
|
||||
import xyz.playedu.api.service.CourseService;
|
||||
import xyz.playedu.api.service.UserCourseHourRecordService;
|
||||
import xyz.playedu.api.service.UserCourseRecordService;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordUserCountMapper;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserPaginateFilter;
|
||||
|
||||
@ -52,6 +54,8 @@ public class CourseUserController {
|
||||
|
||||
@Autowired private UserCourseRecordService userCourseRecordService;
|
||||
|
||||
@Autowired private UserCourseHourRecordService userCourseHourRecordService;
|
||||
|
||||
@Autowired private UserService userService;
|
||||
|
||||
@Autowired private ApplicationContext ctx;
|
||||
@ -85,18 +89,29 @@ public class CourseUserController {
|
||||
|
||||
PaginationResult<User> result = userService.paginate(page, size, filter);
|
||||
|
||||
List<Integer> userIds = result.getData().stream().map(User::getId).toList();
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("data", result.getData());
|
||||
data.put("total", result.getTotal());
|
||||
data.put(
|
||||
"user_course_records",
|
||||
userCourseRecordService.chunk(
|
||||
result.getData().stream().map(User::getId).toList(),
|
||||
userIds,
|
||||
new ArrayList<>() {
|
||||
{
|
||||
add(courseId);
|
||||
}
|
||||
}));
|
||||
data.put(
|
||||
"user_course_hour_user_count",
|
||||
userCourseHourRecordService
|
||||
.getUserCourseHourUserCount(courseId, userIds, null)
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
UserCourseHourRecordUserCountMapper::getUserId,
|
||||
UserCourseHourRecordUserCountMapper::getTotal)));
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ import xyz.playedu.api.request.backend.UserRequest;
|
||||
import xyz.playedu.api.service.*;
|
||||
import xyz.playedu.api.service.internal.UserDepartmentService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCountMapper;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCourseCountMapper;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserCourseHourRecordPaginateFilter;
|
||||
import xyz.playedu.api.types.paginate.UserCourseRecordPaginateFilter;
|
||||
@ -488,8 +488,8 @@ public class UserController {
|
||||
userCourseHourRecordService.getUserCourseHourCount(id, courseIds, null).stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
UserCourseHourRecordCountMapper::getCourseId,
|
||||
UserCourseHourRecordCountMapper::getTotal));
|
||||
UserCourseHourRecordCourseCountMapper::getCourseId,
|
||||
UserCourseHourRecordCourseCountMapper::getTotal));
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("open_courses", openCourses);
|
||||
|
@ -30,7 +30,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.mapper.UserCourseHourRecordCourseCountMapper;
|
||||
import xyz.playedu.api.types.response.UserLatestLearn;
|
||||
import xyz.playedu.api.util.PrivacyUtil;
|
||||
|
||||
@ -221,8 +221,8 @@ public class UserController {
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
UserCourseHourRecordCountMapper::getCourseId,
|
||||
UserCourseHourRecordCountMapper::getTotal)));
|
||||
UserCourseHourRecordCourseCountMapper::getCourseId,
|
||||
UserCourseHourRecordCourseCountMapper::getTotal)));
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
@ -20,7 +20,8 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCountMapper;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCourseCountMapper;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordUserCountMapper;
|
||||
import xyz.playedu.api.types.paginate.UserCourseHourRecordPaginateFilter;
|
||||
|
||||
import java.util.List;
|
||||
@ -34,9 +35,12 @@ import java.util.List;
|
||||
public interface UserCourseHourRecordMapper extends BaseMapper<UserCourseHourRecord> {
|
||||
List<UserCourseHourRecord> getUserLatestRecords(Integer userId, Integer size);
|
||||
|
||||
List<UserCourseHourRecordCountMapper> getUserCourseHourCount(
|
||||
List<UserCourseHourRecordCourseCountMapper> getUserCourseHourCount(
|
||||
Integer userId, List<Integer> courseIds, Integer isFinished);
|
||||
|
||||
List<UserCourseHourRecordUserCountMapper> getUserCourseHourUserCount(
|
||||
Integer courseId, List<Integer> userIds, Integer isFinished);
|
||||
|
||||
List<UserCourseHourRecord> paginate(UserCourseHourRecordPaginateFilter filter);
|
||||
|
||||
Long paginateCount(UserCourseHourRecordPaginateFilter filter);
|
||||
|
@ -18,7 +18,8 @@ package xyz.playedu.api.service;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
|
||||
import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCountMapper;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCourseCountMapper;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordUserCountMapper;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserCourseHourRecordPaginateFilter;
|
||||
|
||||
@ -51,9 +52,12 @@ public interface UserCourseHourRecordService extends IService<UserCourseHourReco
|
||||
|
||||
void remove(Integer userId, Integer courseId, Integer hourId);
|
||||
|
||||
List<UserCourseHourRecordCountMapper> getUserCourseHourCount(
|
||||
List<UserCourseHourRecordCourseCountMapper> getUserCourseHourCount(
|
||||
Integer userId, List<Integer> courseIds, Integer isFinished);
|
||||
|
||||
List<UserCourseHourRecordUserCountMapper> getUserCourseHourUserCount(
|
||||
Integer courseId, List<Integer> userIds, Integer isFinished);
|
||||
|
||||
PaginationResult<UserCourseHourRecord> paginate(
|
||||
int page, int size, UserCourseHourRecordPaginateFilter filter);
|
||||
}
|
||||
|
@ -25,7 +25,8 @@ import xyz.playedu.api.domain.UserCourseHourRecord;
|
||||
import xyz.playedu.api.event.UserCourseHourFinishedEvent;
|
||||
import xyz.playedu.api.mapper.UserCourseHourRecordMapper;
|
||||
import xyz.playedu.api.service.UserCourseHourRecordService;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCountMapper;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordCourseCountMapper;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordUserCountMapper;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserCourseHourRecordPaginateFilter;
|
||||
|
||||
@ -127,7 +128,7 @@ public class UserCourseHourRecordServiceImpl
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCourseHourRecordCountMapper> getUserCourseHourCount(
|
||||
public List<UserCourseHourRecordCourseCountMapper> getUserCourseHourCount(
|
||||
Integer userId, List<Integer> courseIds, Integer isFinished) {
|
||||
if (courseIds == null || courseIds.size() == 0) {
|
||||
return new ArrayList<>();
|
||||
@ -135,6 +136,15 @@ public class UserCourseHourRecordServiceImpl
|
||||
return getBaseMapper().getUserCourseHourCount(userId, courseIds, isFinished);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCourseHourRecordUserCountMapper> getUserCourseHourUserCount(
|
||||
Integer courseId, List<Integer> userIds, Integer isFinished) {
|
||||
if (userIds == null || userIds.size() == 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return getBaseMapper().getUserCourseHourUserCount(courseId, userIds, isFinished);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Integer userId, Integer courseId) {
|
||||
remove(query().getWrapper().eq("user_id", userId).eq("course_id", courseId));
|
||||
|
@ -25,7 +25,7 @@ import lombok.Data;
|
||||
* @create 2023/3/29 10:01
|
||||
*/
|
||||
@Data
|
||||
public class UserCourseHourRecordCountMapper {
|
||||
public class UserCourseHourRecordCourseCountMapper {
|
||||
@JsonProperty("course_id")
|
||||
private Integer courseId;
|
||||
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2023 杭州白书科技有限公司
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package xyz.playedu.api.types.mapper;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/5/8 11:22
|
||||
*/
|
||||
@Data
|
||||
public class UserCourseHourRecordUserCountMapper {
|
||||
@JsonProperty("user_id")
|
||||
private Integer userId;
|
||||
|
||||
private Integer total;
|
||||
}
|
@ -38,7 +38,7 @@
|
||||
limit #{size};
|
||||
</select>
|
||||
<select id="getUserCourseHourCount"
|
||||
resultType="xyz.playedu.api.types.mapper.UserCourseHourRecordCountMapper">
|
||||
resultType="xyz.playedu.api.types.mapper.UserCourseHourRecordCourseCountMapper">
|
||||
SELECT `course_id`, count(1) AS `total`
|
||||
FROM `user_course_hour_records`
|
||||
WHERE `user_id` = #{userId}
|
||||
@ -115,4 +115,17 @@
|
||||
</if>
|
||||
</where>
|
||||
</select>
|
||||
<select id="getUserCourseHourUserCount"
|
||||
resultType="xyz.playedu.api.types.mapper.UserCourseHourRecordUserCountMapper">
|
||||
SELECT `user_id`, count(1) AS `total`
|
||||
FROM `user_course_hour_records`
|
||||
WHERE `course_id` = #{courseId}
|
||||
<if test="userIds != null and #{userIds}.size() > 0">
|
||||
AND `user_id` IN (<foreach collection="userIds" item="userId" separator=",">#{userId}</foreach>)
|
||||
</if>
|
||||
<if test="isFinished != null">
|
||||
AND `is_finisehd` = #{isFinished}
|
||||
</if>
|
||||
GROUP BY `user_id`;
|
||||
</select>
|
||||
</mapper>
|
||||
|
Loading…
x
Reference in New Issue
Block a user