Bladeren bron

教材征订班级征订获取班级教材信息

大数据与最优化研究所 1 maand geleden
bovenliggende
commit
bf6d5f3c50

+ 0 - 3
src/main/java/com/xjrsoft/module/textbook/dto/TextbookSubscriptionListDto.java

@@ -28,7 +28,4 @@ public class TextbookSubscriptionListDto extends PageInput {
 
     @ApiModelProperty("学期id")
     public Long baseSemesterId;
-
-    @ApiModelProperty(value = "班级ids", hidden = true)
-    public List<String> classIdList;
 }

+ 83 - 35
src/main/java/com/xjrsoft/module/textbook/service/impl/TextbookServiceImpl.java

@@ -23,10 +23,7 @@ import com.xjrsoft.common.page.ConventPage;
 import com.xjrsoft.common.utils.VoToColumnUtil;
 import com.xjrsoft.common.utils.excel.ExcelFillCellMergePrevColUtil;
 import com.xjrsoft.common.utils.excel.ExcelMergeUtil;
-import com.xjrsoft.module.base.entity.BaseClass;
-import com.xjrsoft.module.base.entity.BaseClassCourse;
-import com.xjrsoft.module.base.entity.BaseCourseSubject;
-import com.xjrsoft.module.base.entity.BaseSemester;
+import com.xjrsoft.module.base.entity.*;
 import com.xjrsoft.module.base.mapper.BaseClassCourseMapper;
 import com.xjrsoft.module.base.mapper.BaseCourseSubjectMapper;
 import com.xjrsoft.module.base.mapper.BaseSemesterMapper;
@@ -968,7 +965,6 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
             String[] classIdArr =  dto.getClassIds().split(",");
             classIdList = Arrays.asList(classIdArr);
         }
-        dto.setClassIdList(classIdList);
 
         // 找到可以使用多个学期且已经征订的教材
         MPJLambdaWrapper<BaseClassCourse> subscribedTextbook = new MPJLambdaWrapper<>();
@@ -984,7 +980,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
                 .innerJoin(Textbook.class, Textbook::getId, BaseClassCourse::getTextbookId)
                 .gt(Textbook::getUseType, 1)
                 .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
-                .in(BaseClassCourse::getClassId, dto.getClassIdList())
+                .in(BaseClassCourse::getClassId, classIdList)
         ;
         List<BaseClassCourse> baseClassCourses = baseClassCourseMapper.selectJoinList(BaseClassCourse.class, subscribedTextbook);
 
@@ -1007,7 +1003,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
                         .selectAs(DictionaryDetail::getName, TextbookSubscriptionListVo::getTextbookTypeCn)
                 )
                 .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
-                .in(BaseClassCourse::getClassId, dto.getClassIdList())
+                .in(BaseClassCourse::getClassId, classIdList)
                 .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
                 .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
                 .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
@@ -1024,7 +1020,7 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
                         .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
                         .eq(BaseClassCourse::getTextbookId, t.getTextbookId())
                         .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
-                        .in(BaseClassCourse::getClassId, dto.getClassIdList())
+                        .in(BaseClassCourse::getClassId, classIdList)
                         .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
                         .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
                 ;
@@ -1040,28 +1036,33 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
 
     @Override
     public List<TextbookSubscriptionListVo> getSubscriptionListByClass(TextbookSubscriptionListDto dto) {
-        List<String> classIdList = new ArrayList<>();
-        if(dto.getClassIds() != null && !"".equals(dto.getClassIds())){
-            String[] classIdArr =  dto.getClassIds().split(",");
-            classIdList = Arrays.asList(classIdArr);
+        if(StringUtils.isBlank(dto.getClassIds())){
+            throw new MyException("请选择需要征订教材的班级");
+        }
+        String[] classIdArr =  dto.getClassIds().split(",");
+        List<String> classIdList = Arrays.asList(classIdArr);
+        if(ObjectUtils.isEmpty(classIdList)){
+            throw new MyException("请选择需要征订教材的班级");
         }
-        dto.setClassIdList(classIdList);
 
         // 找到可以使用多个学期且已经征订的教材
         MPJLambdaWrapper<BaseClassCourse> subscribedTextbook = new MPJLambdaWrapper<>();
         subscribedTextbook
                 .distinct()
                 .select(BaseClassCourse::getId)
-                .innerJoin(TextbookSubscriptionClass.class, TextbookSubscriptionClass::getBaseClassId, BaseClassCourse::getClassId)
+                .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getId, BaseClassCourse::getClassId)
+
+                .innerJoin(TextbookSubscriptionClass.class, TextbookSubscriptionClass::getBaseClassId, BaseClassAdminCourse::getClassId)
                 .innerJoin(TextbookSubscriptionItem.class, wrapper -> wrapper
                         .eq(TextbookSubscriptionItem::getTextbookSubscriptionId, TextbookSubscriptionClass::getTextbookSubscriptionId)
                         .eq(TextbookSubscriptionItem::getTextbookId, BaseClassCourse::getTextbookId)
                 )
 
                 .innerJoin(Textbook.class, Textbook::getId, BaseClassCourse::getTextbookId)
+
                 .gt(Textbook::getUseType, 1)
-                .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
-                .in(BaseClassCourse::getClassId, dto.getClassIdList())
+                .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
+                .in(BaseClassAdminCourse::getClassId, classIdList)
         ;
         List<BaseClassCourse> baseClassCourses = baseClassCourseMapper.selectJoinList(BaseClassCourse.class, subscribedTextbook);
 
@@ -1077,39 +1078,86 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
                 .selectAs(BaseClassCourse::getTextbookId, TextbookSubscriptionListVo::getTextbookId)
                 .selectAs(BaseCourseSubject::getName, TextbookSubscriptionListVo::getCourseName)
                 .select(Textbook.class, x -> VoToColumnUtil.fieldsToColumns(TextbookSubscriptionListVo.class).contains(x.getProperty()))
+
+                .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getId, BaseClassCourse::getClassId)
+
                 .innerJoin(Textbook.class, Textbook::getId, BaseClassCourse::getTextbookId)
+
                 .leftJoin(BaseCourseSubject.class, BaseCourseSubject::getId, BaseClassCourse::getCourseId)
                 .leftJoin(DictionaryDetail.class, DictionaryDetail::getCode, Textbook::getTextbookType,
                         wrapper -> wrapper
                                 .selectAs(DictionaryDetail::getName, TextbookSubscriptionListVo::getTextbookTypeCn)
                 )
-                .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
-                .in(BaseClassCourse::getClassId, dto.getClassIdList())
+
+                .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
+                .in(BaseClassAdminCourse::getClassId, classIdList)
                 .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
-                .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
+                .eq(BaseClassAdminCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
                 .eq(Textbook::getDeleteMark, DeleteMark.NODELETE.getCode())
         ;
         List<TextbookSubscriptionListVo> textbookSubscriptionListVoList = baseClassCourseMapper.selectJoinList(TextbookSubscriptionListVo.class, baseClassCourseMPJLambdaWrapper);
-//        IPage<TextbookSubscriptionListVo> page = this.baseMapper.getSubscriptionPageByClass(new Page<>(dto.getLimit(), dto.getSize()), dto);
+
+        List<String> textbookIds = textbookSubscriptionListVoList.stream()
+                .map(TextbookSubscriptionListVo::getTextbookId)
+                .distinct() // 去重操作
+                .collect(Collectors.toList());
 
         // 处理每本教材使用的人数
-        if(!classIdList.isEmpty()) {
-            for(TextbookSubscriptionListVo t : textbookSubscriptionListVoList){
-                MPJLambdaWrapper<BaseClassCourse> countNum = new MPJLambdaWrapper<>();
-                countNum
-                        .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassCourse::getClassId)
-                        .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
-                        .eq(BaseClassCourse::getTextbookId, t.getTextbookId())
-                        .eq(BaseClassCourse::getBaseSemesterId, dto.getBaseSemesterId())
-                        .in(BaseClassCourse::getClassId, dto.getClassIdList())
-                        .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
-                        .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
-                ;
-                Long num = baseClassCourseMapper.selectCount(countNum);
-                t.setStudentSubscriptionNumber(num.intValue());
+        if(ObjectUtils.isNotEmpty(textbookIds)){
+            MPJLambdaWrapper<BaseClassCourse> countNum = new MPJLambdaWrapper<>();
+            countNum
+                    .selectAs(BaseClassCourse::getTextbookId, TextbookSubscriptionListVo::getTextbookId)
+                    .selectCount(BaseStudentSchoolRoll::getId, TextbookSubscriptionListVo::getStudentSubscriptionNumber)
+
+                    .innerJoin(BaseClassAdminCourse.class, BaseClassAdminCourse::getId, BaseClassCourse::getClassId)
+
+                    .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassAdminCourse::getClassId)
+
+                    .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
+                    .in(BaseClassCourse::getTextbookId, textbookIds)
+                    .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
+                    .in(BaseClassAdminCourse::getClassId, classIdList)
+                    .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
+                    .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
+                    .groupBy(BaseClassCourse::getTextbookId)
+            ;
 
-                t.setClassIds(dto.getClassIds());
+            List<TextbookSubscriptionListVo> countStuNumList = baseClassCourseMapper.selectJoinList(TextbookSubscriptionListVo.class, countNum);
+
+            Map<String, Integer> countStuNumMap = countStuNumList.stream()
+                    .collect(Collectors.toMap(TextbookSubscriptionListVo::getTextbookId, TextbookSubscriptionListVo::getStudentSubscriptionNumber, (t1, t2) -> t1));
+
+            if(ObjectUtils.isNotEmpty(countStuNumMap)){
+                for(TextbookSubscriptionListVo t : textbookSubscriptionListVoList){
+                    Integer num = countStuNumMap.get(t.getTextbookId());
+                    if(ObjectUtils.isNotEmpty(num)){
+                        t.setStudentSubscriptionNumber(num);
+                    }else {
+                        t.setStudentSubscriptionNumber(0);
+                    }
+                    t.setClassIds(dto.getClassIds());
+                }
             }
+
+//        for(TextbookSubscriptionListVo t : textbookSubscriptionListVoList){
+//            MPJLambdaWrapper<BaseClassAdminCourse> countNum = new MPJLambdaWrapper<>();
+//            countNum
+//                    .innerJoin(BaseClassCourse.class, BaseClassCourse::getClassId, BaseClassAdminCourse::getId)
+//
+//                    .innerJoin(BaseStudentSchoolRoll.class, BaseStudentSchoolRoll::getClassId, BaseClassAdminCourse::getClassId)
+//
+//                    .eq(BaseStudentSchoolRoll::getArchivesStatus, ArchivesStatusEnum.FB2901.getCode())
+//                    .eq(BaseClassCourse::getTextbookId, t.getTextbookId())
+//                    .eq(BaseClassAdminCourse::getBaseSemesterId, dto.getBaseSemesterId())
+//                    .in(BaseClassAdminCourse::getClassId, dto.getClassIdList())
+//                    .notIn(!baseClassCourseIds.isEmpty(), BaseClassCourse::getId, baseClassCourseIds)
+//                    .eq(BaseClassCourse::getDeleteMark, DeleteMark.NODELETE.getCode())
+//            ;
+//            Long num = baseClassCourseMapper.selectCount(countNum);
+//            t.setStudentSubscriptionNumber(num.intValue());
+//
+//            t.setClassIds(dto.getClassIds());
+//        }
         }
 
         return textbookSubscriptionListVoList;