Sfoglia il codice sorgente

单独导入修改

wangxx 1 settimana fa
parent
commit
915a873160

+ 164 - 22
airport-admin/src/main/java/com/sundot/airport/web/controller/ledger/LedgerImportController.java

@@ -66,7 +66,14 @@ public class LedgerImportController extends BaseController {
66 66
     public AjaxResult importSupervisionProblem(@RequestParam("file") MultipartFile file) throws Exception {
67 67
         String batchNo = generateBatchNo();
68 68
         ExcelUtil<LedgerSupervisionProblem> util = new ExcelUtil<>(LedgerSupervisionProblem.class);
69
-        List<LedgerSupervisionProblem> list = util.importExcel(file.getInputStream());
69
+        List<LedgerSupervisionProblem> list = util.importExcel(file.getInputStream(), 1);
70
+        // 过滤null元素,避免空指针异常
71
+        if (list != null) {
72
+            list.removeIf(item -> item == null);
73
+        }
74
+        if (list == null || list.isEmpty()) {
75
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
76
+        }
70 77
         list.forEach(item -> {
71 78
             item.setImportBatch(batchNo);
72 79
             item.setSourceType("1");
@@ -82,7 +89,14 @@ public class LedgerImportController extends BaseController {
82 89
     public AjaxResult importPatrolInspection(@RequestParam("file") MultipartFile file) throws Exception {
83 90
         String batchNo = generateBatchNo();
84 91
         ExcelUtil<LedgerPatrolInspection> util = new ExcelUtil<>(LedgerPatrolInspection.class);
85
-        List<LedgerPatrolInspection> list = util.importExcel(file.getInputStream());
92
+        List<LedgerPatrolInspection> list = util.importExcel(file.getInputStream(), 1);
93
+        // 过滤null元素,避免空指针异常
94
+        if (list != null) {
95
+            list.removeIf(item -> item == null);
96
+        }
97
+        if (list == null || list.isEmpty()) {
98
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
99
+        }
86 100
         list.forEach(item -> {
87 101
             item.setImportBatch(batchNo);
88 102
             item.setSourceType("1");
@@ -98,7 +112,14 @@ public class LedgerImportController extends BaseController {
98 112
     public AjaxResult importRealtimeInterception(@RequestParam("file") MultipartFile file) throws Exception {
99 113
         String batchNo = generateBatchNo();
100 114
         ExcelUtil<LedgerRealtimeInterception> util = new ExcelUtil<>(LedgerRealtimeInterception.class);
101
-        List<LedgerRealtimeInterception> list = util.importExcel(file.getInputStream());
115
+        List<LedgerRealtimeInterception> list = util.importExcel(file.getInputStream(), 1);
116
+        // 过滤null元素,避免空指针异常
117
+        if (list != null) {
118
+            list.removeIf(item -> item == null);
119
+        }
120
+        if (list == null || list.isEmpty()) {
121
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
122
+        }
102 123
         list.forEach(item -> {
103 124
             item.setImportBatch(batchNo);
104 125
             item.setSourceType("1");
@@ -114,7 +135,14 @@ public class LedgerImportController extends BaseController {
114 135
     public AjaxResult importServicePatrol(@RequestParam("file") MultipartFile file) throws Exception {
115 136
         String batchNo = generateBatchNo();
116 137
         ExcelUtil<LedgerServicePatrol> util = new ExcelUtil<>(LedgerServicePatrol.class);
117
-        List<LedgerServicePatrol> list = util.importExcel(file.getInputStream());
138
+        List<LedgerServicePatrol> list = util.importExcel(file.getInputStream(), 1);
139
+        // 过滤null元素,避免空指针异常
140
+        if (list != null) {
141
+            list.removeIf(item -> item == null);
142
+        }
143
+        if (list == null || list.isEmpty()) {
144
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
145
+        }
118 146
         list.forEach(item -> {
119 147
             item.setImportBatch(batchNo);
120 148
             item.setSourceType("1");
@@ -130,7 +158,14 @@ public class LedgerImportController extends BaseController {
130 158
     public AjaxResult importComplaint(@RequestParam("file") MultipartFile file) throws Exception {
131 159
         String batchNo = generateBatchNo();
132 160
         ExcelUtil<LedgerComplaint> util = new ExcelUtil<>(LedgerComplaint.class);
133
-        List<LedgerComplaint> list = util.importExcel(file.getInputStream());
161
+        List<LedgerComplaint> list = util.importExcel(file.getInputStream(), 1);
162
+        // 过滤null元素,避免空指针异常
163
+        if (list != null) {
164
+            list.removeIf(item -> item == null);
165
+        }
166
+        if (list == null || list.isEmpty()) {
167
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
168
+        }
134 169
         list.forEach(item -> {
135 170
             item.setImportBatch(batchNo);
136 171
             item.setSourceType("1");
@@ -146,7 +181,14 @@ public class LedgerImportController extends BaseController {
146 181
     public AjaxResult importSecurityTest(@RequestParam("file") MultipartFile file) throws Exception {
147 182
         String batchNo = generateBatchNo();
148 183
         ExcelUtil<LedgerSecurityTest> util = new ExcelUtil<>(LedgerSecurityTest.class);
149
-        List<LedgerSecurityTest> list = util.importExcel(file.getInputStream());
184
+        List<LedgerSecurityTest> list = util.importExcel(file.getInputStream(), 1);
185
+        // 过滤null元素,避免空指针异常
186
+        if (list != null) {
187
+            list.removeIf(item -> item == null);
188
+        }
189
+        if (list == null || list.isEmpty()) {
190
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
191
+        }
150 192
         list.forEach(item -> {
151 193
             item.setImportBatch(batchNo);
152 194
             item.setSourceType("1");
@@ -162,7 +204,14 @@ public class LedgerImportController extends BaseController {
162 204
     public AjaxResult importChannelPassRate(@RequestParam("file") MultipartFile file) throws Exception {
163 205
         String batchNo = generateBatchNo();
164 206
         ExcelUtil<LedgerChannelPassRate> util = new ExcelUtil<>(LedgerChannelPassRate.class);
165
-        List<LedgerChannelPassRate> list = util.importExcel(file.getInputStream());
207
+        List<LedgerChannelPassRate> list = util.importExcel(file.getInputStream(), 1);
208
+        // 过滤null元素,避免空指针异常
209
+        if (list != null) {
210
+            list.removeIf(item -> item == null);
211
+        }
212
+        if (list == null || list.isEmpty()) {
213
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
214
+        }
166 215
         list.forEach(item -> {
167 216
             item.setImportBatch(batchNo);
168 217
             item.setSourceType("1");
@@ -178,7 +227,14 @@ public class LedgerImportController extends BaseController {
178 227
     public AjaxResult importUnsafeEvent(@RequestParam("file") MultipartFile file) throws Exception {
179 228
         String batchNo = generateBatchNo();
180 229
         ExcelUtil<LedgerUnsafeEvent> util = new ExcelUtil<>(LedgerUnsafeEvent.class);
181
-        List<LedgerUnsafeEvent> list = util.importExcel(file.getInputStream());
230
+        List<LedgerUnsafeEvent> list = util.importExcel(file.getInputStream(), 1);
231
+        // 过滤null元素,避免空指针异常
232
+        if (list != null) {
233
+            list.removeIf(item -> item == null);
234
+        }
235
+        if (list == null || list.isEmpty()) {
236
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
237
+        }
182 238
         list.forEach(item -> {
183 239
             item.setImportBatch(batchNo);
184 240
             item.setSourceType("1");
@@ -194,7 +250,14 @@ public class LedgerImportController extends BaseController {
194 250
     public AjaxResult importSeizureStats(@RequestParam("file") MultipartFile file) throws Exception {
195 251
         String batchNo = generateBatchNo();
196 252
         ExcelUtil<LedgerSeizureStats> util = new ExcelUtil<>(LedgerSeizureStats.class);
197
-        List<LedgerSeizureStats> list = util.importExcel(file.getInputStream());
253
+        List<LedgerSeizureStats> list = util.importExcel(file.getInputStream(), 1);
254
+        // 过滤null元素,避免空指针异常
255
+        if (list != null) {
256
+            list.removeIf(item -> item == null);
257
+        }
258
+        if (list == null || list.isEmpty()) {
259
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
260
+        }
198 261
         list.forEach(item -> {
199 262
             item.setImportBatch(batchNo);
200 263
             item.setSourceType("1");
@@ -210,7 +273,17 @@ public class LedgerImportController extends BaseController {
210 273
     public AjaxResult importTerminalBonus(@RequestParam("file") MultipartFile file) throws Exception {
211 274
         String batchNo = generateBatchNo();
212 275
         ExcelUtil<LedgerTerminalBonus> util = new ExcelUtil<>(LedgerTerminalBonus.class);
213
-        List<LedgerTerminalBonus> list = util.importExcel(file.getInputStream());
276
+        // titleNum=1 表示跳过第1行标题,从第2行读取表头
277
+        List<LedgerTerminalBonus> list = util.importExcel(file.getInputStream(), 1);
278
+        
279
+        // 过滤null元素,避免空指针异常
280
+        if (list != null) {
281
+            list.removeIf(item -> item == null);
282
+        }
283
+        if (list == null || list.isEmpty()) {
284
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
285
+        }
286
+        
214 287
         list.forEach(item -> {
215 288
             item.setImportBatch(batchNo);
216 289
             item.setSourceType("1");
@@ -226,7 +299,14 @@ public class LedgerImportController extends BaseController {
226 299
     public AjaxResult importExamScore(@RequestParam("file") MultipartFile file) throws Exception {
227 300
         String batchNo = generateBatchNo();
228 301
         ExcelUtil<LedgerExamScore> util = new ExcelUtil<>(LedgerExamScore.class);
229
-        List<LedgerExamScore> list = util.importExcel(file.getInputStream());
302
+        List<LedgerExamScore> list = util.importExcel(file.getInputStream(), 1);
303
+        // 过滤null元素,避免空指针异常
304
+        if (list != null) {
305
+            list.removeIf(item -> item == null);
306
+        }
307
+        if (list == null || list.isEmpty()) {
308
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
309
+        }
230 310
         list.forEach(item -> {
231 311
             item.setImportBatch(batchNo);
232 312
             item.setSourceType("1");
@@ -241,9 +321,15 @@ public class LedgerImportController extends BaseController {
241 321
     @PostMapping("/rewardApproval")
242 322
     public AjaxResult importRewardApproval(@RequestParam("file") MultipartFile file) throws Exception {
243 323
         String batchNo = generateBatchNo();
244
-        ExcelUtil<LedgerRewardApproval> util =
245
-            new ExcelUtil<>(LedgerRewardApproval.class);
246
-        List<LedgerRewardApproval> list = util.importExcel(file.getInputStream());
324
+        ExcelUtil<LedgerRewardApproval> util = new ExcelUtil<>(LedgerRewardApproval.class);
325
+        List<LedgerRewardApproval> list = util.importExcel(file.getInputStream(), 1);
326
+        // 过滤null元素,避免空指针异常
327
+        if (list != null) {
328
+            list.removeIf(item -> item == null);
329
+        }
330
+        if (list == null || list.isEmpty()) {
331
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
332
+        }
247 333
         list.forEach(item -> {
248 334
             item.setImportBatch(batchNo);
249 335
             item.setSourceType("1");
@@ -259,7 +345,14 @@ public class LedgerImportController extends BaseController {
259 345
     public AjaxResult importDailyTraining(@RequestParam("file") MultipartFile file) throws Exception {
260 346
         String batchNo = generateBatchNo();
261 347
         ExcelUtil<LedgerDailyTraining> util = new ExcelUtil<>(LedgerDailyTraining.class);
262
-        List<LedgerDailyTraining> list = util.importExcel(file.getInputStream());
348
+        List<LedgerDailyTraining> list = util.importExcel(file.getInputStream(), 1);
349
+        // 过滤null元素,避免空指针异常
350
+        if (list != null) {
351
+            list.removeIf(item -> item == null);
352
+        }
353
+        if (list == null || list.isEmpty()) {
354
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
355
+        }
263 356
         list.forEach(item -> { item.setImportBatch(batchNo); item.setSourceType("1"); item.setCreateBy(getUsername()); });
264 357
         dailyTrainingService.batchInsert(list);
265 358
         return AjaxResult.success("导入成功,共" + list.size() + "条");
@@ -271,7 +364,14 @@ public class LedgerImportController extends BaseController {
271 364
     public AjaxResult importLeaderDuty(@RequestParam("file") MultipartFile file) throws Exception {
272 365
         String batchNo = generateBatchNo();
273 366
         ExcelUtil<LedgerLeaderDuty> util = new ExcelUtil<>(LedgerLeaderDuty.class);
274
-        List<LedgerLeaderDuty> list = util.importExcel(file.getInputStream());
367
+        List<LedgerLeaderDuty> list = util.importExcel(file.getInputStream(), 1);
368
+        // 过滤null元素,避免空指针异常
369
+        if (list != null) {
370
+            list.removeIf(item -> item == null);
371
+        }
372
+        if (list == null || list.isEmpty()) {
373
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
374
+        }
275 375
         list.forEach(item -> { item.setImportBatch(batchNo); item.setSourceType("1"); item.setCreateBy(getUsername()); });
276 376
         leaderDutyService.batchInsert(list);
277 377
         return AjaxResult.success("导入成功,共" + list.size() + "条");
@@ -283,7 +383,14 @@ public class LedgerImportController extends BaseController {
283 383
     public AjaxResult importHealthSoldier(@RequestParam("file") MultipartFile file) throws Exception {
284 384
         String batchNo = generateBatchNo();
285 385
         ExcelUtil<LedgerHealthSoldier> util = new ExcelUtil<>(LedgerHealthSoldier.class);
286
-        List<LedgerHealthSoldier> list = util.importExcel(file.getInputStream());
386
+        List<LedgerHealthSoldier> list = util.importExcel(file.getInputStream(), 1);
387
+        // 过滤null元素,避免空指针异常
388
+        if (list != null) {
389
+            list.removeIf(item -> item == null);
390
+        }
391
+        if (list == null || list.isEmpty()) {
392
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
393
+        }
287 394
         list.forEach(item -> { item.setImportBatch(batchNo); item.setSourceType("1"); item.setCreateBy(getUsername()); });
288 395
         healthSoldierService.batchInsert(list);
289 396
         return AjaxResult.success("导入成功,共" + list.size() + "条");
@@ -295,7 +402,14 @@ public class LedgerImportController extends BaseController {
295 402
     public AjaxResult importDormFireSafety(@RequestParam("file") MultipartFile file) throws Exception {
296 403
         String batchNo = generateBatchNo();
297 404
         ExcelUtil<LedgerDormFireSafety> util = new ExcelUtil<>(LedgerDormFireSafety.class);
298
-        List<LedgerDormFireSafety> list = util.importExcel(file.getInputStream());
405
+        List<LedgerDormFireSafety> list = util.importExcel(file.getInputStream(), 1);
406
+        // 过滤null元素,避免空指针异常
407
+        if (list != null) {
408
+            list.removeIf(item -> item == null);
409
+        }
410
+        if (list == null || list.isEmpty()) {
411
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
412
+        }
299 413
         list.forEach(item -> { item.setImportBatch(batchNo); item.setSourceType("1"); item.setCreateBy(getUsername()); });
300 414
         dormFireSafetyService.batchInsert(list);
301 415
         return AjaxResult.success("导入成功,共" + list.size() + "条");
@@ -307,7 +421,14 @@ public class LedgerImportController extends BaseController {
307 421
     public AjaxResult importTrainingIssue(@RequestParam("file") MultipartFile file) throws Exception {
308 422
         String batchNo = generateBatchNo();
309 423
         ExcelUtil<LedgerTrainingIssue> util = new ExcelUtil<>(LedgerTrainingIssue.class);
310
-        List<LedgerTrainingIssue> list = util.importExcel(file.getInputStream());
424
+        List<LedgerTrainingIssue> list = util.importExcel(file.getInputStream(), 1);
425
+        // 过滤null元素,避免空指针异常
426
+        if (list != null) {
427
+            list.removeIf(item -> item == null);
428
+        }
429
+        if (list == null || list.isEmpty()) {
430
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
431
+        }
311 432
         list.forEach(item -> { item.setImportBatch(batchNo); item.setSourceType("1"); item.setCreateBy(getUsername()); });
312 433
         trainingIssueService.batchInsert(list);
313 434
         return AjaxResult.success("导入成功,共" + list.size() + "条");
@@ -323,7 +444,14 @@ public class LedgerImportController extends BaseController {
323 444
     public AjaxResult importRewardPenalty(@RequestParam("file") MultipartFile file) throws Exception {
324 445
         String batchNo = generateBatchNo();
325 446
         ExcelUtil<LedgerRewardPenalty> util = new ExcelUtil<>(LedgerRewardPenalty.class);
326
-        List<LedgerRewardPenalty> list = util.importExcel(file.getInputStream());
447
+        List<LedgerRewardPenalty> list = util.importExcel(file.getInputStream(), 1);
448
+        // 过滤null元素,避免空指针异常
449
+        if (list != null) {
450
+            list.removeIf(item -> item == null);
451
+        }
452
+        if (list == null || list.isEmpty()) {
453
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
454
+        }
327 455
         list.forEach(item -> { item.setImportBatch(batchNo); item.setSourceType("1"); item.setCreateBy(getUsername()); });
328 456
         rewardPenaltyService.batchInsert(list);
329 457
         return AjaxResult.success("导入成功,共" + list.size() + "条");
@@ -339,7 +467,14 @@ public class LedgerImportController extends BaseController {
339 467
     public AjaxResult importLeaveSpecial(@RequestParam("file") MultipartFile file) throws Exception {
340 468
         String batchNo = generateBatchNo();
341 469
         ExcelUtil<LedgerLeaveSpecial> util = new ExcelUtil<>(LedgerLeaveSpecial.class);
342
-        List<LedgerLeaveSpecial> list = util.importExcel(file.getInputStream());
470
+        List<LedgerLeaveSpecial> list = util.importExcel(file.getInputStream(), 1);
471
+        // 过滤null元素,避免空指针异常
472
+        if (list != null) {
473
+            list.removeIf(item -> item == null);
474
+        }
475
+        if (list == null || list.isEmpty()) {
476
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
477
+        }
343 478
         list.forEach(item -> { item.setImportBatch(batchNo); item.setSourceType("1"); item.setCreateBy(getUsername()); });
344 479
         leaveSpecialService.batchInsert(list);
345 480
         return AjaxResult.success("导入成功,共" + list.size() + "条");
@@ -355,7 +490,14 @@ public class LedgerImportController extends BaseController {
355 490
     public AjaxResult importBannerLetter(@RequestParam("file") MultipartFile file) throws Exception {
356 491
         String batchNo = generateBatchNo();
357 492
         ExcelUtil<LedgerBannerLetter> util = new ExcelUtil<>(LedgerBannerLetter.class);
358
-        List<LedgerBannerLetter> list = util.importExcel(file.getInputStream());
493
+        List<LedgerBannerLetter> list = util.importExcel(file.getInputStream(), 1);
494
+        // 过滤null元素,避免空指针异常
495
+        if (list != null) {
496
+            list.removeIf(item -> item == null);
497
+        }
498
+        if (list == null || list.isEmpty()) {
499
+            return AjaxResult.error("导入数据为空或解析失败,请检查Excel表头是否与模板一致");
500
+        }
359 501
         list.forEach(item -> { item.setImportBatch(batchNo); item.setSourceType("1"); item.setCreateBy(getUsername()); });
360 502
         bannerLetterService.batchInsert(list);
361 503
         return AjaxResult.success("导入成功,共" + list.size() + "条");