|
@@ -10,10 +10,11 @@ import com.qmth.distributed.print.business.bean.dto.SubjectiveStructDto;
|
|
|
import com.qmth.distributed.print.business.bean.dto.importFile.BasicExamStudentImport;
|
|
|
import com.qmth.distributed.print.business.bean.dto.importFile.BasicExamStudentParseDto;
|
|
|
import com.qmth.distributed.print.business.entity.BasicExamRule;
|
|
|
+import com.qmth.distributed.print.business.entity.ExamPrintPlan;
|
|
|
+import com.qmth.distributed.print.business.entity.ExamTask;
|
|
|
+import com.qmth.distributed.print.business.enums.PrintPlanStatusEnum;
|
|
|
import com.qmth.distributed.print.business.enums.RequiredFieldsEnum;
|
|
|
-import com.qmth.distributed.print.business.service.BasicExamRuleService;
|
|
|
-import com.qmth.distributed.print.business.service.BasicExamService;
|
|
|
-import com.qmth.distributed.print.business.service.BasicExamStudentService;
|
|
|
+import com.qmth.distributed.print.business.service.*;
|
|
|
import com.qmth.distributed.print.business.templete.service.ImportLogicService;
|
|
|
import com.qmth.teachcloud.common.base.BaseEntity;
|
|
|
import com.qmth.teachcloud.common.bean.dto.mark.MarkUser;
|
|
@@ -85,6 +86,12 @@ public class ImportLogicServiceImpl implements ImportLogicService {
|
|
|
SysRoleService sysRoleService;
|
|
|
@Resource
|
|
|
private CommonCacheService commonCacheService;
|
|
|
+ @Resource
|
|
|
+ private TBTaskPdfService tbTaskPdfService;
|
|
|
+ @Resource
|
|
|
+ private ExamPrintPlanService examPrintPlanService;
|
|
|
+ @Resource
|
|
|
+ private ExamTaskService examTaskService;
|
|
|
|
|
|
|
|
|
@Transactional
|
|
@@ -233,6 +240,194 @@ public class ImportLogicServiceImpl implements ImportLogicService {
|
|
|
return map;
|
|
|
}
|
|
|
|
|
|
+ @Transactional
|
|
|
+ @Override
|
|
|
+ public Map<String, Object> executeImportExamStudentLogic(Map<String, Object> map, TBTask tbTask, StringJoiner stringJoinerSummary) {
|
|
|
+ SysUser requestUser = (SysUser) map.get(SystemConstant.USER);
|
|
|
+ InputStream inputStream = (InputStream) map.get("inputStream");
|
|
|
+ Long schoolId = requestUser.getSchoolId();
|
|
|
+ ExamPrintPlan examPrintPlan = examPrintPlanService.getById(tbTask.getPrintPlanId());
|
|
|
+ if (examPrintPlan == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("印刷计划不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ String printPlanName = examPrintPlan.getName();
|
|
|
+ if (!tbTaskPdfService.countByPrintPlanIdAndEntityId(schoolId, tbTask.getPrintPlanId())) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("印刷计划[" + printPlanName + "]有数据正在生成PDF文件,无法导入考务数据");
|
|
|
+ }
|
|
|
+ PrintPlanStatusEnum printPlanStatus = examPrintPlan.getStatus();
|
|
|
+ if (PrintPlanStatusEnum.NEW != printPlanStatus && PrintPlanStatusEnum.READY != printPlanStatus) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("印刷计划状态为[" + PrintPlanStatusEnum.NEW.getName() + "、" + PrintPlanStatusEnum.READY.getName() + "]时才可导入,当前状态[" + printPlanStatus.getName() + "]");
|
|
|
+ }
|
|
|
+
|
|
|
+ Long examId = examPrintPlan.getExamId();
|
|
|
+ BasicExam basicExam = basicExamService.getById(examId);
|
|
|
+ if (Objects.isNull(basicExam)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("考试不存在");
|
|
|
+ }
|
|
|
+ Long semesterId = SystemConstant.convertIdToLong(basicExam.getSemesterId());
|
|
|
+
|
|
|
+ // 解析excel文件
|
|
|
+ SystemConstant.addSummary(stringJoinerSummary, "开始解析文件内容");
|
|
|
+ BasicExamStudentParseDto basicExamStudentParseDto;
|
|
|
+ try {
|
|
|
+ basicExamStudentParseDto = this.parseExamStudent(schoolId, inputStream);
|
|
|
+ } catch (Exception e) {
|
|
|
+ SystemConstant.addSummary(stringJoinerSummary, "解析文件内容结束,解析失败。" + e.getMessage());
|
|
|
+ throw ExceptionResultEnum.ERROR.exception(e.getMessage());
|
|
|
+ }
|
|
|
+ SystemConstant.addSummary(stringJoinerSummary, "解析文件内容结束,开始进行数据校验");
|
|
|
+
|
|
|
+ List<BasicExamStudentImport> basicExamStudentImportList = basicExamStudentParseDto.getBasicExamStudentImportList();
|
|
|
+ if (CollectionUtils.isEmpty(basicExamStudentImportList)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("没有可导入数据");
|
|
|
+ }
|
|
|
+
|
|
|
+ List<BasicExamStudent> basicExamStudentList = basicExamStudentService.list(new QueryWrapper<BasicExamStudent>().lambda()
|
|
|
+ .select(BasicExamStudent::getId, BasicExamStudent::getCourseId, BasicExamStudent::getStudentCode, BasicExamStudent::getPaperNumber)
|
|
|
+ .eq(BasicExamStudent::getSchoolId, schoolId).eq(BasicExamStudent::getExamId, examId));
|
|
|
+ Map<String, Long> courseIdStudentCodeMap = basicExamStudentList.stream().collect(Collectors.toMap(k -> k.getCourseId() + SystemConstant.HYPHEN + k.getStudentCode(), BaseEntity::getId));
|
|
|
+
|
|
|
+ // 文件中试卷编号对应多个课程代码
|
|
|
+ Map<String, Long> paperNumberWithCourseCodeInExcelMap = new HashMap<>();
|
|
|
+ Map<String, Long> basicCourseIdMap = new HashMap<>();
|
|
|
+
|
|
|
+ // 课程管理中课程代码-课程名
|
|
|
+ Map<String, BasicCourse> courseCodeNameInBasicCourseMap = new HashMap<>();
|
|
|
+ List<BasicCourse> basicCourseList = basicCourseService.list(new QueryWrapper<BasicCourse>().lambda().eq(BasicCourse::getSchoolId, schoolId));
|
|
|
+ basicCourseList.forEach(e -> courseCodeNameInBasicCourseMap.put(e.getTeachingRoomId().toString().concat(e.getCode()), e));
|
|
|
+ // 是否有错误提示
|
|
|
+ boolean hasError = false;
|
|
|
+
|
|
|
+ List<ExamTask> examTaskList = examTaskService.listByExamId(examId);
|
|
|
+ Map<String, List<ExamTask>> paperNumberMap = examTaskList.stream().collect(Collectors.groupingBy(m -> m.getPaperNumber()));
|
|
|
+
|
|
|
+ List<BasicExamStudent> basicExamStudents = new ArrayList<>();
|
|
|
+ for (BasicExamStudentImport basicExamStudentImport : basicExamStudentImportList) {
|
|
|
+ BasicExamStudent basicExamStudent = new BasicExamStudent();
|
|
|
+ BeanUtils.copyProperties(basicExamStudentImport, basicExamStudent);
|
|
|
+ basicExamStudent.setSchoolId(schoolId);
|
|
|
+ basicExamStudent.setSemesterId(semesterId);
|
|
|
+ basicExamStudent.setExamId(examId);
|
|
|
+ basicExamStudent.setRequiredFields(CollectionUtils.isNotEmpty(basicExamStudentImport.getRequiredFieldList()) ? JSON.toJSONString(basicExamStudentImport.getRequiredFieldList()) : null);
|
|
|
+ basicExamStudent.setExtendFields(CollectionUtils.isNotEmpty(basicExamStudentImport.getExtendFieldList()) ? JSON.toJSONString(basicExamStudentImport.getExtendFieldList()) : null);
|
|
|
+
|
|
|
+ StringJoiner stringJoiner = new StringJoiner(";");
|
|
|
+ // 校验excel内容
|
|
|
+ basicExamStudentImport.getRequiredFieldList().forEach(m -> {
|
|
|
+ if (m.getEnable() && StringUtils.isBlank(m.getValue())) {
|
|
|
+ stringJoiner.add(m.getName() + "必填");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ if (StringUtils.isNotBlank(basicExamStudentImport.getTeacherCode()) && StringUtils.isBlank(basicExamStudentImport.getTeacherName())) {
|
|
|
+ stringJoiner.add(RequiredFieldsEnum.TEACHER_NAME.getName() + "必填");
|
|
|
+ }
|
|
|
+ if (StringUtils.isNotBlank(basicExamStudentImport.getTeacherName()) && StringUtils.isBlank(basicExamStudentImport.getTeacherCode())) {
|
|
|
+ stringJoiner.add(RequiredFieldsEnum.TEACHER_CODE.getName() + "必填");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ Map<String, Object> timeMap = ConvertUtil.analyzeStartAndEndTime(basicExamStudentImport.getExamDate(), basicExamStudentImport.getExamTime());
|
|
|
+ basicExamStudent.setExamStartTime(Long.valueOf(String.valueOf(timeMap.get("startTime"))));
|
|
|
+ basicExamStudent.setExamEndTime(Long.valueOf(String.valueOf(timeMap.get("endTime"))));
|
|
|
+ } catch (Exception e) {
|
|
|
+ stringJoiner.add("考试日期或考试时间格式错误");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验课程
|
|
|
+ String key = basicExamStudentImport.getCourseCode() + SystemConstant.HYPHEN + basicExamStudentImport.getTeachingRoomName();
|
|
|
+ if (!basicCourseIdMap.containsKey(key)) {
|
|
|
+ List<SysOrg> sysOrgList = sysOrgService.getSecondOrg(schoolId, basicExamStudentImport.getTeachingRoomName());
|
|
|
+ if (CollectionUtils.isEmpty(sysOrgList)) {
|
|
|
+ stringJoiner.add("开课学院[" + basicExamStudentImport.getTeachingRoomName() + "]在学院层级不存在");
|
|
|
+ } else if (sysOrgList.size() == 1) {
|
|
|
+ SysOrg sysOrg = sysOrgList.get(0);
|
|
|
+ // 校验课程代码和开课学院
|
|
|
+ BasicCourse basicCourse = courseCodeNameInBasicCourseMap.get(sysOrg.getId().toString().concat(basicExamStudentImport.getCourseCode()));
|
|
|
+ if (Objects.isNull(basicCourse)) {
|
|
|
+ stringJoiner.add("课程代码[" + basicExamStudentImport.getCourseCode() + "]在开课学院[" + basicExamStudentImport.getTeachingRoomName() + "]不存在");
|
|
|
+ } else {
|
|
|
+ basicExamStudent.setCourseId(basicCourse.getId());
|
|
|
+ basicCourseIdMap.put(key, basicCourse.getId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ stringJoiner.add("开课学院[" + basicExamStudentImport.getTeachingRoomName() + "]存在多个");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ basicExamStudent.setCourseId(basicCourseIdMap.get(key));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 校验试卷编号和课程代码对应关系
|
|
|
+ if (paperNumberWithCourseCodeInExcelMap.containsKey(basicExamStudent.getPaperNumber())) {
|
|
|
+ Long courseId = paperNumberWithCourseCodeInExcelMap.get(basicExamStudent.getPaperNumber());
|
|
|
+ if (!basicExamStudent.getCourseId().equals(courseId)) {
|
|
|
+ stringJoiner.add(String.format("文件中试卷编号[%s]对应多个不同的课程代码", basicExamStudent.getPaperNumber()));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ paperNumberWithCourseCodeInExcelMap.put(basicExamStudent.getPaperNumber(), basicExamStudent.getCourseId());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (paperNumberMap.containsKey(basicExamStudent.getPaperNumber())) {
|
|
|
+ List<ExamTask> examTasks = paperNumberMap.get(basicExamStudent.getPaperNumber());
|
|
|
+ if (examTasks.size() > 1) {
|
|
|
+ stringJoiner.add(String.format("试卷编号[%s]在考试[%s]下有多条命题任务,请联系管理员处理", basicExamStudent.getPaperNumber(), examId));
|
|
|
+ } else {
|
|
|
+ Long courseId = paperNumberWithCourseCodeInExcelMap.get(basicExamStudent.getPaperNumber());
|
|
|
+ ExamTask examTask = examTasks.get(0);
|
|
|
+ if (!examTask.getCourseId().equals(courseId)) {
|
|
|
+ stringJoiner.add(String.format("文件中试卷编号[%s]对应课程代码与命题任务中对应课程代码不一致", basicExamStudent.getPaperNumber()));
|
|
|
+ } else {
|
|
|
+ basicExamStudent.setCoursePaperId(String.valueOf(examTask.getId()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //校验任课老师
|
|
|
+ if (StringUtils.isNotBlank(basicExamStudentImport.getTeacherCode()) && StringUtils.isNotBlank(basicExamStudentImport.getTeacherName())) {
|
|
|
+ SysUser sysUser = sysUserService.getByLoginName(schoolId, basicExamStudentImport.getTeacherCode());
|
|
|
+ if (sysUser == null) {
|
|
|
+ stringJoiner.add("任课老师工号[" + basicExamStudentImport.getTeacherCode() + "]不存在");
|
|
|
+ } else {
|
|
|
+ if (!sysUser.getEnable()) {
|
|
|
+ stringJoiner.add("任课老师工号[" + basicExamStudentImport.getTeacherCode() + "]已禁用");
|
|
|
+ } else if (!sysUser.getRealName().equals(basicExamStudentImport.getTeacherName())) {
|
|
|
+ stringJoiner.add("任课老师[" + basicExamStudentImport.getTeacherName() + "]与用户管理中姓名[" + sysUser.getRealName() + "]不一致");
|
|
|
+ } else {
|
|
|
+ basicExamStudent.setTeacherId(sysUser.getId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (basicExamStudent.getCourseId() != null) {
|
|
|
+ if (courseIdStudentCodeMap.containsKey(basicExamStudent.getCourseId() + SystemConstant.HYPHEN + basicExamStudent.getStudentCode())) {
|
|
|
+ basicExamStudent.setId(courseIdStudentCodeMap.get(basicExamStudent.getCourseId() + SystemConstant.HYPHEN + basicExamStudent.getStudentCode()));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (stringJoiner.toString().length() > 0) {
|
|
|
+ basicExamStudentImport.setErrorMsg(stringJoiner.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!hasError && stringJoiner.toString().length() > 0) {
|
|
|
+ hasError = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (stringJoiner.toString().length() == 0) {
|
|
|
+ basicExamStudents.add(basicExamStudent);
|
|
|
+ }
|
|
|
+
|
|
|
+ map.put(SystemConstant.ERROR_DATA_LIST, basicExamStudentImportList);
|
|
|
+ map.put(SystemConstant.DATASOURCE, basicExamStudents);
|
|
|
+ map.put(SystemConstant.DATA_COUNT, basicExamStudentImportList.size());
|
|
|
+ map.put(SystemConstant.SUCCESS_DATA_COUNT, basicExamStudents.size());
|
|
|
+ map.put(SystemConstant.ERROR_DATA_COUNT, basicExamStudentImportList.size() - basicExamStudents.size());
|
|
|
+ map.put(SystemConstant.HAS_ERROR_DATA, hasError);
|
|
|
+ map.put(SystemConstant.COLUMN_NAMES, basicExamStudentParseDto.getColumnNames());
|
|
|
+ }
|
|
|
+
|
|
|
+ return map;
|
|
|
+ }
|
|
|
+
|
|
|
private BasicExamStudentParseDto parseBasicExamStudent(Long schoolId, InputStream inputStream) {
|
|
|
ExcelReader excelReader = ExcelReader.create(ExcelType.XLSX, inputStream, 1);
|
|
|
List<DataMap> dataMapList = null;
|
|
@@ -293,6 +488,66 @@ public class ImportLogicServiceImpl implements ImportLogicService {
|
|
|
return basicExamStudentParseDto;
|
|
|
}
|
|
|
|
|
|
+ private BasicExamStudentParseDto parseExamStudent(Long schoolId, InputStream inputStream) {
|
|
|
+ ExcelReader excelReader = ExcelReader.create(ExcelType.XLSX, inputStream, 1);
|
|
|
+ List<DataMap> dataMapList = null;
|
|
|
+ try {
|
|
|
+ dataMapList = excelReader.getDataMapList();
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("读取excel内容失败");
|
|
|
+ }
|
|
|
+ BasicExamStudentParseDto basicExamStudentParseDto = new BasicExamStudentParseDto();
|
|
|
+ List<BasicExamStudentImport> list = new ArrayList<>();
|
|
|
+ if (CollectionUtils.isNotEmpty(dataMapList)) {
|
|
|
+ String[] columnNames = excelReader.getColumnNames();
|
|
|
+
|
|
|
+ BasicExamRule basicExamRule = basicExamRuleService.getBySchoolId(schoolId);
|
|
|
+ if (basicExamRule == null) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("通用规则未设置");
|
|
|
+ }
|
|
|
+
|
|
|
+ Map<String, EnumResult> requiredMap = basicExamRule.getRequiredFieldList().stream().filter(m -> m.getEnable()).collect(Collectors.toMap(EnumResult::getName, e -> e));
|
|
|
+ Map<String, EnumResult> extendMap = basicExamRule.getExtendFieldList().stream().filter(m -> m.getEnable()).collect(Collectors.toMap(EnumResult::getName, e -> e));
|
|
|
+
|
|
|
+ // 通用规则表头
|
|
|
+ List<String> actualTitleList = Stream.concat(requiredMap.keySet().stream(), extendMap.keySet().stream()).collect(Collectors.toList());
|
|
|
+ if (!CollectionUtils.isEqualCollection(Arrays.asList(columnNames), actualTitleList)) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("表头有误,表头字段应为【" + String.join(",", actualTitleList) + "】");
|
|
|
+ }
|
|
|
+
|
|
|
+ basicExamStudentParseDto.setColumnNames(columnNames);
|
|
|
+
|
|
|
+ dataMapList.forEach(m -> {
|
|
|
+ BasicExamStudentImport basicExamStudentImport = new BasicExamStudentImport();
|
|
|
+ Class<BasicExamStudentImport> aClass = (Class<BasicExamStudentImport>) basicExamStudentImport.getClass();
|
|
|
+ for (Map.Entry<String, String> entry : m.entrySet()) {
|
|
|
+ // 必填字段
|
|
|
+ if (requiredMap.containsKey(entry.getKey())) {
|
|
|
+ EnumResult enumResult = requiredMap.get(entry.getKey());
|
|
|
+ try {
|
|
|
+ Field declaredField = aClass.getDeclaredField(enumResult.getCode());
|
|
|
+ declaredField.setAccessible(true);
|
|
|
+ declaredField.set(basicExamStudentImport, entry.getValue());
|
|
|
+ } catch (NoSuchFieldException e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("未获取到表头为[" + entry.getKey() + "]的属性值");
|
|
|
+ } catch (IllegalAccessException e) {
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("表头为[" + entry.getKey() + "]的值赋值失败");
|
|
|
+ }
|
|
|
+ basicExamStudentImport.getRequiredFieldList().add(new CodeNameEnableDisabledValue(enumResult.getCode(), enumResult.getName(), enumResult.getEnable(), enumResult.getDisabled(), StringUtils.isNotBlank(entry.getValue()) ? entry.getValue() : ""));
|
|
|
+ }
|
|
|
+ // 扩展字段
|
|
|
+ if (extendMap.containsKey(entry.getKey())) {
|
|
|
+ EnumResult enumResult = extendMap.get(entry.getKey());
|
|
|
+ basicExamStudentImport.getExtendFieldList().add(new CodeNameEnableDisabledValue(enumResult.getCode(), enumResult.getName(), enumResult.getEnable(), enumResult.getDisabled(), StringUtils.isNotBlank(entry.getValue()) ? entry.getValue() : ""));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ list.add(basicExamStudentImport);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ basicExamStudentParseDto.setBasicExamStudentImportList(list);
|
|
|
+ return basicExamStudentParseDto;
|
|
|
+ }
|
|
|
+
|
|
|
@Transactional
|
|
|
@Override
|
|
|
public void saveMarkStudent(Long examId, List<BasicExamStudent> basicExamStudentList) {
|