|
@@ -2,14 +2,17 @@ package com.qmth.paper.library.business.service.impl;
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.qmth.boot.api.exception.ApiException;
|
|
import com.qmth.paper.library.business.bean.result.PaperLibraryImageResult;
|
|
import com.qmth.paper.library.business.bean.result.PaperLibraryImageResult;
|
|
import com.qmth.paper.library.business.bean.result.PaperLibraryResult;
|
|
import com.qmth.paper.library.business.bean.result.PaperLibraryResult;
|
|
import com.qmth.paper.library.business.bean.result.TaskStudentResult;
|
|
import com.qmth.paper.library.business.bean.result.TaskStudentResult;
|
|
import com.qmth.paper.library.business.bean.vo.FilePathVo;
|
|
import com.qmth.paper.library.business.bean.vo.FilePathVo;
|
|
|
|
+import com.qmth.paper.library.business.bean.vo.PathSequenceVo;
|
|
import com.qmth.paper.library.business.bean.vo.RecognitionResultVo;
|
|
import com.qmth.paper.library.business.bean.vo.RecognitionResultVo;
|
|
import com.qmth.paper.library.business.entity.PaperLibrary;
|
|
import com.qmth.paper.library.business.entity.PaperLibrary;
|
|
import com.qmth.paper.library.business.entity.PaperScanTask;
|
|
import com.qmth.paper.library.business.entity.PaperScanTask;
|
|
@@ -18,17 +21,17 @@ import com.qmth.paper.library.business.service.*;
|
|
import com.qmth.paper.library.common.bean.dto.syssetting.SimpleObject;
|
|
import com.qmth.paper.library.common.bean.dto.syssetting.SimpleObject;
|
|
import com.qmth.paper.library.common.contant.SysSettingConstant;
|
|
import com.qmth.paper.library.common.contant.SysSettingConstant;
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
import com.qmth.paper.library.common.contant.SystemConstant;
|
|
|
|
+import com.qmth.paper.library.common.entity.BasicExam;
|
|
import com.qmth.paper.library.common.entity.BasicSchool;
|
|
import com.qmth.paper.library.common.entity.BasicSchool;
|
|
|
|
+import com.qmth.paper.library.common.entity.BasicSemester;
|
|
import com.qmth.paper.library.common.entity.ExamStudent;
|
|
import com.qmth.paper.library.common.entity.ExamStudent;
|
|
-import com.qmth.paper.library.common.enums.ExceptionResultEnum;
|
|
|
|
-import com.qmth.paper.library.common.enums.RecognitionTypeEnum;
|
|
|
|
-import com.qmth.paper.library.common.enums.RoleTypeEnum;
|
|
|
|
-import com.qmth.paper.library.common.enums.UploadFileEnum;
|
|
|
|
|
|
+import com.qmth.paper.library.common.enums.*;
|
|
import com.qmth.paper.library.common.service.BasicSchoolService;
|
|
import com.qmth.paper.library.common.service.BasicSchoolService;
|
|
|
|
+import com.qmth.paper.library.common.service.BasicSemesterService;
|
|
import com.qmth.paper.library.common.service.CommonCacheService;
|
|
import com.qmth.paper.library.common.service.CommonCacheService;
|
|
-import com.qmth.paper.library.common.service.SysUserService;
|
|
|
|
import com.qmth.paper.library.common.util.*;
|
|
import com.qmth.paper.library.common.util.*;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
|
|
+import org.apache.commons.io.FilenameUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
@@ -41,7 +44,6 @@ import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
-import java.util.Set;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -56,6 +58,12 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
@Resource
|
|
@Resource
|
|
private BasicSchoolService basicSchoolService;
|
|
private BasicSchoolService basicSchoolService;
|
|
@Resource
|
|
@Resource
|
|
|
|
+ private BasicExamService basicExamService;
|
|
|
|
+ @Resource
|
|
|
|
+ private BusinessCacheService businessCacheService;
|
|
|
|
+ @Resource
|
|
|
|
+ private BasicSemesterService basicSemesterService;
|
|
|
|
+ @Resource
|
|
private ExamStudentService examStudentService;
|
|
private ExamStudentService examStudentService;
|
|
@Resource
|
|
@Resource
|
|
private FileUploadService fileUploadService;
|
|
private FileUploadService fileUploadService;
|
|
@@ -252,11 +260,23 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
if (paperLibrary.getStudentId() != null && paperLibrary.getStudentId().equals(studentId)) {
|
|
if (paperLibrary.getStudentId() != null && paperLibrary.getStudentId().equals(studentId)) {
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+ PathSequenceVo pathSequenceVo = null;
|
|
|
|
+ try {
|
|
|
|
+ // 将图片复制到学号目录下,并删除原图片
|
|
|
|
+ pathSequenceVo = copyImageToStudentCode(paperLibrary, studentId, UploadFileEnum.IMAGE);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error("纠错操作复制图片失败");
|
|
|
|
+ }
|
|
|
|
|
|
// 更新绑定考生ID
|
|
// 更新绑定考生ID
|
|
UpdateWrapper<PaperLibrary> updateWrapper = new UpdateWrapper<>();
|
|
UpdateWrapper<PaperLibrary> updateWrapper = new UpdateWrapper<>();
|
|
- updateWrapper.lambda().set(PaperLibrary::getStudentId, studentId)
|
|
|
|
- .eq(PaperLibrary::getId, paperLibraryId);
|
|
|
|
|
|
+ LambdaUpdateWrapper<PaperLibrary> lambda = updateWrapper.lambda();
|
|
|
|
+ lambda.set(PaperLibrary::getStudentId, studentId);
|
|
|
|
+ if (pathSequenceVo != null) {
|
|
|
|
+ lambda.set(PaperLibrary::getPath, pathSequenceVo.getPath());
|
|
|
|
+ lambda.set(PaperLibrary::getSequence, pathSequenceVo.getSequence());
|
|
|
|
+ }
|
|
|
|
+ lambda.eq(PaperLibrary::getId, paperLibraryId);
|
|
this.update(updateWrapper);
|
|
this.update(updateWrapper);
|
|
// 更新考生绑定数量
|
|
// 更新考生绑定数量
|
|
if (paperLibrary.getStudentId() != null) {
|
|
if (paperLibrary.getStudentId() != null) {
|
|
@@ -266,6 +286,62 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private PathSequenceVo copyImageToStudentCode(PaperLibrary paperLibrary, Long studentId, UploadFileEnum uploadFileEnum) {
|
|
|
|
+ PaperScanTask paperScanTask = paperScanTaskService.getById(paperLibrary.getPaperScanTaskId());
|
|
|
|
+ BasicSchool basicSchool = basicSchoolService.getById(paperScanTask.getSchoolId());
|
|
|
|
+ BasicExam basicExam = basicExamService.getById(paperScanTask.getExamId());
|
|
|
|
+ BasicSemester basicSemester = basicSemesterService.getById(basicExam.getSemesterId());
|
|
|
|
+ String courseNameCode = String.format("%s(%s)", paperScanTask.getCourseName(), paperScanTask.getCourseCode());
|
|
|
|
+ ExamStudent examStudent = examStudentService.getById(studentId);
|
|
|
|
+ String rootPath = fileStoreUtil.buildPath(UploadFileEnum.IMAGE, false, basicSchool.getName(), basicSemester.getName(), basicExam.getName(), courseNameCode);
|
|
|
|
+ if (StoreTypeEnum.ROOM.equals(paperScanTask.getStoreType())) {
|
|
|
|
+ rootPath = fileStoreUtil.buildPath(UploadFileEnum.IMAGE, false, basicSchool.getName(), basicSemester.getName(), basicExam.getName(), courseNameCode, examStudent.getExamRoom());
|
|
|
|
+ } else if (StoreTypeEnum.CLASS.equals(paperScanTask.getStoreType())) {
|
|
|
|
+ rootPath = fileStoreUtil.buildPath(UploadFileEnum.IMAGE, false, basicSchool.getName(), basicSemester.getName(), basicExam.getName(), courseNameCode, examStudent.getClassName());
|
|
|
|
+ } else if (StoreTypeEnum.COURSE.equals(paperScanTask.getStoreType())) {
|
|
|
|
+ rootPath = fileStoreUtil.buildPath(UploadFileEnum.IMAGE, false, basicSchool.getName(), basicSemester.getName(), basicExam.getName(), courseNameCode, examStudent.getStudentCode());
|
|
|
|
+ }
|
|
|
|
+ // 根目录
|
|
|
|
+ boolean isAllCopy = true;
|
|
|
|
+ List<FilePathVo> objects = new ArrayList<>();
|
|
|
|
+ int sequence = businessCacheService.getSequence(paperScanTask.getId(), examStudent.getStudentCode());
|
|
|
|
+ String sequenceStr = String.valueOf(sequence);
|
|
|
|
+ try {
|
|
|
|
+ int idx = 1;
|
|
|
|
+ String prefix = examStudent.getStudentCode() + "-" + sequenceStr;
|
|
|
|
+ List<FilePathVo> filePathVoList = JSON.parseArray(paperLibrary.getPath(), FilePathVo.class);
|
|
|
|
+ for (FilePathVo filePath : filePathVoList) {
|
|
|
|
+ String suffix = filePath.getPath().substring(filePath.getPath().lastIndexOf("."));
|
|
|
|
+ // 目标文件名
|
|
|
|
+ String dirName = rootPath + File.separator + prefix + "-" + idx + suffix;
|
|
|
|
+ File file = new File(dirName);
|
|
|
|
+ if(!file.exists()){
|
|
|
|
+ file.getParentFile().mkdirs();
|
|
|
|
+ file.createNewFile();
|
|
|
|
+ }
|
|
|
|
+ boolean success = fileUploadService.copy(filePath.getPath(), dirName);
|
|
|
|
+ if (isAllCopy) {
|
|
|
|
+ isAllCopy = success;
|
|
|
|
+ }
|
|
|
|
+ objects.add(new FilePathVo(dirName, uploadFileEnum, filePath.getType(), filePath.getMd5()));
|
|
|
|
+ idx++;
|
|
|
|
+ }
|
|
|
|
+ if (isAllCopy) {
|
|
|
|
+ for (FilePathVo filePathVo : filePathVoList) {
|
|
|
|
+ fileUploadService.deleteFile(filePathVo.getPath());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
+ if (e instanceof ApiException) {
|
|
|
|
+ ResultUtil.error((ApiException) e, e.getMessage());
|
|
|
|
+ } else {
|
|
|
|
+ ResultUtil.error(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ return isAllCopy ? new PathSequenceVo(JSON.toJSONString(objects), sequence) : null;
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public int countByStudentId(Long studentId) {
|
|
public int countByStudentId(Long studentId) {
|
|
QueryWrapper<PaperLibrary> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<PaperLibrary> queryWrapper = new QueryWrapper<>();
|