Преглед изворни кода

检测档案文件日期、责任者等

lvy пре 3 дана
родитељ
комит
e924218fd5

+ 6 - 0
blade-service-api/blade-business-api/src/main/java/org/springblade/business/entity/ArchiveFile.java

@@ -341,6 +341,12 @@ public class ArchiveFile extends BaseEntity {
     private String remark;
     @ApiModelProperty("是否锁定 1已锁定")
     private Integer isLock;
+    /**
+     *  检测文件完整性,包括:日期、责任者、PDF是否有污渍、PDF分辨率是否大于等于300DPI
+     *
+     */
+    @ApiModelProperty("-1:检测无误,0:未检测,1:无日期,2:无责任者,3:dpi小于300,4:pdf有遮挡或者污渍")
+    private Integer checkStatus;
 
     public void fromExternal(ArchiveFileVo vo) {
         if (vo == null) {

+ 2 - 0
blade-service-api/blade-manager-api/src/main/java/org/springblade/manager/vo/ArchiveTreeContractVO2.java

@@ -237,6 +237,8 @@ public class ArchiveTreeContractVO2 implements INodeEx<ArchiveTreeContractVO2> {
      */
     private Integer classify;
 
+    private Integer checkStatus;
+
     public String toString() {
         return "TreeNode(parentId=" + this.getParentId()
                 + ",ancestors" + this.getAncestors()

+ 76 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ScanFileController.java

@@ -1,17 +1,23 @@
 package org.springblade.archive.controller;
 
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.itextpdf.text.pdf.PdfDictionary;
+import com.itextpdf.text.pdf.PdfReader;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
 import lombok.AllArgsConstructor;
+import org.apache.pdfbox.pdmodel.PDDocument;
+import org.apache.pdfbox.pdmodel.PDPage;
 import org.springblade.archive.dto.ScanFileMoveDTO;
 import org.springblade.archive.entity.ScanFile;
 import org.springblade.archive.entity.ScanFolder;
 import org.springblade.archive.service.ScanFileService;
 import org.springblade.archive.service.ScanFolderService;
 import org.springblade.archive.vo.ScanFolderVO;
+import org.springblade.business.entity.ArchiveFile;
+import org.springblade.common.utils.CommonUtil;
 import org.springblade.core.mp.support.Query;
 import org.springblade.core.tool.api.R;
 import org.springblade.manager.entity.ContractInfo;
@@ -23,6 +29,9 @@ import org.springframework.stereotype.Controller;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import java.net.URLEncoder;
+import java.util.Collection;
+import java.util.Date;
 import java.util.List;
 import java.util.concurrent.CompletableFuture;
 import java.util.concurrent.ThreadPoolExecutor;
@@ -32,6 +41,8 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.Future;
 import java.util.concurrent.TimeUnit;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
 
 @RestController
 @AllArgsConstructor
@@ -174,5 +185,70 @@ public class ScanFileController {
     }
 
 
+    /**
+     * 每天3点执行一次
+     *  检测文件完整性,包括:日期、责任者、PDF是否有污渍、PDF分辨率是否大于等于300DPI
+     */
+    @Scheduled(cron = "0 0 3 * * ?")
+    public void checkFileInfo(){
+        String sql = "select id,node_id,duty_user,file_time,file_url,pdf_file_url from u_archive_file where is_deleted = 0 and check_status >= 0 and node_id is not null and project_is is not null limit ? offset ?";
+        int size = 10000;
+        int offset = 0;
+        Pattern datePattern = Pattern.compile("[0-9]{4}.?[0-9]{2}.?[0-9]{2}");
+        while (true) {
+            List<ArchiveFile> query = jdbcTemplate.query(String.format(sql, size, offset), new BeanPropertyRowMapper<>(ArchiveFile.class));
+            if (query.isEmpty()) {
+                break;
+            }
+            offset += size;
+            for (ArchiveFile file : query) {
+                String status = "";
+                if (file.getFileTime() == null || !datePattern.matcher(file.getFileTime()).find()) {
+                    status += "1";
+                }
+                if (file.getDutyUser() ==  null || file.getDutyUser().trim().isEmpty() || file.getDutyUser().trim().equals("null")) {
+                    status += "2";
+                }
+                String url = "";
+                if (file.getPdfFileUrl() != null && file.getPdfFileUrl().contains("http")) {
+                    url = file.getFileUrl();
+                } else if (file.getFileUrl() != null && file.getFileUrl().contains("http")) {
+                    url = file.getPdfFileUrl();
+                }
+                if (url == null || url.isEmpty()) {
+                    status += "3";
+                    file.setCheckStatus(Integer.parseInt(status));
+                    continue;
+                }
+                int lastIndexOf = url.lastIndexOf("/");
+                String prefix = url.substring(0, lastIndexOf + 1);
+                String suffix = url.substring(lastIndexOf + 1);
+                try {
+                    url = prefix + URLEncoder.encode(suffix, "UTF-8");
+                    PDDocument document = PDDocument.load(CommonUtil.getOSSInputStream(url));
+                    PDPage page = document.getPage(0);
+                    // 获取pdf 的dpi信息
+                    int dpi = (int) (page.getCropBox().getWidth() / page.getTrimBox().getWidth() * 72);
+                    if (dpi < 300) {
+                        status += "3";
+                    }
+                    // todo 检测pdf是否有遮挡或者污渍
+                    if (status.isEmpty()) {
+                        file.setCheckStatus(-1);
+                    } else {
+                        file.setCheckStatus(Integer.parseInt( status));
+                    }
+                } catch (Exception e) {
+                    status += "3";
+                    file.setCheckStatus(Integer.parseInt( status));
+                }
+            }
+            Date date = new Date();
+            List<Object[]> params = query.stream().map(entry -> new Object[]{entry.getCheckStatus(), date, entry.getId()}).collect(Collectors.toList());
+            jdbcTemplate.batchUpdate("update archive_file set check_status = ?, update_time = ? where id = ?", params);
+        }
+
+
+    }
 
 }

+ 5 - 3
blade-service/blade-manager/src/main/java/org/springblade/manager/mapper/ArchiveTreeContractMapper.xml

@@ -173,6 +173,7 @@
         <result column="specification" property="specification"/>
         <result column="archive_name_suffix" property="archiveNameSuffix"/>
         <result column="tree_number" property="treeNumber"/>
+        <result column="check_status" property="checkStatus"/>
 <!--        <association property="treeNumber" javaType="java.lang.Integer" select="selectFileNumber"-->
 <!--                     column="{id=id,projectId=project_id,code=code,contractId=contract_id,extType=ext_type}"/>-->
     </resultMap>
@@ -273,6 +274,7 @@
         d.archive_name_suffix,
         d.contract_id,
         IFNULL(SUM(file_counts.count), 0) AS tree_number,
+        file_counts.check_status AS check_status,
         (SELECT CASE WHEN count(1) > 0 THEN 1 ELSE 0 END FROM m_archive_tree_contract WHERE parent_id = d.id and is_deleted = 0 and project_id = #{projectId}) AS "has_children"
         FROM
         m_archive_tree_contract d
@@ -281,11 +283,11 @@
             SELECT
                 a.id,
                 a.ancestors,
-                SUM(b.count) AS count
+                SUM(b.count) AS count, if(b.check_status > 0, 1, 0) as check_status
             FROM
                 m_archive_tree_contract a
             INNER JOIN (
-                SELECT node_id AS id, COUNT(*) AS count
+                SELECT node_id AS id, COUNT(*) AS count, count(CASE WHEN check_status > 0 THEN 1 END) as check_status
                 FROM u_archive_file
                 WHERE project_id = #{projectId}
                 AND is_deleted = 0
@@ -294,7 +296,7 @@
                 <if test="extType > 0">
                     UNION ALL
 
-                    SELECT node_ext_id AS id, COUNT(*) AS count
+                    SELECT node_ext_id AS id, COUNT(*) AS count, count(CASE WHEN check_status > 0 THEN 1 END) as check_status
                     FROM u_archive_file
                     WHERE project_id = #{projectId}
                     AND is_deleted = 0