|
|
@@ -11,13 +11,15 @@ import com.xjrsoft.common.enums.ArchivesStatusEnum;
|
|
|
import com.xjrsoft.common.enums.DeleteMark;
|
|
|
import com.xjrsoft.common.utils.VoToColumnUtil;
|
|
|
import com.xjrsoft.module.base.entity.BaseCourseSubject;
|
|
|
-import com.xjrsoft.module.base.service.IBaseClassService;
|
|
|
import com.xjrsoft.module.base.service.IBaseCourseSubjectService;
|
|
|
+import com.xjrsoft.module.generator.entity.ImportConfig;
|
|
|
import com.xjrsoft.module.organization.entity.User;
|
|
|
import com.xjrsoft.module.organization.service.IUserService;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudent;
|
|
|
import com.xjrsoft.module.student.entity.BaseStudentSchoolRoll;
|
|
|
+import com.xjrsoft.module.veb.util.ImportExcelUtil;
|
|
|
import com.xjrsoft.module.xycxedu.dto.AddExamSubjectScoreEnterDto;
|
|
|
+import com.xjrsoft.module.xycxedu.dto.ExamSubjectScoreEnterDto;
|
|
|
import com.xjrsoft.module.xycxedu.dto.ExamSubjectScoreEnterPageDto;
|
|
|
import com.xjrsoft.module.xycxedu.entity.ExamSubjectScore;
|
|
|
import com.xjrsoft.module.xycxedu.entity.ExamSubjectScoreEnter;
|
|
|
@@ -28,10 +30,22 @@ import com.xjrsoft.module.xycxedu.vo.ExamSubjectScoreEnterImportVo;
|
|
|
import com.xjrsoft.module.xycxedu.vo.ExamSubjectScoreEnterPageVo;
|
|
|
import com.xjrsoft.module.xycxedu.vo.ExamSubjectScoreEnterVo;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+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 org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
@@ -52,7 +66,6 @@ public class ExamSubjectScoreEnterServiceImpl extends MPJBaseServiceImpl<ExamSub
|
|
|
private final IBaseCourseSubjectService courseSubjectService;
|
|
|
private final IUserService userService;
|
|
|
private final IExamSubjectScoreService scoreService;
|
|
|
- private final IBaseClassService classService;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
@@ -155,4 +168,135 @@ public class ExamSubjectScoreEnterServiceImpl extends MPJBaseServiceImpl<ExamSub
|
|
|
public ExamSubjectScoreEnterVo getInfo(Long id) {
|
|
|
return this.baseMapper.getInfo(id);
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public byte[] downloadTemplate(ExamSubjectScoreEnterDto dto) throws IOException {
|
|
|
+ ExamSubjectScoreEnter scoreEnter = this.getById(dto.getExamSubjectScoreEnterId());
|
|
|
+ BaseCourseSubject courseSubject = courseSubjectService.getById(scoreEnter.getCourseSubjectId());
|
|
|
+
|
|
|
+ List<ExamSubjectScoreEnterImportVo> result = scoreService.getEnterScoreStudentList(dto);
|
|
|
+ List<ArrayList<String>> dataList = new ArrayList<>();
|
|
|
+ for (ExamSubjectScoreEnterImportVo recordVo : result) {
|
|
|
+ ArrayList<String> data = new ArrayList<>();
|
|
|
+ data.add(recordVo.getClassName());
|
|
|
+ data.add(recordVo.getStudentName());
|
|
|
+ data.add(recordVo.getCredentialNumber());
|
|
|
+ data.add(courseSubject.getName());
|
|
|
+ data.add(recordVo.getScore());
|
|
|
+ data.add(recordVo.getClassRanking() + "");
|
|
|
+ data.add(recordVo.getGradeRanking() + "");
|
|
|
+ dataList.add(data);
|
|
|
+ }
|
|
|
+
|
|
|
+ Workbook workbook = new XSSFWorkbook();
|
|
|
+ // 创建一个工作表(sheet)
|
|
|
+ String sheetName = "数据";
|
|
|
+ Sheet sheet = workbook.createSheet(sheetName);
|
|
|
+
|
|
|
+ createFirstTitle(workbook, sheet);
|
|
|
+ createSecondTitle(workbook, sheet);
|
|
|
+ createThirdTitle(workbook, sheet, ExamSubjectScoreEnterImportVo.class);
|
|
|
+
|
|
|
+ int dataRowNumber = 3;
|
|
|
+
|
|
|
+ for (ArrayList<String> rowData : dataList) {
|
|
|
+ Row dataRow = sheet.createRow(dataRowNumber);
|
|
|
+ for (int i = 0; i < rowData.size(); i ++){
|
|
|
+ if(dataRowNumber == 3){
|
|
|
+ sheet.autoSizeColumn(i);
|
|
|
+ }
|
|
|
+ String content = rowData.get(i);
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setBold(false);// 设置为粗体
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
+
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ Cell row1cell2 = dataRow.createCell(i);
|
|
|
+ row1cell2.setCellValue(content);
|
|
|
+ row1cell2.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ dataRowNumber ++;
|
|
|
+ }
|
|
|
+
|
|
|
+ ByteArrayOutputStream bot = new ByteArrayOutputStream();
|
|
|
+ workbook.write(bot);
|
|
|
+ return bot.toByteArray();
|
|
|
+ }
|
|
|
+
|
|
|
+ void createFirstTitle(Workbook workbook, Sheet sheet) {
|
|
|
+ int rowNumber = 0;
|
|
|
+ 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(rowNumber);
|
|
|
+ //合并第一行的列
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, 0, 6));
|
|
|
+
|
|
|
+ //3、处理表头
|
|
|
+ String title1 = "学生成绩导入模板";
|
|
|
+ // 创建单元格并设置值
|
|
|
+ Cell cell = row.createCell(0);
|
|
|
+ cell.setCellValue(title1);
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ void createSecondTitle(Workbook workbook, Sheet sheet) {
|
|
|
+ int rowNumber = 1;
|
|
|
+ Font font = workbook.createFont();
|
|
|
+ font.setBold(true);// 设置为粗体
|
|
|
+ font.setFontName("宋体");
|
|
|
+ font.setColor(IndexedColors.RED.getIndex()); // 设置字体颜色为红色
|
|
|
+ font.setFontHeightInPoints((short)12);
|
|
|
+
|
|
|
+ CellStyle cellStyle = workbook.createCellStyle();
|
|
|
+ cellStyle.setFont(font); // 将字体应用到样式
|
|
|
+ cellStyle.setVerticalAlignment(VerticalAlignment.CENTER);
|
|
|
+ cellStyle.setAlignment(HorizontalAlignment.CENTER);
|
|
|
+
|
|
|
+ Row row = sheet.createRow(rowNumber);
|
|
|
+ //合并第一行的列
|
|
|
+ sheet.addMergedRegion(new CellRangeAddress(rowNumber, rowNumber, 0, 6));
|
|
|
+
|
|
|
+ //3、处理表头
|
|
|
+ String title1 = "说明:导入的学生信息必须保证与系统现有信息一致,导入时请将示例数据删除,避免导入失败!黄底红字为必填项,白底黑字为非必填项;";
|
|
|
+ // 创建单元格并设置值
|
|
|
+ Cell cell = row.createCell(0);
|
|
|
+ cell.setCellValue(title1);
|
|
|
+ cell.setCellStyle(cellStyle);
|
|
|
+ }
|
|
|
+
|
|
|
+ void createThirdTitle(Workbook workbook, Sheet sheet, Class<?> clazz) {
|
|
|
+ int rowNumber = 2;
|
|
|
+ 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(rowNumber);
|
|
|
+ List<ImportConfig> importConfigs = ImportExcelUtil.allFields(clazz);
|
|
|
+ for(int i = 0; i < importConfigs.size(); i ++){
|
|
|
+ ImportConfig importConfig = importConfigs.get(i);
|
|
|
+ Cell rowcell = row1.createCell(i);
|
|
|
+ rowcell.setCellValue(importConfig.getFieldName());
|
|
|
+ rowcell.setCellStyle(cellStyle);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|