mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-29 00:42:50 +08:00
added: 课时重复添加检测
This commit is contained in:
parent
11de12cb7c
commit
a98018a7c0
@ -78,6 +78,14 @@ public class CourseHourController {
|
||||
Integer chapterId = req.getChapterId();
|
||||
chapterService.findOrFail(chapterId, courseId);
|
||||
|
||||
// 课时重复添加校验
|
||||
List<Integer> existsRids = hourService.getRidsByCourseId(courseId, BackendConstant.RESOURCE_TYPE_VIDEO);
|
||||
if (existsRids != null) {
|
||||
if (existsRids.contains(req.getRid())) {
|
||||
return JsonResponse.error("课时已存在");
|
||||
}
|
||||
}
|
||||
|
||||
CourseHour courseHour = hourService.create(courseId, chapterId, req.getSort(), req.getTitle(), type, req.getRid(), req.getDuration());
|
||||
ctx.publishEvent(new CourseHourCreatedEvent(this, PlayEduBCtx.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
|
||||
return JsonResponse.success();
|
||||
@ -91,10 +99,16 @@ public class CourseHourController {
|
||||
return JsonResponse.error("参数为空");
|
||||
}
|
||||
|
||||
List<Integer> existsRids = hourService.getRidsByCourseId(courseId, BackendConstant.RESOURCE_TYPE_VIDEO);
|
||||
|
||||
List<CourseHour> hours = new ArrayList<>();
|
||||
Date now = new Date();
|
||||
|
||||
for (CourseHourMultiRequest.HourItem item : req.getHours()) {
|
||||
if (existsRids.contains(item.getRid())) {
|
||||
return JsonResponse.error("课时《" + item.getTitle() + "》已存在");
|
||||
}
|
||||
|
||||
hours.add(new CourseHour() {{
|
||||
setCourseId(courseId);
|
||||
setChapterId(item.getChapterId());
|
||||
|
@ -28,4 +28,6 @@ public interface CourseHourService extends IService<CourseHour> {
|
||||
void remove(Integer courseId, Integer chapterId);
|
||||
|
||||
void updateSort(List<Integer> ids, Integer cid);
|
||||
|
||||
List<Integer> getRidsByCourseId(Integer courseId, String type);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import org.springframework.stereotype.Service;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
/**
|
||||
* @author tengteng
|
||||
@ -93,6 +94,11 @@ public class CourseHourServiceImpl extends ServiceImpl<CourseHourMapper, CourseH
|
||||
}
|
||||
updateBatchById(hours);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Integer> getRidsByCourseId(Integer courseId, String type) {
|
||||
return list(query().getWrapper().eq("course_id", courseId).eq("type", type)).stream().map(CourseHour::getRid).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user