Browse Source

允许小数

master
han\hanst 5 days ago
parent
commit
a2c33820f5
  1. 62
      src/main/java/com/xujie/sys/modules/ecss/service/impl/CoDelExcelServiceImpl.java
  2. BIN
      src/main/resources/templates/packing-template.xlsx

62
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<String, Object> 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;
}
/**
* 导出出口货物委托书
*/

BIN
src/main/resources/templates/packing-template.xlsx

Loading…
Cancel
Save