|
...
|
...
|
@@ -31,6 +31,7 @@ import javax.annotation.Resource; |
|
31
|
31
|
import java.io.*;
|
|
32
|
32
|
import java.math.BigDecimal;
|
|
33
|
33
|
import java.math.RoundingMode;
|
|
|
34
|
+import java.nio.charset.StandardCharsets;
|
|
34
|
35
|
import java.nio.file.Files;
|
|
35
|
36
|
import java.time.format.DateTimeFormatter;
|
|
36
|
37
|
import java.util.ArrayList;
|
|
...
|
...
|
@@ -183,6 +184,8 @@ public class BusinessDataExportHandler implements ExportHandler { |
|
183
|
184
|
}
|
|
184
|
185
|
// 时间格式
|
|
185
|
186
|
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
187
|
+ // 失败单清单:单张失败不影响其余单据导出,最后在 zip 内附失败清单
|
|
|
188
|
+ List<String> failedOrders = new ArrayList<>();
|
|
186
|
189
|
try (FileOutputStream fosZip = new FileOutputStream(file);
|
|
187
|
190
|
ZipOutputStream zos = new ZipOutputStream(fosZip)) {
|
|
188
|
191
|
for (PurchaseOrderInfo orderInfo : orderInfoList) {
|
|
...
|
...
|
@@ -311,20 +314,31 @@ public class BusinessDataExportHandler implements ExportHandler { |
|
311
|
314
|
}
|
|
312
|
315
|
}
|
|
313
|
316
|
} else {
|
|
314
|
|
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
315
|
|
- workbook.write(baos);
|
|
|
317
|
+ // 直接写入 zip 流,避免 ByteArrayOutputStream 整文件拷贝占用双倍内存
|
|
316
|
318
|
ZipEntry entry = new ZipEntry(orderInfo.getOrderNo() + "-"
|
|
317
|
319
|
+ orderInfo.getOrderingUnitName() + "-" + orderInfo.getWorkshopName() + "-订货单打印-" + createTime + ".xlsx");
|
|
318
|
320
|
zos.putNextEntry(entry);
|
|
319
|
|
- zos.write(baos.toByteArray());
|
|
|
321
|
+ workbook.write(zos);
|
|
320
|
322
|
zos.closeEntry();
|
|
321
|
323
|
}
|
|
|
324
|
+ } catch (Exception e) {
|
|
|
325
|
+ // 单张失败:记录原因后跳过,继续导出其余单据
|
|
|
326
|
+ log.error("订货单{}导出失败,跳过继续导出", orderInfo.getOrderNo(), e);
|
|
|
327
|
+ failedOrders.add(orderInfo.getOrderNo() + "-" + orderInfo.getOrderingUnitName()
|
|
|
328
|
+ + ": " + (e.getMessage() == null ? e.getClass().getName() : e.getMessage()));
|
|
322
|
329
|
}
|
|
323
|
330
|
}
|
|
|
331
|
+ // 有失败单时在 zip 内附失败清单,便于核对补打
|
|
|
332
|
+ if (!failedOrders.isEmpty()) {
|
|
|
333
|
+ zos.putNextEntry(new ZipEntry("导出失败清单.txt"));
|
|
|
334
|
+ zos.write(String.join("\r\n", failedOrders).getBytes(StandardCharsets.UTF_8));
|
|
|
335
|
+ zos.closeEntry();
|
|
|
336
|
+ }
|
|
324
|
337
|
zos.flush();
|
|
325
|
338
|
} catch (Exception e) {
|
|
326
|
339
|
log.error("订货单批量打印失败: {}", e.getMessage(), e);
|
|
327
|
|
- throw new DefaultClientException(e.getMessage());
|
|
|
340
|
+ throw new DefaultClientException("订货单批量导出失败: "
|
|
|
341
|
+ + (e.getMessage() == null ? e.getClass().getName() : e.getMessage()));
|
|
328
|
342
|
}
|
|
329
|
343
|
}
|
|
330
|
344
|
|
...
|
...
|
|