课程分类删除

This commit is contained in:
none 2023-02-26 18:56:25 +08:00
parent 316d5d2d26
commit 9883faf3d1
5 changed files with 24 additions and 5 deletions

View File

@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import xyz.playedu.api.PlayEduBackendThreadLocal;
import xyz.playedu.api.constant.BPermissionConstant; import xyz.playedu.api.constant.BPermissionConstant;
import xyz.playedu.api.domain.CourseCategory; import xyz.playedu.api.domain.CourseCategory;
import xyz.playedu.api.event.CourseCategoryDestroyEvent; import xyz.playedu.api.event.CourseCategoryDestroyEvent;
@ -77,9 +78,7 @@ public class CourseCategoryController {
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException { public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
CourseCategory category = categoryService.findOrFail(id); CourseCategory category = categoryService.findOrFail(id);
categoryService.deleteById(category.getId()); categoryService.deleteById(category.getId());
ctx.publishEvent(new CourseCategoryDestroyEvent(this, PlayEduBackendThreadLocal.getAdminUserID(), category.getId(), new Date()));
ctx.publishEvent(new CourseCategoryDestroyEvent(this, id, new Date()));
return JsonResponse.success(); return JsonResponse.success();
} }

View File

@ -14,11 +14,13 @@ import java.util.Date;
@Getter @Getter
public class CourseCategoryDestroyEvent extends ApplicationEvent { public class CourseCategoryDestroyEvent extends ApplicationEvent {
private Integer adminId;
private Integer categoryId; private Integer categoryId;
private Date at; private Date at;
public CourseCategoryDestroyEvent(Object source, Integer categoryId, Date date) { public CourseCategoryDestroyEvent(Object source, Integer adminId, Integer categoryId, Date date) {
super(source); super(source);
this.adminId = adminId;
this.categoryId = categoryId; this.categoryId = categoryId;
this.at = date; this.at = date;
} }

View File

@ -1,14 +1,25 @@
package xyz.playedu.api.listener; package xyz.playedu.api.listener;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import xyz.playedu.api.event.CourseCategoryDestroyEvent;
import xyz.playedu.api.service.CourseService;
/** /**
* @Author 杭州白书科技有限公司 * @Author 杭州白书科技有限公司
* @create 2023/2/24 14:07 * @create 2023/2/24 14:07
*/ */
@Component @Component
@Slf4j
public class CourseCategoryDestroyListener { public class CourseCategoryDestroyListener {
@Autowired
private CourseService courseService;
@EventListener
public void resetRelateCourseCategoryId(CourseCategoryDestroyEvent event) {
courseService.removeCategoryIdRelate(event.getCategoryId());
}
} }

View File

@ -36,4 +36,6 @@ public interface CourseService extends IService<Course> {
List<Integer> getCategoryIdsByCourseId(Integer courseId); List<Integer> getCategoryIdsByCourseId(Integer courseId);
void updateClassHour(Integer courseId, Integer classHour); void updateClassHour(Integer courseId, Integer classHour);
void removeCategoryIdRelate(Integer categoryId);
} }

View File

@ -183,6 +183,11 @@ public class CourseServiceImpl extends ServiceImpl<CourseMapper, Course> impleme
course.setClassHour(classHour); course.setClassHour(classHour);
updateById(course); updateById(course);
} }
@Override
public void removeCategoryIdRelate(Integer categoryId) {
categoryCourseService.remove(categoryCourseService.query().getWrapper().eq("category_id", categoryId));
}
} }