学员全部课程api增加分类过滤

This commit is contained in:
none 2023-05-08 10:41:55 +08:00
parent 4c4046dff5
commit 2bb9e7491b
5 changed files with 51 additions and 7 deletions

View File

@ -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);

View File

@ -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);
}

View File

@ -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);

View File

@ -209,7 +209,41 @@ 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.retainAll(tmpCourseIds);
}
if (courseIds.size() == 0) {
return new ArrayList<>();
}
return list(query().getWrapper().in("id", courseIds).eq("is_show", 1));
}
@Override

View File

@ -171,9 +171,12 @@
<select id="openCoursesAndShow" resultType="xyz.playedu.api.domain.Course">
SELECT `courses`.*
FROM `courses`
LEFT JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
LEFT JOIN `course_department` ON `course_department`.`course_id` = `courses`.`id`
WHERE `course_department`.`course_id` IS NULL
AND `courses`.`is_show` = 1
LIMIT #{limit}
AND `courses`.`is_show` = 1
<if test="categoryId != null and categoryId > 0">
AND `course_department`.`caetgory_id` = #{categoryId}
</if>
LIMIT #{limit}
</select>
</mapper>