mirror of
https://codeup.aliyun.com/64f7d6b8ce01efaafef1e678/coal/coal.git
synced 2026-01-25 07:46:40 +08:00
完善数据查询表达式
This commit is contained in:
@@ -19,6 +19,7 @@ import lombok.With;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.core.convert.ConversionFailedException;
|
||||
import org.springframework.core.convert.ConversionService;
|
||||
import org.springframework.data.domain.Sort;
|
||||
import org.springframework.data.jpa.domain.Specification;
|
||||
@@ -175,8 +176,20 @@ public class CommonQuery {
|
||||
map.put(
|
||||
Tuple.of("eq", LocalDateTime.class),
|
||||
(Root root, CriteriaBuilder criteriaBuilder, QueryItem x, ConversionService c) -> {
|
||||
return criteriaBuilder.equal(
|
||||
parseKey(root, x.key), c.convert(x.value, LocalDateTime.class));
|
||||
try {
|
||||
|
||||
return criteriaBuilder.equal(
|
||||
parseKey(root, x.key), c.convert(x.value, LocalDateTime.class));
|
||||
} catch (ConversionFailedException e) {
|
||||
|
||||
return criteriaBuilder.and(
|
||||
criteriaBuilder.greaterThanOrEqualTo(
|
||||
parseKey(root, x.key),
|
||||
c.convert(x.value + " 00:00:00", LocalDateTime.class)),
|
||||
criteriaBuilder.lessThanOrEqualTo(
|
||||
parseKey(root, x.key),
|
||||
c.convert(x.value + " 23:59:59", LocalDateTime.class)));
|
||||
}
|
||||
});
|
||||
|
||||
map.put(
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.lihongjie.coal.common;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
|
||||
@Component
|
||||
public class LocalDateTImeConverter implements Converter<String, LocalDateTime> {
|
||||
@Override
|
||||
public LocalDateTime convert(String source) {
|
||||
|
||||
if (source == null || source.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
try {
|
||||
|
||||
return LocalDateTime.parse(source);
|
||||
} catch (Exception e) {
|
||||
return LocalDateTime.parse(source, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user