opt:优化单据管理
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
package org.nl.common.domain.handler;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||
import com.fasterxml.jackson.databind.JsonDeserializer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* 时区转换
|
||||
*
|
||||
* @author gbx
|
||||
* @since 2025-06-27
|
||||
*/
|
||||
public class IsoToLocalDateTimeStringDeserializer extends JsonDeserializer<String> {
|
||||
private static final DateTimeFormatter FORMATTER =
|
||||
DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.of("Asia/Shanghai"));
|
||||
|
||||
@Override
|
||||
public String deserialize(JsonParser p, DeserializationContext ctxt)
|
||||
throws IOException {
|
||||
String isoString = p.getText();
|
||||
try {
|
||||
Instant instant = Instant.parse(isoString);
|
||||
return FORMATTER.format(instant);
|
||||
} catch (Exception e) {
|
||||
return isoString;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -63,25 +63,45 @@ public class PageQuery implements Serializable {
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
if (StringUtils.isNotEmpty(sort)){
|
||||
String[] split = sort.split(",");
|
||||
for (int i = 0; i < (split.length & ~1); i=i+2) {
|
||||
for (int i = 0; i < (split.length & ~1); i = i + 2) {
|
||||
String col = split[i];
|
||||
OrderItem item = new OrderItem();
|
||||
item.setColumn(col);
|
||||
item.setAsc(split[i+1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
item.setAsc(split[i + 1].toLowerCase(Locale.ROOT).equals("asc"));
|
||||
page.addOrder(item);
|
||||
}
|
||||
}
|
||||
return page;
|
||||
}
|
||||
|
||||
public <R,T> Page<T> build(Class<R> r) {
|
||||
public static void trimStringFields(Object obj) {
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
Field[] fields = obj.getClass().getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
if (field.getType() == String.class) {
|
||||
field.setAccessible(true);
|
||||
try {
|
||||
String value = (String) field.get(obj);
|
||||
if (value != null) {
|
||||
field.set(obj, value.trim().toUpperCase());
|
||||
}
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public <R, T> Page<T> build(Class<R> r) {
|
||||
Integer pageNum = ObjectUtil.defaultIfNull(getPage(), DEFAULT_PAGE_NUM);
|
||||
Integer pageSize = ObjectUtil.defaultIfNull(getSize(), DEFAULT_PAGE_SIZE);
|
||||
if (pageNum <= 0) {
|
||||
pageNum = DEFAULT_PAGE_NUM;
|
||||
}
|
||||
Page<T> page = new Page<>(pageNum, pageSize);
|
||||
if (StringUtils.isNotEmpty(sort)){
|
||||
if (StringUtils.isNotEmpty(sort)) {
|
||||
String[] split = sort.split(",");
|
||||
for (int i = 0; i < (split.length & ~1); i=i+2) {
|
||||
String col = split[i];
|
||||
|
||||
@@ -157,4 +157,17 @@ public class DateUtil {
|
||||
public static LocalDateTime parseLocalDateTimeFormatyMdHms(String localDateTime) {
|
||||
return LocalDateTime.from(DFY_MD_HMS.parse(localDateTime));
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转 yyyy-MM-dd
|
||||
*
|
||||
* @param localDateTime /
|
||||
* @return /
|
||||
*/
|
||||
public static String parseLocalDateTimeFormatYmd(String localDateTime) {
|
||||
if (localDateTime == null || localDateTime.length() < 10) {
|
||||
return localDateTime;
|
||||
}
|
||||
return localDateTime.substring(0, 10);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user