|
@@ -1,5 +1,36 @@
|
|
|
package cn.com.qmth.stmms.ms.collect.api;
|
|
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.File;
|
|
|
+import java.io.FileInputStream;
|
|
|
+import java.io.FileNotFoundException;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Optional;
|
|
|
+import java.util.function.Consumer;
|
|
|
+
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+
|
|
|
+import net.sf.json.JSONObject;
|
|
|
+
|
|
|
+import org.apache.commons.codec.digest.DigestUtils;
|
|
|
+import org.assertj.core.util.Strings;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
+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 cn.com.qmth.stmms.ms.accesscontrol.config.LoginConfig;
|
|
|
import cn.com.qmth.stmms.ms.admin.service.DataUploadService;
|
|
|
import cn.com.qmth.stmms.ms.collect.dto.CollectStuDTO;
|
|
@@ -9,7 +40,6 @@ import cn.com.qmth.stmms.ms.commons.config.ImageCompressionConfig;
|
|
|
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.MarkSubject;
|
|
|
-import cn.com.qmth.stmms.ms.core.domain.Paper;
|
|
|
import cn.com.qmth.stmms.ms.core.domain.Student;
|
|
|
import cn.com.qmth.stmms.ms.core.domain.Work;
|
|
|
import cn.com.qmth.stmms.ms.core.repository.MarkSubjectRepo;
|
|
@@ -17,26 +47,6 @@ 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.WorkRepo;
|
|
|
import cn.com.qmth.stmms.ms.core.vo.Subject;
|
|
|
-import net.sf.json.JSONObject;
|
|
|
-
|
|
|
-import org.apache.commons.codec.digest.DigestUtils;
|
|
|
-import org.assertj.core.util.Strings;
|
|
|
-import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.util.FileCopyUtils;
|
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
-
|
|
|
-import javax.imageio.ImageIO;
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
-import javax.servlet.http.HttpServletResponse;
|
|
|
-
|
|
|
-import java.awt.image.BufferedImage;
|
|
|
-import java.io.*;
|
|
|
-import java.text.SimpleDateFormat;
|
|
|
-import java.util.ArrayList;
|
|
|
-import java.util.Date;
|
|
|
-import java.util.List;
|
|
|
-import java.util.Optional;
|
|
|
-import java.util.function.Consumer;
|
|
|
|
|
|
/**
|
|
|
* Created by dizhi on 2016/12/24.
|
|
@@ -112,7 +122,7 @@ public class CollectApi {
|
|
|
|
|
|
@RequestMapping(value = "upload/student/{subjectId}", method = RequestMethod.POST)
|
|
|
public List<CollectStuDTO> saveStudent(HttpServletRequest request, @PathVariable Integer subjectId,
|
|
|
- @RequestBody CollectStuDTO[] uploadStudentArray) {
|
|
|
+ @RequestBody CollectStuDTO[] uploadStudentArray) throws IOException {
|
|
|
Subject subject = Subject.values()[subjectId-1];
|
|
|
Work activeWork = workRepo.findByActiveTrue();
|
|
|
List<CollectStuDTO> list = new ArrayList<>();
|
|
@@ -138,37 +148,31 @@ public class CollectApi {
|
|
|
public void upload(@PathVariable Long workId,@PathVariable Integer subjectId,
|
|
|
@PathVariable String fileName,
|
|
|
HttpServletRequest request,HttpServletResponse response) throws IOException{
|
|
|
- String md5 = request.getHeader("md5");
|
|
|
InputStream inputStream = request.getInputStream();
|
|
|
- String sliceMD5 = DigestUtils.md5Hex(inputStream);
|
|
|
- if(!md5.equalsIgnoreCase(sliceMD5)){
|
|
|
- throw new RuntimeException("图片md5值不一致");
|
|
|
- }
|
|
|
Student student = studentRepo.findByWorkIdAndExamNumber(workId,fileName);
|
|
|
Subject subject = Subject.values()[subjectId-1];
|
|
|
- Paper paper = paperRepo.findByWorkIdAndSubjectAndExamNumber(student.getWorkId(), subject,
|
|
|
- student.getExamNumber());
|
|
|
- //保存遮盖图
|
|
|
- String savePath = systemConfig.getImageDir() + File.separator + workId + File.separator + subject
|
|
|
+ //保存遮盖图
|
|
|
+ String savePath = systemConfig.getImageDir() + File.separator + workId + File.separator + subject
|
|
|
+ File.separator + student.getAreaCode();
|
|
|
- File outFile = saveImage(student, inputStream, savePath);
|
|
|
- // 生成缩略图
|
|
|
- String thumbDir = systemConfig.getThumbDir() + File.separator + workId + File.separator + subject
|
|
|
+ File outFile = saveImage(student, inputStream, savePath);
|
|
|
+
|
|
|
+ // 生成缩略图
|
|
|
+ String thumbDir = systemConfig.getThumbDir() + File.separator + workId + File.separator + subject
|
|
|
+ File.separator + student.getAreaCode();
|
|
|
- File thumb = new File(thumbDir);
|
|
|
- if (!thumb.exists()) {
|
|
|
- thumb.mkdirs();
|
|
|
- }
|
|
|
- BufferedImage bufferedImage = ImageCompression.compress(outFile, compressionConfig);
|
|
|
- String thumbFileName = thumbDir + File.separator + student.getExamNumber() + ".jpg";
|
|
|
- ImageIO.write(bufferedImage, "jpg", new File(thumbFileName));
|
|
|
-
|
|
|
- paper.setSliceMD5(sliceMD5);
|
|
|
- paperRepo.save(paper);
|
|
|
+ File thumb = new File(thumbDir);
|
|
|
+ if (!thumb.exists()) {
|
|
|
+ thumb.mkdirs();
|
|
|
+ }
|
|
|
+ BufferedImage bufferedImage = ImageCompression.compress(outFile, compressionConfig);
|
|
|
+ String thumbFileName = thumbDir + File.separator + student.getExamNumber() + ".jpg";
|
|
|
+ ImageIO.write(bufferedImage, "jpg", new File(thumbFileName));
|
|
|
|
|
|
+ String md5 = request.getHeader("md5");
|
|
|
+ String sliceMD5 = DigestUtils.md5Hex(new FileInputStream(outFile));
|
|
|
+ if(!md5.equalsIgnoreCase(sliceMD5)){
|
|
|
+ throw new RuntimeException("图片md5值不一致");
|
|
|
+ }
|
|
|
// ImageCompression.imageThumbnail(outFile,new File(thumbFileName),compressionConfig);
|
|
|
-
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private File saveImage(Student student, InputStream inputStream,
|
|
@@ -197,20 +201,17 @@ public class CollectApi {
|
|
|
HttpServletRequest request,HttpServletResponse response) throws IOException{
|
|
|
Student student = studentRepo.findByWorkIdAndExamNumber(workId,fileName);
|
|
|
Subject subject = Subject.values()[subjectId-1];
|
|
|
- Paper paper = paperRepo.findByWorkIdAndSubjectAndExamNumber(student.getWorkId(), subject,
|
|
|
- student.getExamNumber());
|
|
|
InputStream inputStream = request.getInputStream();
|
|
|
- String md5 = request.getHeader("md5");
|
|
|
- String sheetMD5 = DigestUtils.md5Hex(inputStream);
|
|
|
- if(!md5.equalsIgnoreCase(sheetMD5)){
|
|
|
- throw new RuntimeException("图片md5值不一致");
|
|
|
- }
|
|
|
//保存原图图
|
|
|
String savePath = systemConfig.getSheetDir() + File.separator + workId + File.separator + subject
|
|
|
+ File.separator + student.getAreaCode();
|
|
|
- saveImage(student, inputStream, savePath);
|
|
|
- paper.setSheetMD5(sheetMD5);
|
|
|
- paperRepo.save(paper);
|
|
|
+ File outFile = saveImage(student, inputStream, savePath);
|
|
|
+
|
|
|
+ String md5 = request.getHeader("md5");
|
|
|
+ String sheetMD5 = DigestUtils.md5Hex(new FileInputStream(outFile));
|
|
|
+ if(!md5.equalsIgnoreCase(sheetMD5)){
|
|
|
+ throw new RuntimeException("图片md5值不一致");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "subject/collect-config", method = RequestMethod.POST)
|