Просмотр исходного кода

优化导出,优化导入不分层垛位层号为1

dw 1 неделю назад
Родитель
Сommit
52d135bc82

+ 398
- 3
src/main/java/com/th/demo/controller/ware/StoreController.java Просмотреть файл

@@ -5,14 +5,19 @@ import com.th.demo.model.system.Type;
5 5
 import com.th.demo.model.ware.Store;
6 6
 import com.th.demo.service.maint.CustomerService;
7 7
 import com.th.demo.service.ware.StoreService;
8
+import com.th.demo.tools.DateTools;
9
+import com.th.demo.tools.ExportExcelTools;
8 10
 import com.th.demo.tools.JSONTools;
11
+import com.th.demo.tools.Tools;
9 12
 import org.springframework.beans.factory.annotation.Autowired;
10 13
 import org.springframework.web.bind.annotation.RequestMapping;
11 14
 import org.springframework.web.bind.annotation.RestController;
12 15
 
13 16
 import javax.servlet.http.HttpServletRequest;
14
-import java.util.Arrays;
15
-import java.util.List;
17
+import javax.servlet.http.HttpServletResponse;
18
+import java.io.*;
19
+import java.text.SimpleDateFormat;
20
+import java.util.*;
16 21
 
17 22
 @RestController
18 23
 @RequestMapping(value = "/WareStore")
@@ -21,7 +26,6 @@ public class StoreController {
21 26
     public StoreService storeService;
22 27
     String result = Type.FAIL;
23 28
 
24
-
25 29
     @RequestMapping(value = "/query.do")//查询方法 前两个参数是分页参数
26 30
     public String query(
27 31
             int page,
@@ -220,4 +224,395 @@ public class StoreController {
220 224
             return result;
221 225
         }
222 226
     }
227
+
228
+    /**
229
+     * 导出入库记录Excel - 分批查询流式导出,解决大数据量内存溢出问题
230
+     */
231
+    @RequestMapping(value = "/inExportStoreExcel.do")
232
+    public void inExportStoreExcel(
233
+            int page, int rows,
234
+            String wareName,
235
+            String stackName,
236
+            String model,
237
+            String materialName,
238
+            String standard,
239
+            String customerName,
240
+            String plateNo,
241
+            String fromDate,
242
+            String toDate,
243
+            String ordNo,
244
+            String carNo,
245
+            String tallyPeople,
246
+            String fkComponyName,
247
+            String remark1,
248
+            String contractNo,
249
+            String userId,
250
+            String belongId,
251
+            HttpServletRequest request,
252
+            HttpServletResponse response) {
253
+        try {
254
+
255
+            Date fromDate2 = DateTools.StrToDate(fromDate, "yyyy-MM-dd HH:mm:ss");
256
+            Date toDate2 = DateTools.StrToDate(toDate, "yyyy-MM-dd HH:mm:ss");
257
+
258
+            // 设置表头
259
+            String[] headers = {"仓库名称"
260
+                    ,"垛位"
261
+                    ,"层号"
262
+                    ,"品名"
263
+                    ,"订单号"
264
+                    ,"规格"
265
+                    ,"钢种"
266
+                    ,"入库数量"
267
+                    ,"入库重量"
268
+                    ,"钢板号"
269
+                    ,"订货单位"
270
+                    ,"客户单位"
271
+                    ,"收货地址"
272
+                    ,"计量方式"
273
+                    ,"切边类型"
274
+                    ,"产地"
275
+                    ,"入库车号"
276
+                    ,"入库理货人员"
277
+                    ,"入库操作人"
278
+                    ,"入库时间"
279
+                    ,"垛位备注"
280
+                    ,"类型"
281
+                    ,"备注"
282
+                    ,"合约号"};
283
+
284
+            // 设置字段名
285
+            String[] columns = {"wareName"
286
+                    ,"stackName"
287
+                    ,"layer"
288
+                    ,"materialName"
289
+                    ,"ordNo"
290
+                    ,"model"
291
+                    ,"standard"
292
+                    ,"count"
293
+                    ,"weight"
294
+                    ,"plateNo"
295
+                    ,"customerName"
296
+                    ,"fkComponyName"
297
+                    ,"receiveAddress"
298
+                    ,"wgtDcnMtcCd"
299
+                    ,"edgeTy"
300
+                    ,"productionPlace"
301
+                    ,"carNo"
302
+                    ,"tallyPeople"
303
+                    ,"addUserUserDesc"
304
+                    ,"addTime"
305
+                    ,"remark1"
306
+                    ,"recordType"
307
+                    ,"remark"
308
+                    ,"contractNo"};
309
+
310
+            // 设置列宽
311
+            int[] arrWidth = {
312
+                    50, 30, 50, 50, 50, 50, 50,
313
+                    30, 30, 50, 50, 80, 40, 40,
314
+                    50, 50, 60, 50, 50, 50,
315
+                    30, 30, 40, 40
316
+            };
317
+
318
+            // 生成文件名
319
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
320
+            String filename = "入库库记录_" + sdf.format(new Date()) + ".xlsx";
321
+
322
+            // 分批查询,每批5000条
323
+            final int batchSize = 5000;
324
+            int offset = 0;
325
+
326
+            // 使用try-with-resources自动关闭流
327
+            try (OutputStream out = Tools.getExportOutStream(filename, response)) {
328
+                // 创建流式工作簿
329
+                ExportExcelTools<List<Map<String, Object>>> exportExcel = new ExportExcelTools<>();
330
+                
331
+                // 写入表头
332
+                exportExcel.writeHeaders("入库记录", headers, columns, arrWidth, out, "yyyy/MM/dd HH:mm:ss");
333
+                
334
+                // 分批查询并写入
335
+                while (true) {
336
+                    List<Map<String, Object>> batchData = storeService.exportStoreExcelBatch(
337
+                            page, rows, wareName, stackName, model, materialName, standard, customerName,
338
+                            plateNo, fromDate2, toDate2, userId, belongId, ordNo, carNo, tallyPeople, 
339
+                            fkComponyName, remark1, contractNo, offset, batchSize);
340
+                    
341
+                    if (batchData == null || batchData.isEmpty()) {
342
+                        break;
343
+                    }
344
+                    
345
+                    // 写入数据
346
+                    exportExcel.appendData(columns, batchData, "yyyy/MM/dd HH:mm:ss");
347
+                    
348
+                    // 如果数据少于批次大小,说明是最后一批
349
+                    if (batchData.size() < batchSize) {
350
+                        break;
351
+                    }
352
+                    
353
+                    offset += batchSize;
354
+                    
355
+                    // 手动触发GC回收内存
356
+                    System.gc();
357
+                }
358
+                
359
+                // 完成写入
360
+                exportExcel.finishWrite(out);
361
+                out.flush();
362
+            } catch (Exception e) {
363
+                e.printStackTrace();
364
+                response.reset();
365
+                response.setContentType("text/html;charset=utf-8");
366
+                response.getWriter().write("导出失败:" + e.getMessage());
367
+            }
368
+
369
+        } catch (Exception e) {
370
+            e.printStackTrace();
371
+        }
372
+    }
373
+
374
+    /**
375
+     * 导出出库记录Excel - 分批查询流式导出,解决大数据量内存溢出问题
376
+     */
377
+    @RequestMapping(value = "/outExportStoreExcel.do")
378
+    public void outExportStoreExcel(
379
+            int page,int rows,  String wareName,
380
+            String stackName,
381
+            String model,
382
+            String materialName,
383
+            String standard,
384
+            String customerName,
385
+            String plateNo,
386
+            String pFromDate,
387
+            String pToDate,
388
+            String carNo,
389
+            String tallyPeople,
390
+            String ordNo,
391
+            String fkComponyName,
392
+            String remark1,
393
+            String contractNo,
394
+            String userId,
395
+            String belongId,
396
+            HttpServletRequest request,
397
+            HttpServletResponse response) {
398
+        try {
399
+            // 设置超时时间,单位毫秒(10分钟)
400
+            response.setHeader("timeout", "600000");
401
+
402
+            Date fromDate = DateTools.StrToDate(pFromDate, "yyyy-MM-dd HH:mm:ss");
403
+            Date toDate = DateTools.StrToDate(pToDate, "yyyy-MM-dd HH:mm:ss");
404
+
405
+            // 设置表头
406
+            String[] headers = {"仓库名称"
407
+                    ,"垛位"
408
+                    ,"层号"
409
+                    ,"品名"
410
+                    ,"订单号"
411
+                    ,"入库人"
412
+                    ,"入库车号"
413
+                    ,"入库时间"
414
+                    ,"规格"
415
+                    ,"钢种"
416
+                    ,"出库数量"
417
+                    ,"出库重量"
418
+                    ,"钢板号"
419
+                    ,"订单客户"
420
+                    ,"客户单位"
421
+                    ,"收货地址"
422
+                    ,"计量方式"
423
+                    ,"切边类型"
424
+                    ,"产地"
425
+                    ,"出库车号"
426
+                    ,"出库理货人员"
427
+                    ,"出库操作人"
428
+                    ,"出库时间"
429
+                    ,"备注"
430
+                    ,"垛位备注"
431
+                    ,"类型"
432
+                    ,"合约号"};
433
+
434
+            // 设置字段名
435
+            String[] columns = {"wareName"
436
+                    ,"stackName"
437
+                    ,"layer"
438
+                    ,"materialName"
439
+                    ,"ordNo"
440
+                    ,"inUser"
441
+                    ,"inCarNo"
442
+                    ,"inTime"
443
+                    ,"model"
444
+                    ,"standard"
445
+                    ,"count"
446
+                    ,"weight"
447
+                    ,"plateNo"
448
+                    ,"customerName"
449
+                    ,"fkComponyName"
450
+                    ,"receiveAddress"
451
+                    ,"wgtDcnMtcCd"
452
+                    ,"edgeTy"
453
+                    ,"productionPlace"
454
+                    ,"outCarNo"
455
+                    ,"tallyPeople"
456
+                    ,"addId"
457
+                    ,"addTime"
458
+                    ,"remark"
459
+                    ,"remark1"
460
+                    ,"recordType"
461
+                    ,"contractNo"};
462
+
463
+            // 设置列宽
464
+            int[] arrWidth = {
465
+                    50, 30, 50, 50, 50, 50, 50,
466
+                    30, 30, 50, 50, 80, 40, 40,
467
+                    50, 50, 60, 50, 50, 50,
468
+                    50, 50, 50, 50, 50, 50, 50
469
+            };
470
+
471
+            // 生成文件名
472
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
473
+            String filename = "出库记录_" + sdf.format(new Date()) + ".xlsx";
474
+
475
+            // 分批查询,每批5000条
476
+            final int batchSize = 5000;
477
+            int offset = 0;
478
+
479
+            // 使用try-with-resources自动关闭流
480
+            try (OutputStream out = Tools.getExportOutStream(filename, response)) {
481
+                // 创建流式工作簿
482
+                ExportExcelTools<List<Map<String, Object>>> exportExcel = new ExportExcelTools<>();
483
+
484
+                // 写入表头
485
+                exportExcel.writeHeaders("出库记录", headers, columns, arrWidth, out, "yyyy/MM/dd HH:mm:ss");
486
+
487
+                // 分批查询并写入
488
+                while (true) {
489
+                    List<Map<String, Object>> batchData = storeService.outExportStoreExcelBatch(
490
+                            page, rows, wareName, stackName, model, materialName, standard, customerName,
491
+                            plateNo, carNo, tallyPeople, ordNo, fkComponyName, remark1, contractNo, fromDate, toDate, userId, belongId,
492
+                            offset, batchSize);
493
+
494
+                    if (batchData == null || batchData.isEmpty()) {
495
+                        break;
496
+                    }
497
+
498
+                    // 写入数据
499
+                    exportExcel.appendData(columns, batchData, "yyyy/MM/dd HH:mm:ss");
500
+
501
+                    // 如果数据少于批次大小,说明是最后一批
502
+                    if (batchData.size() < batchSize) {
503
+                        break;
504
+                    }
505
+
506
+                    offset += batchSize;
507
+
508
+                    // 手动触发GC回收内存
509
+                    System.gc();
510
+                }
511
+
512
+                // 完成写入
513
+                exportExcel.finishWrite(out);
514
+                out.flush();
515
+            } catch (Exception e) {
516
+                e.printStackTrace();
517
+            }
518
+
519
+        } catch (Exception e) {
520
+            e.printStackTrace();
521
+        }
522
+    }
523
+
524
+    /**
525
+     * 导库存Excel - 使用StoreMapper查询,分批流式导出
526
+     */
527
+    @RequestMapping(value = "/exportStoreExcel.do")
528
+    public void exportStoreExcel(
529
+            int page, int rows,
530
+            String wareName,
531
+            String stackName,
532
+            String model,
533
+            String materialName,
534
+            String standard,
535
+            String customerName,
536
+            String plateNo,
537
+            String ordNo,
538
+            String remark1,
539
+            String fkcustmerName,
540
+            String userId,
541
+            String belongId,
542
+            HttpServletRequest request,
543
+            HttpServletResponse response) {
544
+        try {
545
+            // 设置超时时间,单位毫秒(10分钟)
546
+            response.setHeader("timeout", "600000");
547
+
548
+            // 获取导出数据
549
+            List<Map<String, Object>> dataList = storeService.exportStoreForExcel(
550
+                    wareName, stackName, model, materialName, standard, customerName,
551
+                    plateNo, ordNo, remark1, fkcustmerName, userId, belongId, 0, -1);
552
+
553
+            // 设置表头
554
+            String[] headers = {"层数"
555
+                    ,"垛位"
556
+                    ,"货物品名"
557
+                    ,"材质"
558
+                    ,"钢板号"
559
+                    ,"规格型号"
560
+                    ,"数量"
561
+                    ,"重量"
562
+                    ,"订单号"
563
+                    ,"合约号"
564
+                    ,"订单客户"
565
+                    ,"客户名称"
566
+                    ,"收货地址"
567
+                    ,"产地"
568
+                    ,"备注"
569
+                    ,"垛位备注"
570
+                    ,"入库时间"
571
+                    ,"入库车号"};
572
+
573
+            // 设置字段名
574
+            String[] columns = {"layer"
575
+                    ,"stackName"
576
+                    ,"materialName"
577
+                    ,"materialStandard"
578
+                    ,"plateNo"
579
+                    ,"model"
580
+                    ,"count"
581
+                    ,"weight"
582
+                    ,"ordNo"
583
+                    ,"contractNo"
584
+                    ,"customerName"
585
+                    ,"fkComponyName"
586
+                    ,"receiveAddress"
587
+                    ,"productionPlace"
588
+                    ,"remark"
589
+                    ,"remark1"
590
+                    ,"addTime"
591
+                    ,"carNo"};
592
+
593
+            // 设置列宽
594
+            int[] arrWidth = {
595
+                    30, 30, 50, 50, 50, 50,
596
+                    30, 30, 50, 50, 50, 50,
597
+                    80, 50, 50, 50, 50, 50
598
+            };
599
+
600
+            // 生成文件名
601
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
602
+            String filename = "库存记录_" + sdf.format(new Date()) + ".xlsx";
603
+
604
+            // 使用try-with-resources自动关闭流
605
+            try (OutputStream out = Tools.getExportOutStream(filename, response)) {
606
+                ExportExcelTools<List<Map<String, Object>>> exportExcel = new ExportExcelTools<>();
607
+                // 导出Excel
608
+                exportExcel.exportXSExcelByColumn("库存记录", headers, columns, arrWidth, dataList, out, "yyyy/MM/dd HH:mm:ss");
609
+                out.flush(); // 强制刷缓冲区
610
+            } catch (Exception e) {
611
+                e.printStackTrace();
612
+            }
613
+
614
+        } catch (Exception e) {
615
+            e.printStackTrace();
616
+        }
617
+    }
223 618
 }

+ 7
- 0
src/main/java/com/th/demo/mapping/ware/InRecordMapper.java Просмотреть файл

@@ -27,6 +27,13 @@ public interface InRecordMapper {
27 27
                           Date toDate, String userId, String belongId, String ordNo, String carNo, String tallyPeople, String fkComponyName
28 28
                             ,List<String> plateNos,List<String> ordNos,String remark1,String contractNo,List<String> contractNos);
29 29
 
30
+    //分页查询导出数据(不含关联用户信息,减少内存占用)
31
+    List<InRecord> selectForExport(String wareName, String stackName, String layer, String materialName, String standard, String customerName,
32
+                          String plateNo, Date fromDate,
33
+                          Date toDate, String userId, String belongId, String ordNo, String carNo, String tallyPeople, String fkComponyName
34
+                            ,List<String> plateNos,List<String> ordNos,String remark1,String contractNo,List<String> contractNos,
35
+                            int offset, int limit);
36
+
30 37
     int updateIn(InRecord inRecord);
31 38
 
32 39
     List<TrackRecord> selectTrackRecord(String plateNo, String userId, String belongId);

+ 6
- 0
src/main/java/com/th/demo/mapping/ware/OutRecordMapper.java Просмотреть файл

@@ -27,6 +27,12 @@ public interface OutRecordMapper {
27 27
                                 String plateNo, Date fromDate, Date toDate, String userId, String belongId, String carNo, String tallyPeople,
28 28
                                 String ordNo, String fkComponyName, List<String> plateNos, List<String> ordNos, String remark1,String contractNo,List<String> contractNos);
29 29
 
30
+    //分页查询导出(不含关联用户信息,减少内存占用)
31
+    List<OutRecord> selectForExport(String wareName, String stackName, String layer, String materialName, String standard, String customerName,
32
+                                String plateNo, Date fromDate, Date toDate, String userId, String belongId, String carNo, String tallyPeople,
33
+                                String ordNo, String fkComponyName, List<String> plateNos, List<String> ordNos, String remark1, String contractNo, List<String> contractNos,
34
+                                int offset, int limit);
35
+
30 36
     List<TotalRecord>  selectTotal(String wareName, String stackName, String layer, String materialName, String standard, String customerName,
31 37
                                    String plateNo, Date fromDate, Date toDate, String userId, String belongId, String carNo,
32 38
                                    String tallyPeople, String ordNo, String fkComponyName,List<String> plateNos,List<String> ordNos,String remark1);

+ 8
- 0
src/main/java/com/th/demo/mapping/ware/StoreMapper.java Просмотреть файл

@@ -76,4 +76,12 @@ public interface StoreMapper {
76 76
      * 根据垛位id查询当前垛位下是否存在未出库钢板
77 77
      */
78 78
     List<String> queryStoreById(@Param("stackId") String stackId);
79
+
80
+    /**
81
+     * 库存导出查询(支持分页偏移,直接返回Map)
82
+     */
83
+    List<Map<String, Object>> selectStoreForExport(String wareName, String stackName, String model, String materialName, String standard,
84
+                            String customerName, String plateNo, String orderNo, List<String> plateNos, List<String> ordNos,
85
+                            String userId, String belongId, String remark1, String fkcustmerName,
86
+                            int offset, int limit);
79 87
 }

+ 1
- 1
src/main/java/com/th/demo/service/impl/ware/InServiceImpl.java Просмотреть файл

@@ -228,7 +228,7 @@ public class InServiceImpl implements InService {
228 228
             if (stack.getIsLayer().equals("1")) {
229 229
                 listSameStack.get(m).setLayer(currentLayer + m + 1);
230 230
             } else {
231
-                listSameStack.get(m).setLayer(0);
231
+                listSameStack.get(m).setLayer(1);
232 232
             }
233 233
             listSameStack.get(m).setAddId(userId);
234 234
             listSameStack.get(m).setAddTime(new Date());

+ 300
- 11
src/main/java/com/th/demo/service/impl/ware/StoreServiceImpl.java Просмотреть файл

@@ -6,17 +6,12 @@ import com.github.pagehelper.PageHelper;
6 6
 import com.github.pagehelper.PageInfo;
7 7
 import com.th.demo.mapping.maint.CustomerMapper;
8 8
 import com.th.demo.mapping.maint.StackMapper;
9
-import com.th.demo.mapping.ware.ChangeRecordMapper;
10
-import com.th.demo.mapping.ware.MoveRecordMapper;
11
-import com.th.demo.mapping.ware.StoreMapper;
9
+import com.th.demo.mapping.ware.*;
12 10
 import com.th.demo.model.maint.Customer;
13 11
 import com.th.demo.model.maint.Stack;
14 12
 import com.th.demo.model.system.SysUser;
15 13
 import com.th.demo.model.system.Type;
16
-import com.th.demo.model.ware.ChangeRecord;
17
-import com.th.demo.model.ware.MoveRecord;
18
-import com.th.demo.model.ware.SplitRecord;
19
-import com.th.demo.model.ware.Store;
14
+import com.th.demo.model.ware.*;
20 15
 import com.th.demo.service.maint.CustomerService;
21 16
 import com.th.demo.service.ware.MoveService;
22 17
 import com.th.demo.service.ware.StoreService;
@@ -26,10 +21,7 @@ import org.springframework.beans.factory.annotation.Autowired;
26 21
 import org.springframework.stereotype.Service;
27 22
 
28 23
 import java.text.SimpleDateFormat;
29
-import java.util.ArrayList;
30
-import java.util.Arrays;
31
-import java.util.Date;
32
-import java.util.List;
24
+import java.util.*;
33 25
 
34 26
 @Service("StoreService")
35 27
 public class StoreServiceImpl implements StoreService {
@@ -44,6 +36,10 @@ public class StoreServiceImpl implements StoreService {
44 36
     public MoveRecordMapper moveRecordMapper;
45 37
     @Autowired//自动注入Mapper
46 38
     public CustomerMapper customerMapper;
39
+    @Autowired
40
+    public InRecordMapper inRecordMapper;
41
+    @Autowired
42
+    public OutRecordMapper outRecordMapper;
47 43
     String result = Type.FAIL;
48 44
     int num = 0;
49 45
 
@@ -386,5 +382,298 @@ public class StoreServiceImpl implements StoreService {
386 382
 //        修改入库表收货地址
387 383
         int i1 = storeMapper.updateInAddressById(inId, newCustomerAddress);
388 384
         return result;
385
+      }
386
+
387
+    /**
388
+     * 导出库存Excel
389
+     */
390
+    @Override
391
+    public List<Map<String, Object>> exportStoreExcel(int page, int rows,
392
+                                                     String wareName, String stackName, String model, String materialName, String standard, String customerName,
393
+                                                     String plateNo, Date fromDate, Date toDate, String userId, String belongId,
394
+                                                     String ordNo, String carNo, String tallyPeople, String fkComponyName,String remark1,String contractNo) {
395
+
396
+        // 调用分批查询方法
397
+        return exportStoreExcelBatch(page, rows, wareName, stackName, model, materialName, standard, customerName,
398
+                plateNo, fromDate, toDate, userId, belongId, ordNo, carNo, tallyPeople, fkComponyName, remark1, contractNo, 0, -1);
399
+    }
400
+
401
+    /**
402
+     * 分批导出库存Excel(解决大数据量内存溢出问题)
403
+     */
404
+    @Override
405
+    public List<Map<String, Object>> exportStoreExcelBatch(int page, int rows,
406
+                                                     String wareName, String stackName, String model, String materialName, String standard, String customerName,
407
+                                                     String plateNo, Date fromDate, Date toDate, String userId, String belongId,
408
+                                                     String ordNo, String carNo, String tallyPeople, String fkComponyName,String remark1,String contractNo,
409
+                                                     int offset, int limit) {
410
+
411
+        // ========== 1. 所有字符串入参统一把 null 转为空串 ==========
412
+        wareName = wareName == null ? "" : wareName;
413
+        stackName = stackName == null ? "" : stackName;
414
+        model = model == null ? "" : model;
415
+        materialName = materialName == null ? "" : materialName;
416
+        standard = standard == null ? "" : standard;
417
+        customerName = customerName == null ? "" : customerName;
418
+        plateNo = plateNo == null ? "" : plateNo;
419
+        userId = userId == null ? "" : userId;
420
+        belongId = belongId == null ? "" : belongId;
421
+        ordNo = ordNo == null ? "" : ordNo;
422
+        carNo = carNo == null ? "" : carNo;
423
+        tallyPeople = tallyPeople == null ? "" : tallyPeople;
424
+        fkComponyName = fkComponyName == null ? "" : fkComponyName;
425
+        remark1 = remark1 == null ? "" : remark1;
426
+        contractNo = contractNo == null ? "" : contractNo;
427
+
428
+        List<String> pltNos = new ArrayList<>();
429
+        List<String> ordNos = new ArrayList<>();
430
+        List<String> contractNos =new ArrayList<>() ;
431
+
432
+        // 现在plateNo一定不为null,直接判断逗号
433
+        if (plateNo.contains(",")) {
434
+            pltNos = Arrays.asList(plateNo.split(","));
435
+        }
436
+        if (contractNo.contains(",")){
437
+            contractNos = Arrays.asList(contractNo.split(","));
438
+        }
439
+        if (ordNo.contains(",")) {
440
+            ordNos = Arrays.asList(ordNo.split(","));
441
+        }
442
+
443
+        List<InRecord> storeList;
444
+        // 如果 limit <= 0,使用原来的全量查询
445
+        if (limit <= 0) {
446
+            storeList = inRecordMapper.select(
447
+                    wareName, stackName, model, materialName, standard, customerName,
448
+                    plateNo, fromDate, toDate, userId, belongId, ordNo, carNo,
449
+                    tallyPeople, fkComponyName, pltNos, ordNos, remark1, contractNo, contractNos);
450
+        } else {
451
+            // 分批查询
452
+            storeList = inRecordMapper.selectForExport(
453
+                    wareName, stackName, model, materialName, standard, customerName,
454
+                    plateNo, fromDate, toDate, userId, belongId, ordNo, carNo,
455
+                    tallyPeople, fkComponyName, pltNos, ordNos, remark1, contractNo, contractNos,
456
+                    limit, offset);
457
+        }
458
+
459
+        List<Map<String, Object>> resultList = new ArrayList<>();
460
+        for (InRecord store : storeList) {
461
+            Map<String, Object> map = new LinkedHashMap<>();
462
+            // 仓库名称
463
+            map.put("wareName", store.getWareName() != null ? store.getWareName() : "");
464
+            // 垛位
465
+            map.put("stackName", store.getStackName() != null ? store.getStackName() : "");
466
+            // 层号
467
+            map.put("layer", store.getLayer() != null ? store.getLayer() : "");
468
+            // 品名
469
+            map.put("materialName", store.getMaterialName() != null ? store.getMaterialName() : "");
470
+            // 订单号
471
+            map.put("ordNo", store.getOrdNo() != null ? store.getOrdNo() : "");
472
+            // 规格型号
473
+            map.put("model", store.getModel() != null ? store.getModel() : "");
474
+            // 钢种
475
+            map.put("standard", store.getStandard() != null ? store.getStandard() : "");
476
+            // 数量
477
+            map.put("count", store.getCount() != null ? store.getCount() : "");
478
+            // 重量
479
+            map.put("weight", store.getWeight() != null ? store.getWeight() : "");
480
+            // 钢板号
481
+            map.put("plateNo", store.getPlateNo() != null ? store.getPlateNo() : "");
482
+            // 客户
483
+            map.put("customerName", store.getCustomerName() != null ? store.getCustomerName() : "");
484
+            // 货权单位
485
+            map.put("fkComponyName", store.getFkComponyName() != null ? store.getFkComponyName() : "");
486
+            // 收货地址
487
+            map.put("receiveAddress", store.getReceiveAddress() != null ? store.getReceiveAddress() : "");
488
+            // 计量方式
489
+            map.put("wgtDcnMtcCd", store.getWgtDcnMtcCd() != null ? store.getWgtDcnMtcCd() : "");
490
+            // 切边类型
491
+            map.put("edgeTy", store.getEdgeTy() != null ? store.getEdgeTy() : "");
492
+            // 产地
493
+            map.put("productionPlace", store.getProductionPlace() != null ? store.getProductionPlace() : "");
494
+            // 入库车号
495
+            map.put("carNo", store.getCarNo() != null ? store.getCarNo() : "");
496
+            // 入库理货人员
497
+            map.put("tallyPeople", store.getTallyPeople() != null ? store.getTallyPeople() : "");
498
+
499
+            // ========== 修复空指针核心:addUser判空 ==========
500
+            String addUserDesc = "";
501
+            if(store.getAddUser() != null){
502
+                addUserDesc = store.getAddUser().getUserDesc() != null ? store.getAddUser().getUserDesc() : "";
503
+            }
504
+            map.put("addUserUserDesc", addUserDesc);
505
+
506
+            // 入库时间
507
+            map.put("addTime", store.getAddTime() != null ? store.getAddTime() : "");
508
+            // 垛位备注
509
+            map.put("remark1", store.getRemark1() != null ? store.getRemark1() : "");
510
+            // 类型
511
+            map.put("recordType", store.getRecordType() != null ? store.getRecordType() : "");
512
+            // 备注
513
+            map.put("remark", store.getRemark() != null ? store.getRemark() : "");
514
+            // 合约号
515
+            map.put("contractNo", store.getContractNo() != null ? store.getContractNo() : "");
516
+
517
+            resultList.add(map);
518
+        }
519
+        return resultList;
520
+    }
521
+
522
+    /**
523
+     * 导出出库Excel
524
+     */
525
+    public List<Map<String, Object>> outExportStoreExcel(int page, int rows,
526
+                                                         String wareName, String stackName, String model, String materialName, String standard,
527
+                                                         String customerName, String plateNo, String carNo, String tallyPeople, String ordNo,
528
+                                                         String fkComponyName, String remark1, String contractNo, Date fromDate, Date toDate, String userId, String belongId) {
529
+        // 调用分批查询方法
530
+        return outExportStoreExcelBatch(page, rows, wareName, stackName, model, materialName, standard,
531
+                customerName, plateNo, carNo, tallyPeople, ordNo, fkComponyName, remark1, contractNo, fromDate, toDate, userId, belongId, 0, -1);
532
+    }
533
+
534
+    /**
535
+     * 分批导出出库Excel(解决大数据量内存溢出问题)
536
+     */
537
+    public List<Map<String, Object>> outExportStoreExcelBatch(int page, int rows,
538
+                                                         String wareName, String stackName, String model, String materialName, String standard,
539
+                                                         String customerName, String plateNo, String carNo, String tallyPeople, String ordNo,
540
+                                                         String fkComponyName, String remark1, String contractNo, Date fromDate, Date toDate, String userId, String belongId,
541
+                                                         int offset, int limit) {
542
+        // 入参空值处理
543
+        wareName = wareName == null ? "" : wareName;
544
+        stackName = stackName == null ? "" : stackName;
545
+        model = model == null ? "" : model;
546
+        materialName = materialName == null ? "" : materialName;
547
+        standard = standard == null ? "" : standard;
548
+        customerName = customerName == null ? "" : customerName;
549
+        plateNo = plateNo == null ? "" : plateNo;
550
+        carNo = carNo == null ? "" : carNo;
551
+        tallyPeople = tallyPeople == null ? "" : tallyPeople;
552
+        ordNo = ordNo == null ? "" : ordNo;
553
+        fkComponyName = fkComponyName == null ? "" : fkComponyName;
554
+        remark1 = remark1 == null ? "" : remark1;
555
+        contractNo = contractNo == null ? "" : contractNo;
556
+
557
+        List<String> pltNos =new ArrayList<>() ;
558
+        List<String> ordNos =new ArrayList<>() ;
559
+        List<String> contractNos =new ArrayList<>() ;
560
+        if (plateNo.indexOf(",") != -1){
561
+            pltNos = Arrays.asList(plateNo.split(","));
562
+        }
563
+        if (contractNo.indexOf(",") != -1){
564
+            contractNos = Arrays.asList(contractNo.split(","));
565
+        }
566
+        if (ordNo.indexOf(",") != -1){
567
+            ordNos = Arrays.asList(ordNo.split(","));
568
+        }
569
+
570
+        List<OutRecord> list;
571
+        // 如果 limit <= 0,使用原来的全量查询
572
+        if (limit <= 0) {
573
+            list = outRecordMapper.selectExpt(wareName, stackName, model, materialName, standard, customerName,
574
+                    plateNo, fromDate, toDate, userId, belongId, carNo, tallyPeople, ordNo, fkComponyName, pltNos, ordNos, remark1, contractNo, contractNos);
575
+        } else {
576
+            // 分批查询
577
+            list = outRecordMapper.selectForExport(wareName, stackName, model, materialName, standard, customerName,
578
+                    plateNo, fromDate, toDate, userId, belongId, carNo, tallyPeople, ordNo, fkComponyName, pltNos, ordNos, remark1, contractNo, contractNos,
579
+                    limit, offset);
580
+        }
581
+
582
+        List<Map<String, Object>> resultList = new ArrayList<>();
583
+        for (OutRecord record : list) {
584
+            Map<String, Object> map = new LinkedHashMap<>();
585
+            // 仓库名称
586
+            map.put("wareName", record.getWareName() != null ? record.getWareName() : "");
587
+            // 垛位
588
+            map.put("stackName", record.getStackName() != null ? record.getStackName() : "");
589
+            // 层号
590
+            map.put("layer", record.getLayer() != null ? record.getLayer() : "");
591
+            // 品名
592
+            map.put("materialName", record.getMaterialName() != null ? record.getMaterialName() : "");
593
+            // 订单号
594
+            map.put("ordNo", record.getOrdNo() != null ? record.getOrdNo() : "");
595
+            // 入库人
596
+            map.put("inUser", record.getInUser() != null ? record.getInUser() : "");
597
+            // 入库车号
598
+            map.put("inCarNo", record.getInCarNo() != null ? record.getInCarNo() : "");
599
+            // 入库时间
600
+            map.put("inTime", record.getInTime() != null ? record.getInTime() : "");
601
+            // 规格型号
602
+            map.put("model", record.getModel() != null ? record.getModel() : "");
603
+            // 钢种/规格
604
+            map.put("standard", record.getStandard() != null ? record.getStandard() : "");
605
+            // 出库数量
606
+            map.put("count", record.getCount() != null ? record.getCount() : "");
607
+            // 出库重量
608
+            map.put("weight", record.getWeight() != null ? record.getWeight() : "");
609
+            // 钢板号
610
+            map.put("plateNo", record.getPlateNo() != null ? record.getPlateNo() : "");
611
+            // 订单客户
612
+            map.put("customerName", record.getCustomerName() != null ? record.getCustomerName() : "");
613
+            // 客户单位
614
+            map.put("fkComponyName", record.getFkComponyName() != null ? record.getFkComponyName() : "");
615
+            // 收货地址
616
+            map.put("receiveAddress", record.getReceiveAddress() != null ? record.getReceiveAddress() : "");
617
+            // 计量方式
618
+            map.put("wgtDcnMtcCd", record.getWgtDcnMtcCd() != null ? record.getWgtDcnMtcCd() : "");
619
+            // 切边类型
620
+            map.put("edgeTy", record.getEdgeTy() != null ? record.getEdgeTy() : "");
621
+            // 产地
622
+            map.put("productionPlace", record.getProductionPlace() != null ? record.getProductionPlace() : "");
623
+            // 出库车号
624
+            map.put("outCarNo", record.getOutCarNo() != null ? record.getOutCarNo() : "");
625
+            // 出库理货人员
626
+            map.put("tallyPeople", record.getTallyPeople() != null ? record.getTallyPeople() : "");
627
+            // 出库操作人
628
+            map.put("addId", record.getAddId() != null ? record.getAddId() : "");
629
+            // 出库时间
630
+            map.put("addTime", record.getAddTime() != null ? record.getAddTime() : "");
631
+            // 备注
632
+            map.put("remark", record.getRemark() != null ? record.getRemark() : "");
633
+            // 垛位备注
634
+            map.put("remark1", record.getRemark1() != null ? record.getRemark1() : "");
635
+            // 类型
636
+            map.put("recordType", record.getRecordType() != null ? record.getRecordType() : "");
637
+            // 合约号
638
+            map.put("contractNo", record.getContractNo() != null ? record.getContractNo() : "");
639
+            resultList.add(map);
640
+        }
641
+        return resultList;
389 642
     }
643
+
644
+    /**
645
+     * 导出库存Excel(使用StoreMapper查询,与入库/出库导出独立)
646
+     */
647
+    @Override
648
+    public List<Map<String, Object>> exportStoreForExcel(String wareName, String stackName, String model, String materialName, String standard,
649
+                                                         String customerName, String plateNo, String ordNo, String remark1, String fkcustmerName,
650
+                                                         String userId, String belongId, int offset, int limit) {
651
+        // 空值处理
652
+        wareName = wareName == null ? "" : wareName;
653
+        stackName = stackName == null ? "" : stackName;
654
+        model = model == null ? "" : model;
655
+        materialName = materialName == null ? "" : materialName;
656
+        standard = standard == null ? "" : standard;
657
+        customerName = customerName == null ? "" : customerName;
658
+        plateNo = plateNo == null ? "" : plateNo;
659
+        ordNo = ordNo == null ? "" : ordNo;
660
+        remark1 = remark1 == null ? "" : remark1;
661
+        fkcustmerName = fkcustmerName == null ? "" : fkcustmerName;
662
+        userId = userId == null ? "" : userId;
663
+        belongId = belongId == null ? "" : belongId;
664
+
665
+        List<String> pltNos = new ArrayList<>();
666
+        List<String> ordNos = new ArrayList<>();
667
+        if (plateNo.indexOf(",") != -1) {
668
+            pltNos = Arrays.asList(plateNo.split(","));
669
+        }
670
+        if (ordNo.indexOf(",") != -1) {
671
+            ordNos = Arrays.asList(ordNo.split(","));
672
+        }
673
+
674
+        // 直接使用 selectStoreForExport 查询,返回 List<Map>
675
+        return storeMapper.selectStoreForExport(wareName, stackName, model, materialName, standard,
676
+                customerName, plateNo, ordNo, pltNos, ordNos, userId, belongId, remark1, fkcustmerName, limit, offset);
677
+    }
678
+
390 679
 }

+ 51
- 0
src/main/java/com/th/demo/service/ware/StoreService.java Просмотреть файл

@@ -2,7 +2,9 @@ package com.th.demo.service.ware;
2 2
 
3 3
 import com.th.demo.model.ware.Store;
4 4
 
5
+import java.util.Date;
5 6
 import java.util.List;
7
+import java.util.Map;
6 8
 
7 9
 public interface StoreService {
8 10
     String queryLayerByStackId(String stackId, String userId, String belongId);
@@ -30,4 +32,53 @@ public interface StoreService {
30 32
      * 修改收货地址
31 33
      */
32 34
     String modifyReceiveAddress(List<String> id, List<String> inId, String newCustomerAddress);
35
+
36
+    /**
37
+     * 导出入库记录Excel
38
+     * @return 包含导出数据的List<Map>
39
+     */
40
+    List<Map<String, Object>> exportStoreExcel(int page, int rows, String wareName, String stackName, String model, String materialName, String standard, String customerName,
41
+                                               String plateNo, Date fromDate,
42
+                                               Date toDate, String userId, String belongId, String ordNo, String carNo, String tallyPeople, String fkComponyName,String remark1,String contractNo);
43
+
44
+    /**
45
+     * 分批导出入库记录Excel(解决大数据量内存溢出问题)
46
+     * @param offset 起始偏移量
47
+     * @param limit 每批数量
48
+     * @return 包含导出数据的List<Map>
49
+     */
50
+    List<Map<String, Object>> exportStoreExcelBatch(int page, int rows, String wareName, String stackName, String model, String materialName, String standard, String customerName,
51
+                                               String plateNo, Date fromDate,
52
+                                               Date toDate, String userId, String belongId, String ordNo, String carNo, String tallyPeople, String fkComponyName,String remark1,String contractNo,
53
+                                               int offset, int limit);
54
+
55
+    /**
56
+     * 导出出库记录Excel
57
+     * @return 包含导出数据的List<Map>
58
+     */
59
+    List<Map<String, Object>> outExportStoreExcel( int page, int rows, String wareName, String stackName, String model, String materialName, String standard, String customerName,
60
+                                                   String plateNo, String carNo, String tallyPeople,
61
+                                                   String ordNo, String fkComponyName,String remark1,String contractNo , Date fromDate, Date toDate, String userId, String belongId);
62
+
63
+    /**
64
+     * 分批导出出库记录Excel(解决大数据量内存溢出问题)
65
+     * @param offset 起始偏移量
66
+     * @param limit 每批数量
67
+     * @return 包含导出数据的List<Map>
68
+     */
69
+    List<Map<String, Object>> outExportStoreExcelBatch(int page, int rows, String wareName, String stackName, String model, String materialName, String standard, String customerName,
70
+                                                   String plateNo, String carNo, String tallyPeople,
71
+                                                   String ordNo, String fkComponyName, String remark1, String contractNo, Date fromDate, Date toDate, String userId, String belongId,
72
+                                                   int offset, int limit);
73
+
74
+    /**
75
+     * 导出库存Excel(使用StoreMapper查询,与入库/出库导出独立)
76
+     * @param offset 起始偏移量
77
+     * @param limit 每批数量(<=0时全量查询)
78
+     */
79
+    List<Map<String, Object>> exportStoreForExcel(String wareName, String stackName, String model, String materialName, String standard,
80
+                                                   String customerName, String plateNo, String ordNo, String remark1, String fkcustmerName,
81
+                                                   String userId, String belongId, int offset, int limit);
82
+
33 83
 }
84
+

+ 138
- 13
src/main/java/com/th/demo/tools/ExportExcelTools.java Просмотреть файл

@@ -17,10 +17,7 @@ import java.io.IOException;
17 17
 import java.io.OutputStream;
18 18
 import java.lang.reflect.InvocationTargetException;
19 19
 import java.lang.reflect.Method;
20
-import java.util.Collection;
21
-import java.util.Date;
22
-import java.util.Iterator;
23
-import java.util.Map;
20
+import java.util.*;
24 21
 import java.util.regex.Matcher;
25 22
 import java.util.regex.Pattern;
26 23
 
@@ -324,17 +321,11 @@ public class ExportExcelTools<T> {
324 321
                         patriarch.createPicture(anchor, workbook.addPicture(bsValue, Workbook.PICTURE_TYPE_JPEG));
325 322
                     } else {
326 323
                         // 其它数据类型都当作字符串简单处理
327
-
328
-                        if (i == 0) {
329
-                            textValue = index  + "";
324
+                        if (value != null) {
325
+                            textValue = value.toString();
330 326
                             sheet.setColumnWidth(i, (int) (arrWidth[i] * 37.5));
331 327
                         } else {
332
-                            if (value != null) {
333
-                                textValue = value.toString();
334
-                                sheet.setColumnWidth(i, (int) (arrWidth[i] * 37.5));
335
-                            } else {
336
-                                textValue = "";
337
-                            }
328
+                            textValue = "";
338 329
                         }
339 330
                     }
340 331
                     // 如果不是图片数据,就利用正则表达式判断textValue是否全部由数字组成
@@ -366,4 +357,138 @@ public class ExportExcelTools<T> {
366 357
             IOUtils.closeQuietly(out);
367 358
         }
368 359
     }
360
+
361
+    // ========== 流式导出支持 ==========
362
+    private Workbook streamingWorkbook;
363
+    private Sheet streamingSheet;
364
+    private int currentRowIndex = 0;
365
+    private int columnCount = 0;
366
+
367
+    /**
368
+     * 开始流式导出 - 写入表头
369
+     */
370
+    public void writeHeaders(String title, String[] headers, String[] columns, int[] arrWidth,
371
+                             OutputStream out, String pattern) {
372
+        streamingWorkbook = new SXSSFWorkbook();
373
+        streamingSheet = streamingWorkbook.createSheet(title);
374
+        streamingSheet.setDefaultColumnWidth(10);
375
+        streamingSheet.setDefaultRowHeightInPoints(24);
376
+
377
+        XSSFPrintSetup ps = (XSSFPrintSetup) streamingSheet.getPrintSetup();
378
+        ps.setLandscape(true);
379
+
380
+        // 表头样式
381
+        CellStyle style = streamingWorkbook.createCellStyle();
382
+        style.setFillForegroundColor(IndexedColors.GREY_25_PERCENT.getIndex());
383
+        style.setFillPattern(FillPatternType.SOLID_FOREGROUND);
384
+        style.setBorderBottom(BorderStyle.THIN);
385
+        style.setBorderLeft(BorderStyle.THIN);
386
+        style.setBorderRight(BorderStyle.THIN);
387
+        style.setBorderTop(BorderStyle.THIN);
388
+        style.setAlignment(HorizontalAlignment.CENTER);
389
+        Font font = streamingWorkbook.createFont();
390
+        font.setColor(IndexedColors.WHITE.getIndex());
391
+        font.setFontHeightInPoints((short) 10);
392
+        font.setBold(true);
393
+        style.setFont(font);
394
+
395
+        // 写入表头
396
+        Row row = streamingSheet.createRow(0);
397
+        currentRowIndex = 1;
398
+        columnCount = headers.length < columns.length ? headers.length : columns.length;
399
+        for (int i = 0; i < headers.length; i++) {
400
+            Cell cell = row.createCell(i);
401
+            cell.setCellStyle(style);
402
+            RichTextString text = new XSSFRichTextString(headers[i]);
403
+            cell.setCellValue(text);
404
+        }
405
+    }
406
+
407
+    /**
408
+     * 追加数据行
409
+     */
410
+    public void appendData(String[] columns, List<Map<String, Object>> dataList, String pattern) {
411
+        if (streamingSheet == null || dataList == null || dataList.isEmpty()) {
412
+            return;
413
+        }
414
+
415
+        if (StringUtils.isEmpty(pattern)) {
416
+            pattern = "yyyy/MM/dd";
417
+        }
418
+        FastDateFormat instance = FastDateFormat.getInstance(pattern);
419
+
420
+        // 内容样式
421
+        CellStyle style2 = streamingWorkbook.createCellStyle();
422
+        style2.setFillForegroundColor(IndexedColors.WHITE.getIndex());
423
+        style2.setFillPattern(FillPatternType.SOLID_FOREGROUND);
424
+        style2.setBorderBottom(BorderStyle.THIN);
425
+        style2.setBorderLeft(BorderStyle.THIN);
426
+        style2.setBorderRight(BorderStyle.THIN);
427
+        style2.setBorderTop(BorderStyle.THIN);
428
+        style2.setAlignment(HorizontalAlignment.CENTER);
429
+        style2.setVerticalAlignment(VerticalAlignment.CENTER);
430
+        Font font2 = streamingWorkbook.createFont();
431
+        font2.setBold(true);
432
+        style2.setFont(font2);
433
+
434
+        for (Map<String, Object> map : dataList) {
435
+            Row row = streamingSheet.createRow(currentRowIndex++);
436
+            for (int i = 0; i < columnCount; i++) {
437
+                Cell cell = row.createCell(i);
438
+                cell.setCellStyle(style2);
439
+                try {
440
+                    Object value = map.get(columns[i]);
441
+                    String textValue = null;
442
+                    if (value instanceof Date) {
443
+                        Date date = (Date) value;
444
+                        textValue = instance.format(date);
445
+                    } else if (value instanceof byte[]) {
446
+                        // 图片暂不处理
447
+                    } else {
448
+                        textValue = value != null ? value.toString() : "";
449
+                    }
450
+                    if (textValue != null) {
451
+                        Pattern p = Pattern.compile("^//d+(//.//d+)?$");
452
+                        Matcher matcher = p.matcher(textValue);
453
+                        if (matcher.matches()) {
454
+                            cell.setCellValue(Double.parseDouble(textValue));
455
+                        } else {
456
+                            RichTextString richString = new XSSFRichTextString(textValue);
457
+                            Font font3 = streamingWorkbook.createFont();
458
+                            font3.setColor(IndexedColors.BLACK.index);
459
+                            richString.applyFont(font3);
460
+                            cell.setCellValue(richString);
461
+                        }
462
+                    }
463
+                } catch (Exception e) {
464
+                    e.printStackTrace();
465
+                }
466
+            }
467
+        }
468
+    }
469
+
470
+    /**
471
+     * 完成写入
472
+     */
473
+    public void finishWrite(OutputStream out) {
474
+        if (streamingWorkbook != null) {
475
+            try {
476
+                streamingWorkbook.write(out);
477
+            } catch (IOException e) {
478
+                e.printStackTrace();
479
+            } finally {
480
+                try {
481
+                    streamingWorkbook.close();
482
+                } catch (IOException e) {
483
+                    e.printStackTrace();
484
+                }
485
+                // 清理临时文件
486
+                if (streamingWorkbook instanceof SXSSFWorkbook) {
487
+                    ((SXSSFWorkbook) streamingWorkbook).dispose();
488
+                }
489
+                streamingWorkbook = null;
490
+                streamingSheet = null;
491
+            }
492
+        }
493
+    }
369 494
 }

+ 1
- 1
src/main/java/com/th/demo/tools/TokenInterceptor.java Просмотреть файл

@@ -41,7 +41,7 @@ public class TokenInterceptor  implements HandlerInterceptor{
41 41
         String userId = request.getHeader("userId");
42 42
         String belongId = request.getHeader("belongId");
43 43
         String url =  request.getRequestURL().toString();
44
-        if (url.contains("download")||url.contains("show")){
44
+        if (url.contains("download")||url.contains("show")||url.contains("Export")){
45 45
             request.setAttribute("userId",userId);
46 46
             request.setAttribute("belongId",belongId);
47 47
             return true;

+ 45
- 0
src/main/resource/mapper/ware/InRecordMapper.xml Просмотреть файл

@@ -370,6 +370,51 @@
370 370
     order by t.add_time desc
371 371
   </select>
372 372
 
373
+  <!-- 分页查询导出(不使用 association,避免 N+1 查询问题) -->
374
+  <select id="selectForExport" resultMap="BaseResultMap" >
375
+    select
376
+    a.name as fk_compony_name,t.*
377
+    from t_ware_in_record t LEFT JOIN t_maint_customer a
378
+    on   t.fk_compony_name = a.id
379
+    where   t.ware_name  like concat('%',#{param1,jdbcType=VARCHAR},'%')
380
+    and t.stack_name like concat('%',#{param2,jdbcType=VARCHAR},'%')
381
+    and t.model like concat('%',#{param3,jdbcType=INTEGER},'%')
382
+    and t.material_name like concat('%',#{param4,jdbcType=VARCHAR},'%')
383
+    and t.standard like concat('%',#{param5,jdbcType=VARCHAR},'%')
384
+    <if test="param6 != null and param6 != ''" >
385
+      and t.customer_name  = #{param6,jdbcType=VARCHAR}
386
+    </if>
387
+      and (t.plate_no like concat('%',#{param7,jdbcType=VARCHAR},'%')
388
+            <if test="param16 != null and param16.size() !=0" >
389
+            OR t.plate_no IN <foreach  item="item" collection="param16" index="index"  open="(" separator="," close=")">
390
+            #{item,jdbcType=VARCHAR}  </foreach>
391
+            </if>
392
+          )
393
+      and (t.contract_no like concat('%',#{param19,jdbcType=VARCHAR},'%')
394
+      <if test="param20 != null and param20.size() !=0" >
395
+          OR t.contract_no IN <foreach  item="item" collection="param20" index="index"  open="(" separator="," close=")">
396
+          #{item,jdbcType=VARCHAR}  </foreach>
397
+      </if>
398
+      )
399
+      and t.add_time between #{param8,jdbcType=TIMESTAMP} and #{param9,jdbcType=TIMESTAMP}
400
+    and t.cancel_flag = '0'
401
+    and (ifnull(t.ord_no,'*') like concat('%',#{param12,jdbcType=VARCHAR},'%')
402
+    <if test="param17 != null and param17.size() !=0" >
403
+      OR ifnull(t.ord_no,'*') IN <foreach  item="item" collection="param17" index="index"  open="(" separator="," close=")">
404
+      #{item,jdbcType=VARCHAR}  </foreach>
405
+    </if>)
406
+    and ifnull(t.car_no,'*') like concat('%',#{param13,jdbcType=VARCHAR},'%')
407
+    and ((t.belong_id=#{param11,jdbcType=VARCHAR} and  t.ware_name in (
408
+            select b.name from t_maint_userware a ,t_maint_ware b  where a.ware_id = b.id
409
+            and  a.user_id = #{param10,jdbcType=VARCHAR}  )
410
+            )  or t.customer_name like CONCAT((select attr3 from sys_user temp where temp.id=#{param10,jdbcType=VARCHAR}),'%') )
411
+    and ifnull(t.tally_people,'*') like concat('%',#{param14,jdbcType=VARCHAR},'%')
412
+    and ifnull(a.name,'*') like concat('%',#{param15,jdbcType=VARCHAR},'%')
413
+    AND ifnull(t.remark1,'*') like concat('%',#{param18,jdbcType=VARCHAR},'%')
414
+    order by t.add_time desc
415
+    LIMIT #{param21,jdbcType=INTEGER} OFFSET #{param22,jdbcType=INTEGER}
416
+  </select>
417
+
373 418
   <select id="selectTotal" resultMap="TotalResultMap" >
374 419
     select
375 420
       sum(t.count) as total_amount

+ 54
- 0
src/main/resource/mapper/ware/OutRecordMapper.xml Просмотреть файл

@@ -519,6 +519,60 @@
519 519
     order by t.add_time desc
520 520
   </select>
521 521
 
522
+  <!-- 分页查询导出(不使用 association,避免 N+1 查询问题) -->
523
+  <select id="selectForExport" resultMap="CleanResultMap" >
524
+    select
525
+    e.name as fk_compony_name,p.tally_people as tally_people,p.truck_no as out_car_no,f.user_desc as add_id,t.*,c.ord_no,DATE_FORMAT(d.add_time, '%Y-%m-%d %H:%i:%s') as in_time
526
+    ,(select tt.user_desc as in_user from sys_user tt where tt.id = d.add_id) as in_user,d.car_no as in_car_no
527
+    ,t.invoice_price,t.distribution_id,t.contract_no
528
+    from t_ware_out_record t LEFT JOIN sys_user f on t.add_id = f.id
529
+    ,t_ware_distribution p,(select t.plate_no,max(t.ord_no) ord_no from t_ware_store t group by t.plate_no) c,t_ware_in_record d
530
+    LEFT JOIN t_maint_customer e on d.fk_compony_name = e.id
531
+
532
+    where t.ware_name  like concat('%',#{param1,jdbcType=VARCHAR},'%')
533
+    and t.stack_name like concat('%',#{param2,jdbcType=VARCHAR},'%')
534
+    and t.model like concat('%',#{param3,jdbcType=INTEGER},'%')
535
+    and t.material_name like concat('%',#{param4,jdbcType=VARCHAR},'%')
536
+    and t.standard like concat('%',#{param5,jdbcType=VARCHAR},'%')
537
+    <if test="param6 != null and param6 != ''" >
538
+      and t.customer_name  = #{param6,jdbcType=VARCHAR}
539
+    </if>
540
+    and (t.plate_no like concat('%',#{param7,jdbcType=VARCHAR},'%')
541
+        <if test="param16 != null and param16.size() !=0" >
542
+         OR t.plate_no IN <foreach  item="item" collection="param16" index="index"  open="(" separator="," close=")">
543
+         #{item,jdbcType=VARCHAR}  </foreach>
544
+        </if>
545
+        )
546
+      and (t.contract_no like concat('%',#{param19,jdbcType=VARCHAR},'%')
547
+      <if test="param20 != null and param20.size() !=0" >
548
+          OR t.contract_no IN <foreach  item="item" collection="param20" index="index"  open="(" separator="," close=")">
549
+          #{item,jdbcType=VARCHAR}  </foreach>
550
+      </if>
551
+      )
552
+    and t.add_time between #{param8,jdbcType=TIMESTAMP} and #{param9,jdbcType=TIMESTAMP}
553
+    and t.distribution_id = p.id
554
+    and t.plate_no = c.plate_no
555
+    and t.in_id = d.id
556
+    and p.truck_no like concat('%',#{param12,jdbcType=VARCHAR},'%')
557
+    and t.cancel_flag = '0'
558
+    and ((t.belong_id=#{param11,jdbcType=VARCHAR} and t.ware_name in (
559
+    select b.name from t_maint_userware a ,t_maint_ware b  where a.ware_id = b.id
560
+    and  a.user_id = #{param10,jdbcType=VARCHAR}  )
561
+    )  or t.customer_name like CONCAT((select attr3 from sys_user temp where temp.id=#{param10,jdbcType=VARCHAR}),'%') )
562
+    and ifnull(p.tally_people,'*') like concat('%',#{param13,jdbcType=VARCHAR},'%')
563
+    and (ifnull(c.ord_no,'*') like concat('%',#{param14,jdbcType=VARCHAR},'%')
564
+        <if test="param17 != null and param17.size() !=0" >
565
+        OR ifnull(c.ord_no,'*') IN <foreach  item="item" collection="param17" index="index"  open="(" separator="," close=")">
566
+        #{item,jdbcType=VARCHAR}  </foreach>
567
+        </if>
568
+        )
569
+    and ifnull(e.name,'*') like concat('%',#{param15,jdbcType=VARCHAR},'%')
570
+    and ifnull(t.remark1,'*') like concat('%',#{param18,jdbcType=VARCHAR},'%')
571
+    and ifnull(t.back_flag,0) &lt;> '1'
572
+    order by t.add_time desc
573
+    LIMIT #{param21,jdbcType=INTEGER} OFFSET #{param22,jdbcType=INTEGER}
574
+  </select>
575
+
522 576
   <update id="updateOutDtmByOutId" >
523 577
     update t_ware_out_record
524 578
     set add_time = #{param2,jdbcType=TIMESTAMP}

+ 82
- 0
src/main/resource/mapper/ware/StoreMapper.xml Просмотреть файл

@@ -603,4 +603,86 @@ update t_ware_store t set t.layer =   #{param7,jdbcType=INTEGER}
603 603
     <select id="queryStoreById" resultType="java.lang.String" parameterType="java.lang.String">
604 604
         select plate_no from t_ware_store where stack_id = #{stackId,jdbcType=VARCHAR} and out_flag = '0' and cancel_flag = '0'
605 605
     </select>
606
+
607
+    <!-- 库存导出查询(支持分页偏移,直接JOIN获取所有字段) -->
608
+    <select id="selectStoreForExport" resultType="java.util.Map">
609
+        SELECT
610
+            t.layer as layer,
611
+            b.name as stackName,
612
+            c.name as materialName,
613
+            c.standard as materialStandard,
614
+            t.plate_no as plateNo,
615
+            t.model as model,
616
+            t.count as count,
617
+            t.weight as weight,
618
+            t.ord_no as ordNo,
619
+            t.contract_no as contractNo,
620
+            e.name as customerName,
621
+            d.name as fkComponyName,
622
+            t.receive_address as receiveAddress,
623
+            t.production_place as productionPlace,
624
+            t.remark as remark,
625
+            t.remark1 as remark1,
626
+            t.add_time as addTime,
627
+            t.car_no as carNo
628
+        FROM t_ware_store t
629
+        LEFT JOIN t_maint_ware a ON t.ware_id = a.id
630
+        LEFT JOIN t_maint_stack b ON t.stack_id = b.id
631
+        LEFT JOIN t_maint_material c ON t.material_id = c.id
632
+        LEFT JOIN t_maint_customer d ON t.fk_compony_id = d.id
633
+        LEFT JOIN t_maint_customer e ON t.customer_id = e.id
634
+        WHERE 1=1
635
+        <if test="param1 != null and param1 != ''">
636
+            AND a.name LIKE CONCAT('%', #{param1}, '%')
637
+        </if>
638
+        <if test="param2 != null and param2 != ''">
639
+            AND e.name LIKE CONCAT('%', #{param2}, '%')
640
+        </if>
641
+        <if test="param14 != null and param14 != ''">
642
+            AND d.name LIKE CONCAT('%', #{param14}, '%')
643
+        </if>
644
+        <if test="param3 != null and param3 != ''">
645
+            AND t.model LIKE CONCAT('%', #{param3}, '%')
646
+        </if>
647
+        <if test="param4 != null and param4 != ''">
648
+            AND c.name LIKE CONCAT('%', #{param4}, '%')
649
+        </if>
650
+        <if test="param5 != null and param5 != ''">
651
+            AND c.standard LIKE CONCAT('%', #{param5}, '%')
652
+        </if>
653
+        <if test="param6 != null and param6 != ''">
654
+            AND e.name LIKE CONCAT('%', #{param6}, '%')
655
+        </if>
656
+        <if test="param13 != null and param13 != ''">
657
+            AND t.remark1 LIKE CONCAT('%', #{param13}, '%')
658
+        </if>
659
+        <if test="param7 != null and param7 != ''">
660
+            AND t.plate_no LIKE CONCAT('%', #{param7}, '%')
661
+        </if>
662
+        <if test="param9 != null and param9.size() != 0">
663
+            OR t.plate_no IN
664
+            <foreach item="item" collection="param9" open="(" separator="," close=")">
665
+                #{item}
666
+            </foreach>
667
+        </if>
668
+        <if test="param8 != null and param8 != ''">
669
+            AND t.ord_no LIKE CONCAT('%', #{param8}, '%')
670
+        </if>
671
+        <if test="param10 != null and param10.size() != 0">
672
+            OR t.ord_no IN
673
+            <foreach item="item" collection="param10" open="(" separator="," close=")">
674
+                #{item}
675
+            </foreach>
676
+        </if>
677
+        AND t.belong_id = #{param12}
678
+        AND t.cancel_flag = '0'
679
+        AND t.out_flag = '0'
680
+        AND t.ware_id IN (
681
+            SELECT m.ware_id FROM t_maint_userware m WHERE m.user_id = #{param11}
682
+        )
683
+        ORDER BY b.code, t.layer DESC
684
+        <if test="param17 != null and param17 > 0">
685
+            LIMIT #{param17} OFFSET #{param18}
686
+        </if>
687
+    </select>
606 688
 </mapper>

Загрузка…
Отмена
Сохранить