修改es开始时间和截至时间报错问题

This commit is contained in:
chenshaohua
2026-07-08 16:29:07 +08:00
parent f42ef9c83a
commit d692c7915f
2 changed files with 13 additions and 9 deletions

View File

@@ -720,13 +720,17 @@ public class ESJobSearchImpl implements IESJobSearchService
//开始时间
Date startDate = jobQuery.getStartDate();
Date endDate = jobQuery.getEndDate();
if (Objects.nonNull(startDate) || Objects.nonNull(endDate)) {
wrapper.and(w -> {
if (Objects.nonNull(startDate)) {
String startStr = DateUtils.UTC_FORMATTER.format(startDate.toInstant());
wrapper.ge(ESJobDocument::getPostingDate, startStr);
String startStr = DateUtils.ES_DATE_FORMATTER.format(startDate.toInstant());
w.ge(ESJobDocument::getPostingDate, startStr);
}
if (Objects.nonNull(endDate)) {
String endStr = DateUtils.UTC_FORMATTER.format(endDate.toInstant());
wrapper.le(ESJobDocument::getPostingDate, endStr);
String endStr = DateUtils.ES_DATE_FORMATTER.format(endDate.toInstant());
w.le(ESJobDocument::getPostingDate, endStr);
}
});
}
// 先开启打分、优先按匹配分数排序(关键词前台命中越高越靠前)
wrapper.trackScores();

View File

@@ -37,8 +37,8 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
"yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
"yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
public static final DateTimeFormatter UTC_FORMATTER = DateTimeFormatter
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
public static final DateTimeFormatter ES_DATE_FORMATTER = DateTimeFormatter
.ofPattern("yyyy-MM-dd HH:mm:ss")
.withZone(ZoneId.of("UTC"));
/**