|
@@ -1,13 +1,19 @@
|
|
package com.qmth.teachcloud.mark.service.impl;
|
|
package com.qmth.teachcloud.mark.service.impl;
|
|
|
|
|
|
-import java.io.ByteArrayOutputStream;
|
|
|
|
-import java.io.File;
|
|
|
|
|
|
+import java.awt.*;
|
|
|
|
+import java.awt.color.ColorSpace;
|
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
|
+import java.awt.image.ColorConvertOp;
|
|
|
|
+import java.io.*;
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.net.URLEncoder;
|
|
import java.net.URLEncoder;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
|
|
+import java.util.List;
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
+import javax.imageio.ImageIO;
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.ServletOutputStream;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.validation.constraints.NotNull;
|
|
import javax.validation.constraints.NotNull;
|
|
@@ -29,6 +35,11 @@ import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
|
+import com.itextpdf.text.Document;
|
|
|
|
+import com.itextpdf.text.Image;
|
|
|
|
+import com.itextpdf.text.PageSize;
|
|
|
|
+import com.itextpdf.text.Rectangle;
|
|
|
|
+import com.itextpdf.text.pdf.PdfWriter;
|
|
import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
import com.qmth.boot.core.concurrent.service.ConcurrentService;
|
|
import com.qmth.boot.core.exception.ParameterException;
|
|
import com.qmth.boot.core.exception.ParameterException;
|
|
import com.qmth.boot.tools.excel.ExcelWriter;
|
|
import com.qmth.boot.tools.excel.ExcelWriter;
|
|
@@ -141,6 +152,8 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
|
|
|
|
|
|
@Resource
|
|
@Resource
|
|
private FileUploadService fileUploadService;
|
|
private FileUploadService fileUploadService;
|
|
|
|
+ @Resource
|
|
|
|
+ private MarkTrackService markTrackService;
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public List<String> listClassByExamIdAndCourseCode(Long examId, String paperNumber) {
|
|
public List<String> listClassByExamIdAndCourseCode(Long examId, String paperNumber) {
|
|
@@ -1402,13 +1415,32 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
|
|
continue;
|
|
continue;
|
|
}
|
|
}
|
|
List<FilePathVo> vos = JSON.parseArray(s.getSheetPath(), FilePathVo.class);
|
|
List<FilePathVo> vos = JSON.parseArray(s.getSheetPath(), FilePathVo.class);
|
|
|
|
+ List<MarkTrack> trackList = markTrackService.listByStudentId(s.getId());
|
|
|
|
+ Document document = new Document(new Rectangle(PageSize.A3.getHeight(),PageSize.A3.getWidth()));
|
|
|
|
+ // 本地保存目录
|
|
|
|
+ File tempFile = SystemConstant.getFileTempParentDirVar(SystemConstant.TEMP_PREFIX);
|
|
|
|
+ File file =new File(tempFile.getPath()+File.separator + s.getStudentCode()+".pdf");
|
|
|
|
+ PdfWriter pdfWriter = PdfWriter.getInstance(document,new FileOutputStream(file));
|
|
|
|
+ document.open();
|
|
for (int i = 0; i < vos.size(); i++) {
|
|
for (int i = 0; i < vos.size(); i++) {
|
|
FilePathVo vo = vos.get(i);
|
|
FilePathVo vo = vos.get(i);
|
|
- File file = fileUploadService.downloadFile( JSON.toJSONString(vo),vo.getPath());
|
|
|
|
- String format = FilenameUtils.getExtension(file.getName());
|
|
|
|
- writer.write(file, s.getStudentCode()+"-"+(i+1)+"."+format);
|
|
|
|
- file.delete();
|
|
|
|
|
|
+ File sheet = fileUploadService.downloadFile(JSON.toJSONString(vo),vo.getPath());
|
|
|
|
+ File track = new File(tempFile.getPath()+File.separator + s.getStudentCode()+"-"+(i+1)+".jpg");
|
|
|
|
+ int offsetIndex = i+1;
|
|
|
|
+ List<MarkTrack> tracks = trackList.stream().filter(t->t.getOffsetIndex().equals(offsetIndex)).collect(Collectors.toList());
|
|
|
|
+ this.createTrack(sheet,track,tracks);
|
|
|
|
+ Image image = Image.getInstance(track.getPath());
|
|
|
|
+ image.scaleAbsolute(PageSize.A3.getHeight()-100,PageSize.A3.getWidth()-100);
|
|
|
|
+ if(i!=0){
|
|
|
|
+ document.newPage();
|
|
|
|
+ }
|
|
|
|
+ document.add(image);
|
|
|
|
+ sheet.delete();
|
|
|
|
+ track.delete();
|
|
}
|
|
}
|
|
|
|
+ document.close();
|
|
|
|
+ pdfWriter.close();
|
|
|
|
+ writer.write(file,s.getStudentCode()+".pdf");
|
|
}
|
|
}
|
|
writer.close();
|
|
writer.close();
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
@@ -1419,6 +1451,40 @@ public class MarkStudentServiceImpl extends ServiceImpl<MarkStudentMapper, MarkS
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void createTrack(File sheet, File track, List<MarkTrack> trackList)throws IOException {
|
|
|
|
+ {
|
|
|
|
+ FileOutputStream output = null;
|
|
|
|
+ try {
|
|
|
|
+ BufferedImage image = ImageIO.read(new FileInputStream(sheet));
|
|
|
|
+ image = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_sRGB), null).filter(image, null);
|
|
|
|
+ Graphics2D g = image.createGraphics();// 得到图形上下文
|
|
|
|
+ g.setColor(Color.red); // 设置画笔颜色
|
|
|
|
+ // 设置字体
|
|
|
|
+ g.setFont(new Font("微软雅黑", Font.LAYOUT_LEFT_TO_RIGHT, 30));
|
|
|
|
+ // 写入签名
|
|
|
|
+ if (trackList != null && !trackList.isEmpty()) {
|
|
|
|
+ for (int i = 0; i < trackList.size(); i++) {
|
|
|
|
+ MarkTrack t = trackList.get(i);
|
|
|
|
+ BigDecimal left = new BigDecimal(t.getOffsetY());
|
|
|
|
+ BigDecimal top = new BigDecimal(t.getOffsetX());
|
|
|
|
+ g.drawString(t.getScore().toString(), left.intValue(), top.intValue());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ g.dispose();
|
|
|
|
+
|
|
|
|
+ output = new FileOutputStream(track);
|
|
|
|
+ ImageIO.write(image, "jpg", output);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
+ } finally {
|
|
|
|
+ if (Objects.nonNull(output)) {
|
|
|
|
+ output.flush();
|
|
|
|
+ output.close();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
@Override
|
|
@Override
|
|
public void sheetExport(Long examId, String coursePaperId, HttpServletResponse response) {
|
|
public void sheetExport(Long examId, String coursePaperId, HttpServletResponse response) {
|
|
List<MarkStudent> list = this.listByExamIdAndCoursePaperId(examId,coursePaperId);
|
|
List<MarkStudent> list = this.listByExamIdAndCoursePaperId(examId,coursePaperId);
|