Forráskód Böngészése

优化教材导出接口

大数据与最优化研究所 1 éve
szülő
commit
19382236cc

+ 9 - 0
src/main/java/com/xjrsoft/common/enums/TimeNumberEnum.java

@@ -59,4 +59,13 @@ public enum TimeNumberEnum {
         }
         return 0;
     }
+
+    public static String getValue(int code) {
+        for (TimeNumberEnum c : TimeNumberEnum.values()) {
+            if (c.getCode() == code) {
+                return c.getValue();
+            }
+        }
+        return "";
+    }
 }

+ 9 - 0
src/main/java/com/xjrsoft/common/enums/TimePeriodEnum.java

@@ -42,4 +42,13 @@ public enum TimePeriodEnum {
         }
         return 0;
     }
+
+    public static String getValue(int code) {
+        for (TimePeriodEnum c : TimePeriodEnum.values()) {
+            if (c.getCode() == code) {
+                return c.getValue();
+            }
+        }
+        return "";
+    }
 }

+ 165 - 35
src/main/java/com/xjrsoft/module/courseTable/service/impl/CourseTableServiceImpl.java

@@ -6,6 +6,8 @@ import cn.hutool.core.date.DateTime;
 import cn.hutool.core.date.DateUtil;
 import cn.hutool.core.util.ObjectUtil;
 import cn.hutool.core.util.StrUtil;
+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.query.QueryWrapper;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
@@ -42,15 +44,22 @@ import com.xjrsoft.module.schedule.util.ScheduleUtil;
 import com.xjrsoft.module.schedule.vo.CourseDetailVo;
 import com.xjrsoft.module.schedule.vo.CourseListVo;
 import com.xjrsoft.module.schedule.vo.CourseTableVo;
+import com.xjrsoft.module.schedule.vo.ScheduleWeekExportQueryVo;
 import com.xjrsoft.module.teacher.entity.BaseTeacher;
 import com.xjrsoft.module.teacher.entity.XjrUser;
 import com.xjrsoft.module.teacher.service.ITeacherbaseManagerService;
+import com.xjrsoft.module.textbook.entity.SubjectGroupCourse;
+import com.xjrsoft.module.textbook.vo.TextbookClaimExportQueryVo;
+import com.xjrsoft.module.textbook.vo.TextbookIssueRecordExcelVo;
+import io.swagger.models.auth.In;
 import lombok.AllArgsConstructor;
 import org.apache.poi.xwpf.usermodel.XWPFDocument;
 import org.apache.poi.xwpf.usermodel.XWPFParagraph;
 import org.apache.poi.xwpf.usermodel.XWPFTable;
 import org.apache.poi.xwpf.usermodel.XWPFTableCell;
 import org.apache.poi.xwpf.usermodel.XWPFTableRow;
+import org.checkerframework.checker.units.qual.C;
+import org.springframework.beans.BeanUtils;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
@@ -63,10 +72,7 @@ import java.time.LocalDate;
 import java.time.LocalDateTime;
 import java.time.ZoneId;
 import java.time.format.DateTimeFormatter;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -152,7 +158,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
     public List<ClassListVo> classList(ClassListDto dto) {
         LambdaQueryWrapper<CourseTable> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(CourseTable::getClassId, dto.getClassId())
-                .eq(ObjectUtil.isNotEmpty(dto.getWeeks()), CourseTable::getWeeks,dto.getWeeks());
+                .eq(ObjectUtil.isNotEmpty(dto.getWeeks()), CourseTable::getWeeks, dto.getWeeks());
 
         List<CourseTable> courseTables = courseTableMapper.selectList(queryWrapper);
 
@@ -183,13 +189,13 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
     public CourseTableVo getList(CourseTableDto dto) {
 
         List<ClassTime> classTimes = classTimeMapper.selectList(
-            new QueryWrapper<ClassTime>().lambda().orderByAsc(ClassTime::getSummerStartTime)
+                new QueryWrapper<ClassTime>().lambda().orderByAsc(ClassTime::getSummerStartTime)
         );
 
         CourseTableVo tableVo = new CourseTableVo();
         tableVo.setClassTimeList(classTimes);
 
-        if(dto.getSemesterId() != null){
+        if (dto.getSemesterId() != null) {
             BaseSemester baseSemester = baseSemesterMapper.selectById(dto.getSemesterId());
             tableVo.setSemesterName(baseSemester.getName());
             LocalDateTime now = LocalDateTime.now();
@@ -199,16 +205,16 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
             Duration between = Duration.between(startDateTime, endDateTime);
             long days = between.toDays();
             int weeks = (int) Math.ceil((double) days / 7);
-            if(dto.getWeek() == null){
+            if (dto.getWeek() == null) {
 
-                for (int i = 0; i < weeks; i ++){
+                for (int i = 0; i < weeks; i++) {
                     LocalDateTime startDate = startDateTime.plusDays(i * 6).withHour(0).withMinute(0).withSecond(0).withNano(0);
                     LocalDateTime endDate = startDateTime.plusDays((i + 1) * 6).withHour(23).withMinute(59).withSecond(59).withNano(9999);
-                    if(now.isAfter(startDate) && now.isBefore(endDate)){
+                    if (now.isAfter(startDate) && now.isBefore(endDate)) {
                         tableVo.setWeek("第" + (i + 1) + "周");
                     }
                 }
-            }else{
+            } else {
                 LocalDateTime startDate = startDateTime.plusDays((dto.getWeek() - 1) * 6).withHour(0).withMinute(0).withSecond(0).withNano(0);
                 LocalDateTime endDate = startDateTime.plusDays(dto.getWeek() * 6).withHour(23).withMinute(59).withSecond(59).withNano(9999);
                 dto.setStartDate(startDate);
@@ -217,17 +223,17 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
             }
 
         }
-        if(!StrUtil.isEmpty(dto.getTeacherName())){
+        if (!StrUtil.isEmpty(dto.getTeacherName())) {
             List<XjrUser> userList = teacherbaseManagerService.list(
-                new QueryWrapper<XjrUser>().lambda()
-                .like(!StrUtil.isEmpty(dto.getTeacherName()), XjrUser::getName, dto.getTeacherName())
+                    new QueryWrapper<XjrUser>().lambda()
+                            .like(!StrUtil.isEmpty(dto.getTeacherName()), XjrUser::getName, dto.getTeacherName())
             );
             List<XjrUser> userList2 = teacherbaseManagerService.list(
-                new QueryWrapper<XjrUser>().lambda()
-                .like(!StrUtil.isEmpty(dto.getTeacherName()), XjrUser::getCode, dto.getTeacherName())
+                    new QueryWrapper<XjrUser>().lambda()
+                            .like(!StrUtil.isEmpty(dto.getTeacherName()), XjrUser::getCode, dto.getTeacherName())
             );
             userList.addAll(userList2);
-            if(userList != null && !userList.isEmpty()){
+            if (userList != null && !userList.isEmpty()) {
                 XjrUser xjrUser = userList.get(0);
                 dto.setTeacherId(xjrUser.getId());
                 tableVo.setTeacherName(xjrUser.getName());
@@ -236,7 +242,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
         List<CourseDetailVo> list = courseTableMapper.getList(dto);
         tableVo.setCourseList(list);
         tableVo.setClassHour(list.size());
-        if(dto.getClassId() != null){
+        if (dto.getClassId() != null) {
             BaseClass baseClass = baseClassService.getById(dto.getClassId());
             tableVo.setClassName(baseClass.getName());
         }
@@ -250,7 +256,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
     @Override
     public List<CourseListVo> getAdjustList(String teacherId, String adjustDate, String classId) {
         CourseTableAdjustDto dto = new CourseTableAdjustDto();
-        if(adjustDate != null && !"".equals(adjustDate)){
+        if (adjustDate != null && !"".equals(adjustDate)) {
             DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
             LocalDate localDateTime = LocalDate.parse(adjustDate, formatter);
             DayOfWeek dayOfWeek = localDateTime.getDayOfWeek();
@@ -261,11 +267,11 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
         dto.setTeacherId(Long.parseLong(teacherId));
         List<CourseListVo> list = courseTableMapper.getAdjustList(dto);
         for (CourseListVo courseListVo : list) {
-            if(courseListVo.getTimePeriod() == 1){
+            if (courseListVo.getTimePeriod() == 1) {
                 courseListVo.setTimePeriodCn("上午");
-            }else if(courseListVo.getTimePeriod() == 2){
+            } else if (courseListVo.getTimePeriod() == 2) {
                 courseListVo.setTimePeriodCn("下午");
-            }else if(courseListVo.getTimePeriod() == 3){
+            } else if (courseListVo.getTimePeriod() == 3) {
                 courseListVo.setTimePeriodCn("晚上");
             }
         }
@@ -275,26 +281,26 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
 
     @Override
     public String getPreCheck(String preCheckType, String courseId, String swapCourseId, String swapDate, String subTeacherId) {
-        if(preCheckType != null && !"".equals(preCheckType)){
-            if(CourseAdjustTypeEnum.courseExchange.getCode().equals(preCheckType)){
+        if (preCheckType != null && !"".equals(preCheckType)) {
+            if (CourseAdjustTypeEnum.courseExchange.getCode().equals(preCheckType)) {
                 CourseTable courseTable = courseTableMapper.selectById(courseId);
                 CourseTable swapCourseTable = courseTableMapper.selectById(swapCourseId);
                 try {
                     DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                     LocalDate localDateTime = LocalDate.parse(swapDate, formatter);
                     JsonObject preCheck = getExtendPreCheck(localDateTime, courseTable, swapCourseTable);
-                    if(preCheck.get("code").getAsInt() == -1 && !preCheck.get("msg").isJsonNull()){
+                    if (preCheck.get("code").getAsInt() == -1 && !preCheck.get("msg").isJsonNull()) {
                         return preCheck.get("msg").getAsString();
                     }
                 } catch (Exception e) {
                     throw new RuntimeException(e);
                 }
 
-            }else if(CourseAdjustTypeEnum.courseSubstitute.getCode().equals(preCheckType)){
+            } else if (CourseAdjustTypeEnum.courseSubstitute.getCode().equals(preCheckType)) {
                 CourseTable courseTable = courseTableMapper.selectById(courseId);
                 try {
                     JsonObject jsonObject = substitutePreTestin(subTeacherId, courseTable);
-                    if(jsonObject.get("code").getAsInt() == -1 && !jsonObject.get("msg").isJsonNull()){
+                    if (jsonObject.get("code").getAsInt() == -1 && !jsonObject.get("msg").isJsonNull()) {
                         return jsonObject.get("msg").getAsString();
                     }
                 } catch (Exception e) {
@@ -307,7 +313,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
 
     @Override
     public Boolean adjustCourse(WfCourseAdjust courseAdjust) throws Exception {
-        if(CourseAdjustTypeEnum.courseExchange.getCode().equals(courseAdjust.getAdjustType())){
+        if (CourseAdjustTypeEnum.courseExchange.getCode().equals(courseAdjust.getAdjustType())) {
             //调课,将双方课程的日期(schedule_date)、时段(time_period)、节次(time_number)、周(week)、星期几(1-7)(weeks)、星期中文(weeks_cn)对调
             CourseTable courseTable = courseTableMapper.selectById(courseAdjust.getCourseId());
             CourseTable swapCourseTable = courseTableMapper.selectById(courseAdjust.getExchangeCourseId());
@@ -333,7 +339,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
             //提交调课接口
             sendExchange(courseTableBak, swapCourseTableBak, courseAdjust);
 
-        }else if(CourseAdjustTypeEnum.courseSubstitute.getCode().equals(courseAdjust.getAdjustType())){
+        } else if (CourseAdjustTypeEnum.courseSubstitute.getCode().equals(courseAdjust.getAdjustType())) {
             CourseTable courseTable = courseTableMapper.selectById(courseAdjust.getCourseId());
 
             courseTable.setTeacherId(courseAdjust.getExchangeTeacherId());
@@ -346,12 +352,133 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
 
     @Override
     public ByteArrayOutputStream listScheduleWeekExportQuery(ScheduleWeekExportQueryDto dto) {
+        // 创建一个字节输出流
+        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
 
-        return null;
+        // 获取课程表数据
+        CourseTableVo courseTableVo = getCourseTableVo(dto);
+
+        // 构建课程安排导出列表
+        List<ScheduleWeekExportQueryVo> scheduleWeekExportQueryVoList = buildScheduleWeekExportQueryList(courseTableVo);
+
+        // 将数据写入Excel文件
+        writeScheduleWeekExportToExcel(outputStream, scheduleWeekExportQueryVoList);
+
+        return outputStream;
+    }
+
+    private CourseTableVo getCourseTableVo(ScheduleWeekExportQueryDto dto) {
+        CourseTableDto courseTableDto = new CourseTableDto();
+        BeanUtils.copyProperties(dto, courseTableDto);
+        return this.getList(courseTableDto);
+    }
+
+    private List<ScheduleWeekExportQueryVo> buildScheduleWeekExportQueryList(CourseTableVo courseTableVo) {
+        List<ClassTime> classTimeList = courseTableVo.getClassTimeList();
+        List<CourseDetailVo> courseList = courseTableVo.getCourseList();
+        List<ScheduleWeekExportQueryVo> scheduleWeekExportQueryVoList = new ArrayList<>();
+
+        if (!courseList.isEmpty()) {
+            Map<Integer, Map<Integer, List<CourseDetailVo>>> courseDetailVoMap = buildCourseDetailMap(courseList);
+            scheduleWeekExportQueryVoList.addAll(buildScheduleWeekExportQueryVoList(courseDetailVoMap, classTimeList));
+        }
+
+        return scheduleWeekExportQueryVoList;
+    }
+
+    private Map<Integer, Map<Integer, List<CourseDetailVo>>> buildCourseDetailMap(List<CourseDetailVo> courseList) {
+        // 实现构建课程详情Map的逻辑
+        Map<Integer, Map<Integer, List<CourseDetailVo>>> courseDetailVoMap = new HashMap<>();
+
+        for (CourseDetailVo courseDetailVo : courseList) {
+            int timePeriod = Integer.parseInt(courseDetailVo.getTimePeriod().trim());
+            int timeNumber = Integer.parseInt(courseDetailVo.getTimeNumber().trim());
+
+            // 如果时间段不存在,则创建一个新的时间段Map
+            courseDetailVoMap.putIfAbsent(timePeriod, new HashMap<>());
+
+            // 获取当前时间段的Map
+            Map<Integer, List<CourseDetailVo>> timePeriodMap = courseDetailVoMap.get(timePeriod);
+
+            // 如果时间序号不存在,则创建一个新的课程列表
+            timePeriodMap.putIfAbsent(timeNumber, new ArrayList<>());
+
+            // 将课程详情添加到对应的时间段和时间序号中
+            timePeriodMap.get(timeNumber).add(courseDetailVo);
+        }
+
+        // 返回构建好的课程详情Map
+        return courseDetailVoMap;
+    }
+
+    private List<ScheduleWeekExportQueryVo> buildScheduleWeekExportQueryVoList(Map<Integer, Map<Integer, List<CourseDetailVo>>> courseDetailVoMap, List<ClassTime> classTimeList) {
+        List<ScheduleWeekExportQueryVo> scheduleWeekExportQueryVoList = new ArrayList<>();
+        // 实现构建ScheduleWeekExportQueryVo对象列表的逻辑
+        for (ClassTime classTime : classTimeList) {
+            ScheduleWeekExportQueryVo scheduleWeekExportQueryVo = new ScheduleWeekExportQueryVo();
+            scheduleWeekExportQueryVo.setTimePeriod(TimePeriodEnum.getValue(classTime.getTimePeriod()));
+            scheduleWeekExportQueryVo.setTimeNumber(TimeNumberEnum.getValue(classTime.getNumber()));
+
+            Map<Integer, List<CourseDetailVo>> timePeriodListMap = courseDetailVoMap.get(classTime.getTimePeriod());
+            if (timePeriodListMap != null) {
+                List<CourseDetailVo> courseDetailVoList = timePeriodListMap.get(classTime.getNumber());
+                if (courseDetailVoList != null) {
+                    Map<Integer, CourseDetailVo> courseDetailVoByWeeksMap = courseDetailVoList.stream()
+                            .collect(Collectors.toMap(CourseDetailVo::getWeeks, item -> item));
+
+                    for (int i = 1; i <= 7; i++) {
+                        CourseDetailVo courseDetailVo = courseDetailVoByWeeksMap.get(i);
+                        if (courseDetailVo != null) {
+                            String courseInfo = courseDetailVo.getCourseName() + " " +
+                                    courseDetailVo.getTeacherName() + " " +
+                                    courseDetailVo.getClassName() + " " +
+                                    courseDetailVo.getClassroomName() + " ";
+                            switch (i) {
+                                case 1:
+                                    scheduleWeekExportQueryVo.setMonday(courseInfo);
+                                    break;
+                                case 2:
+                                    scheduleWeekExportQueryVo.setTuesday(courseInfo);
+                                    break;
+                                case 3:
+                                    scheduleWeekExportQueryVo.setWednesday(courseInfo);
+                                    break;
+                                case 4:
+                                    scheduleWeekExportQueryVo.setThursday(courseInfo);
+                                    break;
+                                case 5:
+                                    scheduleWeekExportQueryVo.setFriday(courseInfo);
+                                    break;
+                                case 6:
+                                    scheduleWeekExportQueryVo.setSaturday(courseInfo);
+                                    break;
+                                case 7:
+                                    scheduleWeekExportQueryVo.setSunday(courseInfo);
+                                    break;
+                            }
+                        }
+                    }
+                }
+            }
+
+            scheduleWeekExportQueryVoList.add(scheduleWeekExportQueryVo);
+        }
+        // 返回构建好的ScheduleWeekExportQueryVo对象列表
+        return scheduleWeekExportQueryVoList;
+    }
+
+    private void writeScheduleWeekExportToExcel(ByteArrayOutputStream outputStream, List<ScheduleWeekExportQueryVo> scheduleWeekExportQueryVoList) {
+        // 将数据写入Excel文件
+        EasyExcel.write(outputStream, ScheduleWeekExportQueryVo.class)
+                .automaticMergeHead(true)
+                .excelType(ExcelTypeEnum.XLSX)
+                .sheet()
+                .doWrite(scheduleWeekExportQueryVoList);
     }
 
     /**
      * 提交顶课接口
+     *
      * @param courseTable
      * @param courseAdjust
      * @throws Exception
@@ -376,6 +503,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
 
     /**
      * 提交调课
+     *
      * @param courseTable
      * @param swapCourseTable
      * @throws Exception
@@ -401,7 +529,8 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
 
 
     /**
-     *  顶课预检查
+     * 顶课预检查
+     *
      * @param courseTable
      * @return 检查结果
      */
@@ -419,7 +548,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
         //生成签名
         String sign = ScheduleUtil.createSign(timestamp);
         String result = ScheduleUtil.doPost(url, jsonObject.toString(), sign, timestamp);
-        if(StrUtil.isEmpty(result)){
+        if (StrUtil.isEmpty(result)) {
             return null;
         }
 
@@ -427,8 +556,9 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
     }
 
     /**
-     *  调课预检查
-     * @param courseTable 需要调整的课程
+     * 调课预检查
+     *
+     * @param courseTable     需要调整的课程
      * @param swapCourseTable 对调的课程
      * @return 检查结果
      */
@@ -451,7 +581,7 @@ public class CourseTableServiceImpl extends ServiceImpl<CourseTableMapper, Cours
         //生成签名
         String sign = ScheduleUtil.createSign(timestamp);
         String result = ScheduleUtil.doPost(url, jsonObject.toString(), sign, timestamp);
-        if(StrUtil.isEmpty(result)){
+        if (StrUtil.isEmpty(result)) {
             return null;
         }
 

+ 11 - 5
src/main/java/com/xjrsoft/module/schedule/controller/ScheduleController.java

@@ -235,12 +235,18 @@ public class ScheduleController {
         return jsonParser.parse(result).getAsJsonObject();
     }
 
-    @PostMapping("/schedule-week-export-query")
-    @ApiOperation(value = "按周导出课表")
-    public ResponseEntity<byte[]> scheduleWeekExportQuery(@Valid @RequestBody ScheduleWeekExportQueryDto dto) {
-//    @GetMapping("/schedule-week-export-query")
+//    @PostMapping("/schedule-week-export-query")
 //    @ApiOperation(value = "按周导出课表")
-//    public ResponseEntity<byte[]> textbookClaimExportQuery(@Valid ScheduleWeekExportQueryDto dto) {
+//    public ResponseEntity<byte[]> scheduleWeekExportQuery(@Valid @RequestBody ScheduleWeekExportQueryDto dto) {
+    @GetMapping("/schedule-week-export-query")
+    @ApiOperation(value = "按周导出课表")
+    public ResponseEntity<byte[]> textbookClaimExportQuery(@Valid ScheduleWeekExportQueryDto dto) {
+        dto = new ScheduleWeekExportQueryDto(){{
+            setSemesterId(1753983822311616512L);
+            setCourseType("teacher");
+            setWeek(3);
+            setTeacherName("彭霞");
+        }};
         ByteArrayOutputStream bot = courseTableService.listScheduleWeekExportQuery(dto);
         return RT.fileStream(bot.toByteArray(), "scheduleWeek" + ExcelTypeEnum.XLSX.getValue());
     }

+ 58 - 0
src/main/java/com/xjrsoft/module/schedule/vo/ScheduleWeekExportQueryVo.java

@@ -0,0 +1,58 @@
+package com.xjrsoft.module.schedule.vo;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import com.alibaba.excel.annotation.write.style.ContentStyle;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import org.springframework.format.annotation.DateTimeFormat;
+
+/**
+ * 周课表导出
+ */
+@Data
+public class ScheduleWeekExportQueryVo {
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("时间")
+    @ApiModelProperty("时段(1=上午 2=下午 3=晚上)")
+    private String timePeriod;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("时间")
+    @ApiModelProperty("节次")
+    private String timeNumber;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("周一")
+    @ApiModelProperty("星期一的课")
+    private String monday;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("周二")
+    @ApiModelProperty("星期二的课")
+    private String tuesday;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("周三")
+    @ApiModelProperty("星期三的课")
+    private String wednesday;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("周四")
+    @ApiModelProperty("星期四的课")
+    private String thursday;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("周五")
+    @ApiModelProperty("星期五的课")
+    private String friday;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("周六")
+    @ApiModelProperty("星期六的课")
+    private String saturday;
+
+    @ContentStyle(dataFormat = 49)
+    @ExcelProperty("周日")
+    @ApiModelProperty("星期日的课")
+    private String sunday;
+}

+ 122 - 178
src/main/java/com/xjrsoft/module/textbook/service/impl/TextbookServiceImpl.java

@@ -40,11 +40,13 @@ import com.xjrsoft.module.textbook.vo.*;
 import lombok.AllArgsConstructor;
 import org.apache.poi.ss.usermodel.BorderStyle;
 import org.apache.poi.ss.usermodel.HorizontalAlignment;
+import org.apache.poi.ss.usermodel.IndexedColors;
 import org.apache.poi.ss.usermodel.VerticalAlignment;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -586,193 +588,135 @@ public class TextbookServiceImpl extends MPJBaseServiceImpl<TextbookMapper, Text
     @Override
     public ByteArrayOutputStream listTextbookClaimExportQuery(TextbookClaimExportQueryDto dto) {
         List<TextbookClaimExportQueryVo> customerList = textbookTextbookMapper.listTextbookClaimExportQuery(dto);
-
         ByteArrayOutputStream bot = new ByteArrayOutputStream();
-        //内容样式
+
+        // 创建内容样式
+        WriteCellStyle contentWriteCellStyle = createContentCellStyle();
+        // 创建头部样式
+        WriteCellStyle headWriteCellStyle = createHeadCellStyle();
+
+        try (ExcelWriter excelWriter = EasyExcel.write(bot, TextbookClaimExportQueryVo.class)
+                .registerWriteHandler(new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle))
+                .build()) {
+
+            int rowIndex = 0;
+            int tableIndex = 0;
+
+            writeSheetHead(excelWriter, rowIndex, tableIndex);
+
+            processTextbookClaimData(excelWriter, customerList, rowIndex, tableIndex);
+
+        }
+
+        return bot;
+    }
+
+    private WriteCellStyle createContentCellStyle() {
         WriteCellStyle contentWriteCellStyle = new WriteCellStyle();
-        //设计内容居中
-        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);// 水平居中
-        contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);// 垂直居中
-        contentWriteCellStyle.setWrapped(true); //设置自动换行;
-        // 设置字体
+        contentWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+        contentWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        contentWriteCellStyle.setWrapped(true);
+
         WriteFont contentWriteFont = new WriteFont();
-        contentWriteFont.setFontHeightInPoints((short) 12);//设置字体大小
-        contentWriteFont.setFontName("宋体"); //设置字体名字
-        contentWriteCellStyle.setWriteFont(contentWriteFont);//在样式用应用设置的字体;
-        //设置样式;
-        contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
-        contentWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
-        contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);  //设置左边框;
-        contentWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
-        contentWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
-        contentWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
-        contentWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
-        contentWriteCellStyle.setTopBorderColor((short) 0); ///设置顶边框颜色;
-
-        //设置头部样式
-        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
-        // 背景颜色
-//        headWriteCellStyle.setFillForegroundColor(IndexedColors.LIGHT_TURQUOISE1.getIndex());
-//        headWriteCellStyle.setFillPatternType(FillPatternType.SOLID_FOREGROUND);
+        contentWriteFont.setFontHeightInPoints((short) 12);
+        contentWriteFont.setFontName("宋体");
+        contentWriteCellStyle.setWriteFont(contentWriteFont);
+
+        contentWriteCellStyle.setBorderBottom(BorderStyle.THIN);
+        contentWriteCellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
+        contentWriteCellStyle.setBorderLeft(BorderStyle.THIN);
+        contentWriteCellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
+        contentWriteCellStyle.setBorderRight(BorderStyle.THIN);
+        contentWriteCellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
+        contentWriteCellStyle.setBorderTop(BorderStyle.THIN);
+        contentWriteCellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
+
+        return contentWriteCellStyle;
+    }
 
-        // 字体
+    private WriteCellStyle createHeadCellStyle() {
+        WriteCellStyle headWriteCellStyle = new WriteCellStyle();
         WriteFont headWriteFont = new WriteFont();
-        headWriteFont.setFontName("宋体");//设置字体名字
-        headWriteFont.setFontHeightInPoints((short)14);//设置字体大小
-        headWriteFont.setBold(true);//字体加粗
-        headWriteCellStyle.setWriteFont(headWriteFont); //在样式用应用设置的字体;
-
-        // 样式
-        headWriteCellStyle.setBorderBottom(BorderStyle.THIN);//设置底边框;
-        headWriteCellStyle.setBottomBorderColor((short) 0);//设置底边框颜色;
-        headWriteCellStyle.setBorderLeft(BorderStyle.THIN);  //设置左边框;
-        headWriteCellStyle.setLeftBorderColor((short) 0);//设置左边框颜色;
-        headWriteCellStyle.setBorderRight(BorderStyle.THIN);//设置右边框;
-        headWriteCellStyle.setRightBorderColor((short) 0);//设置右边框颜色;
-        headWriteCellStyle.setBorderTop(BorderStyle.THIN);//设置顶边框;
-        headWriteCellStyle.setTopBorderColor((short) 0); //设置顶边框颜色;
-
-        headWriteCellStyle.setWrapped(true);  //设置自动换行;
-
-        //设置头部标题居中
-        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);//设置水平对齐的样式为居中对齐;
-        headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);  //设置垂直对齐的样式为居中对齐;
-        headWriteCellStyle.setShrinkToFit(true);//设置文本收缩至合适
-
-        // 这个策略是 头是头的样式 内容是内容的样式 其他的策略可以自己实现
-        HorizontalCellStyleStrategy horizontalCellStyleStrategy =
-                new HorizontalCellStyleStrategy(headWriteCellStyle, contentWriteCellStyle);
-        try (ExcelWriter excelWriter = EasyExcel.write(bot, TextbookClaimExportQueryVo.class).registerWriteHandler(horizontalCellStyleStrategy).build()) {
-            //已经写入的行
-            int rowIndex = 0;
-            //已经写入的表
-            int tableIndex = 0;
-            // 把sheet设置为不需要头 不然会输出sheet的头 这样看起来第一个table 就有2个头了
-            WriteSheet writeSheet = EasyExcel.writerSheet("模板").needHead(Boolean.FALSE).build();
-
-            //sheet的表头
-            List<List<String>> sheetHeadList = new ArrayList<List<String>>();
-            sheetHeadList.add(new ArrayList<String>(){{
-                add("铜梁执教中心班级教材教辅发放情况表");
-            }});
-            //sheet的表头合并策略
-            ExcelFillCellMergePrevColUtil sheetHeadColumn = new ExcelFillCellMergePrevColUtil();
-            sheetHeadColumn.add(rowIndex, 0, 9);
-            //这是一个sheet表头的table
-            WriteTable writeSheetHeadTable = EasyExcel.writerTable(tableIndex).needHead(Boolean.TRUE).head(sheetHeadList).registerWriteHandler(sheetHeadColumn).build();
-            excelWriter.write(new ArrayList<>(), writeSheet, writeSheetHeadTable);
-
-            //对返回的集合进行处理
-            //现针对学期进行分组
-            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>> groupedBySemesterByClassIdEntry = groupedBySemesterByClassIdIterator.next();
-                    Long k = groupedBySemesterByClassIdEntry.getKey();
-                    List<TextbookClaimExportQueryVo> v = groupedBySemesterByClassIdEntry.getValue();
-
-                    //这是一个table的表头
-                    List<List<String>> tableHeadList = new ArrayList<List<String>>();
-                    tableHeadList.add(new ArrayList<String>(){{
-                        add("日期:" + v.get(0).getBaseSemesterIdCn() + " 班级:" + v.get(0).getClassIdCn() + " 班主任:" + v.get(0).getHeadTeacherName() + " 教室:" + v.get(0).getClassRoomName() + " ");
-                    }});
-                    //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);
-
-                    Map<String, List<TextbookClaimExportQueryVo>> groupedByTextbookType = v.stream()
-                            .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getTextbookTypeCn));
-                    Iterator<Map.Entry<String, List<TextbookClaimExportQueryVo>>> groupedByTextbookTypeIterator = groupedByTextbookType.entrySet().iterator();
-                    int index = 1;
-                    BigDecimal total = new BigDecimal("0");
-                    while (groupedByTextbookTypeIterator.hasNext()) {
-                        Map.Entry<String, List<TextbookClaimExportQueryVo>> groupedByTextbookTypeEntry = groupedByTextbookTypeIterator.next();
-                        String kk = groupedByTextbookTypeEntry.getKey();
-                        List<TextbookClaimExportQueryVo> vv = groupedByTextbookTypeEntry.getValue();
-                        if(index == 1){
-                            //添加小计
-                            ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
-                            subtotalColumn.add(rowIndex + vv.size() + 2, 1, 4);
-                            BigDecimal subtotal = new BigDecimal("0");
-                            for (TextbookClaimExportQueryVo tv : vv) {
-                                subtotal = subtotal.add(tv.getSubtotal());
-                            }
-                            BigDecimal finalSubtotal = subtotal;
-                            vv.add(new TextbookClaimExportQueryVo(){{
-                                setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
-                                setBookName("小计");
-                                setSubtotal(finalSubtotal);
-                            }});
-                            total = total.add(finalSubtotal);
-
-                            // 调用合并单元格工具类,此工具类是根据工程名称相同则合并后面数据
-                            int mergeRowIndex = rowIndex + 1;
-                            int[] mergeColumeIndex = {0};
-                            ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex);
-
-                            // 第一次必须指定需要头,table 会继承sheet的配置,sheet配置了不需要,table 默认也是不需要
-                            WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).registerWriteHandler(subtotalColumn).registerWriteHandler(excelFillCellMergeStrategy).build();
-                            // 第一次写入会创建头
-                            excelWriter.write(vv, writeSheet, writeContentTable);
-
-                            rowIndex += (1 + vv.size());
-                        }else {
-                            //添加小计
-                            ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
-                            subtotalColumn.add(rowIndex + vv.size() + 1, 1, 4);
-                            BigDecimal subtotal = new BigDecimal("0");
-                            for (TextbookClaimExportQueryVo tv : vv) {
-                                subtotal = subtotal.add(tv.getSubtotal());
-                            }
-                            BigDecimal finalSubtotal = subtotal;
-                            vv.add(new TextbookClaimExportQueryVo(){{
-                                setTextbookTypeCn(vv.get(0).getTextbookTypeCn());
-                                setBookName("小计");
-                                setSubtotal(finalSubtotal);
-                            }});
-                            total = total.add(finalSubtotal);
-                            // 调用合并单元格工具类,此工具类是根据工程名称相同则合并后面数据
-                            int mergeRowIndex = rowIndex;
-                            int[] mergeColumeIndex = {0};
-                            ExcelMergeUtil excelFillCellMergeStrategy = new ExcelMergeUtil(mergeRowIndex, mergeColumeIndex);
+        headWriteFont.setFontName("宋体");
+        headWriteFont.setFontHeightInPoints((short) 14);
+        headWriteFont.setBold(true);
+        headWriteCellStyle.setWriteFont(headWriteFont);
+
+        headWriteCellStyle.setBorderBottom(BorderStyle.THIN);
+        headWriteCellStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
+        headWriteCellStyle.setBorderLeft(BorderStyle.THIN);
+        headWriteCellStyle.setLeftBorderColor(IndexedColors.BLACK.getIndex());
+        headWriteCellStyle.setBorderRight(BorderStyle.THIN);
+        headWriteCellStyle.setRightBorderColor(IndexedColors.BLACK.getIndex());
+        headWriteCellStyle.setBorderTop(BorderStyle.THIN);
+        headWriteCellStyle.setTopBorderColor(IndexedColors.BLACK.getIndex());
+        headWriteCellStyle.setWrapped(true);
+        headWriteCellStyle.setHorizontalAlignment(HorizontalAlignment.CENTER);
+        headWriteCellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
+        headWriteCellStyle.setShrinkToFit(true);
+
+        return headWriteCellStyle;
+    }
 
-                            // 不需要头
-                            WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.FALSE).registerWriteHandler(subtotalColumn).registerWriteHandler(excelFillCellMergeStrategy).build();
-                            excelWriter.write(vv, writeSheet, writeContentTable);
+    private void writeSheetHead(ExcelWriter excelWriter, int rowIndex, int tableIndex) {
+        List<List<String>> sheetHeadList = new ArrayList<>();
+        sheetHeadList.add(Collections.singletonList("铜梁执教中心班级教材教辅发放情况表"));
 
-                            rowIndex += (vv.size());
-                        }
-                        index++;
-                    }
-                    //添加合计
-                    BigDecimal finalTotal = total;
-                    List<TextbookClaimExportQueryVo> totalList = new ArrayList<>();
-                    totalList.add(new TextbookClaimExportQueryVo(){{
-                        setTextbookTypeCn("合计");
-                        setSubtotal(finalTotal);
-                    }});
-                    //-合并策略
-                    ExcelFillCellMergePrevColUtil totaColumn = new ExcelFillCellMergePrevColUtil();
-                    totaColumn.add(++rowIndex, 0, 5);
-                    //这是一个合计的table
-                    WriteTable writeTotalTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.FALSE).registerWriteHandler(totaColumn).build();
-                    excelWriter.write(totalList, writeSheet, writeTotalTable);
-                }
+        ExcelFillCellMergePrevColUtil sheetHeadColumn = new ExcelFillCellMergePrevColUtil();
+        sheetHeadColumn.add(rowIndex, 0, 9);
+
+        WriteTable writeSheetHeadTable = EasyExcel.writerTable(tableIndex).needHead(Boolean.TRUE).head(sheetHeadList).registerWriteHandler(sheetHeadColumn).build();
+        excelWriter.write(new ArrayList<>(), EasyExcel.writerSheet("模板").build(), writeSheetHeadTable);
+    }
+
+    private void processTextbookClaimData(ExcelWriter excelWriter, List<TextbookClaimExportQueryVo> customerList, int rowIndex, int tableIndex) {
+        // 处理数据逻辑
+        // 写入数据到Excel表格
+        for (TextbookClaimExportQueryVo customer : customerList) {
+            List<List<String>> tableHeadList = new ArrayList<>();
+            tableHeadList.add(Collections.singletonList("日期:" + customer.getBaseSemesterIdCn() + " 班级:" + customer.getClassIdCn() + " 班主任:" + customer.getHeadTeacherName() + " 教室:" + customer.getClassRoomName()));
+
+            ExcelFillCellMergePrevColUtil tableHeadColumn = new ExcelFillCellMergePrevColUtil();
+            tableHeadColumn.add(++rowIndex, 0, 9);
+
+            WriteTable writeTableHeadTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).head(tableHeadList).registerWriteHandler(tableHeadColumn).build();
+            excelWriter.write(new ArrayList<>(), EasyExcel.writerSheet("模板").build(), writeTableHeadTable);
+
+            Map<String, List<TextbookClaimExportQueryVo>> groupedByTextbookType = customerList.stream()
+                    .filter(c -> c.getBaseSemesterId().equals(customer.getBaseSemesterId()) && c.getClassId().equals(customer.getClassId()))
+                    .collect(Collectors.groupingBy(TextbookClaimExportQueryVo::getTextbookTypeCn));
+
+            BigDecimal total = BigDecimal.ZERO;
+
+            for (Map.Entry<String, List<TextbookClaimExportQueryVo>> entry : groupedByTextbookType.entrySet()) {
+                List<TextbookClaimExportQueryVo> group = entry.getValue();
+
+                BigDecimal subtotal = group.stream()
+                        .map(TextbookClaimExportQueryVo::getSubtotal)
+                        .reduce(BigDecimal.ZERO, BigDecimal::add);
+
+                group.add(new TextbookClaimExportQueryVo("小计", subtotal));
+                total = total.add(subtotal);
+
+                ExcelFillCellMergePrevColUtil subtotalColumn = new ExcelFillCellMergePrevColUtil();
+                subtotalColumn.add(rowIndex + group.size() + 1, 1, 4);
+
+                WriteTable writeContentTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.TRUE).registerWriteHandler(subtotalColumn).build();
+                excelWriter.write(group, EasyExcel.writerSheet("模板").build(), writeContentTable);
+                rowIndex += group.size();
             }
+
+            List<TextbookClaimExportQueryVo> totalList = new ArrayList<>();
+            totalList.add(new TextbookClaimExportQueryVo("合计", total));
+
+            ExcelFillCellMergePrevColUtil totalColumn = new ExcelFillCellMergePrevColUtil();
+            totalColumn.add(++rowIndex, 0, 5);
+
+            WriteTable writeTotalTable = EasyExcel.writerTable(++tableIndex).needHead(Boolean.FALSE).registerWriteHandler(totalColumn).build();
+            excelWriter.write(totalList, EasyExcel.writerSheet("模板").build(), writeTotalTable);
+
+            rowIndex++;
         }
-        return bot;
     }
 
     @Override

+ 9 - 0
src/main/java/com/xjrsoft/module/textbook/vo/TextbookClaimExportQueryVo.java

@@ -102,4 +102,13 @@ public class TextbookClaimExportQueryVo {
     @ExcelProperty("备注")
     @ApiModelProperty("备注")
     private String remark;
+
+    public TextbookClaimExportQueryVo() {
+
+    }
+
+    public TextbookClaimExportQueryVo(String bookName, BigDecimal subtotal) {
+        this.bookName = bookName;
+        this.subtotal = subtotal;
+    }
 }

+ 2 - 1
src/main/resources/mapper/textbook/TextbookIssueRecordMapper.xml

@@ -20,7 +20,7 @@
         t1.create_date,
         t9.name  AS claim_user,
         t1.issue_number,
-        t3.base_semester_id as baseSemesterIdCn
+        t15.name as baseSemesterIdCn
         FROM textbook_issue_record t1
         LEFT JOIN wf_textbook_claim_item t2 ON t1.data_item_id = t2.id
         LEFT JOIN wf_textbook_claim t4 ON t1.data_id = t4.id
@@ -35,6 +35,7 @@
         LEFT JOIN xjr_user t9 ON t1.receive_user_id = t9.id
         LEFT JOIN xjr_dictionary_detail t10 ON t3.textbook_type = t10.code AND t10.item_id = 1739209191193636865
         LEFT JOIN xjr_dictionary_detail t11 ON t1.issue_mode = t11.code AND t11.item_id = 1739821685805215745
+        LEFT JOIN base_semester t15 ON t15.id = t3.base_semester_id
         WHERE t1.delete_mark = 0
         <if test="dto.textbookType != null and dto.textbookType != ''">
             and t3.textbook_type = #{dto.textbookType}

+ 2 - 1
src/main/resources/mapper/textbook/TextbookWarehouseRecordMapper.xml

@@ -19,7 +19,7 @@
         t1.create_date,
         t2.name AS warehouse_user,
         t1.warehouse_number,
-        t3.base_semester_id as baseSemesterIdCn,
+        t9.name as baseSemesterIdCn,
         (SELECT GROUP_CONCAT(c2.name)
         FROM textbook_class_relation c1
         LEFT JOIN base_class c2 ON c1.class_id = c2.id
@@ -33,6 +33,7 @@
         LEFT JOIN xjr_dictionary_detail t6 ON t3.textbook_type = t6.code AND t6.item_id = 1739209191193636865
         LEFT JOIN base_grade t7 ON t3.grade_id = t7.id
         LEFT JOIN textbook_class_relation t8 ON t8.textbook_id = t3.id
+        LEFT JOIN base_semester t9 ON t9.id = t3.base_semester_id
         WHERE t1.delete_mark = 0
         <if test="dto.textbookType != null and dto.textbookType != ''">
             and t3.textbook_type = #{dto.textbookType}