部门列表返回值优化

This commit is contained in:
none 2023-02-19 17:52:03 +08:00
parent 3df3b9c8a4
commit 1af46e9323
3 changed files with 15 additions and 4 deletions

View File

@ -11,8 +11,8 @@ import xyz.playedu.api.request.backend.DepartmentRequest;
import xyz.playedu.api.service.DepartmentService; import xyz.playedu.api.service.DepartmentService;
import xyz.playedu.api.types.JsonResponse; import xyz.playedu.api.types.JsonResponse;
import java.util.Date; import java.util.*;
import java.util.List; import java.util.stream.Collectors;
/** /**
* @Author 杭州白书科技有限公司 * @Author 杭州白书科技有限公司
@ -31,7 +31,11 @@ public class DepartmentController {
@GetMapping("/index") @GetMapping("/index")
public JsonResponse index() { public JsonResponse index() {
List<Department> data = departmentService.list(); Map<Integer, List<Department>> departments = departmentService.all().stream().collect(Collectors.groupingBy(Department::getParentId));
HashMap<String, Object> data = new HashMap<>();
data.put("departments", departments);
return JsonResponse.data(data); return JsonResponse.data(data);
} }

View File

@ -15,6 +15,8 @@ public interface DepartmentService extends IService<Department> {
List<Department> listByParentId(Integer id); List<Department> listByParentId(Integer id);
List<Department> all();
Department findOrFail(Integer id) throws NotFoundException; Department findOrFail(Integer id) throws NotFoundException;
void deleteById(Integer id) throws NotFoundException; void deleteById(Integer id) throws NotFoundException;

View File

@ -27,7 +27,12 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
@Override @Override
public List<Department> listByParentId(Integer id) { public List<Department> listByParentId(Integer id) {
return list(query().getWrapper().eq("parent_id", id)); return list(query().getWrapper().eq("parent_id", id).orderByAsc("sort"));
}
@Override
public List<Department> all() {
return list(query().getWrapper().orderByAsc("sort"));
} }
@Override @Override