优化课程创建

This commit is contained in:
none
2023-03-15 10:40:33 +08:00
parent fb94e93f80
commit cca6d050bc
13 changed files with 213 additions and 136 deletions

View File

@@ -4,28 +4,24 @@ import xyz.playedu.api.domain.CourseHour;
import com.baomidou.mybatisplus.extension.service.IService;
import xyz.playedu.api.exception.NotFoundException;
import java.util.Date;
import java.util.List;
/**
* @author tengteng
* @description 针对表【course_hour】的数据库操作Service
* @createDate 2023-02-26 17:48:12
*/
* @author tengteng
* @description 针对表【course_hour】的数据库操作Service
* @createDate 2023-03-15 10:16:45
*/
public interface CourseHourService extends IService<CourseHour> {
List<CourseHour> getHoursByCourseId(Integer courseId);
CourseHour create(Integer courseId, Integer chapterId, String title, String type, Integer duration, Date publishedAt);
void update(CourseHour courseHour, Integer chapterId, String title, Integer duration, Date publishedAt);
CourseHour findOrFail(Integer id) throws NotFoundException;
CourseHour findOrFail(Integer id, Integer courseId) throws NotFoundException;
void update(CourseHour courseHour, Integer chapterId, Integer sort, String title, Integer duration);
List<CourseHour> getHoursByCourseId(Integer courseId);
CourseHour create(Integer courseId, Integer chapterId, Integer sort, String title, String type, Integer rid, Integer duration);
Integer getCourseClassHourByCourseId(Integer courseId);
void resetChapterIdByCourseIdAndChapterId(Integer courseId,Integer chapterId);
void remove(Integer courseId, Integer chapterId);
}

View File

@@ -17,7 +17,7 @@ public interface CourseService extends IService<Course> {
PaginationResult<Course> paginate(int page, int size, CoursePaginateFiler filter);
void createWithCategoryIdsAndDepIds(String title, String thumb, Integer isShow, Integer[] categoryIds, Integer[] depIds);
Course createWithCategoryIdsAndDepIds(String title, String thumb, Integer isShow, Integer[] categoryIds, Integer[] depIds);
void updateWithCategoryIdsAndDepIds(Course course, String title, String thumb, Integer isShow, Integer[] categoryIds, Integer[] depIds);

View File

@@ -13,63 +13,52 @@ import java.util.List;
/**
* @author tengteng
* @description 针对表【course_hour】的数据库操作Service实现
* @createDate 2023-02-26 17:48:12
* @createDate 2023-03-15 10:16:45
*/
@Service
public class CourseHourServiceImpl extends ServiceImpl<CourseHourMapper, CourseHour> implements CourseHourService {
@Override
public List<CourseHour> getHoursByCourseId(Integer courseId) {
return list(query().getWrapper().eq("course_id", courseId).orderByAsc("published_at"));
}
@Override
public CourseHour create(Integer courseId, Integer chapterId, String title, String type, Integer duration, Date publishedAt) {
CourseHour courseHour = new CourseHour();
courseHour.setCourseId(courseId);
courseHour.setChapterId(chapterId);
courseHour.setTitle(title);
courseHour.setType(type);
courseHour.setDuration(duration);
courseHour.setPublishedAt(publishedAt);
courseHour.setCreatedAt(new Date());
courseHour.setUpdatedAt(new Date());
save(courseHour);
return courseHour;
}
@Override
public void update(CourseHour courseHour, Integer chapterId, String title, Integer duration, Date publishedAt) {
CourseHour newCourseHour = new CourseHour();
newCourseHour.setId(courseHour.getId());
newCourseHour.setChapterId(chapterId);
newCourseHour.setTitle(title);
newCourseHour.setDuration(duration);
newCourseHour.setPublishedAt(publishedAt);
newCourseHour.setCreatedAt(new Date());
newCourseHour.setUpdatedAt(new Date());
updateById(newCourseHour);
}
@Override
public CourseHour findOrFail(Integer id) throws NotFoundException {
CourseHour courseHour = getOne(query().getWrapper().eq("id", id));
if (courseHour == null) {
throw new NotFoundException("课时不存在");
}
return courseHour;
}
@Override
public CourseHour findOrFail(Integer id, Integer courseId) throws NotFoundException {
CourseHour courseHour = getOne(query().getWrapper().eq("id", id).eq("course_id", courseId));
if (courseHour == null) {
CourseHour hour = getOne(query().getWrapper().eq("id", id).eq("course_id", courseId));
if (hour == null) {
throw new NotFoundException("课时不存在");
}
return courseHour;
return hour;
}
@Override
public void update(CourseHour courseHour, Integer chapterId, Integer sort, String title, Integer duration) {
CourseHour hour = new CourseHour();
hour.setId(courseHour.getId());
hour.setChapterId(chapterId);
hour.setSort(sort);
hour.setTitle(title);
hour.setDuration(duration);
updateById(hour);
}
@Override
public List<CourseHour> getHoursByCourseId(Integer courseId) {
return list(query().getWrapper().eq("course_id", courseId).orderByAsc("sort"));
}
@Override
public CourseHour create(Integer courseId, Integer chapterId, Integer sort, String title, String type, Integer rid, Integer duration) {
CourseHour hour = new CourseHour();
hour.setCourseId(courseId);
hour.setChapterId(chapterId);
hour.setSort(sort);
hour.setTitle(title);
hour.setType(type);
hour.setRid(rid);
hour.setDuration(duration);
hour.setCreatedAt(new Date());
save(hour);
return hour;
}
@Override
@@ -78,8 +67,8 @@ public class CourseHourServiceImpl extends ServiceImpl<CourseHourMapper, CourseH
}
@Override
public void resetChapterIdByCourseIdAndChapterId(Integer courseId, Integer chapterId) {
update(update().getWrapper().eq("course_id", courseId).eq("chapter_id", chapterId).set("chapter_id", 0));
public void remove(Integer courseId, Integer chapterId) {
remove(query().getWrapper().eq("course_id", courseId).eq("chapter_id", chapterId));
}
}

View File

@@ -91,7 +91,7 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
@Override
@Transactional
public void createWithCategoryIdsAndDepIds(String title, String thumb, Integer isShow, Integer[] categoryIds, Integer[] depIds) {
public Course createWithCategoryIdsAndDepIds(String title, String thumb, Integer isShow, Integer[] categoryIds, Integer[] depIds) {
// 创建课程
Course course = new Course();
course.setTitle(title);
@@ -104,6 +104,8 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
relateCategories(course, categoryIds);
// 关联部门
relateDepartments(course, depIds);
return course;
}
@Override