|
@@ -1,11 +1,23 @@
|
|
package com.qmth.paper.library.business.templete.service.impl;
|
|
package com.qmth.paper.library.business.templete.service.impl;
|
|
|
|
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.google.common.collect.Lists;
|
|
import com.google.common.collect.Lists;
|
|
|
|
+import com.qmth.paper.library.business.bean.dto.excel.PaperScanTaskImportDto;
|
|
|
|
+import com.qmth.paper.library.business.bean.params.PaperScanTaskParam;
|
|
|
|
+import com.qmth.paper.library.business.entity.PaperArchives;
|
|
|
|
+import com.qmth.paper.library.business.entity.PaperScanTask;
|
|
|
|
+import com.qmth.paper.library.business.entity.PaperScanTaskDetail;
|
|
|
|
+import com.qmth.paper.library.business.service.PaperArchivesService;
|
|
|
|
+import com.qmth.paper.library.business.service.PaperScanTaskDetailService;
|
|
|
|
+import com.qmth.paper.library.business.service.PaperScanTaskService;
|
|
import com.qmth.paper.library.business.templete.service.TaskLogicService;
|
|
import com.qmth.paper.library.business.templete.service.TaskLogicService;
|
|
import com.qmth.paper.library.common.bean.dto.excel.DescribeImportDto;
|
|
import com.qmth.paper.library.common.bean.dto.excel.DescribeImportDto;
|
|
import com.qmth.paper.library.common.bean.dto.excel.SysOrgImportDto;
|
|
import com.qmth.paper.library.common.bean.dto.excel.SysOrgImportDto;
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
|
|
+import com.qmth.paper.library.common.entity.BasicStudent;
|
|
import com.qmth.paper.library.common.entity.SysUser;
|
|
import com.qmth.paper.library.common.entity.SysUser;
|
|
|
|
+import com.qmth.paper.library.common.enums.ExceptionResultEnum;
|
|
|
|
+import com.qmth.paper.library.common.service.BasicStudentService;
|
|
import com.qmth.paper.library.common.service.SysOrgService;
|
|
import com.qmth.paper.library.common.service.SysOrgService;
|
|
import com.qmth.paper.library.common.util.ExcelUtil;
|
|
import com.qmth.paper.library.common.util.ExcelUtil;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
@@ -18,11 +30,9 @@ import org.springframework.util.LinkedMultiValueMap;
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.io.InputStream;
|
|
-import java.security.NoSuchAlgorithmException;
|
|
|
|
-import java.util.ArrayList;
|
|
|
|
-import java.util.List;
|
|
|
|
-import java.util.Map;
|
|
|
|
|
|
+import java.util.*;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
+import java.util.stream.Stream;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Description: 任务处理逻辑impl
|
|
* @Description: 任务处理逻辑impl
|
|
@@ -37,11 +47,19 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private SysOrgService sysOrgService;
|
|
private SysOrgService sysOrgService;
|
|
|
|
+ @Resource
|
|
|
|
+ private PaperArchivesService paperArchivesService;
|
|
|
|
+ @Resource
|
|
|
|
+ private PaperScanTaskService paperScanTaskService;
|
|
|
|
+ @Resource
|
|
|
|
+ private PaperScanTaskDetailService paperScanTaskDetailService;
|
|
|
|
+ @Resource
|
|
|
|
+ private BasicStudentService basicStudentService;
|
|
|
|
|
|
|
|
|
|
@Transactional
|
|
@Transactional
|
|
@Override
|
|
@Override
|
|
- public Map<String, Object> executeImportSysOrgLogic(Map<String, Object> map) throws IOException, NoSuchFieldException, NoSuchAlgorithmException {
|
|
|
|
|
|
+ public Map<String, Object> executeImportSysOrgLogic(Map<String, Object> map) throws IOException, NoSuchFieldException {
|
|
InputStream inputStream = (InputStream) map.get("inputStream");
|
|
InputStream inputStream = (InputStream) map.get("inputStream");
|
|
List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(SysOrgImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> finalExcelList);
|
|
List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(SysOrgImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> finalExcelList);
|
|
List<String> orgInfoList = new ArrayList<>();
|
|
List<String> orgInfoList = new ArrayList<>();
|
|
@@ -71,4 +89,173 @@ public class TaskLogicServiceImpl implements TaskLogicService {
|
|
}
|
|
}
|
|
return map;
|
|
return map;
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public Map<String, Object> executeImportPaperScanTaskDetailLogic(Map<String, Object> map) throws Exception {
|
|
|
|
+ SysUser requestUser = (SysUser) map.get(SystemConstant.SYS_USER);
|
|
|
|
+ Long schoolId = requestUser.getSchoolId();
|
|
|
|
+ InputStream inputStream = (InputStream) map.get("inputStream");
|
|
|
|
+
|
|
|
|
+ List<LinkedMultiValueMap<Integer, Object>> finalList = ExcelUtil.excelReader(inputStream, Lists.newArrayList(PaperScanTaskImportDto.class, DescribeImportDto.class), (finalExcelList, finalColumnNameList, finalExcelErrorList) -> finalExcelList);
|
|
|
|
+ List<PaperScanTaskImportDto> datasource = new ArrayList<>();
|
|
|
|
+ for (int i = 0; i < finalList.size(); i++) {
|
|
|
|
+ LinkedMultiValueMap<Integer, Object> excelMap = finalList.get(i);
|
|
|
|
+ List<Object> paperScanTaskImportDtoList = excelMap.get(i);
|
|
|
|
+ assert paperScanTaskImportDtoList != null;
|
|
|
|
+ if (paperScanTaskImportDtoList.get(0) instanceof DescribeImportDto) {
|
|
|
|
+ continue;
|
|
|
|
+ }
|
|
|
|
+ map.put("dataCount", paperScanTaskImportDtoList.size());
|
|
|
|
+ // 处理机构
|
|
|
|
+ if (paperScanTaskImportDtoList.get(0) instanceof PaperScanTaskImportDto) {
|
|
|
|
+ datasource = paperScanTaskImportDtoList.stream().map(e -> {
|
|
|
|
+ PaperScanTaskImportDto paperScanTaskImportDto = new PaperScanTaskImportDto();
|
|
|
|
+ BeanUtils.copyProperties(e, paperScanTaskImportDto);
|
|
|
|
+ return paperScanTaskImportDto;
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (datasource.size() > 0) {
|
|
|
|
+ // 选择的扫描档案id
|
|
|
|
+ Long paperArchivesId = SystemConstant.convertIdToLong(String.valueOf(map.get("paperArchivesId")));
|
|
|
|
+ List<Map<String, String>> archivesCheckMapList = datasource.stream().flatMap(e -> {
|
|
|
|
+ Map<String, String> checkMap = new HashMap<>();
|
|
|
|
+ checkMap.put("archivesName", e.getArchivesName());
|
|
|
|
+ checkMap.put("archivesCode", e.getArchivesCode());
|
|
|
|
+ return Stream.of(checkMap);
|
|
|
|
+ }).distinct().collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ if (archivesCheckMapList.size() != 1) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel中的档案信息异常(导入扫描任务数据必须是一个档案下的)");
|
|
|
|
+ }
|
|
|
|
+ Map<String, String> archivesCheckMap = archivesCheckMapList.get(0);
|
|
|
|
+ String archivesName = archivesCheckMap.get("archivesName");
|
|
|
|
+ String archivesCode = archivesCheckMap.get("archivesCode");
|
|
|
|
+
|
|
|
|
+ // 判断选择的档案和导入的是同一个
|
|
|
|
+ PaperArchives paperArchives = paperArchivesService.getOne(new QueryWrapper<PaperArchives>()
|
|
|
|
+ .lambda()
|
|
|
|
+ .eq(PaperArchives::getId, paperArchivesId)
|
|
|
|
+ .eq(PaperArchives::getArchivesCode, archivesCode)
|
|
|
|
+ .eq(PaperArchives::getArchivesName, archivesName));
|
|
|
|
+ if (Objects.nonNull(paperArchives)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel中的档案信息和选择的档案不符");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 归纳 - 扫描任务集合
|
|
|
|
+ // 扫描任务唯一信息
|
|
|
|
+ Map<String, PaperScanTask> paperScanTaskMap = new HashMap<>();
|
|
|
|
+ for (PaperScanTaskImportDto paperScanTaskImportDto : datasource) {
|
|
|
|
+ String scanTaskName = paperScanTaskImportDto.getScanTaskName();
|
|
|
|
+ String courseName = paperScanTaskImportDto.getCourseName();
|
|
|
|
+ String teacherName = paperScanTaskImportDto.getTeacherName();
|
|
|
|
+ String teachClazzName = paperScanTaskImportDto.getTeachClazzName();
|
|
|
|
+
|
|
|
|
+ if (paperScanTaskMap.containsKey(scanTaskName)) {
|
|
|
|
+ // 如果试卷任务map中包含该任务名称 - 检验其他信息是否一致(课程,任课教师,教学班 为空的不检验)
|
|
|
|
+ PaperScanTask v = paperScanTaskMap.get(scanTaskName);
|
|
|
|
+ String vCourseName = v.getCourseName();
|
|
|
|
+ String vTeacherName = v.getTeacherName();
|
|
|
|
+ String vTeachClazzName = v.getTeachClazzName();
|
|
|
|
+
|
|
|
|
+ // 同一任务课程名称检验
|
|
|
|
+ if (!SystemConstant.strNotNull(vCourseName)) {
|
|
|
|
+ v.setCourseName(courseName);
|
|
|
|
+ } else if (SystemConstant.strNotNull(courseName) && !vCourseName.equals(courseName)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel数据异常:导入的任务【" + scanTaskName + "】存在不同的课程名称【" + vCourseName + "," + courseName + "】");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 同一任务任课教师检验
|
|
|
|
+ if (!SystemConstant.strNotNull(vTeacherName)) {
|
|
|
|
+ v.setTeacherName(teacherName);
|
|
|
|
+ } else if (SystemConstant.strNotNull(teacherName) && !vTeacherName.equals(teacherName)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel数据异常:导入的任务【" + scanTaskName + "】存在不同的任课教师【" + vTeacherName + "," + teacherName + "】");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 同一任务教学班检验
|
|
|
|
+ if (!SystemConstant.strNotNull(vTeachClazzName)) {
|
|
|
|
+ v.setTeachClazzName(teachClazzName);
|
|
|
|
+ } else if (SystemConstant.strNotNull(teachClazzName) && !vTeachClazzName.equals(teachClazzName)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("excel数据异常:导入的任务【" + scanTaskName + "】存在不同的教学班【" + vTeachClazzName + "," + teachClazzName + "】");
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ // 没包含直接put
|
|
|
|
+ PaperScanTask v = new PaperScanTask();
|
|
|
|
+ v.setScanTaskName(scanTaskName);
|
|
|
|
+ v.setCourseName(courseName);
|
|
|
|
+ v.setTeacherName(teacherName);
|
|
|
|
+ v.setTeachClazzName(teachClazzName);
|
|
|
|
+ paperScanTaskMap.put(scanTaskName, v);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 创建扫描任务并把编辑后的任务id放回map中
|
|
|
|
+ List<Long> paperScanTaskIdList = new ArrayList<>();
|
|
|
|
+ for (String k : paperScanTaskMap.keySet()) {
|
|
|
|
+ PaperScanTask v = paperScanTaskMap.get(k);
|
|
|
|
+ PaperScanTask db = paperScanTaskService.getOne(new QueryWrapper<PaperScanTask>()
|
|
|
|
+ .lambda()
|
|
|
|
+ .eq(PaperScanTask::getSchoolId, requestUser.getSchoolId())
|
|
|
|
+ .eq(PaperScanTask::getScanTaskName, k)
|
|
|
|
+ .eq(PaperScanTask::getPaperArchivesId, paperArchivesId));
|
|
|
|
+ PaperScanTaskParam paperScanTaskParam = new PaperScanTaskParam();
|
|
|
|
+ if (Objects.nonNull(db)) {
|
|
|
|
+ // 编辑
|
|
|
|
+ paperScanTaskParam.setPaperScanTaskId(db.getId());
|
|
|
|
+ paperScanTaskIdList.add(db.getId());
|
|
|
|
+ }
|
|
|
|
+ paperScanTaskParam.setPaperArchivesId(paperArchivesId);
|
|
|
|
+ paperScanTaskParam.setCourseName(v.getCourseName());
|
|
|
|
+ paperScanTaskParam.setTeacherName(v.getTeacherName());
|
|
|
|
+ paperScanTaskParam.setTeachClazzName(v.getTeachClazzName());
|
|
|
|
+ paperScanTaskParam.setScanTaskName(k);
|
|
|
|
+ Long paperScanTaskId = paperScanTaskService.editPaperScanTask(paperScanTaskParam, requestUser);
|
|
|
|
+ v.setId(paperScanTaskId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 归纳 - 扫描任务详情
|
|
|
|
+ // 上面编辑的任务绑定的扫描详情集合
|
|
|
|
+ List<PaperScanTaskDetail> paperScanTaskDetailDbList = paperScanTaskDetailService.list(new QueryWrapper<PaperScanTaskDetail>()
|
|
|
|
+ .lambda()
|
|
|
|
+ .in(PaperScanTaskDetail::getPaperScanTaskId, paperScanTaskIdList)
|
|
|
|
+ .eq(PaperScanTaskDetail::getSchoolId, schoolId));
|
|
|
|
+ // 学生基础数据集合
|
|
|
|
+ List<BasicStudent> basicStudentDbList = basicStudentService.list(new QueryWrapper<BasicStudent>().lambda().eq(BasicStudent::getSchoolId, schoolId));
|
|
|
|
+
|
|
|
|
+ List<PaperScanTaskDetail> paperScanTaskDetailList = datasource.stream().flatMap(e -> {
|
|
|
|
+
|
|
|
|
+ String scanTaskName = e.getScanTaskName();
|
|
|
|
+ PaperScanTask paperScanTask = paperScanTaskMap.get(scanTaskName);
|
|
|
|
+ if (Objects.isNull(paperScanTask)) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("扫描任务数据异常");
|
|
|
|
+ }
|
|
|
|
+ Long paperScanTaskId = paperScanTask.getId();
|
|
|
|
+
|
|
|
|
+ String studentCode = e.getStudentCode();
|
|
|
|
+ List<BasicStudent> studentList = basicStudentDbList.stream().filter(s -> s.getStudentCode().equals(studentCode)).collect(Collectors.toList());
|
|
|
|
+ if (studentList.size() != 1) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("学号为【" + studentCode + "】的学生不存在或异常");
|
|
|
|
+ }
|
|
|
|
+ // 目标学生
|
|
|
|
+ BasicStudent targetStudent = studentList.get(0);
|
|
|
|
+ Long studentId = targetStudent.getId();
|
|
|
|
+
|
|
|
|
+ PaperScanTaskDetail paperScanTaskDetail = new PaperScanTaskDetail();
|
|
|
|
+ List<PaperScanTaskDetail> paperScanTaskDetailCellList = paperScanTaskDetailDbList.stream()
|
|
|
|
+ .filter(d -> d.getPaperScanTaskId().equals(paperScanTaskId) && d.getStudentId().equals(studentId) && d.getSchoolId().equals(schoolId))
|
|
|
|
+ .collect(Collectors.toList());
|
|
|
|
+ if (paperScanTaskDetailCellList.size() == 1) {
|
|
|
|
+ paperScanTaskDetail.setId(paperScanTaskDetailCellList.get(0).getId());
|
|
|
|
+ }
|
|
|
|
+ paperScanTaskDetail.setPaperScanTaskId(paperScanTaskId);
|
|
|
|
+ paperScanTaskDetail.setSchoolId(schoolId);
|
|
|
|
+ paperScanTaskDetail.setStudentId(studentId);
|
|
|
|
+ return Stream.of(paperScanTaskDetail);
|
|
|
|
+ }).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ paperScanTaskDetailService.saveOrUpdateBatch(paperScanTaskDetailList);
|
|
|
|
+ }
|
|
|
|
+ return map;
|
|
|
|
+ }
|
|
}
|
|
}
|