|
@@ -8,14 +8,10 @@ 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 cn.com.qmth.examcloud.common.dto.core.enums.CourseLevel;
|
|
|
-import cn.com.qmth.examcloud.common.util.excel.ExcelError;
|
|
|
-import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
|
|
|
-import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
|
|
|
-import cn.com.qmth.examcloud.service.core.dto.SpecialtyDTO;
|
|
|
-import cn.com.qmth.examcloud.service.core.entity.Specialty;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.data.domain.Page;
|
|
|
import org.springframework.data.domain.Pageable;
|
|
@@ -23,8 +19,11 @@ import org.springframework.data.jpa.domain.Specification;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.StringUtils;
|
|
|
|
|
|
-import com.rabbitmq.client.AMQP.Basic.Return;
|
|
|
-
|
|
|
+import cn.com.qmth.examcloud.common.util.excel.ExcelError;
|
|
|
+import cn.com.qmth.examcloud.common.util.excel.ExcelReader;
|
|
|
+import cn.com.qmth.examcloud.common.util.excel.ExcelReaderHandle;
|
|
|
+import cn.com.qmth.examcloud.service.core.dto.SpecialtyDTO;
|
|
|
+import cn.com.qmth.examcloud.service.core.entity.CourseSpeciatly;
|
|
|
import cn.com.qmth.examcloud.service.core.entity.Specialty;
|
|
|
import cn.com.qmth.examcloud.service.core.repo.SpecialtyRepo;
|
|
|
|
|
@@ -54,7 +53,7 @@ public class SpecialtyService {
|
|
|
return error;
|
|
|
}
|
|
|
});
|
|
|
- List<Specialty> specialtyList = specialtyRepo.save(list);
|
|
|
+ specialtyRepo.save(list);
|
|
|
return excelErrors;
|
|
|
}
|
|
|
|
|
@@ -78,13 +77,13 @@ public class SpecialtyService {
|
|
|
* @param pageable
|
|
|
* @return
|
|
|
*/
|
|
|
- public Page<Specialty> findAll(Specialty specialty,Pageable pageable){
|
|
|
- Specification<Specialty> specification = getSpecification(specialty);
|
|
|
+ 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){
|
|
|
+ public Specification<Specialty> getSpecification(Specialty specialty,Long courseId){
|
|
|
Specification<Specialty> specification = (root, query, cb) -> {
|
|
|
List<Predicate> predicates = new ArrayList<>();
|
|
|
if(!StringUtils.isEmpty(specialty.getOrgId())){
|
|
@@ -98,6 +97,15 @@ public class SpecialtyService {
|
|
|
}
|
|
|
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()]));
|
|
|
};
|
|
@@ -110,7 +118,7 @@ public class SpecialtyService {
|
|
|
* @return
|
|
|
*/
|
|
|
public List<Specialty> findAll(Specialty specialty){
|
|
|
- Specification<Specialty> specification = getSpecification(specialty);
|
|
|
+ Specification<Specialty> specification = getSpecification(specialty,null);
|
|
|
return specialtyRepo.findAll(specification);
|
|
|
}
|
|
|
|
|
@@ -122,6 +130,7 @@ public class SpecialtyService {
|
|
|
public void save(Specialty specialty){
|
|
|
checkCode(specialty.getOrgId(), specialty.getCode());
|
|
|
specialty.setCreateTime(new Date());
|
|
|
+ specialty.setEnable(true);
|
|
|
specialtyRepo.save(specialty);
|
|
|
}
|
|
|
|