Ver código fonte

班级课程批量新增

大数据与最优化研究所 11 meses atrás
pai
commit
61e5578db9

+ 11 - 28
src/main/java/com/xjrsoft/module/base/service/impl/BaseClassCourseServiceImpl.java

@@ -82,32 +82,15 @@ public class BaseClassCourseServiceImpl extends MPJBaseServiceImpl<BaseClassCour
     }
 
     @Override
+    @Transactional
     public Boolean oneUpdateClassCoursesAndTextbooks(ClassCourseTextbook dto) {
-        if (dto.getClassIds() == null || dto.getClassIds().length == 0 || dto.getBaseSemesterId() == null || dto.getBaseSemesterId() == 0) {
-            return false;
+        if (ObjectUtils.isEmpty(dto.getClassIds()) || ObjectUtils.isEmpty(dto.getBaseSemesterId())) {
+            throw new MyException("请选中班级和学期");
         }
 
         boolean isSuccess = false;
 
-        // 根据班级id查出班级已经存在的课程和教程
         List<Long> classIdList = Arrays.asList(dto.getClassIds());
-        LambdaQueryWrapper<BaseClassCourse> baseClassCourseLambdaQueryWrapper = new LambdaQueryWrapper<>();
-        baseClassCourseLambdaQueryWrapper
-                .in(BaseClassCourse::getClassId, classIdList)
-                .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
-                .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
-        ;
-        List<BaseClassCourse> oldList = this.list(baseClassCourseLambdaQueryWrapper);
-
-        // 使用Stream API和Lambda表达式生成所需的字符串列表
-        Map<Long, List<String>> tourseId_textbookIdMap = oldList.stream()
-                .collect(Collectors.groupingBy(
-                        BaseClassCourse::getClassId,
-                        Collectors.mapping(
-                                course -> course.getCourseId() + "_" + course.getTextbookId(),
-                                Collectors.toList()
-                        )
-                ));
 
         //删除班级的这学期的所有课程教材
         LambdaUpdateWrapper<BaseClassCourse> baseClassCourseLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
@@ -137,12 +120,7 @@ public class BaseClassCourseServiceImpl extends MPJBaseServiceImpl<BaseClassCour
         List<BaseClassCourse> baseClassCourseList = new ArrayList<>();
 //        List<TextbookStudentClaim> textbookStudentClaimList = new ArrayList<>();
         for (Long classId : dto.getClassIds()) {
-            // 判断当前的班级是否已经有了该课程和教材
-            List<String> tourseId_textbookIdList = tourseId_textbookIdMap.get(classId);
             for (String id : dto.getIds()) {
-                if(tourseId_textbookIdList.contains(id)){
-                    continue;
-                }
                 String[] idArr = id.split("_");
                 if (idArr[0].equals("") || idArr[1].equals("")) {
                     continue;
@@ -178,8 +156,8 @@ public class BaseClassCourseServiceImpl extends MPJBaseServiceImpl<BaseClassCour
     @Override
     @Transactional
     public Boolean updateAddCourseBook(ClassCourseTextbook dto){
-        if (dto.getClassIds() == null || dto.getClassIds().length == 0 || dto.getBaseSemesterId() == null || dto.getBaseSemesterId() == 0) {
-            return false;
+        if (ObjectUtils.isEmpty(dto.getClassIds()) || ObjectUtils.isEmpty(dto.getBaseSemesterId())) {
+            throw new MyException("请选中班级和学期");
         }
 
         boolean isSuccess = false;
@@ -235,7 +213,7 @@ public class BaseClassCourseServiceImpl extends MPJBaseServiceImpl<BaseClassCour
             // 判断当前的班级是否已经有了该课程和教材
             List<String> tourseId_textbookIdList = tourseId_textbookIdMap.get(classId);
             for (String id : dto.getIds()) {
-                if(tourseId_textbookIdList.contains(id)){
+                if(ObjectUtils.isNotEmpty(tourseId_textbookIdList) && !tourseId_textbookIdList.isEmpty() && tourseId_textbookIdList.contains(id)){
                     continue;
                 }
                 String[] idArr = id.split("_");
@@ -271,7 +249,12 @@ public class BaseClassCourseServiceImpl extends MPJBaseServiceImpl<BaseClassCour
     }
 
     @Override
+    @Transactional
     public Boolean updateRemoveCourseBook(ClassCourseTextbook dto){
+        if (ObjectUtils.isEmpty(dto.getClassIds()) || ObjectUtils.isEmpty(dto.getBaseSemesterId())) {
+            throw new MyException("请选中班级和学期");
+        }
+
 //        baseClassCourseMapper.updateRemoveClassCourseTextbooks(classId, courseId, textbookId);
         for (Long classId : dto.getClassIds()) {
             for (String id : dto.getIds()) {