diff --git a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java index 191faa98..2599714a 100644 --- a/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java +++ b/src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java @@ -2035,33 +2035,15 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { palletList = sqlSession.selectList("ecssMapper.searchEcssCoDelNotifyDetail", data); } //计算总数和总箱数 - int totalQty = 0; - int totalBoxQty = 0; + BigDecimal totalQty = BigDecimal.ZERO; + BigDecimal totalBoxQty = BigDecimal.ZERO; for (Map item : palletList) { Object qtyObj = item.get("qty"); Object boxQtyObj = item.get("boxQty"); - int qty = 0; - int boxQty = 0; - if (qtyObj instanceof Number) { - qty = ((Number) qtyObj).intValue(); - } else if (qtyObj instanceof String) { - try { - qty = Integer.parseInt((String) qtyObj); - } catch (NumberFormatException e) { - qty = 0; // 或者根据需求处理异常 - } - } - if (boxQtyObj instanceof Number) { - boxQty = ((Number) boxQtyObj).intValue(); - } else if (boxQtyObj instanceof String) { - try { - boxQty = Integer.parseInt((String) boxQtyObj); - } catch (NumberFormatException e) { - boxQty = 0; // 或者根据需求处理异常 - } - } - totalQty += qty; - totalBoxQty += boxQty; + BigDecimal qty = parseDecimalValue(qtyObj); + BigDecimal boxQty = parseDecimalValue(boxQtyObj); + totalQty = totalQty.add(qty); + totalBoxQty = totalBoxQty.add(boxQty); item.put("qty", qty); item.put("boxQty", boxQty); } @@ -2084,6 +2066,38 @@ public class CoDelExcelServiceImpl implements CoDelExcelService { } } + /** + * 统一将对象解析为BigDecimal,支持整数/小数/字符串数字(含千分位)。 + */ + private BigDecimal parseDecimalValue(Object value) { + if (value == null) { + return BigDecimal.ZERO; + } + if (value instanceof BigDecimal) { + return (BigDecimal) value; + } + if (value instanceof Number) { + try { + return new BigDecimal(value.toString()); + } catch (NumberFormatException e) { + return BigDecimal.ZERO; + } + } + if (value instanceof String) { + String str = ((String) value).trim(); + if (str.isEmpty()) { + return BigDecimal.ZERO; + } + str = str.replace(",", ""); + try { + return new BigDecimal(str); + } catch (NumberFormatException e) { + return BigDecimal.ZERO; + } + } + return BigDecimal.ZERO; + } + /** * 导出出口货物委托书 */ diff --git a/src/main/resources/templates/packing-template.xlsx b/src/main/resources/templates/packing-template.xlsx index 1c8af08a..d2648a36 100644 Binary files a/src/main/resources/templates/packing-template.xlsx and b/src/main/resources/templates/packing-template.xlsx differ