|
@@ -1,19 +1,22 @@
|
|
|
package cn.com.qmth.stmms.ms.collect.api;
|
|
|
|
|
|
-import cn.com.qmth.stmms.ms.commons.config.SystemConfig;
|
|
|
-import cn.com.qmth.stmms.ms.commons.utils.image.ImageCompression;
|
|
|
-import cn.com.qmth.stmms.ms.core.domain.Paper;
|
|
|
-import cn.com.qmth.stmms.ms.core.repository.PaperRepo;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.concurrent.ExecutorService;
|
|
|
+import java.util.concurrent.Executors;
|
|
|
+
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
+import org.springframework.web.bind.annotation.RequestParam;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
-import javax.imageio.ImageIO;
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
-import java.io.*;
|
|
|
-import java.nio.file.Path;
|
|
|
-import java.nio.file.Paths;
|
|
|
+import cn.com.qmth.stmms.ms.collect.util.RotateTask;
|
|
|
+import cn.com.qmth.stmms.ms.commons.config.SystemConfig;
|
|
|
+import cn.com.qmth.stmms.ms.core.domain.Paper;
|
|
|
+import cn.com.qmth.stmms.ms.core.repository.PaperRepo;
|
|
|
|
|
|
/**
|
|
|
* Created by zhengmin on 2017/2/24.
|
|
@@ -27,33 +30,24 @@ public class ImageApi {
|
|
|
|
|
|
@Autowired
|
|
|
private SystemConfig systemConfig;
|
|
|
+
|
|
|
+ private ExecutorService executor = Executors.newFixedThreadPool(10);
|
|
|
+
|
|
|
+ private HashSet<String> papers = new HashSet<String>();
|
|
|
|
|
|
@RequestMapping(value = "{paperId}/rotate",method = RequestMethod.GET)
|
|
|
- public ResponseEntity rotate(@PathVariable Long paperId,
|
|
|
- @RequestParam int degree){
|
|
|
- Paper paper = paperRepo.findOne(paperId);
|
|
|
- Path thumbPath = Paths.get(systemConfig.getThumbDir(),String.valueOf(paper.getWorkId()),paper.getSubject().toString(),paper.getAreaCode(),paper.getExamNumber() + ".jpg");
|
|
|
- Path imagePath = Paths.get(systemConfig.getImageDir(),String.valueOf(paper.getWorkId()),paper.getSubject().toString(),paper.getAreaCode(),paper.getExamNumber() + ".jpg");
|
|
|
- try {
|
|
|
- File thumbFile = thumbPath.toFile();
|
|
|
- if(thumbFile.exists()) {
|
|
|
- InputStream is = new FileInputStream(thumbFile);
|
|
|
- BufferedImage image = ImageIO.read(is);
|
|
|
- ImageCompression.rotate(thumbFile, thumbFile, degree);
|
|
|
- is.close();
|
|
|
- }
|
|
|
- File imageFile = imagePath.toFile();
|
|
|
- if(imageFile.exists()){
|
|
|
- InputStream is = new FileInputStream(imageFile);
|
|
|
- BufferedImage image = ImageIO.read(is);
|
|
|
- ImageCompression.rotate(imageFile, imageFile, degree);
|
|
|
- is.close();
|
|
|
- }
|
|
|
- } catch (FileNotFoundException e) {
|
|
|
- e.printStackTrace();
|
|
|
- } catch (IOException ioe){
|
|
|
- ioe.printStackTrace();
|
|
|
+ public ResponseEntity rotate(@PathVariable Long paperId,@RequestParam int degree){
|
|
|
+ Paper paper = paperRepo.findOne(paperId);
|
|
|
+ if(!papers.contains(paper.getExamNumber())){
|
|
|
+ executor.submit(new RotateTask(paper,degree,paperRepo,systemConfig,papers));
|
|
|
+ papers.add(paper.getExamNumber());
|
|
|
}
|
|
|
return new ResponseEntity(HttpStatus.OK);
|
|
|
}
|
|
|
+
|
|
|
+ @RequestMapping(value = "process",method = RequestMethod.GET)
|
|
|
+ public ResponseEntity process(){
|
|
|
+ return new ResponseEntity(papers.size(),HttpStatus.OK);
|
|
|
+ }
|
|
|
+
|
|
|
}
|