wangwei %!s(int64=6) %!d(string=hai) anos
pai
achega
967abe4e72

+ 1 - 1
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/CourseController.java

@@ -111,7 +111,7 @@ public class CourseController extends ControllerSupport {
 						.subquery(CourseSpeciatlyRelationEntity.class);
 				Root<CourseSpeciatlyRelationEntity> subRoot = subquery
 						.from(CourseSpeciatlyRelationEntity.class);
-				subquery.select(subRoot);
+				subquery.select(subRoot.get("courseId"));
 				Predicate p1 = cb.equal(subRoot.get("specialtyId"), specialtyId);
 				Predicate p2 = cb.equal(subRoot.get("courseId"), root.get("id"));
 				subquery.where(cb.and(p1, p2));

+ 93 - 65
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/CourseSpeciatlyRelationController.java

@@ -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;
 	}
+
 }

+ 11 - 0
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/SpecialtyController.java

@@ -37,7 +37,10 @@ import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
 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.api.controller.bean.SpecialtyDomain;
+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.dao.entity.CourseEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
 import cn.com.qmth.examcloud.core.basic.service.SpecialtyService;
@@ -60,6 +63,12 @@ public class SpecialtyController extends ControllerSupport {
 	@Autowired
 	SpecialtyRepo specialtyRepo;
 
+	@Autowired
+	CourseRepo courseRepo;
+
+	@Autowired
+	CourseSpeciatlyRelationRepo courseSpeciatlyRelationRepo;
+
 	/**
 	 * 方法注释
 	 *
@@ -234,6 +243,8 @@ public class SpecialtyController extends ControllerSupport {
 			}
 			validateRootOrgIsolation(one.getRootOrgId());
 			specialtyRepo.delete(one);
+
+			courseSpeciatlyRelationRepo.deleteBySpecialtyId(specialtyId);
 		}
 	}
 

+ 4 - 1
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/CourseSpeciatlyRelationRepo.java

@@ -7,14 +7,17 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
 import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationPK;
 
 public interface CourseSpeciatlyRelationRepo
 		extends
-			JpaRepository<CourseSpeciatlyRelationEntity, Long>,
+			JpaRepository<CourseSpeciatlyRelationEntity, CourseSpeciatlyRelationPK>,
 			QueryByExampleExecutor<CourseSpeciatlyRelationEntity>,
 			JpaSpecificationExecutor<CourseSpeciatlyRelationEntity> {
 
 	List<CourseSpeciatlyRelationEntity> findBySpecialtyId(Long specialtyId);
 
 	List<CourseSpeciatlyRelationEntity> findByCourseId(Long courseId);
+
+	void deleteBySpecialtyId(Long specialtyId);
 }