|
@@ -809,25 +809,29 @@ public class CollectApi {
|
|
|
@RequestParam(required = false) Integer startScore,
|
|
|
@RequestParam(required = false) Integer endScore,
|
|
|
@RequestParam String savePath) throws Exception {
|
|
|
- String[] strings = {"{{workId}}","{{areaCode}}","{{school}}","{{subject}}"};
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(imageType)) {
|
|
|
+ throw new RuntimeException("请选择图片类型");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(nameRule)) {
|
|
|
+ throw new RuntimeException("请选择命名规则");
|
|
|
+ }
|
|
|
+ if (StringUtils.isBlank(savePath)) {
|
|
|
+ throw new RuntimeException("请输入文档路径");
|
|
|
+ }
|
|
|
+
|
|
|
+ String[] strings = {"{{workId}}", "{{areaCode}}", "{{school}}", "{{subject}}"};
|
|
|
List<String> stringList = Arrays.asList(strings);
|
|
|
String[] savePaths = savePath.split("\\\\");
|
|
|
for (String string : savePaths) {
|
|
|
- if(StringUtils.isEmpty(string)){
|
|
|
+ if (StringUtils.isEmpty(string)) {
|
|
|
continue;
|
|
|
}
|
|
|
- if(!stringList.contains(string)){
|
|
|
+ if (!stringList.contains(string)) {
|
|
|
throw new Exception("文档路径格式不对");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- if (StringUtils.isBlank(imageType)) {
|
|
|
- throw new RuntimeException("请选择图片类型");
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(nameRule)) {
|
|
|
- throw new RuntimeException("请选择命名规则");
|
|
|
- }
|
|
|
-
|
|
|
try {
|
|
|
//首先根据workId和阶段去查所有试卷
|
|
|
StringBuffer sql = new StringBuffer();
|
|
@@ -844,154 +848,166 @@ public class CollectApi {
|
|
|
}
|
|
|
List<Map<String, Object>> paperList = jdbcTemplate.queryForList(sql.toString());
|
|
|
AtomicInteger atomicInteger = new AtomicInteger(0);
|
|
|
+ LOGGER.info("==========================导出分数图片开始,共{}数据================================", paperList.size());
|
|
|
for (Map map : paperList) {
|
|
|
- LOGGER.info("==========================导出分数图片开始,共{}数据================================", paperList.size());
|
|
|
executors.submit(() -> {
|
|
|
- InputStream inputStream = null;
|
|
|
- OutputStream outputStream = null;
|
|
|
- long start = System.currentTimeMillis();
|
|
|
- try {
|
|
|
- Long studentId = Long.valueOf(map.get("studentId").toString());
|
|
|
- String studentName = map.get("studentName").toString();
|
|
|
- String subject = map.get("subject").toString();
|
|
|
- Subject subject1 = Subject.valueOf(subject);
|
|
|
- String areaCode = map.get("areaCode").toString();
|
|
|
- String school = String.valueOf(map.get("school"));
|
|
|
- String examNumber = map.get("examNumber").toString();
|
|
|
- Double score = Double.parseDouble(map.get("score").toString());
|
|
|
-
|
|
|
- String fileName = examNumber;
|
|
|
- //图片加密、命名规则为随机码的,都是需要md5
|
|
|
- if (ParamCache.paramMap.get(workId).getNameRule() == 1 || ParamCache.paramMap.get(workId).getImageEncrypt() == 1) {
|
|
|
- fileName = MD5Util.getImageRuleMd5(workId, subject1.ordinal(), areaCode, examNumber, studentId);
|
|
|
- }
|
|
|
-
|
|
|
- //组装导出目录
|
|
|
- StringJoiner expSj = new StringJoiner(File.separator);
|
|
|
- expSj.add(systemConfig.getLocalhostPath()).add("image-export").add(exportType);
|
|
|
- //原图或者裁切图
|
|
|
- String imageTypeStr = Objects.equals("1", imageType) ? "sheet" : Objects.equals("2", imageType) ? "images" : "default";
|
|
|
- //是否水印
|
|
|
- String waterTypeStr = Objects.equals("1", isWatermark) ? "yes" : Objects.equals("0", isWatermark) ? "no" : "default";
|
|
|
- expSj.add(imageTypeStr.concat("-").concat(waterTypeStr));
|
|
|
- LOGGER.info("{},【{}】开始导出,参数:图片类型:{},是否有水印:{},是否续传:{},命名规则:{}",examNumber, studentName,imageTypeStr, waterTypeStr, isResume == "1"?"是":"否", nameRule == "1"?"考号+姓名":"流水号");
|
|
|
- //是否加水印
|
|
|
- for (String spath : savePaths) {
|
|
|
- if (stringPath("workId").equals(spath)) {
|
|
|
- expSj.add(String.valueOf(workId));
|
|
|
+ synchronized (map.get("examNumber")) {
|
|
|
+// synchronized (this) {
|
|
|
+ InputStream inputStream = null;
|
|
|
+ OutputStream outputStream = null;
|
|
|
+ long start = System.currentTimeMillis();
|
|
|
+ try {
|
|
|
+ Long studentId = Long.valueOf(map.get("studentId").toString());
|
|
|
+ String studentName = map.get("studentName").toString();
|
|
|
+ String subject = map.get("subject").toString();
|
|
|
+ Subject subject1 = Subject.valueOf(subject);
|
|
|
+ String areaCode = map.get("areaCode").toString();
|
|
|
+ String school = String.valueOf(map.get("school"));
|
|
|
+ String examNumber = map.get("examNumber").toString();
|
|
|
+ Double score = Double.parseDouble(map.get("score").toString());
|
|
|
+
|
|
|
+ String fileName = examNumber;
|
|
|
+ //图片加密、命名规则为随机码的,都是需要md5
|
|
|
+ if (ParamCache.paramMap.get(workId).getNameRule() == 1 || ParamCache.paramMap.get(workId).getImageEncrypt() == 1) {
|
|
|
+ fileName = MD5Util.getImageRuleMd5(workId, subject1.ordinal(), areaCode, examNumber, studentId);
|
|
|
}
|
|
|
- if (stringPath("areaCode").equals(spath)) {
|
|
|
- expSj.add(areaCode);
|
|
|
+
|
|
|
+ //组装导出目录
|
|
|
+ StringJoiner expSj = new StringJoiner(File.separator);
|
|
|
+ expSj.add(systemConfig.getLocalhostPath()).add("image-export").add(exportType);
|
|
|
+ //原图或者裁切图
|
|
|
+ String imageTypeStr = Objects.equals("1", imageType) ? "sheet" : Objects.equals("2", imageType) ? "images" : "default";
|
|
|
+ //是否水印
|
|
|
+ String waterTypeStr = Objects.equals("1", isWatermark) ? "yes" : Objects.equals("0", isWatermark) ? "no" : "default";
|
|
|
+ expSj.add(imageTypeStr.concat("-").concat(waterTypeStr));
|
|
|
+ LOGGER.info("【{},{}】开始导出,参数:图片类型:{},是否有水印:{},是否续传:{},命名规则:{}", examNumber, studentName, imageTypeStr, waterTypeStr, Objects.equals(isResume, "1") ? "是" : "否", Objects.equals(nameRule, "1") ? "考号+姓名" : "流水号");
|
|
|
+ //是否加水印
|
|
|
+ for (String spath : savePaths) {
|
|
|
+ if (stringPath("workId").equals(spath)) {
|
|
|
+ expSj.add(String.valueOf(workId));
|
|
|
+ }
|
|
|
+ if (stringPath("areaCode").equals(spath)) {
|
|
|
+ expSj.add(areaCode);
|
|
|
+ }
|
|
|
+ if (stringPath("school").equals(spath)) {
|
|
|
+ expSj.add(school);
|
|
|
+ }
|
|
|
+ if (stringPath("subject").equals(spath)) {
|
|
|
+ expSj.add(subject);
|
|
|
+ }
|
|
|
}
|
|
|
- if (stringPath("school").equals(spath)) {
|
|
|
- expSj.add(school);
|
|
|
+ File out = new File(expSj.toString());
|
|
|
+ if (!out.exists()) {
|
|
|
+ out.mkdirs();
|
|
|
}
|
|
|
- if (stringPath("subject").equals(spath)) {
|
|
|
- expSj.add(subject);
|
|
|
+ //输出命名
|
|
|
+ String outFileName;
|
|
|
+ if (Objects.equals("1", nameRule)) {
|
|
|
+ StringJoiner sj = new StringJoiner("-");
|
|
|
+ sj.add(examNumber).add(studentName);
|
|
|
+ outFileName = sj.toString();
|
|
|
+ } else if (Objects.equals("2", nameRule)) {
|
|
|
+ outFileName = String.valueOf(atomicInteger.incrementAndGet());
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("命名参数有误");
|
|
|
}
|
|
|
- }
|
|
|
- File out = new File(expSj.toString());
|
|
|
- if (!out.exists()) {
|
|
|
- out.mkdirs();
|
|
|
- }
|
|
|
- //输出命名
|
|
|
- String outFileName;
|
|
|
- if (Objects.equals("1", nameRule)) {
|
|
|
- StringJoiner sj = new StringJoiner("-");
|
|
|
- sj.add(examNumber).add(studentName);
|
|
|
- outFileName = sj.toString();
|
|
|
- } else if (Objects.equals("2", nameRule)) {
|
|
|
- outFileName = String.valueOf(atomicInteger.incrementAndGet());
|
|
|
- } else {
|
|
|
- throw new RuntimeException("命名参数有误");
|
|
|
- }
|
|
|
|
|
|
- String path;
|
|
|
- String dir;
|
|
|
- if (Objects.equals("1", imageType)) {
|
|
|
- path = systemConfig.getSheetDir() + File.separator + workId + File.separator + subject1
|
|
|
- + File.separator + areaCode;
|
|
|
- dir = systemConfig.getSheetDir();
|
|
|
- } else if (Objects.equals("2", imageType)) {
|
|
|
- path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject1
|
|
|
- + File.separator + areaCode;
|
|
|
- dir = systemConfig.getImageDir();
|
|
|
- } else {
|
|
|
- throw new RuntimeException("图片类型有误");
|
|
|
- }
|
|
|
-
|
|
|
- String outFile = expSj.toString() + File.separator + outFileName + ".jpg";
|
|
|
- if (imageServerConfig.isAliyunOss()) {
|
|
|
- //是否断点续传
|
|
|
- if (Objects.equals("1", isResume) && new File(outFile).exists()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- StringJoiner ossSavePath = new StringJoiner("/").add(imageServerConfig.getDir()).add(dir.replace("\\", "/")).add(String.valueOf(workId)).add(subject).add(areaCode);
|
|
|
- String saveFileName = fileName + ".jpg";
|
|
|
- String saveFile = ossSavePath.toString().concat("/").concat(saveFileName);
|
|
|
- if (Objects.equals("0", isWatermark)) {
|
|
|
- ossUtil.ossDownload(saveFile, outFile);
|
|
|
+ String path;
|
|
|
+ String dir;
|
|
|
+ if (Objects.equals("1", imageType)) {
|
|
|
+ path = systemConfig.getSheetDir() + File.separator + workId + File.separator + subject1
|
|
|
+ + File.separator + areaCode;
|
|
|
+ dir = systemConfig.getSheetDir();
|
|
|
+ } else if (Objects.equals("2", imageType)) {
|
|
|
+ path = systemConfig.getImageDir() + File.separator + workId + File.separator + subject1
|
|
|
+ + File.separator + areaCode;
|
|
|
+ dir = systemConfig.getImageDir();
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("图片类型有误");
|
|
|
}
|
|
|
- //下载临时原图
|
|
|
- if (Objects.equals("1", isWatermark)) {
|
|
|
- String outSheetFile = expSj.toString() + File.separator + outFileName + "_" + start + ".jpg";
|
|
|
- File sheetFileTemp = ossUtil.ossDownload(saveFile, outSheetFile);
|
|
|
+
|
|
|
+ String outFile = expSj.toString() + File.separator + outFileName + ".jpg";
|
|
|
+ if (imageServerConfig.isAliyunOss()) {
|
|
|
+ //是否断点续传
|
|
|
+ if (Objects.equals("1", isResume) && new File(outFile).exists()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ StringJoiner ossSavePath = new StringJoiner("/").add(imageServerConfig.getDir()).add(dir.replace("\\", "/")).add(String.valueOf(workId)).add(subject).add(areaCode);
|
|
|
+ String saveFileName = fileName + ".jpg";
|
|
|
+ String saveFile = ossSavePath.toString().concat("/").concat(saveFileName);
|
|
|
+ if (Objects.equals("0", isWatermark)) {
|
|
|
+ ossUtil.ossDownload(saveFile, outFile);
|
|
|
+ }
|
|
|
+ //下载临时原图
|
|
|
+ if (Objects.equals("1", isWatermark)) {
|
|
|
+ long s1 = System.currentTimeMillis();
|
|
|
+ LOGGER.info("【{},{}】下载临时原图开始", examNumber, studentName);
|
|
|
+ String outSheetFile = expSj.toString() + File.separator + outFileName + "_" + start + ".jpg";
|
|
|
+ File sheetFileTemp = ossUtil.ossDownload(saveFile, outSheetFile);
|
|
|
+ long s2 = System.currentTimeMillis();
|
|
|
+ LOGGER.info("【{},{}】下载临时原图结束,总耗时:{}秒", examNumber, studentName, (s2 - s1) / 1000);
|
|
|
+ File expFile = new File(outFile);
|
|
|
+ //生成分数水印图片
|
|
|
+ long s3 = System.currentTimeMillis();
|
|
|
+ LOGGER.info("【{},{}】加水印开始,总耗时:{}秒", examNumber, studentName, (s3 - s2) / 1000);
|
|
|
+ BufferedImage watermarkImage = createWaterImage(score.intValue() + "分");
|
|
|
+ Thumbnails.of(sheetFileTemp).scale(1).watermark(Positions.BOTTOM_CENTER, watermarkImage, 1f).toFile(expFile);
|
|
|
+ long s4 = System.currentTimeMillis();
|
|
|
+ LOGGER.info("【{},{}】加水印结束,总耗时:{}秒", examNumber, studentName, (s4 - s3) / 1000);
|
|
|
+ sheetFileTemp.delete();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ File file = new File(path + File.separator + fileName + ".jpg");
|
|
|
File expFile = new File(outFile);
|
|
|
- //生成分数水印图片
|
|
|
- BufferedImage watermarkImage = createWaterImage(score.intValue() + "分");
|
|
|
- Thumbnails.of(sheetFileTemp).scale(0.8).watermark(Positions.BOTTOM_CENTER, watermarkImage, 1f).toFile(expFile);
|
|
|
- sheetFileTemp.delete();
|
|
|
- }
|
|
|
- } else {
|
|
|
- File file = new File(path + File.separator + fileName + ".jpg");
|
|
|
- File expFile = new File(outFile);
|
|
|
- //是否断点续传
|
|
|
- if (Objects.equals("1", isResume) && expFile.exists()) {
|
|
|
- return;
|
|
|
- }
|
|
|
- if (Objects.equals("0", isWatermark)) {
|
|
|
- //读取指定路径下面的文件
|
|
|
- inputStream = new FileInputStream(file);
|
|
|
- outputStream = new FileOutputStream(expFile);
|
|
|
- if (ParamCache.paramMap.get(workId).getImageEncrypt() == 1) {
|
|
|
- outputStream = SystemConstant.writeStream(inputStream, outputStream);
|
|
|
- } else {
|
|
|
- outputStream = SystemConstant.writeStreamFomal(inputStream, outputStream);
|
|
|
+ //是否断点续传
|
|
|
+ if (Objects.equals("1", isResume) && expFile.exists()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (Objects.equals("0", isWatermark)) {
|
|
|
+ //读取指定路径下面的文件
|
|
|
+ inputStream = new FileInputStream(file);
|
|
|
+ outputStream = new FileOutputStream(expFile);
|
|
|
+ if (ParamCache.paramMap.get(workId).getImageEncrypt() == 1) {
|
|
|
+ outputStream = SystemConstant.writeStream(inputStream, outputStream);
|
|
|
+ } else {
|
|
|
+ outputStream = SystemConstant.writeStreamFomal(inputStream, outputStream);
|
|
|
+ }
|
|
|
+ inputStream.close();
|
|
|
+ outputStream.flush();
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+ if (Objects.equals("1", isWatermark)) {
|
|
|
+ //生成分数水印图片
|
|
|
+ BufferedImage watermarkImage = createWaterImage(score.intValue() + "分");
|
|
|
+ Thumbnails.of(file).scale(1).watermark(Positions.BOTTOM_CENTER, watermarkImage, 1f).toFile(expFile);
|
|
|
}
|
|
|
- inputStream.close();
|
|
|
- outputStream.flush();
|
|
|
- outputStream.close();
|
|
|
- }
|
|
|
- if (Objects.equals("1", isWatermark)) {
|
|
|
- //生成分数水印图片
|
|
|
- BufferedImage watermarkImage = createWaterImage(score.intValue() + "分");
|
|
|
- Thumbnails.of(file).scale(0.8).watermark(Positions.BOTTOM_CENTER, watermarkImage, 1f).toFile(expFile);
|
|
|
- }
|
|
|
- }
|
|
|
- long end = System.currentTimeMillis();
|
|
|
- LOGGER.info("{},【{}】结束导出,总耗时:{}秒", examNumber, studentName, (end-start)/1000);
|
|
|
- } catch (Exception e) {
|
|
|
- LOGGER.info("{},【{}】导出失败");
|
|
|
- } finally {
|
|
|
- try {
|
|
|
- //强制将缓存区的数据进行输出
|
|
|
- if (Objects.nonNull(outputStream)) {
|
|
|
- outputStream.flush();
|
|
|
- //关流
|
|
|
- outputStream.close();
|
|
|
- }
|
|
|
- if (Objects.nonNull(inputStream)) {
|
|
|
- inputStream.close();
|
|
|
}
|
|
|
-
|
|
|
+ long end = System.currentTimeMillis();
|
|
|
+ LOGGER.info("【{},{}】结束导出,总耗时:{}秒", examNumber, studentName, (end - start) / 1000);
|
|
|
} catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ LOGGER.info("导出失败:{}", e.getMessage());
|
|
|
+ } finally {
|
|
|
+ try {
|
|
|
+ //强制将缓存区的数据进行输出
|
|
|
+ if (Objects.nonNull(outputStream)) {
|
|
|
+ outputStream.flush();
|
|
|
+ //关流
|
|
|
+ outputStream.close();
|
|
|
+ }
|
|
|
+ if (Objects.nonNull(inputStream)) {
|
|
|
+ inputStream.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
- LOGGER.info("==========================导出分数图片结束================================");
|
|
|
|
|
|
}
|
|
|
+ LOGGER.info("==========================导出分数图片结束================================");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|