|
@@ -1,12 +1,37 @@
|
|
package com.xjrsoft.module.classtime.service.impl;
|
|
package com.xjrsoft.module.classtime.service.impl;
|
|
|
|
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
import com.github.yulichang.base.MPJBaseServiceImpl;
|
|
|
|
+import com.google.gson.JsonArray;
|
|
|
|
+import com.google.gson.JsonElement;
|
|
|
|
+import com.google.gson.JsonObject;
|
|
|
|
+import com.google.gson.JsonParser;
|
|
|
|
+import com.xjrsoft.common.exception.MyException;
|
|
|
|
+import com.xjrsoft.module.classtime.entity.ClassTimeStatistics;
|
|
import com.xjrsoft.module.classtime.entity.ClassTimeStatisticsRecord;
|
|
import com.xjrsoft.module.classtime.entity.ClassTimeStatisticsRecord;
|
|
import com.xjrsoft.module.classtime.mapper.ClassTimeStatisticsRecordMapper;
|
|
import com.xjrsoft.module.classtime.mapper.ClassTimeStatisticsRecordMapper;
|
|
import com.xjrsoft.module.classtime.service.IClassTimeStatisticsRecordService;
|
|
import com.xjrsoft.module.classtime.service.IClassTimeStatisticsRecordService;
|
|
|
|
+import com.xjrsoft.module.classtime.service.IClassTimeStatisticsService;
|
|
import lombok.AllArgsConstructor;
|
|
import lombok.AllArgsConstructor;
|
|
|
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
|
|
+import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
|
+import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
|
+import org.apache.poi.ss.usermodel.Font;
|
|
|
|
+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.Workbook;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFColor;
|
|
|
|
+import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
|
+import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTColor;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.awt.*;
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* @title: 课时统计
|
|
* @title: 课时统计
|
|
* @Author dzx
|
|
* @Author dzx
|
|
@@ -16,5 +41,125 @@ import org.springframework.stereotype.Service;
|
|
@Service
|
|
@Service
|
|
@AllArgsConstructor
|
|
@AllArgsConstructor
|
|
public class ClassTimeStatisticsServiceRecordImpl extends MPJBaseServiceImpl<ClassTimeStatisticsRecordMapper, ClassTimeStatisticsRecord> implements IClassTimeStatisticsRecordService {
|
|
public class ClassTimeStatisticsServiceRecordImpl extends MPJBaseServiceImpl<ClassTimeStatisticsRecordMapper, ClassTimeStatisticsRecord> implements IClassTimeStatisticsRecordService {
|
|
|
|
+ private final IClassTimeStatisticsService statisticsService;
|
|
|
|
+ /**
|
|
|
|
+ * 导出教师的明细
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ @Override
|
|
|
|
+ public byte[] recordDetailExportQuery(Long id){
|
|
|
|
+ try {
|
|
|
|
+ ClassTimeStatisticsRecord record = this.getById(id);
|
|
|
|
+ ClassTimeStatistics statistics = statisticsService.getById(record.getClassTimeStatisticsId());
|
|
|
|
+
|
|
|
|
+ String allClassTimeData = record.getAllClassTimeData();
|
|
|
|
+ JsonParser parser = new JsonParser();
|
|
|
|
+ JsonObject allClassTimeDataJson = parser.parse(allClassTimeData).getAsJsonObject();
|
|
|
|
+ JsonArray data = allClassTimeDataJson.get("data").getAsJsonArray();
|
|
|
|
+ int allRowNumber = data.size() + 2;//表格最大行号
|
|
|
|
+ JsonArray rowTitle = allClassTimeDataJson.get("rowTitle").getAsJsonArray();
|
|
|
|
+ int allColumnNumber = rowTitle.size() + 2;//表格最大列号
|
|
|
|
+ //总的数据
|
|
|
|
+ List<ArrayList<String>> allDataList = new ArrayList<>();
|
|
|
|
+
|
|
|
|
+ //1、组装execel表头
|
|
|
|
+ int rowNumber = 0;
|
|
|
|
+ ArrayList<String> rowTitleList = new ArrayList<>();
|
|
|
|
+ ArrayList<String> lastRowDataList = new ArrayList<>();
|
|
|
|
+ rowTitleList.add("课程名称(计算课时)");
|
|
|
|
+ lastRowDataList.add("合计(课时)");
|
|
|
|
+ rowNumber ++;
|
|
|
|
+
|
|
|
|
+ Map<Integer, String> columnNumberMap = new HashMap<>();
|
|
|
|
+ for (JsonElement jsonElement : rowTitle) {
|
|
|
|
+ JsonObject rowTitleJson = jsonElement.getAsJsonObject();
|
|
|
|
+ String scheduleDate = rowTitleJson.get("scheduleDate").getAsString();
|
|
|
|
+ rowTitleList.add(scheduleDate);
|
|
|
|
+
|
|
|
|
+ columnNumberMap.put(rowNumber, statistics.getYear() +"-" + scheduleDate.replace(".", "-"));
|
|
|
|
+ rowNumber ++;
|
|
|
|
+ }
|
|
|
|
+ rowTitleList.add("合计(课时)");
|
|
|
|
+ allDataList.add(rowTitleList);
|
|
|
|
+ //数据
|
|
|
|
+ JsonArray columnTitle = allClassTimeDataJson.get("columnTitle").getAsJsonArray();
|
|
|
|
+ for (JsonElement columnElement : columnTitle) {
|
|
|
|
+ JsonObject columnJson = columnElement.getAsJsonObject();
|
|
|
|
+ ArrayList<String> rowDataList = new ArrayList<>();
|
|
|
|
+ rowDataList.add(columnJson.get("type").getAsString());
|
|
|
|
+ String type = columnJson.get("type").getAsString();
|
|
|
|
+ for (Integer i : columnNumberMap.keySet()) {
|
|
|
|
+ String scheduleDate = columnNumberMap.get(i);
|
|
|
|
+ for (JsonElement datum : data) {
|
|
|
|
+ JsonObject dataJson = datum.getAsJsonObject();
|
|
|
|
+ if(type.equals(dataJson.get("type").getAsString()) && scheduleDate.equals(dataJson.get("scheduleDate").getAsString())){
|
|
|
|
+ rowDataList.add(dataJson.get("content").getAsString());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ rowDataList.add(columnJson.get("content").getAsString());
|
|
|
|
+ allDataList.add(rowDataList);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ lastRowDataList.add(allClassTimeDataJson.get("allClassTime").getAsString());
|
|
|
|
+ allDataList.add(lastRowDataList);
|
|
|
|
+
|
|
|
|
+ //Map<String, XSSFColor> stringXSSFColorMap = initColorMap();
|
|
|
|
+ // 创建一个新的工作簿
|
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
|
+ // 创建一个工作表(sheet)
|
|
|
|
+ String sheetName = "数据";
|
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
|
+
|
|
|
|
+ // 创建一个字体对象
|
|
|
|
+ Font font = workbook.createFont();
|
|
|
|
+ font.setFontName("宋体");
|
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
|
+
|
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
|
+ cellStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());//设置背景颜色
|
|
|
|
+ cellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//设置填充模式
|
|
|
|
+ cellStyle.setFont(font);
|
|
|
|
+
|
|
|
|
+ CellStyle lastCellStyle = workbook.createCellStyle();
|
|
|
|
+ lastCellStyle.setFillForegroundColor(IndexedColors.BLUE.getIndex());//设置背景颜色
|
|
|
|
+ lastCellStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);//设置填充模式
|
|
|
|
+ lastCellStyle.setFont(font);
|
|
|
|
+
|
|
|
|
+ for (int i = 0; i < allRowNumber; i ++){
|
|
|
|
+ Row row = sheet.createRow(i);
|
|
|
|
+ ArrayList<String> rowData = allDataList.get(i);
|
|
|
|
+ for (int j = 0; j < allColumnNumber; j ++) {
|
|
|
|
+ Cell cell = row.createCell(j);
|
|
|
|
+ cell.setCellValue(rowData.get(j));
|
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
|
+ if(i == allRowNumber - 1 && j == allColumnNumber - 1){
|
|
|
|
+ cell.setCellStyle(lastCellStyle);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //写入文件
|
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
|
+ workbook.write(bot);
|
|
|
|
+ return bot.toByteArray();
|
|
|
|
+ }catch(Exception e){
|
|
|
|
+ log.error(e.getMessage());
|
|
|
|
+ throw new MyException("导出失败,请联系管理员");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Map<String, XSSFColor> initColorMap(){
|
|
|
|
+ Map<String, XSSFColor> colorMap = new HashMap<>();
|
|
|
|
+ String cssColor = "#ec808d";
|
|
|
|
+ XSSFColor color = new XSSFColor((CTColor) Color.decode(cssColor), null);
|
|
|
|
+ colorMap.put("course_substitute", color);
|
|
|
|
+
|
|
|
|
+ cssColor = "#facd91";
|
|
|
|
+ color = new XSSFColor((CTColor) Color.decode(cssColor), null);
|
|
|
|
+ colorMap.put("course_exchange", color);
|
|
|
|
|
|
|
|
+ return colorMap;
|
|
|
|
+ }
|
|
}
|
|
}
|