mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 23:31:52 +08:00
✨ ERP:增加金额计算的四舍五入
This commit is contained in:
parent
f6d3290426
commit
3479ef8123
@ -13,6 +13,11 @@ import java.math.RoundingMode;
|
||||
*/
|
||||
public class MoneyUtils {
|
||||
|
||||
/**
|
||||
* 金额的小数位数
|
||||
*/
|
||||
private static final int PRICE_SCALE = 2;
|
||||
|
||||
/**
|
||||
* 计算百分比金额,四舍五入
|
||||
*
|
||||
@ -86,4 +91,20 @@ public class MoneyUtils {
|
||||
return new Money(0, fen).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 金额相乘,默认进行四舍五入
|
||||
*
|
||||
* 位数:{@link #PRICE_SCALE}
|
||||
*
|
||||
* @param price 金额
|
||||
* @param count 数量
|
||||
* @return 金额相乘结果
|
||||
*/
|
||||
public static BigDecimal priceMultiply(BigDecimal price, BigDecimal count) {
|
||||
if (price == null || count == null) {
|
||||
return null;
|
||||
}
|
||||
return price.multiply(count).setScale(PRICE_SCALE, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,7 +2,7 @@ package cn.iocoder.yudao.module.erp.service.stock;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.number.MoneyUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInPageReqVO;
|
||||
import cn.iocoder.yudao.module.erp.controller.admin.stock.vo.in.ErpStockInSaveReqVO;
|
||||
@ -130,7 +130,7 @@ public class ErpStockInServiceImpl implements ErpStockInService {
|
||||
// 2. 转化为 ErpStockInItemDO 列表
|
||||
return convertList(list, o -> BeanUtils.toBean(o, ErpStockInItemDO.class, item -> item
|
||||
.setProductUnitId(productMap.get(item.getProductId()).getUnitId())
|
||||
.setTotalPrice(NumberUtils.mul(item.getProductPrice(), item.getCount()))));
|
||||
.setTotalPrice(MoneyUtils.priceMultiply(item.getProductPrice(), item.getCount()))));
|
||||
}
|
||||
|
||||
private void updateStockInItemList(Long id, List<ErpStockInItemDO> newList) {
|
||||
|
Loading…
Reference in New Issue
Block a user