mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-12-22 18:29:51 +08:00
课时管理
This commit is contained in:
29
src/main/java/xyz/playedu/api/service/CourseHourService.java
Normal file
29
src/main/java/xyz/playedu/api/service/CourseHourService.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package xyz.playedu.api.service;
|
||||
|
||||
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
|
||||
*/
|
||||
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;
|
||||
|
||||
Integer getCourseClassHourByCourseId(Integer courseId);
|
||||
|
||||
}
|
||||
@@ -34,4 +34,6 @@ public interface CourseService extends IService<Course> {
|
||||
List<Integer> getDepIdsByCourseId(Integer courseId);
|
||||
|
||||
List<Integer> getCategoryIdsByCourseId(Integer courseId);
|
||||
|
||||
void updateClassHour(Integer courseId, Integer classHour);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package xyz.playedu.api.service.impl;
|
||||
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import xyz.playedu.api.domain.CourseHour;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.service.CourseHourService;
|
||||
import xyz.playedu.api.mapper.CourseHourMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
* @description 针对表【course_hour】的数据库操作Service实现
|
||||
* @createDate 2023-02-26 17:48:12
|
||||
*/
|
||||
@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) {
|
||||
throw new NotFoundException("课时不存在");
|
||||
}
|
||||
return courseHour;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCourseClassHourByCourseId(Integer courseId) {
|
||||
return Math.toIntExact(count(query().getWrapper().eq("course_id", courseId)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -175,6 +175,14 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
|
||||
public List<Integer> getCategoryIdsByCourseId(Integer courseId) {
|
||||
return categoryCourseService.getCategoryIdsByCourseId(courseId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClassHour(Integer courseId, Integer classHour) {
|
||||
Course course = new Course();
|
||||
course.setId(courseId);
|
||||
course.setClassHour(classHour);
|
||||
updateById(course);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user