|
|
@@ -11,6 +11,7 @@ import cn.seecoder.seecoderportalserver.service.Impl.CoderService;
|
|
|
import cn.seecoder.seecoderportalserver.service.Impl.EvalService;
|
|
|
import cn.seecoder.seecoderportalserver.service.Impl.HelperService;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.sun.org.apache.xpath.internal.operations.Bool;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -45,27 +46,31 @@ public class CourseService {
|
|
|
throw new CustomErrorException("当前用户无权创建课程");
|
|
|
}
|
|
|
|
|
|
-// Integer coderId;
|
|
|
-// Integer evalId;
|
|
|
-//
|
|
|
-// // 创建Coder课程
|
|
|
-// JSONObject coderRes = coderService.createService(courseVO);
|
|
|
-// if (!coderRes.containsKey("res")) {
|
|
|
-// throw new CustomErrorException("Coder: " + coderRes.get("msg"));
|
|
|
-// } else {
|
|
|
-// JSONObject coderCourse = (JSONObject) coderRes.get("res");
|
|
|
-// coderId = (Integer) coderCourse.get("id");
|
|
|
-// courseVO.setCoderId(coderId);
|
|
|
-// }
|
|
|
-// // 创建Eval课程
|
|
|
-// JSONObject evalRes = evalService.createService(courseVO);
|
|
|
-// if (evalRes.containsKey("error")) {
|
|
|
-// throw new CustomErrorException("Eval: " + evalRes.get("error"));
|
|
|
-// } else {
|
|
|
-// JSONObject evalCourse = (JSONObject) evalRes.get("result");
|
|
|
-// evalId = (Integer) evalCourse.get("id");
|
|
|
-// courseVO.setEvalId(evalId);
|
|
|
-// }
|
|
|
+ Integer coderId;
|
|
|
+ Integer evalId;
|
|
|
+
|
|
|
+ // 创建Coder课程
|
|
|
+ if (courseVO.getCoderId().equals(-1)) {
|
|
|
+ JSONObject coderRes = coderService.createService(courseVO);
|
|
|
+ if (!coderRes.containsKey("res")) {
|
|
|
+ throw new CustomErrorException("Coder: " + coderRes.get("msg"));
|
|
|
+ } else {
|
|
|
+ JSONObject coderCourse = (JSONObject) coderRes.get("res");
|
|
|
+ coderId = (Integer) coderCourse.get("id");
|
|
|
+ courseVO.setCoderId(coderId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 创建Eval课程
|
|
|
+ if (courseVO.getEvalId().equals(-1)) {
|
|
|
+ JSONObject evalRes = evalService.createService(courseVO);
|
|
|
+ if (evalRes.containsKey("error")) {
|
|
|
+ throw new CustomErrorException("Eval: " + evalRes.get("error"));
|
|
|
+ } else {
|
|
|
+ JSONObject evalCourse = (JSONObject) evalRes.get("result");
|
|
|
+ evalId = (Integer) evalCourse.get("id");
|
|
|
+ courseVO.setEvalId(evalId);
|
|
|
+ }
|
|
|
+ }
|
|
|
Course course = courseMapper.courseVOToCourse(courseVO);
|
|
|
course.setState(ObjectState.NORMAL);
|
|
|
Course result = courseRepository.save(course);
|
|
|
@@ -73,15 +78,20 @@ public class CourseService {
|
|
|
}
|
|
|
|
|
|
public CourseVO updateCourse(CourseVO courseVO, Long userId) {
|
|
|
- CourseVO originalCourse = this.getCourseById(courseVO.getId());
|
|
|
- if (!courseVO.getTeacher().getId().equals(originalCourse.getTeacher().getId())
|
|
|
- || !userId.equals(originalCourse.getTeacher().getId())) {
|
|
|
+ CourseVO course = this.getCourseById(courseVO.getId());
|
|
|
+ if (!userId.equals(course.getTeacher().getId())) {
|
|
|
throw new CustomErrorException("当前用户无权修改课程");
|
|
|
}
|
|
|
- Course course = courseMapper.courseVOToCourse(courseVO);
|
|
|
- course.setCreatedTime(originalCourse.getCreatedTime());
|
|
|
- course.setState(originalCourse.getState());
|
|
|
- Course result = courseRepository.save(course);
|
|
|
+ course.setName(courseVO.getName());
|
|
|
+ course.setSemester(courseVO.getSemester());
|
|
|
+ course.setImageUrl(courseVO.getImageUrl());
|
|
|
+ course.setDescription(courseVO.getDescription());
|
|
|
+ course.setStartTime(courseVO.getStartTime());
|
|
|
+ course.setEndTime(courseVO.getEndTime());
|
|
|
+ course.setInvitationCode(courseVO.getInvitationCode());
|
|
|
+ course.setMoocUrl(courseVO.getMoocUrl());
|
|
|
+ course.setPrice(courseVO.getPrice());
|
|
|
+ Course result = courseRepository.save(courseMapper.courseVOToCourse(course));
|
|
|
return courseMapper.courseToCourseVO(result);
|
|
|
}
|
|
|
|
|
|
@@ -151,11 +161,16 @@ public class CourseService {
|
|
|
}
|
|
|
CourseVO course = this.getCourseById(courseSelectionKey.getCourseId());
|
|
|
// coder系统选课
|
|
|
- JSONObject coderRes = coderService.chooseCourseByCode(course.getInvitationCode());
|
|
|
- if (!coderRes.containsKey("res")) {
|
|
|
- throw new CustomErrorException("Coder: " + coderRes.get("msg"));
|
|
|
+ if (course.getCoderId() != null) {
|
|
|
+ JSONObject coderRes = coderService.chooseCourseByCode(course.getInvitationCode());
|
|
|
+ if (!coderRes.containsKey("res")) {
|
|
|
+ throw new CustomErrorException("Coder: " + coderRes.get("msg"));
|
|
|
+ }
|
|
|
}
|
|
|
// eval系统选课
|
|
|
+ if (course.getEvalId() != null) {
|
|
|
+ JSONObject evalRes;
|
|
|
+ }
|
|
|
// 门户系统选课
|
|
|
CourseSelection courseSelection = new CourseSelection(courseSelectionKey);
|
|
|
courseSelection.setState(true);
|
|
|
@@ -183,4 +198,9 @@ public class CourseService {
|
|
|
CourseSelection record = courseSelectionRepository.findById(key).orElse(null);
|
|
|
return record != null && record.getState();
|
|
|
}
|
|
|
+
|
|
|
+ public Boolean checkCourseCodeUnique(Long id, String code) {
|
|
|
+ Course course = courseRepository.findCourseByInvitationCode(code).orElse(null);
|
|
|
+ return course == null || course.getId().equals(id);
|
|
|
+ }
|
|
|
}
|