|
@@ -1,24 +1,22 @@
|
|
|
package cn.com.qmth.examcloud.core.basic.api.controller;
|
|
|
|
|
|
-import java.util.List;
|
|
|
-
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
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.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
|
|
|
+import cn.com.qmth.examcloud.commons.web.security.bean.User;
|
|
|
import cn.com.qmth.examcloud.commons.web.support.ControllerSupport;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.CourseSpeciatlyRelationRepo;
|
|
|
import cn.com.qmth.examcloud.core.basic.dao.SpecialtyRepo;
|
|
|
-import cn.com.qmth.examcloud.core.basic.service.impl.CourseSpeciatlyRelationServiceImpl;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationEntity;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationPK;
|
|
|
+import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
|
|
|
/**
|
|
@@ -28,11 +26,11 @@ import io.swagger.annotations.ApiOperation;
|
|
|
*/
|
|
|
@Transactional
|
|
|
@RestController
|
|
|
-@RequestMapping("${$rmp.ctr.basic}/CourseSpeciatlyRelation")
|
|
|
+@RequestMapping("${$rmp.ctr.basic}/courseSpeciatlyRelation")
|
|
|
public class CourseSpeciatlyRelationController extends ControllerSupport {
|
|
|
|
|
|
@Autowired
|
|
|
- CourseSpeciatlyRelationServiceImpl courseSpeciatlyService;
|
|
|
+ CourseSpeciatlyRelationRepo courseSpeciatlyRelationRepo;
|
|
|
|
|
|
@Autowired
|
|
|
CourseRepo courseRepo;
|
|
@@ -40,62 +38,92 @@ public class CourseSpeciatlyRelationController extends ControllerSupport {
|
|
|
@Autowired
|
|
|
SpecialtyRepo specialtyRepo;
|
|
|
|
|
|
- /**
|
|
|
- * 根据专业ID查询课程
|
|
|
- *
|
|
|
- * @param speciatlyId
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ApiOperation(value = "根据专业ID取课程", notes = "根据专业ID取课程")
|
|
|
- @GetMapping("/allCourses/{speciatlyId}")
|
|
|
- public ResponseEntity getAllCoursesBySpeciatly(@PathVariable String speciatlyId,
|
|
|
- HttpServletRequest request) {
|
|
|
- // cn.com.qmth.examcloud.commons.web.security.bean.User accessUser =
|
|
|
- // getAccessUser();
|
|
|
- // List<Course> courses =
|
|
|
- // courseSpeciatlyService.getAllCoursesBySpeciatlyId(speciatlyId);
|
|
|
- // // List<Course> list =
|
|
|
- // // courseSpeciatlyService.getCoursesNotInSpeciatly(courses);
|
|
|
- // List<Course> list =
|
|
|
- // courseRepo.findByOrgId(accessUser.getRootOrgId());
|
|
|
- // Map map = new HashMap();
|
|
|
- // map.put("courseList", courses);
|
|
|
- // map.put("courseAllList", list);
|
|
|
- // return new ResponseEntity(map, HttpStatus.OK);
|
|
|
- return null;
|
|
|
- }
|
|
|
+ @ApiOperation(value = "新增关联课程专业")
|
|
|
+ @PostMapping("add")
|
|
|
+ public CourseSpeciatlyRelationEntity add(@RequestParam(required = true) Long courseId,
|
|
|
+ @RequestParam(required = true) Long specialtyId) {
|
|
|
+ User accessUser = getAccessUser();
|
|
|
|
|
|
- @ApiOperation(value = "新增关联课程专业", notes = "新增关联课程专业")
|
|
|
- @PostMapping("/addCourse/{speciallyId}")
|
|
|
- public ResponseEntity addCourseSpeciatly(@RequestBody List<String> list,
|
|
|
- @PathVariable String speciallyId, HttpServletRequest request) {
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
- courseSpeciatlyService.addCourseSpecialty(accessUser.getUserId(), list, speciallyId);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
- }
|
|
|
+ if (null == courseId) {
|
|
|
+ throw new StatusException("B-320001", "courseId is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == specialtyId) {
|
|
|
+ throw new StatusException("B-320002", "specialtyId is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ CourseEntity courseEntity = courseRepo.findOne(courseId);
|
|
|
+ if (null == courseEntity) {
|
|
|
+ throw new StatusException("B-320001", "courseId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ this.validateRootOrgIsolation(courseEntity.getRootOrgId());
|
|
|
+
|
|
|
+ SpecialtyEntity specialtyEntity = specialtyRepo.findOne(specialtyId);
|
|
|
+ if (null == specialtyEntity) {
|
|
|
+ throw new StatusException("B-320001", "specialtyId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ this.validateRootOrgIsolation(specialtyEntity.getRootOrgId());
|
|
|
+
|
|
|
+ CourseSpeciatlyRelationPK pk = new CourseSpeciatlyRelationPK();
|
|
|
+ pk.setCourseId(courseId);
|
|
|
+ pk.setSpecialtyId(specialtyId);
|
|
|
+
|
|
|
+ CourseSpeciatlyRelationEntity one = courseSpeciatlyRelationRepo.findOne(pk);
|
|
|
+ if (null != one) {
|
|
|
+ throw new StatusException("B-320003", "课程专业已关联");
|
|
|
+ }
|
|
|
+
|
|
|
+ one = new CourseSpeciatlyRelationEntity();
|
|
|
+ one.setCourseId(courseId);
|
|
|
+ one.setSpecialtyId(specialtyId);
|
|
|
+ one.setCreator(accessUser.getUserId());
|
|
|
|
|
|
- @ApiOperation(value = "根据课程ID取专业", notes = "根据课程ID取专业")
|
|
|
- @GetMapping("/allSpecialty/{courseId}")
|
|
|
- public ResponseEntity getAllSpeciatly(@PathVariable Long courseId, HttpServletRequest request) {
|
|
|
- // cn.com.qmth.examcloud.commons.web.security.bean.User accessUser =
|
|
|
- // getAccessUser();
|
|
|
- // List<Specialty> specialtys =
|
|
|
- // courseSpeciatlyService.getAllSpecialtyByCourseId(courseId);
|
|
|
- // List<Specialty> list =
|
|
|
- // specialtyRepo.findByOrgId(accessUser.getRootOrgId());
|
|
|
- // Map map = new HashMap();
|
|
|
- // map.put("specialtyList", specialtys);
|
|
|
- // map.put("specialtyAllList", list);
|
|
|
- // return new ResponseEntity(map, HttpStatus.OK);
|
|
|
- return null;
|
|
|
+ CourseSpeciatlyRelationEntity saved = courseSpeciatlyRelationRepo.save(one);
|
|
|
+
|
|
|
+ return saved;
|
|
|
}
|
|
|
|
|
|
- @ApiOperation(value = "新增关联课程专业", notes = "新增关联课程专业")
|
|
|
- @PostMapping("/addSpeciatly/{courseId}")
|
|
|
- public ResponseEntity addSpeciatly(@RequestBody List<String> list, @PathVariable Long courseId,
|
|
|
- HttpServletRequest request) {
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
- courseSpeciatlyService.addCourse(accessUser.getUserId(), list, courseId);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
+ @ApiOperation(value = "删除关联课程专业")
|
|
|
+ @PostMapping("delete")
|
|
|
+ public CourseSpeciatlyRelationEntity delete(@RequestParam(required = true) Long courseId,
|
|
|
+ @RequestParam(required = true) Long specialtyId) {
|
|
|
+
|
|
|
+ if (null == courseId) {
|
|
|
+ throw new StatusException("B-320001", "courseId is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null == specialtyId) {
|
|
|
+ throw new StatusException("B-320002", "specialtyId is null");
|
|
|
+ }
|
|
|
+
|
|
|
+ CourseEntity courseEntity = courseRepo.findOne(courseId);
|
|
|
+ if (null == courseEntity) {
|
|
|
+ throw new StatusException("B-320001", "courseId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ this.validateRootOrgIsolation(courseEntity.getRootOrgId());
|
|
|
+
|
|
|
+ SpecialtyEntity specialtyEntity = specialtyRepo.findOne(specialtyId);
|
|
|
+ if (null == specialtyEntity) {
|
|
|
+ throw new StatusException("B-320001", "specialtyId is wrong");
|
|
|
+ }
|
|
|
+
|
|
|
+ this.validateRootOrgIsolation(specialtyEntity.getRootOrgId());
|
|
|
+
|
|
|
+ CourseSpeciatlyRelationPK pk = new CourseSpeciatlyRelationPK();
|
|
|
+ pk.setCourseId(courseId);
|
|
|
+ pk.setSpecialtyId(specialtyId);
|
|
|
+
|
|
|
+ CourseSpeciatlyRelationEntity one = courseSpeciatlyRelationRepo.findOne(pk);
|
|
|
+ if (null == one) {
|
|
|
+ throw new StatusException("B-320003", "课程专业未关联");
|
|
|
+ }
|
|
|
+
|
|
|
+ courseSpeciatlyRelationRepo.delete(one);
|
|
|
+
|
|
|
+ return one;
|
|
|
}
|
|
|
+
|
|
|
}
|