Commit b1c592cb by 黄明步

更新

parent e3208b5f
......@@ -186,13 +186,6 @@
<artifactId>druid-spring-boot-starter</artifactId>
<version>${alibaba.druid.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId>
......
......@@ -74,6 +74,9 @@ public class AppAbilityRecordAllController {
}
System.out.println("yearMonthDay==========" + yearMonthDay + ";endYearMonthDay==========" + endYearMonthDay);
} else {
yearMonthDay = DateUtil.parse("2014-01-01 00:00:00", "yyyy-MM-dd HH:mm:ss").toString();
endYearMonthDay = DateUtil.parse(DateUtil.date().toString(), "yyyy-MM-dd HH:mm:ss").toString();
}
try{
List<CallRecordModel> callRecordList = this.recordAllService.selectCallRecord(yearMonthDay, endYearMonthDay);
......
......@@ -14,7 +14,6 @@ import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch._types.SortOrder;
import co.elastic.clients.elasticsearch._types.aggregations.*;
import co.elastic.clients.elasticsearch.core.*;
import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem;
import co.elastic.clients.elasticsearch.core.search.TotalHits;
import co.elastic.clients.elasticsearch.indices.DeleteIndexResponse;
import co.elastic.clients.json.JsonData;
......@@ -26,6 +25,7 @@ import com.gxmailu.ocrCloudPlatform.entity.*;
import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel;
import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper;
import com.gxmailu.ocrCloudPlatform.mapper.ServerInfoMapper;
import com.gxmailu.ocrCloudPlatform.mapper.TmpRecordByTriggerMapper;
import com.gxmailu.ocrCloudPlatform.service.ConfigAbilityService;
import com.gxmailu.ocrCloudPlatform.service.ConfigApplicationService;
import com.gxmailu.ocrCloudPlatform.service.CourtService;
......@@ -55,11 +55,13 @@ public class ElasticSearchService {
private static final Map<Character, String> SPECIAL_CHARACTERS_MAP = new HashMap<>();
private static String lastIndexTime = "2023-05-11 07:00:00";
private static String lastIndexTime = "2024-01-23 08:00:00";
@Resource
private AppAbilityRecordAllMapper recordAllMapper;
@Resource
private TmpRecordByTriggerMapper tmpRecordByTriggerMapper;
@Resource
private ServerInfoMapper serverInfoMapper;
@Resource
private ConfigAbilityService configAbilityService;
......@@ -104,7 +106,7 @@ public class ElasticSearchService {
return response.source();
}
public List<Map.Entry<String, String>> recordDataImport(List<AppAbilityRecord> appAbilityRecordList) {
public void recordDataImport(List<AppAbilityRecord> appAbilityRecordList) {
if (CollUtil.isNotEmpty(appAbilityRecordList)) {
BulkRequest.Builder br = new BulkRequest.Builder();
......@@ -115,18 +117,9 @@ public class ElasticSearchService {
try {
response = client.bulk(br.build());
} catch (IOException e) {
throw new RuntimeException(e);
}
if (response.errors()) {
log.error("AppAbilityRecord数据导入失败,错误信息:{}", response);
return new ArrayList<>();
}
List<BulkResponseItem> items = response.items();
Map<String, String> map = items.stream().collect(Collectors.toMap(BulkResponseItem::id, BulkResponseItem::result));
return new ArrayList<>(map.entrySet());
}
return new ArrayList<>();
}
......@@ -246,8 +239,6 @@ public class ElasticSearchService {
// 日期范围查询
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime")
// .from(startTime)
// .to(endTime)
.gte(JsonData.of(startTime))
.lt(JsonData.of(endTime))
));
......@@ -276,9 +267,9 @@ public class ElasticSearchService {
String startTime = lastIndexTime;
String endTime = "";
while (!DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss").after(new Date())) {
endTime = DateUtil.offsetHour(DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss"), 2).toString("yyyy-MM-dd HH:mm:ss");
List<AppAbilityRecordAll> documentList = recordAllMapper.selectList(Wrappers.lambdaQuery(AppAbilityRecordAll.class).between(AppAbilityRecordAll::getCallTime, startTime, endTime));
documentList = documentList.stream().sorted(Comparator.comparing(AppAbilityRecordAll::getCallTime)).collect(Collectors.toList());
endTime = DateUtil.offsetMinute(DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss"), 20).toString("yyyy-MM-dd HH:mm:ss");
List<TmpRecordByTrigger> documentList = tmpRecordByTriggerMapper.selectList(Wrappers.lambdaQuery(TmpRecordByTrigger.class).between(TmpRecordByTrigger::getCallTime, startTime, endTime));
documentList = documentList.stream().sorted(Comparator.comparing(TmpRecordByTrigger::getCallTime)).collect(Collectors.toList());
if (CollUtil.isNotEmpty(documentList)) {
BulkRequest.Builder br = new BulkRequest.Builder();
......
......@@ -208,7 +208,7 @@ public class RetransmissionService {
if (StringUtils.isNotEmpty(res)) {
break;
}
} catch (HttpException e) {
} catch (Exception e) {
addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e);
......@@ -319,7 +319,7 @@ public class RetransmissionService {
if (StringUtils.isNotEmpty(res)) {
break;
}
} catch (HttpException e) {
} catch (Exception e) {
addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e);
......@@ -370,7 +370,7 @@ public class RetransmissionService {
}
// 赋值body
IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream());
} catch (IOException e) {
} catch (Exception e) {
log.error("OCR云平台接口异常", e);
returnError(response, 500, "OCR云平台接口异常");
}
......@@ -389,9 +389,10 @@ public class RetransmissionService {
if (appAbilityRecordAll == null || StrUtil.isBlank(appAbilityRecordAll.getServerIp())
|| StrUtil.isBlank(appAbilityRecordAll.getDstUrl())
|| StrUtil.isBlank(appAbilityRecordAll.getPdf())) {
log.error("文件下载未命中ES,准备从数据库中查询 id={}", id);
TmpRecordByTrigger tmpRecordByTrigger = tmpRecordByTriggerMapper.selectById(id);
if (tmpRecordByTrigger == null) {
log.error("从查询不到ID为 {} 的文件数据", id);
log.error("从数据库查询不到ID为 {} 的文件数据", id);
return;
}
elasticSearchService.recordDataImport(CollUtil.newArrayList(tmpRecordByTrigger));
......@@ -461,9 +462,10 @@ public class RetransmissionService {
if (appAbilityRecordAll == null || StrUtil.isBlank(appAbilityRecordAll.getServerIp())
|| StrUtil.isBlank(appAbilityRecordAll.getDstUrl())
|| StrUtil.isBlank(appAbilityRecordAll.getPdf())) {
log.error("文件下载未命中ES,准备从数据库中查询 id={}", id);
TmpRecordByTrigger tmpRecordByTrigger = tmpRecordByTriggerMapper.selectById(id);
if (tmpRecordByTrigger == null) {
log.error("从数据库中无法获取ID为 {} 的文件数据", id);
log.error("从数据库查询不到ID为 {} 的文件数据", id);
return;
}
elasticSearchService.recordDataImport(CollUtil.newArrayList(tmpRecordByTrigger));
......@@ -539,7 +541,7 @@ public class RetransmissionService {
if (StringUtils.isNotEmpty(res)) {
break;
}
} catch (HttpException e) {
} catch (Exception e) {
addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e);
......@@ -555,7 +557,7 @@ public class RetransmissionService {
saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId);
return result;
} catch (IOException e) {
} catch (Exception e) {
log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date());
} finally {
......@@ -610,7 +612,7 @@ public class RetransmissionService {
if (StringUtils.isNotEmpty(res)) {
break;
}
} catch (HttpException e) {
} catch (Exception e) {
addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount);
......@@ -626,7 +628,7 @@ public class RetransmissionService {
saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId);
return result;
} catch (IOException e) {
} catch (Exception e) {
log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date());
} finally {
......@@ -675,7 +677,7 @@ public class RetransmissionService {
saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId);
return result;
} catch (IOException e) {
} catch (Exception e) {
log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date());
} finally {
......
......@@ -13,7 +13,7 @@ public class OcrResult {
private String code;
private String message;
private Object data;
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSSX")
@JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
private Date time;
public OcrResult(String code, String msg, Object data, Date time) {
......
......@@ -72,6 +72,6 @@ elasticsearch:
username: elastic
password: RQuT4eQIdIZ57waX9f87
#eureka:
# client:
# enabled: false
\ No newline at end of file
eureka:
client:
enabled: false
\ No newline at end of file
......@@ -110,6 +110,41 @@ public class ESTest {
System.out.println(totalHits.value());
}
// @Test
public static void main(String[] args) {
ArrayList<CallRecordModel> callRecordModels = new ArrayList<>();
Court court1 = new Court();
court1.setIpScope("192.168.4.");
court1.setName("南宁市中级人民法院");
Court court2 = new Court();
court2.setIpScope("192.168.2.;192.168.1.");
court2.setName("柳州市中级人民法院");
List<Court> courtList = new ArrayList<>();
courtList.add(court1);
courtList.add(court2);
for (int i = 0; i < 10; i++) {
CallRecordModel callRecordModel = new CallRecordModel();
callRecordModel.setIp("192.168.4." + i);
callRecordModel.setCourtName(courtList.stream()
.filter(court -> Arrays.stream(court.getIpScope().split(";")).anyMatch(callRecordModel.getIp()::contains))
.findFirst()
.map(Court::getName)
.orElse("未知"));
callRecordModels.add(callRecordModel);
}
// CallRecordModel recordModel = new CallRecordModel();
// recordModel.setIp("192.168.1.1");
//
// recordModel.setCourtName(courtList.stream()
// .filter(court -> Arrays.stream(court.getIpScope().split(";")).anyMatch(recordModel.getIp()::contains))
// .findFirst()
// .map(Court::getName)
// .orElse("未知"));
System.out.println(callRecordModels);
}
@Test
public void getCourtUseSum() throws IOException {
List<Court> courtList;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment