Переглянути джерело

优化档案系统文件检测、新增pdf尺寸检测

lvy 20 годин тому
батько
коміт
1c279d2216

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

@@ -345,8 +345,8 @@ public class ArchiveFile extends BaseEntity {
      *  检测文件完整性,包括:日期、责任者、PDF是否有污渍、PDF分辨率是否大于等于300DPI
      *
      */
-    @ApiModelProperty("-1:检测无误,0:未检测,1:无日期,2:无责任者,3:dpi小于300,4:pdf有遮挡或者污渍")
-    private Integer checkStatus;
+    @ApiModelProperty("-1:检测无误,0:未检测,1:无日期,2:无责任者,3:pdf文件无法访问,4:pdf有遮挡或者污渍, 5:dpi小于300,6:pdf尺寸不符合要求")
+    private String checkStatus;
 
     /**
      * fileUrl md5值

+ 2 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/controller/ArchiveFileAutoController.java

@@ -131,6 +131,7 @@ ArchiveFileAutoController extends BladeController {
                         archive.setFileSize(saveVos.getList().get(0).getFileSize());
                     }
                     archivesAutoService.save(archive);
+                    archivesAutoService.checkFileInfo(Collections.singletonList(archive.getId() + ""));
                 } else {
                     ArchivesAuto archivesAuto = archivesAutoService.getById(archive.getId());
                     ArchivesAuto update= new ArchivesAuto();
@@ -176,6 +177,7 @@ ArchiveFileAutoController extends BladeController {
                     update.setStartDate(archive.getStartDate());
                     update.setEndDate(archive.getEndDate());
                     archivesAutoService.updateById(update);
+                    archivesAutoService.checkFileInfo(Collections.singletonList(archive.getId() + ""));
 
                 }
             }

+ 37 - 25
blade-service/blade-archive/src/main/java/org/springblade/archive/service/impl/ArchivesAutoServiceImpl.java

@@ -76,6 +76,7 @@ import org.springblade.core.tool.api.R;
 import org.springblade.core.tool.utils.BeanUtil;
 import org.springblade.core.tool.utils.FileUtil;
 import org.springblade.core.tool.utils.Func;
+import org.springblade.core.tool.utils.StringUtil;
 import org.springblade.manager.entity.*;
 import org.springblade.manager.feign.ArchiveTreeContractClient;
 import org.springblade.manager.feign.ContractClient;
@@ -5561,10 +5562,15 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 		if (ids == null || ids.isEmpty()) {
 			return;
 		}
-		List<ArchiveFile> query = jdbcTemplate.query("select id,node_id,duty_user,file_time,file_url,pdf_file_url from u_archive_file where is_deleted = 0 and id in (" + String.join(",", ids) + ")",
+		String idsStr = ids.stream().filter(StringUtil::isNumeric).collect(Collectors.joining(","));
+		List<ArchiveFile> query = jdbcTemplate.query("select id,node_id,duty_user,file_time,file_url,pdf_file_url from u_archive_file where is_deleted = 0 and id in (" + idsStr + ")",
 				new BeanPropertyRowMapper<>(ArchiveFile.class));
 		if (query.isEmpty()) {
-			return;
+			query = jdbcTemplate.query("select id,node_id,duty_user,file_time,file_url,pdf_file_url from u_archive_file where is_deleted = 0 and archive_id in (" + idsStr + ")",
+					new BeanPropertyRowMapper<>(ArchiveFile.class));
+			if (query.isEmpty()) {
+				return;
+			}
 		}
 		checkArchiveFile( query);
 		List<Object[]> params = query.stream().map(entry -> new Object[]{entry.getCheckStatus(), entry.getId()}).collect(Collectors.toList());
@@ -5577,13 +5583,12 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 	private void checkArchiveFile(List<ArchiveFile> list) {
 		Pattern datePattern = Pattern.compile("[0-9]{4}.?[0-9]{2}.?[0-9]{2}");
 		for (ArchiveFile file : list) {
+			String checkStatus = "";
 			if (file.getFileTime() == null || !datePattern.matcher(file.getFileTime()).find()) {
-				file.setCheckStatus(1);
-				continue;
+				checkStatus += "1";
 			}
 			if (file.getDutyUser() ==  null || file.getDutyUser().trim().isEmpty() || file.getDutyUser().trim().equals("null")) {
-				file.setCheckStatus(2);
-				continue;
+				checkStatus += ",2";
 			}
 			String url = "";
 			if (file.getPdfFileUrl() != null && file.getPdfFileUrl().contains("http")) {
@@ -5592,31 +5597,38 @@ public class ArchivesAutoServiceImpl extends BaseServiceImpl<ArchivesAutoMapper,
 				url = file.getPdfFileUrl();
 			}
 			if (url == null || !url.endsWith(".pdf")) {
-				file.setCheckStatus(3);
-				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");
-				try (InputStream ossIs = CommonUtil.getOSSInputStream(url); ) {
-					Map<String, Object> map = ImageQualityDetectorUtils.checkImageQuality(ossIs, 96);
-					Object checkDPI = map.get("checkDPI");
-					if (checkDPI != null && !"true".equals(checkDPI.toString())) {
-						file.setCheckStatus(3);
-					} else {
+				checkStatus += ",3";
+			} else {
+				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");
+					try (InputStream ossIs = CommonUtil.getOSSInputStream(url); ) {
+						Map<String, Object> map = ImageQualityDetectorUtils.checkImageQuality(ossIs, 0);
+						Object checkDPI = map.get("checkDPI");
+						if (checkDPI != null && !"true".equals(checkDPI.toString())) {
+							checkStatus += ",5";
+						}
 						Object hasStains = map.get("hasStains");
 						if (hasStains != null && "true".equals(hasStains.toString())) {
-							file.setCheckStatus(4);
-						} else {
-							file.setCheckStatus(-1);
+							checkStatus += ",4";
+						}
+						Object isA4OrA3 = map.get("isA4OrA3");
+						if (isA4OrA3 != null && !"true".equals(isA4OrA3.toString())) {
+							checkStatus += ",6";
 						}
 					}
+				} catch (Exception e) {
+					checkStatus += ",3";
 				}
-			} catch (Exception e) {
-				file.setCheckStatus(3);
 			}
+			if (checkStatus.isEmpty()) {
+				checkStatus = "-1";
+			} else if (checkStatus.charAt(0) == ',') {
+				checkStatus = checkStatus.substring(1);
+			}
+			file.setCheckStatus(checkStatus);
 		}
 	}
 

+ 32 - 0
blade-service/blade-archive/src/main/java/org/springblade/archive/utils/ImageQualityDetectorUtils.java

@@ -4,6 +4,7 @@ import org.apache.pdfbox.contentstream.PDFGraphicsStreamEngine;
 import org.apache.pdfbox.io.MemoryUsageSetting;
 import org.apache.pdfbox.pdmodel.PDDocument;
 import org.apache.pdfbox.pdmodel.PDPage;
+import org.apache.pdfbox.pdmodel.common.PDRectangle;
 import org.apache.pdfbox.pdmodel.graphics.image.PDImage;
 import org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject;
 import org.apache.pdfbox.rendering.PDFRenderer;
@@ -52,6 +53,7 @@ public class ImageQualityDetectorUtils {
              OpenCVFrameConverter.ToMat converter2 = new OpenCVFrameConverter.ToMat()) {
             boolean checkDPI = true;
             int pages = document.getNumberOfPages();
+            boolean isA4OrA3 = true;
             for (int i = 0; i < pages; i++) {
                 PDPage page = document.getPage(i);
                 PageImageCollectorEngine engine = new PageImageCollectorEngine(page);
@@ -59,6 +61,12 @@ public class ImageQualityDetectorUtils {
                 if (dpi > 0 && !(checkDPI = engine.checkDpiForImages(dpi, 5))) {
                     break;
                 }
+                if (isA4OrA3) {
+                    String pageSize = getPageSize(page.getMediaBox());
+                    if (!pageSize.equals("A4") && !pageSize.equals("A3")) {
+                        isA4OrA3 = false;
+                    }
+                }
 //                if (engine.hasNonImagePainting) {
 //                    break;
 //                }
@@ -103,9 +111,33 @@ public class ImageQualityDetectorUtils {
             if (!checkDPI) {
                 result.put("checkDPI", false);
             }
+            if (!isA4OrA3) {
+                result.put("isA4OrA3", false);
+            }
             return result;
         }
     }
+    /**
+     * 获取页面尺寸名称
+     *
+     * @param mediaBox 页面尺寸
+     * @return 页面尺寸名称,如果不是标准尺寸,则返回"Unknown"
+     */
+    private static String getPageSize(PDRectangle mediaBox) {
+        float width = mediaBox.getWidth() / 72 * 25.4f;
+        float height = mediaBox.getHeight() / 72 * 25.4f;
+
+        if ((Math.abs(width - 210) < 1 && Math.abs(height - 297) < 1) || (Math.abs(width - 297) < 1 && Math.abs(height - 210) < 1)) {
+            return "A4";
+        } else if ((Math.abs(width - 420) < 1 && Math.abs(height - 297) < 1) || (Math.abs(width - 297) < 1 && Math.abs(height - 420) < 1)) {
+            return "A3";
+        } else if ((Math.abs(width - 420) < 1 && Math.abs(height - 594) < 1) || (Math.abs(width - 594) < 1 && Math.abs(height - 420) < 1)) {
+            return "A2";
+        } else if ((Math.abs(width - 594) < 1 && Math.abs(height - 841) < 1) || (Math.abs(width - 841) < 1 && Math.abs(height - 594) < 1)) {
+            return "A1";
+        }
+        return "Unknown";
+    }
 
     public static java.util.List<Map<String, Object>> evaluatePdfPages(InputStream is, int dpi) throws IOException {
         java.util.List<Map<String, Object>> list = new java.util.ArrayList<>();

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

@@ -287,7 +287,7 @@
             FROM
                 m_archive_tree_contract a
             INNER JOIN (
-                SELECT node_id AS id, COUNT(*) AS count, count(CASE WHEN check_status > 0 THEN 1 END) as check_status
+                SELECT node_id AS id, COUNT(*) AS count, count(CASE WHEN check_status != '-1' and check_status != '0' THEN 1 END) as check_status
                 FROM u_archive_file
                 WHERE project_id = #{projectId}
                 AND is_deleted = 0
@@ -296,7 +296,7 @@
                 <if test="extType > 0">
                     UNION ALL
 
-                    SELECT node_ext_id AS id, COUNT(*) AS count, count(CASE WHEN check_status > 0 THEN 1 END) as check_status
+                    SELECT node_ext_id AS id, COUNT(*) AS count, count(CASE WHEN check_status != '-1' and check_status != '0' THEN 1 END) as check_status
                     FROM u_archive_file
                     WHERE project_id = #{projectId}
                     AND is_deleted = 0