From e5ae1e7a653269f2bfddacf54809b99f14104f00 Mon Sep 17 00:00:00 2001 From: Fai Luk Date: Mon, 5 Oct 2026 16:13:42 +0800 Subject: [PATCH] fixing the pdf label --- src/main/java/com/ffii/core/utils/PdfUtils.java | 13 +++++++++++-- .../modules/stock/service/StockInLineService.kt | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/ffii/core/utils/PdfUtils.java b/src/main/java/com/ffii/core/utils/PdfUtils.java index 5a36a446..e4783c57 100644 --- a/src/main/java/com/ffii/core/utils/PdfUtils.java +++ b/src/main/java/com/ffii/core/utils/PdfUtils.java @@ -12,6 +12,7 @@ import net.sf.jasperreports.engine.JRDataSource; import net.sf.jasperreports.engine.JREmptyDataSource; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource; +import net.sf.jasperreports.engine.data.JRMapCollectionDataSource; public class PdfUtils { @@ -23,8 +24,16 @@ public class PdfUtils { public static JasperPrint fillReport(JasperReport report, List loopList, Map params) throws Exception { - JRDataSource dataSources = loopList.size() > 0 ? new JRBeanCollectionDataSource(loopList) - : new JREmptyDataSource(); + JRDataSource dataSources; + if (loopList == null || loopList.isEmpty()) { + dataSources = new JREmptyDataSource(); + } else if (loopList.get(0) instanceof Map) { + @SuppressWarnings("unchecked") + List> rows = (List>) loopList; + dataSources = new JRMapCollectionDataSource(rows); + } else { + dataSources = new JRBeanCollectionDataSource(loopList); + } JasperPrint jasperPrint = JasperFillManager.fillReport(report, params, dataSources); return jasperPrint; } diff --git a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt index 7d141fc2..66c59367 100644 --- a/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt +++ b/src/main/java/com/ffii/fpsms/modules/stock/service/StockInLineService.kt @@ -1221,6 +1221,9 @@ open class StockInLineService( val inputStream = resource.inputStream val poLabel = JasperCompileManager.compileReport(inputStream) val qrCodeInfo = stockInLineRepository.findStockInLineInfoByIdInAndDeletedFalse(request.stockInLineIds).toMutableList() + if (qrCodeInfo.isEmpty()) { + throw IllegalArgumentException("找不到來貨記錄,無法產生二維碼") + } val fields = mutableListOf>() for (info in qrCodeInfo) {