|
@@ -9,73 +9,83 @@ import org.springframework.stereotype.Service;
|
|
|
|
|
|
import cn.com.qmth.examcloud.service.core.entity.Course;
|
|
|
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.CourseRepo;
|
|
|
import cn.com.qmth.examcloud.service.core.repo.CourseSpeciatlyRepo;
|
|
|
+import cn.com.qmth.examcloud.service.core.repo.SpecialtyRepo;
|
|
|
|
|
|
@Service
|
|
|
public class CourseSpeciatlyService {
|
|
|
|
|
|
@Autowired
|
|
|
CourseSpeciatlyRepo courseSpeciatlyRepo;
|
|
|
-
|
|
|
+
|
|
|
@Autowired
|
|
|
CourseRepo courseRepo;
|
|
|
-
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ SpecialtyRepo specialtyRepo;
|
|
|
+
|
|
|
/**
|
|
|
* 根据专业ID查询关联课程
|
|
|
+ *
|
|
|
* @param speciatlyId
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Course> getAllCoursesBySpeciatlyId(String speciatlyId){
|
|
|
- //根据专业id查询 专业课程
|
|
|
- List<CourseSpeciatly> list = courseSpeciatlyRepo.findBySpecialtyId(Long.parseLong(speciatlyId));
|
|
|
+ public List<Course> getAllCoursesBySpeciatlyId(String speciatlyId) {
|
|
|
+ // 根据专业id查询 专业课程
|
|
|
+ List<CourseSpeciatly> list = courseSpeciatlyRepo.findBySpecialtyId(Long
|
|
|
+ .parseLong(speciatlyId));
|
|
|
List<Course> courses = new ArrayList<Course>();
|
|
|
- if(list == null){
|
|
|
+ if (list == null) {
|
|
|
return null;
|
|
|
}
|
|
|
courses = getCoursesByCourseSpeciatly(list);
|
|
|
return courses;
|
|
|
}
|
|
|
-
|
|
|
- //根据课程专业查询课程集合
|
|
|
- public List<Course> getCoursesByCourseSpeciatly(List<CourseSpeciatly> list){
|
|
|
+
|
|
|
+ // 根据课程专业查询课程集合
|
|
|
+ public List<Course> getCoursesByCourseSpeciatly(List<CourseSpeciatly> list) {
|
|
|
List<Course> courses = new ArrayList<Course>();
|
|
|
- for(CourseSpeciatly courseSpeciatly:list){
|
|
|
+ for (CourseSpeciatly courseSpeciatly : list) {
|
|
|
Course course = courseRepo.findOne(courseSpeciatly.getCourseId());
|
|
|
courses.add(course);
|
|
|
}
|
|
|
return courses;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 获取未关联的课程
|
|
|
+ *
|
|
|
* @param courses
|
|
|
* @return
|
|
|
*/
|
|
|
- public List<Course> getCoursesNotInSpeciatly(List<Course> courses){
|
|
|
+ public List<Course> getCoursesNotInSpeciatly(List<Course> courses) {
|
|
|
List<Course> list = new ArrayList<Course>();
|
|
|
- if(courses == null || courses.size() < 1){
|
|
|
+ if (courses == null || courses.size() < 1) {
|
|
|
list = courseRepo.findAll();
|
|
|
return list;
|
|
|
}
|
|
|
List<Long> ids = new ArrayList<Long>();
|
|
|
- for(Course course: courses){
|
|
|
+ for (Course course : courses) {
|
|
|
ids.add(course.getId());
|
|
|
}
|
|
|
list = courseRepo.findByIdNotIn(ids);
|
|
|
return list;
|
|
|
}
|
|
|
-
|
|
|
- public void addCourseSpecialty(Long userId,List<String> courseIds,String speciallyId){
|
|
|
- //首先判断该专业是否有关联的课程
|
|
|
- List<CourseSpeciatly> list = courseSpeciatlyRepo.findBySpecialtyId(Long.parseLong(speciallyId));
|
|
|
- if(list != null || list.size()>0){
|
|
|
- for(CourseSpeciatly courseSpeciatly: list){
|
|
|
+
|
|
|
+ public void addCourseSpecialty(Long userId, List<String> courseIds,
|
|
|
+ String speciallyId) {
|
|
|
+ // 首先判断该专业是否有关联的课程
|
|
|
+ List<CourseSpeciatly> list = courseSpeciatlyRepo.findBySpecialtyId(Long
|
|
|
+ .parseLong(speciallyId));
|
|
|
+ if (list != null || list.size() > 0) {
|
|
|
+ for (CourseSpeciatly courseSpeciatly : list) {
|
|
|
courseSpeciatlyRepo.delete(courseSpeciatly);
|
|
|
}
|
|
|
}
|
|
|
- //保存新关联的课程
|
|
|
- for(String courseId: courseIds){
|
|
|
+ // 保存新关联的课程
|
|
|
+ for (String courseId : courseIds) {
|
|
|
CourseSpeciatly courseSpeciatly = new CourseSpeciatly();
|
|
|
courseSpeciatly.setCourseId(Long.parseLong(courseId));
|
|
|
courseSpeciatly.setSpecialtyId(Long.parseLong(speciallyId));
|
|
@@ -83,5 +93,32 @@ public class CourseSpeciatlyService {
|
|
|
courseSpeciatly.setCreateTime(new Date());
|
|
|
courseSpeciatlyRepo.save(courseSpeciatly);
|
|
|
}
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ public List<Specialty> getAllSpecialtyByCourseId(Long courseId) {
|
|
|
+ List<CourseSpeciatly> list = courseSpeciatlyRepo.findByCourseId(courseId);
|
|
|
+ List<Specialty> specialties = new ArrayList<Specialty>();
|
|
|
+ for (CourseSpeciatly courseSpeciatly : list) {
|
|
|
+ specialties.add(specialtyRepo.findOne(courseSpeciatly.getSpecialtyId()));
|
|
|
+ }
|
|
|
+ return specialties;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void addCourse(Long userId, List<String> SpecialtyIds, Long courseId) {
|
|
|
+ // 首先判断该专业是否有关联的课程
|
|
|
+ List<CourseSpeciatly> list = courseSpeciatlyRepo.findByCourseId(courseId);
|
|
|
+ for (CourseSpeciatly courseSpeciatly : list) {
|
|
|
+ courseSpeciatlyRepo.delete(courseSpeciatly);
|
|
|
+ }
|
|
|
+ // 保存新关联的课程
|
|
|
+ for (String specialtyId : SpecialtyIds) {
|
|
|
+ CourseSpeciatly courseSpeciatly = new CourseSpeciatly();
|
|
|
+ courseSpeciatly.setCourseId(courseId);
|
|
|
+ courseSpeciatly.setSpecialtyId(Long.parseLong(specialtyId));
|
|
|
+ courseSpeciatly.setCreator(userId);
|
|
|
+ courseSpeciatly.setCreateTime(new Date());
|
|
|
+ courseSpeciatlyRepo.save(courseSpeciatly);
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|