|
@@ -25,11 +25,8 @@ public class RotateTask implements Runnable {
|
|
private PaperRepo paperRepo;
|
|
private PaperRepo paperRepo;
|
|
private SystemConfig systemConfig;
|
|
private SystemConfig systemConfig;
|
|
private HashSet<String> papers;
|
|
private HashSet<String> papers;
|
|
- File thumbTempFile = null;
|
|
|
|
- File imageTempFile = null;
|
|
|
|
|
|
|
|
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
|
|
-// ,File thumbTempFile,File imageTempFile
|
|
|
|
) {
|
|
) {
|
|
this.paper = paper;
|
|
this.paper = paper;
|
|
this.degree = degree;
|
|
this.degree = degree;
|
|
@@ -38,8 +35,6 @@ public class RotateTask implements Runnable {
|
|
this.papers = papers;
|
|
this.papers = papers;
|
|
this.imageConfig = imageConfig;
|
|
this.imageConfig = imageConfig;
|
|
this.studentRepo = studentRepo;
|
|
this.studentRepo = studentRepo;
|
|
-// this.thumbTempFile = thumbTempFile;
|
|
|
|
-// this.imageTempFile = imageTempFile;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -53,76 +48,69 @@ public class RotateTask implements Runnable {
|
|
String sliceMD5 = null;
|
|
String sliceMD5 = null;
|
|
LOGGER.info("准备生成缩略和裁切旋转图:{}", start);
|
|
LOGGER.info("准备生成缩略和裁切旋转图:{}", start);
|
|
if (imageConfig.isImageEnc()) {
|
|
if (imageConfig.isImageEnc()) {
|
|
- InputStream is = null;
|
|
|
|
- OutputStream outputStream = 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;
|
|
|
|
|
|
+ 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);
|
|
|
|
- //读取指定路径下面的文件
|
|
|
|
- thumbTempFile = new File(thumbTempPath);
|
|
|
|
- is = new FileInputStream(thumbOldPath);
|
|
|
|
- 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 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);
|
|
|
|
- //读取指定路径下面的文件
|
|
|
|
- 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);
|
|
|
|
|
|
+ //裁切原图旋转生成
|
|
|
|
+ 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);
|
|
|
|
- } catch (Exception e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- } finally {
|
|
|
|
- if (Objects.nonNull(is)) {
|
|
|
|
- is.close();
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(outputStream)) {
|
|
|
|
- outputStream.flush();
|
|
|
|
- outputStream.close();
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(thumbTempFile) && thumbTempFile.exists()) {
|
|
|
|
- thumbTempFile.delete();
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(imageTempFile) && imageTempFile.exists()) {
|
|
|
|
- imageTempFile.delete();
|
|
|
|
- }
|
|
|
|
|
|
+ is = new FileInputStream(imageRotate);
|
|
|
|
+ sliceMD5 = DigestUtils.md5Hex(is);
|
|
|
|
+ if (Objects.nonNull(is)) {
|
|
|
|
+ is.close();
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(outputStream)) {
|
|
|
|
+ outputStream.flush();
|
|
|
|
+ outputStream.close();
|
|
|
|
+ }
|
|
|
|
+ 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()
|
|
@@ -162,12 +150,6 @@ public class RotateTask implements Runnable {
|
|
ioe.printStackTrace();
|
|
ioe.printStackTrace();
|
|
} finally {
|
|
} finally {
|
|
papers.remove(paper.getExamNumber());
|
|
papers.remove(paper.getExamNumber());
|
|
- if (Objects.nonNull(thumbTempFile) && thumbTempFile.exists()) {
|
|
|
|
- thumbTempFile.delete();
|
|
|
|
- }
|
|
|
|
- if (Objects.nonNull(imageTempFile) && imageTempFile.exists()) {
|
|
|
|
- imageTempFile.delete();
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|