提交 250ecaa9 作者: yanxin

已采集数据检索逻辑优化,动态匹配索引

上级 6a7cbac9
...@@ -58,6 +58,7 @@ import org.springframework.stereotype.Service; ...@@ -58,6 +58,7 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.io.IOException; import java.io.IOException;
import java.time.LocalDate;
import java.util.*; import java.util.*;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
...@@ -609,6 +610,28 @@ public class EsService { ...@@ -609,6 +610,28 @@ public class EsService {
*/ */
public IPage<EventDataVO> collectPageList(InfoDataSearchCondition eventDataCondition) { public IPage<EventDataVO> collectPageList(InfoDataSearchCondition eventDataCondition) {
SearchRequest searchRequest = new SearchRequest(Constants.COLLECT_INDEX); SearchRequest searchRequest = new SearchRequest(Constants.COLLECT_INDEX);
if ("1".equals(eventDataCondition.getIsSubject())) {
Subject byId = subjectService.getById(eventDataCondition.getSubjectId());
//更新开始、结束时间
if(byId.getTimeEnable()!=null){
String timeEnable = DateUtil.format(byId.getTimeEnable(), "yyyy-MM-dd");
if(StringUtils.isEmpty(eventDataCondition.getStartTime()) || eventDataCondition.getStartTime().compareTo(timeEnable)<0){
eventDataCondition.setStartTime(timeEnable);
}
}
if(byId.getTimeDisable()!=null){
String timeDisable = DateUtil.format(byId.getTimeDisable(), "yyyy-MM-dd");
if(StringUtils.isEmpty(eventDataCondition.getEndTime()) || eventDataCondition.getEndTime().compareTo(timeDisable)>0){
eventDataCondition.setEndTime(timeDisable);
}
}
}
//根据检索开始结束时间确定索引范围
String firstIndex = LocalDate.now().minusMonths(23).toString();
if (StringUtils.isNotEmpty(eventDataCondition.getStartTime()) && eventDataCondition.getStartTime().compareTo(firstIndex) > 0) {
String[] indexs = EsIndexUtil.getIndexMonth(Constants.COLLECT_INDEX, eventDataCondition.getStartTime(), eventDataCondition.getEndTime());
searchRequest = new SearchRequest(indexs);
}
SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
String[] fetchFields = eventDataCondition.getFetchFields(); String[] fetchFields = eventDataCondition.getFetchFields();
String[] excludeFields = eventDataCondition.getExcludeFields(); String[] excludeFields = eventDataCondition.getExcludeFields();
......
...@@ -141,4 +141,43 @@ public class EsIndexUtil { ...@@ -141,4 +141,43 @@ public class EsIndexUtil {
String[] indexs = getIndexIntervalYear(index,startYear,endYear); String[] indexs = getIndexIntervalYear(index,startYear,endYear);
return indexs; return indexs;
} }
/**
* 获取月份索引,用于采集库检索
* @param index
* @param startDate
* @param endDate
* @return
*/
public static String[] getIndexMonth(String index, String startDate, String endDate) {
int startYear = Integer.parseInt(startDate.substring(0, 4));
int startMonth = Integer.parseInt(startDate.substring(0, 7).substring(5));
int endYear;
int endMonth;
if (StringUtils.isNotBlank(endDate)) {
endYear = Integer.parseInt(endDate.substring(0, 4));
endMonth = Integer.parseInt(endDate.substring(0, 7).substring(5));
} else {
endYear = LocalDateTime.now().getYear();
endMonth = LocalDateTime.now().getMonthValue();
}
List<String> result = new ArrayList<>();
while (startYear <= endYear) {
while (startYear<endYear || startMonth <= endMonth) {
if(startMonth<10){
result.add(index + "_" + startYear + "0" + startMonth);
}else{
result.add(index + "_" + startYear + startMonth);
}
if(startMonth == 12){
startMonth = 1;
break;
}
startMonth++;
}
startYear++;
}
return result.toArray(new String[0]);
}
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论