Commit b1c592cb by 黄明步

更新

parent e3208b5f
...@@ -186,13 +186,6 @@ ...@@ -186,13 +186,6 @@
<artifactId>druid-spring-boot-starter</artifactId> <artifactId>druid-spring-boot-starter</artifactId>
<version>${alibaba.druid.version}</version> <version>${alibaba.druid.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>com.alibaba</groupId> <groupId>com.alibaba</groupId>
<artifactId>easyexcel</artifactId> <artifactId>easyexcel</artifactId>
......
...@@ -74,6 +74,9 @@ public class AppAbilityRecordAllController { ...@@ -74,6 +74,9 @@ public class AppAbilityRecordAllController {
} }
System.out.println("yearMonthDay==========" + yearMonthDay + ";endYearMonthDay==========" + endYearMonthDay); 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{ try{
List<CallRecordModel> callRecordList = this.recordAllService.selectCallRecord(yearMonthDay, endYearMonthDay); List<CallRecordModel> callRecordList = this.recordAllService.selectCallRecord(yearMonthDay, endYearMonthDay);
......
...@@ -14,7 +14,6 @@ import co.elastic.clients.elasticsearch._types.FieldValue; ...@@ -14,7 +14,6 @@ import co.elastic.clients.elasticsearch._types.FieldValue;
import co.elastic.clients.elasticsearch._types.SortOrder; import co.elastic.clients.elasticsearch._types.SortOrder;
import co.elastic.clients.elasticsearch._types.aggregations.*; import co.elastic.clients.elasticsearch._types.aggregations.*;
import co.elastic.clients.elasticsearch.core.*; 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.core.search.TotalHits;
import co.elastic.clients.elasticsearch.indices.DeleteIndexResponse; import co.elastic.clients.elasticsearch.indices.DeleteIndexResponse;
import co.elastic.clients.json.JsonData; import co.elastic.clients.json.JsonData;
...@@ -26,6 +25,7 @@ import com.gxmailu.ocrCloudPlatform.entity.*; ...@@ -26,6 +25,7 @@ import com.gxmailu.ocrCloudPlatform.entity.*;
import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel; import com.gxmailu.ocrCloudPlatform.excel.model.CallRecordModel;
import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper; import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper;
import com.gxmailu.ocrCloudPlatform.mapper.ServerInfoMapper; import com.gxmailu.ocrCloudPlatform.mapper.ServerInfoMapper;
import com.gxmailu.ocrCloudPlatform.mapper.TmpRecordByTriggerMapper;
import com.gxmailu.ocrCloudPlatform.service.ConfigAbilityService; import com.gxmailu.ocrCloudPlatform.service.ConfigAbilityService;
import com.gxmailu.ocrCloudPlatform.service.ConfigApplicationService; import com.gxmailu.ocrCloudPlatform.service.ConfigApplicationService;
import com.gxmailu.ocrCloudPlatform.service.CourtService; import com.gxmailu.ocrCloudPlatform.service.CourtService;
...@@ -55,11 +55,13 @@ public class ElasticSearchService { ...@@ -55,11 +55,13 @@ public class ElasticSearchService {
private static final Map<Character, String> SPECIAL_CHARACTERS_MAP = new HashMap<>(); 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 @Resource
private AppAbilityRecordAllMapper recordAllMapper; private AppAbilityRecordAllMapper recordAllMapper;
@Resource @Resource
private TmpRecordByTriggerMapper tmpRecordByTriggerMapper;
@Resource
private ServerInfoMapper serverInfoMapper; private ServerInfoMapper serverInfoMapper;
@Resource @Resource
private ConfigAbilityService configAbilityService; private ConfigAbilityService configAbilityService;
...@@ -104,7 +106,7 @@ public class ElasticSearchService { ...@@ -104,7 +106,7 @@ public class ElasticSearchService {
return response.source(); return response.source();
} }
public List<Map.Entry<String, String>> recordDataImport(List<AppAbilityRecord> appAbilityRecordList) { public void recordDataImport(List<AppAbilityRecord> appAbilityRecordList) {
if (CollUtil.isNotEmpty(appAbilityRecordList)) { if (CollUtil.isNotEmpty(appAbilityRecordList)) {
BulkRequest.Builder br = new BulkRequest.Builder(); BulkRequest.Builder br = new BulkRequest.Builder();
...@@ -115,18 +117,9 @@ public class ElasticSearchService { ...@@ -115,18 +117,9 @@ public class ElasticSearchService {
try { try {
response = client.bulk(br.build()); response = client.bulk(br.build());
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e);
}
if (response.errors()) {
log.error("AppAbilityRecord数据导入失败,错误信息:{}", response); 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 { ...@@ -246,8 +239,6 @@ public class ElasticSearchService {
// 日期范围查询 // 日期范围查询
boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder boolQuery.must(q -> q.range(rangeQueryBuilder -> rangeQueryBuilder
.field("callTime") .field("callTime")
// .from(startTime)
// .to(endTime)
.gte(JsonData.of(startTime)) .gte(JsonData.of(startTime))
.lt(JsonData.of(endTime)) .lt(JsonData.of(endTime))
)); ));
...@@ -276,9 +267,9 @@ public class ElasticSearchService { ...@@ -276,9 +267,9 @@ public class ElasticSearchService {
String startTime = lastIndexTime; String startTime = lastIndexTime;
String endTime = ""; String endTime = "";
while (!DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss").after(new Date())) { 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"); endTime = DateUtil.offsetMinute(DateUtil.parse(startTime, "yyyy-MM-dd HH:mm:ss"), 20).toString("yyyy-MM-dd HH:mm:ss");
List<AppAbilityRecordAll> documentList = recordAllMapper.selectList(Wrappers.lambdaQuery(AppAbilityRecordAll.class).between(AppAbilityRecordAll::getCallTime, startTime, endTime)); List<TmpRecordByTrigger> documentList = tmpRecordByTriggerMapper.selectList(Wrappers.lambdaQuery(TmpRecordByTrigger.class).between(TmpRecordByTrigger::getCallTime, startTime, endTime));
documentList = documentList.stream().sorted(Comparator.comparing(AppAbilityRecordAll::getCallTime)).collect(Collectors.toList()); documentList = documentList.stream().sorted(Comparator.comparing(TmpRecordByTrigger::getCallTime)).collect(Collectors.toList());
if (CollUtil.isNotEmpty(documentList)) { if (CollUtil.isNotEmpty(documentList)) {
BulkRequest.Builder br = new BulkRequest.Builder(); BulkRequest.Builder br = new BulkRequest.Builder();
......
...@@ -208,7 +208,7 @@ public class RetransmissionService { ...@@ -208,7 +208,7 @@ public class RetransmissionService {
if (StringUtils.isNotEmpty(res)) { if (StringUtils.isNotEmpty(res)) {
break; break;
} }
} catch (HttpException e) { } catch (Exception e) {
addServerRequestCount(ocrServerAddress.getIp(), -1); addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++; retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e); log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e);
...@@ -319,7 +319,7 @@ public class RetransmissionService { ...@@ -319,7 +319,7 @@ public class RetransmissionService {
if (StringUtils.isNotEmpty(res)) { if (StringUtils.isNotEmpty(res)) {
break; break;
} }
} catch (HttpException e) { } catch (Exception e) {
addServerRequestCount(ocrServerAddress.getIp(), -1); addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++; retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e); log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e);
...@@ -370,7 +370,7 @@ public class RetransmissionService { ...@@ -370,7 +370,7 @@ public class RetransmissionService {
} }
// 赋值body // 赋值body
IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream()); IoUtil.copy(httpResponse.bodyStream(), response.getOutputStream());
} catch (IOException e) { } catch (Exception e) {
log.error("OCR云平台接口异常", e); log.error("OCR云平台接口异常", e);
returnError(response, 500, "OCR云平台接口异常"); returnError(response, 500, "OCR云平台接口异常");
} }
...@@ -389,9 +389,10 @@ public class RetransmissionService { ...@@ -389,9 +389,10 @@ public class RetransmissionService {
if (appAbilityRecordAll == null || StrUtil.isBlank(appAbilityRecordAll.getServerIp()) if (appAbilityRecordAll == null || StrUtil.isBlank(appAbilityRecordAll.getServerIp())
|| StrUtil.isBlank(appAbilityRecordAll.getDstUrl()) || StrUtil.isBlank(appAbilityRecordAll.getDstUrl())
|| StrUtil.isBlank(appAbilityRecordAll.getPdf())) { || StrUtil.isBlank(appAbilityRecordAll.getPdf())) {
log.error("文件下载未命中ES,准备从数据库中查询 id={}", id);
TmpRecordByTrigger tmpRecordByTrigger = tmpRecordByTriggerMapper.selectById(id); TmpRecordByTrigger tmpRecordByTrigger = tmpRecordByTriggerMapper.selectById(id);
if (tmpRecordByTrigger == null) { if (tmpRecordByTrigger == null) {
log.error("从查询不到ID为 {} 的文件数据", id); log.error("从数据库查询不到ID为 {} 的文件数据", id);
return; return;
} }
elasticSearchService.recordDataImport(CollUtil.newArrayList(tmpRecordByTrigger)); elasticSearchService.recordDataImport(CollUtil.newArrayList(tmpRecordByTrigger));
...@@ -461,9 +462,10 @@ public class RetransmissionService { ...@@ -461,9 +462,10 @@ public class RetransmissionService {
if (appAbilityRecordAll == null || StrUtil.isBlank(appAbilityRecordAll.getServerIp()) if (appAbilityRecordAll == null || StrUtil.isBlank(appAbilityRecordAll.getServerIp())
|| StrUtil.isBlank(appAbilityRecordAll.getDstUrl()) || StrUtil.isBlank(appAbilityRecordAll.getDstUrl())
|| StrUtil.isBlank(appAbilityRecordAll.getPdf())) { || StrUtil.isBlank(appAbilityRecordAll.getPdf())) {
log.error("文件下载未命中ES,准备从数据库中查询 id={}", id);
TmpRecordByTrigger tmpRecordByTrigger = tmpRecordByTriggerMapper.selectById(id); TmpRecordByTrigger tmpRecordByTrigger = tmpRecordByTriggerMapper.selectById(id);
if (tmpRecordByTrigger == null) { if (tmpRecordByTrigger == null) {
log.error("从数据库中无法获取ID为 {} 的文件数据", id); log.error("从数据库查询不到ID为 {} 的文件数据", id);
return; return;
} }
elasticSearchService.recordDataImport(CollUtil.newArrayList(tmpRecordByTrigger)); elasticSearchService.recordDataImport(CollUtil.newArrayList(tmpRecordByTrigger));
...@@ -539,7 +541,7 @@ public class RetransmissionService { ...@@ -539,7 +541,7 @@ public class RetransmissionService {
if (StringUtils.isNotEmpty(res)) { if (StringUtils.isNotEmpty(res)) {
break; break;
} }
} catch (HttpException e) { } catch (Exception e) {
addServerRequestCount(ocrServerAddress.getIp(), -1); addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++; retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e); log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount, e);
...@@ -555,7 +557,7 @@ public class RetransmissionService { ...@@ -555,7 +557,7 @@ public class RetransmissionService {
saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId); saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId);
return result; return result;
} catch (IOException e) { } catch (Exception e) {
log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e); log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date()); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date());
} finally { } finally {
...@@ -610,7 +612,7 @@ public class RetransmissionService { ...@@ -610,7 +612,7 @@ public class RetransmissionService {
if (StringUtils.isNotEmpty(res)) { if (StringUtils.isNotEmpty(res)) {
break; break;
} }
} catch (HttpException e) { } catch (Exception e) {
addServerRequestCount(ocrServerAddress.getIp(), -1); addServerRequestCount(ocrServerAddress.getIp(), -1);
retryCount++; retryCount++;
log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount); log.error("OCR云平台接口异常, 准备重试 fileId={}, serverIp={}, 当前重试次数={}", fileId, ocrServerAddress.getIp(), retryCount);
...@@ -626,7 +628,7 @@ public class RetransmissionService { ...@@ -626,7 +628,7 @@ public class RetransmissionService {
saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId); saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId);
return result; return result;
} catch (IOException e) { } catch (Exception e) {
log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e); log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date()); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date());
} finally { } finally {
...@@ -675,7 +677,7 @@ public class RetransmissionService { ...@@ -675,7 +677,7 @@ public class RetransmissionService {
saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId); saveToAppAbilityRecordAll(result, request, ocrServerAddress.getIp(), fileId);
return result; return result;
} catch (IOException e) { } catch (Exception e) {
log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e); log.error("OCR云平台接口异常, fileId={}, serverIp={}", fileId, ocrServerAddress.getIp(), e);
return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date()); return new OcrResult("007500", "识别失败,请重试", null, DateUtil.date());
} finally { } finally {
......
...@@ -13,7 +13,7 @@ public class OcrResult { ...@@ -13,7 +13,7 @@ public class OcrResult {
private String code; private String code;
private String message; private String message;
private Object data; 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; private Date time;
public OcrResult(String code, String msg, Object data, Date time) { public OcrResult(String code, String msg, Object data, Date time) {
......
...@@ -72,6 +72,6 @@ elasticsearch: ...@@ -72,6 +72,6 @@ elasticsearch:
username: elastic username: elastic
password: RQuT4eQIdIZ57waX9f87 password: RQuT4eQIdIZ57waX9f87
#eureka: eureka:
# client: client:
# enabled: false enabled: false
\ No newline at end of file \ No newline at end of file
...@@ -110,6 +110,41 @@ public class ESTest { ...@@ -110,6 +110,41 @@ public class ESTest {
System.out.println(totalHits.value()); 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 @Test
public void getCourtUseSum() throws IOException { public void getCourtUseSum() throws IOException {
List<Court> courtList; 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