|
@@ -1,6 +1,10 @@
|
|
|
package com.xjrsoft.module.classtime.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
+import com.alibaba.excel.EasyExcel;
|
|
|
+import com.alibaba.excel.ExcelWriter;
|
|
|
+import com.alibaba.excel.support.ExcelTypeEnum;
|
|
|
+import com.alibaba.excel.write.metadata.WriteSheet;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
@@ -11,7 +15,6 @@ import com.google.gson.JsonObject;
|
|
|
import com.google.gson.JsonParser;
|
|
|
import com.xjrsoft.common.enums.CourseAdjustTypeEnum;
|
|
|
import com.xjrsoft.common.enums.CourseTimeTypeEnum;
|
|
|
-import com.xjrsoft.common.enums.EnabledMark;
|
|
|
import com.xjrsoft.common.exception.MyException;
|
|
|
import com.xjrsoft.module.classtime.dto.AddClassTimeStatisticsDto;
|
|
|
import com.xjrsoft.module.classtime.entity.ClassTimeDelete;
|
|
@@ -29,9 +32,23 @@ import com.xjrsoft.module.classtime.vo.TeacherListVo;
|
|
|
import com.xjrsoft.module.classtime.vo.WeekTimeRangeVo;
|
|
|
import com.xjrsoft.module.oa.entity.WfTeacherCourseTime;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import org.apache.poi.ss.usermodel.BorderStyle;
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
+import org.apache.poi.ss.usermodel.Font;
|
|
|
+import org.apache.poi.ss.usermodel.HorizontalAlignment;
|
|
|
+import org.apache.poi.ss.usermodel.IndexedColors;
|
|
|
+import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
|
+import org.apache.poi.ss.usermodel.VerticalAlignment;
|
|
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
|
+import org.apache.poi.ss.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
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.time.DayOfWeek;
|
|
|
import java.time.LocalDate;
|
|
@@ -463,6 +480,336 @@ public class ClassTimeStatisticsServiceImpl extends MPJBaseServiceImpl<ClassTime
|
|
|
return this.baseMapper.getRecordList(id);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 导出课时统计明细
|
|
|
+ * @param id
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public byte[] recordExport(Long id) throws IOException {
|
|
|
+ //1、查询数据
|
|
|
+ List<ClassTimeStatisticsRecordVo> recordList = this.baseMapper.getRecordList(id);
|
|
|
+ //计算出一共有多少周
|
|
|
+ ClassTimeStatistics statistics = this.getById(id);
|
|
|
+ List<WeekTimeRangeVo> weekTimeRangeVos = calculateNaturalWeeks(statistics.getStartDate(), statistics.getEndDate());
|
|
|
+ /**
|
|
|
+ * 2、将查询出来的数据按照表头转换成二维数组
|
|
|
+ * 前端固定表头:序号、工号、姓名、教研会、督导听课、临近三年退休政策、出题、阅卷、周末培优、早自习、正课(含调顶课时)、晚辅(含调顶课时)、顶课、调课
|
|
|
+ * 中间动态表头:每周,总课时(含调顶课节)、顶课(节)、调课(节)、晚辅(节)......课时晚辅合计
|
|
|
+ * 后端固定表头:总课时、课时费(元)、外聘教师超课时费(元)、总金额(元)
|
|
|
+ */
|
|
|
+ //计算一共多少列
|
|
|
+ int column = 19 + (4 * weekTimeRangeVos.size());
|
|
|
+ List<ArrayList<String>> dataList = new ArrayList<>();
|
|
|
+ Integer sortCode = 1;
|
|
|
+ JsonParser parser = new JsonParser();
|
|
|
+ for (ClassTimeStatisticsRecordVo recordVo : recordList) {
|
|
|
+ ArrayList<String> rowData = new ArrayList<>();
|
|
|
+ rowData.add(sortCode.toString());//序号
|
|
|
+ rowData.add(recordVo.getUserName());//工号
|
|
|
+ rowData.add(recordVo.getName());//姓名
|
|
|
+ rowData.add(recordVo.getClassTime1()==null?"":recordVo.getClassTime1().toString());//教研会
|
|
|
+ rowData.add(recordVo.getClassTime2()==null?"":recordVo.getClassTime2().toString());//督导听课
|
|
|
+ rowData.add(recordVo.getClassTime3()==null?"":recordVo.getClassTime3().toString());//临近三年退休政策
|
|
|
+ rowData.add(recordVo.getClassTime4()==null?"":recordVo.getClassTime4().toString());//出题
|
|
|
+ rowData.add(recordVo.getClassTime5()==null?"":recordVo.getClassTime5().toString());//阅卷
|
|
|
+ rowData.add(recordVo.getClassTime6()==null?"":recordVo.getClassTime6().toString());//周末培优
|
|
|
+ rowData.add(recordVo.getClassTime7()==null?"":recordVo.getClassTime7().toString());//早自习
|
|
|
+ rowData.add(recordVo.getClassTime8()==null?"":recordVo.getClassTime8().toString());//正课(含调顶课时)
|
|
|
+ rowData.add(recordVo.getClassTime9()==null?"":recordVo.getClassTime9().toString());//晚辅(含调顶课时)
|
|
|
+ rowData.add(recordVo.getClassTime10()==null?"":recordVo.getClassTime10().toString());//顶课
|
|
|
+ rowData.add(recordVo.getClassTime11()==null?"":recordVo.getClassTime11().toString());//调课
|
|
|
+
|
|
|
+ //每周数据
|
|
|
+ JsonObject weekDataJson = parser.parse(recordVo.getWeekData()).getAsJsonObject();
|
|
|
+ JsonArray weekDataArray = weekDataJson.getAsJsonArray("weekData");
|
|
|
+ for (int i = 0; i < weekDataArray.size(); i ++){
|
|
|
+ JsonObject jsonElement = weekDataArray.get(i).getAsJsonObject();
|
|
|
+ rowData.add(jsonElement.get("zkTimes").getAsString());//总课时(含调顶课节)
|
|
|
+ rowData.add(jsonElement.get("dkTimes").getAsString());//顶课(节)
|
|
|
+ rowData.add(jsonElement.get("tkTimes").getAsString());//调课(节)
|
|
|
+ rowData.add(jsonElement.get("wzxTimes").getAsString());//晚辅(节)
|
|
|
+ }
|
|
|
+ rowData.add(weekDataJson.get("allTimes").getAsString());//课时晚辅合计
|
|
|
+
|
|
|
+ rowData.add(recordVo.getAllClassTime().toString());//总课时
|
|
|
+ rowData.add(recordVo.getClassTimeAmount().toString());//课时费(元)
|
|
|
+ rowData.add(recordVo.getBeyondClassTimeAmount()==null?"":recordVo.getBeyondClassTimeAmount().toString());//外聘教师超课时费(元)
|
|
|
+ rowData.add(recordVo.getTotalAmount().toString());//总金额(元)
|
|
|
+ dataList.add(rowData);
|
|
|
+ sortCode ++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 创建一个新的工作簿
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ // 创建一个工作表(sheet)
|
|
|
+ String sheetName = "数据";
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
+
|
|
|
+ // 创建一个字体对象
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setBold(true);// 设置为粗体
|
|
|
+ font.setFontName("宋体");
|
|
|
+ //font.setColor(IndexedColors.RED.getIndex()); // 设置字体颜色为红色
|
|
|
+ font.setFontHeightInPoints((short)24);
|
|
|
+
|
|
|
+
|
|
|
+ // 创建一个单元格样式对象
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+
|
|
|
+ // 第一行表头
|
|
|
+ {
|
|
|
+ Row row = sheet.createRow(0);
|
|
|
+ //合并第一行的列
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, column - 1));
|
|
|
+
|
|
|
+ //3、处理表头
|
|
|
+ String title1 = statistics.getYear() + "年" + statistics.getMonth() + "月课时统计";
|
|
|
+ // 创建单元格并设置值
|
|
|
+ Cell cell = row.createCell(0);
|
|
|
+ cell.setCellValue(title1);
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ //第二行表头
|
|
|
+ createSecondTitle(workbook, sheet, statistics, weekTimeRangeVos.size() * 4 + 1);
|
|
|
+
|
|
|
+ //第三行表头
|
|
|
+ createThirdTitle(workbook, sheet, statistics.getMonth(), weekTimeRangeVos, 13);
|
|
|
+ //第四行表头
|
|
|
+ createFourthTitle(workbook, sheet, weekTimeRangeVos, 13);
|
|
|
+ int dataRowNumber = 4;
|
|
|
+ //设置样式
|
|
|
+ font.setFontHeightInPoints((short)24);
|
|
|
+
|
|
|
+ // 创建一个单元格样式对象
|
|
|
+ cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ for (ArrayList<String> rowData : dataList) {
|
|
|
+ Row dataRow = sheet.createRow(dataRowNumber);
|
|
|
+ for (int i = 0; i < rowData.size(); i ++){
|
|
|
+ Cell row1cell2 = dataRow.createCell(i);
|
|
|
+ row1cell2.setCellValue(rowData.get(i));
|
|
|
+ row1cell2.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ dataRowNumber ++;
|
|
|
+ }
|
|
|
+ //写入文件
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
+ workbook.write(bot);
|
|
|
+ return bot.toByteArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成第二行表头
|
|
|
+ * 前端固定表头:序号、工号、姓名、教研会、督导听课、临近三年退休政策、出题、阅卷、周末培优、早自习、正课(含调顶课时)、晚辅(含调顶课时)、顶课、调课
|
|
|
+ * 中间动态表头:每周,总课时(含调顶课节)、顶课(节)、调课(节)、晚辅(节)......课时晚辅合计
|
|
|
+ * 后端固定表头:总课时、课时费(元)、外聘教师超课时费(元)、总金额(元)
|
|
|
+ */
|
|
|
+ void createSecondTitle(Workbook workbook, Sheet sheet, ClassTimeStatistics statistics, int mergeCoulmn){
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
+
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+
|
|
|
+ Row row1 = sheet.createRow(1);
|
|
|
+ Cell row1cell1 = row1.createCell(0);
|
|
|
+ row1cell1.setCellValue("序号");
|
|
|
+ row1cell1.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell2 = row1.createCell(1);
|
|
|
+ row1cell2.setCellValue("工号");
|
|
|
+ row1cell2.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell3 = row1.createCell(2);
|
|
|
+ row1cell3.setCellValue("姓名");
|
|
|
+ row1cell3.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell4 = row1.createCell(3);
|
|
|
+ row1cell4.setCellValue("教研会");
|
|
|
+ row1cell4.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell5 = row1.createCell(4);
|
|
|
+ row1cell5.setCellValue("督导听课");
|
|
|
+ row1cell5.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell6 = row1.createCell(5);
|
|
|
+ row1cell6.setCellValue("临近三年退休政策");
|
|
|
+ row1cell6.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell7 = row1.createCell(6);
|
|
|
+ row1cell7.setCellValue("出题");
|
|
|
+ row1cell7.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell8 = row1.createCell(7);
|
|
|
+ row1cell8.setCellValue("阅卷");
|
|
|
+ row1cell8.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell9 = row1.createCell(8);
|
|
|
+ row1cell9.setCellValue("周末培优");
|
|
|
+ row1cell9.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell10 = row1.createCell(9);
|
|
|
+ row1cell10.setCellValue("早自习");
|
|
|
+ row1cell10.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell11 = row1.createCell(10);
|
|
|
+ row1cell11.setCellValue("正课(含调顶课时)");
|
|
|
+ row1cell11.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell12 = row1.createCell(11);
|
|
|
+ row1cell12.setCellValue("晚辅(含调顶课时)");
|
|
|
+ row1cell12.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell13 = row1.createCell(12);
|
|
|
+ row1cell13.setCellValue("顶课");
|
|
|
+ row1cell13.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell14 = row1.createCell(13);
|
|
|
+ row1cell14.setCellValue("调课");
|
|
|
+ row1cell14.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell15 = row1.createCell(14);
|
|
|
+ row1cell15.setCellValue("正课课时数(平台导出" + statistics.getMonth() + "月)");
|
|
|
+ row1cell15.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ int index = 14 + mergeCoulmn;
|
|
|
+ Cell row1cell16 = row1.createCell(index);
|
|
|
+ row1cell16.setCellValue("总课时");
|
|
|
+ row1cell16.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell17 = row1.createCell(index + 1);
|
|
|
+ row1cell17.setCellValue("课时费(元)");
|
|
|
+ row1cell17.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell18 = row1.createCell(index + 2);
|
|
|
+ row1cell18.setCellValue("外聘教师超课时费(元)");
|
|
|
+ row1cell18.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ Cell row1cell19 = row1.createCell(index + 3);
|
|
|
+ row1cell19.setCellValue("总金额(元)");
|
|
|
+ row1cell19.setCellStyle(cellStyle);
|
|
|
+ //合并表头
|
|
|
+ for(int i = 0; i < 14; i ++){
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(1, 3, i, i));
|
|
|
+ }
|
|
|
+
|
|
|
+ //合并中间动态表头
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(1, 1, 14, index - 1));
|
|
|
+ //合并前端表头
|
|
|
+ for(int i = index; i < index + 4; i ++){
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(1, 3, i, i));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成第三行表头
|
|
|
+ * 关于周的表头,周一日期到周二日期,第几周,最后拼接一个单独的月份
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @param sheet
|
|
|
+ * @param month 月份
|
|
|
+ * @param weekTimeRangeVos 周的数据,包含周一的日期周二的日期
|
|
|
+ * @param lastIndex 前一个表头的单元格
|
|
|
+ */
|
|
|
+ void createThirdTitle(Workbook workbook, Sheet sheet, int month, List<WeekTimeRangeVo> weekTimeRangeVos, int lastIndex){
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
+
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+
|
|
|
+ //设置内容
|
|
|
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MM.dd");
|
|
|
+ int rowNumber = 2;
|
|
|
+ Row row2 = sheet.createRow(rowNumber);
|
|
|
+
|
|
|
+ for(int i = 0; i < weekTimeRangeVos.size(); i ++){
|
|
|
+ WeekTimeRangeVo rangeVo = weekTimeRangeVos.get(i);
|
|
|
+ String cellValue = rangeVo.getMondayDate().format(formatter) + "-"
|
|
|
+ + rangeVo.getSundayDate().format(formatter) + "(第" + rangeVo.getWeeks() + "周)";
|
|
|
+ Cell row1cell1 = row2.createCell(lastIndex + 1 + (i * 4));
|
|
|
+ row1cell1.setCellValue(cellValue);
|
|
|
+ row1cell1.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ //合并单元格
|
|
|
+ int monthIndex = 0;
|
|
|
+ for(int i = 0; i < weekTimeRangeVos.size(); i ++){
|
|
|
+ int startCoulmn = lastIndex + 1 + (i * 4);
|
|
|
+ int endCoulmn = startCoulmn + 3;
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, startCoulmn, endCoulmn));
|
|
|
+ monthIndex = endCoulmn;
|
|
|
+ }
|
|
|
+
|
|
|
+ Cell row1cell2 = row2.createCell(monthIndex + 1);
|
|
|
+ row1cell2.setCellValue(month + "月");
|
|
|
+ row1cell2.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生成第四行表头
|
|
|
+ * 表头内容:总课时(含调顶课节)、顶课(节)、顶课(节)、晚辅(节)、课时晚辅合计
|
|
|
+ *
|
|
|
+ * @param workbook
|
|
|
+ * @param sheet
|
|
|
+ * @param weekTimeRangeVos 周的数据,包含周一的日期周二的日期
|
|
|
+ * @param lastIndex 前一个表头的单元格
|
|
|
+ */
|
|
|
+ void createFourthTitle(Workbook workbook, Sheet sheet, List<WeekTimeRangeVo> weekTimeRangeVos, int lastIndex){
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
+
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+
|
|
|
+ int rowNumber = 3;
|
|
|
+ Row row2 = sheet.createRow(rowNumber);
|
|
|
+ int index = lastIndex + 1;
|
|
|
+ for(int i = 0; i < weekTimeRangeVos.size(); i ++){
|
|
|
+ Cell row1cell1 = row2.createCell(index);
|
|
|
+ row1cell1.setCellValue("总课时(含调顶课节)");
|
|
|
+ row1cell1.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ index ++;
|
|
|
+ Cell row1cell2 = row2.createCell(index);
|
|
|
+ row1cell2.setCellValue("顶课(节)");
|
|
|
+ row1cell2.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ index ++;
|
|
|
+ Cell row1cell3 = row2.createCell(index);
|
|
|
+ row1cell3.setCellValue("顶课(节)");
|
|
|
+ row1cell3.setCellStyle(cellStyle);
|
|
|
+ index ++;
|
|
|
+ Cell row1cell4 = row2.createCell(index);
|
|
|
+ row1cell4.setCellValue("晚辅(节)");
|
|
|
+ row1cell4.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ index ++;
|
|
|
+ }
|
|
|
+ Cell row1cell5 = row2.createCell(index);
|
|
|
+ row1cell5.setCellValue("课时晚辅合计");
|
|
|
+ row1cell5.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
//计算日期内一共几个周,并返回每周的周一日期和周日日期
|
|
|
private static List<WeekTimeRangeVo> calculateNaturalWeeks(LocalDate startDate, LocalDate endDate) {
|
|
|
List<WeekTimeRangeVo> result = new ArrayList<>();
|