mirror of
https://github.com/PlayEdu/PlayEdu
synced 2025-06-29 17:02:42 +08:00
added: 课时重复添加检测
This commit is contained in:
parent
11de12cb7c
commit
a98018a7c0
@ -78,6 +78,14 @@ public class CourseHourController {
|
|||||||
Integer chapterId = req.getChapterId();
|
Integer chapterId = req.getChapterId();
|
||||||
chapterService.findOrFail(chapterId, courseId);
|
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());
|
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()));
|
ctx.publishEvent(new CourseHourCreatedEvent(this, PlayEduBCtx.getAdminUserID(), courseHour.getCourseId(), courseHour.getChapterId(), courseHour.getId()));
|
||||||
return JsonResponse.success();
|
return JsonResponse.success();
|
||||||
@ -91,10 +99,16 @@ public class CourseHourController {
|
|||||||
return JsonResponse.error("参数为空");
|
return JsonResponse.error("参数为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<Integer> existsRids = hourService.getRidsByCourseId(courseId, BackendConstant.RESOURCE_TYPE_VIDEO);
|
||||||
|
|
||||||
List<CourseHour> hours = new ArrayList<>();
|
List<CourseHour> hours = new ArrayList<>();
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
|
|
||||||
for (CourseHourMultiRequest.HourItem item : req.getHours()) {
|
for (CourseHourMultiRequest.HourItem item : req.getHours()) {
|
||||||
|
if (existsRids.contains(item.getRid())) {
|
||||||
|
return JsonResponse.error("课时《" + item.getTitle() + "》已存在");
|
||||||
|
}
|
||||||
|
|
||||||
hours.add(new CourseHour() {{
|
hours.add(new CourseHour() {{
|
||||||
setCourseId(courseId);
|
setCourseId(courseId);
|
||||||
setChapterId(item.getChapterId());
|
setChapterId(item.getChapterId());
|
||||||
|
@ -7,10 +7,10 @@ import xyz.playedu.api.exception.NotFoundException;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
* @description 针对表【course_hour】的数据库操作Service
|
* @description 针对表【course_hour】的数据库操作Service
|
||||||
* @createDate 2023-03-15 10:16:45
|
* @createDate 2023-03-15 10:16:45
|
||||||
*/
|
*/
|
||||||
public interface CourseHourService extends IService<CourseHour> {
|
public interface CourseHourService extends IService<CourseHour> {
|
||||||
|
|
||||||
CourseHour findOrFail(Integer id, Integer courseId) throws NotFoundException;
|
CourseHour findOrFail(Integer id, Integer courseId) throws NotFoundException;
|
||||||
@ -28,4 +28,6 @@ public interface CourseHourService extends IService<CourseHour> {
|
|||||||
void remove(Integer courseId, Integer chapterId);
|
void remove(Integer courseId, Integer chapterId);
|
||||||
|
|
||||||
void updateSort(List<Integer> ids, Integer cid);
|
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.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tengteng
|
* @author tengteng
|
||||||
@ -93,6 +94,11 @@ public class CourseHourServiceImpl extends ServiceImpl<CourseHourMapper, CourseH
|
|||||||
}
|
}
|
||||||
updateBatchById(hours);
|
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