This commit is contained in:
dzc committed 2025-10-14 13:40:49 +08:00
commit b525aec4ba
1 file changed
+11 -2
@@ -566,7 +566,8 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
?smErpUnitEntity.getRetailPrice():smErpUnitEntity.getPromotionPrice());
//使用 BigDecimal 避免浮点数精度问题
//setScale(0, RoundingMode.HALF_UP) 确保四舍五入到整数
BigDecimal quantity = BigDecimal.valueOf(smErpInventoryRecordsItemEntity.getQuantity());
//注意:金额应该使用数量的绝对值计算,因为金额不应该是负数,出入库方向由OrderType区分
BigDecimal quantity = BigDecimal.valueOf(Math.abs(smErpInventoryRecordsItemEntity.getQuantity()));
BigDecimal unitPrice = BigDecimal.valueOf(smErpInventoryRecordsItemEntity.getUnitPrice());
BigDecimal totalAmount = quantity.multiply(unitPrice);
smErpInventoryRecordsItemEntity.setTotalAmount(totalAmount.setScale(0, RoundingMode.HALF_UP).intValue());
@@ -651,10 +652,18 @@ public class SmErpSpuServiceImpl extends ServiceImpl<SmErpSpuMapper, SmErpSpuEnt
smErpInventoryRecordsItemEntity.setUnitPrice
(smErpUnitEntity.getPromotionPrice()==null || smErpUnitEntity.getPromotionPrice()==0
?smErpUnitEntity.getRetailPrice():smErpUnitEntity.getPromotionPrice());
//使用 BigDecimal 避免浮点数精度问题
//注意:金额应该使用数量的绝对值计算,因为金额不应该是负数,出入库方向由OrderType区分
BigDecimal quantity = BigDecimal.valueOf(Math.abs(smErpInventoryRecordsItemEntity.getQuantity()));
BigDecimal unitPrice = BigDecimal.valueOf(smErpInventoryRecordsItemEntity.getUnitPrice());
BigDecimal totalAmount = quantity.multiply(unitPrice);
smErpInventoryRecordsItemEntity.setTotalAmount(totalAmount.setScale(0, RoundingMode.HALF_UP).intValue());
smErpInventoryRecordsItemEntityList.add(smErpInventoryRecordsItemEntity);
}
smErpStockService.updateStock(updateStockDTOS);
int sum = smErpInventoryRecordsItemEntityList.stream().map(smErpInventoryRecordsItemEntity -> smErpInventoryRecordsItemEntity.getUnitPrice()).mapToInt(Integer::intValue).sum();
int sum = smErpInventoryRecordsItemEntityList.stream()
.mapToInt(SmErpInventoryRecordsItemEntity::getTotalAmount)
.sum();
smErpInventoryRecordsEntity.setTotalAmount(sum);
smErpInventoryRecordsEntity.setReceiveAmount(sum);
//生成出入库记录