From 1bbfbb26d3ef0b91e06f3074a73bf9f22c3fcfc7 Mon Sep 17 00:00:00 2001
From: 云 <2163098428@qq.com>
Date: 星期一, 28 九月 2026 23:29:35 +0800
Subject: [PATCH] fix(config): 统一日期格式为yyyy-MM-dd并更新数据库配置
---
src/main/java/com/ruoyi/common/utils/DateFormatRenderPolicy.java | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/common/utils/DateFormatRenderPolicy.java b/src/main/java/com/ruoyi/common/utils/DateFormatRenderPolicy.java
new file mode 100644
index 0000000..9254efc
--- /dev/null
+++ b/src/main/java/com/ruoyi/common/utils/DateFormatRenderPolicy.java
@@ -0,0 +1,53 @@
+package com.ruoyi.common.utils;
+
+import com.deepoove.poi.XWPFTemplate;
+import com.deepoove.poi.exception.RenderException;
+import com.deepoove.poi.policy.RenderPolicy;
+import com.deepoove.poi.template.ElementTemplate;
+import com.deepoove.poi.template.run.RunTemplate;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
+
+import java.time.LocalDate;
+import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.Date;
+
+/**
+ * 鏃ユ湡鏍煎紡鍖栨覆鏌撶瓥鐣ワ紝閬垮厤 poi-tl 鐩存帴璋冪敤 Date.toString() 杈撳嚭甯︽椂鍖虹殑鑻辨枃鏍煎紡
+ */
+public class DateFormatRenderPolicy implements RenderPolicy {
+
+ private final String pattern;
+ private final DateTimeFormatter dateTimeFormatter;
+
+ public DateFormatRenderPolicy(String pattern) {
+ this.pattern = pattern;
+ this.dateTimeFormatter = DateTimeFormatter.ofPattern(pattern);
+ }
+
+ @Override
+ public void render(ElementTemplate eleTemplate, Object data, XWPFTemplate template) {
+ XWPFRun run = ((RunTemplate) eleTemplate).getRun();
+ try {
+ run.setText(format(data), 0);
+ } catch (Exception e) {
+ throw new RenderException("DateFormatRender for " + eleTemplate + " error: " + e.getMessage(), e);
+ }
+ }
+
+ private String format(Object data) {
+ if (data == null) {
+ return "";
+ }
+ if (data instanceof Date date) {
+ return DateUtils.parseDateToStr(pattern, date);
+ }
+ if (data instanceof LocalDateTime dateTime) {
+ return dateTime.format(dateTimeFormatter);
+ }
+ if (data instanceof LocalDate date) {
+ return date.format(dateTimeFormatter);
+ }
+ return data.toString();
+ }
+}
--
Gitblit v1.9.3