后管-线上课、资源:选择分类、部门递归查询该子类、子部门数据

This commit is contained in:
wsw
2024-05-30 14:44:03 +08:00
parent 8beae72101
commit eb02def070
11 changed files with 165 additions and 69 deletions

View File

@@ -34,11 +34,14 @@ import xyz.playedu.common.constant.BPermissionConstant;
import xyz.playedu.common.constant.BusinessTypeConstant;
import xyz.playedu.common.context.BCtx;
import xyz.playedu.common.domain.AdminUser;
import xyz.playedu.common.domain.Category;
import xyz.playedu.common.domain.Department;
import xyz.playedu.common.exception.NotFoundException;
import xyz.playedu.common.service.*;
import xyz.playedu.common.types.JsonResponse;
import xyz.playedu.common.types.paginate.CoursePaginateFiler;
import xyz.playedu.common.types.paginate.PaginationResult;
import xyz.playedu.common.util.StringUtil;
import xyz.playedu.course.domain.Course;
import xyz.playedu.course.domain.CourseAttachment;
import xyz.playedu.course.domain.CourseChapter;
@@ -94,12 +97,66 @@ public class CourseController {
String categoryIds = MapUtils.getString(params, "category_ids");
Integer isRequired = MapUtils.getInteger(params, "is_required");
// 获取所有子部门
Set<Integer> alldepIdsSet = new HashSet<>();
if (StringUtil.isNotEmpty(depIds)) {
String[] depIdArr = depIds.split(",");
if (StringUtil.isNotEmpty(depIdArr)) {
for (String depIdStr : depIdArr) {
Integer depId = Integer.parseInt(depIdStr);
alldepIdsSet.add(depId);
// 查询所有的子部门
List<Department> departmentList =
departmentService.getChildDepartmentsByParentId(depId);
if (StringUtil.isNotEmpty(departmentList)) {
for (Department department : departmentList) {
alldepIdsSet.add(department.getId());
}
}
}
}
}
List<Integer> alldepIds = new ArrayList<>();
if ("0".equals(depIds)) {
alldepIds.add(0);
}
if (StringUtil.isNotEmpty(alldepIdsSet)) {
alldepIds.addAll(alldepIdsSet);
}
// 获取所有子类
Set<Integer> allCategoryIdsSet = new HashSet<>();
if (StringUtil.isNotEmpty(categoryIds)) {
String[] categoryIdArr = categoryIds.split(",");
if (StringUtil.isNotEmpty(categoryIdArr)) {
for (String categoryIdStr : categoryIdArr) {
Integer categoryId = Integer.parseInt(categoryIdStr);
allCategoryIdsSet.add(categoryId);
// 查询所有的子分类
List<Category> categoryList =
categoryService.getChildCategorysByParentId(categoryId);
if (StringUtil.isNotEmpty(categoryList)) {
for (Category category : categoryList) {
allCategoryIdsSet.add(category.getId());
}
}
}
}
}
List<Integer> allCategoryIds = new ArrayList<>();
if ("0".equals(categoryIds)) {
allCategoryIds.add(0);
}
if (StringUtil.isNotEmpty(allCategoryIdsSet)) {
allCategoryIds.addAll(allCategoryIdsSet);
}
CoursePaginateFiler filter = new CoursePaginateFiler();
filter.setTitle(title);
filter.setSortField(sortField);
filter.setSortAlgo(sortAlgo);
filter.setCategoryIds(categoryIds);
filter.setDepIds(depIds);
filter.setCategoryIds(allCategoryIds);
filter.setDepIds(alldepIds);
filter.setIsRequired(isRequired);
if (!backendBus.isSuperAdmin()) {

View File

@@ -31,14 +31,17 @@ import xyz.playedu.common.constant.BackendConstant;
import xyz.playedu.common.constant.BusinessTypeConstant;
import xyz.playedu.common.context.BCtx;
import xyz.playedu.common.domain.AdminUser;
import xyz.playedu.common.domain.Category;
import xyz.playedu.common.exception.NotFoundException;
import xyz.playedu.common.exception.ServiceException;
import xyz.playedu.common.service.AdminUserService;
import xyz.playedu.common.service.AppConfigService;
import xyz.playedu.common.service.CategoryService;
import xyz.playedu.common.types.JsonResponse;
import xyz.playedu.common.types.paginate.PaginationResult;
import xyz.playedu.common.types.paginate.ResourcePaginateFilter;
import xyz.playedu.common.util.S3Util;
import xyz.playedu.common.util.StringUtil;
import xyz.playedu.resource.domain.Resource;
import xyz.playedu.resource.domain.ResourceVideo;
import xyz.playedu.resource.service.ResourceService;
@@ -61,6 +64,8 @@ public class ResourceController {
@Autowired private BackendBus backendBus;
@Autowired private CategoryService categoryService;
@GetMapping("/index")
@Log(title = "资源-列表", businessType = BusinessTypeConstant.GET)
public JsonResponse index(@RequestParam HashMap<String, Object> params) {
@@ -76,11 +81,39 @@ public class ResourceController {
return JsonResponse.error("请选择资源类型");
}
// 获取所有子类
Set<Integer> allCategoryIdsSet = new HashSet<>();
if (StringUtil.isNotEmpty(categoryIds)) {
String[] categoryIdArr = categoryIds.split(",");
if (StringUtil.isNotEmpty(categoryIdArr)) {
for (String categoryIdStr : categoryIdArr) {
Integer categoryId = Integer.parseInt(categoryIdStr);
allCategoryIdsSet.add(categoryId);
// 查询所有的子分类
List<Category> categoryList =
categoryService.getChildCategorysByParentId(categoryId);
if (StringUtil.isNotEmpty(categoryList)) {
for (Category category : categoryList) {
allCategoryIdsSet.add(category.getId());
}
}
}
}
}
List<Integer> allCategoryIds = new ArrayList<>();
if ("0".equals(categoryIds)) {
allCategoryIds.add(0);
}
if (StringUtil.isNotEmpty(allCategoryIdsSet)) {
allCategoryIds.addAll(allCategoryIdsSet);
}
ResourcePaginateFilter filter = new ResourcePaginateFilter();
filter.setSortAlgo(sortAlgo);
filter.setSortField(sortField);
filter.setType(type);
filter.setCategoryIds(categoryIds);
filter.setCategoryIds(allCategoryIds);
filter.setName(name);
if (!backendBus.isSuperAdmin()) { // 非超管只能读取它自己上传的资源

View File

@@ -15,20 +15,13 @@
*/
package xyz.playedu.api.controller.frontend;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import xyz.playedu.common.domain.Department;
import xyz.playedu.common.exception.NotFoundException;
import xyz.playedu.common.service.DepartmentService;
import xyz.playedu.common.types.JsonResponse;
import xyz.playedu.common.types.paginate.CoursePaginateFiler;
import xyz.playedu.common.types.paginate.PaginationResult;
import xyz.playedu.course.domain.Course;
import xyz.playedu.course.service.CourseService;
import java.util.HashMap;
import java.util.stream.Collectors;
/**
@@ -42,38 +35,10 @@ public class DepartmentController {
@Autowired private DepartmentService departmentService;
@Autowired private CourseService courseService;
@GetMapping("/index")
public JsonResponse index() {
return JsonResponse.data(
departmentService.all().stream()
.collect(Collectors.groupingBy(Department::getParentId)));
}
@GetMapping("/{id}/courses")
public JsonResponse courses(
@PathVariable(name = "id") Integer id, @RequestParam HashMap<String, Object> params)
throws NotFoundException {
Integer page = MapUtils.getInteger(params, "page", 1);
Integer size = MapUtils.getInteger(params, "size", 10);
CoursePaginateFiler filer = new CoursePaginateFiler();
filer.setIsShow(1);
if (id == 0) {
filer.setDepIds("0"); // 无部门所属的线上课
} else {
Department department = departmentService.findOrFail(id);
filer.setDepIds(department.getId() + "");
}
PaginationResult<Course> result = courseService.paginate(page, size, filer);
HashMap<String, Object> data = new HashMap<>();
data.put("data", result.getData());
data.put("total", result.getTotal());
return JsonResponse.data(data);
}
}