mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-22 18:29:51 +08:00
部门和分类增加排序和父类修改的api
This commit is contained in:
@@ -37,4 +37,7 @@ public interface DepartmentService extends IService<Department> {
|
||||
|
||||
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);
|
||||
|
||||
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) {
|
||||
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
|
||||
*/
|
||||
@Service
|
||||
public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMapper, ResourceCategory>
|
||||
implements ResourceCategoryService {
|
||||
public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMapper, ResourceCategory> implements ResourceCategoryService {
|
||||
|
||||
@Autowired
|
||||
private ResourceCourseCategoryService resourceCourseCategoryService;
|
||||
@@ -175,6 +174,40 @@ public class ResourceCategoryServiceImpl extends ServiceImpl<ResourceCategoryMap
|
||||
public List<Integer> getRidsById(Integer id) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user