/ / 完成選課??
?? @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 ) ;???
????? } ????????? / / 查詢歷史任務(wù)??????
?? 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 ) ;?????
??? } ??
????? / / 向歷史任務(wù)表播入記錄
???????? Optional < XcTaskHis > optional = xcTaskHisRepository.findById ( xcTask.getId ( ) ) ;???
????? if ( !optional.isPresent ( ) ) { ??????
????? / / 添加歷史任務(wù)????
???????? XcTaskHis xcTaskHis = new XcTaskHis ( ) ;?????
??????? BeanUtils.copyProperties ( xcTask , xcTaskHis ) ;????
???????? xcTaskHisRepository. save ( xcTaskHis ) ;
???????? }
|