|
@@ -5,10 +5,8 @@ import cn.com.qmth.stmms.ms.admin.service.DataUploadService;
|
|
import cn.com.qmth.stmms.ms.collect.dto.CollectStuDTO;
|
|
import cn.com.qmth.stmms.ms.collect.dto.CollectStuDTO;
|
|
import cn.com.qmth.stmms.ms.collect.dto.CollectSubjectDTO;
|
|
import cn.com.qmth.stmms.ms.collect.dto.CollectSubjectDTO;
|
|
import cn.com.qmth.stmms.ms.collect.dto.LoginDTO;
|
|
import cn.com.qmth.stmms.ms.collect.dto.LoginDTO;
|
|
-import cn.com.qmth.stmms.ms.commons.config.AliYunOssConfig;
|
|
|
|
-import cn.com.qmth.stmms.ms.commons.config.ImageCompressionConfig;
|
|
|
|
-import cn.com.qmth.stmms.ms.commons.config.ImageConfig;
|
|
|
|
-import cn.com.qmth.stmms.ms.commons.config.SystemConfig;
|
|
|
|
|
|
+import cn.com.qmth.stmms.ms.collect.util.OssUploadUtil;
|
|
|
|
+import cn.com.qmth.stmms.ms.commons.config.*;
|
|
import cn.com.qmth.stmms.ms.commons.constant.SystemConstant;
|
|
import cn.com.qmth.stmms.ms.commons.constant.SystemConstant;
|
|
import cn.com.qmth.stmms.ms.commons.utils.CommandUtil;
|
|
import cn.com.qmth.stmms.ms.commons.utils.CommandUtil;
|
|
import cn.com.qmth.stmms.ms.commons.utils.FileUtil;
|
|
import cn.com.qmth.stmms.ms.commons.utils.FileUtil;
|
|
@@ -59,6 +57,8 @@ import java.util.stream.Collectors;
|
|
public class CollectApi {
|
|
public class CollectApi {
|
|
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CollectApi.class);
|
|
private static final org.slf4j.Logger LOGGER = LoggerFactory.getLogger(CollectApi.class);
|
|
|
|
|
|
|
|
+ private static final String SHEET = "SHEET", THUMB = "THUMB", IMAGE = "IMAGE";
|
|
|
|
+
|
|
@Autowired
|
|
@Autowired
|
|
private LoginConfig loginConfig;
|
|
private LoginConfig loginConfig;
|
|
|
|
|
|
@@ -104,6 +104,12 @@ public class CollectApi {
|
|
@Autowired
|
|
@Autowired
|
|
JdbcTemplate jdbcTemplate;
|
|
JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ OssUploadUtil ossUploadUtil;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ ImageServerConfig imageServerConfig;
|
|
|
|
+
|
|
@RequestMapping("user/login")
|
|
@RequestMapping("user/login")
|
|
public LoginDTO login(@RequestParam String loginname, @RequestParam String password) throws Exception {
|
|
public LoginDTO login(@RequestParam String loginname, @RequestParam String password) throws Exception {
|
|
LoginDTO loginDTO = null;
|
|
LoginDTO loginDTO = null;
|
|
@@ -184,7 +190,7 @@ public class CollectApi {
|
|
public CollectStuDTO getStudent(@PathVariable String examNumber) {
|
|
public CollectStuDTO getStudent(@PathVariable String examNumber) {
|
|
Work activeWork = workRepo.findByActiveTrue();
|
|
Work activeWork = workRepo.findByActiveTrue();
|
|
Student student = studentRepo.findByWorkIdAndRelateExamNumberAndTest(activeWork.getId(), examNumber, String.valueOf(TrialEnum.DEFAULT.ordinal()));
|
|
Student student = studentRepo.findByWorkIdAndRelateExamNumberAndTest(activeWork.getId(), examNumber, String.valueOf(TrialEnum.DEFAULT.ordinal()));
|
|
- if(student == null){
|
|
|
|
|
|
+ if (student == null) {
|
|
throw new RuntimeException("无该考生,请处理");
|
|
throw new RuntimeException("无该考生,请处理");
|
|
}
|
|
}
|
|
CollectStuDTO collectStuDTO = new CollectStuDTO();
|
|
CollectStuDTO collectStuDTO = new CollectStuDTO();
|
|
@@ -241,9 +247,9 @@ public class CollectApi {
|
|
dataUploadService.savePaper(student, subject, dto.isManual(), dto.getLevel());
|
|
dataUploadService.savePaper(student, subject, dto.isManual(), dto.getLevel());
|
|
}
|
|
}
|
|
//已知档位,更新阶段
|
|
//已知档位,更新阶段
|
|
- if(Objects.nonNull(dto.getLevel()) && dto.getLevel() != ""){
|
|
|
|
|
|
+ if (Objects.nonNull(dto.getLevel()) && dto.getLevel() != "") {
|
|
MarkSubject markSubject = markSubjectRepo.findOne(activeWork.getId() + "-" + subject.name());
|
|
MarkSubject markSubject = markSubjectRepo.findOne(activeWork.getId() + "-" + subject.name());
|
|
- if(markSubject.getStage().name().equals(MarkStage.INIT.name())){
|
|
|
|
|
|
+ if (markSubject.getStage().name().equals(MarkStage.INIT.name())) {
|
|
markSubject.setStage(MarkStage.LEVEL);
|
|
markSubject.setStage(MarkStage.LEVEL);
|
|
markSubjectRepo.saveAndFlush(markSubject);
|
|
markSubjectRepo.saveAndFlush(markSubject);
|
|
}
|
|
}
|
|
@@ -316,6 +322,7 @@ public class CollectApi {
|
|
if (!md5.equalsIgnoreCase(sheetMD5)) {
|
|
if (!md5.equalsIgnoreCase(sheetMD5)) {
|
|
throw new Exception("图片md5值不一致");
|
|
throw new Exception("图片md5值不一致");
|
|
}
|
|
}
|
|
|
|
+// ossUploadUtil.ossUpload(student, subject, sheetFile, SHEET, systemConfig.getSheetDir(), sheetMD5);
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} finally {
|
|
} finally {
|
|
@@ -409,6 +416,8 @@ public class CollectApi {
|
|
//缩略图删除
|
|
//缩略图删除
|
|
// thumbFileTemp.delete();
|
|
// thumbFileTemp.delete();
|
|
SystemConstant.writeStream(inputStream1, outputStream1);
|
|
SystemConstant.writeStream(inputStream1, outputStream1);
|
|
|
|
+
|
|
|
|
+// String thumbMD5 = DigestUtils.md5Hex(inputStream1);
|
|
long end = System.currentTimeMillis();
|
|
long end = System.currentTimeMillis();
|
|
LOGGER.info("生成原图和缩略图耗时:{}", (end - start) / 1000 + "s");
|
|
LOGGER.info("生成原图和缩略图耗时:{}", (end - start) / 1000 + "s");
|
|
|
|
|
|
@@ -422,6 +431,12 @@ public class CollectApi {
|
|
if (!md5.equalsIgnoreCase(sliceMD5)) {
|
|
if (!md5.equalsIgnoreCase(sliceMD5)) {
|
|
throw new Exception("图片md5值不一致");
|
|
throw new Exception("图片md5值不一致");
|
|
}
|
|
}
|
|
|
|
+ /*if(imageFile.exists()){
|
|
|
|
+ ossUploadUtil.ossUpload(student, subject, imageFile ,IMAGE, systemConfig.getImageDir(),sliceMD5);
|
|
|
|
+ }
|
|
|
|
+ if(thumbFile.exists()){
|
|
|
|
+ ossUploadUtil.ossUpload(student, subject, thumbFile, THUMB, systemConfig.getThumbDir(), thumbMD5);
|
|
|
|
+ }*/
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
} finally {
|
|
} finally {
|
|
@@ -456,32 +471,58 @@ public class CollectApi {
|
|
Student student = studentRepo.findOne(studentId);
|
|
Student student = studentRepo.findOne(studentId);
|
|
Subject subject = Subject.values()[subjectId];
|
|
Subject subject = Subject.values()[subjectId];
|
|
String path = null;
|
|
String path = null;
|
|
- switch (imageType) {
|
|
|
|
- case 1:
|
|
|
|
- //裁切原图
|
|
|
|
- path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject
|
|
|
|
- + File.separator + student.getAreaCode();
|
|
|
|
- break;
|
|
|
|
- case 2:
|
|
|
|
- //缩略图
|
|
|
|
- path = systemConfig.getThumbDir() + File.separator + workId + File.separator + subject
|
|
|
|
- + File.separator + student.getAreaCode();
|
|
|
|
- break;
|
|
|
|
- case 3:
|
|
|
|
- //原图
|
|
|
|
- path = systemConfig.getSheetDir() + File.separator + workId + File.separator + subject
|
|
|
|
- + File.separator + student.getAreaCode();
|
|
|
|
- break;
|
|
|
|
- default:
|
|
|
|
- //分数水印图
|
|
|
|
- path = systemConfig.getWatermark() + File.separator + workId + File.separator + subject
|
|
|
|
- + File.separator + student.getAreaCode();
|
|
|
|
- break;
|
|
|
|
|
|
+ if (imageServerConfig.isAliyunOss()) {
|
|
|
|
+ String dir;
|
|
|
|
+ switch (imageType) {
|
|
|
|
+ case 1:
|
|
|
|
+ //裁切原图
|
|
|
|
+ dir = systemConfig.getImageDir();
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ //缩略图
|
|
|
|
+ dir = systemConfig.getThumbDir();
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ //原图
|
|
|
|
+ dir = systemConfig.getSheetDir();
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ //分数水印图
|
|
|
|
+ dir = "";
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ StringJoiner ossSavePath = new StringJoiner("/").add(imageServerConfig.getDir()).add(dir.replace("\\", "/")).add(String.valueOf(student.getWorkId())).add(subject.name()).add(student.getAreaCode());
|
|
|
|
+ String md5 = MD5Util.getImageRuleMd5(workId, subject.ordinal(), student.getAreaCode(), student.getExamNumber(), student.getId());
|
|
|
|
+ String ossFilePath = ossSavePath.toString().concat("/").concat(md5).concat(".jpg");
|
|
|
|
+ inputStream = ossUploadUtil.ossDownload(ossFilePath);
|
|
|
|
+ } else {
|
|
|
|
+ switch (imageType) {
|
|
|
|
+ case 1:
|
|
|
|
+ //裁切原图
|
|
|
|
+ path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject
|
|
|
|
+ + File.separator + student.getAreaCode();
|
|
|
|
+ break;
|
|
|
|
+ case 2:
|
|
|
|
+ //缩略图
|
|
|
|
+ path = systemConfig.getThumbDir() + File.separator + workId + File.separator + subject
|
|
|
|
+ + File.separator + student.getAreaCode();
|
|
|
|
+ break;
|
|
|
|
+ case 3:
|
|
|
|
+ //原图
|
|
|
|
+ path = systemConfig.getSheetDir() + File.separator + workId + File.separator + subject
|
|
|
|
+ + File.separator + student.getAreaCode();
|
|
|
|
+ break;
|
|
|
|
+ default:
|
|
|
|
+ //分数水印图
|
|
|
|
+ path = systemConfig.getWatermark() + File.separator + workId + File.separator + subject
|
|
|
|
+ + File.separator + student.getAreaCode();
|
|
|
|
+ break;
|
|
|
|
+ }
|
|
|
|
+ String md5 = MD5Util.getImageRuleMd5(workId, subject.ordinal(), student.getAreaCode(), student.getExamNumber(), student.getId());
|
|
|
|
+ File file = new File(path + File.separator + md5 + ".jpg");
|
|
|
|
+ //读取指定路径下面的文件
|
|
|
|
+ inputStream = new FileInputStream(file);
|
|
}
|
|
}
|
|
- String md5 = MD5Util.getImageRuleMd5(workId, subject.ordinal(), student.getAreaCode(), student.getExamNumber(), student.getId());
|
|
|
|
- File file = new File(path + File.separator + md5 + ".jpg");
|
|
|
|
- //读取指定路径下面的文件
|
|
|
|
- inputStream = new FileInputStream(file);
|
|
|
|
outputStream = new BufferedOutputStream(response.getOutputStream());
|
|
outputStream = new BufferedOutputStream(response.getOutputStream());
|
|
SystemConstant.writeStream(inputStream, outputStream);
|
|
SystemConstant.writeStream(inputStream, outputStream);
|
|
long end = System.currentTimeMillis();
|
|
long end = System.currentTimeMillis();
|
|
@@ -582,7 +623,11 @@ public class CollectApi {
|
|
}
|
|
}
|
|
BufferedImage bufferedImage = ImageCompression.compress(outImageFile, compressionConfig);
|
|
BufferedImage bufferedImage = ImageCompression.compress(outImageFile, compressionConfig);
|
|
String thumbFileName = thumbDir + File.separator + fileName + ".jpg";
|
|
String thumbFileName = thumbDir + File.separator + fileName + ".jpg";
|
|
- ImageIO.write(bufferedImage, "jpg", new File(thumbFileName));
|
|
|
|
|
|
+ File outThumbFile = new File(thumbFileName);
|
|
|
|
+ ImageIO.write(bufferedImage, "jpg", outThumbFile);
|
|
|
|
+ FileInputStream thumbIn = new FileInputStream(outThumbFile);
|
|
|
|
+ String thumbMD5 = DigestUtils.md5Hex(thumbIn);
|
|
|
|
+ thumbIn.close();
|
|
|
|
|
|
String md5 = request.getHeader("md5");
|
|
String md5 = request.getHeader("md5");
|
|
if (Objects.isNull(md5)) {
|
|
if (Objects.isNull(md5)) {
|
|
@@ -594,6 +639,14 @@ public class CollectApi {
|
|
throw new Exception("图片md5值不一致");
|
|
throw new Exception("图片md5值不一致");
|
|
}
|
|
}
|
|
in.close();
|
|
in.close();
|
|
|
|
+
|
|
|
|
+ if (outImageFile.exists()) {
|
|
|
|
+ ossUploadUtil.ossUpload(student, subject, outImageFile, IMAGE, systemConfig.getImageDir(), sliceMD5);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (outThumbFile.exists()) {
|
|
|
|
+ ossUploadUtil.ossUpload(student, subject, outThumbFile, THUMB, systemConfig.getThumbDir(), thumbMD5);
|
|
|
|
+ }
|
|
// ImageCompression.imageThumbnail(outFile,new File(thumbFileName),compressionConfig);
|
|
// ImageCompression.imageThumbnail(outFile,new File(thumbFileName),compressionConfig);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -658,6 +711,7 @@ public class CollectApi {
|
|
throw new Exception("图片md5值不一致");
|
|
throw new Exception("图片md5值不一致");
|
|
}
|
|
}
|
|
in.close();
|
|
in.close();
|
|
|
|
+ ossUploadUtil.ossUpload(student, subject, outFile, SHEET, systemConfig.getSheetDir(), sheetMD5);
|
|
}
|
|
}
|
|
|
|
|
|
@RequestMapping(value = "subject/collect-config", method = RequestMethod.POST)
|
|
@RequestMapping(value = "subject/collect-config", method = RequestMethod.POST)
|
|
@@ -829,11 +883,11 @@ public class CollectApi {
|
|
expSj.add("watermark");
|
|
expSj.add("watermark");
|
|
}
|
|
}
|
|
//分数
|
|
//分数
|
|
- if(startScore != null && endScore != null){
|
|
|
|
|
|
+ if (startScore != null && endScore != null) {
|
|
expSj.add(startScore + "-" + endScore);
|
|
expSj.add(startScore + "-" + endScore);
|
|
- } else if(startScore != null && endScore == null){
|
|
|
|
|
|
+ } else if (startScore != null && endScore == null) {
|
|
expSj.add(startScore.toString());
|
|
expSj.add(startScore.toString());
|
|
- }else if(startScore == null && endScore != null){
|
|
|
|
|
|
+ } else if (startScore == null && endScore != null) {
|
|
expSj.add(endScore.toString());
|
|
expSj.add(endScore.toString());
|
|
}
|
|
}
|
|
File out = new File(expSj.toString());
|
|
File out = new File(expSj.toString());
|
|
@@ -941,10 +995,10 @@ public class CollectApi {
|
|
fileName = MD5Util.getImageRuleMd5(workId, subject1.ordinal(), areaCode, examNumber, studentId);
|
|
fileName = MD5Util.getImageRuleMd5(workId, subject1.ordinal(), areaCode, examNumber, studentId);
|
|
}
|
|
}
|
|
String path;
|
|
String path;
|
|
- if(Objects.equals("1", imageType)){
|
|
|
|
|
|
+ if (Objects.equals("1", imageType)) {
|
|
path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject1
|
|
path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject1
|
|
+ File.separator + areaCode;
|
|
+ File.separator + areaCode;
|
|
- } else if (Objects.equals("2", imageType)){
|
|
|
|
|
|
+ } else if (Objects.equals("2", imageType)) {
|
|
path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject1
|
|
path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject1
|
|
+ File.separator + areaCode;
|
|
+ File.separator + areaCode;
|
|
} else {
|
|
} else {
|