优化courseCategory

This commit is contained in:
none
2023-02-25 10:39:17 +08:00
parent 138e1f5b98
commit ba101e508b
4 changed files with 32 additions and 50 deletions

View File

@@ -1,40 +0,0 @@
package xyz.playedu.api.bus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xyz.playedu.api.domain.CourseCategory;
import xyz.playedu.api.exception.NotFoundException;
import xyz.playedu.api.service.CourseCategoryService;
/**
* @Author 杭州白书科技有限公司
* @create 2023/2/24 13:57
*/
@Component
public class CourseCategoryBus {
@Autowired
private CourseCategoryService categoryService;
public String compParentChain(Integer parentId) throws NotFoundException {
String parentChain = "";
if (parentId != 0) {
CourseCategory parentCourseCategory = categoryService.getById(parentId);
if (parentCourseCategory == null) {
throw new NotFoundException("父级分类不存在");
}
String pc = parentCourseCategory.getParentChain();
parentChain = pc == null || pc.length() == 0 ? parentId + "" : pc + "," + parentId;
}
return parentChain;
}
public static String childrenParentChain(CourseCategory CourseCategory) {
String prefix = CourseCategory.getId() + "";
if (CourseCategory.getParentChain() != null && CourseCategory.getParentChain().length() > 0) {
prefix = CourseCategory.getParentChain() + "," + prefix;
}
return prefix;
}
}