[AppleScript] 纯文本查看 复制代码
public interface XcLearningCourseRepository extends JpaRepository<XcLearningCourse, String> { //根据用户和课程查询选课记录,用于判断是否添加选课 XcLearningCourse findXcLearningCourseByUserIdAndCourseId(String userId, String courseId); }
[AppleScript] 纯文本查看 复制代码
//完成选课
@Transactional
public ResponseResult addcourse(String userId, String courseId,String valid,Date startTime,Date endTime,XcTask xcTask){ if (StringUtils.isEmpty(courseId)) {
ExceptionCast.cast(LearningCode.LEARNING_GETMEDIA_ERROR);
}
if (StringUtils.isEmpty(userId)) {
ExceptionCast.cast(LearningCode.CHOOSECOURSE_USERISNULL);
}
if(xcTask == null || StringUtils.isEmpty(xcTask.getId())){
ExceptionCast.cast(LearningCode.CHOOSECOURSE_TASKISNULL);
} //查询历史任务
Optional<XcTaskHis> optional = xcTaskHisRepository.findById(xcTask.getId());
if(optional.isPresent()){
return new ResponseResult(CommonCode.SUCCESS);
}
XcLearningCourse xcLearningCourse = xcLearningCourseRepository.findXcLearningCourseByUserIdAndCourseId(userId, courseId); if (xcLearningCourse == null) {//没有选课记录则添加
xcLearningCourse = new XcLearningCourse();
xcLearningCourse.setUserId(userId);
xcLearningCourse.setCourseId(courseId);
xcLearningCourse.setValid(valid);
xcLearningCourse.setStartTime(startTime);
xcLearningCourse.setEndTime(endTime);
xcLearningCourse.setStatus("501001");
xcLearningCourseRepository.save(xcLearningCourse);
} else {//有选课记录则更新日期
xcLearningCourse.setValid(valid);
xcLearningCourse.setStartTime(startTime);
xcLearningCourse.setEndTime(endTime);
xcLearningCourse.setStatus("501001");
xcLearningCourseRepository.save(xcLearningCourse);
}
//向历史任务表播入记录
Optional<XcTaskHis> optional = xcTaskHisRepository.findById(xcTask.getId());
if(!optional.isPresent()){
//添加历史任务
XcTaskHis xcTaskHis = new XcTaskHis();
BeanUtils.copyProperties(xcTask,xcTaskHis);
xcTaskHisRepository.save(xcTaskHis);
}