Commit ddcebb1986c7c11457fb7f93fd142e4af3495e13
1 parent
1cc2dfc9
common: MoneyUtils 移到 common 模块
Showing
3 changed files
with
15 additions
and
6 deletions
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/util/MoneyUtils.java renamed to yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java
| 1 | -package cn.iocoder.yudao.module.pay.util; | |
| 1 | +package cn.iocoder.yudao.framework.common.util.number; | |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.util.NumberUtil; |
| 4 | 4 | |
| ... | ... | @@ -23,6 +23,17 @@ public class MoneyUtils { |
| 23 | 23 | return calculateRatePrice(price, rate, 0, RoundingMode.HALF_UP).intValue(); |
| 24 | 24 | } |
| 25 | 25 | |
| 26 | + /** | |
| 27 | + * 计算百分比金额,向下传入 | |
| 28 | + * | |
| 29 | + * @param price 金额 | |
| 30 | + * @param rate 百分比,例如说 56.77% 则传入 56.77 | |
| 31 | + * @return 百分比金额 | |
| 32 | + */ | |
| 33 | + public static Integer calculateRatePriceFloor(Integer price, Double rate) { | |
| 34 | + return calculateRatePrice(price, rate, 0, RoundingMode.FLOOR).intValue(); | |
| 35 | + } | |
| 36 | + | |
| 26 | 37 | /** |
| 27 | 38 | * 计算百分比金额 |
| 28 | 39 | * | ... | ... |
yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java
| ... | ... | @@ -2,10 +2,10 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.util.BooleanUtil; |
| 5 | -import cn.hutool.core.util.NumberUtil; | |
| 6 | 5 | import cn.hutool.core.util.ObjectUtil; |
| 7 | 6 | import cn.hutool.extra.spring.SpringUtil; |
| 8 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 9 | 9 | import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; |
| 10 | 10 | import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; |
| 11 | 11 | import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; |
| ... | ... | @@ -24,7 +24,6 @@ import org.springframework.transaction.annotation.Transactional; |
| 24 | 24 | import org.springframework.validation.annotation.Validated; |
| 25 | 25 | |
| 26 | 26 | import javax.annotation.Resource; |
| 27 | -import java.math.RoundingMode; | |
| 28 | 27 | import java.time.LocalDateTime; |
| 29 | 28 | import java.util.ArrayList; |
| 30 | 29 | import java.util.List; |
| ... | ... | @@ -126,9 +125,8 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ |
| 126 | 125 | return ObjectUtil.defaultIfNull(fixedBrokeragePrice, 0); |
| 127 | 126 | } |
| 128 | 127 | // 2. 根据比例计算佣金 |
| 129 | - // TODO @疯狂:要不要把 MoneyUtils 抽到 common 里,然后这里也使用这个类的方法; | |
| 130 | 128 | if (basePrice != null && basePrice > 0 && percent != null && percent > 0) { |
| 131 | - return NumberUtil.div(NumberUtil.mul(basePrice, percent), 100, 0, RoundingMode.DOWN).intValue(); | |
| 129 | + return MoneyUtils.calculateRatePriceFloor(basePrice, Double.valueOf(percent)); | |
| 132 | 130 | } |
| 133 | 131 | return 0; |
| 134 | 132 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java
| ... | ... | @@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil; |
| 6 | 6 | import cn.hutool.extra.spring.SpringUtil; |
| 7 | 7 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 8 | 8 | import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; |
| 9 | +import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; | |
| 9 | 10 | import cn.iocoder.yudao.framework.pay.core.client.PayClient; |
| 10 | 11 | import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; |
| 11 | 12 | import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderRespDTO; |
| ... | ... | @@ -31,7 +32,6 @@ import cn.iocoder.yudao.module.pay.framework.pay.config.PayProperties; |
| 31 | 32 | import cn.iocoder.yudao.module.pay.service.app.PayAppService; |
| 32 | 33 | import cn.iocoder.yudao.module.pay.service.channel.PayChannelService; |
| 33 | 34 | import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService; |
| 34 | -import cn.iocoder.yudao.module.pay.util.MoneyUtils; | |
| 35 | 35 | import com.google.common.annotations.VisibleForTesting; |
| 36 | 36 | import lombok.extern.slf4j.Slf4j; |
| 37 | 37 | import org.springframework.stereotype.Service; | ... | ... |