wangwei 6 năm trước cách đây
mục cha
commit
14daa911ba
23 tập tin đã thay đổi với 825 bổ sung927 xóa
  1. 169 109
      examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/CourseController.java
  2. 22 20
      examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/CourseSpeciatlyController.java
  3. 69 114
      examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/SpecialtyController.java
  4. 30 37
      examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/CourseCloudServiceProvider.java
  5. 8 12
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/CourseRepo.java
  6. 20 0
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/CourseSpeciatlyRelationRepo.java
  7. 0 16
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/CourseSpeciatlyRepo.java
  8. 10 6
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/SpecialtyRepo.java
  9. 21 31
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/CourseEntity.java
  10. 0 95
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/CourseSpeciatly.java
  11. 56 0
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/CourseSpeciatlyRelationEntity.java
  12. 36 0
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/CourseSpeciatlyRelationPK.java
  13. 0 117
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/Specialty.java
  14. 81 0
      examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/SpecialtyEntity.java
  15. 2 2
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/CourseAssembler.java
  16. 82 0
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/CourseInfo.java
  17. 2 2
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/SpecialtyDto.java
  18. 0 151
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/CourseService.java
  19. 88 0
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/CourseServiceImpl.java
  20. 28 30
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/CourseSpeciatlyRelationServiceImpl.java
  21. 0 182
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/SpecialtyService.java
  22. 98 0
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/SpecialtyServiceImpl.java
  23. 3 3
      examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/StudentServiceImpl.java

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

@@ -1,6 +1,5 @@
 package cn.com.qmth.examcloud.core.basic.api.controller;
 
-import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.stream.Collectors;
@@ -12,16 +11,14 @@ import javax.persistence.criteria.Subquery;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.domain.Page;
 import org.springframework.data.domain.PageRequest;
 import org.springframework.data.domain.Sort;
 import org.springframework.data.domain.Sort.Direction;
 import org.springframework.data.jpa.domain.Specification;
-import org.springframework.http.HttpStatus;
-import org.springframework.http.ResponseEntity;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.StringUtils;
 import org.springframework.web.bind.annotation.DeleteMapping;
 import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
@@ -36,6 +33,7 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile;
 
 import com.google.common.collect.Lists;
 
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 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;
@@ -44,11 +42,11 @@ 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.entity.Course;
-import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatly;
+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.service.bean.CourseAssembler;
 import cn.com.qmth.examcloud.core.basic.service.bean.CourseDto;
-import cn.com.qmth.examcloud.core.basic.service.impl.CourseService;
+import cn.com.qmth.examcloud.core.basic.service.impl.CourseServiceImpl;
 import cn.com.qmth.examcloud.core.basic.service.impl.ExportService;
 import io.swagger.annotations.ApiOperation;
 
@@ -64,7 +62,7 @@ public class CourseController extends ControllerSupport {
 	CourseRepo courseRepo;
 
 	@Autowired
-	CourseService courseService;
+	CourseServiceImpl courseService;
 
 	@Autowired
 	CourseAssembler courseAssembler;
@@ -76,119 +74,166 @@ public class CourseController extends ControllerSupport {
 	 * 方法注释
 	 *
 	 * @author WANGWEI
-	 * @param courseCriteria
-	 * @param specialtyId
 	 * @param curPage
 	 * @param pageSize
-	 * @param request
+	 * @param name
+	 * @param code
+	 * @param level
+	 * @param enable
+	 * @param specialtyId
 	 * @return
 	 */
-	@ApiOperation(value = "查询课程分页带查询", notes = "分页带查询")
-	@GetMapping("/all/{curPage}/{pageSize}")
-	public Page<Course> getCourseList(@ModelAttribute Course courseCriteria,
-			@RequestParam(required = false) Long specialtyId, @PathVariable Integer curPage,
-			@PathVariable Integer pageSize, HttpServletRequest request) {
+	@ApiOperation(value = "分页查询课程")
+	@GetMapping("coursePage/{curPage}/{pageSize}")
+	public Page<CourseEntity> getCoursePage(@PathVariable Integer curPage, @PathVariable Integer pageSize,
+			@RequestParam(required = false) String name,
+			@RequestParam(required = false) String code,
+			@RequestParam(required = false) String level,
+			@RequestParam(required = false) Boolean enable,
+			@RequestParam(required = false) Long specialtyId) {
+
 		User accessUser = getAccessUser();
 
-		Specification<Course> specification = (root, query, cb) -> {
+		Specification<CourseEntity> specification = (root, query, cb) -> {
 			List<Predicate> predicates = new ArrayList<>();
 
-			predicates.add(cb.equal(root.get("orgId"), accessUser.getRootOrgId()));
+			predicates.add(cb.equal(root.get("rootOrgId"), accessUser.getRootOrgId()));
 
-			if (!StringUtils.isEmpty(courseCriteria.getName())) {
-				predicates.add(cb.like(root.get("name"), "%" + courseCriteria.getName() + "%"));
+			if (StringUtils.isNotBlank(name)) {
+				predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
 			}
-			if (!StringUtils.isEmpty(courseCriteria.getCode())) {
-				predicates.add(cb.like(root.get("code"), "%" + courseCriteria.getCode() + "%"));
+			if (StringUtils.isNotBlank(code)) {
+				predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
 			}
-			if (!StringUtils.isEmpty(courseCriteria.getLevel())) {
-				predicates.add(cb.equal(root.get("level"), courseCriteria.getLevel()));
+			if (StringUtils.isNotBlank(level)) {
+				predicates.add(cb.equal(root.get("level"), toSqlSearchPattern(level)));
 			}
-			if (!StringUtils.isEmpty(courseCriteria.getEnable())) {
-				predicates.add(cb.equal(root.get("enable"), courseCriteria.getEnable()));
+			if (null != enable) {
+				predicates.add(cb.equal(root.get("enable"), enable));
 			}
-			if (specialtyId != null) {
-				Subquery<CourseSpeciatly> subquery = query.subquery(CourseSpeciatly.class);
-				Root<CourseSpeciatly> subRoot = subquery.from(CourseSpeciatly.class);
+
+			if (null != specialtyId) {
+				Subquery<CourseSpeciatlyRelationEntity> subquery = query.subquery(CourseSpeciatlyRelationEntity.class);
+				Root<CourseSpeciatlyRelationEntity> subRoot = subquery.from(CourseSpeciatlyRelationEntity.class);
 				subquery.select(subRoot);
 				Predicate p1 = cb.equal(subRoot.get("specialtyId"), specialtyId);
 				Predicate p2 = cb.equal(subRoot.get("courseId"), root.get("id"));
 				subquery.where(cb.and(p1, p2));
 				predicates.add(cb.exists(subquery));
 			}
+
 			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
 		};
 
-		PageRequest pageRequest = new PageRequest(curPage - 1, pageSize,
+		PageRequest pageRequest = new PageRequest(curPage, pageSize,
 				new Sort(Direction.DESC, "updateTime"));
 
-		Page<Course> page = courseRepo.findAll(specification, pageRequest);
+		Page<CourseEntity> page = courseRepo.findAll(specification, pageRequest);
 		return page;
 	}
 
-	@ApiOperation(value = "按代码或名称查询课程", notes = "代码或名称查询")
-	@GetMapping("/codeOrName")
-	public ResponseEntity getByCodeName(@RequestParam String codeName, HttpServletRequest request) {
-		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-		if (accessUser != null) {
-			return new ResponseEntity(
-					courseRepo.findByCodeName(accessUser.getRootOrgId(), codeName), HttpStatus.OK);
-		} else {
-			return new ResponseEntity(HttpStatus.NOT_FOUND);
-		}
-	}
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param name
+	 * @param code
+	 * @param level
+	 * @param enable
+	 * @param specialtyId
+	 * @return
+	 */
+	@ApiOperation(value = "查询课程")
+	@GetMapping("queryByNameLike")
+	public List<CourseEntity> queryByNameLike(@RequestParam(required = false) String name,
+			@RequestParam(required = false) String code,
+			@RequestParam(required = false) String level,
+			@RequestParam(required = false) Boolean enable,
+			@RequestParam(required = false) Long specialtyId) {
 
-	@ApiOperation(value = "查询课程不分页带查询", notes = "不分页带查询")
-	@GetMapping("/all")
-	public ResponseEntity getEnableExam(@ModelAttribute Course course, HttpServletRequest request) {
-		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-		if (accessUser != null) {
-			course.setOrgId(accessUser.getRootOrgId());
+		User accessUser = getAccessUser();
+		Long rootOrgId = accessUser.getRootOrgId();
+		// 过载保护
+		int total = courseRepo.countByRootOrgIdAndNameLike(rootOrgId, name);
+		if (total > 1000) {
+			List<CourseEntity> list = Lists.newArrayList();
+			return list;
 		}
-		course.setEnable(true);
-		return new ResponseEntity(courseService.findAll(course), HttpStatus.OK);
-	}
 
-	@ApiOperation(value = "查询课程不分页带查询", notes = "不分页带查询")
-	@GetMapping("/all/both")
-	public ResponseEntity getAllExam(@ModelAttribute Course course, HttpServletRequest request) {
-		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-		if (accessUser != null) {
-			course.setOrgId(accessUser.getRootOrgId());
-		}
-		return new ResponseEntity(courseService.findAll(course), HttpStatus.OK);
+		Specification<CourseEntity> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+
+			predicates.add(cb.equal(root.get("rootOrgId"), rootOrgId));
+
+			if (StringUtils.isNotBlank(name)) {
+				predicates.add(cb.like(root.get("name"), toSqlSearchPattern(name)));
+			}
+			if (StringUtils.isNotBlank(code)) {
+				predicates.add(cb.like(root.get("code"), toSqlSearchPattern(code)));
+			}
+			if (StringUtils.isNotBlank(level)) {
+				predicates.add(cb.equal(root.get("level"), toSqlSearchPattern(level)));
+			}
+			if (null != enable) {
+				predicates.add(cb.equal(root.get("enable"), enable));
+			}
+
+			if (null != specialtyId) {
+				Subquery<CourseSpeciatlyRelationEntity> subquery = query.subquery(CourseSpeciatlyRelationEntity.class);
+				Root<CourseSpeciatlyRelationEntity> subRoot = subquery.from(CourseSpeciatlyRelationEntity.class);
+				subquery.select(subRoot);
+				Predicate p1 = cb.equal(subRoot.get("specialtyId"), specialtyId);
+				Predicate p2 = cb.equal(subRoot.get("courseId"), root.get("id"));
+				subquery.where(cb.and(p1, p2));
+				predicates.add(cb.exists(subquery));
+			}
+
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+
+		List<CourseEntity> list = courseRepo.findAll(specification);
+		return list;
 	}
 
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param id
+	 * @return
+	 */
 	@ApiOperation(value = "按ID查询课程", notes = "ID查询")
-	@GetMapping("/{id}")
-	public ResponseEntity getCourseById(@PathVariable Long id) {
-		return new ResponseEntity(courseRepo.findOne(id), HttpStatus.OK);
-	}
+	@GetMapping("{id}")
+	public CourseEntity getCourseById(@PathVariable Long id) {
+		CourseEntity course = courseRepo.findOne(id);
+		if (null == course) {
+			throw new StatusException("B-540001", "课程不存在");
+		}
 
-	@ApiOperation(value = "按code查询课程", notes = "code查询")
-	@GetMapping()
-	public ResponseEntity getCourseByCode(@RequestParam Long orgId, @RequestParam String code) {
-		return new ResponseEntity(courseRepo.findByOrgIdAndCode(orgId, code), HttpStatus.OK);
+		Long rootOrgId = course.getRootOrgId();
+		validateRootOrgIsolation(rootOrgId);
+		return course;
 	}
 
-	@ApiOperation(value = "按orgId查询课程", notes = "orgId查询")
-	@GetMapping("/org/{orgId}")
-	public ResponseEntity getCourseByOrgId(@PathVariable Long orgId) {
-		return new ResponseEntity(courseRepo.findByOrgId(orgId), HttpStatus.OK);
-	}
+	/**
+	 * 方法注释
+	 *
+	 * @author WANGWEI
+	 * @param rootOrgId
+	 * @param code
+	 * @return
+	 */
+	@ApiOperation(value = "按code查询课程", notes = "code查询")
+	@GetMapping("byCode")
+	public CourseEntity getCourseByCode(@RequestParam Long rootOrgId, @RequestParam String code) {
+		validateRootOrgIsolation(rootOrgId);
 
-	@ApiOperation(value = "批量查询课程", notes = "批量查询课程")
-	@PostMapping("/batchGetCourses")
-	public ResponseEntity<List<Course>> batchGetCourses(@RequestBody String[] funcIds,
-			HttpServletRequest request) {
-		List<Course> list = Lists.newArrayList();
-		for (String id : funcIds) {
-			Course one = courseRepo.findOne(Long.parseLong(id));
-			if (null != one) {
-				list.add(one);
-			}
+		CourseEntity course = courseRepo.findByRootOrgIdAndCode(rootOrgId, code);
+		if (null == course) {
+			throw new StatusException("B-540001", "课程不存在");
 		}
-		return new ResponseEntity<List<Course>>(list, HttpStatus.OK);
+
+		return course;
 	}
 
 	/**
@@ -200,7 +245,7 @@ public class CourseController extends ControllerSupport {
 	 */
 	@ApiOperation(value = "新增课程", notes = "新增")
 	@PostMapping
-	public Long addCourse(@RequestBody Course course) {
+	public Long addCourse(@RequestBody CourseEntity course) {
 		trim(course);
 		User accessUser = getAccessUser();
 
@@ -225,7 +270,7 @@ public class CourseController extends ControllerSupport {
 	 */
 	@ApiOperation(value = "更新课程", notes = "更新")
 	@PutMapping
-	public Long updateCourse(@RequestBody Course course, HttpServletRequest request) {
+	public Long updateCourse(@RequestBody CourseEntity course, HttpServletRequest request) {
 		User accessUser = getAccessUser();
 
 		SaveCourseReq saveCourseReq = new SaveCourseReq();
@@ -242,34 +287,37 @@ public class CourseController extends ControllerSupport {
 		return courseBean.getId();
 	}
 
-	@ApiOperation(value = "按ID删除课程", notes = "删除")
-	@DeleteMapping("/{ids}")
-	public ResponseEntity deleteCourse(@PathVariable String ids) {
-		courseService.delete(ids);
-		return new ResponseEntity(HttpStatus.OK);
+	@ApiOperation(value = "删除课程", notes = "删除")
+	@DeleteMapping("{ids}")
+	public void deleteCourse(@PathVariable String ids) {
+		List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+				.collect(Collectors.toList());
+		for (Long courseId : courseIds) {
+			CourseEntity one = courseRepo.findOne(courseId);
+			if (null == one) {
+				continue;
+			}
+			validateRootOrgIsolation(one.getRootOrgId());
+			courseRepo.delete(one);
+		}
+	}
+
+	@ApiOperation(value = "下载导入模板", notes = "下载导入模板")
+	@GetMapping("importTemplate")
+	public void getImportTemplate(HttpServletResponse response) {
+
 	}
 
 	@ApiOperation(value = "导入课程", notes = "导入")
 	@PostMapping("/import")
 	public List<ExcelError> importCourse(HttpServletRequest request,
-			@RequestParam CommonsMultipartFile file) throws IOException {
-		User accessUser = getAccessUser();
-		Long rootOrgId = accessUser.getRootOrgId();
-		List<ExcelError> errors = courseService.importCourse(rootOrgId, file.getInputStream());
-		return errors;
-	}
-
-	@ApiOperation(value = "下载导入模板", notes = "下载导入模板")
-	@GetMapping("/download")
-	public void importFileTemplate(HttpServletResponse response) {
-		List<CourseDto> list = new ArrayList<CourseDto>();
-		list.add(new CourseDto("大学英语", "000001", "0"));
-		ExportService.exportEXCEL("课程导入模板", CourseDto.class, list, response);
+			@RequestParam CommonsMultipartFile file) {
+		return null;
 	}
 
 	@ApiOperation(value = "导出课程", notes = "导出")
-	@GetMapping("/export")
-	public void exportCourse(@ModelAttribute Course orgCriteria, HttpServletResponse response) {
+	@GetMapping("export")
+	public void exportCourse(@ModelAttribute CourseEntity orgCriteria, HttpServletResponse response) {
 		List<CourseDto> list = new ArrayList<CourseDto>();
 		courseService.findAll(orgCriteria).forEach(c -> {
 			list.add(courseAssembler.toDTO(c));
@@ -285,11 +333,17 @@ public class CourseController extends ControllerSupport {
 	 * @return
 	 */
 	@ApiOperation(value = "禁用课程", notes = "禁用")
-	@PutMapping("/disable/{ids}")
+	@PutMapping("disable/{ids}")
 	public List<Long> disableCourse(@PathVariable String ids) {
 		List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
-		courseService.setCourseEnable(courseIds, false);
+
+		for (Long courseId : courseIds) {
+			CourseEntity course = courseRepo.findOne(courseId);
+			course.setEnable(false);
+			courseRepo.save(course);
+		}
+
 		return courseIds;
 	}
 
@@ -301,11 +355,17 @@ public class CourseController extends ControllerSupport {
 	 * @return
 	 */
 	@ApiOperation(value = "启用课程", notes = "启用")
-	@PutMapping("/enable/{ids}")
+	@PutMapping("enable/{ids}")
 	public List<Long> enableCourse(@PathVariable String ids) {
 		List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
 				.collect(Collectors.toList());
-		courseService.setCourseEnable(courseIds, true);
+
+		for (Long courseId : courseIds) {
+			CourseEntity course = courseRepo.findOne(courseId);
+			course.setEnable(true);
+			courseRepo.save(course);
+		}
+
 		return courseIds;
 	}
 }

+ 22 - 20
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/controller/CourseSpeciatlyController.java

@@ -20,9 +20,9 @@ import org.springframework.web.bind.annotation.RestController;
 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.SpecialtyRepo;
-import cn.com.qmth.examcloud.core.basic.dao.entity.Course;
-import cn.com.qmth.examcloud.core.basic.dao.entity.Specialty;
-import cn.com.qmth.examcloud.core.basic.service.impl.CourseSpeciatlyService;
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
+import cn.com.qmth.examcloud.core.basic.service.impl.CourseSpeciatlyRelationServiceImpl;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -36,7 +36,7 @@ import io.swagger.annotations.ApiOperation;
 public class CourseSpeciatlyController extends ControllerSupport {
 
 	@Autowired
-	CourseSpeciatlyService courseSpeciatlyService;
+	CourseSpeciatlyRelationServiceImpl courseSpeciatlyService;
 
 	@Autowired
 	CourseRepo courseRepo;
@@ -54,15 +54,16 @@ public class CourseSpeciatlyController extends ControllerSupport {
 	@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);
+//		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 = "新增关联课程专业", notes = "新增关联课程专业")
@@ -77,13 +78,14 @@ public class CourseSpeciatlyController extends ControllerSupport {
 	@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);
+//		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;
 	}
 
 	@ApiOperation(value = "新增关联课程专业", notes = "新增关联课程专业")

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

@@ -2,15 +2,14 @@ package cn.com.qmth.examcloud.core.basic.api.controller;
 
 import java.io.IOException;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
 import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.PageRequest;
-import org.springframework.http.HttpStatus;
 import org.springframework.http.ResponseEntity;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.bind.annotation.DeleteMapping;
@@ -18,21 +17,19 @@ import org.springframework.web.bind.annotation.GetMapping;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.PutMapping;
-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 org.springframework.web.multipart.commons.CommonsMultipartFile;
 
+import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 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.dao.SpecialtyRepo;
-import cn.com.qmth.examcloud.core.basic.dao.entity.Specialty;
+import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
 import cn.com.qmth.examcloud.core.basic.service.bean.SpecialtyDto;
 import cn.com.qmth.examcloud.core.basic.service.impl.ExportService;
-import cn.com.qmth.examcloud.core.basic.service.impl.SpecialtyService;
+import cn.com.qmth.examcloud.core.basic.service.impl.SpecialtyServiceImpl;
 import io.swagger.annotations.ApiOperation;
 
 /**
@@ -46,133 +43,90 @@ import io.swagger.annotations.ApiOperation;
 public class SpecialtyController extends ControllerSupport {
 
 	@Autowired
-	SpecialtyService specialtyService;
+	SpecialtyServiceImpl specialtyService;
 
 	@Autowired
 	SpecialtyRepo specialtyRepo;
 
-	/**
-	 * 带分页查询
-	 * 
-	 * @param specialty
-	 * @param curPage
-	 * @param pageSize
-	 * @param request
-	 * @return
-	 */
-	@ApiOperation(value = "查询专业带分页", notes = "查询专业带分页")
-	@GetMapping("/all/{curPage}/{pageSize}")
-	public ResponseEntity getAllOrg(@ModelAttribute Specialty specialty,
+	@ApiOperation(value = "分页查询专业")
+	@GetMapping("specialtyPage/{curPage}/{pageSize}")
+	public ResponseEntity getSpecialtyPage(@ModelAttribute SpecialtyEntity specialty,
 			@RequestParam(required = false) Long courseId, @PathVariable Integer curPage,
 			@PathVariable Integer pageSize, HttpServletRequest request) {
-		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-		if (accessUser != null) {
-			specialty.setOrgId(accessUser.getRootOrgId());
-		} else {
-			return new ResponseEntity(HttpStatus.NOT_FOUND);
-		}
-		return new ResponseEntity(specialtyService.findAll(specialty, courseId,
-				new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
+		// cn.com.qmth.examcloud.commons.web.security.bean.User accessUser =
+		// getAccessUser();
+		// if (accessUser != null) {
+		// specialty.setOrgId(accessUser.getRootOrgId());
+		// } else {
+		// return new ResponseEntity(HttpStatus.NOT_FOUND);
+		// }
+		// return new ResponseEntity(specialtyService.findAll(specialty,
+		// courseId,
+		// new PageRequest(curPage - 1, pageSize)), HttpStatus.OK);
+		return null;
 	}
 
 	/**
-	 * 按code查询专业
-	 * 
+	 * 方法注释
+	 *
+	 * @author WANGWEI
 	 * @param orgId
 	 * @param code
 	 * @return
 	 */
-	@ApiOperation(value = "按code查询专业", notes = "按code查询专业")
-	@GetMapping
-	public ResponseEntity getAll(@RequestParam Long orgId, @RequestParam String code) {
-		return new ResponseEntity(specialtyRepo.findByOrgIdAndCode(orgId, code), HttpStatus.OK);
-	}
-
-	/**
-	 * 查询专业不带分页
-	 * 
-	 * @param specialty
-	 * @param request
-	 * @return
-	 */
-	@ApiOperation(value = "查询专业不带分页", notes = "查询专业不带分页")
-	@GetMapping("/all")
-	public ResponseEntity getAll(@ModelAttribute Specialty specialty, HttpServletRequest request) {
-		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-		if (accessUser != null) {
-			specialty.setOrgId(accessUser.getRootOrgId());
+	@ApiOperation(value = "查询专业")
+	@GetMapping("byCode")
+	public SpecialtyEntity getByCode(@RequestParam Long orgId, @RequestParam String code) {
+		SpecialtyEntity specialty = specialtyRepo.findByRootOrgIdAndCode(orgId, code);
+		if (null == specialty) {
+			throw new StatusException("B-620002", "专业不存在");
 		}
-		specialty.setEnable(true);
-		return new ResponseEntity(specialtyService.findAll(specialty), HttpStatus.OK);
+		validateRootOrgIsolation(specialty.getRootOrgId());
+		return specialty;
 	}
 
 	/**
-	 * 新增专业
-	 * 
-	 * @param specialty
-	 * @param request
-	 * @return
-	 */
-	@ApiOperation(value = "新增专业", notes = "新增专业")
-	@PostMapping("/addSpecialty")
-	public void addSpecialty(@RequestBody Specialty specialty, HttpServletRequest request) {
-		specialty.setCreateTime(new Date());
-		User accessUser = getAccessUser();
-		specialty.setOrgId(accessUser.getRootOrgId());
-		specialtyService.save(specialty);
-	}
-
-	/**
-	 * 更新专业
-	 * 
-	 * @param specialty
-	 * @param request
-	 * @return
-	 */
-	@ApiOperation(value = "更新专业", notes = "更新专业")
-	@PutMapping("/updateSpecialty")
-	public void updateSpecialty(@RequestBody Specialty specialty, HttpServletRequest request) {
-		User accessUser = getAccessUser();
-		specialty.setOrgId(accessUser.getRootOrgId());
-		specialtyService.updateSpecialty(specialty);
-	}
-
-	/**
-	 * 根据ID删除专业
-	 * 
+	 * 方法注释
+	 *
+	 * @author WANGWEI
 	 * @param ids
-	 * @return
 	 */
-	@ApiOperation(value = "根据ID删除专业", notes = "根据ID删除专业")
-	@DeleteMapping("/{ids}")
-	public ResponseEntity deleteSpecialtyIds(@PathVariable String ids) {
-		specialtyService.deleteSpecialty(ids);
-		return new ResponseEntity(HttpStatus.OK);
-	}
-
-	@ApiOperation(value = "根据ID删除专业", notes = "根据ID删除专业")
-	@DeleteMapping("/delete/{id}")
-	public ResponseEntity deleteSpecialtyId(@PathVariable String id) {
-		specialtyRepo.delete(Long.parseLong(id));
-		return new ResponseEntity(HttpStatus.OK);
+	@ApiOperation(value = "删除专业")
+	@DeleteMapping("{ids}")
+	public void delete(@PathVariable String ids) {
+		List<Long> specialtyIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+				.collect(Collectors.toList());
+		for (Long specialtyId : specialtyIds) {
+			SpecialtyEntity one = specialtyRepo.findOne(specialtyId);
+			if (null == one) {
+				continue;
+			}
+			validateRootOrgIsolation(one.getRootOrgId());
+			specialtyRepo.delete(one);
+		}
 	}
 
 	@ApiOperation(value = "下载导入模板", notes = "下载导入模板")
-	@GetMapping("/download")
-	public void importFileTemplate(HttpServletResponse response) {
-		List<SpecialtyDto> list = new ArrayList<SpecialtyDto>();
-		ExportService.exportEXCEL("专业导入模板", SpecialtyDto.class, list, response);
+	@GetMapping("downloadTemplate")
+	public void getDownloadTemplate(HttpServletResponse response) {
+		// List<SpecialtyDto> list = new ArrayList<SpecialtyDto>();
+		// ExportService.exportEXCEL("专业导入模板", SpecialtyDto.class, list,
+		// response);
+
 	}
 
 	@ApiOperation(value = "导入", notes = "导入")
 	@PostMapping("/import")
 	public List<ExcelError> importCourse(HttpServletRequest request,
 			@RequestParam CommonsMultipartFile file) throws IOException {
-		cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
-		Long orgId = accessUser.getRootOrgId();
-
-		List<ExcelError> errors = specialtyService.importSpecialty(orgId, file.getInputStream());
-		return errors;
+		// cn.com.qmth.examcloud.commons.web.security.bean.User accessUser =
+		// getAccessUser();
+		// Long orgId = accessUser.getRootOrgId();
+		//
+		// List<ExcelError> errors = specialtyService.importSpecialty(orgId,
+		// file.getInputStream());
+		// return errors;
+		return null;
 	}
 
 	/**
@@ -182,12 +136,13 @@ public class SpecialtyController extends ControllerSupport {
 	 * @param response
 	 */
 	@ApiOperation(value = "导出专业", notes = "导出专业")
-	@GetMapping("/export")
-	public void exportSpecialty(@ModelAttribute Specialty specialty, HttpServletResponse response) {
-		List<SpecialtyDto> list = new ArrayList<SpecialtyDto>();
-		specialtyService.findAll(specialty).forEach(c -> {
-			list.add(new SpecialtyDto(c));
-		});
-		ExportService.exportEXCEL("专业列表", SpecialtyDto.class, list, response);
+	@GetMapping("export")
+	public void exportSpecialty(@ModelAttribute SpecialtyEntity specialty, HttpServletResponse response) {
+		// List<SpecialtyDto> list = new ArrayList<SpecialtyDto>();
+		// specialtyService.findAll(specialty).forEach(c -> {
+		// list.add(new SpecialtyDto(c));
+		// });
+		// ExportService.exportEXCEL("专业列表", SpecialtyDto.class, list,
+		// response);
 	}
 }

+ 30 - 37
examcloud-core-basic-api-provider/src/main/java/cn/com/qmth/examcloud/core/basic/api/provider/CourseCloudServiceProvider.java

@@ -1,8 +1,5 @@
 package cn.com.qmth.examcloud.core.basic.api.provider;
 
-import java.util.Date;
-import java.util.List;
-
 import org.apache.commons.lang3.StringUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
@@ -20,7 +17,7 @@ import cn.com.qmth.examcloud.core.basic.api.response.GetCourseResp;
 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.CourseEntity;
 import cn.com.qmth.examcloud.core.basic.dao.entity.OrgEntity;
 import cn.com.qmth.examcloud.core.basic.dao.enums.CourseLevel;
 import io.swagger.annotations.ApiOperation;
@@ -62,9 +59,11 @@ public class CourseCloudServiceProvider implements CourseCloudService {
 			throw new StatusException("B-160002", "机构错误");
 		}
 
-		Course course = null;
+		CourseEntity course = null;
 
 		Long courseId = courseReq.getCourseId();
+		String courseCode = courseReq.getCourseCode();
+
 		if (null != courseId) {
 			course = courseRepo.findOne(courseId);
 
@@ -72,42 +71,30 @@ public class CourseCloudServiceProvider implements CourseCloudService {
 				throw new StatusException("B-160006", "课程ID错误");
 			}
 
-			Long orgId = course.getOrgId();
-
-			if (!rootOrgId.equals(orgId)) {
+			if (!rootOrgId.equals(course.getRootOrgId())) {
 				throw new StatusException("B-160006", "课程机构错误");
 			}
 
-		} else {
-			String courseName = courseReq.getCourseName();
-			if (StringUtils.isBlank(courseName)) {
-				throw new StatusException("B-160003", "courseName is null");
-			}
+		} else if (StringUtils.isBlank(courseCode)) {
 
-			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);
-			} else if (1 == list.size()) {
-				course = list.get(0);
+			course = courseRepo.findByRootOrgIdAndCode(rootOrgId, courseCode);
+			if (null != course) {
 				if (null == course.getEnable()) {
 					course.setEnable(true);
 				}
 				if (null == course.getLevel()) {
 					course.setLevel(CourseLevel.ALL);
 				}
-
 			} else {
-				course = new Course();
-				course.setOrgId(courseReq.getRootOrgId());
+				course = new CourseEntity();
+				course.setRootOrgId(courseReq.getRootOrgId());
 				course.setCode(courseReq.getCourseCode());
 				course.setEnable(true);
 				course.setLevel(CourseLevel.ALL);
 			}
+
+		} else {
+			throw new StatusException("B-160004", "courseId,courseCode can not be all null");
 		}
 
 		if (null != courseReq.getEnable()) {
@@ -124,15 +111,13 @@ public class CourseCloudServiceProvider implements CourseCloudService {
 		}
 
 		long updateTime = 0L;
-		if (null == course.getCreationTime()) {
-			course.setCreationTime(new Date());
-		}
 		if (null != course.getUpdateTime()) {
 			updateTime = course.getUpdateTime().getTime();
-		} else {
-			course.setUpdateTime(new Date());
 		}
-		Course saved = courseRepo.saveAndFlush(course);
+
+		CourseEntity saved = courseRepo.saveAndFlush(course);
+
+		// 同步操作
 		if (updateTime != saved.getUpdateTime().getTime()) {
 
 		}
@@ -143,7 +128,7 @@ public class CourseCloudServiceProvider implements CourseCloudService {
 		courseBean.setCode(saved.getCode());
 		courseBean.setLevel(saved.getLevel().name());
 		courseBean.setName(saved.getName());
-		courseBean.setRootOrgId(saved.getOrgId());
+		courseBean.setRootOrgId(saved.getRootOrgId());
 
 		resp.setCourseBean(courseBean);
 
@@ -162,14 +147,22 @@ public class CourseCloudServiceProvider implements CourseCloudService {
 		if (null == rootOrgId) {
 			throw new StatusException("B-160000", "rootOrgId is null");
 		}
-		Course c = null;
+		OrgEntity rootOrg = orgRepo.findOne(rootOrgId);
+		if (null == rootOrg) {
+			throw new StatusException("B-160001", "机构不存在");
+		}
+		if (null != rootOrg.getParentId()) {
+			throw new StatusException("B-160002", "机构错误");
+		}
+
+		CourseEntity c = null;
 		if (null != id) {
 			c = courseRepo.findOne(id);
 
 		} else if (StringUtils.isNotBlank(code)) {
-			c = courseRepo.findByOrgIdAndCode(rootOrgId, code);
+			c = courseRepo.findByRootOrgIdAndCode(rootOrgId, code);
 		} else {
-			throw new StatusException("B-160002", "code is blank");
+			throw new StatusException("B-160002", "id,code can not be all null");
 		}
 
 		if (null == c) {
@@ -181,7 +174,7 @@ public class CourseCloudServiceProvider implements CourseCloudService {
 		courseBean.setCode(c.getCode());
 		courseBean.setLevel(c.getLevel().name());
 		courseBean.setName(c.getName());
-		courseBean.setRootOrgId(c.getOrgId());
+		courseBean.setRootOrgId(c.getRootOrgId());
 		courseBean.setEnable(c.getEnable());
 		resp.setCourseBean(courseBean);
 

+ 8 - 12
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/CourseRepo.java

@@ -4,26 +4,22 @@ import java.util.List;
 
 import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
-import org.springframework.data.jpa.repository.Query;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
-import cn.com.qmth.examcloud.core.basic.dao.entity.Course;
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseEntity;
 
 public interface CourseRepo
 		extends
-			JpaRepository<Course, Long>,
-			QueryByExampleExecutor<Course>,
-			JpaSpecificationExecutor<Course> {
+			JpaRepository<CourseEntity, Long>,
+			QueryByExampleExecutor<CourseEntity>,
+			JpaSpecificationExecutor<CourseEntity> {
 
-	List<Course> findByOrgId(Long orgId);
+	List<CourseEntity> findByRootOrgId(Long rootOrgId);
 
-	List<Course> findAllByOrgIdAndCode(Long orgId, String code);
+	CourseEntity findByRootOrgIdAndCode(Long rootOrgId, String code);
 
-	Course findByOrgIdAndCode(Long orgId, String code);
+	List<CourseEntity> findByIdNotIn(List<Long> ids);
 
-	List<Course> findByIdNotIn(List<Long> ids);
-
-	@Query("select t from Course t where t.orgId = ?1 and (t.code like %?2% or t.name like %?2%) and t.enable = true")
-	List<Course> findByCodeName(Long orgId, String codeName);
+	int countByRootOrgIdAndNameLike(Long rootOrgId, String name);
 
 }

+ 20 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/CourseSpeciatlyRelationRepo.java

@@ -0,0 +1,20 @@
+package cn.com.qmth.examcloud.core.basic.dao;
+
+import java.util.List;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.repository.query.QueryByExampleExecutor;
+
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationEntity;
+
+public interface CourseSpeciatlyRelationRepo
+		extends
+			JpaRepository<CourseSpeciatlyRelationEntity, Long>,
+			QueryByExampleExecutor<CourseSpeciatlyRelationEntity>,
+			JpaSpecificationExecutor<CourseSpeciatlyRelationEntity> {
+
+	List<CourseSpeciatlyRelationEntity> findBySpecialtyId(Long specialtyId);
+
+	List<CourseSpeciatlyRelationEntity> findByCourseId(Long courseId);
+}

+ 0 - 16
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/CourseSpeciatlyRepo.java

@@ -1,16 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.dao;
-
-import java.util.List;
-
-import org.springframework.data.jpa.repository.JpaRepository;
-import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
-import org.springframework.data.repository.query.QueryByExampleExecutor;
-
-import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatly;
-
-public interface CourseSpeciatlyRepo extends JpaRepository<CourseSpeciatly, Long>,QueryByExampleExecutor<CourseSpeciatly>,JpaSpecificationExecutor<CourseSpeciatly>{
-
-	List<CourseSpeciatly> findBySpecialtyId(Long specialtyId);
-
-	List<CourseSpeciatly> findByCourseId(Long courseId);
-}

+ 10 - 6
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/SpecialtyRepo.java

@@ -6,11 +6,15 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.repository.query.QueryByExampleExecutor;
 
-import cn.com.qmth.examcloud.core.basic.dao.entity.Specialty;
+import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
 
-public interface SpecialtyRepo extends JpaRepository<Specialty, Long>,QueryByExampleExecutor<Specialty>,JpaSpecificationExecutor<Specialty>{
-     
-	Specialty findByOrgIdAndCode(Long orgId,String code);
-	
-	List<Specialty> findByOrgId(Long orgId);
+public interface SpecialtyRepo
+		extends
+			JpaRepository<SpecialtyEntity, Long>,
+			QueryByExampleExecutor<SpecialtyEntity>,
+			JpaSpecificationExecutor<SpecialtyEntity> {
+
+	SpecialtyEntity findByRootOrgIdAndCode(Long rootOrgId, String code);
+
+	List<SpecialtyEntity> findByRootOrgId(Long rootOrgId);
 }

+ 21 - 31
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/Course.java → examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/CourseEntity.java

@@ -1,14 +1,14 @@
 package cn.com.qmth.examcloud.core.basic.dao.entity;
 
+import javax.persistence.Column;
 import javax.persistence.Entity;
 import javax.persistence.EnumType;
 import javax.persistence.Enumerated;
 import javax.persistence.GeneratedValue;
 import javax.persistence.Id;
+import javax.persistence.Index;
 import javax.persistence.Table;
-import javax.validation.constraints.NotNull;
 
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelProperty;
 import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
 import cn.com.qmth.examcloud.core.basic.dao.enums.CourseLevel;
 
@@ -19,8 +19,10 @@ import cn.com.qmth.examcloud.core.basic.dao.enums.CourseLevel;
  * @date 2017年1月5日
  */
 @Entity
-@Table(name = "ecs_core_course")
-public class Course extends JpaEntity {
+@Table(name = "EC_B_COURSE", indexes = {
+		@Index(name = "IDX_B_COURSE_002001", columnList = "rootOrgId,code", unique = true),
+		@Index(name = "IDX_B_COURSE_002002", columnList = "rootOrgId,name", unique = false)})
+public class CourseEntity extends JpaEntity {
 
 	private static final long serialVersionUID = -6261302618070108336L;
 
@@ -28,34 +30,22 @@ public class Course extends JpaEntity {
 	@GeneratedValue
 	private Long id;
 
-	@ExcelProperty(index = 1)
-	@NotNull
+	@Column(nullable = false)
+	private Long rootOrgId;
+
+	@Column(nullable = false)
 	private String code;
 
-	@ExcelProperty(index = 0)
-	@NotNull
+	@Column(nullable = false)
 	private String name;
 
-	/**
-	 * 顶级机构ID
-	 */
-	@NotNull
-	private Long orgId;
-
+	@Column(nullable = false)
 	@Enumerated(EnumType.STRING)
 	private CourseLevel level;
 
+	@Column(nullable = false)
 	private Boolean enable;
 
-	public Course() {
-	}
-
-	public Course(String name, String code) {
-		this.name = name;
-		this.code = code;
-		this.enable = true;
-	}
-
 	public Long getId() {
 		return id;
 	}
@@ -64,6 +54,14 @@ public class Course extends JpaEntity {
 		this.id = id;
 	}
 
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
 	public String getCode() {
 		return code;
 	}
@@ -80,14 +78,6 @@ public class Course extends JpaEntity {
 		this.name = name;
 	}
 
-	public Long getOrgId() {
-		return orgId;
-	}
-
-	public void setOrgId(Long orgId) {
-		this.orgId = orgId;
-	}
-
 	public CourseLevel getLevel() {
 		return level;
 	}

+ 0 - 95
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/CourseSpeciatly.java

@@ -1,95 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.dao.entity;
-
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.validation.constraints.NotNull;
-
-import org.springframework.format.annotation.DateTimeFormat;
-
-/**
- * @Description 专业课程关联
- * @author Administrator
- * @date 2017年8月8号
- */
-@Entity
-@Table(name = "ecs_core_course_specialty")
-public class CourseSpeciatly implements Serializable{
-
-	private static final long serialVersionUID = -250814769612993025L;
-	
-	@Id
-	@GeneratedValue
-	private Long id;
-	
-	@NotNull
-	private Long courseId;
-	
-	@NotNull
-	private Long specialtyId;
-	
-	@NotNull
-	private Long creator;
-	
-	@DateTimeFormat
-	private Date createTime;
-
-	@DateTimeFormat
-	private Date updateTime;
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
-	public Long getCourseId() {
-		return courseId;
-	}
-
-	public void setCourseId(Long courseId) {
-		this.courseId = courseId;
-	}
-
-	public Long getSpecialtyId() {
-		return specialtyId;
-	}
-
-	public void setSpecialtyId(Long specialtyId) {
-		this.specialtyId = specialtyId;
-	}
-
-	public Date getCreateTime() {
-		return createTime;
-	}
-
-	public void setCreateTime(Date createTime) {
-		this.createTime = createTime;
-	}
-
-	public Date getUpdateTime() {
-		return updateTime;
-	}
-
-	public Long getCreator() {
-		return creator;
-	}
-
-	public void setCreator(Long creator) {
-		this.creator = creator;
-	}
-
-	public void setUpdateTime(Date updateTime) {
-		this.updateTime = updateTime;
-	}
-
-	public static long getSerialversionuid() {
-		return serialVersionUID;
-	}
-}

+ 56 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/CourseSpeciatlyRelationEntity.java

@@ -0,0 +1,56 @@
+package cn.com.qmth.examcloud.core.basic.dao.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.IdClass;
+import javax.persistence.Table;
+
+import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
+
+/**
+ * @Description 专业课程关联
+ * @author Administrator
+ * @date 2017年8月8号
+ */
+@Entity
+@Table(name = "EC_B_CS_RELATION")
+@IdClass(CourseSpeciatlyRelationPK.class)
+public class CourseSpeciatlyRelationEntity extends JpaEntity {
+
+	private static final long serialVersionUID = -4747240416438623301L;
+
+	@Id
+	private Long courseId;
+
+	@Id
+	private Long specialtyId;
+
+	@Column(nullable = true)
+	private Long creator;
+
+	public Long getCourseId() {
+		return courseId;
+	}
+
+	public void setCourseId(Long courseId) {
+		this.courseId = courseId;
+	}
+
+	public Long getSpecialtyId() {
+		return specialtyId;
+	}
+
+	public void setSpecialtyId(Long specialtyId) {
+		this.specialtyId = specialtyId;
+	}
+
+	public Long getCreator() {
+		return creator;
+	}
+
+	public void setCreator(Long creator) {
+		this.creator = creator;
+	}
+
+}

+ 36 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/CourseSpeciatlyRelationPK.java

@@ -0,0 +1,36 @@
+package cn.com.qmth.examcloud.core.basic.dao.entity;
+
+import java.io.Serializable;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年8月27日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class CourseSpeciatlyRelationPK implements Serializable {
+
+	private static final long serialVersionUID = 1L;
+
+	private Long courseId;
+
+	private Long specialtyId;
+
+	public Long getCourseId() {
+		return courseId;
+	}
+
+	public void setCourseId(Long courseId) {
+		this.courseId = courseId;
+	}
+
+	public Long getSpecialtyId() {
+		return specialtyId;
+	}
+
+	public void setSpecialtyId(Long specialtyId) {
+		this.specialtyId = specialtyId;
+	}
+
+}

+ 0 - 117
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/Specialty.java

@@ -1,117 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.dao.entity;
-
-import java.io.Serializable;
-import java.util.Date;
-
-import javax.persistence.Entity;
-import javax.persistence.GeneratedValue;
-import javax.persistence.Id;
-import javax.persistence.Table;
-import javax.validation.constraints.NotNull;
-
-import org.springframework.format.annotation.DateTimeFormat;
-
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelProperty;
-
-/**
- * @Description: 专业
- * @author  weiwenhai
- * @date    2017年8月7号
- */
-@Entity
-@Table(name = "ecs_core_specialty")
-public class Specialty implements Serializable{
-
-	private static final long serialVersionUID = 239263456816448160L;
-	
-	@Id
-	@GeneratedValue
-	private Long id;
-	
-	@ExcelProperty(index = 1)
-	@NotNull
-	private String code;
-
-	@ExcelProperty(index = 0)
-	@NotNull
-	private String name;
-	
-	@NotNull
-	private Long orgId;
-	
-	@DateTimeFormat
-	private Date createTime;
-	
-	@DateTimeFormat
-	private Date updateTime;
-	
-	private Boolean enable;
-
-	public Long getId() {
-		return id;
-	}
-
-	public void setId(Long id) {
-		this.id = id;
-	}
-
-	public String getCode() {
-		return code;
-	}
-
-	public void setCode(String code) {
-		this.code = code;
-	}
-
-	public String getName() {
-		return name;
-	}
-
-	public void setName(String name) {
-		this.name = name;
-	}
-
-	public Long getOrgId() {
-		return orgId;
-	}
-
-	public void setOrgId(Long orgId) {
-		this.orgId = orgId;
-	}
-
-	public Date getCreateTime() {
-		return createTime;
-	}
-
-	public void setCreateTime(Date createTime) {
-		this.createTime = createTime;
-	}
-
-	public Date getUpdateTime() {
-		return updateTime;
-	}
-
-	public void setUpdateTime(Date updateTime) {
-		this.updateTime = updateTime;
-	}
-
-	public Boolean getEnable() {
-		return enable;
-	}
-
-	public void setEnable(Boolean enable) {
-		this.enable = enable;
-	}
-
-	public static long getSerialversionuid() {
-		return serialVersionUID;
-	}
-
-	public Specialty(String code, String name) {
-		this.code = code;
-		this.name = name;
-	}
-
-	public Specialty() {
-	}
-}

+ 81 - 0
examcloud-core-basic-dao/src/main/java/cn/com/qmth/examcloud/core/basic/dao/entity/SpecialtyEntity.java

@@ -0,0 +1,81 @@
+package cn.com.qmth.examcloud.core.basic.dao.entity;
+
+import javax.persistence.Column;
+import javax.persistence.Entity;
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+import javax.persistence.Index;
+import javax.persistence.Table;
+
+import cn.com.qmth.examcloud.commons.web.jpa.JpaEntity;
+
+/**
+ * @Description: 专业
+ * @author weiwenhai
+ * @date 2017年8月7号
+ */
+@Entity
+@Table(name = "EC_B_SPECIALTY", indexes = {
+		@Index(name = "IDX_B_SPE_002001", columnList = "rootOrgId,code", unique = true),
+		@Index(name = "IDX_B_SPE_002002", columnList = "rootOrgId,name", unique = false)})
+public class SpecialtyEntity extends JpaEntity {
+
+	private static final long serialVersionUID = 239263456816448160L;
+
+	@Id
+	@GeneratedValue
+	private Long id;
+
+	@Column(nullable = false)
+	private String code;
+
+	@Column(nullable = false)
+	private String name;
+
+	@Column(nullable = false)
+	private Long rootOrgId;
+
+	@Column(nullable = false)
+	private Boolean enable;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
+
+}

+ 2 - 2
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/CourseAssembler.java

@@ -2,12 +2,12 @@ package cn.com.qmth.examcloud.core.basic.service.bean;
 
 import org.springframework.stereotype.Component;
 
-import cn.com.qmth.examcloud.core.basic.dao.entity.Course;
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseEntity;
 
 @Component
 public class CourseAssembler {
 
-	public CourseDto toDTO(Course course) {
+	public CourseDto toDTO(CourseEntity course) {
 		CourseDto dto = null;
 		if (dto == null) {
 			dto = new CourseDto();

+ 82 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/CourseInfo.java

@@ -0,0 +1,82 @@
+package cn.com.qmth.examcloud.core.basic.service.bean;
+
+import javax.persistence.GeneratedValue;
+import javax.persistence.Id;
+
+import cn.com.qmth.examcloud.commons.web.cloud.api.JsonSerializable;
+import cn.com.qmth.examcloud.core.basic.dao.enums.CourseLevel;
+
+/**
+ * 类注释
+ *
+ * @author WANGWEI
+ * @date 2018年8月27日
+ * @Copyright (c) 2018-? http://qmth.com.cn All Rights Reserved.
+ */
+public class CourseInfo implements JsonSerializable {
+
+	private static final long serialVersionUID = -6261302618070108336L;
+
+	@Id
+	@GeneratedValue
+	private Long id;
+
+	private Long rootOrgId;
+
+	private String code;
+
+	private String name;
+
+	private CourseLevel level;
+
+	private Boolean enable;
+
+	public Long getId() {
+		return id;
+	}
+
+	public void setId(Long id) {
+		this.id = id;
+	}
+
+	public Long getRootOrgId() {
+		return rootOrgId;
+	}
+
+	public void setRootOrgId(Long rootOrgId) {
+		this.rootOrgId = rootOrgId;
+	}
+
+	public String getCode() {
+		return code;
+	}
+
+	public void setCode(String code) {
+		this.code = code;
+	}
+
+	public String getName() {
+		return name;
+	}
+
+	public void setName(String name) {
+		this.name = name;
+	}
+
+	public CourseLevel getLevel() {
+		return level;
+	}
+
+	public void setLevel(CourseLevel level) {
+		this.level = level;
+	}
+
+	public Boolean getEnable() {
+		return enable;
+	}
+
+	public void setEnable(Boolean enable) {
+		this.enable = enable;
+	}
+
+}

+ 2 - 2
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/bean/SpecialtyDto.java

@@ -1,7 +1,7 @@
 package cn.com.qmth.examcloud.core.basic.service.bean;
 
 import cn.com.qmth.examcloud.commons.base.util.excel.ExcelProperty;
-import cn.com.qmth.examcloud.core.basic.dao.entity.Specialty;
+import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
 
 /**
  * @Description 专业
@@ -22,7 +22,7 @@ public class SpecialtyDto {
 	
 	public SpecialtyDto(){}
 	
-	public SpecialtyDto(Specialty specialty){
+	public SpecialtyDto(SpecialtyEntity specialty){
 		this.code = specialty.getCode();
 		this.name = specialty.getName();
 	}

+ 0 - 151
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/CourseService.java

@@ -1,151 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.service.impl;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-import javax.persistence.criteria.Subquery;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.StringUtils;
-
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReader;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReaderHandle;
-import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
-import cn.com.qmth.examcloud.core.basic.dao.entity.Course;
-import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatly;
-import cn.com.qmth.examcloud.core.basic.dao.enums.CourseLevel;
-import cn.com.qmth.examcloud.core.basic.service.bean.CourseDto;
-
-@Service
-public class CourseService {
-
-	@Autowired
-	CourseRepo courseRepo;
-
-	@Transactional
-	public List<ExcelError> importCourse(Long orgId, InputStream inputStream) {
-		ExcelReader excelReader = new ExcelReader(CourseDto.class);
-		List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
-			@Override
-			public ExcelError handle(Object obj) {
-				CourseDto dto = (CourseDto) obj;
-				Course course = new Course(dto.getName(), dto.getCode());
-				course.setOrgId(orgId);
-				course.setEnable(true);
-				if ("ZSB".equalsIgnoreCase(dto.getLevel())) {
-					course.setLevel(CourseLevel.ZSB);
-				}
-				if ("GQZ".equalsIgnoreCase(dto.getLevel())) {
-					course.setLevel(CourseLevel.GQZ);
-				}
-				if ("GQB".equalsIgnoreCase(dto.getLevel())) {
-					course.setLevel(CourseLevel.GQB);
-				}
-				if ("ALL".equalsIgnoreCase(dto.getLevel())) {
-					course.setLevel(CourseLevel.ALL);
-				}
-				ExcelError error = importCheck(course);
-				if (error == null) {
-					addCourse(course);
-				}
-				return error;
-			}
-		});
-		return excelErrors;
-	}
-
-	private void addCourse(Course course) {
-		Course old = courseRepo.findByOrgIdAndCode(course.getOrgId(), course.getCode());
-		if (old == null) {
-			courseRepo.save(course);
-		} else {
-			old.setName(course.getName());
-			old.setLevel(course.getLevel());
-			old.setUpdateTime(new Date());
-			courseRepo.save(old);
-		}
-	}
-
-	private ExcelError importCheck(Course course) {
-		if (StringUtils.isEmpty(course.getCode())) {
-			return new ExcelError("代码不能为空");
-		}
-		if (StringUtils.isEmpty(course.getName())) {
-			return new ExcelError("名称不能为空");
-		}
-		if (null == course.getLevel()) {
-			return new ExcelError("层次不能为空");
-		}
-		return null;
-	}
-
-	private Specification<Course> getSpecification(Course courseCriteria, Long specialtyId) {
-		Specification<Course> specification = (root, query, cb) -> {
-			List<Predicate> predicates = new ArrayList<>();
-			if (!StringUtils.isEmpty(courseCriteria.getOrgId())) {
-				predicates.add(cb.equal(root.get("orgId"), courseCriteria.getOrgId()));
-			}
-			if (!StringUtils.isEmpty(courseCriteria.getName())) {
-				predicates.add(cb.like(root.get("name"), "%" + courseCriteria.getName() + "%"));
-			}
-			if (!StringUtils.isEmpty(courseCriteria.getCode())) {
-				predicates.add(cb.like(root.get("code"), "%" + courseCriteria.getCode() + "%"));
-			}
-			if (!StringUtils.isEmpty(courseCriteria.getLevel())) {
-				predicates.add(cb.equal(root.get("level"), courseCriteria.getLevel()));
-			}
-			if (!StringUtils.isEmpty(courseCriteria.getEnable())) {
-				predicates.add(cb.equal(root.get("enable"), courseCriteria.getEnable()));
-			}
-			if (specialtyId != null) {
-				Subquery<CourseSpeciatly> relationshipSubquery = query
-						.subquery(CourseSpeciatly.class);
-				Root<CourseSpeciatly> residencyRelationshipSubqueryRoot = relationshipSubquery
-						.from(CourseSpeciatly.class);
-				relationshipSubquery.select(residencyRelationshipSubqueryRoot);
-				Predicate predicate = cb.equal(residencyRelationshipSubqueryRoot.get("specialtyId"),
-						specialtyId);
-				Predicate predicate2 = cb.equal(residencyRelationshipSubqueryRoot.get("courseId"),
-						root.get("id"));
-				relationshipSubquery.where(cb.and(predicate, predicate2));
-				predicates.add(cb.exists(relationshipSubquery));
-			}
-			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-		};
-		return specification;
-	}
-
-	public List<Course> findAll(Course courseCriteria) {
-		Specification<Course> specification = getSpecification(courseCriteria, null);
-		return courseRepo.findAll(specification);
-	}
-
-	public void setCourseEnable(List<Long> courseIds, boolean enable) {
-		for (Long courseId : courseIds) {
-			Course course = courseRepo.findOne(courseId);
-			course.setEnable(enable);
-			course.setUpdateTime(new Date());
-			courseRepo.saveAndFlush(course);
-		}
-	}
-
-	@Transactional
-	public void delete(String ids) {
-		List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
-				.collect(Collectors.toList());
-		for (Long courseId : courseIds) {
-			courseRepo.delete(courseId);
-		}
-	}
-
-}

+ 88 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/CourseServiceImpl.java

@@ -0,0 +1,88 @@
+package cn.com.qmth.examcloud.core.basic.service.impl;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Subquery;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.StringUtils;
+
+import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationEntity;
+
+@Service
+public class CourseServiceImpl {
+
+	@Autowired
+	CourseRepo courseRepo;
+
+	private Specification<CourseEntity> getSpecification(CourseEntity courseCriteria, Long specialtyId) {
+		Specification<CourseEntity> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			if (!StringUtils.isEmpty(courseCriteria.getRootOrgId())) {
+				predicates.add(cb.equal(root.get("orgId"), courseCriteria.getRootOrgId()));
+			}
+			if (!StringUtils.isEmpty(courseCriteria.getName())) {
+				predicates.add(cb.like(root.get("name"), "%" + courseCriteria.getName() + "%"));
+			}
+			if (!StringUtils.isEmpty(courseCriteria.getCode())) {
+				predicates.add(cb.like(root.get("code"), "%" + courseCriteria.getCode() + "%"));
+			}
+			if (!StringUtils.isEmpty(courseCriteria.getLevel())) {
+				predicates.add(cb.equal(root.get("level"), courseCriteria.getLevel()));
+			}
+			if (!StringUtils.isEmpty(courseCriteria.getEnable())) {
+				predicates.add(cb.equal(root.get("enable"), courseCriteria.getEnable()));
+			}
+			if (specialtyId != null) {
+				Subquery<CourseSpeciatlyRelationEntity> relationshipSubquery = query
+						.subquery(CourseSpeciatlyRelationEntity.class);
+				Root<CourseSpeciatlyRelationEntity> residencyRelationshipSubqueryRoot = relationshipSubquery
+						.from(CourseSpeciatlyRelationEntity.class);
+				relationshipSubquery.select(residencyRelationshipSubqueryRoot);
+				Predicate predicate = cb.equal(residencyRelationshipSubqueryRoot.get("specialtyId"),
+						specialtyId);
+				Predicate predicate2 = cb.equal(residencyRelationshipSubqueryRoot.get("courseId"),
+						root.get("id"));
+				relationshipSubquery.where(cb.and(predicate, predicate2));
+				predicates.add(cb.exists(relationshipSubquery));
+			}
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+		return specification;
+	}
+
+	public List<CourseEntity> findAll(CourseEntity courseCriteria) {
+		Specification<CourseEntity> specification = getSpecification(courseCriteria, null);
+		return courseRepo.findAll(specification);
+	}
+
+	public void setCourseEnable(List<Long> courseIds, boolean enable) {
+		for (Long courseId : courseIds) {
+			CourseEntity course = courseRepo.findOne(courseId);
+			course.setEnable(enable);
+			course.setUpdateTime(new Date());
+			courseRepo.saveAndFlush(course);
+		}
+	}
+
+	@Transactional
+	public void delete(String ids) {
+		List<Long> courseIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+				.collect(Collectors.toList());
+		for (Long courseId : courseIds) {
+			courseRepo.delete(courseId);
+		}
+	}
+
+}

+ 28 - 30
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/CourseSpeciatlyService.java → examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/CourseSpeciatlyRelationServiceImpl.java

@@ -1,24 +1,23 @@
 package cn.com.qmth.examcloud.core.basic.service.impl;
 
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.core.basic.dao.CourseRepo;
-import cn.com.qmth.examcloud.core.basic.dao.CourseSpeciatlyRepo;
+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.Course;
-import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatly;
-import cn.com.qmth.examcloud.core.basic.dao.entity.Specialty;
+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;
 
 @Service
-public class CourseSpeciatlyService {
+public class CourseSpeciatlyRelationServiceImpl {
 
 	@Autowired
-	CourseSpeciatlyRepo courseSpeciatlyRepo;
+	CourseSpeciatlyRelationRepo courseSpeciatlyRepo;
 
 	@Autowired
 	CourseRepo courseRepo;
@@ -32,11 +31,11 @@ public class CourseSpeciatlyService {
 	 * @param speciatlyId
 	 * @return
 	 */
-	public List<Course> getAllCoursesBySpeciatlyId(String speciatlyId) {
+	public List<CourseEntity> getAllCoursesBySpeciatlyId(String speciatlyId) {
 		// 根据专业id查询 专业课程
-		List<CourseSpeciatly> list = courseSpeciatlyRepo
+		List<CourseSpeciatlyRelationEntity> list = courseSpeciatlyRepo
 				.findBySpecialtyId(Long.parseLong(speciatlyId));
-		List<Course> courses = new ArrayList<Course>();
+		List<CourseEntity> courses = new ArrayList<CourseEntity>();
 		if (list == null) {
 			return null;
 		}
@@ -45,10 +44,11 @@ public class CourseSpeciatlyService {
 	}
 
 	// 根据课程专业查询课程集合
-	public List<Course> getCoursesByCourseSpeciatly(List<CourseSpeciatly> list) {
-		List<Course> courses = new ArrayList<Course>();
-		for (CourseSpeciatly courseSpeciatly : list) {
-			Course course = courseRepo.findOne(courseSpeciatly.getCourseId());
+	public List<CourseEntity> getCoursesByCourseSpeciatly(
+			List<CourseSpeciatlyRelationEntity> list) {
+		List<CourseEntity> courses = new ArrayList<CourseEntity>();
+		for (CourseSpeciatlyRelationEntity courseSpeciatly : list) {
+			CourseEntity course = courseRepo.findOne(courseSpeciatly.getCourseId());
 			courses.add(course);
 		}
 		return courses;
@@ -60,14 +60,14 @@ public class CourseSpeciatlyService {
 	 * @param courses
 	 * @return
 	 */
-	public List<Course> getCoursesNotInSpeciatly(List<Course> courses) {
-		List<Course> list = new ArrayList<Course>();
+	public List<CourseEntity> getCoursesNotInSpeciatly(List<CourseEntity> courses) {
+		List<CourseEntity> list = new ArrayList<CourseEntity>();
 		if (courses == null || courses.size() < 1) {
 			list = courseRepo.findAll();
 			return list;
 		}
 		List<Long> ids = new ArrayList<Long>();
-		for (Course course : courses) {
+		for (CourseEntity course : courses) {
 			ids.add(course.getId());
 		}
 		list = courseRepo.findByIdNotIn(ids);
@@ -76,29 +76,28 @@ public class CourseSpeciatlyService {
 
 	public void addCourseSpecialty(Long userId, List<String> courseIds, String speciallyId) {
 		// 首先判断该专业是否有关联的课程
-		List<CourseSpeciatly> list = courseSpeciatlyRepo
+		List<CourseSpeciatlyRelationEntity> list = courseSpeciatlyRepo
 				.findBySpecialtyId(Long.parseLong(speciallyId));
 		if (list != null || list.size() > 0) {
-			for (CourseSpeciatly courseSpeciatly : list) {
+			for (CourseSpeciatlyRelationEntity courseSpeciatly : list) {
 				courseSpeciatlyRepo.delete(courseSpeciatly);
 			}
 		}
 		// 保存新关联的课程
 		for (String courseId : courseIds) {
-			CourseSpeciatly courseSpeciatly = new CourseSpeciatly();
+			CourseSpeciatlyRelationEntity courseSpeciatly = new CourseSpeciatlyRelationEntity();
 			courseSpeciatly.setCourseId(Long.parseLong(courseId));
 			courseSpeciatly.setSpecialtyId(Long.parseLong(speciallyId));
 			courseSpeciatly.setCreator(userId);
-			courseSpeciatly.setCreateTime(new Date());
 			courseSpeciatlyRepo.save(courseSpeciatly);
 		}
 	}
 
-	public List<Specialty> getAllSpecialtyByCourseId(Long courseId) {
-		List<CourseSpeciatly> list = courseSpeciatlyRepo.findByCourseId(courseId);
-		List<Specialty> specialties = new ArrayList<Specialty>();
-		for (CourseSpeciatly courseSpeciatly : list) {
-			Specialty one = specialtyRepo.findOne(courseSpeciatly.getSpecialtyId());
+	public List<SpecialtyEntity> getAllSpecialtyByCourseId(Long courseId) {
+		List<CourseSpeciatlyRelationEntity> list = courseSpeciatlyRepo.findByCourseId(courseId);
+		List<SpecialtyEntity> specialties = new ArrayList<SpecialtyEntity>();
+		for (CourseSpeciatlyRelationEntity courseSpeciatly : list) {
+			SpecialtyEntity one = specialtyRepo.findOne(courseSpeciatly.getSpecialtyId());
 			if (null != one) {
 				specialties.add(one);
 			}
@@ -108,17 +107,16 @@ public class CourseSpeciatlyService {
 
 	public void addCourse(Long userId, List<String> SpecialtyIds, Long courseId) {
 		// 首先判断该专业是否有关联的课程
-		List<CourseSpeciatly> list = courseSpeciatlyRepo.findByCourseId(courseId);
-		for (CourseSpeciatly courseSpeciatly : list) {
+		List<CourseSpeciatlyRelationEntity> list = courseSpeciatlyRepo.findByCourseId(courseId);
+		for (CourseSpeciatlyRelationEntity courseSpeciatly : list) {
 			courseSpeciatlyRepo.delete(courseSpeciatly);
 		}
 		// 保存新关联的课程
 		for (String specialtyId : SpecialtyIds) {
-			CourseSpeciatly courseSpeciatly = new CourseSpeciatly();
+			CourseSpeciatlyRelationEntity courseSpeciatly = new CourseSpeciatlyRelationEntity();
 			courseSpeciatly.setCourseId(courseId);
 			courseSpeciatly.setSpecialtyId(Long.parseLong(specialtyId));
 			courseSpeciatly.setCreator(userId);
-			courseSpeciatly.setCreateTime(new Date());
 			courseSpeciatlyRepo.save(courseSpeciatly);
 		}
 

+ 0 - 182
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/SpecialtyService.java

@@ -1,182 +0,0 @@
-package cn.com.qmth.examcloud.core.basic.service.impl;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.stream.Collectors;
-import java.util.stream.Stream;
-
-import javax.persistence.criteria.Predicate;
-import javax.persistence.criteria.Root;
-import javax.persistence.criteria.Subquery;
-import javax.transaction.Transactional;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.data.domain.Page;
-import org.springframework.data.domain.Pageable;
-import org.springframework.data.jpa.domain.Specification;
-import org.springframework.stereotype.Service;
-import org.springframework.util.StringUtils;
-
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelError;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReader;
-import cn.com.qmth.examcloud.commons.base.util.excel.ExcelReaderHandle;
-import cn.com.qmth.examcloud.core.basic.dao.SpecialtyRepo;
-import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatly;
-import cn.com.qmth.examcloud.core.basic.dao.entity.Specialty;
-import cn.com.qmth.examcloud.core.basic.service.bean.SpecialtyDto;
-
-@Service
-public class SpecialtyService {
-
-	@Autowired
-	SpecialtyRepo specialtyRepo;
-
-	@Transactional
-	public List<ExcelError> importSpecialty(Long orgId, InputStream inputStream) {
-		ExcelReader excelReader = new ExcelReader(SpecialtyDto.class);
-		List<ExcelError> excelErrors = excelReader.reader(inputStream, new ExcelReaderHandle() {
-			@Override
-			public ExcelError handle(Object obj) {
-				SpecialtyDto dto = (SpecialtyDto) obj;
-				Specialty specialty = new Specialty(dto.getCode(), dto.getName());
-				specialty.setOrgId(orgId);
-				specialty.setCreateTime(new Date());
-				specialty.setEnable(true);
-				ExcelError error = importCheck(specialty);
-				if (error == null) {
-					addSpecialty(specialty);
-				}
-				return error;
-			}
-		});
-		return excelErrors;
-	}
-
-	private void addSpecialty(Specialty specialty) {
-		Specialty old = specialtyRepo.findByOrgIdAndCode(specialty.getOrgId(), specialty.getCode());
-		if (old == null) {
-			specialtyRepo.save(specialty);
-		} else {
-			old.setName(specialty.getName());
-			old.setUpdateTime(new Date());
-			specialtyRepo.save(old);
-		}
-	}
-
-	private ExcelError importCheck(Specialty specialty) {
-		if (StringUtils.isEmpty(specialty.getCode())) {
-			return new ExcelError("代码不能为空");
-		}
-		if (StringUtils.isEmpty(specialty.getName())) {
-			return new ExcelError("名称不能为空");
-		}
-		return null;
-	}
-
-	/**
-	 * 带分页查询专业
-	 * 
-	 * @param specialty
-	 * @param pageable
-	 * @return
-	 */
-	public Page<Specialty> findAll(Specialty specialty, Long courseId, Pageable pageable) {
-		Specification<Specialty> specification = getSpecification(specialty, courseId);
-		Page<Specialty> specialties = specialtyRepo.findAll(specification, pageable);
-		return specialties;
-	}
-
-	public Specification<Specialty> getSpecification(Specialty specialty, Long courseId) {
-		Specification<Specialty> specification = (root, query, cb) -> {
-			List<Predicate> predicates = new ArrayList<>();
-			if (!StringUtils.isEmpty(specialty.getOrgId())) {
-				predicates.add(cb.equal(root.get("orgId"), specialty.getOrgId()));
-			}
-			if (!StringUtils.isEmpty(specialty.getName())) {
-				predicates.add(cb.like(root.get("name"), "%" + specialty.getName() + "%"));
-			}
-			if (!StringUtils.isEmpty(specialty.getCode())) {
-				predicates.add(cb.like(root.get("code"), "%" + specialty.getCode() + "%"));
-			}
-			if (!StringUtils.isEmpty(specialty.getEnable())) {
-				predicates.add(cb.equal(root.get("enable"), specialty.getEnable()));
-			}
-			if (courseId != null) {
-				Subquery<CourseSpeciatly> relationshipSubquery = query
-						.subquery(CourseSpeciatly.class);
-				Root<CourseSpeciatly> residencyRelationshipSubqueryRoot = relationshipSubquery
-						.from(CourseSpeciatly.class);
-				relationshipSubquery.select(residencyRelationshipSubqueryRoot);
-				Predicate predicate = cb.equal(residencyRelationshipSubqueryRoot.get("courseId"),
-						courseId);
-				Predicate predicate2 = cb.equal(
-						residencyRelationshipSubqueryRoot.get("specialtyId"), root.get("id"));
-				relationshipSubquery.where(cb.and(predicate, predicate2));
-				predicates.add(cb.exists(relationshipSubquery));
-			}
-			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
-		};
-		return specification;
-	}
-
-	/**
-	 * 查询专业不带分页
-	 * 
-	 * @param specialty
-	 * @return
-	 */
-	public List<Specialty> findAll(Specialty specialty) {
-		Specification<Specialty> specification = getSpecification(specialty, null);
-		return specialtyRepo.findAll(specification);
-	}
-
-	/**
-	 * 保存专业
-	 * 
-	 * @param specialty
-	 * @return
-	 */
-	public void save(Specialty specialty) {
-		checkCode(specialty.getOrgId(), specialty.getCode());
-		specialty.setCreateTime(new Date());
-		specialty.setEnable(true);
-		specialtyRepo.save(specialty);
-	}
-
-	// 验证专业代码是否存在
-	private void checkCode(Long orgId, String code) {
-		Specialty specialty = specialtyRepo.findByOrgIdAndCode(orgId, code);
-		if (specialty != null) {
-			throw new RuntimeException("专业代码已存在");
-		}
-	}
-
-	/**
-	 * 更新专业
-	 * 
-	 * @param specialty
-	 */
-	public void updateSpecialty(Specialty specialty) {
-		Specialty oldSpecialty = specialtyRepo.findOne(specialty.getId());
-		if (!oldSpecialty.getCode().equals(specialty.getCode())) {
-			checkCode(specialty.getOrgId(), specialty.getCode());
-		}
-		specialty.setUpdateTime(new Date());
-		specialtyRepo.save(specialty);
-	}
-
-	/**
-	 * 根据Id删除专业
-	 * 
-	 * @param ids
-	 */
-	public void deleteSpecialty(String ids) {
-		List<Long> specialtyIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
-				.collect(Collectors.toList());
-		for (Long specialtyId : specialtyIds) {
-			specialtyRepo.delete(specialtyId);
-		}
-	}
-}

+ 98 - 0
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/SpecialtyServiceImpl.java

@@ -0,0 +1,98 @@
+package cn.com.qmth.examcloud.core.basic.service.impl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import javax.persistence.criteria.Predicate;
+import javax.persistence.criteria.Root;
+import javax.persistence.criteria.Subquery;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.domain.Specification;
+import org.springframework.stereotype.Service;
+import org.springframework.util.StringUtils;
+
+import cn.com.qmth.examcloud.core.basic.dao.SpecialtyRepo;
+import cn.com.qmth.examcloud.core.basic.dao.entity.CourseSpeciatlyRelationEntity;
+import cn.com.qmth.examcloud.core.basic.dao.entity.SpecialtyEntity;
+
+@Service
+public class SpecialtyServiceImpl {
+
+	@Autowired
+	SpecialtyRepo specialtyRepo;
+
+	/**
+	 * 带分页查询专业
+	 * 
+	 * @param specialty
+	 * @param pageable
+	 * @return
+	 */
+	public Page<SpecialtyEntity> findAll(SpecialtyEntity specialty, Long courseId, Pageable pageable) {
+		Specification<SpecialtyEntity> specification = getSpecification(specialty, courseId);
+		Page<SpecialtyEntity> specialties = specialtyRepo.findAll(specification, pageable);
+		return specialties;
+	}
+
+	public Specification<SpecialtyEntity> getSpecification(SpecialtyEntity specialty, Long courseId) {
+		Specification<SpecialtyEntity> specification = (root, query, cb) -> {
+			List<Predicate> predicates = new ArrayList<>();
+			if (!StringUtils.isEmpty(specialty.getRootOrgId())) {
+				predicates.add(cb.equal(root.get("orgId"), specialty.getRootOrgId()));
+			}
+			if (!StringUtils.isEmpty(specialty.getName())) {
+				predicates.add(cb.like(root.get("name"), "%" + specialty.getName() + "%"));
+			}
+			if (!StringUtils.isEmpty(specialty.getCode())) {
+				predicates.add(cb.like(root.get("code"), "%" + specialty.getCode() + "%"));
+			}
+			if (!StringUtils.isEmpty(specialty.getEnable())) {
+				predicates.add(cb.equal(root.get("enable"), specialty.getEnable()));
+			}
+			if (courseId != null) {
+				Subquery<CourseSpeciatlyRelationEntity> relationshipSubquery = query
+						.subquery(CourseSpeciatlyRelationEntity.class);
+				Root<CourseSpeciatlyRelationEntity> residencyRelationshipSubqueryRoot = relationshipSubquery
+						.from(CourseSpeciatlyRelationEntity.class);
+				relationshipSubquery.select(residencyRelationshipSubqueryRoot);
+				Predicate predicate = cb.equal(residencyRelationshipSubqueryRoot.get("courseId"),
+						courseId);
+				Predicate predicate2 = cb.equal(
+						residencyRelationshipSubqueryRoot.get("specialtyId"), root.get("id"));
+				relationshipSubquery.where(cb.and(predicate, predicate2));
+				predicates.add(cb.exists(relationshipSubquery));
+			}
+			return cb.and(predicates.toArray(new Predicate[predicates.size()]));
+		};
+		return specification;
+	}
+
+	/**
+	 * 查询专业不带分页
+	 * 
+	 * @param specialty
+	 * @return
+	 */
+	public List<SpecialtyEntity> findAll(SpecialtyEntity specialty) {
+		Specification<SpecialtyEntity> specification = getSpecification(specialty, null);
+		return specialtyRepo.findAll(specification);
+	}
+
+	/**
+	 * 根据Id删除专业
+	 * 
+	 * @param ids
+	 */
+	public void deleteSpecialty(String ids) {
+		List<Long> specialtyIds = Stream.of(ids.split(",")).map(s -> Long.parseLong(s.trim()))
+				.collect(Collectors.toList());
+		for (Long specialtyId : specialtyIds) {
+			specialtyRepo.delete(specialtyId);
+		}
+	}
+}

+ 3 - 3
examcloud-core-basic-service/src/main/java/cn/com/qmth/examcloud/core/basic/service/impl/StudentServiceImpl.java

@@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
 
 import cn.com.qmth.examcloud.commons.base.exception.StatusException;
 import cn.com.qmth.examcloud.commons.base.util.PropertiesUtil;
+import cn.com.qmth.examcloud.commons.base.util.UrlUtil;
 import cn.com.qmth.examcloud.core.basic.base.constants.BasicConsts;
 import cn.com.qmth.examcloud.core.basic.base.constants.PropKeys;
 import cn.com.qmth.examcloud.core.basic.dao.OrgRepo;
@@ -275,9 +276,8 @@ public class StudentServiceImpl implements StudentService {
 			if (StringUtils.isBlank(basePath)) {
 				throw new StatusException("B-160212", "照片根路径未配置");
 			}
-			String path = basePath + "/" + s.getPhotoPath();
-			path = StringUtils.replaceAll(path, "//", "/");
-			info.setPhotoPath(s.getPhotoPath());
+			String path = UrlUtil.joinUrl(basePath, s.getPhotoPath());
+			info.setPhotoPath(path);
 		}
 
 		info.setRemark(s.getRemark());