mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-28 08:17:30 +08:00
优化代码
This commit is contained in:
parent
97061c7678
commit
1867d5fa1a
@ -66,9 +66,8 @@ public class CourseController {
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.COURSE)
|
||||
@GetMapping("/create")
|
||||
public JsonResponse create() {
|
||||
Map<Integer, List<ResourceCategory>> categories = categoryService.all().stream().collect(Collectors.groupingBy(ResourceCategory::getParentId));
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("categories", categories);
|
||||
data.put("categories", categoryService.groupByParent());
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
|
@ -44,11 +44,8 @@ public class DepartmentController {
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index() {
|
||||
Map<Integer, List<Department>> departments = departmentService.all().stream().collect(Collectors.groupingBy(Department::getParentId));
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("departments", departments);
|
||||
|
||||
data.put("departments", departmentService.groupByParent());
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@ -61,11 +58,8 @@ public class DepartmentController {
|
||||
@BackendPermissionMiddleware(slug = BPermissionConstant.DEPARTMENT_CUD)
|
||||
@GetMapping("/create")
|
||||
public JsonResponse create() {
|
||||
Map<Integer, List<Department>> departments = departmentService.all().stream().collect(Collectors.groupingBy(Department::getParentId));
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("departments", departments);
|
||||
|
||||
data.put("departments", departmentService.groupByParent());
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
|
@ -45,11 +45,8 @@ public class ResourceCategoryController {
|
||||
|
||||
@GetMapping("/index")
|
||||
public JsonResponse index() {
|
||||
Map<Integer, List<ResourceCategory>> categories = categoryService.all().stream().collect(Collectors.groupingBy(ResourceCategory::getParentId));
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("categories", categories);
|
||||
|
||||
data.put("categories", categoryService.groupByParent());
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
@ -61,11 +58,8 @@ public class ResourceCategoryController {
|
||||
|
||||
@GetMapping("/create")
|
||||
public JsonResponse create() {
|
||||
Map<Integer, List<ResourceCategory>> categories = categoryService.all().stream().collect(Collectors.groupingBy(ResourceCategory::getParentId));
|
||||
|
||||
HashMap<String, Object> data = new HashMap<>();
|
||||
data.put("categories", categories);
|
||||
|
||||
data.put("categories", categoryService.groupByParent());
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -40,4 +41,6 @@ public interface DepartmentService extends IService<Department> {
|
||||
void changeParent(Integer id, Integer parentId, List<Integer> ids) throws NotFoundException;
|
||||
|
||||
void resetSort(List<Integer> ids);
|
||||
|
||||
Map<Integer, List<Department>> groupByParent();
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -37,4 +38,6 @@ public interface ResourceCategoryService extends IService<ResourceCategory> {
|
||||
|
||||
void changeParent(Integer id, Integer parentId, List<Integer> ids) throws NotFoundException;
|
||||
|
||||
Map<Integer, List<ResourceCategory>> groupByParent();
|
||||
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import xyz.playedu.api.service.internal.UserDepartmentService;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -225,6 +227,11 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
||||
}
|
||||
updateBatchById(departments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, List<Department>> groupByParent() {
|
||||
return list(query().getWrapper().orderByAsc("sort")).stream().collect(Collectors.groupingBy(Department::getParentId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,6 +16,8 @@ import xyz.playedu.api.service.internal.ResourceCourseCategoryService;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -208,6 +210,11 @@ public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMap
|
||||
// 重置排序
|
||||
resetSort(ids);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Integer, List<ResourceCategory>> groupByParent() {
|
||||
return list(query().getWrapper().orderByAsc("sort")).stream().collect(Collectors.groupingBy(ResourceCategory::getParentId));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user