瀏覽代碼

Merge branch 'dev' of http://git.qmth.com.cn/wangliang/distributed-print-service into dev

xiaof 4 年之前
父節點
當前提交
6cc93b00f1

+ 26 - 26
distributed-print-business/src/main/java/com/qmth/distributed/print/business/bean/dto/PdfDto.java

@@ -16,16 +16,16 @@ public class PdfDto {
     String path;
 
     @ApiModelProperty(name = "页数")
-    Integer pageCount = 0;
+    int pageCount = 0;
 
     @ApiModelProperty(name = "实际页数")
-    Integer actualPageCount = 0;
+    int actualPageCount = 0;
 
     @ApiModelProperty(name = "页面大小")
     PageSizeEnum pageSize;
 
     @ApiModelProperty(name = "序号")
-    Integer sequence = 0;
+    int sequence = 0;
 
     @ApiModelProperty(name = "tag")
     boolean tag = true;
@@ -39,44 +39,36 @@ public class PdfDto {
         this.pageSize = pageSize;
     }
 
-    public PdfDto(String path, PageSizeEnum pageSize, Integer pageCount) {
+    public PdfDto(String path, PageSizeEnum pageSize, int pageCount) {
         this.path = path;
         this.pageSize = pageSize;
         this.pageCount = pageCount;
     }
 
-    public PdfDto(String path, PageSizeEnum pageSize, Integer pageCount, Integer sequence) {
+    public PdfDto(String path, PageSizeEnum pageSize, int pageCount, int sequence) {
         this.path = path;
         this.pageSize = pageSize;
         this.pageCount = pageCount;
         this.sequence = sequence;
     }
 
-    public PdfDto(PageSizeEnum pageSize, Integer pageCount, boolean tag) {
+    public PdfDto(PageSizeEnum pageSize, int pageCount, boolean tag) {
         this.pageSize = pageSize;
         this.pageCount = pageCount;
         this.tag = tag;
     }
 
-    public PdfDto(PageSizeEnum pageSize, Integer pageCount) {
+    public PdfDto(PageSizeEnum pageSize, int pageCount) {
         this.pageSize = pageSize;
         this.pageCount = pageCount;
     }
 
-    public PdfDto(PageSizeEnum pageSize, Integer pageCount, Integer actualPageCount) {
+    public PdfDto(PageSizeEnum pageSize, int pageCount, int actualPageCount) {
         this.pageSize = pageSize;
         this.pageCount = pageCount;
         this.actualPageCount = actualPageCount;
     }
 
-    public Integer getActualPageCount() {
-        return actualPageCount;
-    }
-
-    public void setActualPageCount(Integer actualPageCount) {
-        this.actualPageCount = actualPageCount;
-    }
-
     public boolean isTag() {
         return tag;
     }
@@ -85,14 +77,6 @@ public class PdfDto {
         this.tag = tag;
     }
 
-    public Integer getSequence() {
-        return sequence;
-    }
-
-    public void setSequence(Integer sequence) {
-        this.sequence = sequence;
-    }
-
     public String getPath() {
         return path;
     }
@@ -101,14 +85,30 @@ public class PdfDto {
         this.path = path;
     }
 
-    public Integer getPageCount() {
+    public int getPageCount() {
         return pageCount;
     }
 
-    public void setPageCount(Integer pageCount) {
+    public void setPageCount(int pageCount) {
         this.pageCount = pageCount;
     }
 
+    public int getActualPageCount() {
+        return actualPageCount;
+    }
+
+    public void setActualPageCount(int actualPageCount) {
+        this.actualPageCount = actualPageCount;
+    }
+
+    public int getSequence() {
+        return sequence;
+    }
+
+    public void setSequence(int sequence) {
+        this.sequence = sequence;
+    }
+
     public PageSizeEnum getPageSize() {
         return pageSize;
     }

+ 1 - 1
distributed-print-business/src/main/java/com/qmth/distributed/print/business/service/impl/TBTaskServiceImpl.java

@@ -332,7 +332,7 @@ public class TBTaskServiceImpl extends ServiceImpl<TBTaskMapper, TBTask> impleme
         QueryWrapper<TBTask> tbTaskQueryWrapper = new QueryWrapper<>();
         tbTaskQueryWrapper.lambda().eq(TBTask::getType, TaskTypeEnum.CREATE_PDF)
                 .eq(TBTask::getStatus, TaskStatusEnum.FINISH).isNotNull(TBTask::getStatus)
-                .eq(TBTask::getResult, TaskResultEnum.ERROR).last("limit 0,10");
+                .eq(TBTask::getResult, TaskResultEnum.ERROR).last("limit 0,100");
         List<TBTask> tbTasks = this.list(tbTaskQueryWrapper);
         if (Objects.nonNull(tbTasks) && tbTasks.size() > 0) {
             for (TBTask tbTask : tbTasks) {

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

@@ -15,7 +15,6 @@ import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.util.Result;
 import com.qmth.distributed.print.common.util.ResultUtil;
 import org.apache.commons.io.FileUtils;
-import org.apache.velocity.runtime.directive.contrib.For;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.scheduling.annotation.Async;
@@ -28,6 +27,7 @@ import java.util.Date;
 import java.util.Map;
 import java.util.Objects;
 import java.util.StringJoiner;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * @Description: 异步导入模版
@@ -140,6 +140,10 @@ public abstract class AsyncImportTaskTemplete {
             stringJoinerSummary.add(MessageFormat.format("{0}{1}{2}{3}", DateUtil.format(new Date(), SystemConstant.DEFAULT_DATE_PATTERN), EXCEPTION_CREATE_TXT_TITLE, EXCEPTION_DATA, e.getMessage()));
             tbTask.setSummary(stringJoinerSummary.toString());
             tbTask.setResult(TaskResultEnum.ERROR);
+            TBTask dbTask = tbTaskService.getById(tbTask.getId());
+            if (tbTask.getVersion() == dbTask.getVersion()) {
+                tbTask.setResetCount(new AtomicInteger(tbTask.getResetCount()).incrementAndGet());
+            }
             if (e instanceof ApiException) {
                 ResultUtil.error((ApiException) e, e.getMessage());
             } else {

+ 14 - 10
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/CreatePdfUtil.java

@@ -17,7 +17,6 @@ import com.qmth.distributed.print.business.service.CommonService;
 import com.qmth.distributed.print.business.service.ExamDetailService;
 import com.qmth.distributed.print.common.contant.SystemConstant;
 import com.qmth.distributed.print.common.enums.ExceptionResultEnum;
-import com.qmth.distributed.print.common.util.JacksonUtil;
 import org.apache.commons.codec.digest.DigestUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -28,7 +27,6 @@ import java.io.File;
 import java.io.FileInputStream;
 import java.io.IOException;
 import java.util.*;
-import java.util.concurrent.atomic.AtomicInteger;
 import java.util.stream.Collectors;
 
 /**
@@ -477,14 +475,20 @@ public class CreatePdfUtil {
         String dirNameA4 = PdfUtil.mergePdf(pathA4List.toArray(new String[mergePdfA4List.size()]), null);
         String dirNameA3 = PdfUtil.mergePdf(pathA3List.toArray(new String[mergePdfA3List.size()]), null);
         // oss上只认"/",windows生成的路径分隔符全部替换为"/"
-        dirNameA4 = dirNameA4.replaceAll("\\\\", "/");
-        dirNameA3 = dirNameA3.replaceAll("\\\\", "/");
-        File localA4PdfFile = new File(stringJoiner.toString() + File.separator + dirNameA4);
-        File localA3PdfFile = new File(stringJoiner.toString() + File.separator + dirNameA3);
-        BasicAttachment basicAttachment = basicAttachmentService.saveAttachmentPdf(dirNameA3, userId);
-        tbTask.setImportFileName(basicAttachment.getName());
-        tbTask.setImportFilePath(basicAttachment.getPath());
-        examDetail.setAttachmentId(basicAttachment.getId());
+        File localA4PdfFile = null, localA3PdfFile = null;
+        BasicAttachment basicAttachment = null;
+        if (Objects.nonNull(dirNameA4)) {
+            dirNameA4 = dirNameA4.replaceAll("\\\\", "/");
+            localA4PdfFile = new File(stringJoiner.toString() + File.separator + dirNameA4);
+        }
+        if (Objects.nonNull(dirNameA3)) {
+            dirNameA3 = dirNameA3.replaceAll("\\\\", "/");
+            localA3PdfFile = new File(stringJoiner.toString() + File.separator + dirNameA3);
+            basicAttachment = basicAttachmentService.saveAttachmentPdf(dirNameA3, userId);
+            tbTask.setImportFileName(basicAttachment.getName());
+            tbTask.setImportFilePath(basicAttachment.getPath());
+            examDetail.setAttachmentId(basicAttachment.getId());
+        }
         examDetail.setPagesA3(PdfUtil.getPdfPages(localA3PdfFile));
         examDetail.setPagesA4(PdfUtil.getPdfPages(localA4PdfFile));
 //        log.info("pageA3Count:{},examDetail:{}", pageA3Count.get(), JacksonUtil.parseJson(examDetail));

+ 38 - 32
distributed-print-business/src/main/java/com/qmth/distributed/print/business/util/PdfUtil.java

@@ -46,27 +46,29 @@ public class PdfUtil {
         PdfReader reader = null;
         StringJoiner dirName = null;
         try {
-            document = new Document(new PdfReader(files[0]).getPageSize(1));
-            if (Objects.isNull(outputPath)) {
-                LocalDateTime nowTime = LocalDateTime.now();
-                StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
-                dirName = new StringJoiner("")
-                        .add(UploadFileEnum.PDF.getTitle()).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()))
-                        .add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.PDF_PREFIX);
-                outputPath = stringJoiner.toString() + dirName.toString();
-            }
-            copy = new PdfSmartCopy(document, new FileOutputStream(outputPath));
-            document.open();
-            for (int i = 0; i < files.length; i++) {
-                reader = new PdfReader(files[i]);
-                int numberOfPages = reader.getNumberOfPages();
-                for (int j = 1; j <= numberOfPages; j++) {
-                    document.newPage();
-                    PdfImportedPage page = copy.getImportedPage(reader, j);
-                    copy.addPage(page);
+            if (Objects.nonNull(files) && files.length > 0) {
+                document = new Document(new PdfReader(files[0]).getPageSize(1));
+                if (Objects.isNull(outputPath)) {
+                    LocalDateTime nowTime = LocalDateTime.now();
+                    StringJoiner stringJoiner = new StringJoiner("").add(SystemConstant.PDF_TEMP_FILES_DIR).add(File.separator);
+                    dirName = new StringJoiner("")
+                            .add(UploadFileEnum.PDF.getTitle()).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()))
+                            .add(File.separator).add(SystemConstant.getUuid()).add(SystemConstant.PDF_PREFIX);
+                    outputPath = stringJoiner.toString() + dirName.toString();
+                }
+                copy = new PdfSmartCopy(document, new FileOutputStream(outputPath));
+                document.open();
+                for (int i = 0; i < files.length; i++) {
+                    reader = new PdfReader(files[i]);
+                    int numberOfPages = reader.getNumberOfPages();
+                    for (int j = 1; j <= numberOfPages; j++) {
+                        document.newPage();
+                        PdfImportedPage page = copy.getImportedPage(reader, j);
+                        copy.addPage(page);
+                    }
                 }
             }
         } catch (Exception e) {
@@ -98,15 +100,17 @@ public class PdfUtil {
         FileOutputStream fileOutputStream = null;
         int pageCount = 0;
         try {
-            reader = new PdfReader(pdfFile.getPath());
-            pageCount = reader.getNumberOfPages();
-            if (Math.abs(pageCount % 2) == 1) {//取偶
-                ByteArrayOutputStream baos = new ByteArrayOutputStream();
-                PdfStamper stamper = new PdfStamper(reader, baos);
-                stamper.insertPage(pageCount + 1, reader.getPageSizeWithRotation(1));
-                stamper.close();
-                fileOutputStream = new FileOutputStream(pdfFile);
-                IOUtils.write(baos.toByteArray(), fileOutputStream);
+            if (Objects.nonNull(pdfFile)) {
+                reader = new PdfReader(pdfFile.getPath());
+                pageCount = reader.getNumberOfPages();
+                if (Math.abs(pageCount % 2) == 1) {//取偶
+                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
+                    PdfStamper stamper = new PdfStamper(reader, baos);
+                    stamper.insertPage(pageCount + 1, reader.getPageSizeWithRotation(1));
+                    stamper.close();
+                    fileOutputStream = new FileOutputStream(pdfFile);
+                    IOUtils.write(baos.toByteArray(), fileOutputStream);
+                }
             }
         } catch (Exception e) {
             log.error("请求出错", e);
@@ -132,8 +136,10 @@ public class PdfUtil {
     public static int getPdfPages(File pdfFile) throws IOException {
         PdfReader reader = null;
         try {
-            reader = new PdfReader(pdfFile.getPath());
-            return reader.getNumberOfPages();
+            if (Objects.nonNull(pdfFile)) {
+                reader = new PdfReader(pdfFile.getPath());
+                return reader.getNumberOfPages();
+            }
         } catch (Exception e) {
             log.error("请求出错", e);
         } finally {

+ 1 - 0
distributed-print-business/src/main/resources/db/init-data.sql

@@ -3,4 +3,5 @@ truncate table `sys_config`;
 INSERT INTO `sys_config` VALUES (1, 'sys.user.initPassword', '初始密码', '123456', NULL, 1, NULL, NULL, NULL);
 INSERT INTO `sys_config` VALUES (2, 'sys.warning.days', '预警天数', '3',NULL, 1, NULL, NULL, NULL);
 INSERT INTO `sys_config` VALUES (3, 'sys.code.enable', '是否启用短信验证码', 'true', 'true-启用,false-禁用', 1, NULL, NULL, NULL);
+INSERT INTO `sys_config` VALUES (4, 'sys.message.enable', '是否启用短信消息提示', 'true', 'true-启用,false-禁用', 1, NULL, NULL, NULL);
 

+ 26 - 0
distributed-print-business/src/main/resources/db/init-table.sql

@@ -98,6 +98,32 @@ CREATE TABLE `basic_exam_rule`  (
   PRIMARY KEY (`id`) USING BTREE
 ) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci COMMENT = '考务规则' ROW_FORMAT = Dynamic;
 
+-- ----------------------------
+-- Table structure for basic_message
+-- ----------------------------
+DROP TABLE IF EXISTS `basic_message`;
+CREATE TABLE `basic_message`  (
+    `id` bigint(20) NOT NULL,
+    `user_id` bigint(20) NOT NULL COMMENT '消息接收人用户',
+    `mobile_number` varchar(11) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '电话号码',
+    `business_id` bigint(20) NOT NULL COMMENT '业务id',
+    `business_operate` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '业务操作',
+    `template_code` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL COMMENT '消息模板代码',
+    `variable_params` text CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '变量参数内容',
+    `template_content` mediumtext CHARACTER SET utf8 COLLATE utf8_general_ci NULL COMMENT '模板内容',
+    `message_type` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '消息类型',
+    `send_status` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '消息发送状态',
+    `send_result` varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT '消息发送结果',
+    `create_id` bigint(20) NULL DEFAULT NULL COMMENT '创建人',
+    `create_time` bigint(20) NULL DEFAULT NULL COMMENT '创建时间',
+    `update_id` bigint(20) NULL DEFAULT NULL COMMENT '更新人',
+    `update_time` bigint(20) NULL DEFAULT NULL COMMENT '更新时间',
+    PRIMARY KEY (`id`) USING BTREE
+) ENGINE = InnoDB CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
+
+-- ----------------------------
+-- Records of basic_message
+-- ----------------------------
 -- ----------------------------
 -- Table structure for basic_school
 -- ----------------------------