|
@@ -2,6 +2,7 @@ package org.springblade.evisa.controller;
|
|
|
|
|
|
import io.swagger.annotations.Api;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
+import lombok.Synchronized;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
import org.apache.pdfbox.pdmodel.PDPage;
|
|
@@ -9,6 +10,8 @@ import org.jsoup.Jsoup;
|
|
|
import org.jsoup.nodes.Document;
|
|
|
import org.jsoup.nodes.Element;
|
|
|
import org.jsoup.select.Elements;
|
|
|
+import org.springblade.common.utils.CommonUtil;
|
|
|
+import org.springblade.common.utils.SafeURLEncoder;
|
|
|
import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
import org.springblade.core.tool.utils.Func;
|
|
@@ -52,53 +55,49 @@ import javax.imageio.ImageIO;
|
|
|
@Slf4j
|
|
|
public class ArchiveController {
|
|
|
|
|
|
- @Autowired
|
|
|
- StringRedisTemplate RedisTemplate;
|
|
|
- // jdbc
|
|
|
+ private final StringRedisTemplate RedisTemplate;
|
|
|
+
|
|
|
private final JdbcTemplate jdbcTemplate;
|
|
|
|
|
|
private final NewIOSSClient newIOSSClient;
|
|
|
|
|
|
// 线程池
|
|
|
- @Resource(name = "taskExecutor1")
|
|
|
- private ThreadPoolExecutor executor;
|
|
|
+ @Resource(name = "archivePoolExecutor")
|
|
|
+ private ThreadPoolExecutor archExecutor;
|
|
|
|
|
|
- @Scheduled(cron = "0 0/1 * * * ?")
|
|
|
- public void SignInfo() {
|
|
|
+ // @Scheduled(cron = "0/30 * * * * ?")
|
|
|
+ public void SignTaskBatchPng() {
|
|
|
//执行代码
|
|
|
-
|
|
|
log.info("分解pdf专图片");
|
|
|
- String sql = "SELECT distinct b.id,b.archive_id as archiveId ,b.file_url as fileUrl,c.id as taskId from u_archives_auto a , u_archive_file b ,u_task_split c where a.id=b.archive_id and ((FIND_IN_SET(a.id,c.ids) and c.type=3) or (a.contract_id=c.contract_id and c.type=2)) and a.is_deleted=0 and b.is_deleted=0 and a.split_status not in(1,2) ";
|
|
|
+ String sql = "SELECT distinct b.id,b.archive_id as archiveId ,REPLACE(b.file_url,'https://xinan1.zos.ctyun.cn','http://100.86.2.1:80') as fileUrl,c.id as taskId from u_archives_auto a , u_archive_file b ,u_task_split c where a.id=b.archive_id and ((FIND_IN_SET(a.id,c.ids) and c.type=3) or (a.contract_id=c.contract_id and c.type=2)) and a.is_deleted=0 and b.is_deleted=0 and a.split_status not in(1,2) LIMIT 20";
|
|
|
+ // String sql = "SELECT distinct b.id,b.archive_id as archiveId ,b.file_url as fileUrl,c.id as taskId from u_archives_auto a , u_archive_file b ,u_task_split c where a.id=b.archive_id and ((FIND_IN_SET(a.id,c.ids) and c.type=3) or (a.contract_id=c.contract_id and c.type=2)) and a.is_deleted=0 and b.is_deleted=0 and a.split_status not in(1,2) and a.id=1947207326716919808 LIMIT 20";
|
|
|
List<TaskArchiveSplitVO> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(TaskArchiveSplitVO.class));
|
|
|
|
|
|
if (query != null && query.size() >= 1) {
|
|
|
for (TaskArchiveSplitVO dataInfo : query) {
|
|
|
- if (executor.getQueue().size() <= 10) {
|
|
|
+ if (archExecutor.getQueue().size() <= 20) {
|
|
|
Boolean aBoolean = RedisTemplate.hasKey("splitpng-" + dataInfo.getArchiveId());
|
|
|
if (!aBoolean) {
|
|
|
-
|
|
|
- if (!aBoolean) {
|
|
|
- RedisTemplate.opsForValue().set("splitpng-" + dataInfo.getArchiveId(), "1", 600, TimeUnit.SECONDS);
|
|
|
- CompletableFuture<Void> runAsync = CompletableFuture.runAsync(() -> {
|
|
|
- try {
|
|
|
- /*===============执行批量任务===============*/
|
|
|
- signTaskBatchpngToHtml(dataInfo);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }, executor);
|
|
|
- }
|
|
|
+ RedisTemplate.opsForValue().setIfAbsent("splitpng-" + dataInfo.getArchiveId(), "1", 600, TimeUnit.SECONDS);
|
|
|
+ CompletableFuture<Void> runAsync = CompletableFuture.runAsync(() -> {
|
|
|
+ try {
|
|
|
+ signTaskBatchpngToHtml(dataInfo);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }, archExecutor);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- System.out.println("队列数量_img2" + executor.getQueue().size());
|
|
|
- System.out.println("活跃数量_img2" + executor.getActiveCount());
|
|
|
- System.out.println("总共数量_img2" + executor.getTaskCount());
|
|
|
- System.out.println("完成数量_img2" + executor.getCompletedTaskCount());
|
|
|
+ System.out.println("队列数量_img" + archExecutor.getQueue().size());
|
|
|
+ System.out.println("活跃数量_img" + archExecutor.getActiveCount());
|
|
|
+ System.out.println("总共数量_img" + archExecutor.getTaskCount());
|
|
|
+ System.out.println("完成数量_img" + archExecutor.getCompletedTaskCount());
|
|
|
}
|
|
|
|
|
|
// 分解第一页的任务
|
|
|
+
|
|
|
public void signTaskBatchpngToHtml(TaskArchiveSplitVO taskSign) {
|
|
|
try {
|
|
|
String fileUrl = taskSign.getFileUrl();
|
|
@@ -109,90 +108,100 @@ public class ArchiveController {
|
|
|
int startPage = 0;
|
|
|
for (int i = 2; i <= 10; i++) {
|
|
|
// 获取pdf第二页的数据
|
|
|
- String firstUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "first__"+i+"__.pdf";
|
|
|
+ String firstUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "first__" + i + "__.pdf";
|
|
|
File file = new File(firstUrl);
|
|
|
if (!file.exists()) {
|
|
|
- getPdfByPage(i, i, fileUrl, firstUrl);
|
|
|
+ int pdfByPage = getPdfByPage(i, i, fileUrl, firstUrl);
|
|
|
+ if(pdfByPage==1){
|
|
|
+ String sql22 = "INSERT INTO u_archives_split_info(id,status,file_url,first_file_url,task_id,archive_id,create_time) VALUES(?,?,?,?,?,?,SYSDATE())";
|
|
|
+ int addCount = jdbcTemplate.update(sql22, id, 4, fileUrl, "获取数据源失败", taskId, archiveId);
|
|
|
+ String updateSql = "UPDATE u_archives_auto SET split_status=? WHERE id=?";
|
|
|
+ int delCount = jdbcTemplate.update(updateSql, 1, archiveId);
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 保存第一页为300DPI图片
|
|
|
- String imagePath = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "first__"+i+"__.png";
|
|
|
+ String imagePath = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "first__" + i + "__.png";
|
|
|
File imgfile = new File(imagePath);
|
|
|
if (!imgfile.exists()) {
|
|
|
- savePdfAsImage(1, firstUrl, imagePath);
|
|
|
+ int dataNum = savePdfAsImage(1, firstUrl, imagePath);
|
|
|
}
|
|
|
// 删除pdf
|
|
|
file.delete();
|
|
|
- String state = OcrTitle(imagePath,"1");
|
|
|
- if(state.equals("1")){
|
|
|
- if(startPage<2){
|
|
|
- startPage = i ;
|
|
|
+ String state = OcrTitle(imagePath, "1");
|
|
|
+ if (state.equals("1")) {
|
|
|
+ if (startPage < 2) {
|
|
|
+ startPage = i;
|
|
|
}
|
|
|
listPdf.add(imagePath);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
imgfile.delete();
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
System.out.println(listPdf.size());
|
|
|
- String filePath = startPage+"--"+(listPdf.size()+1);
|
|
|
+ String filePath = startPage + "--" + (listPdf.size() + 1);
|
|
|
//判断
|
|
|
List<Map<String, Object>> mapList = jdbcTemplate.queryForList("select * from u_archives_split_info where id=" + id + "");
|
|
|
if (mapList != null && Func.isNotEmpty(mapList) && mapList.size() >= 1) {
|
|
|
String status = mapList.get(0).get("status") + "";
|
|
|
- if (status.equals("3")) {
|
|
|
- String updateSql = "update u_archives_auto set split_status=1 where id=" + archiveId;
|
|
|
- jdbcTemplate.execute(updateSql);
|
|
|
- }
|
|
|
- } else {
|
|
|
- String sql22 = "insert into u_archives_split_info(id,status,file_url,first_file_url,task_id,archive_id,create_time) VALUES(" + id + ",2,'" + fileUrl + "','" + filePath + "'," + taskId + "," + archiveId + ",SYSDATE())";
|
|
|
- jdbcTemplate.execute(sql22);
|
|
|
- String updateSql = "update u_archives_auto set split_status=2 where id=" + archiveId;
|
|
|
- jdbcTemplate.execute(updateSql);
|
|
|
- }
|
|
|
+ // if (status.equals("3")) {
|
|
|
+ String updateSql = "update u_archives_split_info set status=2 ,file_url='"+fileUrl+"',first_file_url ='"+filePath+"' where id=" + id;
|
|
|
+ jdbcTemplate.update(updateSql);
|
|
|
+ String uateSql = "UPDATE u_archives_auto SET split_status=? WHERE id=?";
|
|
|
+ int delCount = jdbcTemplate.update(uateSql, 2, archiveId);
|
|
|
+ // }
|
|
|
|
|
|
- String sql = "delete from u_archive_file where id<>'"+id+"' and archive_id='"+archiveId+"'";
|
|
|
- jdbcTemplate.execute(sql);
|
|
|
+ } else {
|
|
|
+ // 所有SQL都改为参数化查询
|
|
|
+ String sql22 = "INSERT INTO u_archives_split_info(id,status,file_url,first_file_url,task_id,archive_id,create_time) VALUES(?,?,?,?,?,?,SYSDATE())";
|
|
|
+ int addCount = jdbcTemplate.update(sql22, id, 2, fileUrl, filePath, taskId, archiveId);
|
|
|
|
|
|
+ String updateSql = "UPDATE u_archives_auto SET split_status=? WHERE id=?";
|
|
|
+ int delCount = jdbcTemplate.update(updateSql, 2, archiveId);
|
|
|
+ }
|
|
|
+ String delSql = "DELETE FROM u_archive_file WHERE id<>? AND archive_id=?";
|
|
|
+ jdbcTemplate.update(delSql, id, archiveId);
|
|
|
RedisTemplate.delete("splitpng-" + archiveId);
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
+ System.out.println("12321312");
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- @Scheduled(cron = "0/30 * * * * ?")
|
|
|
+ // @Scheduled(cron = "0/30 * * * * ?")
|
|
|
public void SplitPdfInfo() {
|
|
|
//执行代码
|
|
|
-
|
|
|
log.info("分解html开始");
|
|
|
- String sql = "select * from u_archives_split_info where status =2 "; // and TIMESTAMPDIFF(MINUTE, create_time, NOW()) >=3";
|
|
|
+ String sql = "select * from u_archives_split_info where status =2 LIMIT 20 "; // and TIMESTAMPDIFF(MINUTE, create_time, NOW()) >=3";
|
|
|
List<ArchivesSplitInfoVO> query = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(ArchivesSplitInfoVO.class));
|
|
|
- log.info("分解html开始==="+query.size());
|
|
|
+ log.info("分解html开始===" + query.size());
|
|
|
if (query != null && query.size() >= 1) {
|
|
|
for (ArchivesSplitInfoVO dataInfo : query) {
|
|
|
- if (executor.getQueue().size() <= 10) {
|
|
|
+ if (archExecutor.getQueue().size() <= 10) {
|
|
|
Boolean aBoolean = RedisTemplate.hasKey("splithtml-" + dataInfo.getArchiveId());
|
|
|
if (!aBoolean) {
|
|
|
|
|
|
if (!aBoolean) {
|
|
|
- RedisTemplate.opsForValue().set("splithtml-" + dataInfo.getArchiveId(), "1", 1200, TimeUnit.SECONDS);
|
|
|
+ RedisTemplate.opsForValue().setIfAbsent("splithtml-" + dataInfo.getArchiveId(), "1", 1200, TimeUnit.SECONDS);
|
|
|
CompletableFuture<Void> runAsync = CompletableFuture.runAsync(() -> {
|
|
|
try {
|
|
|
/*===============执行批量任务===============*/
|
|
|
signTaskBatchpng(dataInfo);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
+ } finally {
|
|
|
+ RedisTemplate.delete("splithtml-" + dataInfo.getArchiveId());
|
|
|
}
|
|
|
- }, executor);
|
|
|
+ }, archExecutor);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
- System.out.println("队列数量_html" + executor.getQueue().size());
|
|
|
- System.out.println("活跃数量_html" + executor.getActiveCount());
|
|
|
- System.out.println("总共数量_html" + executor.getTaskCount());
|
|
|
- System.out.println("完成数量_html" + executor.getCompletedTaskCount());
|
|
|
+ System.out.println("队列数量_html" + archExecutor.getQueue().size());
|
|
|
+ System.out.println("活跃数量_html" + archExecutor.getActiveCount());
|
|
|
+ System.out.println("总共数量_html" + archExecutor.getTaskCount());
|
|
|
+ System.out.println("完成数量_html" + archExecutor.getCompletedTaskCount());
|
|
|
}
|
|
|
|
|
|
public void signTaskBatchpng(ArchivesSplitInfoVO taskSign) {
|
|
@@ -206,10 +215,10 @@ public class ArchiveController {
|
|
|
int basePage = Integer.parseInt(firstUrl[1]);
|
|
|
int baseStart = Integer.parseInt(firstUrl[0]);
|
|
|
String dutyUser = "";
|
|
|
- int bkb = 0 ;
|
|
|
+ int bkb = 0;
|
|
|
//将imagePath 的数据转成一个可解析的html
|
|
|
- String htmlUrl = pngToHtml(firstPage, archiveId,taskSign.getFirstFileUrl());
|
|
|
- System.out.println("分解002="+htmlUrl);
|
|
|
+ String htmlUrl = pngToHtml(firstPage, archiveId, taskSign.getFirstFileUrl());
|
|
|
+ System.out.println("分解002=" + htmlUrl);
|
|
|
|
|
|
if (htmlUrl.indexOf("_001.html") >= 0 && htmlUrl.indexOf("archiveSplit") >= 0) {
|
|
|
String htmlString = IoUtil.readToString(new FileInputStream(htmlUrl));
|
|
@@ -217,8 +226,8 @@ public class ArchiveController {
|
|
|
Element table = doc.select("table").first();
|
|
|
Elements trs = table.select("tr");
|
|
|
//由于解析已经成功,可能数据已经分解过,需要删除
|
|
|
- if(trs!=null && trs.size()>=1){
|
|
|
- String sql = "delete from u_archive_file where id<>'"+taskSign.getId()+"' and archive_id='"+archiveId+"'";
|
|
|
+ if (trs != null && trs.size() >= 1) {
|
|
|
+ String sql = "delete from u_archive_file where id<>'" + taskSign.getId() + "' and archive_id='" + archiveId + "'";
|
|
|
jdbcTemplate.execute(sql);
|
|
|
}
|
|
|
|
|
@@ -228,78 +237,81 @@ public class ArchiveController {
|
|
|
String wjtm = tr.select("td").get(1).text();
|
|
|
String rq = tr.select("td").get(2).text();
|
|
|
String ym = tr.select("td").get(3).text();
|
|
|
- if(zrz.equals("责任者") && wjtm.equals("文件题名") && rq.equals("日期")){
|
|
|
+ if (zrz.equals("责任者") && wjtm.equals("文件题名") && rq.equals("日期")) {
|
|
|
continue;
|
|
|
- }
|
|
|
+ }
|
|
|
int startYm = 0;
|
|
|
int endYm = 0;
|
|
|
- if(i<trs.size()-1){
|
|
|
+ if (i < trs.size() - 1) {
|
|
|
startYm = Func.toInt(ym);
|
|
|
- String enData = trs.get(i+1).select("td").get(3).text();
|
|
|
- if(enData.indexOf("页")>=0){
|
|
|
- enData = trs.get(i+2).select("td").get(3).text();
|
|
|
+ String enData = trs.get(i + 1).select("td").get(3).text();
|
|
|
+ if (enData.indexOf("页") >= 0) {
|
|
|
+ enData = trs.get(i + 2).select("td").get(3).text();
|
|
|
}
|
|
|
|
|
|
String[] parts = enData.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
|
|
|
- if(parts!=null && parts.length>=1){
|
|
|
+ if (parts != null && parts.length >= 1) {
|
|
|
endYm = Func.toInt(parts[0]);
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
String[] split = ym.split("(?<=\\D)(?=\\d)|(?<=\\d)(?=\\D)");
|
|
|
- if(split!=null && split.length>=3){
|
|
|
+ if (split != null && split.length >= 3) {
|
|
|
startYm = Func.toInt(split[0]);
|
|
|
endYm = Func.toInt(split[2]);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
startYm = Func.toInt(split[0]);
|
|
|
endYm = Func.toInt(split[0]);
|
|
|
}
|
|
|
}
|
|
|
- startYm = basePage+startYm ;
|
|
|
- endYm = basePage+endYm ;
|
|
|
+ startYm = basePage + startYm;
|
|
|
+ endYm = basePage + endYm;
|
|
|
dutyUser = zrz;
|
|
|
- System.out.println("序号="+i+"--文件提名:"+wjtm +"--开始("+startYm+"-"+endYm+")---页数"+(endYm-startYm+1));
|
|
|
+ System.out.println("序号=" + i + "--文件提名:" + wjtm + "--开始(" + startYm + "-" + endYm + ")---页数" + (endYm - startYm + 1));
|
|
|
// 分解文件
|
|
|
- String fmlUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/"+archiveId+"_cf_00"+i+".pdf";
|
|
|
- getPdfByPage(startYm,endYm,fileUlr,fmlUrl);
|
|
|
- saveDataToMysql(fmlUrl,wjtm,taskSign.getId(),endYm-startYm+1,i,zrz,rq);
|
|
|
- bkb = endYm ;
|
|
|
+ String fmlUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "_cf_00" + i + ".pdf";
|
|
|
+ getPdfByPage(startYm, endYm, fileUlr, fmlUrl);
|
|
|
+ saveDataToMysql(fmlUrl, wjtm, taskSign.getId(), endYm - startYm + 1, i, zrz, rq);
|
|
|
+ bkb = endYm;
|
|
|
}
|
|
|
} else {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
// 添加封面信息
|
|
|
- String fmlUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/"+archiveId+"_fm_001.pdf";
|
|
|
- getPdfByPage(1,1,fileUlr,fmlUrl);
|
|
|
- saveDataToMysql(fmlUrl,"封面",taskSign.getId(),1,-4,dutyUser,"");
|
|
|
+ String fmlUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "_fm_001.pdf";
|
|
|
+ getPdfByPage(1, 1, fileUlr, fmlUrl);
|
|
|
+ saveDataToMysql(fmlUrl, "封面", taskSign.getId(), 1, -4, dutyUser, "");
|
|
|
|
|
|
// 卷内目录
|
|
|
- String jnmuUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/"+archiveId+"_jnml_001.pdf";
|
|
|
- getPdfByPage(baseStart,basePage,fileUlr,jnmuUrl);
|
|
|
- saveDataToMysql(jnmuUrl,"卷内目录",taskSign.getId(),1,-3,dutyUser,"");
|
|
|
+ String jnmuUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "_jnml_001.pdf";
|
|
|
+ getPdfByPage(baseStart, basePage, fileUlr, jnmuUrl);
|
|
|
+ saveDataToMysql(jnmuUrl, "卷内目录", taskSign.getId(), 1, -3, dutyUser, "");
|
|
|
|
|
|
// 卷内备考表
|
|
|
- String jnbkbUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/"+archiveId+"_jnbkb_001.pdf";
|
|
|
- getPdfByPage(bkb+1,bkb+1,fileUlr,jnbkbUrl);
|
|
|
- saveDataToMysql(jnbkbUrl,"卷内备考表",taskSign.getId(),1,100,dutyUser,"");
|
|
|
-
|
|
|
- // 背脊表
|
|
|
- String bjbUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/"+archiveId+"_beiji_001.pdf";
|
|
|
- String bjbUrlPng = FileUtils.getSysLocalFileUrl() + "archiveSplit/"+archiveId+"_beiji_001.png";
|
|
|
-
|
|
|
- getPdfByPage(bkb+2,bkb+2,fileUlr,bjbUrl);
|
|
|
+ String jnbkbUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "_jnbkb_001.pdf";
|
|
|
+ getPdfByPage(bkb + 1, bkb + 1, fileUlr, jnbkbUrl);
|
|
|
|
|
|
- File bgImgFile = new File(bjbUrlPng);
|
|
|
- if (!bgImgFile.exists()) {
|
|
|
- savePdfAsImage(1, bjbUrl, bjbUrlPng);
|
|
|
+ File jlPdfFile = new File(jnbkbUrl);
|
|
|
+ if (jlPdfFile.exists()) {
|
|
|
+ saveDataToMysql(jnbkbUrl, "卷内备考表", taskSign.getId(), 1, 100, dutyUser, "");
|
|
|
}
|
|
|
- String state = OcrTitle(bjbUrlPng,"3");
|
|
|
- if(state.equals("1")){
|
|
|
- saveDataToMysql(bjbUrl,"背脊表",taskSign.getId(),1,101,dutyUser,"");
|
|
|
- }
|
|
|
- bgImgFile.delete();
|
|
|
-
|
|
|
|
|
|
+ // 背脊表
|
|
|
+ String bjbUrl = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "_beiji_001.pdf";
|
|
|
+ String bjbUrlPng = FileUtils.getSysLocalFileUrl() + "archiveSplit/" + archiveId + "_beiji_001.png";
|
|
|
+
|
|
|
+ int pdfByPage = getPdfByPage(bkb + 2, bkb + 2, fileUlr, bjbUrl);
|
|
|
+ if(pdfByPage==0){
|
|
|
+ File bgImgFile = new File(bjbUrlPng);
|
|
|
+ if (!bgImgFile.exists()) {
|
|
|
+ int dataNum = savePdfAsImage(1, bjbUrl, bjbUrlPng);
|
|
|
+ }
|
|
|
+ String state = OcrTitle(bjbUrlPng, "3");
|
|
|
+ if (state.equals("1")) {
|
|
|
+ saveDataToMysql(bjbUrl, "背脊表", taskSign.getId(), 1, 101, dutyUser, "");
|
|
|
+ }
|
|
|
+ bgImgFile.delete();
|
|
|
+ }
|
|
|
// 修改任务状态
|
|
|
String updateSql = "update u_archives_split_info set status=3 where id=" + taskSign.getId();
|
|
|
jdbcTemplate.execute(updateSql);
|
|
@@ -308,8 +320,8 @@ public class ArchiveController {
|
|
|
jdbcTemplate.execute(updateSqlAuto);
|
|
|
|
|
|
// 统计各个任务的结果
|
|
|
- String taxkSql = "UPDATE u_task_split a set finished = (SELECT count(1) from u_archives_auto b where FIND_IN_SET(b.id,a.ids) and b.split_status=1) where FIND_IN_SET("+taskSign.getArchiveId()+",a.ids) and a.type=3";
|
|
|
- String taxkSql2 = "UPDATE u_task_split a set finished = (SELECT count(1) from u_archives_auto b where a.contract_id=b.contract_id) where a.id="+taskSign.getTaskId()+" and a.type=2";
|
|
|
+ String taxkSql = "UPDATE u_task_split a set finished = (SELECT count(1) from u_archives_auto b where FIND_IN_SET(b.id,a.ids) and b.split_status=1) where FIND_IN_SET(" + taskSign.getArchiveId() + ",a.ids) and a.type=3";
|
|
|
+ String taxkSql2 = "UPDATE u_task_split a set finished = (SELECT count(1) from u_archives_auto b where a.contract_id=b.contract_id) where a.id=" + taskSign.getTaskId() + " and a.type=2";
|
|
|
jdbcTemplate.execute(taxkSql);
|
|
|
jdbcTemplate.execute(taxkSql2);
|
|
|
|
|
@@ -324,7 +336,7 @@ public class ArchiveController {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static String pngToHtml(String fileUrl, String pKeyId,String pageNum) {
|
|
|
+ public static String pngToHtml(String fileUrl, String pKeyId, String pageNum) {
|
|
|
String lasHhtmlUrl = "";
|
|
|
try {
|
|
|
// 定义Python解释器路径和脚本路径
|
|
@@ -371,7 +383,7 @@ public class ArchiveController {
|
|
|
String htmlUrl;
|
|
|
while ((htmlUrl = reader.readLine()) != null) {
|
|
|
System.out.println("222" + htmlUrl);
|
|
|
- if (htmlUrl.indexOf("图片中是否有卷内目录") >= 0 && htmlUrl.indexOf("True") >=0) {
|
|
|
+ if (htmlUrl.indexOf("图片中是否有卷内目录") >= 0 && htmlUrl.indexOf("True") >= 0) {
|
|
|
return "1";
|
|
|
}
|
|
|
}
|
|
@@ -389,12 +401,11 @@ public class ArchiveController {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public static void getPdfByPage(int startPage, int endPage, String filePath, String savePath) {
|
|
|
+ public static int getPdfByPage(int startPage, int endPage, String filePath, String savePath) {
|
|
|
try {
|
|
|
- InputStream inputStreamByUrl = FileUtils.getInputStreamByUrl(filePath);
|
|
|
+ InputStream inputStreamByUrl = CommonUtil.getOSSInputStream3(filePath);
|
|
|
// 加载PDF文件
|
|
|
PDDocument document = PDDocument.load(inputStreamByUrl);
|
|
|
-
|
|
|
// 创建新文档
|
|
|
PDDocument newDocument = new PDDocument();
|
|
|
|
|
@@ -412,19 +423,19 @@ public class ArchiveController {
|
|
|
newDocument.save(savePath);
|
|
|
newDocument.close();
|
|
|
document.close();
|
|
|
+ return 0;
|
|
|
} catch (Exception e) {
|
|
|
- log.error("提取PDF页面失败", e);
|
|
|
- throw new RuntimeException("提取PDF页面失败", e);
|
|
|
+ return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public static void savePdfAsImage(int pageNum, String filePath, String outputPath) {
|
|
|
+ public static int savePdfAsImage(int pageNum, String filePath, String outputPath) {
|
|
|
try (InputStream inputStream = FileUtils.getInputStreamByUrl(filePath);
|
|
|
PDDocument document = PDDocument.load(inputStream)) {
|
|
|
|
|
|
// 验证页码范围
|
|
|
if (pageNum < 1 || pageNum > document.getNumberOfPages()) {
|
|
|
- throw new IllegalArgumentException("无效的页码");
|
|
|
+ return 1;
|
|
|
}
|
|
|
|
|
|
PDFRenderer renderer = new PDFRenderer(document);
|
|
@@ -445,18 +456,19 @@ public class ArchiveController {
|
|
|
log.info("PDF页面已成功保存为图片: {}", outputPath);
|
|
|
inputStream.close();
|
|
|
document.close();
|
|
|
+ return 0;
|
|
|
} catch (Exception e) {
|
|
|
log.error("PDF转图片失败", e);
|
|
|
- throw new RuntimeException("PDF转图片失败", e);
|
|
|
+ return 1;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- public int saveDataToMysql(String upFileUrl,String fileName,String fileId,int filePage,int sort,String dutyUser,String fileTime) {
|
|
|
+ public int saveDataToMysql(String upFileUrl, String fileName, String fileId, int filePage, int sort, String dutyUser, String fileTime) {
|
|
|
// 获取封面信息
|
|
|
long newPkId = SnowFlakeUtil.getId(); //主键Id
|
|
|
File fmfile = new File(upFileUrl);
|
|
|
if (fmfile.exists()) {
|
|
|
- BladeFile bladeFile = this.newIOSSClient.uploadFile(fileName+".pdf", upFileUrl);
|
|
|
+ BladeFile bladeFile = this.newIOSSClient.uploadFile(fileName + ".pdf", upFileUrl);
|
|
|
if (bladeFile != null && Func.isNotEmpty(bladeFile.getLink())) {
|
|
|
String FmPdfUrl = bladeFile.getLink();
|
|
|
String sql = " insert into u_archive_file( " +
|
|
@@ -464,8 +476,8 @@ public class ArchiveController {
|
|
|
" drawing_no,cite_change_number,certification_time,e_visa_file,node_ext_id,file_type,archive_id,origin_id,filming_time,filmingor_time,tag_id,pic_code,refer_code,film_code,width,height,ftime,utime,del_time,sort,box_name,box_number,is_auto_file,is_archive,page_num, " +
|
|
|
" file_size,source_type,is_element,pdf_page_url,fid,rectification,classify,m_wbs_tree_contract_p_key_id,u_image_classification_file_id,archive_file_storage_type,node_tree_structure,date_name,archive_file_stroage_type,out_id,sort_num " +
|
|
|
" ) " +
|
|
|
- " SELECT "+newPkId+",project_id,contract_id,node_id,file_number,'" + fileName + "','"+fileTime+"','" + FmPdfUrl + "','" + FmPdfUrl + "',"+filePage+",is_approval,is_certification,is_need_certification,'"+dutyUser+"',create_user,create_dept,create_time,update_user,update_time,status,is_deleted,sheet_type,sheet_source, " +
|
|
|
- " drawing_no,cite_change_number,certification_time,e_visa_file,node_ext_id,file_type,archive_id,origin_id,filming_time,filmingor_time,tag_id,pic_code,refer_code,film_code,width,height,ftime,utime,del_time,"+sort+",box_name,box_number,is_auto_file,is_archive,page_num, " +
|
|
|
+ " SELECT " + newPkId + ",project_id,contract_id,node_id,file_number,'" + fileName + "','" + fileTime + "','" + FmPdfUrl + "','" + FmPdfUrl + "'," + filePage + ",is_approval,is_certification,is_need_certification,'" + dutyUser + "',create_user,create_dept,create_time,update_user,update_time,status,is_deleted,sheet_type,sheet_source, " +
|
|
|
+ " drawing_no,cite_change_number,certification_time,e_visa_file,node_ext_id,file_type,archive_id,origin_id,filming_time,filmingor_time,tag_id,pic_code,refer_code,film_code,width,height,ftime,utime,del_time," + sort + ",box_name,box_number,is_auto_file,is_archive,page_num, " +
|
|
|
" file_size,source_type,is_element,pdf_page_url,fid,rectification,classify,m_wbs_tree_contract_p_key_id,u_image_classification_file_id,archive_file_storage_type,node_tree_structure,date_name,archive_file_stroage_type,out_id,sort_num " +
|
|
|
" from u_archive_file where id=" + fileId;
|
|
|
System.out.println(fileName + "----" + sql);
|
|
@@ -476,7 +488,7 @@ public class ArchiveController {
|
|
|
System.out.println("oss服务未启动,无法上传文件到oss");
|
|
|
return 500;
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
return 404;
|
|
|
}
|
|
|
fmfile.delete();
|