|
@@ -1,19 +1,34 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.api.provider;
|
|
|
|
|
|
+import java.util.List;
|
|
|
+
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.CourseCloudService;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.bean.CourseBean;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.request.SaveCourseReq;
|
|
|
import cn.com.qmth.examcloud.core.basic.api.response.SaveCourseResp;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.entity.Course;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.Org;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.enums.CourseLevel;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.CourseService;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
+/**
|
|
|
+ * 类注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @date 2018年7月10日
|
|
|
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
|
|
|
+ */
|
|
|
@RestController
|
|
|
@RequestMapping("${$rmp.cloud.basic}" + "course")
|
|
|
public class CourseCloudServiceProvider implements CourseCloudService {
|
|
@@ -21,19 +36,53 @@ public class CourseCloudServiceProvider implements CourseCloudService {
|
|
|
@Autowired
|
|
|
CourseService courseService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ OrgRepo orgRepo;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ CourseRepo courseRepo;
|
|
|
+
|
|
|
@ApiOperation(value = "保存课程")
|
|
|
@PostMapping("saveCourse")
|
|
|
@Override
|
|
|
- public SaveCourseResp saveCourse(SaveCourseReq courseReq) {
|
|
|
- Course course = courseService.findByOrgIdAndCode(courseReq.getRootOrgId(),
|
|
|
- courseReq.getCourseCode());
|
|
|
+ public SaveCourseResp saveCourse(@RequestBody SaveCourseReq courseReq) {
|
|
|
+
|
|
|
+ Long rootOrgId = courseReq.getRootOrgId();
|
|
|
+ if (null == rootOrgId) {
|
|
|
+ throw new StatusException("B-160000", "rootOrgId is null");
|
|
|
+ }
|
|
|
+ Org rootOrg = orgRepo.findOne(rootOrgId);
|
|
|
+ if (null == rootOrg) {
|
|
|
+ throw new StatusException("B-160001", "机构不存在");
|
|
|
+ }
|
|
|
+ if (null != rootOrg.getParentId()) {
|
|
|
+ throw new StatusException("B-160002", "机构错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ String courseName = courseReq.getCourseName();
|
|
|
+ if (StringUtils.isBlank(courseName)) {
|
|
|
+ throw new StatusException("B-160003", "courseName is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ String courseCode = courseReq.getCourseCode();
|
|
|
+ if (StringUtils.isBlank(courseCode)) {
|
|
|
+ throw new StatusException("B-160004", "courseCode is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Course> list = courseRepo.findAllByOrgIdAndCode(rootOrgId, courseCode);
|
|
|
+ if (1 < list.size()) {
|
|
|
+ throw new StatusException("B-160005", "存在课程编码重复的数据. courseCode: " + courseCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ Course course = courseRepo.findByOrgIdAndCode(rootOrgId, courseCode);
|
|
|
if (course == null) {
|
|
|
course = new Course();
|
|
|
+ course.setOrgId(courseReq.getRootOrgId());
|
|
|
+ course.setCode(courseReq.getCourseCode());
|
|
|
}
|
|
|
- course.setOrgId(courseReq.getRootOrgId());
|
|
|
- course.setName(courseReq.getCourseName());
|
|
|
- course.setCode(courseReq.getCourseCode());
|
|
|
- course.setLevel(getCourseLevelByCName(courseReq.getCourseLevel()));
|
|
|
+ course.setName(courseName);
|
|
|
+ CourseLevel courseLevel = CourseLevel.getCourseLevel(courseReq.getCourseLevel());
|
|
|
+ course.setLevel(courseLevel);
|
|
|
|
|
|
Course saved = courseService.save(course);
|
|
|
|
|
@@ -50,20 +99,4 @@ public class CourseCloudServiceProvider implements CourseCloudService {
|
|
|
return resp;
|
|
|
}
|
|
|
|
|
|
- private CourseLevel getCourseLevelByCName(String cname) {
|
|
|
- CourseLevel courseLevel = null;
|
|
|
- for (CourseLevel level : CourseLevel.values()) {
|
|
|
- if (cname.equals(level.getName())) {
|
|
|
- courseLevel = level;
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if (courseLevel == null) {
|
|
|
- return CourseLevel.ALL;
|
|
|
- } else {
|
|
|
- return courseLevel;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
}
|