|
@@ -32,6 +32,8 @@ import org.springframework.web.bind.annotation.RequestParam;
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
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;
|
|
@@ -40,7 +42,6 @@ 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;
|
|
@@ -127,18 +128,54 @@ public class SpecialtyController extends ControllerSupport {
|
|
|
return page;
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 方法注释
|
|
|
- *
|
|
|
- * @author WANGWEI
|
|
|
- * @return
|
|
|
- */
|
|
|
- @ApiOperation(value = "查询所有专业")
|
|
|
- @GetMapping("all")
|
|
|
- public List<SpecialtyEntity> getAll() {
|
|
|
+ @ApiOperation(value = "查询专业")
|
|
|
+ @GetMapping("query")
|
|
|
+ public List<SpecialtyEntity> query(@RequestParam(required = false) String name,
|
|
|
+ @RequestParam(required = false) String code,
|
|
|
+ @RequestParam(required = false) Boolean enable,
|
|
|
+ @RequestParam(required = false) Long courseId) {
|
|
|
User accessUser = getAccessUser();
|
|
|
+
|
|
|
Long rootOrgId = accessUser.getRootOrgId();
|
|
|
- List<SpecialtyEntity> list = specialtyRepo.findByRootOrgId(rootOrgId);
|
|
|
+ // 过载保护
|
|
|
+ int total = specialtyRepo.countByRootOrgIdAndNameLike(rootOrgId, toSqlSearchPattern(name));
|
|
|
+ if (total > 1000) {
|
|
|
+ List<SpecialtyEntity> list = Lists.newArrayList();
|
|
|
+ return list;
|
|
|
+ }
|
|
|
+
|
|
|
+ Specification<SpecialtyEntity> specification = (root, query, cb) -> {
|
|
|
+ List<Predicate> predicates = new ArrayList<>();
|
|
|
+
|
|
|
+ predicates.add(cb.equal(root.get("rootOrgId"), accessUser.getRootOrgId()));
|
|
|
+
|
|
|
+ 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 (null != enable) {
|
|
|
+ predicates.add(cb.equal(root.get("enable"), enable));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (null != courseId) {
|
|
|
+ Subquery<CourseSpeciatlyRelationEntity> subquery = query
|
|
|
+ .subquery(CourseSpeciatlyRelationEntity.class);
|
|
|
+ Root<CourseSpeciatlyRelationEntity> subRoot = subquery
|
|
|
+ .from(CourseSpeciatlyRelationEntity.class);
|
|
|
+ subquery.select(subRoot.get("specialtyId"));
|
|
|
+ Predicate p1 = cb.equal(subRoot.get("courseId"), courseId);
|
|
|
+ Predicate p2 = cb.equal(subRoot.get("specialtyId"), root.get("id"));
|
|
|
+ subquery.where(cb.and(p1, p2));
|
|
|
+ predicates.add(cb.exists(subquery));
|
|
|
+ }
|
|
|
+
|
|
|
+ return cb.and(predicates.toArray(new Predicate[predicates.size()]));
|
|
|
+ };
|
|
|
+
|
|
|
+ List<SpecialtyEntity> list = specialtyRepo.findAll(specification,
|
|
|
+ new Sort(Direction.DESC, "updateTime"));
|
|
|
return list;
|
|
|
}
|
|
|
|