Bladeren bron

班级课程批量新增

大数据与最优化研究所 11 maanden geleden
bovenliggende
commit
2c222d7f6d

+ 2 - 8
src/main/java/com/xjrsoft/module/base/controller/BaseClassCourseController.java

@@ -164,14 +164,8 @@ public class BaseClassCourseController {
     @PostMapping("/updateRemoveCoursesAndTextbooks")
     @ApiOperation(value = "更新减少课程教材")
     @SaCheckPermission("baseclasscourse:detail")
-    public RT<Boolean> updateRemoveCoursesAndTextbooks(@Valid ClassCourseTextbook list) {
-        boolean isSuccess = true;
-        for (Long classId : list.getClassIds()) {
-            for (Long i = 0L; i < list.getCourseId().length; i++) {
-                baseClassCourseService.updateRemoveCourseBook(classId, list.getCourseId()[Math.toIntExact(i)], list.getTextbookId()[Math.toIntExact(i)]);
-            }
-        }
-        return RT.ok(isSuccess);
+    public RT<Boolean> updateRemoveCoursesAndTextbooks(@Valid  @RequestBody ClassCourseTextbook dto) {
+        return RT.ok(baseClassCourseService.updateRemoveCourseBook(dto));
     }
 
     @PostMapping("/insertClassCourseTextbookCombinations")

+ 2 - 2
src/main/java/com/xjrsoft/module/base/entity/ClassCourseTextbook.java

@@ -11,10 +11,10 @@ public class ClassCourseTextbook {
     @ApiModelProperty("主键id")
     private String[] ids;
 
-    @ApiModelProperty("课程id")
+    @ApiModelProperty(value = "课程id", hidden = true)
     private Long[] courseId;
 
-    @ApiModelProperty("教材id")
+    @ApiModelProperty(value = "教材id", hidden = true)
     private Long[] textbookId;
 
     /**

+ 1 - 1
src/main/java/com/xjrsoft/module/base/service/IBaseClassCourseService.java

@@ -34,7 +34,7 @@ public interface IBaseClassCourseService extends MPJBaseService<BaseClassCourse>
 
     Boolean updateAddCourseBook(ClassCourseTextbook dto);
 
-    void updateRemoveCourseBook(Long classId, Long courseId, Long textbookId);
+    Boolean updateRemoveCourseBook(ClassCourseTextbook dto);
 
     void markExistingRecordsAsDeleted(Long newClassId, Long sourceClassId);
 

+ 76 - 34
src/main/java/com/xjrsoft/module/base/service/impl/BaseClassCourseServiceImpl.java

@@ -3,6 +3,7 @@ package com.xjrsoft.module.base.service.impl;
 import com.alibaba.excel.EasyExcel;
 import com.alibaba.excel.support.ExcelTypeEnum;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.github.yulichang.base.MPJBaseServiceImpl;
 import com.github.yulichang.wrapper.MPJLambdaWrapper;
@@ -89,37 +90,60 @@ public class BaseClassCourseServiceImpl extends MPJBaseServiceImpl<BaseClassCour
 
         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())
         ;
-        isSuccess = this.remove(baseClassCourseLambdaQueryWrapper);
+        List<BaseClassCourse> oldList = this.list(baseClassCourseLambdaQueryWrapper);
 
-
-        // 获取所有班级的所有学生
-        LambdaQueryWrapper<BaseStudentSchoolRoll> baseStudentSchoolRollLambdaQueryWrapper = new LambdaQueryWrapper<>();
-        baseStudentSchoolRollLambdaQueryWrapper
-                .in(BaseStudentSchoolRoll::getClassId, classIdList)
-                .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
-                ;
-        List<BaseStudentSchoolRoll> baseStudentSchoolRolls = baseStudentSchoolRollMapper.selectList(baseStudentSchoolRollLambdaQueryWrapper);
-
-        Map<Long, List<Long>> userIdsMap = baseStudentSchoolRolls.stream()
-                .filter(student -> student.getClassId() != null && student.getUserId() != null)
+        // 使用Stream API和Lambda表达式生成所需的字符串列表
+        Map<Long, List<String>> tourseId_textbookIdMap = oldList.stream()
                 .collect(Collectors.groupingBy(
-                                BaseStudentSchoolRoll::getClassId, // 根据classId分组
-                                Collectors.mapping(BaseStudentSchoolRoll::getUserId, // 提取userId
-                                        Collectors.toList()) // 收集到List<Long>
+                        BaseClassCourse::getClassId,
+                        Collectors.mapping(
+                                course -> course.getCourseId() + "_" + course.getTextbookId(),
+                                Collectors.toList()
                         )
-                );
+                ));
+
+//        //删除班级的这学期的所有课程教材
+//        LambdaQueryWrapper<BaseClassCourse> baseClassCourseLambdaQueryWrapper = new LambdaQueryWrapper<>();
+//        baseClassCourseLambdaQueryWrapper
+//                .in(BaseClassCourse::getClassId, classIdList)
+//                .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
+//        ;
+//        isSuccess = this.remove(baseClassCourseLambdaQueryWrapper);
+
+//        // 获取所有班级的所有学生
+//        LambdaQueryWrapper<BaseStudentSchoolRoll> baseStudentSchoolRollLambdaQueryWrapper = new LambdaQueryWrapper<>();
+//        baseStudentSchoolRollLambdaQueryWrapper
+//                .in(BaseStudentSchoolRoll::getClassId, classIdList)
+//                .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
+//                ;
+//        List<BaseStudentSchoolRoll> baseStudentSchoolRolls = baseStudentSchoolRollMapper.selectList(baseStudentSchoolRollLambdaQueryWrapper);
+//
+//        Map<Long, List<Long>> userIdsMap = baseStudentSchoolRolls.stream()
+//                .filter(student -> student.getClassId() != null && student.getUserId() != null)
+//                .collect(Collectors.groupingBy(
+//                                BaseStudentSchoolRoll::getClassId, // 根据classId分组
+//                                Collectors.mapping(BaseStudentSchoolRoll::getUserId, // 提取userId
+//                                        Collectors.toList()) // 收集到List<Long>
+//                        )
+//                );
 
         List<BaseClassCourse> baseClassCourseList = new ArrayList<>();
-        List<TextbookStudentClaim> textbookStudentClaimList = 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;
@@ -133,29 +157,47 @@ public class BaseClassCourseServiceImpl extends MPJBaseServiceImpl<BaseClassCour
                     setTextbookId(textbookId);
                 }});
 
-                // 添加学生领取教材数据
-                List<Long> userIds = userIdsMap.get(classId);
-                for (Long userId : userIds) {
-                    textbookStudentClaimList.add(new TextbookStudentClaim() {{
-                        setStudentUserId(userId);
-                        setBaseSemesterId(dto.getBaseSemesterId());
-                        setClassId(classId);
-                        setTextbookId(textbookId);
-                    }});
-                }
+//                // 添加学生领取教材数据
+//                List<Long> userIds = userIdsMap.get(classId);
+//                for (Long userId : userIds) {
+//                    textbookStudentClaimList.add(new TextbookStudentClaim() {{
+//                        setStudentUserId(userId);
+//                        setBaseSemesterId(dto.getBaseSemesterId());
+//                        setClassId(classId);
+//                        setTextbookId(textbookId);
+//                    }});
+//                }
             }
         }
 
-        for (TextbookStudentClaim textbookStudentClaim : textbookStudentClaimList) {
-            textbookStudentClaimMapper.insert(textbookStudentClaim);
-        }
+//        for (TextbookStudentClaim textbookStudentClaim : textbookStudentClaimList) {
+//            textbookStudentClaimMapper.insert(textbookStudentClaim);
+//        }
         return this.saveBatch(baseClassCourseList);
-
     }
 
     @Override
-    public void updateRemoveCourseBook(Long classId, Long courseId, Long textbookId){
-        baseClassCourseMapper.updateRemoveClassCourseTextbooks(classId, courseId, textbookId);
+    public Boolean updateRemoveCourseBook(ClassCourseTextbook dto){
+//        baseClassCourseMapper.updateRemoveClassCourseTextbooks(classId, courseId, textbookId);
+        for (Long classId : dto.getClassIds()) {
+            for (String id : dto.getIds()) {
+                String[] idArr = id.split("_");
+                if (idArr[0].equals("") || idArr[1].equals("")) {
+                    continue;
+                }
+                Long courseId = Long.parseLong(idArr[0]);
+                Long textbookId = Long.parseLong(idArr[1]);
+                LambdaUpdateWrapper<BaseClassCourse> baseClassCourseLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
+                baseClassCourseLambdaUpdateWrapper
+                        .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
+                        .eq(BaseClassCourse::getClassId, classId)
+                        .eq(BaseClassCourse::getCourseId, classId)
+                        .eq(BaseClassCourse::getTextbookId, textbookId)
+                        ;
+                this.remove(baseClassCourseLambdaUpdateWrapper);
+            }
+        }
+        return true;
     }
 
     @Override

+ 21 - 18
src/main/resources/mapper/base/BaseClassCourse.xml

@@ -36,7 +36,7 @@
         <if test="dto.semester != null">
             AND t5.base_semester_id = #{dto.semester}
         </if>
-        ) AS total_price,
+        ) AS amount,
         (SELECT sum(t8.discount_price)
         FROM base_class_course t5
         LEFT JOIN textbook t8 ON t8.id = t5.textbook_id
@@ -69,33 +69,36 @@
 
 
     <select id="getAllCourseBook" resultType="com.xjrsoft.module.base.entity.CourseBookInfo">
-        SELECT t.course_subject_id                    AS courseId,
-        t1.name                  AS courseName,
-        t.book_name              AS bookName,
-        t.id                     AS bookId,
-        concat(t.course_subject_id, '_', t.id) AS id,
-        t.issn,
-        t.editor_in_chief,
-        t.version
+        SELECT
+            t.course_subject_id                    AS courseId,
+            t1.name                  AS courseName,
+            t.book_name              AS bookName,
+            t.id                     AS bookId,
+            concat(t.course_subject_id, '_', t.id) AS id,
+            t.issn,
+            t.editor_in_chief,
+            t.version
         FROM textbook t
-        LEFT JOIN base_course_subject t1 ON t.course_subject_id = t1.id
+            LEFT JOIN base_course_subject t1 ON t.course_subject_id = t1.id
         WHERE t.delete_mark = 0
         AND t.course_subject_id IS NOT NULL
+        AND t1.delete_mark = 0
         <if test="subjectGroupId != null">
             AND t.subject_group_id = #{subjectGroupId}
         </if>
-        <if test="semester != null">
-            AND EXISTS (
-            SELECT 1
-            FROM textbook tb
-            WHERE tb.id = t.id
-            AND tb.base_semester_id = #{semester}
-            )
-        </if>
+<!--        <if test="semester != null">-->
+<!--            AND EXISTS (-->
+<!--            SELECT 1-->
+<!--            FROM textbook tb-->
+<!--            WHERE tb.id = t.id-->
+<!--            AND tb.base_semester_id = #{semester}-->
+<!--            )-->
+<!--        </if>-->
     </select>
 
     <select id="getSelectedCourseBook" resultType="com.xjrsoft.module.base.entity.CourseBookInfo">
         select
+            distinct
             t.course_id as courseId,
             t2.name as courseName,
             t1.book_name as bookName,