|
@@ -29,10 +29,14 @@ import com.qmth.paper.library.common.enums.ExceptionResultEnum;
|
|
import com.qmth.paper.library.common.enums.RecognitionTypeEnum;
|
|
import com.qmth.paper.library.common.enums.RecognitionTypeEnum;
|
|
import com.qmth.paper.library.common.enums.StoreTypeEnum;
|
|
import com.qmth.paper.library.common.enums.StoreTypeEnum;
|
|
import com.qmth.paper.library.common.enums.UploadFileEnum;
|
|
import com.qmth.paper.library.common.enums.UploadFileEnum;
|
|
|
|
+import com.qmth.paper.library.common.lock.LockService;
|
|
|
|
+import com.qmth.paper.library.common.lock.LockType;
|
|
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.BasicSemesterService;
|
|
import com.qmth.paper.library.common.service.CommonCacheService;
|
|
import com.qmth.paper.library.common.service.CommonCacheService;
|
|
import com.qmth.paper.library.common.util.*;
|
|
import com.qmth.paper.library.common.util.*;
|
|
|
|
+import net.coobird.thumbnailator.Thumbnails;
|
|
|
|
+import org.apache.commons.collections4.CollectionUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
@@ -46,6 +50,7 @@ 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.stream.Collectors;
|
|
|
|
|
|
/**
|
|
/**
|
|
* <p>
|
|
* <p>
|
|
@@ -75,6 +80,8 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
private FileStoreUtil fileStoreUtil;
|
|
private FileStoreUtil fileStoreUtil;
|
|
@Resource
|
|
@Resource
|
|
private CommonCacheService commonCacheService;
|
|
private CommonCacheService commonCacheService;
|
|
|
|
+ @Resource
|
|
|
|
+ private LockService lockService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public int countScanStudentCount(Long paperScanTaskId) {
|
|
public int countScanStudentCount(Long paperScanTaskId) {
|
|
@@ -100,7 +107,7 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
}
|
|
}
|
|
|
|
|
|
QueryWrapper<PaperLibrary> queryWrapper = new QueryWrapper<>();
|
|
QueryWrapper<PaperLibrary> queryWrapper = new QueryWrapper<>();
|
|
- queryWrapper.lambda().eq(paperScanTaskId!= null, PaperLibrary::getPaperScanTaskId, paperScanTaskId)
|
|
|
|
|
|
+ queryWrapper.lambda().eq(paperScanTaskId != null, PaperLibrary::getPaperScanTaskId, paperScanTaskId)
|
|
.eq(PaperLibrary::getStudentId, studentId)
|
|
.eq(PaperLibrary::getStudentId, studentId)
|
|
.orderByAsc(PaperLibrary::getSequence);
|
|
.orderByAsc(PaperLibrary::getSequence);
|
|
List<PaperLibrary> paperLibraryList = this.list(queryWrapper);
|
|
List<PaperLibrary> paperLibraryList = this.list(queryWrapper);
|
|
@@ -256,7 +263,7 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
public boolean rebind(Long paperLibraryId, Long studentId) {
|
|
public boolean rebind(Long paperLibraryId, Long studentId) {
|
|
PaperLibrary paperLibrary = this.getById(paperLibraryId);
|
|
PaperLibrary paperLibrary = this.getById(paperLibraryId);
|
|
if (paperLibrary == null) {
|
|
if (paperLibrary == null) {
|
|
- throw ExceptionResultEnum.ERROR.exception("该图片数据不存在");
|
|
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("图片数据不存在");
|
|
}
|
|
}
|
|
// 自己绑定自己,直接返回
|
|
// 自己绑定自己,直接返回
|
|
if (paperLibrary.getStudentId() != null && paperLibrary.getStudentId().equals(studentId)) {
|
|
if (paperLibrary.getStudentId() != null && paperLibrary.getStudentId().equals(studentId)) {
|
|
@@ -317,7 +324,7 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
// 目标文件名
|
|
// 目标文件名
|
|
String dirName = rootPath + File.separator + prefix + "-" + idx + suffix;
|
|
String dirName = rootPath + File.separator + prefix + "-" + idx + suffix;
|
|
File file = new File(dirName);
|
|
File file = new File(dirName);
|
|
- if(!file.exists()){
|
|
|
|
|
|
+ if (!file.exists()) {
|
|
file.getParentFile().mkdirs();
|
|
file.getParentFile().mkdirs();
|
|
file.createNewFile();
|
|
file.createNewFile();
|
|
}
|
|
}
|
|
@@ -365,7 +372,54 @@ public class PaperLibraryServiceImpl extends ServiceImpl<PaperLibraryMapper, Pap
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<String> listBatchNo(Long studentId) {
|
|
public List<String> listBatchNo(Long studentId) {
|
|
- return baseMapper.listBatchNo(studentId);
|
|
|
|
|
|
+ List<String> list = baseMapper.listBatchNo(studentId);
|
|
|
|
+ return list.stream().filter(m -> StringUtils.isNotBlank(m)).collect(Collectors.toList());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @Transactional
|
|
|
|
+ @Override
|
|
|
|
+ public boolean deletePicture(Long paperLibraryId) {
|
|
|
|
+ PaperLibrary paperLibrary = this.getById(paperLibraryId);
|
|
|
|
+ if (paperLibrary == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("图片数据不存在");
|
|
|
|
+ }
|
|
|
|
+ if (paperLibrary.getStudentId() != null) {
|
|
|
|
+ examStudentService.updateBindCount(paperLibrary.getStudentId());
|
|
|
|
+ }
|
|
|
|
+ return this.removeById(paperLibraryId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean rotatePictureUpload(Long paperLibraryId, boolean isFront, Integer rotate) {
|
|
|
|
+ File outputFile = null;
|
|
|
|
+ try {
|
|
|
|
+ lockService.waitlock(LockType.ROTATE_PICTURE, paperLibraryId, isFront);
|
|
|
|
+ PaperLibrary paperLibrary = this.getById(paperLibraryId);
|
|
|
|
+ if (paperLibrary == null) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("图片数据不存在");
|
|
|
|
+ }
|
|
|
|
+ List<FilePathVo> filePathVoList = JSON.parseArray(paperLibrary.getPath(), FilePathVo.class);
|
|
|
|
+ if (CollectionUtils.isEmpty(filePathVoList) || filePathVoList.size() != 2) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("图片路径数据错误");
|
|
|
|
+ }
|
|
|
|
+ // 取图片路径
|
|
|
|
+ FilePathVo filePathVo = filePathVoList.get(isFront ? 0 : 1);
|
|
|
|
+ // 旋转图片,并重新上传(文件名不变)
|
|
|
|
+ outputFile = SystemConstant.getFileTempVar(filePathVo.getPath().substring(filePathVo.getPath().lastIndexOf(SystemConstant.ORG_POINT)));
|
|
|
|
+ ImageUtil.rotate(fileUploadService.downloadInputStream(filePathVo.getPath(), filePathVo.getType()), rotate, outputFile);
|
|
|
|
+ if (outputFile.exists()) {
|
|
|
|
+ fileUploadService.uploadFile(outputFile, filePathVo.getUploadType(), filePathVo.getPath());
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ throw ExceptionResultEnum.ERROR.exception("旋转图片保存失败:" + e.getMessage());
|
|
|
|
+ } finally {
|
|
|
|
+ if (outputFile != null && outputFile.exists()) {
|
|
|
|
+ outputFile.delete();
|
|
|
|
+ }
|
|
|
|
+ lockService.unlock(LockType.ROTATE_PICTURE, paperLibraryId, isFront);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|