From ba101e508bb281493940a1ccb875faafcd4f910e Mon Sep 17 00:00:00 2001 From: none Date: Sat, 25 Feb 2023 10:39:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96courseCategory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../playedu/api/bus/CourseCategoryBus.java | 40 ------------------- .../backend/CourseCategoryController.java | 1 - .../api/service/CourseCategoryService.java | 4 ++ .../impl/CourseCategoryServiceImpl.java | 37 ++++++++++++----- 4 files changed, 32 insertions(+), 50 deletions(-) delete mode 100644 src/main/java/xyz/playedu/api/bus/CourseCategoryBus.java diff --git a/src/main/java/xyz/playedu/api/bus/CourseCategoryBus.java b/src/main/java/xyz/playedu/api/bus/CourseCategoryBus.java deleted file mode 100644 index 9d0283f..0000000 --- a/src/main/java/xyz/playedu/api/bus/CourseCategoryBus.java +++ /dev/null @@ -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; - } - -} diff --git a/src/main/java/xyz/playedu/api/controller/backend/CourseCategoryController.java b/src/main/java/xyz/playedu/api/controller/backend/CourseCategoryController.java index 8c3cee4..e3efd7b 100644 --- a/src/main/java/xyz/playedu/api/controller/backend/CourseCategoryController.java +++ b/src/main/java/xyz/playedu/api/controller/backend/CourseCategoryController.java @@ -4,7 +4,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; -import xyz.playedu.api.bus.CourseCategoryBus; import xyz.playedu.api.constant.BPermissionConstant; import xyz.playedu.api.domain.CourseCategory; import xyz.playedu.api.event.CourseCategoryDestroyEvent; diff --git a/src/main/java/xyz/playedu/api/service/CourseCategoryService.java b/src/main/java/xyz/playedu/api/service/CourseCategoryService.java index 5b95145..5f6292e 100644 --- a/src/main/java/xyz/playedu/api/service/CourseCategoryService.java +++ b/src/main/java/xyz/playedu/api/service/CourseCategoryService.java @@ -25,4 +25,8 @@ public interface CourseCategoryService extends IService { void create(String name, Integer parentId, Integer sort) throws NotFoundException; + String childrenParentChain(CourseCategory category); + + String compParentChain(Integer parentId) throws NotFoundException; + } diff --git a/src/main/java/xyz/playedu/api/service/impl/CourseCategoryServiceImpl.java b/src/main/java/xyz/playedu/api/service/impl/CourseCategoryServiceImpl.java index 9c9872d..a941354 100644 --- a/src/main/java/xyz/playedu/api/service/impl/CourseCategoryServiceImpl.java +++ b/src/main/java/xyz/playedu/api/service/impl/CourseCategoryServiceImpl.java @@ -3,7 +3,6 @@ package xyz.playedu.api.service.impl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; -import xyz.playedu.api.bus.CourseCategoryBus; import xyz.playedu.api.domain.CourseCategory; import xyz.playedu.api.exception.NotFoundException; import xyz.playedu.api.service.CourseCategoryService; @@ -22,9 +21,6 @@ import java.util.List; @Service public class CourseCategoryServiceImpl extends ServiceImpl implements CourseCategoryService { - @Autowired - private CourseCategoryBus categoryBus; - @Override public List listByParentId(Integer id) { return list(query().getWrapper().eq("parent_id", id).orderByAsc("sort")); @@ -49,7 +45,7 @@ public class CourseCategoryServiceImpl extends ServiceImpl 0) { + prefix = category.getParentChain() + "," + prefix; + } + return prefix; + } + + @Override + public String compParentChain(Integer parentId) throws NotFoundException { + String parentChain = ""; + if (parentId != 0) { + CourseCategory parentCourseCategory = getById(parentId); + if (parentCourseCategory == null) { + throw new NotFoundException("父级分类不存在"); + } + String pc = parentCourseCategory.getParentChain(); + parentChain = pc == null || pc.length() == 0 ? parentId + "" : pc + "," + parentId; + } + return parentChain; + } }