|
@@ -32,19 +32,15 @@ public class SpecialtyService {
|
|
|
|
|
|
@Autowired
|
|
|
SpecialtyRepo specialtyRepo;
|
|
|
- @Autowired
|
|
|
- DataSendService dataSendService;
|
|
|
-
|
|
|
|
|
|
@Transactional
|
|
|
public List<ExcelError> importSpecialty(Long orgId, InputStream inputStream) {
|
|
|
- List<Specialty> list = new ArrayList<Specialty>();
|
|
|
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 specialty = new Specialty(dto.getCode(), dto.getName());
|
|
|
specialty.setOrgId(orgId);
|
|
|
specialty.setCreateTime(new Date());
|
|
|
specialty.setEnable(true);
|
|
@@ -58,123 +54,128 @@ public class SpecialtyService {
|
|
|
return excelErrors;
|
|
|
}
|
|
|
|
|
|
- private void addSpecialty(Specialty specialty){
|
|
|
- Specialty old = specialtyRepo.findByOrgIdAndCode(specialty.getOrgId(),specialty.getCode());
|
|
|
- if(old == null){
|
|
|
- Specialty tempSpecialty = specialtyRepo.save(specialty);
|
|
|
- dataSendService.sendSpecialty(tempSpecialty);
|
|
|
- }else{
|
|
|
+ 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());
|
|
|
- Specialty tempSpecialty = specialtyRepo.save(old);
|
|
|
- dataSendService.sendSpecialty(tempSpecialty);
|
|
|
+ specialtyRepo.save(old);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private ExcelError importCheck(Specialty specialty) {
|
|
|
- if(StringUtils.isEmpty(specialty.getCode())){
|
|
|
+ if (StringUtils.isEmpty(specialty.getCode())) {
|
|
|
return new ExcelError("代码不能为空");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(specialty.getName())){
|
|
|
+ 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);
|
|
|
+ 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){
|
|
|
+
|
|
|
+ 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.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));
|
|
|
}
|
|
|
- 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);
|
|
|
+ public List<Specialty> findAll(Specialty specialty) {
|
|
|
+ Specification<Specialty> specification = getSpecification(specialty, null);
|
|
|
return specialtyRepo.findAll(specification);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
* 保存专业
|
|
|
+ *
|
|
|
* @param specialty
|
|
|
* @return
|
|
|
*/
|
|
|
- public void save(Specialty specialty){
|
|
|
+ public void save(Specialty specialty) {
|
|
|
checkCode(specialty.getOrgId(), specialty.getCode());
|
|
|
specialty.setCreateTime(new Date());
|
|
|
specialty.setEnable(true);
|
|
|
specialtyRepo.save(specialty);
|
|
|
- dataSendService.sendSpecialty(specialty);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- private void checkCode(Long orgId,String code){
|
|
|
+
|
|
|
+
|
|
|
+ private void checkCode(Long orgId, String code) {
|
|
|
Specialty specialty = specialtyRepo.findByOrgIdAndCode(orgId, code);
|
|
|
- if(specialty != null){
|
|
|
+ if (specialty != null) {
|
|
|
throw new RuntimeException("专业代码已存在");
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
* 更新专业
|
|
|
+ *
|
|
|
* @param specialty
|
|
|
*/
|
|
|
- public void updateSpecialty(Specialty specialty){
|
|
|
+ public void updateSpecialty(Specialty specialty) {
|
|
|
Specialty oldSpecialty = specialtyRepo.findOne(specialty.getId());
|
|
|
- if(!oldSpecialty.getCode().equals(specialty.getCode())){
|
|
|
+ if (!oldSpecialty.getCode().equals(specialty.getCode())) {
|
|
|
checkCode(specialty.getOrgId(), specialty.getCode());
|
|
|
}
|
|
|
specialty.setUpdateTime(new Date());
|
|
|
specialtyRepo.save(specialty);
|
|
|
- dataSendService.sendSpecialty(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){
|
|
|
+ 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);
|
|
|
}
|
|
|
}
|