添加空文件判断

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