Bladeren bron

农村三资数据填报

wwh 2 weken geleden
bovenliggende
commit
09e6c3faf0

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

@@ -203,7 +203,8 @@ public class LivestockProductOutputExcelExporter
203 203
                     continue;
204 204
                 }
205 205
                 String text = formatter.formatCellValue(cell);
206
-                if (StringUtils.isEmpty(text) || !text.contains("年"))
206
+                // 跳过填表人/填表时间行,避免把「XXXX年X月」先改成统计年导致填表日期无法落到当月
207
+                if (StringUtils.isEmpty(text) || !text.contains("年") || isFillerMetaText(text))
207 208
                 {
208 209
                     continue;
209 210
                 }
@@ -227,6 +228,9 @@ public class LivestockProductOutputExcelExporter
227 228
         }
228 229
     }
229 230
 
231
+    /**
232
+     * 将填表人、填表时间/日期写为当前登录用户与<strong>系统当月</strong>(非导出统计年月)。
233
+     */
230 234
     static void updateFiller(Sheet sheet, String fillerName)
231 235
     {
232 236
         java.time.LocalDate today = java.time.LocalDate.now();
@@ -253,7 +257,7 @@ public class LivestockProductOutputExcelExporter
253 257
                     continue;
254 258
                 }
255 259
                 String text = formatter.formatCellValue(cell);
256
-                if (StringUtils.isEmpty(text) || (!text.contains("填表人") && !text.contains("填表时间")))
260
+                if (StringUtils.isEmpty(text) || !isFillerMetaText(text))
257 261
                 {
258 262
                     continue;
259 263
                 }
@@ -262,9 +266,12 @@ public class LivestockProductOutputExcelExporter
262 266
                 {
263 267
                     updated = updated.replace("登录用户名称", fillerName);
264 268
                 }
265
-                updated = updated.replaceAll("填表时间:\\s*XXXX年X月", "填表时间:" + fillTime);
266
-                updated = updated.replaceAll("填表时间:\\s*\\d{4}年\\d{1,2}月", "填表时间:" + fillTime);
267
-                if (updated.contains("XXXX年") && updated.contains("填表时间"))
269
+                // 兼容「填表时间」「填表日期」及占位 XXXX年X月 / 已被误替换的 yyyy年X月
270
+                updated = updated.replaceAll("(填表时间|填表日期):\\s*XXXX年X月", "$1:" + fillTime);
271
+                updated = updated.replaceAll("(填表时间|填表日期):\\s*\\d{4}年X月", "$1:" + fillTime);
272
+                updated = updated.replaceAll("(填表时间|填表日期):\\s*\\d{4}年\\d{1,2}月", "$1:" + fillTime);
273
+                if (updated.contains("XXXX年")
274
+                        && (updated.contains("填表时间") || updated.contains("填表日期")))
268 275
                 {
269 276
                     updated = updated.replaceFirst("XXXX年X?月?", fillTime);
270 277
                 }
@@ -273,6 +280,11 @@ public class LivestockProductOutputExcelExporter
273 280
         }
274 281
     }
275 282
 
283
+    private static boolean isFillerMetaText(String text)
284
+    {
285
+        return text.contains("填表人") || text.contains("填表时间") || text.contains("填表日期");
286
+    }
287
+
276 288
     private static void mergeTotalLabelCells(Sheet sheet, int rowIndex)
277 289
     {
278 290
         int firstCol = COL_SEQ;

BIN
baqing-admin/src/main/resources/templates/livestock_ownership_household_import_template.xlsx


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

@@ -62,6 +62,34 @@ class LivestockProductOutputExcelTest
62 62
         }
63 63
     }
64 64
 
65
+    @Test
66
+    @DisplayName("导出填表时间默认为系统当月,且标题统计月与填表月可不同")
67
+    void exportFillerDateDefaultsToCurrentMonth() throws Exception
68
+    {
69
+        java.time.LocalDate today = java.time.LocalDate.now();
70
+        String expectedFill = today.getYear() + "年" + today.getMonthValue() + "月";
71
+        // 故意导出非当月统计期,验证填表时间仍为系统当月
72
+        int exportMonth = today.getMonthValue() == 1 ? 12 : today.getMonthValue() - 1;
73
+        int exportYear = today.getMonthValue() == 1 ? today.getYear() - 1 : today.getYear();
74
+        byte[] bytes = exporter.export(exportYear, exportMonth, Arrays.asList(sample("雅安镇", "雅安镇荣嘎村", "1", "2")),
75
+                "测试用户");
76
+        try (Workbook wb = WorkbookFactory.create(new ByteArrayInputStream(bytes)))
77
+        {
78
+            Sheet sheet = LivestockProductOutputExcelParser.resolveSheet(wb);
79
+            Row fillerRow = sheet.getRow(1);
80
+            assertNotNull(fillerRow);
81
+            String fillerText = LivestockProductOutputExcelParser.cellString(fillerRow, 0);
82
+            assertNotNull(fillerText);
83
+            assertTrue(fillerText.contains("测试用户"), fillerText);
84
+            assertTrue(fillerText.contains(expectedFill), "填表时间应为当月: " + fillerText);
85
+            assertTrue(!fillerText.contains("X月"), fillerText);
86
+            Row titleRow = sheet.getRow(0);
87
+            String title = LivestockProductOutputExcelParser.cellString(titleRow, 0);
88
+            assertTrue(title.contains(exportYear + "年"), title);
89
+            assertTrue(title.contains("(" + exportMonth + "月)"), title);
90
+        }
91
+    }
92
+
65 93
     private static BizLivestockProductOutput sample(String town, String village, String meat, String milk)
66 94
     {
67 95
         BizLivestockProductOutput row = new BizLivestockProductOutput();