|
@@ -6,13 +6,21 @@ 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.servlet.http.HttpServletRequest;
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
|
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.util.StringUtils;
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
@@ -37,6 +45,7 @@ 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.service.bean.CourseAssembler;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.bean.CourseDto;
|
|
|
import cn.com.qmth.examcloud.core.basic.service.impl.CourseService;
|
|
@@ -62,20 +71,62 @@ public class CourseController extends ControllerSupport {
|
|
|
@Autowired
|
|
|
CourseCloudService courseCloudService;
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param courseCriteria
|
|
|
+ * @param specialtyId
|
|
|
+ * @param curPage
|
|
|
+ * @param pageSize
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "查询课程分页带查询", notes = "分页带查询")
|
|
|
@GetMapping("/all/{curPage}/{pageSize}")
|
|
|
- public ResponseEntity getAllOrg(@ModelAttribute Course course,
|
|
|
+ public Page<Course> getCourseList(@ModelAttribute Course courseCriteria,
|
|
|
@RequestParam(required = false) Long specialtyId, @PathVariable Integer curPage,
|
|
|
@PathVariable Integer pageSize, HttpServletRequest request) {
|
|
|
- cn.com.qmth.examcloud.commons.web.security.bean.User accessUser = getAccessUser();
|
|
|
- if (accessUser != null) {
|
|
|
- course.setOrgId(accessUser.getRootOrgId());
|
|
|
- } else {
|
|
|
- return new ResponseEntity(HttpStatus.NOT_FOUND);
|
|
|
- }
|
|
|
- return new ResponseEntity(
|
|
|
- courseService.findAll(course, specialtyId, new PageRequest(curPage - 1, pageSize)),
|
|
|
- HttpStatus.OK);
|
|
|
+ User accessUser = getAccessUser();
|
|
|
+
|
|
|
+ Specification<Course> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+
|
|
|
+ predicates.add(cb.equal(root.get("orgId"), accessUser.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<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()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ PageRequest pageRequest = new PageRequest(curPage - 1, pageSize,
|
|
|
+ new Sort(Direction.DESC, "updateTime"));
|
|
|
+
|
|
|
+ Page<Course> page = courseRepo.findAll(specification, pageRequest);
|
|
|
+ return page;
|
|
|
}
|
|
|
|
|
|
@ApiOperation(value = "按代码或名称查询课程", notes = "代码或名称查询")
|
|
@@ -184,6 +235,9 @@ public class CourseController extends ControllerSupport {
|
|
|
saveCourseReq.setCourseName(course.getName());
|
|
|
saveCourseReq.setCourseLevel(course.getLevel().getName());
|
|
|
saveCourseReq.setRootOrgId(accessUser.getRootOrgId());
|
|
|
+ if (null != course.getEnable()) {
|
|
|
+ saveCourseReq.setEnable(course.getEnable());
|
|
|
+ }
|
|
|
|
|
|
SaveCourseResp saveCourseResp = courseCloudService.saveCourse(saveCourseReq);
|
|
|
CourseBean courseBean = saveCourseResp.getCourseBean();
|
|
@@ -235,21 +289,35 @@ public class CourseController extends ControllerSupport {
|
|
|
ExportService.exportEXCEL("课程列表", CourseDto.class, list, response);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "禁用课程", notes = "禁用")
|
|
|
@PutMapping("/disable/{ids}")
|
|
|
- public ResponseEntity disableCourse(@PathVariable String 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.enableCourse(courseIds, false);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
+ courseService.setCourseEnable(courseIds, false);
|
|
|
+ return courseIds;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 方法注释
|
|
|
+ *
|
|
|
+ * @author WANGWEI
|
|
|
+ * @param ids
|
|
|
+ * @return
|
|
|
+ */
|
|
|
@ApiOperation(value = "启用课程", notes = "启用")
|
|
|
@PutMapping("/enable/{ids}")
|
|
|
- public ResponseEntity enableCourse(@PathVariable String 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.enableCourse(courseIds, true);
|
|
|
- return new ResponseEntity(HttpStatus.OK);
|
|
|
+ courseService.setCourseEnable(courseIds, true);
|
|
|
+ return courseIds;
|
|
|
}
|
|
|
}
|