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

This commit is contained in:
chenshaohua
2026-07-08 16:19:58 +08:00
parent 20e4cb1bb7
commit f42ef9c83a
2 changed files with 13 additions and 4 deletions

View File

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

View File

@@ -8,6 +8,7 @@ import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import org.apache.commons.lang3.time.DateFormatUtils;
@@ -36,6 +37,10 @@ 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")
.withZone(ZoneId.of("UTC"));
/**
* 获取当前Date型日期
*