mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-22 18:29:51 +08:00
课程分类代码优化
This commit is contained in:
@@ -23,4 +23,6 @@ public interface CourseCategoryService extends IService<CourseCategory> {
|
||||
|
||||
void update(CourseCategory category, String name, Integer parentId, Integer sort) throws NotFoundException;
|
||||
|
||||
void create(String name, Integer parentId, Integer sort) throws NotFoundException;
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
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;
|
||||
@@ -10,6 +11,7 @@ import xyz.playedu.api.mapper.CourseCategoryMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -20,6 +22,9 @@ import java.util.List;
|
||||
@Service
|
||||
public class CourseCategoryServiceImpl extends ServiceImpl<CourseCategoryMapper, CourseCategory> implements CourseCategoryService {
|
||||
|
||||
@Autowired
|
||||
private CourseCategoryBus categoryBus;
|
||||
|
||||
@Override
|
||||
public List<CourseCategory> listByParentId(Integer id) {
|
||||
return list(query().getWrapper().eq("parent_id", id).orderByAsc("sort"));
|
||||
@@ -112,6 +117,24 @@ public class CourseCategoryServiceImpl extends ServiceImpl<CourseCategoryMapper,
|
||||
updateBatchById(updateRows);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void create(String name, Integer parentId, Integer sort) throws NotFoundException {
|
||||
String parentChain = "";
|
||||
if (parentId != 0) {
|
||||
parentChain = categoryBus.compParentChain(parentId);
|
||||
}
|
||||
|
||||
CourseCategory category = new CourseCategory();
|
||||
category.setName(name);
|
||||
category.setParentId(parentId);
|
||||
category.setParentChain(parentChain);
|
||||
category.setSort(sort);
|
||||
category.setCreatedAt(new Date());
|
||||
category.setUpdatedAt(new Date());
|
||||
|
||||
save(category);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user