|
|
|
@ -1,5 +1,7 @@
|
|
|
|
|
package com.supervision.police.service.impl;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.cache.CacheUtil;
|
|
|
|
|
import cn.hutool.cache.impl.TimedCache;
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
|
|
import cn.hutool.core.date.DateUnit;
|
|
|
|
@ -20,10 +22,8 @@ import org.springframework.aop.framework.AopContext;
|
|
|
|
|
import org.springframework.scheduling.annotation.Async;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.Objects;
|
|
|
|
|
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@Slf4j
|
|
|
|
@ -42,6 +42,8 @@ public class OCREvidenceServiceImpl implements OCREvidenceService {
|
|
|
|
|
private final CaseEvidenceService caseEvidenceService;
|
|
|
|
|
|
|
|
|
|
private final OcrExtractService ocrExtractService;
|
|
|
|
|
|
|
|
|
|
private final TimedCache<String, DateTime> timedCache = CacheUtil.newTimedCache(5*60*1000);
|
|
|
|
|
@Override
|
|
|
|
|
public Boolean submitOrcTask(String fileId) {
|
|
|
|
|
Assert.notEmpty(fileId, "文件id不能为空");
|
|
|
|
@ -181,6 +183,13 @@ public class OCREvidenceServiceImpl implements OCREvidenceService {
|
|
|
|
|
if (CollUtil.isEmpty(fileIdList)){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean timeOut = processTimeOut(fileIdList);
|
|
|
|
|
if (timeOut){
|
|
|
|
|
log.info("retrieveTitleProcess:文件识别超时,跳过等待...");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
List<FileEvidenceProperty> properties = fileEvidencePropertyService.lambdaQuery().in(FileEvidenceProperty::getFileId, fileIdList).list();
|
|
|
|
|
for (String fileId : fileIdList) {
|
|
|
|
|
if (!evidencePropertiesExist(fileId, properties)){
|
|
|
|
@ -190,6 +199,16 @@ public class OCREvidenceServiceImpl implements OCREvidenceService {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private boolean processTimeOut(List<String> fileIdList) {
|
|
|
|
|
String join = StrUtil.join(",", fileIdList);
|
|
|
|
|
if (!timedCache.containsKey(join)){
|
|
|
|
|
timedCache.put(join, DateUtil.date());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
DateTime dateTime = timedCache.get(join);
|
|
|
|
|
return DateUtil.between(dateTime, DateUtil.date(), DateUnit.SECOND) > fileIdList.size() * 20L;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
@Transactional(rollbackFor = Exception.class,transactionManager = "dataSourceTransactionManager")
|
|
|
|
|
public List<String> batchSaveEvidence(List<EvidenceFileOCRDTO> evidenceFileOCRDTOS) {
|
|
|
|
@ -217,7 +236,7 @@ public class OCREvidenceServiceImpl implements OCREvidenceService {
|
|
|
|
|
@Transactional(rollbackFor = Exception.class,transactionManager = "dataSourceTransactionManager")
|
|
|
|
|
public void doRetrieveTitle(List<String> fileIdList) {
|
|
|
|
|
|
|
|
|
|
List<RecordFileDTO> recordFileDTOS = waitingOCRFinish(fileIdList, 60 * 2);
|
|
|
|
|
List<RecordFileDTO> recordFileDTOS = waitingOCRFinish(fileIdList, 30 * fileIdList.size());
|
|
|
|
|
if (CollUtil.isEmpty(recordFileDTOS)){
|
|
|
|
|
log.warn("doRetrieveTitle:文件id:{} 未查询到文件信息...", StrUtil.join(",", fileIdList));
|
|
|
|
|
return;
|
|
|
|
@ -229,6 +248,7 @@ public class OCREvidenceServiceImpl implements OCREvidenceService {
|
|
|
|
|
dto.setText(recordFileDTO.getOcrText());
|
|
|
|
|
return dto;
|
|
|
|
|
}).toList();
|
|
|
|
|
log.info("doRetrieveTitle,extractTitle参数是:{}", JSONUtil.toJsonStr(dtoList));
|
|
|
|
|
List<OcrExtractDto> result = ocrExtractService.extractTitle(dtoList);
|
|
|
|
|
|
|
|
|
|
log.info("doRetrieveTitle,extractTitle返回结果是:{}", JSONUtil.toJsonStr(result));
|
|
|
|
|