Kaynağa Gözat

农村三资数据填报

wwh 1 hafta önce
ebeveyn
işleme
63302f1877

+ 17 - 5
baqing-admin/src/main/java/com/ruoyi/web/modules/industryservice/support/YakOutboundReportExcelExporter.java

@@ -191,7 +191,8 @@ public class YakOutboundReportExcelExporter
191 191
                     continue;
192 192
                 }
193 193
                 String text = formatter.formatCellValue(cell);
194
-                if (StringUtils.isEmpty(text) || !text.contains("年"))
194
+                // 跳过填表人/填表时间行,避免把「XXXX年X月」先改成统计年导致填表日期无法落到当月
195
+                if (StringUtils.isEmpty(text) || !text.contains("年") || isFillerMetaText(text))
195 196
                 {
196 197
                     continue;
197 198
                 }
@@ -215,6 +216,9 @@ public class YakOutboundReportExcelExporter
215 216
         }
216 217
     }
217 218
 
219
+    /**
220
+     * 将填表人、填表时间/日期写为当前登录用户与<strong>系统当月</strong>(非导出统计年月)。
221
+     */
218 222
     static void updateFiller(Sheet sheet, String fillerName)
219 223
     {
220 224
         java.time.LocalDate today = java.time.LocalDate.now();
@@ -241,7 +245,7 @@ public class YakOutboundReportExcelExporter
241 245
                     continue;
242 246
                 }
243 247
                 String text = formatter.formatCellValue(cell);
244
-                if (StringUtils.isEmpty(text) || (!text.contains("填表人") && !text.contains("填表时间")))
248
+                if (StringUtils.isEmpty(text) || !isFillerMetaText(text))
245 249
                 {
246 250
                     continue;
247 251
                 }
@@ -250,9 +254,12 @@ public class YakOutboundReportExcelExporter
250 254
                 {
251 255
                     updated = updated.replace("登录用户名称", fillerName);
252 256
                 }
253
-                updated = updated.replaceAll("填表时间:\\s*XXXX年X月", "填表时间:" + fillTime);
254
-                updated = updated.replaceAll("填表时间:\\s*\\d{4}年\\d{1,2}月", "填表时间:" + fillTime);
255
-                if (updated.contains("XXXX年") && updated.contains("填表时间"))
257
+                // 兼容「填表时间」「填表日期」及占位 XXXX年X月 / 已被误替换的 yyyy年X月
258
+                updated = updated.replaceAll("(填表时间|填表日期):\\s*XXXX年X月", "$1:" + fillTime);
259
+                updated = updated.replaceAll("(填表时间|填表日期):\\s*\\d{4}年X月", "$1:" + fillTime);
260
+                updated = updated.replaceAll("(填表时间|填表日期):\\s*\\d{4}年\\d{1,2}月", "$1:" + fillTime);
261
+                if (updated.contains("XXXX年")
262
+                        && (updated.contains("填表时间") || updated.contains("填表日期")))
256 263
                 {
257 264
                     updated = updated.replaceFirst("XXXX年X?月?", fillTime);
258 265
                 }
@@ -261,6 +268,11 @@ public class YakOutboundReportExcelExporter
261 268
         }
262 269
     }
263 270
 
271
+    private static boolean isFillerMetaText(String text)
272
+    {
273
+        return text.contains("填表人") || text.contains("填表时间") || text.contains("填表日期");
274
+    }
275
+
264 276
     private static void mergeTotalLabelCells(Sheet sheet, int rowIndex)
265 277
     {
266 278
         int firstCol = COL_SEQ;

+ 27 - 0
baqing-admin/src/test/java/com/ruoyi/web/modules/industryservice/support/YakOutboundReportExcelExporterTest.java

@@ -65,6 +65,33 @@ class YakOutboundReportExcelExporterTest
65 65
         }
66 66
     }
67 67
 
68
+    @Test
69
+    @DisplayName("导出填表时间默认为系统当月,且标题统计月与填表月可不同")
70
+    void exportFillerDateDefaultsToCurrentMonth() throws Exception
71
+    {
72
+        java.time.LocalDate today = java.time.LocalDate.now();
73
+        String expectedFill = today.getYear() + "年" + today.getMonthValue() + "月";
74
+        int exportMonth = today.getMonthValue() == 1 ? 12 : today.getMonthValue() - 1;
75
+        int exportYear = today.getMonthValue() == 1 ? today.getYear() - 1 : today.getYear();
76
+        byte[] bytes = exporter.export(exportYear, exportMonth,
77
+                Collections.singletonList(sample("雅安镇", "雅安镇荣嘎村", 10, 100)), "测试用户");
78
+        try (org.apache.poi.ss.usermodel.Workbook wb = org.apache.poi.ss.usermodel.WorkbookFactory.create(
79
+                new ByteArrayInputStream(bytes)))
80
+        {
81
+            org.apache.poi.ss.usermodel.Sheet sheet = YakOutboundReportExcelParser.resolveSheet(wb);
82
+            org.apache.poi.ss.usermodel.Row fillerRow = sheet.getRow(1);
83
+            assertNotNull(fillerRow);
84
+            String fillerText = YakOutboundReportExcelParser.cellString(fillerRow, 0);
85
+            assertNotNull(fillerText);
86
+            assertTrue(fillerText.contains("测试用户"), fillerText);
87
+            assertTrue(fillerText.contains(expectedFill), "填表时间应为当月: " + fillerText);
88
+            assertTrue(!fillerText.contains("X月"), fillerText);
89
+            String title = YakOutboundReportExcelParser.cellString(sheet.getRow(0), 0);
90
+            assertTrue(title.contains(exportYear + "年"), title);
91
+            assertTrue(title.contains("(" + exportMonth + "月)"), title);
92
+        }
93
+    }
94
+
68 95
     private static BizYakOutboundReport sample(String town, String village, int households, int yak)
69 96
     {
70 97
         BizYakOutboundReport report = new BizYakOutboundReport();