|
@@ -47,69 +47,78 @@ public class RotateTask implements Runnable {
|
|
|
String sliceMD5 = null;
|
|
|
LOGGER.info("准备生成缩略和裁切旋转图:{}", start);
|
|
|
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;
|
|
|
+ InputStream is = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ 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 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 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);
|
|
|
+ //裁切原图旋转生成
|
|
|
+ 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);
|
|
|
|
|
|
- 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();
|
|
|
+ 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();
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
thumbPath = systemConfig.getThumbDir() + File.separator + paper.getWorkId() + File.separator + paper.getSubject().toString()
|