添加空文件判断

This commit is contained in:
梁琦涛
2023-12-12 19:39:25 +08:00
parent 2cf9a38f70
commit 9fc5da5209
3 changed files with 26 additions and 19 deletions
@@ -2,35 +2,47 @@ package com.jero.modules.document.utils;
import com.jero.common.exception.JeroBootException;
import com.jero.common.util.MinioUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.text.PDFTextStripper;
import org.apache.pdfbox.text.PDFTextStripperByArea;
import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
/**
* @description
* @date 2022/3/21 17:04
* @auth zhn
*/
@Slf4j
public class ReadPdfUtil {
public static String readPdf(String path) {
if(MinioUtil.doesObjectExist(path)){
try (InputStream in = MinioUtil.download(path);
PDDocument document = PDDocument.load(in)) {
document.getClass();
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition(true);
PDFTextStripper tStripper = new PDFTextStripper();
try (InputStream in = MinioUtil.download(path)) {
if(Objects.isNull(in) || in.available() == 0){
return null;
}
try (PDDocument document = PDDocument.load(in)) {
document.getClass();
PDFTextStripperByArea stripper = new PDFTextStripperByArea();
stripper.setSortByPosition(true);
PDFTextStripper tStripper = new PDFTextStripper();
String pdfFileInText = tStripper.getText(document);
return pdfFileInText;
String pdfFileInText = tStripper.getText(document);
return pdfFileInText;
}catch (IOException e) {
throw new JeroBootException("文件内容读取失败");
}catch (Exception e) {
log.error("文件内容读取失败",e);
// throw new JeroBootException("文件内容读取失败");
}
}catch (Exception e) {
log.error("文件内容读取失败",e);
// throw new JeroBootException("文件内容读取失败");
}
}
return null;
}
@@ -56,6 +56,7 @@ public class HomeSearchCheckEsPlanJob implements Job {
@Override
public void execute(JobExecutionContext context) throws JobExecutionException {
log.info("============ es同步任务开始==============");
// 获取外部传来的参数
JobDataMap map = context.getJobDetail().getJobDataMap();
String resourceType = map.getString("parameter");
@@ -92,6 +93,7 @@ public class HomeSearchCheckEsPlanJob implements Job {
default:break;
}
});
log.info("============ es同步任务结束==============");
}
private void checkLawsNewsFeed(String resourceType, Map<String, Integer> mapHash) {
@@ -102,8 +104,6 @@ public class HomeSearchCheckEsPlanJob implements Job {
m4 = listLawsNewsFeed.size();
}
if(count4 != m4 || !StringUtils.isBlank(resourceType)){
// 清理数据重新更新
delete(resourceType);
if(!CollectionUtils.isEmpty(listLawsNewsFeed)){
List<String> listIds = listLawsNewsFeed.stream().map(LawsNewsFeed::getId).collect(Collectors.toList());
addES(listIds, LawsHomeSearchCommon.LAWS_NEWS_FEED);
@@ -119,8 +119,6 @@ public class HomeSearchCheckEsPlanJob implements Job {
m3 = listLawsEnterpriseStandard.size();
}
if(count3 != m3 || !StringUtils.isBlank(resourceType)){
// 清理数据重新更新
delete(resourceType);
if(!CollectionUtils.isEmpty(listLawsEnterpriseStandard)){
List<String> listIds = listLawsEnterpriseStandard.stream().map(LawsEnterpriseStandard::getId).collect(Collectors.toList());
addES(listIds, LawsHomeSearchCommon.LAWS_ENTERPRISE_STANDARD);
@@ -136,8 +134,6 @@ public class HomeSearchCheckEsPlanJob implements Job {
m2 = listLawsOverseasStandard.size();
}
if(count2 != m2 || !StringUtils.isBlank(resourceType)){
// 清理数据重新更新
delete(resourceType);
if(!CollectionUtils.isEmpty(listLawsOverseasStandard)){
List<String> listIds = listLawsOverseasStandard.stream().map(LawsOverseasStandard::getId).collect(Collectors.toList());
addES(listIds, LawsHomeSearchCommon.LAWS_OVERSEAS_STANDARD);
@@ -154,8 +150,6 @@ public class HomeSearchCheckEsPlanJob implements Job {
m1 = listLawsDomesticStandard.size();
}
if(count1 != m1 || !StringUtils.isBlank(resourceType)){
// 清理数据重新更新
delete(resourceType);
if(!CollectionUtils.isEmpty(listLawsDomesticStandard)){
List<String> listIds = listLawsDomesticStandard.stream().map(LawsDomesticStandard::getId).collect(Collectors.toList());
addES(listIds, LawsHomeSearchCommon.LAWS_DOMESTIC_STANDARD);
@@ -1044,7 +1044,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
// 批量操作
// 从第0个下标开始
int startIndex = 0;
int batchCount = 2000;
int batchCount = 500;
List<String> listIds = Arrays.asList(ids.split(","));
ForkJoinPool pool = new ForkJoinPool();
if(CollectionUtils.isEmpty(listIds)) {
@@ -1368,6 +1368,7 @@ public class LawsHomeSearchServiceImpl implements ILawsHomeSearchService {
public void updateElasticsearch(LawsHomeNormalSearchVO obj,List<OSSFile> listFile){
String idTemp = obj.getId();
System.out.println("--------------" + obj);
StringBuilder fileTextAll = getStringBuilder(listFile);
addES(obj, idTemp, fileTextAll);
}