mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-10 20:04:06 +08:00
优化event的时间属性 && 新增线上课章节和课时的排序编辑apic
This commit is contained in:
parent
00e4e66271
commit
337e600432
@ -11,7 +11,9 @@ import xyz.playedu.api.event.CourseChapterDestroyEvent;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.CourseChapterRequest;
|
||||
import xyz.playedu.api.request.backend.CourseChapterSortRequest;
|
||||
import xyz.playedu.api.service.CourseChapterService;
|
||||
import xyz.playedu.api.service.CourseHourService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
|
||||
import java.util.Date;
|
||||
@ -27,6 +29,9 @@ public class CourseChapterController {
|
||||
@Autowired
|
||||
private CourseChapterService chapterService;
|
||||
|
||||
@Autowired
|
||||
private CourseHourService hourService;
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext ctx;
|
||||
|
||||
@ -56,8 +61,17 @@ public class CourseChapterController {
|
||||
@DeleteMapping("/{id}")
|
||||
public JsonResponse destroy(@PathVariable(name = "courseId") Integer courseId, @PathVariable(name = "id") Integer id) throws NotFoundException {
|
||||
CourseChapter chapter = chapterService.findOrFail(id, courseId);
|
||||
if (hourService.getCountByChapterId(chapter.getId()) > 0) {
|
||||
return JsonResponse.error("当前章节下面存在课时无法删除");
|
||||
}
|
||||
chapterService.removeById(chapter.getId());
|
||||
ctx.publishEvent(new CourseChapterDestroyEvent(this, PlayEduBContext.getAdminUserID(), chapter.getCourseId(), chapter.getId(), new Date()));
|
||||
ctx.publishEvent(new CourseChapterDestroyEvent(this, PlayEduBContext.getAdminUserID(), chapter.getCourseId(), chapter.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@PutMapping("/update/sort")
|
||||
public JsonResponse updateSort(@PathVariable(name = "courseId") Integer courseId, @RequestBody @Validated CourseChapterSortRequest req) {
|
||||
chapterService.updateSort(req.getIds(), courseId);
|
||||
return JsonResponse.success();
|
||||
}
|
||||
}
|
||||
|
@ -185,7 +185,7 @@ public class CourseController {
|
||||
@DeleteMapping("/{id}")
|
||||
public JsonResponse destroy(@PathVariable(name = "id") Integer id) {
|
||||
courseService.removeById(id);
|
||||
ctx.publishEvent(new CourseDestroyEvent(this, PlayEduBContext.getAdminUserID(), id, new Date()));
|
||||
ctx.publishEvent(new CourseDestroyEvent(this, PlayEduBContext.getAdminUserID(), id));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@ import xyz.playedu.api.event.CourseHourDestroyEvent;
|
||||
import xyz.playedu.api.exception.NotFoundException;
|
||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||
import xyz.playedu.api.request.backend.CourseHourRequest;
|
||||
import xyz.playedu.api.request.backend.CourseHourSortRequest;
|
||||
import xyz.playedu.api.service.CourseChapterService;
|
||||
import xyz.playedu.api.service.CourseHourService;
|
||||
import xyz.playedu.api.types.JsonResponse;
|
||||
@ -74,7 +75,7 @@ public class CourseHourController {
|
||||
chapterService.findOrFail(chapterId, courseId);
|
||||
|
||||
CourseHour courseHour = hourService.create(courseId, chapterId, req.getSort(), req.getTitle(), type, req.getRid(), req.getDuration());
|
||||
ctx.publishEvent(new CourseHourCreatedEvent(this, PlayEduBContext.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId(), new Date()));
|
||||
ctx.publishEvent(new CourseHourCreatedEvent(this, PlayEduBContext.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@ -102,7 +103,13 @@ public class CourseHourController {
|
||||
public JsonResponse destroy(@PathVariable(name = "courseId") Integer courseId, @PathVariable(name = "id") Integer id) throws NotFoundException {
|
||||
CourseHour courseHour = hourService.findOrFail(id, courseId);
|
||||
hourService.removeById(courseHour.getId());
|
||||
ctx.publishEvent(new CourseHourDestroyEvent(this, PlayEduBContext.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId(), new Date()));
|
||||
ctx.publishEvent(new CourseHourDestroyEvent(this, PlayEduBContext.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
@PutMapping("/update/sort")
|
||||
public JsonResponse updateSort(@PathVariable(name = "courseId") Integer courseId, @RequestBody @Validated CourseHourSortRequest req) {
|
||||
hourService.updateSort(req.getIds(), courseId);
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ public class DepartmentController {
|
||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||
Department department = departmentService.findOrFail(id);
|
||||
departmentService.deleteById(department.getId());
|
||||
ctx.publishEvent(new DepartmentDestroyEvent(this, PlayEduBContext.getAdminUserID(), department.getId(), new Date()));
|
||||
ctx.publishEvent(new DepartmentDestroyEvent(this, PlayEduBContext.getAdminUserID(), department.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class LoginController {
|
||||
data.put("token", token.getToken());
|
||||
data.put("expire", token.getExpire());
|
||||
|
||||
ctx.publishEvent(new AdminUserLoginEvent(this, adminUser.getId(), new Date(), token.getToken(), IpUtil.getIpAddress(), adminUser.getLoginTimes()));
|
||||
ctx.publishEvent(new AdminUserLoginEvent(this, adminUser.getId(), token.getToken(), IpUtil.getIpAddress(), adminUser.getLoginTimes()));
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public class ResourceCategoryController {
|
||||
public JsonResponse destroy(@PathVariable Integer id) throws NotFoundException {
|
||||
ResourceCategory category = categoryService.findOrFail(id);
|
||||
categoryService.deleteById(category.getId());
|
||||
ctx.publishEvent(new ResourceCategoryDestroyEvent(this, PlayEduBContext.getAdminUserID(), category.getId(), new Date()));
|
||||
ctx.publishEvent(new ResourceCategoryDestroyEvent(this, PlayEduBContext.getAdminUserID(), category.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -143,7 +143,7 @@ public class UserController {
|
||||
public JsonResponse destroy(@PathVariable(name = "id") Integer id) throws NotFoundException {
|
||||
User user = userService.findOrFail(id);
|
||||
userService.removeById(user.getId());
|
||||
context.publishEvent(new UserDestroyEvent(this, user.getId(), new Date()));
|
||||
context.publishEvent(new UserDestroyEvent(this, user.getId()));
|
||||
return JsonResponse.success();
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class LoginController {
|
||||
data.put("token", token.getToken());
|
||||
data.put("expired", token.getExpire());
|
||||
|
||||
ctx.publishEvent(new UserLoginEvent(this, user.getId(), user.getEmail(), new Date(), token.getToken(), IpUtil.getIpAddress(), RequestUtil.ua()));
|
||||
ctx.publishEvent(new UserLoginEvent(this, user.getId(), user.getEmail(), token.getToken(), IpUtil.getIpAddress(), RequestUtil.ua()));
|
||||
|
||||
return JsonResponse.data(data);
|
||||
}
|
||||
|
@ -20,10 +20,10 @@ public class AdminUserLoginEvent extends ApplicationEvent {
|
||||
|
||||
private Integer loginTimes;
|
||||
|
||||
public AdminUserLoginEvent(Object source, Integer adminId, Date loginAt, String token, String ip, Integer loginTimes) {
|
||||
public AdminUserLoginEvent(Object source, Integer adminId, String token, String ip, Integer loginTimes) {
|
||||
super(source);
|
||||
this.adminId = adminId;
|
||||
this.loginAt = loginAt;
|
||||
this.loginAt = new Date();
|
||||
this.token = token;
|
||||
this.ip = ip;
|
||||
this.loginTimes = loginTimes;
|
||||
|
@ -16,13 +16,13 @@ public class CourseCategoryDestroyEvent extends ApplicationEvent {
|
||||
|
||||
private Integer adminId;
|
||||
private Integer categoryId;
|
||||
private Date at;
|
||||
private Date createdAt;
|
||||
|
||||
public CourseCategoryDestroyEvent(Object source, Integer adminId, Integer categoryId, Date date) {
|
||||
public CourseCategoryDestroyEvent(Object source, Integer adminId, Integer categoryId) {
|
||||
super(source);
|
||||
this.adminId = adminId;
|
||||
this.categoryId = categoryId;
|
||||
this.at = date;
|
||||
this.createdAt = new Date();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,13 +16,13 @@ public class CourseChapterDestroyEvent extends ApplicationEvent {
|
||||
private Integer adminId;
|
||||
private Integer courseId;
|
||||
private Integer chapterId;
|
||||
private Date date;
|
||||
private Date createdAt;
|
||||
|
||||
public CourseChapterDestroyEvent(Object source, Integer adminId, Integer courseId, Integer chapterId, Date date) {
|
||||
public CourseChapterDestroyEvent(Object source, Integer adminId, Integer courseId, Integer chapterId) {
|
||||
super(source);
|
||||
this.adminId = adminId;
|
||||
this.courseId = courseId;
|
||||
this.chapterId = chapterId;
|
||||
this.date = date;
|
||||
this.createdAt = new Date();
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ import java.util.Date;
|
||||
public class CourseDestroyEvent extends ApplicationEvent {
|
||||
|
||||
private Integer courseId;
|
||||
private Date at;
|
||||
private Date createdAt;
|
||||
private Integer adminId;
|
||||
|
||||
public CourseDestroyEvent(Object source, Integer adminId, Integer courseId, Date date) {
|
||||
public CourseDestroyEvent(Object source, Integer adminId, Integer courseId) {
|
||||
super(source);
|
||||
this.courseId = courseId;
|
||||
this.at = date;
|
||||
this.createdAt = new Date();
|
||||
this.adminId = adminId;
|
||||
}
|
||||
|
||||
|
@ -17,14 +17,14 @@ public class CourseHourCreatedEvent extends ApplicationEvent {
|
||||
private Integer hourId;
|
||||
private Integer courseId;
|
||||
private Integer chapterId;
|
||||
private Date date;
|
||||
private Date createdAt;
|
||||
|
||||
public CourseHourCreatedEvent(Object source, Integer adminId, Integer courseId, Integer chapterId, Integer hourId, Date date) {
|
||||
public CourseHourCreatedEvent(Object source, Integer adminId, Integer courseId, Integer chapterId, Integer hourId) {
|
||||
super(source);
|
||||
this.adminId = adminId;
|
||||
this.courseId = courseId;
|
||||
this.chapterId = chapterId;
|
||||
this.hourId = hourId;
|
||||
this.date = date;
|
||||
this.createdAt = new Date();
|
||||
}
|
||||
}
|
||||
|
@ -17,14 +17,14 @@ public class CourseHourDestroyEvent extends ApplicationEvent {
|
||||
private Integer hourId;
|
||||
private Integer courseId;
|
||||
private Integer chapterId;
|
||||
private Date date;
|
||||
private Date createdAt;
|
||||
|
||||
public CourseHourDestroyEvent(Object source, Integer adminId, Integer courseId, Integer chapterId, Integer hourId, Date date) {
|
||||
public CourseHourDestroyEvent(Object source, Integer adminId, Integer courseId, Integer chapterId, Integer hourId) {
|
||||
super(source);
|
||||
this.adminId = adminId;
|
||||
this.courseId = courseId;
|
||||
this.chapterId = chapterId;
|
||||
this.hourId = hourId;
|
||||
this.date = date;
|
||||
this.createdAt = new Date();
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,12 @@ public class DepartmentDestroyEvent extends ApplicationEvent {
|
||||
|
||||
private Integer depId;
|
||||
private Integer adminId;
|
||||
private Date at;
|
||||
private Date createdAt;
|
||||
|
||||
public DepartmentDestroyEvent(Object source, Integer adminId, Integer depId, Date date) {
|
||||
public DepartmentDestroyEvent(Object source, Integer adminId, Integer depId) {
|
||||
super(source);
|
||||
this.adminId = adminId;
|
||||
this.depId = depId;
|
||||
this.at = date;
|
||||
this.createdAt = new Date();
|
||||
}
|
||||
}
|
||||
|
@ -16,12 +16,12 @@ public class ResourceCategoryDestroyEvent extends ApplicationEvent {
|
||||
|
||||
private Integer adminId;
|
||||
private Integer categoryId;
|
||||
private Date date;
|
||||
private Date createdAt;
|
||||
|
||||
public ResourceCategoryDestroyEvent(Object source, Integer adminId, Integer categoryId, Date date) {
|
||||
public ResourceCategoryDestroyEvent(Object source, Integer adminId, Integer categoryId) {
|
||||
super(source);
|
||||
this.adminId = adminId;
|
||||
this.categoryId = categoryId;
|
||||
this.date = date;
|
||||
this.createdAt = new Date();
|
||||
}
|
||||
}
|
||||
|
@ -15,11 +15,11 @@ import java.util.Date;
|
||||
public class UserDestroyEvent extends ApplicationEvent {
|
||||
|
||||
private Integer userId;
|
||||
private Date at;
|
||||
private Date createdAt;
|
||||
|
||||
public UserDestroyEvent(Object source, Integer userId, Date date) {
|
||||
public UserDestroyEvent(Object source, Integer userId) {
|
||||
super(source);
|
||||
this.userId = userId;
|
||||
this.at = date;
|
||||
this.createdAt = new Date();
|
||||
}
|
||||
}
|
||||
|
@ -27,14 +27,14 @@ public class UserLoginEvent extends ApplicationEvent {
|
||||
|
||||
private UserAgent userAgent;
|
||||
|
||||
public UserLoginEvent(Object source, Integer userId,String email, Date loginAt, String token, String ip, UserAgent userAgent) {
|
||||
public UserLoginEvent(Object source, Integer userId, String email, String token, String ip, UserAgent userAgent) {
|
||||
super(source);
|
||||
this.userId = userId;
|
||||
this.email = email;
|
||||
this.loginAt = loginAt;
|
||||
this.token = token;
|
||||
this.ip = ip;
|
||||
this.userAgent = userAgent;
|
||||
this.loginAt = new Date();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class CourseHourCreatedListener {
|
||||
|
||||
@EventListener
|
||||
public void courseClassHourUpdate(CourseHourCreatedEvent event) {
|
||||
Integer classHour = hourService.getCourseClassHourByCourseId(event.getCourseId());
|
||||
Integer classHour = hourService.getCountByCourseId(event.getCourseId());
|
||||
courseService.updateClassHour(event.getCourseId(), classHour);
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ public class CourseHourDestroyListener {
|
||||
|
||||
@EventListener
|
||||
public void courseClassHourUpdate(CourseHourDestroyEvent event) {
|
||||
Integer classHour = hourService.getCourseClassHourByCourseId(event.getCourseId());
|
||||
Integer classHour = hourService.getCountByCourseId(event.getCourseId());
|
||||
courseService.updateClassHour(event.getCourseId(), classHour);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,16 @@
|
||||
package xyz.playedu.api.request.backend;
|
||||
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/3/20 10:42
|
||||
*/
|
||||
@Data
|
||||
public class CourseChapterSortRequest {
|
||||
@NotNull(message = "ids参数不存在")
|
||||
private List<Integer> ids;
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package xyz.playedu.api.request.backend;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @Author 杭州白书科技有限公司
|
||||
* @create 2023/3/20 10:45
|
||||
*/
|
||||
@Data
|
||||
public class CourseHourSortRequest {
|
||||
private List<Integer> ids;
|
||||
}
|
@ -23,4 +23,6 @@ public interface CourseChapterService extends IService<CourseChapter> {
|
||||
|
||||
CourseChapter findOrFail(Integer id, Integer courseId) throws NotFoundException;
|
||||
|
||||
void updateSort(List<Integer> ids, Integer cid);
|
||||
|
||||
}
|
||||
|
@ -21,7 +21,11 @@ public interface CourseHourService extends IService<CourseHour> {
|
||||
|
||||
CourseHour create(Integer courseId, Integer chapterId, Integer sort, String title, String type, Integer rid, Integer duration);
|
||||
|
||||
Integer getCourseClassHourByCourseId(Integer courseId);
|
||||
Integer getCountByCourseId(Integer courseId);
|
||||
|
||||
Integer getCountByChapterId(Integer chapterId);
|
||||
|
||||
void remove(Integer courseId, Integer chapterId);
|
||||
|
||||
void updateSort(List<Integer> ids, Integer cid);
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import xyz.playedu.api.service.CourseChapterService;
|
||||
import xyz.playedu.api.mapper.CourseChapterMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -61,6 +62,23 @@ public class CourseChapterServiceImpl extends ServiceImpl<CourseChapterMapper, C
|
||||
}
|
||||
return chapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSort(List<Integer> ids, Integer cid) {
|
||||
if (ids == null || ids.size() == 0) {
|
||||
return;
|
||||
}
|
||||
List<CourseChapter> chapters = new ArrayList<>();
|
||||
final Integer[] sortVal = {0};
|
||||
for (Integer idItem : ids) {
|
||||
chapters.add(new CourseChapter() {{
|
||||
setId(idItem);
|
||||
setId(cid);
|
||||
setSort(sortVal[0]++);
|
||||
}});
|
||||
}
|
||||
updateBatchById(chapters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -7,6 +7,7 @@ import xyz.playedu.api.service.CourseHourService;
|
||||
import xyz.playedu.api.mapper.CourseHourMapper;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
@ -62,14 +63,36 @@ public class CourseHourServiceImpl extends ServiceImpl<CourseHourMapper, CourseH
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCourseClassHourByCourseId(Integer courseId) {
|
||||
public Integer getCountByCourseId(Integer courseId) {
|
||||
return Math.toIntExact(count(query().getWrapper().eq("course_id", courseId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer getCountByChapterId(Integer chapterId) {
|
||||
return Math.toIntExact(count(query().getWrapper().eq("chapter_id", chapterId)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove(Integer courseId, Integer chapterId) {
|
||||
remove(query().getWrapper().eq("course_id", courseId).eq("chapter_id", chapterId));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateSort(List<Integer> ids, Integer cid) {
|
||||
if (ids == null || ids.size() == 0) {
|
||||
return;
|
||||
}
|
||||
List<CourseHour> hours = new ArrayList<>();
|
||||
final Integer[] sortVal = {0};
|
||||
for (Integer idVal : ids) {
|
||||
hours.add(new CourseHour() {{
|
||||
setId(idVal);
|
||||
setCourseId(cid);
|
||||
setSort(sortVal[0]++);
|
||||
}});
|
||||
}
|
||||
updateBatchById(hours);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user