mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-13 01:35:03 +08:00
部门和分类增加排序和父类修改的api
This commit is contained in:
parent
0ebb278f42
commit
75f83415ad
@ -12,7 +12,7 @@ import xyz.playedu.api.domain.User;
|
|||||||
import xyz.playedu.api.event.DepartmentDestroyEvent;
|
import xyz.playedu.api.event.DepartmentDestroyEvent;
|
||||||
import xyz.playedu.api.exception.NotFoundException;
|
import xyz.playedu.api.exception.NotFoundException;
|
||||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||||
import xyz.playedu.api.request.backend.DepartmentRequest;
|
import xyz.playedu.api.request.backend.*;
|
||||||
import xyz.playedu.api.service.CourseService;
|
import xyz.playedu.api.service.CourseService;
|
||||||
import xyz.playedu.api.service.DepartmentService;
|
import xyz.playedu.api.service.DepartmentService;
|
||||||
import xyz.playedu.api.service.UserService;
|
import xyz.playedu.api.service.UserService;
|
||||||
@ -128,4 +128,16 @@ public class DepartmentController {
|
|||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update/resort")
|
||||||
|
public JsonResponse resort(@RequestBody @Validated DepartmentSortRequest req) {
|
||||||
|
departmentService.resetSort(req.getIds());
|
||||||
|
return JsonResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update/parent")
|
||||||
|
public JsonResponse updateParent(@RequestBody @Validated DepartmentParentRequest req) throws NotFoundException {
|
||||||
|
departmentService.changeParent(req.getId(), req.getParentId(), req.getIds());
|
||||||
|
return JsonResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,9 @@ import xyz.playedu.api.domain.ResourceCategory;
|
|||||||
import xyz.playedu.api.event.ResourceCategoryDestroyEvent;
|
import xyz.playedu.api.event.ResourceCategoryDestroyEvent;
|
||||||
import xyz.playedu.api.exception.NotFoundException;
|
import xyz.playedu.api.exception.NotFoundException;
|
||||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||||
|
import xyz.playedu.api.request.backend.ResourceCategoryParentRequest;
|
||||||
import xyz.playedu.api.request.backend.ResourceCategoryRequest;
|
import xyz.playedu.api.request.backend.ResourceCategoryRequest;
|
||||||
|
import xyz.playedu.api.request.backend.ResourceCategorySortRequest;
|
||||||
import xyz.playedu.api.service.CourseService;
|
import xyz.playedu.api.service.CourseService;
|
||||||
import xyz.playedu.api.service.ResourceCategoryService;
|
import xyz.playedu.api.service.ResourceCategoryService;
|
||||||
import xyz.playedu.api.service.ResourceService;
|
import xyz.playedu.api.service.ResourceService;
|
||||||
@ -131,4 +133,16 @@ public class ResourceCategoryController {
|
|||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update/resort")
|
||||||
|
public JsonResponse resort(@RequestBody @Validated ResourceCategorySortRequest req) {
|
||||||
|
categoryService.resetSort(req.getIds());
|
||||||
|
return JsonResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/update/parent")
|
||||||
|
public JsonResponse updateParent(@RequestBody @Validated ResourceCategoryParentRequest req) throws NotFoundException {
|
||||||
|
categoryService.changeParent(req.getId(), req.getParentId(), req.getIds());
|
||||||
|
return JsonResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package xyz.playedu.api.request.backend;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/3/14 11:13
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DepartmentParentRequest {
|
||||||
|
@NotNull(message = "参数为空")
|
||||||
|
private List<Integer> ids;
|
||||||
|
|
||||||
|
@NotNull(message = "参数为空")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotNull(message = "参数为空")
|
||||||
|
private Integer parentId;
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
package xyz.playedu.api.request.backend;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/3/14 11:11
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class DepartmentSortRequest {
|
||||||
|
private List<Integer> ids;
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package xyz.playedu.api.request.backend;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/3/14 11:07
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ResourceCategoryParentRequest {
|
||||||
|
@NotNull(message = "参数为空")
|
||||||
|
private List<Integer> ids;
|
||||||
|
|
||||||
|
@NotNull(message = "参数为空")
|
||||||
|
private Integer id;
|
||||||
|
|
||||||
|
@NotNull(message = "参数为空")
|
||||||
|
private Integer parentId;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package xyz.playedu.api.request.backend;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/3/14 11:02
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class ResourceCategorySortRequest {
|
||||||
|
|
||||||
|
@NotNull(message = "参数为空")
|
||||||
|
private List<Integer> ids;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -37,4 +37,7 @@ public interface DepartmentService extends IService<Department> {
|
|||||||
|
|
||||||
List<Integer> getCourseIdsByDepId(Integer depId);
|
List<Integer> getCourseIdsByDepId(Integer depId);
|
||||||
|
|
||||||
|
void changeParent(Integer id, Integer parentId, List<Integer> ids) throws NotFoundException;
|
||||||
|
|
||||||
|
void resetSort(List<Integer> ids);
|
||||||
}
|
}
|
||||||
|
@ -33,4 +33,8 @@ public interface ResourceCategoryService extends IService<ResourceCategory> {
|
|||||||
|
|
||||||
List<Integer> getRidsById(Integer id);
|
List<Integer> getRidsById(Integer id);
|
||||||
|
|
||||||
|
void resetSort(List<Integer> ids);
|
||||||
|
|
||||||
|
void changeParent(Integer id, Integer parentId, List<Integer> ids) throws NotFoundException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -191,6 +191,40 @@ public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Departm
|
|||||||
public List<Integer> getCourseIdsByDepId(Integer depId) {
|
public List<Integer> getCourseIdsByDepId(Integer depId) {
|
||||||
return courseDepartmentService.list(courseDepartmentService.query().getWrapper().eq("dep_id", depId)).stream().map(CourseDepartment::getCourseId).toList();
|
return courseDepartmentService.list(courseDepartmentService.query().getWrapper().eq("dep_id", depId)).stream().map(CourseDepartment::getCourseId).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void changeParent(Integer id, Integer parentId, List<Integer> ids) throws NotFoundException {
|
||||||
|
Department department = new Department();
|
||||||
|
department.setId(id);
|
||||||
|
department.setParentId(parentId);
|
||||||
|
if (parentId.equals(0)) {
|
||||||
|
department.setParentChain("");
|
||||||
|
} else {
|
||||||
|
Department parentDep = findOrFail(parentId);
|
||||||
|
department.setParentChain(childrenParentChain(parentDep));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置排序
|
||||||
|
resetSort(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetSort(List<Integer> ids) {
|
||||||
|
if (ids == null || ids.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<Department> departments = new ArrayList<>();
|
||||||
|
int sortVal = 0;
|
||||||
|
for (Integer idItem : ids) {
|
||||||
|
Integer finalSortVal = ++sortVal;
|
||||||
|
departments.add(new Department() {{
|
||||||
|
setId(idItem);
|
||||||
|
setSort(finalSortVal);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
updateBatchById(departments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,8 +23,7 @@ import java.util.List;
|
|||||||
* @createDate 2023-02-23 09:50:18
|
* @createDate 2023-02-23 09:50:18
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMapper, ResourceCategory>
|
public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMapper, ResourceCategory> implements ResourceCategoryService {
|
||||||
implements ResourceCategoryService {
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private ResourceCourseCategoryService resourceCourseCategoryService;
|
private ResourceCourseCategoryService resourceCourseCategoryService;
|
||||||
@ -175,6 +174,40 @@ public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMap
|
|||||||
public List<Integer> getRidsById(Integer id) {
|
public List<Integer> getRidsById(Integer id) {
|
||||||
return resourceCategoryRelationService.list(resourceCategoryRelationService.query().getWrapper().eq("cid", id)).stream().map(ResourceCategoryRelation::getRid).toList();
|
return resourceCategoryRelationService.list(resourceCategoryRelationService.query().getWrapper().eq("cid", id)).stream().map(ResourceCategoryRelation::getRid).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resetSort(List<Integer> ids) {
|
||||||
|
if (ids == null || ids.size() == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<ResourceCategory> categories = new ArrayList<>();
|
||||||
|
int sortVal = 0;
|
||||||
|
for (Integer idItem : ids) {
|
||||||
|
Integer finalSortVal = ++sortVal;
|
||||||
|
categories.add(new ResourceCategory() {{
|
||||||
|
setId(idItem);
|
||||||
|
setSort(finalSortVal);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
updateBatchById(categories);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Transactional
|
||||||
|
public void changeParent(Integer id, Integer parentId, List<Integer> ids) throws NotFoundException {
|
||||||
|
ResourceCategory category = new ResourceCategory();
|
||||||
|
category.setId(id);
|
||||||
|
category.setParentId(parentId);
|
||||||
|
if (parentId.equals(0)) {
|
||||||
|
category.setParentChain("");
|
||||||
|
} else {
|
||||||
|
ResourceCategory parentResourceCategory = findOrFail(parentId);
|
||||||
|
category.setParentChain(childrenParentChain(parentResourceCategory));
|
||||||
|
}
|
||||||
|
|
||||||
|
// 重置排序
|
||||||
|
resetSort(ids);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user