|
|
@@ -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);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|