|
@@ -2,11 +2,27 @@ package com.qmth.distributed.print.business.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.qmth.distributed.print.business.bean.excel.ExcelField;
|
|
|
+import com.qmth.distributed.print.business.bean.result.ScoreNormalResult;
|
|
|
import com.qmth.distributed.print.business.entity.TCScoreNormal;
|
|
|
import com.qmth.distributed.print.business.mapper.TCScoreNormalMapper;
|
|
|
import com.qmth.distributed.print.business.service.TCScoreNormalService;
|
|
|
+import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
|
+import com.qmth.teachcloud.common.util.ExcelUtil;
|
|
|
+import com.qmth.teachcloud.common.util.ServletUtil;
|
|
|
+import org.apache.poi.ss.usermodel.FillPatternType;
|
|
|
+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.util.CellRangeAddress;
|
|
|
+import org.apache.poi.xssf.usermodel.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import javax.servlet.ServletOutputStream;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.URLEncoder;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -26,10 +42,98 @@ public class TCScoreNormalServiceImpl extends ServiceImpl<TCScoreNormalMapper, T
|
|
|
* @param iPage
|
|
|
* @param semesterId
|
|
|
* @param examId
|
|
|
+ * @param courseCode
|
|
|
* @return
|
|
|
*/
|
|
|
@Override
|
|
|
- public IPage<Map> scoreList(IPage<Map> iPage, Long semesterId, Long examId) {
|
|
|
- return this.baseMapper.scoreList(iPage, semesterId, examId);
|
|
|
+ public IPage<ScoreNormalResult> scoreList(IPage<Map> iPage, Long semesterId, Long examId, String courseCode) {
|
|
|
+ return this.baseMapper.scoreList(iPage, semesterId, examId, courseCode);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 动态生成excel
|
|
|
+ *
|
|
|
+ * @param describe
|
|
|
+ * @param sheetName
|
|
|
+ * @param fileName
|
|
|
+ * @param excelFieldList
|
|
|
+ * @throws IOException
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public void downLoadExaminationTemplate(String describe, String sheetName, String fileName, List<ExcelField> excelFieldList) throws IOException {
|
|
|
+ HttpServletResponse response = ServletUtil.getResponse();
|
|
|
+ log.debug("导出Excel开始...");
|
|
|
+ XSSFWorkbook wb = new XSSFWorkbook();
|
|
|
+ response.setHeader("Content-Disposition", "inline;filename=" + URLEncoder.encode(fileName, SystemConstant.CHARSET_NAME) + ExcelUtil.DEFALUT_EXT);
|
|
|
+ response.setContentType(ExcelUtil.DEFALUT_CONTENT_TYPE);
|
|
|
+ XSSFSheet sheet = wb.createSheet(sheetName);
|
|
|
+
|
|
|
+ Font defaultFont = wb.createFont();
|
|
|
+ defaultFont.setFontHeightInPoints((short) 12);
|
|
|
+ defaultFont.setFontName("宋体");
|
|
|
+
|
|
|
+ int cellCount = excelFieldList.size();
|
|
|
+ // 说明
|
|
|
+ XSSFCellStyle describeStyle = wb.createCellStyle();
|
|
|
+ describeStyle.setAlignment(HorizontalAlignment.LEFT);
|
|
|
+ Font describeFont = wb.createFont();
|
|
|
+ describeFont.setFontHeightInPoints((short) 12);
|
|
|
+ describeFont.setFontName("宋体");
|
|
|
+ describeFont.setColor(IndexedColors.RED.getIndex());
|
|
|
+ describeStyle.setFont(describeFont);
|
|
|
+ describe = describe.trim();
|
|
|
+ XSSFRow rowDescribe = sheet.createRow(0);
|
|
|
+ rowDescribe.setHeightInPoints(195); //行高设置成195px
|
|
|
+ for (int i = 0; i < cellCount; i++) {
|
|
|
+ XSSFCell cell = rowDescribe.createCell(i);
|
|
|
+ if (i == 0) {
|
|
|
+ cell.setCellValue(describe);
|
|
|
+ cell.setCellStyle(describeStyle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ CellRangeAddress region = new CellRangeAddress(0, 0, 0, cellCount - 1);
|
|
|
+ sheet.addMergedRegion(region);
|
|
|
+
|
|
|
+ // 表头行
|
|
|
+ XSSFCellStyle headerStyle = wb.createCellStyle();
|
|
|
+ headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
|
|
|
+ headerStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+ headerStyle.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
|
|
|
+ headerStyle.setFont(defaultFont);
|
|
|
+ XSSFRow rowHead = sheet.createRow(1);
|
|
|
+ for (int i = 0; i < excelFieldList.size(); i++) {
|
|
|
+ XSSFCell cell = rowHead.createCell(i);
|
|
|
+ cell.setCellValue(excelFieldList.get(i).getName());
|
|
|
+ cell.setCellStyle(headerStyle);
|
|
|
+ if (excelFieldList.get(i).getComment()) {
|
|
|
+ // 前四个参数是坐标点,后四个参数是编辑和显示批注时的大小.
|
|
|
+ XSSFDrawing p = sheet.createDrawingPatriarch();
|
|
|
+ XSSFComment comment = p.createCellComment(new XSSFClientAnchor(0, 0, 0, 0, (short) 3, 3, (short) 5, 6));
|
|
|
+ // 输入批注信息
|
|
|
+ comment.setString(new XSSFRichTextString("必填"));
|
|
|
+ cell.setCellComment(comment);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 样例行
|
|
|
+ XSSFCellStyle exampleStyle = wb.createCellStyle();
|
|
|
+ exampleStyle.setAlignment(HorizontalAlignment.LEFT);
|
|
|
+ exampleStyle.setFont(defaultFont);
|
|
|
+ XSSFRow rowExample = sheet.createRow(2);
|
|
|
+ for (int i = 0; i < excelFieldList.size(); i++) {
|
|
|
+ XSSFCell cell = rowExample.createCell(i);
|
|
|
+ cell.setCellValue(excelFieldList.get(i).getValue());
|
|
|
+ cell.setCellStyle(exampleStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < cellCount; i++) {
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
+ sheet.setColumnWidth(i, sheet.getColumnWidth(i) * 17 / 10);
|
|
|
+ }
|
|
|
+ ServletOutputStream outputStream = response.getOutputStream();
|
|
|
+ wb.write(outputStream);
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ log.debug("导出Excel结束...");
|
|
|
}
|
|
|
}
|