wangliang 4 роки тому
батько
коміт
25d781de7a

+ 1 - 2
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/BasicAttachmentService.java

@@ -46,12 +46,11 @@ public interface BasicAttachmentService extends IService<BasicAttachment> {
      *
      * @param fileName
      * @param htmlContent
-     * @param schoolId
      * @param userId
      * @return
      * @throws IOException
      */
-    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long schoolId, Long userId) throws IOException;
+    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId) throws IOException;
 
     /**
      * 删除附件

+ 8 - 7
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/BasicAttachmentServiceImpl.java

@@ -11,7 +11,6 @@ import com.qmth.distributed.print.business.entity.SysUser;
 import com.qmth.distributed.print.business.enums.UploadFileEnum;
 import com.qmth.distributed.print.business.mapper.BasicAttachmentMapper;
 import com.qmth.distributed.print.business.service.BasicAttachmentService;
-import com.qmth.distributed.print.business.util.FileMd5Util;
 import com.qmth.distributed.print.business.util.OssUtil;
 import com.qmth.distributed.print.business.util.ServletUtil;
 import com.qmth.distributed.print.common.contant.SystemConstant;
@@ -30,7 +29,9 @@ import org.springframework.util.FileCopyUtils;
 import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
+import java.io.ByteArrayInputStream;
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
 import java.time.LocalDateTime;
@@ -166,14 +167,13 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
      *
      * @param fileName
      * @param htmlContent
-     * @param schoolId
      * @param userId
      * @return
      * @throws IOException
      */
     @Override
     @Transactional
-    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long schoolId, Long userId) throws IOException {
+    public BasicAttachment saveAttachmentHtml(String fileName, String htmlContent, Long userId) throws IOException {
         BasicAttachment basicAttachment = null;
         try {
             byte[] bytes = htmlContent.getBytes();
@@ -185,18 +185,18 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
                 stringJoiner.add(SystemConstant.TEMP_FILES_DIR).add(File.separator);
             }
             stringJoiner.add(UploadFileEnum.HTML.getTitle()).add(File.separator)
-                    .add(String.valueOf(schoolId)).add(File.separator)
                     .add(String.valueOf(nowTime.getYear())).add(File.separator)
                     .add(String.format("%02d", nowTime.getMonthValue())).add(File.separator)
                     .add(String.format("%02d", nowTime.getDayOfMonth()));
 
             JSONObject jsonObject = new JSONObject();
-            stringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(File.separator).add(fileName).add(SystemConstant.HTML_PREFIX);
-            //计算html文件md5
-            String fileMd5 = FileMd5Util.pathMd5(stringJoiner.toString());
+            stringJoiner.add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.HTML_PREFIX);
+            String fileMd5 = null;
             if (oss) {//上传至oss\
                 String dirName = stringJoiner.toString().replaceAll("\\\\", "/");
                 ossUtil.ossUpload(dirName, htmlContent);
+                byte[] data = ossUtil.ossDownload(dirName);
+                fileMd5 = DigestUtils.md5Hex(new ByteArrayInputStream(data));
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.OSS);
                 jsonObject.put(SystemConstant.PATH, dirName);
             } else {//上传至服务器
@@ -206,6 +206,7 @@ public class BasicAttachmentServiceImpl extends ServiceImpl<BasicAttachmentMappe
                     finalFile.createNewFile();
                 }
                 FileCopyUtils.copy(bytes, new File(stringJoiner.toString()));
+                fileMd5 = DigestUtils.md5Hex(new FileInputStream(stringJoiner.toString()));
                 jsonObject.put(SystemConstant.TYPE, SystemConstant.LOCAL);
                 jsonObject.put(SystemConstant.PATH, stringJoiner.toString());
             }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/importData/AsyncImportTaskTemplete.java

@@ -42,7 +42,7 @@ public abstract class AsyncImportTaskTemplete {
     public static final String FINISH_TITLE = "->数据处理结束,共处理了";
     public static final String FINISH_SIZE = "条数据";
     public static final String TXT_PREFIX = ".txt";
-    public static final String EXCEPTION_CREATE_TXT_TITLE = "->创建导出文件时发生异常!";
+    public static final String EXCEPTION_CREATE_TXT_TITLE = "->创建导出日志时发生异常!";
     public static final String FORMAT_TIME = DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN);
 
     /**

+ 10 - 6
distributed-print-business/src/main/java/com/qmth/distributed/print/business/templete/service/impl/TaskLogicServiceImpl.java

@@ -158,7 +158,9 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                 throw ExceptionResultEnum.ERROR.exception("考务计划为空");
             }
             attachmentIds = Objects.isNull(attachmentIds) ? attachmentIds = new HashSet<>() : attachmentIds;
-            attachmentIds.add(examDetail.getAttachmentId());
+            if (Objects.nonNull(examDetail.getAttachmentId())) {
+                attachmentIds.add(examDetail.getAttachmentId());
+            }
 
             //查询examDetailCourse
             QueryWrapper<ExamDetailCourse> examDetailCourseQueryWrapper = new QueryWrapper<>();
@@ -230,7 +232,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                 String paperCodeImg = GoogleBarCodeUtil.createBarCode(paperCode, false);
                                 String paperCodeDiv = "<div class=\"page-box page-box-0\"><div class=\"package-number\" style=\"position: absolute;width: 200px;height: 40px;top: 80px;right: 35px;transform: rotate(-90deg);transform-origin: center right;text-align: center;z-index: 99;\"><img src=\"data:image/png;base64," + paperCodeImg + "\" style=\"display: block; height: 28px; width: 100%\" /><p style=\"line-height: 1; font-size: 12px; margin: 0;\">" + paperCode + "</p></div>";
                                 cardTemp = cardTemp.replaceAll("<div class=\"page-box page-box-0\">", paperCodeDiv);
-                                BasicAttachment cardAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), cardTemp, examCard.getSchoolId(), sysUser.getId());
+                                BasicAttachment cardAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), cardTemp, sysUser.getId());
                                 JSONObject object = new JSONObject();
                                 object.put("name", paperType);
                                 object.put("examTaskDetailId", examTaskDetail.getId());
@@ -246,9 +248,11 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                             List<ExamStudent> examStudentList = examStudentService.list(examStudentQueryWrapper);
 
                             for (ExamStudent t : examStudentList) {
-//                            if (Objects.nonNull(t.getAttachmentIds())) {
-//                                attachmentIds.add(t.getAttachmentId());
-//                            }
+                                if (Objects.nonNull(t.getAttachmentIds())) {
+                                    JSONObject json = JSONObject.parseObject(t.getAttachmentIds());
+                                    attachmentIds.add((Long) json.get("htmlAttachmentId"));
+//                                    attachmentIds.add((Long) json.get("pdfAttachmentId"));
+                                }
                                 String studentHtml = studentContent;
                                 if (Objects.nonNull(t.getExtendFields())) {
                                     JSONArray jsonObjectExtend = (JSONArray) JSONArray.parse(t.getExtendFields());//扩展字段
@@ -270,7 +274,7 @@ public class TaskLogicServiceImpl implements TaskLogicService {
                                 studentHtml = studentHtml.replaceAll("\\$\\{courseName\\}", examCard.getCourseName());
 
                                 //学生题卡
-                                BasicAttachment examStudentAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode(), studentHtml, examCard.getSchoolId(), sysUser.getId());
+                                BasicAttachment examStudentAttachment = basicAttachmentService.saveAttachmentHtml(examCard.getSchoolId() + "|" + examCard.getCourseCode() + "|" + t.getTicketNumber(), studentHtml, sysUser.getId());
                                 JSONObject jsonObjectExamStudent = new JSONObject();
                                 jsonObjectExamStudent.put("htmlAttachmentId", examStudentAttachment.getId());
                                 jsonObjectExamStudent.put("pdfAttachmentId", 123L);

+ 0 - 46
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/FileMd5Util.java

@@ -1,46 +0,0 @@
-package com.qmth.distributed.print.business.util;
-
-import com.qmth.distributed.print.common.contant.SystemConstant;
-import org.apache.commons.codec.binary.Hex;
-import org.apache.commons.lang3.StringUtils;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.security.MessageDigest;
-
-public class FileMd5Util {
-
-    public static String pathMd5(String path) {
-        if (StringUtils.isEmpty(path)) {
-            return "";
-        }
-        File file = new File(path);
-        if (!file.exists()) {
-            return "";
-        }
-
-        FileInputStream fileInputStream = null;
-        try {
-            MessageDigest MD5 = MessageDigest.getInstance(SystemConstant.MD5);
-            fileInputStream = new FileInputStream(file);
-            byte[] buffer = new byte[8192];
-            int length;
-            while ((length = fileInputStream.read(buffer)) != -1) {
-                MD5.update(buffer, 0, length);
-            }
-            return new String(Hex.encodeHex(MD5.digest()));
-        } catch (Exception e) {
-            e.printStackTrace();
-            return "";
-        } finally {
-            try {
-                if (fileInputStream != null) {
-                    fileInputStream.close();
-                }
-            } catch (IOException e) {
-                e.printStackTrace();
-            }
-        }
-    }
-}