|
@@ -8,6 +8,7 @@ import com.aliyun.oss.common.utils.BinaryUtil;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.qmth.boot.api.exception.ApiException;
|
|
|
import com.qmth.distributed.print.business.bean.dto.ExaminationExportDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.ExaminationImportDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.FieldsDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.PdfDto;
|
|
|
import com.qmth.distributed.print.business.bean.params.ArraysParams;
|
|
@@ -42,6 +43,7 @@ import org.springframework.util.FileCopyUtils;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.io.*;
|
|
|
+import java.lang.reflect.Field;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.util.*;
|
|
|
import java.util.stream.Collectors;
|
|
@@ -382,13 +384,16 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
Workbook workbook;
|
|
|
if (path.endsWith(SystemConstant.XLSX)) {
|
|
|
workbook = new XSSFWorkbook(inputStream);
|
|
|
- } else if (path.endsWith("xls")) {
|
|
|
+ } else if (path.endsWith(SystemConstant.XLS)) {
|
|
|
workbook = new HSSFWorkbook(inputStream);
|
|
|
} else {
|
|
|
throw ExceptionResultEnum.ERROR.exception("文件格式异常");
|
|
|
}
|
|
|
// 读取第一个工作表
|
|
|
Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ if (sheet.getLastRowNum() == 0 && sheet.getPhysicalNumberOfRows() == 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("第一个sheet为空,考务数据必须放在第一个sheet(工作表)内");
|
|
|
+ }
|
|
|
// 获取sheet行数
|
|
|
int totalRows = sheet.getPhysicalNumberOfRows();
|
|
|
// 获取sheet列数
|
|
@@ -400,7 +405,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
List<String> headList = new ArrayList<>();
|
|
|
// 将必填字段匹配excel解析的表头索引
|
|
|
for (int i = 0; i < totalCells; i++) {
|
|
|
- String cellValue = head.getCell(i).getStringCellValue();
|
|
|
+ String cellValue = String.valueOf(ExcelUtil.convert(head.getCell(i)));
|
|
|
for (FieldsDto fieldsDto : fieldsDtoList) {
|
|
|
if (cellValue.equals(fieldsDto.getName())) {
|
|
|
fieldsDto.setIndex(i);
|
|
@@ -415,22 +420,16 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
throw ExceptionResultEnum.ERROR.exception("学校考务必填字段 :'" + fieldsDto.getName() + "' 不存在");
|
|
|
}
|
|
|
}
|
|
|
- List<Map<String, Object>> dataList = new ArrayList<>();
|
|
|
+ List<ExaminationImportDto> examinationImportDtoList = new ArrayList<>();
|
|
|
|
|
|
for (int r = 1; r < totalRows; r++) {
|
|
|
Row row = sheet.getRow(r);
|
|
|
|
|
|
- String studentCode = null;
|
|
|
- String studentName = null;
|
|
|
- String courseCode = null;
|
|
|
- String courseName = null;
|
|
|
- String examPlace = null;
|
|
|
- String examRoom = null;
|
|
|
- String examDate = null;
|
|
|
- String examTime = null;
|
|
|
- String paperNumber = null;
|
|
|
List<FieldsDto> secondaryFieldList = new ArrayList<>(); // 备选字段
|
|
|
+
|
|
|
+ ExaminationImportDto examinationImportDto = new ExaminationImportDto();
|
|
|
for (FieldsDto fieldsDto : fieldsDtoList) {
|
|
|
+ boolean match = false;
|
|
|
String name = fieldsDto.getName();
|
|
|
String code = fieldsDto.getCode();
|
|
|
int index = fieldsDto.getIndex();
|
|
@@ -445,33 +444,22 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
throw ExceptionResultEnum.ERROR.exception("excel中第[" + (r + 1) + "]行,第[" + (index + 1) + "]列,字段[" + name + "]必填");
|
|
|
}
|
|
|
|
|
|
- // TODO: 2021/4/20 可以优化
|
|
|
- if (ExaminationDBFieldsEnum.STUDENT_CODE.getDesc().equals(name)) {
|
|
|
- studentCode = cellValue;
|
|
|
- ConvertUtil.verifyLength(studentCode, 10, ExaminationDBFieldsEnum.STUDENT_CODE.getDesc());
|
|
|
- } else if (ExaminationDBFieldsEnum.STUDENT_NAME.getDesc().equals(name)) {
|
|
|
- studentName = cellValue;
|
|
|
- ConvertUtil.verifyLength(studentName, 15, ExaminationDBFieldsEnum.STUDENT_NAME.getDesc());
|
|
|
- } else if (ExaminationDBFieldsEnum.COURSE_CODE.getDesc().equals(name)) {
|
|
|
- courseCode = cellValue;
|
|
|
- ConvertUtil.verifyLength(courseCode, 10, ExaminationDBFieldsEnum.COURSE_CODE.getDesc());
|
|
|
- } else if (ExaminationDBFieldsEnum.COURSE_NAME.getDesc().equals(name)) {
|
|
|
- courseName = cellValue;
|
|
|
- ConvertUtil.verifyLength(courseName, 20, ExaminationDBFieldsEnum.COURSE_NAME.getDesc());
|
|
|
- } else if (ExaminationDBFieldsEnum.EXAM_PLACE.getDesc().equals(name)) {
|
|
|
- examPlace = cellValue;
|
|
|
- ConvertUtil.verifyLength(examPlace, 10, ExaminationDBFieldsEnum.EXAM_PLACE.getDesc());
|
|
|
- } else if (ExaminationDBFieldsEnum.EXAM_ROOM.getDesc().equals(name)) {
|
|
|
- examRoom = cellValue;
|
|
|
- ConvertUtil.verifyLength(examRoom, 10, ExaminationDBFieldsEnum.EXAM_ROOM.getDesc());
|
|
|
- } else if (ExaminationDBFieldsEnum.EXAM_DATE.getDesc().equals(name)) {
|
|
|
- examDate = cellValue;
|
|
|
- } else if (ExaminationDBFieldsEnum.EXAM_TIME.getDesc().equals(name)) {
|
|
|
- examTime = cellValue;
|
|
|
- } else if (ExaminationDBFieldsEnum.PAPER_NUMBER.getDesc().equals(name)) {
|
|
|
- paperNumber = cellValue;
|
|
|
- ConvertUtil.verifyLength(paperNumber, 15, ExaminationDBFieldsEnum.PAPER_NUMBER.getDesc());
|
|
|
- } else {
|
|
|
+ for (ExaminationDBFieldsEnum value : ExaminationDBFieldsEnum.values()) {
|
|
|
+ String dbName = value.getDesc();
|
|
|
+ String dbCode = value.getCode();
|
|
|
+ int dbLength = value.getLength();
|
|
|
+ if (dbName.equals(name)) {
|
|
|
+ if (dbLength > 0) {
|
|
|
+ ConvertUtil.verifyLength(cellValue, dbLength, dbName);
|
|
|
+ }
|
|
|
+ Field field = examinationImportDto.getClass().getDeclaredField(dbCode);
|
|
|
+ field.setAccessible(true);
|
|
|
+ field.set(examinationImportDto, cellValue);
|
|
|
+ match = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!match) {
|
|
|
if ("primary".equals(level)) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("有数据库不需要的必选字段 : " + name);
|
|
|
}
|
|
@@ -487,46 +475,39 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
}
|
|
|
}
|
|
|
// 校验试卷编号
|
|
|
- examTaskService.verifyCourseCodeByPaperNumber(schoolId, paperNumber, courseCode);
|
|
|
+ examTaskService.verifyCourseCodeByPaperNumber(schoolId, examinationImportDto.getPaperNumber(), examinationImportDto.getCourseCode());
|
|
|
|
|
|
// 校验课程信息
|
|
|
- basicCourseService.verifyCourseInfo(schoolId, courseCode, courseName, userId);
|
|
|
+ basicCourseService.verifyCourseInfo(schoolId, examinationImportDto.getCourseCode(), examinationImportDto.getCourseName(), userId);
|
|
|
|
|
|
// 解析时间
|
|
|
- Map<String, Object> timeMap = ConvertUtil.analyzeStartAndEndTime(examDate, examTime);
|
|
|
+ Map<String, Object> timeMap = ConvertUtil.analyzeStartAndEndTime(examinationImportDto.getExamDate(), examinationImportDto.getExamTime());
|
|
|
String examStartTime = String.valueOf(timeMap.get("startTime"));
|
|
|
String examEndTime = String.valueOf(timeMap.get("endTime"));
|
|
|
|
|
|
- Map<String, Object> dataMap = new HashMap<>();
|
|
|
- dataMap.put("studentCode", studentCode);
|
|
|
- dataMap.put("studentName", studentName);
|
|
|
- dataMap.put("courseCode", courseCode);
|
|
|
- dataMap.put("courseName", courseName);
|
|
|
- dataMap.put("examPlace", examPlace);
|
|
|
- dataMap.put("examRoom", examRoom);
|
|
|
- dataMap.put("examStartTime", examStartTime);
|
|
|
- dataMap.put("examEndTime", examEndTime);
|
|
|
- dataMap.put("paperNumber", paperNumber);
|
|
|
- dataMap.put("secondaryFieldList", secondaryFieldList);
|
|
|
- dataMap.put("schoolId", schoolId);
|
|
|
- dataMap.put("printPlanId", printPlanId);
|
|
|
- dataMap.put("printPlanName", printPlanName);
|
|
|
- dataList.add(dataMap);
|
|
|
+ examinationImportDto.setSecondaryFieldList(secondaryFieldList);
|
|
|
+ examinationImportDto.setExamStartTime(examStartTime);
|
|
|
+ examinationImportDto.setExamEndTime(examEndTime);
|
|
|
+ examinationImportDto.setSchoolId(schoolId);
|
|
|
+ examinationImportDto.setPrintPlanId(printPlanId);
|
|
|
+ examinationImportDto.setPrintPlanName(printPlanName);
|
|
|
+ examinationImportDtoList.add(examinationImportDto);
|
|
|
}
|
|
|
- System.out.println(JSON.toJSONString(dataList));
|
|
|
+ System.out.println(JSON.toJSONString(examinationImportDtoList));
|
|
|
+
|
|
|
// 校验课程代码和试卷编号在印刷计划下是1对1的关系
|
|
|
- List<String> courseCodeList = dataList.stream().map(e -> String.valueOf(e.get("courseCode"))).distinct().collect(Collectors.toList());
|
|
|
- List<String> paperNumberList = dataList.stream().map(e -> String.valueOf(e.get("paperNumber"))).distinct().collect(Collectors.toList());
|
|
|
+ List<String> courseCodeList = examinationImportDtoList.stream().map(ExaminationImportDto::getCourseCode).distinct().collect(Collectors.toList());
|
|
|
+ List<String> paperNumberList = examinationImportDtoList.stream().map(ExaminationImportDto::getPaperNumber).distinct().collect(Collectors.toList());
|
|
|
for (String courseCode : courseCodeList) {
|
|
|
- List<String> tmp = dataList.stream().filter(e -> courseCode.equals(String.valueOf(e.get("courseCode"))))
|
|
|
- .map(e -> String.valueOf(e.get("paperNumber"))).distinct().collect(Collectors.toList());
|
|
|
+ List<String> tmp = examinationImportDtoList.stream().filter(e -> courseCode.equals(e.getCourseCode()))
|
|
|
+ .map(ExaminationImportDto::getPaperNumber).distinct().collect(Collectors.toList());
|
|
|
if (tmp.size() != 1) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("课程代码为 " + courseCode + ",对应多个试卷编号 : " + tmp);
|
|
|
}
|
|
|
}
|
|
|
for (String paperNumber : paperNumberList) {
|
|
|
- List<String> tmp = dataList.stream().filter(e -> paperNumber.equals(String.valueOf(e.get("paperNumber"))))
|
|
|
- .map(e -> String.valueOf(e.get("courseCode"))).distinct().collect(Collectors.toList());
|
|
|
+ List<String> tmp = examinationImportDtoList.stream().filter(e -> paperNumber.equals(e.getPaperNumber()))
|
|
|
+ .map(ExaminationImportDto::getCourseCode).distinct().collect(Collectors.toList());
|
|
|
if (tmp.size() != 1) {
|
|
|
throw ExceptionResultEnum.ERROR.exception("试卷编号为 " + paperNumber + ",对应多个课程代码 : " + tmp);
|
|
|
}
|
|
@@ -535,25 +516,25 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
// 删除印刷计划下的考务数据
|
|
|
examDetailService.deleteExaminationData(printPlanId);
|
|
|
|
|
|
-
|
|
|
+ // 卷袋号生成规则
|
|
|
SerialNumberParams serialNumberParams = new SerialNumberParams("packageCode-", "p", 6);
|
|
|
String key = serialNumberParams.getModel() + serialNumberParams.getPrefix();
|
|
|
RedisAtomicLong counter = new RedisAtomicLong(key, Objects.requireNonNull(redisTemplate.getConnectionFactory()));
|
|
|
Long value = counter.get();
|
|
|
try {
|
|
|
// 组装exam_detail数据
|
|
|
- List<Long> examDetailIdList = examDetailService.disposeExamDetailByExaminationExcel(dataList, userId, serialNumberParams);
|
|
|
+ List<Long> examDetailIdList = examDetailService.disposeExamDetailByExaminationExcel(examinationImportDtoList, userId, serialNumberParams);
|
|
|
// 组装exam_detail_course数据
|
|
|
- examDetailService.disposeExamDetailCourseByExaminationExcel(dataList, userId);
|
|
|
+ examDetailService.disposeExamDetailCourseByExaminationExcel(examinationImportDtoList, userId);
|
|
|
// 组装exam_student数据
|
|
|
- examDetailService.disposeExamStudentByExaminationExcel(dataList, userId);
|
|
|
+ examDetailService.disposeExamStudentByExaminationExcel(examinationImportDtoList, userId);
|
|
|
|
|
|
// 更改印刷计划状态
|
|
|
examPrintPlan.setStatus(PrintPlanStatusEnum.READY);
|
|
|
examPrintPlanService.updateById(examPrintPlan);
|
|
|
|
|
|
map.put("examDetailIdList", examDetailIdList);
|
|
|
- map.put("dataCount", dataList.size());
|
|
|
+ map.put("dataCount", examinationImportDtoList.size());
|
|
|
} catch (Exception e) {
|
|
|
redisTemplate.opsForValue().set(key, value);
|
|
|
throw new RuntimeException(e);
|