mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-23 17:49:34 +08:00
章节删除
This commit is contained in:
parent
dd7bed66b5
commit
0b47ddc173
@ -60,14 +60,14 @@ public class CourseChapterController {
|
||||
public JsonResponse update(@PathVariable(name = "courseId") Integer courseId, @PathVariable(name = "id") Integer id, @RequestBody @Validated CourseChapterRequest req) throws NotFoundException {
|
||||
CourseChapter chapter = chapterService.findOrFail(id, courseId);
|
||||
chapterService.update(chapter, req.getName(), req.getSort());
|
||||
return JsonResponse.data(chapter);
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@DeleteMapping("/{id}")
|
||||
public JsonResponse destroy(@PathVariable(name = "courseId") Integer courseId, @PathVariable(name = "id") Integer id) throws NotFoundException {
|
||||
CourseChapter chapter = chapterService.findOrFail(id, courseId);
|
||||
chapterService.removeById(chapter.getId());
|
||||
ctx.publishEvent(new CourseChapterDestroyEvent(this, PlayEduBackendThreadLocal.getAdminUserID(), chapter.getCourseId(), new Date()));
|
||||
ctx.publishEvent(new CourseChapterDestroyEvent(this, PlayEduBackendThreadLocal.getAdminUserID(), chapter.getCourseId(), chapter.getId(), new Date()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
}
|
||||
|
@ -14,12 +14,14 @@ import java.util.Date;
|
||||
@Setter
|
||||
public class CourseChapterDestroyEvent extends ApplicationEvent {
|
||||
private Integer adminId;
|
||||
private Integer courseId;
|
||||
private Integer chapterId;
|
||||
private Date date;
|
||||
|
||||
public CourseChapterDestroyEvent(Object source, Integer adminId, Integer chapterId, Date date) {
|
||||
public CourseChapterDestroyEvent(Object source, Integer adminId, Integer courseId, Integer chapterId, Date date) {
|
||||
super(source);
|
||||
this.adminId = adminId;
|
||||
this.courseId = courseId;
|
||||
this.chapterId = chapterId;
|
||||
this.date = date;
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
package xyz.playedu.api.listener;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.event.EventListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
import xyz.playedu.api.event.CourseChapterDestroyEvent;
|
||||
import xyz.playedu.api.service.CourseHourService;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/2/26 18:25
|
||||
*/
|
||||
@Component
|
||||
public class CourseChapterDestroyListener {
|
||||
|
||||
@Autowired
|
||||
private CourseHourService hourService;
|
||||
|
||||
@EventListener
|
||||
public void resetCourseHourChapterId(CourseChapterDestroyEvent event) {
|
||||
hourService.resetChapterIdByCourseIdAndChapterId(event.getCourseId(), event.getChapterId());
|
||||
}
|
||||
|
||||
}
|
@ -26,4 +26,6 @@ public interface CourseHourService extends IService<CourseHour> {
|
||||
|
||||
Integer getCourseClassHourByCourseId(Integer courseId);
|
||||
|
||||
void resetChapterIdByCourseIdAndChapterId(Integer courseId,Integer chapterId);
|
||||
|
||||
}
|
||||
|
@ -76,6 +76,11 @@ public class CourseHourServiceImpl extends ServiceImpl<CourseHourMapper, CourseH
|
||||
public Integer getCourseClassHourByCourseId(Integer courseId) {
|
||||
return Math.toIntExact(count(query().getWrapper().eq("course_id", courseId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetChapterIdByCourseIdAndChapterId(Integer courseId, Integer chapterId) {
|
||||
update(update().getWrapper().eq("course_id", courseId).eq("chapter_id", chapterId).set("chapter_id", 0));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user