mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-23 04:22:43 +08:00
commit
1479727e59
@ -4,10 +4,10 @@
|
||||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
|
||||
<mirrors>
|
||||
<mirror>
|
||||
<id>ali</id>
|
||||
<name>ali Maven</name>
|
||||
<id>Ali</id>
|
||||
<name>Ali Maven</name>
|
||||
<mirrorOf>*</mirrorOf>
|
||||
<url>http://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
<url>https://maven.aliyun.com/nexus/content/groups/public/</url>
|
||||
</mirror>
|
||||
</mirrors>
|
||||
</settings>
|
||||
|
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>
|
||||
|
@ -37,11 +37,11 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class ExceptionController {
|
||||
|
||||
@ExceptionHandler(Exception.class)
|
||||
public JsonResponse exceptionHandler(Exception e) {
|
||||
log.error(e.getMessage());
|
||||
return JsonResponse.error("系统错误", 500);
|
||||
}
|
||||
// @ExceptionHandler(Exception.class)
|
||||
// public JsonResponse exceptionHandler(Exception e) {
|
||||
// log.error(e.getMessage());
|
||||
// return JsonResponse.error("系统错误", 500);
|
||||
// }
|
||||
|
||||
@ExceptionHandler(ServiceException.class)
|
||||
public JsonResponse serviceExceptionHandler(ServiceException e) {
|
||||
|
@ -15,6 +15,9 @@
|
||||
*/
|
||||
package xyz.playedu.api.controller.backend;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import org.apache.commons.collections4.MapUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@ -22,19 +25,21 @@ import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import xyz.playedu.api.constant.BPermissionConstant;
|
||||
import xyz.playedu.api.domain.User;
|
||||
import xyz.playedu.api.domain.UserCourseRecord;
|
||||
import xyz.playedu.api.event.UserCourseRecordDestroyEvent;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.CourseUserDestroyRequest;
|
||||
import xyz.playedu.api.service.UserCourseRecordService;
|
||||
import xyz.playedu.api.service.UserService;
|
||||
import xyz.playedu.api.service.*;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
import xyz.playedu.api.types.mapper.UserCourseHourRecordUserFirstCreatedAtMapper;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserCourseRecordPaginateFilter;
|
||||
import xyz.playedu.api.types.paginate.UserPaginateFilter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
@ -42,17 +47,25 @@ import java.util.List;
|
||||
* @create 2023/3/24 16:08
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/backend/v1/course/{courseId}/user")
|
||||
public class CourseUserController {
|
||||
|
||||
@Autowired private CourseService courseService;
|
||||
|
||||
@Autowired private UserCourseRecordService userCourseRecordService;
|
||||
|
||||
@Autowired private UserCourseHourRecordService userCourseHourRecordService;
|
||||
|
||||
@Autowired private UserService userService;
|
||||
|
||||
@Autowired private DepartmentService departmentService;
|
||||
|
||||
@Autowired private ApplicationContext ctx;
|
||||
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.COURSE_USER)
|
||||
@GetMapping("/index")
|
||||
@SneakyThrows
|
||||
public JsonResponse index(
|
||||
@PathVariable(name = "courseId") Integer courseId,
|
||||
@RequestParam HashMap<String, Object> params) {
|
||||
@ -63,25 +76,64 @@ public class CourseUserController {
|
||||
String name = MapUtils.getString(params, "name");
|
||||
String email = MapUtils.getString(params, "email");
|
||||
String idCard = MapUtils.getString(params, "id_card");
|
||||
Integer depId = MapUtils.getInteger(params, "dep_id");
|
||||
|
||||
UserCourseRecordPaginateFilter filter = new UserCourseRecordPaginateFilter();
|
||||
filter.setCourseId(courseId);
|
||||
UserPaginateFilter filter = new UserPaginateFilter();
|
||||
filter.setName(name);
|
||||
filter.setEmail(email);
|
||||
filter.setIdCard(idCard);
|
||||
filter.setSortAlgo(sortAlgo);
|
||||
filter.setSortField(sortField);
|
||||
filter.setIdCard(idCard);
|
||||
|
||||
PaginationResult<UserCourseRecord> result =
|
||||
userCourseRecordService.paginate(page, size, filter);
|
||||
// 所属部门
|
||||
if (depId != null && depId > 0) { // 设置过滤部门
|
||||
filter.setDepIds(
|
||||
new ArrayList<>() {
|
||||
{
|
||||
add(depId);
|
||||
}
|
||||
});
|
||||
} else { // 默认读取课程关联的全部部门
|
||||
List<Integer> depIds = courseService.getDepIdsByCourseId(courseId);
|
||||
if (depIds != null && depIds.size() > 0) {
|
||||
filter.setDepIds(depIds);
|
||||
}
|
||||
}
|
||||
|
||||
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(
|
||||
"users",
|
||||
userService.chunks(
|
||||
result.getData().stream().map(UserCourseRecord::getUserId).toList()));
|
||||
"user_course_records",
|
||||
userCourseRecordService
|
||||
.chunk(
|
||||
userIds,
|
||||
new ArrayList<>() {
|
||||
{
|
||||
add(courseId);
|
||||
}
|
||||
})
|
||||
.stream()
|
||||
.collect(Collectors.toMap(UserCourseRecord::getUserId, e -> e)));
|
||||
data.put(
|
||||
"user_course_hour_user_first_at",
|
||||
userCourseHourRecordService
|
||||
.getUserCourseHourUserFirstCreatedAt(courseId, userIds)
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
UserCourseHourRecordUserFirstCreatedAtMapper::getUserId,
|
||||
UserCourseHourRecordUserFirstCreatedAtMapper
|
||||
::getCreatedAt)));
|
||||
data.put("course", courseService.findOrFail(courseId));
|
||||
data.put(
|
||||
"user_dep_ids",
|
||||
userService.getDepIdsGroup(result.getData().stream().map(User::getId).toList()));
|
||||
data.put("departments", departmentService.id2name());
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
@ -188,7 +188,12 @@ public class DepartmentController {
|
||||
String name = MapUtils.getString(params, "name");
|
||||
String email = MapUtils.getString(params, "email");
|
||||
String idCard = MapUtils.getString(params, "id_card");
|
||||
String depIds = String.valueOf(id);
|
||||
List<Integer> depIds =
|
||||
new ArrayList<>() {
|
||||
{
|
||||
add(id);
|
||||
}
|
||||
};
|
||||
|
||||
String courseIdsStr = MapUtils.getString(params, "course_ids");
|
||||
String showMode = MapUtils.getString(params, "show_mode");
|
||||
|
@ -43,6 +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.UserCourseHourRecordCourseCountMapper;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserCourseHourRecordPaginateFilter;
|
||||
import xyz.playedu.api.types.paginate.UserCourseRecordPaginateFilter;
|
||||
@ -98,8 +99,17 @@ public class UserController {
|
||||
Integer isVerify = MapUtils.getInteger(params, "is_verify");
|
||||
Integer isSetPassword = MapUtils.getInteger(params, "is_set_password");
|
||||
String createdAt = MapUtils.getString(params, "created_at");
|
||||
String depIds = MapUtils.getString(params, "dep_ids");
|
||||
String depIdsStr = MapUtils.getString(params, "dep_ids");
|
||||
List<Integer> depIds = null;
|
||||
if (depIdsStr != null && depIdsStr.trim().length() > 0) {
|
||||
if ("0".equals(depIdsStr)) {
|
||||
depIds = new ArrayList<>();
|
||||
} else {
|
||||
depIds = Arrays.stream(depIdsStr.split(",")).map(Integer::valueOf).toList();
|
||||
}
|
||||
}
|
||||
|
||||
List<Integer> finalDepIds = depIds;
|
||||
UserPaginateFilter filter =
|
||||
new UserPaginateFilter() {
|
||||
{
|
||||
@ -110,7 +120,7 @@ public class UserController {
|
||||
setIsLock(isLock);
|
||||
setIsVerify(isVerify);
|
||||
setIsSetPassword(isSetPassword);
|
||||
setDepIds(depIds);
|
||||
setDepIds(finalDepIds);
|
||||
setSortAlgo(sortAlgo);
|
||||
setSortField(sortField);
|
||||
}
|
||||
@ -482,6 +492,14 @@ public class UserController {
|
||||
userCourseRecords = userCourseRecordService.chunk(id, courseIds);
|
||||
}
|
||||
|
||||
// 获取学员线上课的课时学习数量(只要学习了就算,不一定需要已完成)
|
||||
Map<Integer, Integer> userCourseHourCount =
|
||||
userCourseHourRecordService.getUserCourseHourCount(id, courseIds, null).stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
UserCourseHourRecordCourseCountMapper::getCourseId,
|
||||
UserCourseHourRecordCourseCountMapper::getTotal));
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("open_courses", openCourses);
|
||||
data.put("departments", departments);
|
||||
@ -490,6 +508,7 @@ public class UserController {
|
||||
"user_course_records",
|
||||
userCourseRecords.stream()
|
||||
.collect(Collectors.toMap(UserCourseRecord::getCourseId, e -> e)));
|
||||
data.put("user_course_hour_count", userCourseHourCount);
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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.controller.frontend;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import xyz.playedu.api.domain.ResourceCategory;
|
||||
import xyz.playedu.api.service.ResourceCategoryService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/v1/category")
|
||||
public class CategoryController {
|
||||
|
||||
@Autowired private ResourceCategoryService resourceCategoryService;
|
||||
|
||||
@GetMapping("/all")
|
||||
public JsonResponse all() {
|
||||
List<ResourceCategory> categories = resourceCategoryService.all();
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put(
|
||||
"categories",
|
||||
categories.stream().collect(Collectors.groupingBy(ResourceCategory::getParentId)));
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
}
|
@ -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;
|
||||
|
||||
@ -106,6 +106,8 @@ public class UserController {
|
||||
return JsonResponse.error("请选择部门");
|
||||
}
|
||||
|
||||
Integer categoryId = MapUtils.getInteger(params, "category_id");
|
||||
|
||||
List<Integer> userJoinDepIds = userService.getDepIdsByUserId(FCtx.getId());
|
||||
if (userJoinDepIds == null) {
|
||||
return JsonResponse.error("当前学员未加入任何部门");
|
||||
@ -126,9 +128,10 @@ public class UserController {
|
||||
{
|
||||
add(depId);
|
||||
}
|
||||
});
|
||||
},
|
||||
categoryId);
|
||||
// 全部部门课
|
||||
List<Course> openCourses = courseService.getOpenCoursesAndShow(500);
|
||||
List<Course> openCourses = courseService.getOpenCoursesAndShow(500, categoryId);
|
||||
// 汇总到一个list中
|
||||
if (depCourses != null && depCourses.size() > 0) {
|
||||
courses.addAll(depCourses);
|
||||
@ -218,8 +221,8 @@ public class UserController {
|
||||
.stream()
|
||||
.collect(
|
||||
Collectors.toMap(
|
||||
UserCourseHourRecordCountMapper::getCourseId,
|
||||
UserCourseHourRecordCountMapper::getTotal)));
|
||||
UserCourseHourRecordCourseCountMapper::getCourseId,
|
||||
UserCourseHourRecordCourseCountMapper::getTotal)));
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
@ -36,5 +36,5 @@ public interface CourseMapper extends BaseMapper<Course> {
|
||||
|
||||
Long paginateCount(CoursePaginateFiler filer);
|
||||
|
||||
List<Course> openCoursesAndShow(Integer limit);
|
||||
List<Course> openCoursesAndShow(Integer limit, Integer categoryId);
|
||||
}
|
||||
|
@ -20,7 +20,9 @@ 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.mapper.UserCourseHourRecordUserFirstCreatedAtMapper;
|
||||
import xyz.playedu.api.types.paginate.UserCourseHourRecordPaginateFilter;
|
||||
|
||||
import java.util.List;
|
||||
@ -34,9 +36,15 @@ 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<UserCourseHourRecordUserFirstCreatedAtMapper> getUserCourseHourUserFirstCreatedAt(
|
||||
Integer courseId, List<Integer> userIds);
|
||||
|
||||
List<UserCourseHourRecord> paginate(UserCourseHourRecordPaginateFilter filter);
|
||||
|
||||
Long paginateCount(UserCourseHourRecordPaginateFilter filter);
|
||||
|
@ -77,8 +77,12 @@ public interface CourseService extends IService<Course> {
|
||||
|
||||
List<Course> getOpenCoursesAndShow(Integer limit);
|
||||
|
||||
List<Course> getOpenCoursesAndShow(Integer limit, Integer categoryId);
|
||||
|
||||
List<Course> getDepCoursesAndShow(List<Integer> depIds);
|
||||
|
||||
List<Course> getDepCoursesAndShow(List<Integer> depIds, Integer categoryId);
|
||||
|
||||
Map<Integer, List<Integer>> getCategoryIdsGroup(List<Integer> courseIds);
|
||||
|
||||
Map<Integer, List<Integer>> getDepIdsGroup(List<Integer> courseIds);
|
||||
|
@ -18,7 +18,9 @@ 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.mapper.UserCourseHourRecordUserFirstCreatedAtMapper;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserCourseHourRecordPaginateFilter;
|
||||
|
||||
@ -51,9 +53,15 @@ 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);
|
||||
|
||||
List<UserCourseHourRecordUserFirstCreatedAtMapper> getUserCourseHourUserFirstCreatedAt(
|
||||
Integer courseId, List<Integer> userIds);
|
||||
|
||||
PaginationResult<UserCourseHourRecord> paginate(
|
||||
int page, int size, UserCourseHourRecordPaginateFilter filter);
|
||||
}
|
||||
|
@ -209,7 +209,40 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
||||
|
||||
@Override
|
||||
public List<Course> getOpenCoursesAndShow(Integer limit) {
|
||||
return getBaseMapper().openCoursesAndShow(limit);
|
||||
return getBaseMapper().openCoursesAndShow(limit, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Course> getOpenCoursesAndShow(Integer limit, Integer categoryId) {
|
||||
return getBaseMapper().openCoursesAndShow(limit, categoryId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Course> getDepCoursesAndShow(List<Integer> depIds, Integer categoryId) {
|
||||
if (depIds == null || depIds.size() == 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
List<Integer> courseIds = courseDepartmentService.getCourseIdsByDepIds(depIds);
|
||||
if (courseIds == null || courseIds.size() == 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
if (categoryId != null && categoryId > 0) {
|
||||
List<Integer> tmpCourseIds =
|
||||
courseCategoryService.getCourseIdsByCategoryIds(
|
||||
new ArrayList<>() {
|
||||
{
|
||||
add(categoryId);
|
||||
}
|
||||
});
|
||||
if (tmpCourseIds == null || tmpCourseIds.size() == 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
courseIds = courseIds.stream().filter(tmpCourseIds::contains).toList();
|
||||
if (courseIds.size() == 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
return list(query().getWrapper().in("id", courseIds).eq("is_show", 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,7 +25,9 @@ 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.mapper.UserCourseHourRecordUserFirstCreatedAtMapper;
|
||||
import xyz.playedu.api.types.paginate.PaginationResult;
|
||||
import xyz.playedu.api.types.paginate.UserCourseHourRecordPaginateFilter;
|
||||
|
||||
@ -127,7 +129,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 +137,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));
|
||||
@ -162,4 +173,13 @@ public class UserCourseHourRecordServiceImpl
|
||||
.eq("course_id", courseId)
|
||||
.eq("hour_id", hourId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<UserCourseHourRecordUserFirstCreatedAtMapper> getUserCourseHourUserFirstCreatedAt(
|
||||
Integer courseId, List<Integer> userIds) {
|
||||
if (userIds == null || userIds.size() == 0) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
return getBaseMapper().getUserCourseHourUserFirstCreatedAt(courseId, userIds);
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
* @create 2023/5/8 14:42
|
||||
*/
|
||||
@Data
|
||||
public class UserCourseHourRecordUserFirstCreatedAtMapper {
|
||||
@JsonProperty("user_id")
|
||||
private Integer userId;
|
||||
|
||||
@JsonProperty("created_at")
|
||||
private Date createdAt;
|
||||
}
|
@ -17,6 +17,8 @@ package xyz.playedu.api.types.paginate;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
*
|
||||
@ -36,7 +38,7 @@ public class UserPaginateFilter {
|
||||
// 创建时间范围过滤
|
||||
private String[] createdAt;
|
||||
|
||||
private String depIds;
|
||||
private List<Integer> depIds;
|
||||
|
||||
// 排序控制
|
||||
private String sortField;
|
||||
|
@ -172,8 +172,14 @@
|
||||
SELECT `courses`.*
|
||||
FROM `courses`
|
||||
LEFT JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
|
||||
<if test="categoryId != null and categoryId > 0">
|
||||
INNER JOIN `resource_course_category` ON `resource_course_category`.`course_id` = `courses`.`id`
|
||||
</if>
|
||||
WHERE `course_department`.`course_id` IS NULL
|
||||
AND `courses`.`is_show` = 1
|
||||
<if test="categoryId != null and categoryId > 0">
|
||||
AND `resource_course_category`.`category_id` = #{categoryId}
|
||||
</if>
|
||||
LIMIT #{limit}
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -38,11 +38,11 @@
|
||||
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}
|
||||
<if test="courseIds != null and #{courseIds}.size() > 0">
|
||||
<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">
|
||||
@ -115,4 +115,35 @@
|
||||
</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>
|
||||
<select id="getUserCourseHourUserFirstCreatedAt"
|
||||
resultType="xyz.playedu.api.types.mapper.UserCourseHourRecordUserFirstCreatedAtMapper">
|
||||
SELECT `t1`.`created_at`, `t1`.`user_id`
|
||||
FROM `user_course_hour_records` AS `t1`
|
||||
INNER JOIN (SELECT `t2`.`user_id`, min(`t2`.`created_at`) as `created_at`
|
||||
FROM `user_course_hour_records` AS `t2`
|
||||
WHERE `t2`.`course_id` = #{courseId}
|
||||
<if test="userIds != null and userIds.size > 0">
|
||||
AND `t2`.`user_id` IN (<foreach collection="userIds" item="userId" separator=",">#{userId}</foreach>)
|
||||
</if>
|
||||
GROUP BY `t2`.`user_id`) AS `t3`
|
||||
ON `t3`.`user_id` = `t1`.`user_id`
|
||||
AND `t3`.`created_at` = `t1`.`created_at`
|
||||
WHERE `t1`.`course_id` = #{courseId}
|
||||
<if test="userIds != null and userIds.size > 0">
|
||||
AND `t1`.`user_id` IN (<foreach collection="userIds" item="userId" separator=",">#{userId}</foreach>)
|
||||
</if>
|
||||
</select>
|
||||
</mapper>
|
||||
|
@ -36,24 +36,23 @@
|
||||
<select id="paginateCount" resultType="java.lang.Long">
|
||||
SELECT count(1)
|
||||
FROM `users`
|
||||
<if test="depIds != null and depIds != ''">
|
||||
<choose>
|
||||
<when test="depIds.indexOf('0') == 0">
|
||||
LEFT JOIN `user_department` ON `user_department`.`user_id` = `users`.`id`
|
||||
</when>
|
||||
<otherwise>
|
||||
INNER JOIN `user_department` ON `user_department`.`user_id` = `users`.`id`
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<where>
|
||||
<if test="depIds != null and depIds != ''">
|
||||
<if test="depIds != null">
|
||||
<choose>
|
||||
<when test="depIds.indexOf('0') == 0">
|
||||
AND `user_department`.`user_id` IS NULL
|
||||
<when test="depIds.size == 0">
|
||||
AND `users`.`id` IN (
|
||||
SELECT `users`.`id` from `users` LEFT JOIN `user_department` ON `user_department`.`user_id` =
|
||||
`users`.`id`
|
||||
WHERE `user_department`.`user_id` IS NULL
|
||||
)
|
||||
</when>
|
||||
<otherwise>
|
||||
AND `user_department`.`dep_id` IN (#{depIds})
|
||||
AND `users`.`id` IN (
|
||||
SELECT `users`.`id` from `users` LEFT JOIN `user_department` ON `user_department`.`user_id` =
|
||||
`users`.`id`
|
||||
WHERE `user_department`.`dep_id` IN (<foreach collection="depIds" item="depId" separator=",">
|
||||
#{depId}</foreach>)
|
||||
)
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
@ -78,7 +77,7 @@
|
||||
<if test="isSetPassword != null">
|
||||
AND `users`.`is_set_password` = #{isSetPassword}
|
||||
</if>
|
||||
<if test="createdAt != null">
|
||||
<if test="createdAt != null and createdAt.size == 2">
|
||||
AND `users`.`created_at` BETWEEN
|
||||
<foreach collection="createdAt" item="createdAtItem" separator=" AND ">#{createdAtItem}</foreach>
|
||||
</if>
|
||||
@ -88,24 +87,23 @@
|
||||
<select id="paginate" resultType="xyz.playedu.api.domain.User">
|
||||
SELECT `users`.*
|
||||
FROM `users`
|
||||
<if test="depIds != null and depIds != ''">
|
||||
<choose>
|
||||
<when test="depIds.indexOf('0') == 0">
|
||||
LEFT JOIN `user_department` ON `user_department`.`user_id` = `users`.`id`
|
||||
</when>
|
||||
<otherwise>
|
||||
INNER JOIN `user_department` ON `user_department`.`user_id` = `users`.`id`
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
<where>
|
||||
<if test="depIds != null and depIds != ''">
|
||||
<if test="depIds != null">
|
||||
<choose>
|
||||
<when test="depIds.indexOf('0') == 0">
|
||||
AND `user_department`.`user_id` IS NULL
|
||||
<when test="depIds.size == 0">
|
||||
AND `users`.`id` IN (
|
||||
SELECT `users`.`id` from `users` LEFT JOIN `user_department` ON `user_department`.`user_id` =
|
||||
`users`.`id`
|
||||
WHERE `user_department`.`user_id` IS NULL
|
||||
)
|
||||
</when>
|
||||
<otherwise>
|
||||
AND `user_department`.`dep_id` IN (#{depIds})
|
||||
AND `users`.`id` IN (
|
||||
SELECT `users`.`id` from `users` LEFT JOIN `user_department` ON `user_department`.`user_id` =
|
||||
`users`.`id`
|
||||
WHERE `user_department`.`dep_id` IN (<foreach collection="depIds" item="depId" separator=",">
|
||||
#{depId}</foreach>)
|
||||
)
|
||||
</otherwise>
|
||||
</choose>
|
||||
</if>
|
||||
@ -130,7 +128,7 @@
|
||||
<if test="isSetPassword != null">
|
||||
AND `users`.`is_set_password` = #{isSetPassword}
|
||||
</if>
|
||||
<if test="createdAt != null">
|
||||
<if test="createdAt != null and createdAt.size == 2">
|
||||
AND `users`.`created_at` BETWEEN
|
||||
<foreach collection="createdAt" item="createdAtItem" separator=" AND ">#{createdAtItem}</foreach>
|
||||
</if>
|
||||
|
Loading…
x
Reference in New Issue
Block a user