课程分类代码优化

This commit is contained in:
none
2023-02-25 10:35:24 +08:00
parent 75fa2abb32
commit 138e1f5b98
4 changed files with 34 additions and 24 deletions

View File

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

View File

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