Browse Source

货权转移记录新增导出

转移数量变动日志 新增    (总计 , 备注模糊查询 )
货权转移管理列表新增删除
货权转移编辑弹窗,客户不清空,备注清空
dw 1 week ago
parent
commit
ce27375e7d

+ 2
- 2
src/main/java/com/th/demo/controller/maint/CargoController.java View File

@@ -66,7 +66,7 @@ public class CargoController {
66 66
 
67 67
     @RequestMapping(value = "/queryRecord.do")
68 68
     public String queryRecord(int page, int rows,String uperCustomer, String Customer,
69
-            String RecordDateBegin,String RecordDateEnd,String subStr,String changeFrom,
69
+            String RecordDateBegin,String RecordDateEnd,String subStr,String changeFrom,String remark,
70 70
                               HttpServletRequest request) {
71 71
 
72 72
         try {
@@ -81,7 +81,7 @@ public class CargoController {
81 81
 
82 82
             String userId = (String) request.getAttribute("userId");
83 83
             String belongId = (String) request.getAttribute("belongId");
84
-            result = cargoService.queryRecord(page,rows,uperCustomer,Customer,fromDate2,toDate2,subStr,changeFrom,userId,belongId);
84
+            result = cargoService.queryRecord(page,rows,uperCustomer,Customer,fromDate2,toDate2,subStr,changeFrom,userId,belongId,remark);
85 85
         } catch (Exception ex) {
86 86
             ex.printStackTrace();
87 87
             result = JSONTools.toString(ResponseCodeMsg.CODE_EX, ex.getMessage());

+ 101
- 0
src/main/java/com/th/demo/controller/ware/ChangeRecordController.java View File

@@ -5,14 +5,20 @@ import com.th.demo.model.system.Type;
5 5
 import com.th.demo.service.ware.ChangeRecordService;
6 6
 import com.th.demo.service.ware.ChangeService;
7 7
 import com.th.demo.tools.DateTools;
8
+import com.th.demo.tools.ExportExcelTools;
8 9
 import com.th.demo.tools.JSONTools;
10
+import com.th.demo.tools.Tools;
9 11
 import org.springframework.beans.factory.annotation.Autowired;
10 12
 import org.springframework.web.bind.annotation.RequestMapping;
11 13
 import org.springframework.web.bind.annotation.RequestMethod;
12 14
 import org.springframework.web.bind.annotation.RestController;
13 15
 
14 16
 import javax.servlet.http.HttpServletRequest;
17
+import javax.servlet.http.HttpServletResponse;
18
+import java.io.OutputStream;
19
+import java.text.SimpleDateFormat;
15 20
 import java.util.Date;
21
+import java.util.List;
16 22
 
17 23
 @RestController
18 24
 @RequestMapping(value = "/WareChangeRecord")
@@ -76,4 +82,99 @@ public class ChangeRecordController {
76 82
         }
77 83
     }
78 84
 
85
+    /**
86
+     * 导出转移记录Excel - 分批查询流式导出
87
+     */
88
+    @RequestMapping(value = "/exportExcel.do")
89
+    public void exportExcel(
90
+            String wareName,
91
+            String stackName,
92
+            String model,
93
+            String materialName,
94
+            String standard,
95
+            String customerName,
96
+            String plateNo,
97
+            String pFromDate,
98
+            String pToDate,
99
+            String userId,
100
+            String belongId,
101
+            HttpServletRequest request,
102
+            HttpServletResponse response) {
103
+        try {
104
+            // 设置超时时间,单位毫秒(10分钟)
105
+            response.setHeader("timeout", "600000");
106
+
107
+            Date fromDate = DateTools.StrToDate(pFromDate, "yyyy-MM-dd HH:mm:ss");
108
+            Date toDate = DateTools.StrToDate(pToDate, "yyyy-MM-dd HH:mm:ss");
109
+
110
+            // 设置表头
111
+            String[] headers = {"仓库名称", "垛位", "层号", "品名", "规格型号", "钢种", "数量", "重量",
112
+                    "钢板号", "类型", "客户名称(旧)", "收货地址(旧)", "客户名称(新)", "收货地址(新)",
113
+                    "计量方式", "切边类型", "产地", "备注", "操作人", "操作时间"};
114
+
115
+            // 设置字段名
116
+            String[] columns = {"wareName", "stackName", "layer", "materialName", "model", "standard",
117
+                    "count", "weight", "plateNo", "recordType", "customerNameOld", "receiveAddressOld",
118
+                    "customerNameNew", "receiveAddressNew", "wgtDcnMtcCd", "edgeTy", "productionPlace",
119
+                    "remark", "addUserUserDesc", "addTime"};
120
+
121
+            // 设置列宽
122
+            int[] arrWidth = {80, 50, 50, 50, 80, 50, 50, 50, 100, 60,
123
+                    100, 150, 100, 150, 60, 60, 100, 80, 60, 120};
124
+
125
+            // 生成文件名
126
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
127
+            String filename = "转移记录_" + sdf.format(new Date()) + ".xlsx";
128
+
129
+            // 分批查询,每批5000条
130
+            final int batchSize = 5000;
131
+            int offset = 0;
132
+
133
+            // 使用try-with-resources自动关闭流
134
+            try (OutputStream out = Tools.getExportOutStream(filename, response)) {
135
+                // 创建流式工作簿
136
+                ExportExcelTools<List<java.util.Map<String, Object>>> exportExcel = new ExportExcelTools<>();
137
+
138
+                // 写入表头
139
+                exportExcel.writeHeaders("转移记录", headers, columns, arrWidth, out, "yyyy/MM/dd HH:mm:ss");
140
+
141
+                // 分批查询并写入
142
+                while (true) {
143
+                    List<java.util.Map<String, Object>> batchData = changeRecordService.exportForExcelBatch(
144
+                            wareName, stackName, model, materialName, standard, customerName,
145
+                            plateNo, fromDate, toDate, userId, belongId, offset, batchSize);
146
+
147
+                    if (batchData == null || batchData.isEmpty()) {
148
+                        break;
149
+                    }
150
+
151
+                    // 写入数据
152
+                    exportExcel.appendData(columns, batchData, "yyyy/MM/dd HH:mm:ss");
153
+
154
+                    // 如果数据少于批次大小,说明是最后一批
155
+                    if (batchData.size() < batchSize) {
156
+                        break;
157
+                    }
158
+
159
+                    offset += batchSize;
160
+
161
+                    // 手动触发GC回收内存
162
+                    System.gc();
163
+                }
164
+
165
+                // 完成写入
166
+                exportExcel.finishWrite(out);
167
+                out.flush();
168
+            } catch (Exception e) {
169
+                e.printStackTrace();
170
+                response.reset();
171
+                response.setContentType("text/html;charset=utf-8");
172
+                response.getWriter().write("导出失败:" + e.getMessage());
173
+            }
174
+
175
+        } catch (Exception e) {
176
+            e.printStackTrace();
177
+        }
178
+    }
179
+
79 180
 }

+ 1
- 1
src/main/java/com/th/demo/mapping/ware/CargoChangeRecordMapper.java View File

@@ -16,7 +16,7 @@ public interface CargoChangeRecordMapper {
16 16
     CargoChangeRecord selectByCustomer(String uperCustomer, String Customer);
17 17
 
18 18
     List<CargoChangeRecord> selectRecord(String uperCustomer, String Customer,
19
-                                         Date RecordDateBegin,Date RecordDateEnd,String subStr,String changeFrom);
19
+                                         Date RecordDateBegin,Date RecordDateEnd,String subStr,String changeFrom,String remark);
20 20
 
21 21
 
22 22
 

+ 8
- 0
src/main/java/com/th/demo/mapping/ware/ChangeRecordMapper.java View File

@@ -5,6 +5,7 @@ import com.th.demo.model.ware.MoveRecord;
5 5
 
6 6
 import java.util.Date;
7 7
 import java.util.List;
8
+import java.util.Map;
8 9
 
9 10
 public interface ChangeRecordMapper {
10 11
     int deleteByPrimaryKey(String id);
@@ -24,4 +25,11 @@ public interface ChangeRecordMapper {
24 25
     List<ChangeRecord> select(String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date fromDate, Date toDate, String userId, String belongId);
25 26
 
26 27
     List<ChangeRecord> selectTotal(String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date date, Date fromDate, String userId, String belongId);
28
+
29
+    List<Map<String, Object>> selectForExport(String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date fromDate, Date toDate, String userId, String belongId);
30
+
31
+    /**
32
+     * 分批查询导出数据
33
+     */
34
+    List<Map<String, Object>> selectForExportBatch(String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date fromDate, Date toDate, String userId, String belongId, int offset, int limit);
27 35
 }

+ 2
- 2
src/main/java/com/th/demo/service/impl/maint/CargoServiceImpl.java View File

@@ -126,9 +126,9 @@ public class CargoServiceImpl implements CargoService {
126 126
     @Override
127 127
     public String queryRecord(int page, int rows, String uperCustomer, String Customer ,
128 128
                               Date RecordDateBegin,Date RecordDateEnd,String subStr,String changeFrom,
129
-                              String userId, String belongId) {
129
+                              String userId, String belongId,String remark) {
130 130
         PageHelper.startPage(page, rows);
131
-        List<CargoChangeRecord> list   = cargoChangeRecordMapper.selectRecord(uperCustomer, Customer,RecordDateBegin,RecordDateEnd,subStr,changeFrom);
131
+        List<CargoChangeRecord> list   = cargoChangeRecordMapper.selectRecord(uperCustomer, Customer,RecordDateBegin,RecordDateEnd,subStr,changeFrom,remark);
132 132
         PageInfo<CargoChangeRecord> pageInfo = new PageInfo<>(list);
133 133
         result = JSONTools.toStringyyyyMMddHHmmss(pageInfo);
134 134
         return result;

+ 28
- 0
src/main/java/com/th/demo/service/impl/ware/ChangeRecordServiceImpl.java View File

@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
12 12
 
13 13
 import java.util.Date;
14 14
 import java.util.List;
15
+import java.util.Map;
15 16
 
16 17
 @Service("ChangeRecordService")
17 18
 public class ChangeRecordServiceImpl implements ChangeRecordService {
@@ -39,4 +40,31 @@ public class ChangeRecordServiceImpl implements ChangeRecordService {
39 40
         result = JSONTools.toStringyyyyMMddHHmmss(list);
40 41
         return result;
41 42
     }
43
+
44
+    @Override
45
+    public List<Map<String, Object>> exportForExcel(String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date fromDate, Date toDate, String userId, String belongId) {
46
+        // 调用 Mapper 获取数据,返回已转换为 Map 的列表
47
+        return changeRecordMapper.selectForExport(wareName, stackName, model, materialName, standard, customerName, plateNo, fromDate, toDate, userId, belongId);
48
+    }
49
+
50
+    /**
51
+     * 分批导出转移记录Excel(解决大数据量内存溢出问题)
52
+     */
53
+    @Override
54
+    public List<Map<String, Object>> exportForExcelBatch(String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date fromDate, Date toDate, String userId, String belongId, int offset, int limit) {
55
+        // ========== 入参空值处理 ==========
56
+        wareName = wareName == null ? "" : wareName;
57
+        stackName = stackName == null ? "" : stackName;
58
+        model = model == null ? "" : model;
59
+        materialName = materialName == null ? "" : materialName;
60
+        standard = standard == null ? "" : standard;
61
+        customerName = customerName == null ? "" : customerName;
62
+        plateNo = plateNo == null ? "" : plateNo;
63
+        userId = userId == null ? "" : userId;
64
+        belongId = belongId == null ? "" : belongId;
65
+
66
+        // 调用分批查询 Mapper
67
+        return changeRecordMapper.selectForExportBatch(wareName, stackName, model, materialName, standard,
68
+                customerName, plateNo, fromDate, toDate, userId, belongId, offset, limit);
69
+    }
42 70
 }

+ 1
- 1
src/main/java/com/th/demo/service/maint/CargoService.java View File

@@ -10,5 +10,5 @@ public interface CargoService {
10 10
 
11 11
     String queryRecord(int page, int rows, String uperCustomer, String Customer ,
12 12
                        Date RecordDateBegin,Date RecordDateEnd,String subStr,String changeFrom,
13
-                       String userId, String belongId);
13
+                       String userId, String belongId,String remark);
14 14
 }

+ 9
- 0
src/main/java/com/th/demo/service/ware/ChangeRecordService.java View File

@@ -1,9 +1,18 @@
1 1
 package com.th.demo.service.ware;
2 2
 
3 3
 import java.util.Date;
4
+import java.util.List;
5
+import java.util.Map;
4 6
 
5 7
 public interface ChangeRecordService {
6 8
     String query(int page, int rows, String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date fromDate, Date toDate, String userId, String belongId);
7 9
 
8 10
     String queryTotal(int page, int rows, String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date fromDate, Date toDate, String userId, String belongId);
11
+
12
+    List<Map<String, Object>> exportForExcel(String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date fromDate, Date toDate, String userId, String belongId);
13
+
14
+    /**
15
+     * 分批导出转移记录Excel(解决大数据量内存溢出问题)
16
+     */
17
+    List<Map<String, Object>> exportForExcelBatch(String wareName, String stackName, String model, String materialName, String standard, String customerName, String plateNo, Date fromDate, Date toDate, String userId, String belongId, int offset, int limit);
9 18
 }

+ 3
- 0
src/main/resource/mapper/ware/CargoChangeRecordMapper.xml View File

@@ -68,6 +68,9 @@
68 68
     <if test="param6 != null and param6 != ''" >
69 69
       and change_from like concat('%',#{param6,jdbcType=VARCHAR},'%')
70 70
     </if>
71
+      <if test="param7 != null and param7 != ''" >
72
+          and remark like concat('%',#{param7,jdbcType=VARCHAR},'%')
73
+      </if>
71 74
     order by modify_time desc
72 75
   </select>
73 76
 

+ 134
- 0
src/main/resource/mapper/ware/ChangeRecordMapper.xml View File

@@ -424,5 +424,139 @@
424 424
     order by t.add_time desc
425 425
   </select>
426 426
 
427
+  <!-- 导出转移记录查询,返回Map列表 -->
428
+  <select id="selectForExport" resultType="java.util.Map">
429
+    select
430
+      t.ware_name as wareName,
431
+      t.stack_name as stackName,
432
+      t.layer as layer,
433
+      t.material_name as materialName,
434
+      t.model as model,
435
+      t.standard as standard,
436
+      t.count as count,
437
+      t.weight as weight,
438
+      t.plate_no as plateNo,
439
+      (case t.record_type when '0' then '入库取消' when '1' then '入库' else t.record_type end) as recordType,
440
+      t.customer_name_old as customerNameOld,
441
+      t.receive_address_old as receiveAddressOld,
442
+      t.customer_name_new as customerNameNew,
443
+      t.receive_address_new as receiveAddressNew,
444
+      t.wgt_dcn_mtc_cd as wgtDcnMtcCd,
445
+      t.edge_ty as edgeTy,
446
+      t.production_place as productionPlace,
447
+      t.remark as remark,
448
+      u.user_desc as addUserUserDesc,
449
+      t.add_time as addTime
450
+    from t_ware_change_record t
451
+    left join sys_user u on t.add_id = u.id
452
+    where 1=1
453
+    <if test="param1 != null and param1 != ''">
454
+      and t.ware_name like concat('%', #{param1,jdbcType=VARCHAR}, '%')
455
+    </if>
456
+    <if test="param2 != null and param2 != ''">
457
+      and t.stack_name like concat('%', #{param2,jdbcType=VARCHAR}, '%')
458
+    </if>
459
+    <if test="param3 != null and param3 != ''">
460
+      and t.model like concat('%', #{param3,jdbcType=VARCHAR}, '%')
461
+    </if>
462
+    <if test="param4 != null and param4 != ''">
463
+      and t.material_name like concat('%', #{param4,jdbcType=VARCHAR}, '%')
464
+    </if>
465
+    <if test="param5 != null and param5 != ''">
466
+      and t.standard like concat('%', #{param5,jdbcType=VARCHAR}, '%')
467
+    </if>
468
+    <if test="param6 != null and param6 != ''">
469
+      and (t.customer_name_old like concat('%', #{param6,jdbcType=VARCHAR}, '%')
470
+           or t.customer_name_new like concat('%', #{param6,jdbcType=VARCHAR}, '%'))
471
+    </if>
472
+    <if test="param7 != null and param7 != ''">
473
+      and t.plate_no like concat('%', #{param7,jdbcType=VARCHAR}, '%')
474
+    </if>
475
+    <if test="param8 != null">
476
+      and t.add_time &gt;= #{param8,jdbcType=TIMESTAMP}
477
+    </if>
478
+    <if test="param9 != null">
479
+      and t.add_time &lt;= #{param9,jdbcType=TIMESTAMP}
480
+    </if>
481
+    <if test="param10 != null and param10 != ''">
482
+      and t.ware_name in (
483
+        select b.name from t_maint_userware a, t_maint_ware b
484
+        where a.ware_id = b.id and a.user_id = #{param10,jdbcType=VARCHAR}
485
+      )
486
+    </if>
487
+    <if test="param11 != null and param11 != ''">
488
+      and t.belong_id = #{param11,jdbcType=VARCHAR}
489
+    </if>
490
+    and t.cancel_flag = '0'
491
+    order by t.add_time desc
492
+  </select>
493
+
494
+  <!-- 分批导出转移记录查询,支持分页 -->
495
+  <select id="selectForExportBatch" resultType="java.util.Map">
496
+    select
497
+      t.ware_name as wareName,
498
+      t.stack_name as stackName,
499
+      t.layer as layer,
500
+      t.material_name as materialName,
501
+      t.model as model,
502
+      t.standard as standard,
503
+      t.count as count,
504
+      t.weight as weight,
505
+      t.plate_no as plateNo,
506
+      (case t.record_type when '0' then '入库取消' when '1' then '入库' else t.record_type end) as recordType,
507
+      t.customer_name_old as customerNameOld,
508
+      t.receive_address_old as receiveAddressOld,
509
+      t.customer_name_new as customerNameNew,
510
+      t.receive_address_new as receiveAddressNew,
511
+      t.wgt_dcn_mtc_cd as wgtDcnMtcCd,
512
+      t.edge_ty as edgeTy,
513
+      t.production_place as productionPlace,
514
+      t.remark as remark,
515
+      u.user_desc as addUserUserDesc,
516
+      t.add_time as addTime
517
+    from t_ware_change_record t
518
+    left join sys_user u on t.add_id = u.id
519
+    where 1=1
520
+    <if test="param1 != null and param1 != ''">
521
+      and t.ware_name like concat('%', #{param1,jdbcType=VARCHAR}, '%')
522
+    </if>
523
+    <if test="param2 != null and param2 != ''">
524
+      and t.stack_name like concat('%', #{param2,jdbcType=VARCHAR}, '%')
525
+    </if>
526
+    <if test="param3 != null and param3 != ''">
527
+      and t.model like concat('%', #{param3,jdbcType=INTEGER}, '%')
528
+    </if>
529
+    <if test="param4 != null and param4 != ''">
530
+      and t.material_name like concat('%', #{param4,jdbcType=VARCHAR}, '%')
531
+    </if>
532
+    <if test="param5 != null and param5 != ''">
533
+      and t.standard like concat('%', #{param5,jdbcType=VARCHAR}, '%')
534
+    </if>
535
+    <if test="param6 != null and param6 != ''">
536
+      and (t.customer_name_old like concat('%', #{param6,jdbcType=VARCHAR}, '%')
537
+           or t.customer_name_new like concat('%', #{param6,jdbcType=VARCHAR}, '%'))
538
+    </if>
539
+    <if test="param7 != null and param7 != ''">
540
+      and t.plate_no like concat('%', #{param7,jdbcType=VARCHAR}, '%')
541
+    </if>
542
+    <if test="param8 != null and param9 != null">
543
+      and t.add_time between #{param8,jdbcType=TIMESTAMP} and #{param9,jdbcType=TIMESTAMP}
544
+    </if>
545
+    <if test="param10 != null and param10 != ''">
546
+      and t.ware_name in (
547
+        select b.name from t_maint_userware a, t_maint_ware b
548
+        where a.ware_id = b.id and a.user_id = #{param10,jdbcType=VARCHAR}
549
+      )
550
+    </if>
551
+    <if test="param11 != null and param11 != ''">
552
+      and t.belong_id = #{param11,jdbcType=VARCHAR}
553
+    </if>
554
+    and t.cancel_flag = '0'
555
+    order by t.add_time desc
556
+    <if test="param12 != null and param12 >= 0">
557
+      LIMIT #{param13,jdbcType=INTEGER} OFFSET #{param12,jdbcType=INTEGER}
558
+    </if>
559
+  </select>
560
+
427 561
 
428 562
 </mapper>

Loading…
Cancel
Save