Commit 8b056187 by 黄明步

修改年月日调用量查询

parent f870502a
package com.gxmailu.ocrCloudPlatform.service.impl;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateUtil;
import co.elastic.clients.elasticsearch.ElasticsearchClient;
import co.elastic.clients.elasticsearch.core.BulkRequest;
import co.elastic.clients.elasticsearch.core.BulkResponse;
import co.elastic.clients.elasticsearch.core.DeleteByQueryResponse;
import co.elastic.clients.elasticsearch.core.GetResponse;
import co.elastic.clients.elasticsearch.indices.DeleteIndexResponse;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecord3;
import com.gxmailu.ocrCloudPlatform.entity.AppAbilityRecordAll;
import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord3Mapper;
import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecord4Mapper;
import com.gxmailu.ocrCloudPlatform.mapper.AppAbilityRecordAllMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
/**
* @author Hmb
......@@ -29,6 +40,15 @@ public class ElasticSearchService{
private static final Map<Character, String> SPECIAL_CHARACTERS_MAP = new HashMap<>();
private static String lastIndexTime = "2023-11-30 00:00:00";
@Resource
private AppAbilityRecordAllMapper recordAllMapper;
@Resource
private AppAbilityRecord4Mapper record4Mapper;
@Resource
private AppAbilityRecord3Mapper record3Mapper;
static {
SPECIAL_CHARACTERS_MAP.put('[', "\\[");
SPECIAL_CHARACTERS_MAP.put(']', "\\]");
......@@ -75,4 +95,35 @@ public class ElasticSearchService{
DeleteByQueryResponse deleteByQueryResponse = client.deleteByQuery(s -> s.index(index).query(q -> q.matchAll(m -> m)));
log.info("删除索引文档操作结果:{}",deleteByQueryResponse.deleted());
}
@Scheduled(fixedDelayString = "10000")
private void dataImport() {
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"), 4).toString("yyyy-MM-dd HH:mm:ss");
// List<AppAbilityRecordAll> documentList = recordAllMapper.selectList(Wrappers.lambdaQuery(AppAbilityRecordAll.class).between(AppAbilityRecordAll::getCallTime, startTime, endTime));
List<AppAbilityRecord3> documentList = record3Mapper.selectList(Wrappers.lambdaQuery(AppAbilityRecord3.class).between(AppAbilityRecord3::getCallTime, startTime, endTime));
documentList = documentList.stream().sorted(Comparator.comparing(AppAbilityRecord3::getCallTime)).collect(Collectors.toList());
if (CollUtil.isNotEmpty(documentList)) {
BulkRequest.Builder br = new BulkRequest.Builder();
documentList.forEach(document -> br.operations(bo -> bo.index(io -> io.index("app_ability_record").id(String.valueOf(document.getId())).document(document))));
BulkResponse response = null;
try {
response = client.bulk(br.build());
} catch (IOException e) {
throw new RuntimeException(e);
}
log.info("是否发生错误:{}", response.errors());
log.info("调用记录增量数据条数:{}", documentList.size());
}
startTime = endTime;
}
lastIndexTime = DateUtil.formatDateTime(new Date());
log.info("app_ability_record索引最后更新时间:{}", lastIndexTime);
}
}
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