mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-07-25 02:39:31 +08:00
fixed: 线上课添加
This commit is contained in:
parent
a231e7e6a0
commit
526d661255
@ -93,25 +93,20 @@ public class CourseController {
|
||||
public JsonResponse store(@RequestBody @Validated CourseRequest req) throws ParseException {
|
||||
Course course = courseService.createWithCategoryIdsAndDepIds(req.getTitle(), req.getThumb(), req.getIsShow(), req.getCategoryIds(), req.getDepIds());
|
||||
|
||||
Map<String, Map<String, Object>[]> chapters = req.getChapters();
|
||||
Date now = new Date();
|
||||
|
||||
if (req.getHours() != null) {//无章节课时配置
|
||||
List<CourseHour> insertHours = new ArrayList<>();
|
||||
for (Map<String, Object> hourItem : req.getHours()) {
|
||||
// 资源类型
|
||||
String typeVal = MapUtils.getString(hourItem, "type");
|
||||
// 时长
|
||||
Integer durationVal = MapUtils.getInteger(hourItem, "duration");
|
||||
// 资源ID
|
||||
Integer ridVal = MapUtils.getInteger(hourItem, "rid");
|
||||
|
||||
final Integer[] chapterSort = {0};
|
||||
for (CourseRequest.HourItem hourItem : req.getHours()) {
|
||||
insertHours.add(new CourseHour() {{
|
||||
setChapterId(0);
|
||||
setCourseId(course.getId());
|
||||
setType(typeVal);
|
||||
setDuration(durationVal);
|
||||
setRid(ridVal);
|
||||
setChapterId(0);
|
||||
setSort(chapterSort[0]++);
|
||||
setTitle(hourItem.getName());
|
||||
setType(hourItem.getType());
|
||||
setDuration(hourItem.getDuration());
|
||||
setRid(hourItem.getRid());
|
||||
setCreatedAt(now);
|
||||
}});
|
||||
}
|
||||
@ -119,20 +114,17 @@ public class CourseController {
|
||||
hourService.saveBatch(insertHours);
|
||||
}
|
||||
} else {
|
||||
if (chapters == null) {
|
||||
if (req.getChapters() == null || req.getChapters().size() == 0) {
|
||||
return JsonResponse.error("请配置课时");
|
||||
}
|
||||
List<CourseHour> insertHours = new ArrayList<>();
|
||||
final Integer[] chapterSort = {0};
|
||||
|
||||
for (Map.Entry<String, Map<String, Object>[]> entry : chapters.entrySet()) {
|
||||
String chapterName = entry.getKey();
|
||||
Map<String, Object>[] hoursList = entry.getValue();
|
||||
|
||||
for (CourseRequest.ChapterItem chapterItem : req.getChapters()) {
|
||||
CourseChapter tmpChapter = new CourseChapter() {{
|
||||
setCourseId(course.getId());
|
||||
setSort(chapterSort[0]++);
|
||||
setName(chapterName);
|
||||
setName(chapterItem.getName());
|
||||
setCreatedAt(now);
|
||||
setUpdatedAt(now);
|
||||
}};
|
||||
@ -140,22 +132,16 @@ public class CourseController {
|
||||
chapterService.save(tmpChapter);
|
||||
|
||||
final Integer[] hourSort = {0};
|
||||
for (Map<String, Object> hourItem : hoursList) {
|
||||
// 资源类型
|
||||
String typeVal = MapUtils.getString(hourItem, "type");
|
||||
// 时长
|
||||
Integer durationVal = MapUtils.getInteger(hourItem, "duration");
|
||||
// 资源ID
|
||||
Integer ridVal = MapUtils.getInteger(hourItem, "rid");
|
||||
|
||||
for (CourseRequest.HourItem hourItem : chapterItem.getHours()) {
|
||||
insertHours.add(new CourseHour() {{
|
||||
setChapterId(tmpChapter.getId());
|
||||
setCourseId(course.getId());
|
||||
setType(typeVal);
|
||||
setDuration(durationVal);
|
||||
setRid(ridVal);
|
||||
setCreatedAt(now);
|
||||
setSort(hourSort[0]++);
|
||||
setTitle(hourItem.getName());
|
||||
setType(hourItem.getType());
|
||||
setDuration(hourItem.getDuration());
|
||||
setRid(hourItem.getRid());
|
||||
setCreatedAt(now);
|
||||
}});
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import jakarta.validation.constraints.NotBlank;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -34,29 +35,46 @@ public class CourseRequest {
|
||||
@JsonProperty("category_ids")
|
||||
private Integer[] categoryIds;
|
||||
|
||||
// 格式
|
||||
// [
|
||||
// '章节名' => [
|
||||
// [
|
||||
// 'name' => '课时名',
|
||||
// 'type' => '课时类型', // 可选值[VIDEO]
|
||||
// 'duration' => 时长, // 单位[秒]
|
||||
// 'rid' => 资源ID, // 如果是type=VIDEO的话则对应视频的id
|
||||
// ]...
|
||||
// ]...
|
||||
// ]
|
||||
@NotNull(message = "chapters参数不存在")
|
||||
private Map<String, Map<String, Object>[]> chapters;
|
||||
@Data
|
||||
public static class HourItem {
|
||||
private String name;
|
||||
private String type;
|
||||
private Integer duration;
|
||||
private Integer rid;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ChapterItem {
|
||||
private String name;
|
||||
private List<HourItem> hours;
|
||||
}
|
||||
|
||||
// 格式
|
||||
// [
|
||||
// [
|
||||
// {
|
||||
// 'name' => '章节名',
|
||||
// 'hours' => [
|
||||
// [
|
||||
// 'name' => '课时名',
|
||||
// 'type' => '课时类型',
|
||||
// 'duration' => '时长',
|
||||
// 'rid' => '资源id',
|
||||
// ],...
|
||||
// ],
|
||||
// }...
|
||||
// ]
|
||||
@NotNull(message = "chapters参数不存在")
|
||||
private List<ChapterItem> chapters;
|
||||
|
||||
// 格式
|
||||
// [
|
||||
// {
|
||||
// 'name' => '课时名',
|
||||
// 'type' => '课时类型',
|
||||
// 'duration' => '时长',
|
||||
// 'rid' => '资源id',
|
||||
// ]...
|
||||
// }...
|
||||
// ]
|
||||
@NotNull(message = "hours参数不存在")
|
||||
private Map<String, Object>[] hours;
|
||||
private List<HourItem> hours;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user