|
@@ -13,8 +13,10 @@ import com.google.gson.Gson;
|
|
|
import com.qmth.distributed.print.business.bean.dto.*;
|
|
|
import com.qmth.distributed.print.business.bean.dto.approvalForm.*;
|
|
|
import com.qmth.distributed.print.business.bean.dto.examObject.ExamObjectDto;
|
|
|
+import com.qmth.distributed.print.business.bean.dto.excel.ExamStudentImportDto;
|
|
|
import com.qmth.distributed.print.business.bean.params.*;
|
|
|
import com.qmth.distributed.print.business.bean.result.WorkResult;
|
|
|
+import com.qmth.distributed.print.business.bean.result.examTaskStudent.ExamTaskExamStudentImportResult;
|
|
|
import com.qmth.distributed.print.business.bean.result.examTaskStudent.ExamTaskStudentObjectResult;
|
|
|
import com.qmth.distributed.print.business.bean.result.examTaskStudent.StudentInfo;
|
|
|
import com.qmth.distributed.print.business.entity.*;
|
|
@@ -27,6 +29,9 @@ import com.qmth.distributed.print.business.util.CreatePdfUtil;
|
|
|
import com.qmth.distributed.print.business.util.HtmlToPdfUtil;
|
|
|
import com.qmth.teachcloud.common.bean.dto.BlurryUserDto;
|
|
|
import com.qmth.teachcloud.common.bean.dto.MqDto;
|
|
|
+import com.qmth.teachcloud.common.bean.dto.excel.BasicStudentImportDto;
|
|
|
+import com.qmth.teachcloud.common.bean.dto.excel.DescribeImportDto;
|
|
|
+import com.qmth.teachcloud.common.bean.params.BasicStudentExtrasParam;
|
|
|
import com.qmth.teachcloud.common.bean.result.BasicStudentResult;
|
|
|
import com.qmth.teachcloud.common.config.DictionaryConfig;
|
|
|
import com.qmth.teachcloud.common.contant.SystemConstant;
|
|
@@ -1861,7 +1866,7 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@Override
|
|
|
- public List<ExamTaskStudentObjectResult> findExamTaskStudentObject(ExamObjectType examObjectType, Long basicCourseId, MultipartFile file, SysUser requestUser) throws Exception {
|
|
|
+ public List<ExamTaskStudentObjectResult> findExamTaskStudentObject(ExamObjectType examObjectType, Long basicCourseId,SysUser requestUser) throws Exception {
|
|
|
Long schoolId = requestUser.getSchoolId();
|
|
|
Long userId = requestUser.getId();
|
|
|
List<ExamTaskStudentObjectResult> result = new ArrayList<>();
|
|
@@ -1946,42 +1951,150 @@ public class ExamTaskServiceImpl extends ServiceImpl<ExamTaskMapper, ExamTask> i
|
|
|
result.add(examTaskStudentObjectResult);
|
|
|
}
|
|
|
break;
|
|
|
- case IMPORT_STUDENT:
|
|
|
- // 学生导入
|
|
|
- if (Objects.isNull(file)) {
|
|
|
- throw ExceptionResultEnum.ERROR.exception("缺少导入文件");
|
|
|
+ }
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ @Override
|
|
|
+ public List<ExamTaskExamStudentImportResult> examTaskExamStudentImport(MultipartFile file, SysUser requestUser) throws IOException, NoSuchFieldException, IllegalAccessException {
|
|
|
+ if (Objects.isNull(file)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("缺少导入文件");
|
|
|
+ }
|
|
|
+ // excel 读取和检验
|
|
|
+ List<ExamStudentImportDto> examStudentImportDtoList = new ArrayList<>();
|
|
|
+ List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(file.getInputStream(), Lists.newArrayList(ExamStudentImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> {
|
|
|
+ List<ExcelError> excelErrorTemp = new ArrayList<>();
|
|
|
+ Map<String, String> checkCodeMap = new HashMap<>();
|
|
|
+ Map<String, String> checkPhoneMap = new HashMap<>();
|
|
|
+ for (int i = 0; i < finalExcelList.size(); i++) {
|
|
|
+ LinkedMultiValueMap<Integer, Object> excelMap = finalExcelList.get(i);
|
|
|
+ List<Object> examStudentImportDtoDatasource = excelMap.get(i);
|
|
|
+ assert examStudentImportDtoDatasource != null;
|
|
|
+ if (examStudentImportDtoDatasource.get(0) instanceof DescribeImportDto) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- Map<String, Object> studentImportMap = new HashMap<>();
|
|
|
- studentImportMap.put("inputStream", file.getInputStream());
|
|
|
- studentImportMap.put(SystemConstant.SYS_USER, requestUser);
|
|
|
- taskLogicService.executeImportBasicStudentLogic(studentImportMap);
|
|
|
- List<String> studentCodeList = JSONObject.parseArray(JSON.toJSONString(studentImportMap.get("studentCodeList")), String.class);
|
|
|
-
|
|
|
- // 导入的学生信息查询
|
|
|
- List<BasicStudentResult> basicStudentResultDatasource = basicStudentService.basicStudentList(schoolId, null, null, null, studentCodeList);
|
|
|
- List<Long> basicClazzIdList = basicStudentResultDatasource.stream().map(BasicStudentResult::getClazzId).distinct().collect(Collectors.toList());
|
|
|
- for (Long basicClazzId : basicClazzIdList) {
|
|
|
- List<BasicStudentResult> basicStudentResultList = basicStudentResultDatasource.stream()
|
|
|
- .filter(e -> basicClazzId.equals(e.getClazzId())).collect(Collectors.toList());
|
|
|
- List<StudentInfo> studentInfoList = basicStudentResultList.stream().flatMap(e -> {
|
|
|
- StudentInfo studentInfo = new StudentInfo();
|
|
|
- studentInfo.setStudentId(e.getId());
|
|
|
- studentInfo.setStudentCode(e.getStudentCode());
|
|
|
- studentInfo.setStudentName(e.getStudentName());
|
|
|
- studentInfo.setCollegeName(e.getCollegeName());
|
|
|
- studentInfo.setMajorName(e.getMajorName());
|
|
|
- studentInfo.setBasicClazzId(e.getClazzId());
|
|
|
- studentInfo.setBasicClazzName(e.getClazz());
|
|
|
- return Stream.of(studentInfo);
|
|
|
- }).collect(Collectors.toList());
|
|
|
- ExamTaskStudentObjectResult examTaskStudentObjectResult = new ExamTaskStudentObjectResult();
|
|
|
- examTaskStudentObjectResult.setClazzId(basicClazzId);
|
|
|
- examTaskStudentObjectResult.setClazzName(basicClazzService.getById(basicClazzId).getClazzName());
|
|
|
- examTaskStudentObjectResult.setStudentInfoList(studentInfoList);
|
|
|
- examTaskStudentObjectResult.setStudentClazzType(examObjectType.getStudentClazzType());
|
|
|
- result.add(examTaskStudentObjectResult);
|
|
|
+ for (int y = 0; y < Objects.requireNonNull(examStudentImportDtoDatasource).size(); y++) {
|
|
|
+ ExamStudentImportDto examStudentImportDto = (ExamStudentImportDto) examStudentImportDtoDatasource.get(y);
|
|
|
+ String studentName = examStudentImportDto.getStudentName();
|
|
|
+ String studentCode = examStudentImportDto.getStudentCode();
|
|
|
+ String phoneNumber = examStudentImportDto.getPhoneNumber();
|
|
|
+ String clazzName = examStudentImportDto.getClazzName();
|
|
|
+ String examPlace = examStudentImportDto.getExamPlace();
|
|
|
+ String examRoom = examStudentImportDto.getExamRoom();
|
|
|
+ examStudentImportDtoList.add(examStudentImportDto);
|
|
|
+
|
|
|
+
|
|
|
+ // 检验excel中
|
|
|
+ // 检验学号
|
|
|
+ if (SystemConstant.strNotNull(studentCode)) {
|
|
|
+ if (checkCodeMap.containsKey(studentCode)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("导入的excel中包含在重复的【学生编号】:" + studentCode);
|
|
|
+ } else {
|
|
|
+ checkCodeMap.put(studentCode, studentName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果电话有值则检验电话excel中唯一性
|
|
|
+ if (SystemConstant.strNotNull(phoneNumber)) {
|
|
|
+ if (checkPhoneMap.containsKey(phoneNumber)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("导入的excel中包含在重复的【电话号码】:" + phoneNumber);
|
|
|
+ } else {
|
|
|
+ checkPhoneMap.put(phoneNumber, studentCode);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ excelErrorTemp.addAll(ExcelUtil.checkExcelField(examStudentImportDto, y, i));
|
|
|
+ if (Objects.isNull(studentCode) || studentCode.length() > 30 || !studentCode.matches(SystemConstant.REGULAR_EXPRESSION_OF_CODE)) {
|
|
|
+ excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[学号]不符合输入规范"));
|
|
|
+ }
|
|
|
+ if (Objects.isNull(studentName) || studentName.length() > 30) {
|
|
|
+ excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[学生名称]不符合输入规范"));
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(phoneNumber) && !phoneNumber.matches(SystemConstant.REGULAR_EXPRESSION_OF_PHONE)) {
|
|
|
+ excelErrorTemp.add(new ExcelError(y + 1, "excel第" + (i + 1) + "个sheet第" + (y + 1) + "行[电话号码]不符合输入规范"));
|
|
|
+ }
|
|
|
}
|
|
|
- break;
|
|
|
+ }
|
|
|
+ if (excelErrorTemp.size() > 0) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(JSONObject.toJSONString(excelErrorTemp));
|
|
|
+ }
|
|
|
+ return finalExcelList;
|
|
|
+ });
|
|
|
+ // 创建基础学生信息
|
|
|
+ List<BasicStudentExtrasParam> basicStudentExtrasParamList = examStudentImportDtoList.stream().flatMap(e -> {
|
|
|
+ BasicStudentExtrasParam basicStudentExtrasParam = new BasicStudentExtrasParam();
|
|
|
+ basicStudentExtrasParam.setStudentName(e.getStudentName());
|
|
|
+ basicStudentExtrasParam.setStudentCode(e.getStudentCode());
|
|
|
+ basicStudentExtrasParam.setPhoneNumber(e.getPhoneNumber());
|
|
|
+ basicStudentExtrasParam.setCollegeName(e.getCollegeName());
|
|
|
+ basicStudentExtrasParam.setMajorName(e.getMajorName());
|
|
|
+ basicStudentExtrasParam.setClazzName(e.getClazzName());
|
|
|
+ return Stream.of(basicStudentExtrasParam);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ basicStudentService.saveBasicStudentWithExtrasList(basicStudentExtrasParamList, requestUser);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 考生信息回溯
|
|
|
+ List<ExamTaskExamStudentImportResult> result = new ArrayList<>();
|
|
|
+
|
|
|
+ List<String> studentCodeDatasource = examStudentImportDtoList.stream().map(ExamStudentImportDto::getStudentCode).distinct().collect(Collectors.toList());
|
|
|
+ List<String> examRoomDatasource = examStudentImportDtoList.stream().map(ExamStudentImportDto::getExamRoom).distinct().collect(Collectors.toList());
|
|
|
+ // 导入的excel创建或查询的学生集合
|
|
|
+ List<BasicStudentResult> basicStudentResultDatasource = basicStudentService.basicStudentList(requestUser.getSchoolId(), null, null, null, studentCodeDatasource);
|
|
|
+
|
|
|
+ for (String examRoom : examRoomDatasource) {
|
|
|
+ // 考点
|
|
|
+ List<String> examPlaceList = examStudentImportDtoList
|
|
|
+ .stream()
|
|
|
+ .filter(e -> examRoom.equals(e.getExamRoom()))
|
|
|
+ .map(ExamStudentImportDto::getExamPlace)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ if (examPlaceList.size() > 1){
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("异常:考场对应多个考点");
|
|
|
+ }
|
|
|
+ String examPlace = examPlaceList.get(0);
|
|
|
+
|
|
|
+
|
|
|
+ // 该考场学号集合
|
|
|
+ List<String> studentCodeList = examStudentImportDtoList.stream()
|
|
|
+ .filter(e -> examRoom.equals(e.getExamRoom()))
|
|
|
+ .map(ExamStudentImportDto::getStudentCode)
|
|
|
+ .distinct()
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ List<ExamTaskStudentObjectResult> examTaskStudentObjectResultList = new ArrayList<>();
|
|
|
+ List<BasicStudentResult> basicStudentResultList = basicStudentResultDatasource.stream().filter(e -> studentCodeList.contains(e.getStudentCode())).collect(Collectors.toList());
|
|
|
+ List<Long> basicClazzIdList = basicStudentResultList.stream().map(BasicStudentResult::getClazzId).distinct().collect(Collectors.toList());
|
|
|
+ for (Long basicClazzId : basicClazzIdList) {
|
|
|
+ List<BasicStudentResult> basicStudentClazzList = basicStudentResultList.stream()
|
|
|
+ .filter(e -> basicClazzId.equals(e.getClazzId())).collect(Collectors.toList());
|
|
|
+ List<StudentInfo> studentInfoList = basicStudentClazzList.stream().flatMap(e -> {
|
|
|
+ StudentInfo studentInfo = new StudentInfo();
|
|
|
+ studentInfo.setStudentId(e.getId());
|
|
|
+ studentInfo.setStudentCode(e.getStudentCode());
|
|
|
+ studentInfo.setStudentName(e.getStudentName());
|
|
|
+ studentInfo.setCollegeName(e.getCollegeName());
|
|
|
+ studentInfo.setMajorName(e.getMajorName());
|
|
|
+ studentInfo.setBasicClazzId(e.getClazzId());
|
|
|
+ studentInfo.setBasicClazzName(e.getClazz());
|
|
|
+ return Stream.of(studentInfo);
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ ExamTaskStudentObjectResult examTaskStudentObjectResult = new ExamTaskStudentObjectResult();
|
|
|
+ examTaskStudentObjectResult.setClazzId(basicClazzId);
|
|
|
+ examTaskStudentObjectResult.setClazzName(basicClazzService.getById(basicClazzId).getClazzName());
|
|
|
+ examTaskStudentObjectResult.setStudentInfoList(studentInfoList);
|
|
|
+ examTaskStudentObjectResult.setStudentClazzType(ExamObjectType.IMPORT_STUDENT.getStudentClazzType());
|
|
|
+ examTaskStudentObjectResultList.add(examTaskStudentObjectResult);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ExamTaskExamStudentImportResult examTaskExamStudentImportResult = new ExamTaskExamStudentImportResult();
|
|
|
+ examTaskExamStudentImportResult.setExamRoom(examRoom);
|
|
|
+ examTaskExamStudentImportResult.setExamPlace(examPlace);
|
|
|
+ examTaskExamStudentImportResult.setExamTaskStudentObjectResultList(examTaskStudentObjectResultList);
|
|
|
+ result.add(examTaskExamStudentImportResult);
|
|
|
}
|
|
|
return result;
|
|
|
}
|