Преглед на файлове

教材管理发放记录导出

大数据与最优化研究所 преди 1 година
родител
ревизия
f91c4b3f44

+ 8 - 6
src/main/java/com/xjrsoft/module/textbook/controller/TextbookController.java

@@ -194,7 +194,9 @@ public class TextbookController {
             baseSemesterLambdaQueryWrapper
                     .eq(BaseSemester::getId, dto.getBaseSemesterId());
             BaseSemester baseSemester = baseSemesterService.getOne(baseSemesterLambdaQueryWrapper);
-            baseSemesterCn = baseSemester.getName();
+            if(baseSemester != null){
+                baseSemesterCn = baseSemester.getName();
+            }
         }
         String headTitle = "重庆市铜梁职业教育中心" + baseSemesterCn + "教材征订表";
         List<List<String>> headList = new ArrayList<>();
@@ -272,12 +274,12 @@ public class TextbookController {
         return RT.fileStream(bot.toByteArray(), "TextbookSubscription" + ExcelTypeEnum.XLSX.getValue());
     }
 
-//    @PostMapping("/textbook-claim-export-query")
-//    @ApiOperation(value = "教材发放记录条件导出")
-//    public ResponseEntity<byte[]> textbookClaimExportQuery(@Valid @RequestBody TextbookClaimExportQueryDto dto) {
-    @GetMapping("/textbook-claim-export-query")
+    @PostMapping("/textbook-claim-export-query")
     @ApiOperation(value = "教材发放记录条件导出")
-    public ResponseEntity<byte[]> textbookClaimExportQuery(@Valid TextbookClaimExportQueryDto dto) {
+    public ResponseEntity<byte[]> textbookClaimExportQuery(@Valid @RequestBody TextbookClaimExportQueryDto dto) {
+//    @GetMapping("/textbook-claim-export-query")
+//    @ApiOperation(value = "教材发放记录条件导出")
+//    public ResponseEntity<byte[]> textbookClaimExportQuery(@Valid TextbookClaimExportQueryDto dto) {
         ByteArrayOutputStream bot = textbookService.listTextbookClaimExportQuery(dto);
         return RT.fileStream(bot.toByteArray(), "TextbookClaim" + ExcelTypeEnum.XLSX.getValue());
     }

+ 72 - 21
src/main/java/com/xjrsoft/module/textbook/service/impl/TextbookServiceImpl.java

@@ -22,6 +22,7 @@ import com.xjrsoft.common.enums.WarehouseModeEnum;
 import com.xjrsoft.common.exception.MyException;
 import com.xjrsoft.common.utils.excel.ExcelFillCellMergePrevColUtil;
 import com.xjrsoft.module.base.entity.BaseClass;
+import com.xjrsoft.module.base.entity.BaseClassroom;
 import com.xjrsoft.module.base.entity.BaseSemester;
 import com.xjrsoft.module.base.mapper.BaseClassMapper;
 import com.xjrsoft.module.base.service.IBaseClassService;
@@ -40,10 +41,7 @@ import org.springframework.transaction.annotation.Transactional;
 
 import java.io.ByteArrayOutputStream;
 import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.Objects;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -605,24 +603,77 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
             WriteTable writeSheetHeadTable = EasyExcel.writerTable(tableIndex).needHead(Boolean.TRUE).head(sheetHeadList).registerWriteHandler(sheetHeadColumn).build();
             excelWriter.write(new ArrayList<>(), writeSheet, writeSheetHeadTable);
 
-            for (int i = 0; i < 3; i++){
-                //这是一个table的表头
-                List<List<String>> tableHeadList = new ArrayList<List<String>>();
-                tableHeadList.add(new ArrayList<String>(){{
-                    add("日期:2023春期 班级:23数控1班 班主任:路童话 教室:4502");
-                }});
-                //table的表头合并策略
-                ExcelFillCellMergePrevColUtil tableHeadColumn = new ExcelFillCellMergePrevColUtil();
-                tableHeadColumn.add(++rowIndex, 0, 9);
-                //这是一个table表头的table
-                WriteTable writeTableHeadTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).head(tableHeadList).registerWriteHandler(tableHeadColumn).build();
-                excelWriter.write(new ArrayList<>(), writeSheet, writeTableHeadTable);
-                // 这里必须指定需要头,table 会继承sheet的配置,sheet配置了不需要,table 默认也是不需要
-                WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).build();
-                // 第一次写入会创建头
-                excelWriter.write(customerList, writeSheet, writeContentTable);
-                rowIndex += (1 + customerList.size());
+            //对返回的集合进行处理
+            //现针对学期进行分组
+            Map<Long, List<TextbookClaimExportQueryVo>> groupedBySemester = customerList.stream()
+                    .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getBaseSemesterId));
+
+            Iterator<Map.Entry<Long, List<TextbookClaimExportQueryVo>>> groupedBySemesterIterator = groupedBySemester.entrySet().iterator();
+            while (groupedBySemesterIterator.hasNext()) {
+                Map.Entry<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterEntry = groupedBySemesterIterator.next();
+                Long key = groupedBySemesterEntry.getKey();
+                List<TextbookClaimExportQueryVo> value = groupedBySemesterEntry.getValue();
+
+                Map<Long, List<TextbookClaimExportQueryVo>> groupedBySemesterByClass = value.stream()
+                        .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getClassId));
+
+                Iterator<Map.Entry<Long, List<TextbookClaimExportQueryVo>>> groupedBySemesterByClassIdIterator = groupedBySemesterByClass.entrySet().iterator();
+                while (groupedBySemesterByClassIdIterator.hasNext()) {
+                    Map.Entry<Long, List<TextbookClaimExportQueryVo>> entry = groupedBySemesterByClassIdIterator.next();
+                    Long k = entry.getKey();
+                    List<TextbookClaimExportQueryVo> v = entry.getValue();
+
+                    //这是一个table的表头
+                    List<List<String>> tableHeadList = new ArrayList<List<String>>();
+                    tableHeadList.add(new ArrayList<String>(){{
+                        //获取班级相关信息
+                        MPJLambdaWrapper<BaseClass> baseClassMPJLambdaWrapper = new MPJLambdaWrapper<>();
+                        baseClassMPJLambdaWrapper
+                                .selectAs(BaseClass::getName, ClassInfo::getClassName)
+                                .selectAs(XjrUser::getName, ClassInfo::getHeadTeacherName)
+                                .selectAs(BaseClassroom::getName, ClassInfo::getClassRoomName)
+                                .leftJoin(XjrUser.class, XjrUser::getId, BaseClass::getTeacherId)
+                                .leftJoin(BaseClassroom.class, BaseClassroom::getId, BaseClass::getClassroomId)
+                                .eq(BaseClass::getId, k)
+                                .disableSubLogicDel();
+                        ClassInfo classInfo = baseClassService.selectJoinOne(ClassInfo.class, baseClassMPJLambdaWrapper);
+                        if(classInfo != null){
+                            add("日期:" + key + " 班级:" + classInfo.getClassName() + " 班主任:" + classInfo.getHeadTeacherName() + " 教室:" + classInfo.getClassRoomName() + " ");
+                        }
+                        add("日期:" + key);
+                    }});
+                    //table的表头合并策略
+                    ExcelFillCellMergePrevColUtil tableHeadColumn = new ExcelFillCellMergePrevColUtil();
+                    tableHeadColumn.add(++rowIndex, 0, 9);
+                    //这是一个table表头的table
+                    WriteTable writeTableHeadTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).head(tableHeadList).registerWriteHandler(tableHeadColumn).build();
+                    excelWriter.write(new ArrayList<>(), writeSheet, writeTableHeadTable);
+                    // 这里必须指定需要头,table 会继承sheet的配置,sheet配置了不需要,table 默认也是不需要
+                    WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).build();
+                    // 第一次写入会创建头
+                    excelWriter.write(v, writeSheet, writeContentTable);
+                    rowIndex += (1 + v.size());
+                }
             }
+
+//            for (int i = 0; i < 3; i++){
+//                //这是一个table的表头
+//                List<List<String>> tableHeadList = new ArrayList<List<String>>();
+//                tableHeadList.add(new ArrayList<String>(){{
+//                    add("日期:2023春期 班级:23数控1班 班主任:路童话 教室:4502");
+//                }});
+//                //table的表头合并策略
+//                ExcelFillCellMergePrevColUtil tableHeadColumn = new ExcelFillCellMergePrevColUtil();
+//                tableHeadColumn.add(++rowIndex, 0, 9);
+//                //这是一个table表头的table
+//                WriteTable writeTableHeadTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).head(tableHeadList).registerWriteHandler(tableHeadColumn).build();
+//                excelWriter.write(new ArrayList<>(), writeSheet, writeTableHeadTable);
+//                // 这里必须指定需要头,table 会继承sheet的配置,sheet配置了不需要,table 默认也是不需要
+//                WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).build();
+//                // 第一次写入会创建头
+//                excelWriter.write(customerList, writeSheet, writeContentTable);
+//                rowIndex += (1 + customerList.size());
+//            }
         }
 
         // EasyExcel.write(bot, TextbookClaimExportQueryVo.class).automaticMergeHead(true).excelType(ExcelTypeEnum.XLSX).sheet().doWrite(customerList);

+ 10 - 0
src/main/java/com/xjrsoft/module/textbook/vo/ClassInfo.java

@@ -0,0 +1,10 @@
+package com.xjrsoft.module.textbook.vo;
+
+import lombok.Data;
+
+@Data
+public class ClassInfo {
+    private String className;
+    private String headTeacherName;
+    private String classRoomName;
+}

+ 12 - 11
src/main/resources/mapper/textbook/TextbookMapper.xml

@@ -186,13 +186,13 @@
         <if test="dto.textbookType != null and dto.textbookType != ''">
             and t1.textbook_type = #{dto.textbookType}
         </if>
-        <if test="dto.baseSemesterId != null">
+        <if test="dto.baseSemesterId != null and dto.baseSemesterId > 0">
             and t1.base_semester_id = #{dto.baseSemesterId}
         </if>
-        <if test="dto.subjectGroupId != null">
+        <if test="dto.subjectGroupId != null and dto.subjectGroupId > 0">
             and t1.subject_group_id = #{dto.subjectGroupId}
         </if>
-        <if test="dto.courseSubjectId != null">
+        <if test="dto.courseSubjectId != null and dto.courseSubjectId > 0">
             and t1.course_subject_id = #{dto.courseSubjectId}
         </if>
         <if test="dto.bookName != null and dto.bookName != ''">
@@ -238,13 +238,13 @@
         <if test="dto.textbookType != null and dto.textbookType != ''">
             and t8.textbook_type = #{dto.textbookType}
         </if>
-        <if test="dto.baseSemesterId != null">
+        <if test="dto.baseSemesterId != null and dto.baseSemesterId > 0">
             and t8.base_semester_id = #{dto.baseSemesterId}
         </if>
-        <if test="dto.subjectGroupId != null">
+        <if test="dto.subjectGroupId != null and dto.subjectGroupId > 0">
             and t8.subject_group_id = #{dto.subjectGroupId}
         </if>
-        <if test="dto.courseSubjectId != null">
+        <if test="dto.courseSubjectId != null and dto.courseSubjectId > 0">
             and t8.course_subject_id = #{dto.courseSubjectId}
         </if>
         <if test="dto.bookName != null and dto.bookName != ''">
@@ -271,13 +271,13 @@
                 left join wf_textbook_claim_item t1 on t1.wf_textbook_claim_id = t.id
                 left join textbook t2 on t2.id = t1.textbook_id
             where claim_type = 'claim_student'
-            <if test="dto.baseSemesterId != null">
+            <if test="dto.baseSemesterId != null and dto.baseSemesterId > 0">
                 amd t.base_semester_id = #{dto.baseSemesterId}
             </if>
-            <if test="dto.classId != null">
+            <if test="dto.classId != null and dto.classId > 0">
                 and t.class_id = #{dto.classId}
             </if>
-            <if test="dto.textbookId != null">
+            <if test="dto.textbookId != null and dto.textbookId > 0">
                 and t1.textbook_id = #{dto.textbookId}
             </if>
             group by t.base_semester_id, t.class_id, t1.textbook_id
@@ -302,10 +302,10 @@
             <if test="dto.textbookType != null and dto.textbookType != ''">
                 and t1.textbook_type = #{dto.textbookType}
             </if>
-            <if test="dto.subjectGroupId != null">
+            <if test="dto.subjectGroupId != null and dto.subjectGroupId > 0">
                 and t1.subject_group_id = #{dto.subjectGroupId}
             </if>
-            <if test="dto.courseSubjectId != null">
+            <if test="dto.courseSubjectId != null and dto.courseSubjectId > 0">
                 and t1.course_subject_id = #{dto.courseSubjectId}
             </if>
             <if test="dto.bookName != null and dto.bookName != ''">
@@ -318,5 +318,6 @@
                 and t1.issn like concat('%', #{dto.issn}, '%')
             </if>
         </where>
+        order by t2.name desc
     </select>
 </mapper>