Commit 3479ef81234da086d606989ddcdec1e796a65ca2
1 parent
f6d32904
✨ ERP:增加金额计算的四舍五入
Showing
2 changed files
with
23 additions
and
2 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java
| ... | ... | @@ -14,6 +14,11 @@ import java.math.RoundingMode; |
| 14 | 14 | public class MoneyUtils { |
| 15 | 15 | |
| 16 | 16 | /** |
| 17 | + * 金额的小数位数 | |
| 18 | + */ | |
| 19 | + private static final int PRICE_SCALE = 2; | |
| 20 | + | |
| 21 | + /** | |
| 17 | 22 | * 计算百分比金额,四舍五入 |
| 18 | 23 | * |
| 19 | 24 | * @param price 金额 |
| ... | ... | @@ -86,4 +91,20 @@ public class MoneyUtils { |
| 86 | 91 | return new Money(0, fen).toString(); |
| 87 | 92 | } |
| 88 | 93 | |
| 94 | + /** | |
| 95 | + * 金额相乘,默认进行四舍五入 | |
| 96 | + * | |
| 97 | + * 位数:{@link #PRICE_SCALE} | |
| 98 | + * | |
| 99 | + * @param price 金额 | |
| 100 | + * @param count 数量 | |
| 101 | + * @return 金额相乘结果 | |
| 102 | + */ | |
| 103 | + public static BigDecimal priceMultiply(BigDecimal price, BigDecimal count) { | |
| 104 | + if (price == null || count == null) { | |
| 105 | + return null; | |
| 106 | + } | |
| 107 | + return price.multiply(count).setScale(PRICE_SCALE, RoundingMode.HALF_UP); | |
| 108 | + } | |
| 109 | + | |
| 89 | 110 | } | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/stock/ErpStockInServiceImpl.java
| ... | ... | @@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.erp.service.stock; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 5 | -import cn.iocoder.yudao.framework.common.util.number.NumberUtils; | |
| 5 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 6 | 6 | import cn.iocoder.yudao.framework.common.util.object.BeanUtils; |
| 7 | 7 | import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO; |
| 8 | 8 | import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO; |
| ... | ... | @@ -130,7 +130,7 @@ public class ErpStockInServiceImpl implements ErpStockInService { |
| 130 | 130 | // 2. 转化为 ErpStockInItemDO 列表 |
| 131 | 131 | return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item |
| 132 | 132 | .setProductUnitId(productMap.get(item.getProductId()).getUnitId()) |
| 133 | - .setTotalPrice(NumberUtils.mul(item.getProductPrice(), item.getCount())))); | |
| 133 | + .setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount())))); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | private void updateStockInItemList(Long id, List<ErpStockInItemDO> newList) { | ... | ... |