部门和分类增加排序和父类修改的api

This commit is contained in:
none
2023-03-14 11:22:36 +08:00
parent 0ebb278f42
commit 75f83415ad
10 changed files with 180 additions and 3 deletions

View File

@@ -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);
}

View File

@@ -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;
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}