1.根据部门ID获取所有父级部门的课程

后管-学员--学习课程列表、学员-部门学习进度及导出
pc-课程首页
2.根据分类ID获取所有子分类的课程
pc-课程首页
This commit is contained in:
wsw
2024-05-30 16:33:59 +08:00
parent eb02def070
commit 5d1a6109c2
7 changed files with 106 additions and 63 deletions

View File

@@ -42,6 +42,7 @@ import xyz.playedu.common.service.UserService;
import xyz.playedu.common.types.JsonResponse;
import xyz.playedu.common.types.paginate.PaginationResult;
import xyz.playedu.common.types.paginate.UserPaginateFilter;
import xyz.playedu.common.util.StringUtil;
import xyz.playedu.course.domain.Course;
import xyz.playedu.course.domain.UserCourseRecord;
import xyz.playedu.course.service.CourseDepartmentService;
@@ -207,6 +208,7 @@ public class DepartmentController {
return JsonResponse.success();
}
@SneakyThrows
@BackendPermission(slug = BPermissionConstant.DEPARTMENT_USER_LEARN)
@GetMapping("/{id}/users")
@Log(title = "部门-学员", businessType = BusinessTypeConstant.GET)
@@ -220,12 +222,19 @@ public class DepartmentController {
String name = MapUtils.getString(params, "name");
String email = MapUtils.getString(params, "email");
String idCard = MapUtils.getString(params, "id_card");
List<Integer> depIds =
new ArrayList<>() {
{
add(id);
}
};
// 查询所有的父级部门ID
List<Integer> allDepIds = new ArrayList<>();
allDepIds.add(id);
Department department = departmentService.findOrFail(id);
String parentChain = department.getParentChain();
if (StringUtil.isNotEmpty(parentChain)) {
List<Integer> parentChainList =
Arrays.stream(parentChain.split(",")).map(Integer::parseInt).toList();
if (StringUtil.isNotEmpty(parentChainList)) {
allDepIds.addAll(parentChainList);
}
}
String courseIdsStr = MapUtils.getString(params, "course_ids");
String showMode = MapUtils.getString(params, "show_mode");
@@ -236,7 +245,7 @@ public class DepartmentController {
setName(name);
setEmail(email);
setIdCard(idCard);
setDepIds(depIds);
setDepIds(allDepIds);
setSortAlgo(sortAlgo);
setSortField(sortField);
}
@@ -256,24 +265,11 @@ public class DepartmentController {
courses = courseService.getOpenCoursesAndShow(10000);
} else if ("only_dep".equals(showMode)) {
// 部门关联线上课
courses =
courseService.getDepCoursesAndShow(
new ArrayList<>() {
{
add(id);
}
});
courses = courseService.getDepCoursesAndShow(allDepIds);
} else {
// 部门关联线上课
courses =
courseService.getDepCoursesAndShow(
new ArrayList<>() {
{
add(id);
}
});
courses = courseService.getDepCoursesAndShow(allDepIds);
List<Course> openCourses = courseService.getOpenCoursesAndShow(10000);
;
if (openCourses != null) {
courses.addAll(openCourses);
}

View File

@@ -51,6 +51,7 @@ import xyz.playedu.common.types.paginate.UserCourseHourRecordPaginateFilter;
import xyz.playedu.common.types.paginate.UserCourseRecordPaginateFilter;
import xyz.playedu.common.types.paginate.UserPaginateFilter;
import xyz.playedu.common.util.HelperUtil;
import xyz.playedu.common.util.StringUtil;
import xyz.playedu.course.domain.*;
import xyz.playedu.course.service.*;
@@ -478,15 +479,29 @@ public class UserController {
if (depIds != null && !depIds.isEmpty()) {
departments = departmentService.chunk(depIds);
Map<Integer, Department> departmentMap = new HashMap<>();
if (StringUtil.isNotEmpty(departments)) {
departmentMap =
departments.stream().collect(Collectors.toMap(Department::getId, e -> e));
}
Map<Integer, Department> finalDepartmentMap = departmentMap;
depIds.forEach(
(depId) -> {
List<Course> tmpCourses =
courseService.getDepCoursesAndShow(
new ArrayList<>() {
{
add(depId);
}
});
// 查询所有的父级部门ID
List<Integer> allDepIds = new ArrayList<>();
allDepIds.add(depId);
Department department = finalDepartmentMap.get(depId);
String parentChain = department.getParentChain();
if (StringUtil.isNotEmpty(parentChain)) {
List<Integer> parentChainList =
Arrays.stream(parentChain.split(","))
.map(Integer::parseInt)
.toList();
if (StringUtil.isNotEmpty(parentChainList)) {
allDepIds.addAll(parentChainList);
}
}
List<Course> tmpCourses = courseService.getDepCoursesAndShow(allDepIds);
depCourses.put(depId, tmpCourses);
if (tmpCourses != null && !tmpCourses.isEmpty()) {

View File

@@ -15,6 +15,7 @@
*/
package xyz.playedu.api.controller.frontend;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.MapUtils;
@@ -26,15 +27,18 @@ import org.springframework.web.multipart.MultipartFile;
import xyz.playedu.api.request.frontend.ChangePasswordRequest;
import xyz.playedu.common.constant.FrontendConstant;
import xyz.playedu.common.context.FCtx;
import xyz.playedu.common.domain.Category;
import xyz.playedu.common.domain.Department;
import xyz.playedu.common.domain.User;
import xyz.playedu.common.domain.UserUploadImageLog;
import xyz.playedu.common.exception.ServiceException;
import xyz.playedu.common.service.CategoryService;
import xyz.playedu.common.service.DepartmentService;
import xyz.playedu.common.service.UserService;
import xyz.playedu.common.types.JsonResponse;
import xyz.playedu.common.types.mapper.UserCourseHourRecordCourseCountMapper;
import xyz.playedu.common.util.PrivacyUtil;
import xyz.playedu.common.util.StringUtil;
import xyz.playedu.course.domain.*;
import xyz.playedu.course.service.*;
import xyz.playedu.resource.service.UploadService;
@@ -63,6 +67,8 @@ public class UserController {
@Autowired private UploadService uploadService;
@Autowired private CategoryService categoryService;
@GetMapping("/detail")
public JsonResponse detail() {
User user = FCtx.getUser();
@@ -100,6 +106,7 @@ public class UserController {
return JsonResponse.success();
}
@SneakyThrows
@GetMapping("/courses")
public JsonResponse courses(@RequestParam HashMap<String, Object> params) {
Integer depId = MapUtils.getInteger(params, "dep_id");
@@ -120,19 +127,38 @@ public class UserController {
HashMap<String, Object> data = new HashMap<>();
data.put("learn_course_records", new HashMap<>());
// 查询所有的父级部门ID
List<Integer> allDepIds = new ArrayList<>();
allDepIds.add(depId);
Department department = departmentService.findOrFail(depId);
String parentChain = department.getParentChain();
if (StringUtil.isNotEmpty(parentChain)) {
List<Integer> parentChainList =
Arrays.stream(parentChain.split(",")).map(Integer::parseInt).toList();
if (StringUtil.isNotEmpty(parentChainList)) {
allDepIds.addAll(parentChainList);
}
}
// 获取所有子分类ID
List<Integer> allCategoryIds = new ArrayList<>();
if (categoryId != null && categoryId > 0) {
allCategoryIds.add(categoryId);
// 查询所有的子分类
List<Category> categoryList = categoryService.getChildCategorysByParentId(categoryId);
if (StringUtil.isNotEmpty(categoryList)) {
for (Category category : categoryList) {
allCategoryIds.add(category.getId());
}
}
}
// -------- 读取当前学员可以参加的课程 ----------
List<Course> courses = new ArrayList<>();
// 读取部门课
List<Course> depCourses =
courseService.getDepCoursesAndShow(
new ArrayList<>() {
{
add(depId);
}
},
categoryId);
List<Course> depCourses = courseService.getDepCoursesAndShow(allDepIds, allCategoryIds);
// 全部部门课
List<Course> openCourses = courseService.getOpenCoursesAndShow(500, categoryId);
List<Course> openCourses = courseService.getOpenCoursesAndShow(500, allCategoryIds);
// 汇总到一个list中
if (depCourses != null && !depCourses.isEmpty()) {
courses.addAll(depCourses);