@ -1,9 +1,16 @@
package com.huoran.iasf.service.impl ;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import com.huoran.iasf.common.utils.R ;
import com.huoran.iasf.entity.Discipline ;
import com.huoran.iasf.entity.Professional ;
import com.huoran.iasf.entity.ProfessionalClass ;
import com.huoran.iasf.mapper.DisciplineMapper ;
import com.huoran.iasf.mapper.ProfessionalClassMapper ;
import com.huoran.iasf.mapper.ProfessionalMapper ;
import com.huoran.iasf.service.DisciplineService ;
import org.springframework.beans.factory.annotation.Autowired ;
import org.springframework.stereotype.Service ;
import java.util.List ;
@ -18,9 +25,41 @@ import java.util.List;
* /
@Service
public class DisciplineServiceImpl extends ServiceImpl < DisciplineMapper , Discipline > implements DisciplineService {
@Autowired
private DisciplineMapper disciplineMapper ;
@Autowired
private ProfessionalClassMapper professionalClassMapper ;
@Autowired
private ProfessionalMapper professionalMapper ;
@Override
public List < Discipline > subjectCategory ( ) {
return baseMapper . selectList ( null ) ;
}
@Override
public R getCourseDisciplineWithDetails ( Integer disciplineId ) {
if ( disciplineId = = null ) {
// 如果没有disciplineId,只查询第一级(学科类别)
List < Discipline > disciplines = disciplineMapper . selectList ( new LambdaQueryWrapper < > ( ) ) ;
return R . success ( disciplines ) ;
} else {
// 进行完整的三级联查
List < Discipline > disciplines = disciplineMapper . selectList ( new LambdaQueryWrapper < Discipline > ( ) . eq ( Discipline : : getDisciplineId , disciplineId ) ) ;
disciplines . forEach ( discipline - > {
// 获取该学科类别下的所有专业类别
List < ProfessionalClass > professionalClasses = professionalClassMapper . selectList ( new LambdaQueryWrapper < ProfessionalClass > ( ) . eq ( ProfessionalClass : : getDisciplineId , discipline . getDisciplineId ( ) ) ) ;
discipline . setProfessionalClasses ( professionalClasses ) ;
// 为每个专业类别填充其下的专业
professionalClasses . forEach ( professionalClass - > {
List < Professional > professionals = professionalMapper . selectList ( new LambdaQueryWrapper < Professional > ( ) . eq ( Professional : : getProfessionalClassId , professionalClass . getProfessionalClassId ( ) ) ) ;
professionalClass . setProfessionals ( professionals ) ;
} ) ;
} ) ;
return R . success ( disciplines ) ;
}
}
}