From 4d15fa8051884869c5b612d0641508874cc71811 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期三, 29 七月 2026 11:04:15 +0800
Subject: [PATCH] feat(erp): 集成SRM供应商服务并优化ERP模块功能
---
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/databind/TimestampLocalDateTimeSerializer.java | 29 +++++++++++++++++++----------
1 files changed, 19 insertions(+), 10 deletions(-)
diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/databind/TimestampLocalDateTimeSerializer.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/databind/TimestampLocalDateTimeSerializer.java
index fc49e80..617eda2 100644
--- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/databind/TimestampLocalDateTimeSerializer.java
+++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/databind/TimestampLocalDateTimeSerializer.java
@@ -35,9 +35,11 @@
super(LocalDateTime.class);
}
+ private static final DateTimeFormatter DEFAULT_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+
@Override
public void serialize(LocalDateTime value, JsonGenerator gen, SerializationContext serializers) throws JacksonException {
- // 鎯呭喌涓�锛氭湁 JsonFormat 鑷畾涔夋敞瑙o紝鍒欎娇鐢ㄥ畠銆俬ttps://github.com/YunaiV/ruoyi-vue-pro/pull/1019
+ // 鎯呭喌涓�锛氭湁 JsonFormat 鑷畾涔夋敞瑙o紝鍒欎娇鐢ㄥ畠
String fieldName = gen.streamWriteContext().currentName();
if (fieldName != null) {
Object currentValue = gen.currentValue();
@@ -45,23 +47,30 @@
Class<?> clazz = currentValue.getClass();
Map<String, Field> fieldMap = FIELD_CACHE.computeIfAbsent(clazz, this::buildFieldMap);
Field field = fieldMap.get(fieldName);
- // 杩涗竴姝ヤ慨澶嶏細https://gitee.com/zhijiantianya/ruoyi-vue-pro/pulls/1480
if (field != null && field.isAnnotationPresent(JsonFormat.class)) {
JsonFormat jsonFormat = field.getAnnotation(JsonFormat.class);
- try {
- DateTimeFormatter formatter = DateTimeFormatter.ofPattern(jsonFormat.pattern());
- gen.writeString(formatter.format(value));
+ // 鑻ユ寚瀹氳緭鍑轰负鏁板瓧锛堟椂闂存埑锛夛紝鍒欐寜鍘熷鏂瑰紡澶勭悊
+ if (jsonFormat.shape() == JsonFormat.Shape.NUMBER) {
+ gen.writeNumber(value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
return;
- } catch (Exception ex) {
- log.warn("[serialize][({}#{}) 浣跨敤 JsonFormat pattern 澶辫触锛屽皾璇曚娇鐢ㄩ粯璁ょ殑 Long 鏃堕棿鎴砞",
- clazz.getName(), fieldName, ex);
+ }
+ // 鑻ユ寚瀹氫簡鑷畾涔� pattern锛屽垯浣跨敤 pattern 鏍煎紡鍖�
+ if (StrUtil.isNotEmpty(jsonFormat.pattern())) {
+ try {
+ DateTimeFormatter formatter = DateTimeFormatter.ofPattern(jsonFormat.pattern());
+ gen.writeString(formatter.format(value));
+ return;
+ } catch (Exception ex) {
+ log.warn("[serialize][({}#{}) 浣跨敤 JsonFormat pattern 澶辫触锛屽皾璇曚娇鐢ㄩ粯璁ゆ牸寮廬",
+ clazz.getName(), fieldName, ex);
+ }
}
}
}
}
- // 鎯呭喌浜岋細榛樿灏� LocalDateTime 瀵硅薄锛岃浆鎹负 Long 鏃堕棿鎴�
- gen.writeNumber(value.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
+ // 鎯呭喌浜岋細榛樿鏍煎紡鍖栦负 yyyy-MM-dd HH:mm:ss 瀛楃涓�
+ gen.writeString(DEFAULT_FORMATTER.format(value));
}
/**
--
Gitblit v1.9.3