|
@@ -11,6 +11,7 @@ import cn.com.qmth.stmms.ms.core.repository.PaperRepo;
|
|
import cn.com.qmth.stmms.ms.core.repository.StudentRepo;
|
|
import cn.com.qmth.stmms.ms.core.repository.StudentRepo;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.apache.commons.codec.digest.DigestUtils;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
|
|
|
import java.io.*;
|
|
import java.io.*;
|
|
import java.util.HashSet;
|
|
import java.util.HashSet;
|
|
@@ -26,8 +27,7 @@ public class RotateTask implements Runnable {
|
|
private SystemConfig systemConfig;
|
|
private SystemConfig systemConfig;
|
|
private HashSet<String> papers;
|
|
private HashSet<String> papers;
|
|
|
|
|
|
- public RotateTask(Paper paper, int degree, PaperRepo paperRepo, SystemConfig systemConfig, HashSet<String> papers, ImageConfig imageConfig, StudentRepo studentRepo
|
|
|
|
- ) {
|
|
|
|
|
|
+ public RotateTask(Paper paper, int degree, PaperRepo paperRepo, SystemConfig systemConfig, HashSet<String> papers, ImageConfig imageConfig, StudentRepo studentRepo) {
|
|
this.paper = paper;
|
|
this.paper = paper;
|
|
this.degree = degree;
|
|
this.degree = degree;
|
|
this.paperRepo = paperRepo;
|
|
this.paperRepo = paperRepo;
|
|
@@ -48,69 +48,101 @@ public class RotateTask implements Runnable {
|
|
String sliceMD5 = null;
|
|
String sliceMD5 = null;
|
|
LOGGER.info("准备生成缩略和裁切旋转图:{}", start);
|
|
LOGGER.info("准备生成缩略和裁切旋转图:{}", start);
|
|
if (imageConfig.isImageEnc()) {
|
|
if (imageConfig.isImageEnc()) {
|
|
- Student student = studentRepo.findByWorkIdAndExamNumber(paper.getWorkId(), paper.getExamNumber());
|
|
|
|
- String imageMd5 = MD5Util.getImageRuleMd5(paper.getWorkId(), paper.getSubject().ordinal(), paper.getAreaCode(), paper.getExamNumber(), student.getId());
|
|
|
|
- thumbPath = systemConfig.getThumbDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
|
|
- + File.separator + paper.getAreaCode() + File.separator + imageMd5;
|
|
|
|
- thumbNew = systemConfig.getThumbDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
|
|
- + File.separator + paper.getAreaCode() + File.separator + imageMd5;
|
|
|
|
- imagePath = systemConfig.getImageDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
|
|
- + File.separator + paper.getAreaCode() + File.separator + imageMd5;
|
|
|
|
- imageNew = systemConfig.getImageDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
|
|
- + File.separator + paper.getAreaCode() + File.separator + imageMd5;
|
|
|
|
|
|
+ File thumbTempFile = null;
|
|
|
|
+ File imageTempFile = null;
|
|
|
|
+ try {
|
|
|
|
+ Student student = studentRepo.findByWorkIdAndExamNumber(paper.getWorkId(), paper.getExamNumber());
|
|
|
|
+ String imageMd5 = MD5Util.getImageRuleMd5(paper.getWorkId(), paper.getSubject().ordinal(), paper.getAreaCode(), paper.getExamNumber(), student.getId());
|
|
|
|
+ thumbPath = systemConfig.getThumbDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
|
|
+ + File.separator + paper.getAreaCode() + File.separator + imageMd5;
|
|
|
|
+ thumbNew = systemConfig.getThumbDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
|
|
+ + File.separator + paper.getAreaCode() + File.separator + imageMd5;
|
|
|
|
+ imagePath = systemConfig.getImageDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
|
|
+ + File.separator + paper.getAreaCode() + File.separator + imageMd5;
|
|
|
|
+ imageNew = systemConfig.getImageDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
|
|
+ + File.separator + paper.getAreaCode() + File.separator + imageMd5;
|
|
|
|
|
|
- //缩略图旋转生成
|
|
|
|
- String thumbOldPath = thumbPath + ".jpg";
|
|
|
|
- String thumbTempPath = thumbPath + "temp.jpg";
|
|
|
|
- File thumbOldFile = new File(thumbOldPath);
|
|
|
|
- //读取指定路径下面的文件
|
|
|
|
- File thumbTempFile = new File(thumbTempPath);
|
|
|
|
- InputStream is = new FileInputStream(thumbOldPath);
|
|
|
|
- OutputStream outputStream = new FileOutputStream(thumbTempPath);
|
|
|
|
- SystemConstant.writeStream(is, outputStream);
|
|
|
|
- //生成旋转图
|
|
|
|
- File thumbNewFile = new File(thumbNew + "_" + start + ".jpg");
|
|
|
|
- thumbTempFile.renameTo(thumbNewFile);
|
|
|
|
- ImageCompression.rotate(thumbNewFile, thumbTempFile, degree);
|
|
|
|
- thumbOldFile.renameTo(thumbNewFile);
|
|
|
|
- is = new FileInputStream(thumbTempFile);
|
|
|
|
- File thumbRotate = new File(thumbPath + ".jpg");
|
|
|
|
- outputStream = new FileOutputStream(thumbRotate);
|
|
|
|
- SystemConstant.writeStream(is, outputStream);
|
|
|
|
-
|
|
|
|
- //裁切原图旋转生成
|
|
|
|
- String imageOldPath = imagePath + ".jpg";
|
|
|
|
- String imageTempPath = imagePath + "temp.jpg";
|
|
|
|
- File imageOldFile = new File(imageOldPath);
|
|
|
|
- //读取指定路径下面的文件
|
|
|
|
- File imageTempFile = new File(imageTempPath);
|
|
|
|
- is = new FileInputStream(imageOldPath);
|
|
|
|
- outputStream = new FileOutputStream(imageTempFile);
|
|
|
|
- SystemConstant.writeStream(is, outputStream);
|
|
|
|
- //生成旋转图
|
|
|
|
- File imageNewFile = new File(imageNew + "_" + start + ".jpg");
|
|
|
|
- imageTempFile.renameTo(imageNewFile);
|
|
|
|
- ImageCompression.rotate(imageNewFile, imageTempFile, degree);
|
|
|
|
- imageOldFile.renameTo(imageNewFile);
|
|
|
|
- is = new FileInputStream(imageTempFile);
|
|
|
|
- File imageRotate = new File(imagePath + ".jpg");
|
|
|
|
- outputStream = new FileOutputStream(imageRotate);
|
|
|
|
- SystemConstant.writeStream(is, outputStream);
|
|
|
|
-
|
|
|
|
- is = new FileInputStream(imageRotate);
|
|
|
|
- sliceMD5 = DigestUtils.md5Hex(is);
|
|
|
|
- if (Objects.nonNull(is)) {
|
|
|
|
|
|
+ //缩略图旋转生成
|
|
|
|
+ String thumbOldPath = thumbPath + ".jpg";
|
|
|
|
+ String thumbTempPath = thumbPath + "temp.jpg";
|
|
|
|
+ File thumbOldFile = new File(thumbOldPath);
|
|
|
|
+ //读取指定路径下面的文件
|
|
|
|
+ thumbTempFile = new File(thumbTempPath);
|
|
|
|
+ InputStream is = new FileInputStream(thumbOldPath);
|
|
|
|
+ OutputStream outputStream = new FileOutputStream(thumbTempPath);
|
|
|
|
+ SystemConstant.writeStream(is, outputStream);
|
|
is.close();
|
|
is.close();
|
|
- }
|
|
|
|
- if (Objects.nonNull(outputStream)) {
|
|
|
|
outputStream.flush();
|
|
outputStream.flush();
|
|
outputStream.close();
|
|
outputStream.close();
|
|
- }
|
|
|
|
- if (Objects.nonNull(thumbTempFile) && thumbTempFile.exists()) {
|
|
|
|
- thumbTempFile.delete();
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(imageTempFile) && imageTempFile.exists()) {
|
|
|
|
- imageTempFile.delete();
|
|
|
|
|
|
+
|
|
|
|
+ //读取原图
|
|
|
|
+ File thumbNewFile = new File(thumbNew + "_" + start + ".jpg");
|
|
|
|
+ FileCopyUtils.copy(thumbTempFile, thumbNewFile);
|
|
|
|
+ ImageCompression.rotate(thumbTempFile, thumbTempFile, degree);
|
|
|
|
+ FileCopyUtils.copy(thumbTempFile, thumbOldFile);
|
|
|
|
+ InputStream is1 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(thumbNewFile));
|
|
|
|
+ //加密原图
|
|
|
|
+ OutputStream outputStream1 = new FileOutputStream(thumbNewFile);
|
|
|
|
+ SystemConstant.writeStream(is1, outputStream1);
|
|
|
|
+ is1.close();
|
|
|
|
+ outputStream1.flush();
|
|
|
|
+ outputStream1.close();
|
|
|
|
+
|
|
|
|
+ //生成旋转图和加密
|
|
|
|
+ InputStream is2 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(thumbOldFile));
|
|
|
|
+ OutputStream outputStream2 = new FileOutputStream(thumbOldFile);
|
|
|
|
+ SystemConstant.writeStream(is2, outputStream2);
|
|
|
|
+ is2.close();
|
|
|
|
+ outputStream2.flush();
|
|
|
|
+ outputStream2.close();
|
|
|
|
+
|
|
|
|
+ //裁切原图旋转生成
|
|
|
|
+ String imageOldPath = imagePath + ".jpg";
|
|
|
|
+ String imageTempPath = imagePath + "temp.jpg";
|
|
|
|
+ File imageOldFile = new File(imageOldPath);
|
|
|
|
+ //读取指定路径下面的文件
|
|
|
|
+ imageTempFile = new File(imageTempPath);
|
|
|
|
+ InputStream is3 = new FileInputStream(imageOldPath);
|
|
|
|
+ OutputStream outputStream3 = new FileOutputStream(imageTempFile);
|
|
|
|
+ SystemConstant.writeStream(is3, outputStream3);
|
|
|
|
+ is3.close();
|
|
|
|
+ outputStream3.flush();
|
|
|
|
+ outputStream3.close();
|
|
|
|
+
|
|
|
|
+ //读取原图
|
|
|
|
+ File imageNewFile = new File(imageNew + "_" + start + ".jpg");
|
|
|
|
+ FileCopyUtils.copy(imageTempFile, imageNewFile);
|
|
|
|
+ ImageCompression.rotate(imageTempFile, imageTempFile, degree);
|
|
|
|
+ FileCopyUtils.copy(imageTempFile, imageOldFile);
|
|
|
|
+ InputStream is4 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(imageNewFile));
|
|
|
|
+ //加密原图
|
|
|
|
+ OutputStream outputStream4 = new FileOutputStream(imageNewFile);
|
|
|
|
+ SystemConstant.writeStream(is4, outputStream4);
|
|
|
|
+ is4.close();
|
|
|
|
+ outputStream4.flush();
|
|
|
|
+ outputStream4.close();
|
|
|
|
+
|
|
|
|
+ //生成旋转图和加密
|
|
|
|
+ InputStream is5 = new ByteArrayInputStream(FileCopyUtils.copyToByteArray(imageOldFile));
|
|
|
|
+ OutputStream outputStream5 = new FileOutputStream(imageOldFile);
|
|
|
|
+ SystemConstant.writeStream(is5, outputStream5);
|
|
|
|
+ is5.close();
|
|
|
|
+ outputStream5.flush();
|
|
|
|
+ outputStream5.close();
|
|
|
|
+
|
|
|
|
+ InputStream is6 = new FileInputStream(imageNewFile);
|
|
|
|
+ sliceMD5 = DigestUtils.md5Hex(is6);
|
|
|
|
+ is6.close();
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ } finally {
|
|
|
|
+// System.gc();
|
|
|
|
+ if (Objects.nonNull(thumbTempFile) && thumbTempFile.exists()) {
|
|
|
|
+ thumbTempFile.delete();
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(imageTempFile) && imageTempFile.exists()) {
|
|
|
|
+ imageTempFile.delete();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
thumbPath = systemConfig.getThumbDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|
|
thumbPath = systemConfig.getThumbDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|