mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-21 19:32:41 +08:00
added: 课时批量创建接口
This commit is contained in:
parent
ee6a506b7f
commit
4f268732be
@ -2,6 +2,7 @@ package xyz.playedu.api.controller.backend;
|
|||||||
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
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.PlayEduBCtx;
|
import xyz.playedu.api.PlayEduBCtx;
|
||||||
@ -13,6 +14,7 @@ import xyz.playedu.api.event.CourseHourCreatedEvent;
|
|||||||
import xyz.playedu.api.event.CourseHourDestroyEvent;
|
import xyz.playedu.api.event.CourseHourDestroyEvent;
|
||||||
import xyz.playedu.api.exception.NotFoundException;
|
import xyz.playedu.api.exception.NotFoundException;
|
||||||
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
import xyz.playedu.api.middleware.BackendPermissionMiddleware;
|
||||||
|
import xyz.playedu.api.request.backend.CourseHourMultiRequest;
|
||||||
import xyz.playedu.api.request.backend.CourseHourRequest;
|
import xyz.playedu.api.request.backend.CourseHourRequest;
|
||||||
import xyz.playedu.api.request.backend.CourseHourSortRequest;
|
import xyz.playedu.api.request.backend.CourseHourSortRequest;
|
||||||
import xyz.playedu.api.service.CourseChapterService;
|
import xyz.playedu.api.service.CourseChapterService;
|
||||||
@ -79,6 +81,39 @@ public class CourseHourController {
|
|||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@BackendPermissionMiddleware(slug = BPermissionConstant.COURSE)
|
||||||
|
@PostMapping("/create-batch")
|
||||||
|
@Transactional
|
||||||
|
public JsonResponse storeMulti(@PathVariable(name = "courseId") Integer courseId, @RequestBody @Validated CourseHourMultiRequest req) {
|
||||||
|
if (req.getHours().size() == 0) {
|
||||||
|
return JsonResponse.error("参数为空");
|
||||||
|
}
|
||||||
|
|
||||||
|
List<CourseHour> hours = new ArrayList<>();
|
||||||
|
Date now = new Date();
|
||||||
|
|
||||||
|
for (CourseHourMultiRequest.CourseHourItem item : req.getHours()) {
|
||||||
|
hours.add(new CourseHour() {{
|
||||||
|
setCourseId(courseId);
|
||||||
|
setChapterId(item.getChapterId());
|
||||||
|
setSort(item.getSort());
|
||||||
|
setType(item.getType());
|
||||||
|
setRid(item.getRid());
|
||||||
|
setTitle(item.getTitle());
|
||||||
|
setDuration(item.getDuration());
|
||||||
|
setCreatedAt(now);
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
hourService.saveBatch(hours);
|
||||||
|
|
||||||
|
// 只需要发布一次event就可以了
|
||||||
|
CourseHour firstHour = hours.get(0);
|
||||||
|
ctx.publishEvent(new CourseHourCreatedEvent(this, PlayEduBCtx.getAdminUserID(), firstHour.getCourseId(), firstHour.getChapterId(), firstHour.getId()));
|
||||||
|
|
||||||
|
return JsonResponse.success();
|
||||||
|
}
|
||||||
|
|
||||||
@BackendPermissionMiddleware(slug = BPermissionConstant.COURSE)
|
@BackendPermissionMiddleware(slug = BPermissionConstant.COURSE)
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
public JsonResponse edit(@PathVariable(name = "courseId") Integer courseId, @PathVariable(name = "id") Integer id) throws NotFoundException {
|
public JsonResponse edit(@PathVariable(name = "courseId") Integer courseId, @PathVariable(name = "id") Integer id) throws NotFoundException {
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
package xyz.playedu.api.request.backend;
|
||||||
|
|
||||||
|
import jakarta.validation.constraints.NotNull;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author 杭州白书科技有限公司
|
||||||
|
* @create 2023/3/21 16:33
|
||||||
|
*/
|
||||||
|
@Data
|
||||||
|
public class CourseHourMultiRequest {
|
||||||
|
@Data
|
||||||
|
public class CourseHourItem {
|
||||||
|
private Integer chapterId;
|
||||||
|
private String title;
|
||||||
|
private Integer duration;
|
||||||
|
private Integer sort;
|
||||||
|
private String type;
|
||||||
|
private Integer rid;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull(message = "hours参数不存在")
|
||||||
|
private List<CourseHourItem> hours;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user