|
|
@@ -30,6 +30,7 @@ import org.springblade.core.secure.utils.SecureUtil;
|
|
|
import org.springblade.core.tool.api.R;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.deliver.goods.entity.Delivery;
|
|
|
+import org.springblade.deliver.goods.entity.DeliveryFees;
|
|
|
import org.springblade.deliver.goods.entity.DeliveryItems;
|
|
|
import org.springblade.deliver.goods.enums.DeliveryEnum;
|
|
|
import org.springblade.deliver.goods.enums.DeliveryStatusEnum;
|
|
|
@@ -173,7 +174,7 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
if (temp) {
|
|
|
// 判断要发货物的金额和已收金额的大小
|
|
|
if (delivery.getDeliveryType().equals(DeliveryEnum.DELIVER.getType())) {
|
|
|
- R amount = this.deliveryAmount(collect, delivery.getTradeType());
|
|
|
+ R amount = this.deliveryAmount(collect, delivery.getDeliveryFeesList(), delivery.getTradeType());
|
|
|
if (!amount.isSuccess()) {
|
|
|
throw new RuntimeException(amount.getMsg());
|
|
|
}
|
|
|
@@ -599,42 +600,52 @@ public class DeliveryItemsServiceImpl extends ServiceImpl<DeliveryItemsMapper, D
|
|
|
|
|
|
/**
|
|
|
* 查询已发货金额和本次发货金额和是否比已收金额小或者等于
|
|
|
+ *
|
|
|
* @param deliveryItemsList
|
|
|
* @return
|
|
|
*/
|
|
|
- public R deliveryAmount(List<DeliveryItems> deliveryItemsList,String tradeType){
|
|
|
- //先获取发货明细中的订单号,并将其分组
|
|
|
- //获取每个订单号的已发货金额 和每个订单的已收金额
|
|
|
- //若已发货金额加本次发货金额小于等于订单已收金额可以发货反之不能发货
|
|
|
+ public R deliveryAmount(List<DeliveryItems> deliveryItemsList, List<DeliveryFees> deliveryFeesList, String tradeType) {
|
|
|
+ // 先获取发货明细中的订单号,并将其分组
|
|
|
+ // 获取每个订单号的已发货金额 和每个订单的已收金额
|
|
|
+ // 若已发货金额加本次发货金额小于等于订单已收金额可以发货反之不能发货
|
|
|
List<String> collect = deliveryItemsList.stream().map(DeliveryItems::getSrcOrderNo).collect(Collectors.toList());
|
|
|
- if (CollectionUtils.isNotEmpty(collect)){
|
|
|
+ if (CollectionUtils.isNotEmpty(collect)) {
|
|
|
for (String srcOrderNo : collect) {
|
|
|
- BigDecimal newDelivery = new BigDecimal(BigInteger.ZERO);//本次发货金额
|
|
|
- BigDecimal oldDelivery = new BigDecimal(BigInteger.ZERO);//已发货金额
|
|
|
- BigDecimal gathering = new BigDecimal(BigInteger.ZERO);//已收金额
|
|
|
- R<BigDecimal> financeAcc = financeClient.getFinanceAcc(srcOrderNo,tradeType);
|
|
|
- if (financeAcc.isSuccess() && financeAcc.getData() != null && financeAcc.getData().compareTo(BigDecimal.ZERO) >0){
|
|
|
+ // 本次发货金额
|
|
|
+ BigDecimal newDelivery;
|
|
|
+ // 已发货金额
|
|
|
+ BigDecimal oldDelivery;
|
|
|
+ // 已收金额
|
|
|
+ BigDecimal gathering;
|
|
|
+ R<BigDecimal> financeAcc = financeClient.getFinanceAcc(srcOrderNo, tradeType);
|
|
|
+ if (financeAcc.isSuccess() && financeAcc.getData() != null && financeAcc.getData().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
gathering = financeAcc.getData();
|
|
|
- }else {
|
|
|
+ } else {
|
|
|
throw new RuntimeException("未找到收款记录");
|
|
|
}
|
|
|
- //本次金额
|
|
|
+ // 本次金额
|
|
|
List<DeliveryItems> itemsList = deliveryItemsList.stream().filter(e -> e.getSrcOrderNo().equals(srcOrderNo)).collect(Collectors.toList());
|
|
|
- //已发金额
|
|
|
- List<DeliveryItems> deliveryItems = baseMapper.selectItem(SecureUtil.getTenantId(),DeliveryStatusEnum.DELIVER.getType(),srcOrderNo,tradeType);
|
|
|
- newDelivery = itemsList.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getContractAmount().multiply(y.getExRate())); },BigDecimal::add);//本次发货金额
|
|
|
- oldDelivery = deliveryItems.stream().reduce(BigDecimal.ZERO,(x,y) ->{ return x.add(y.getContractAmount().multiply(y.getExRate())); },BigDecimal::add);//历史发货金额
|
|
|
- //原来的判断 条件 : if (gathering.subtract(newDelivery.add(oldDelivery)).compareTo(BigDecimal.ZERO) <= 0){
|
|
|
- if (gathering.subtract(newDelivery.add(oldDelivery)).compareTo(BigDecimal.ZERO) == -1){
|
|
|
- throw new RuntimeException("订单"+srcOrderNo+"发货金额超出 ,可发货金额为(CNY):"+(gathering.subtract(oldDelivery)).setScale(2,BigDecimal.ROUND_UP));
|
|
|
+ // 已发金额
|
|
|
+ List<DeliveryItems> deliveryItems = baseMapper.selectItem(SecureUtil.getTenantId(), DeliveryStatusEnum.DELIVER.getType(), srcOrderNo, tradeType);
|
|
|
+ // 本次发货金额
|
|
|
+ newDelivery = itemsList.stream().reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getContractAmount().multiply(y.getExRate())), BigDecimal::add);
|
|
|
+ // 历史发货金额
|
|
|
+ oldDelivery = deliveryItems.stream().reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getContractAmount().multiply(y.getExRate())), BigDecimal::add);
|
|
|
+ // 应收费用金额
|
|
|
+ BigDecimal ar = deliveryFeesList.stream().filter(e -> e.getFeesType() == 1).reduce(BigDecimal.ZERO, (x, y) -> x.add(y.getAmount()), BigDecimal::add);
|
|
|
+ gathering = gathering.subtract(ar);
|
|
|
+
|
|
|
+ // 原来的判断 条件 : if (gathering.subtract(newDelivery.add(oldDelivery)).compareTo(BigDecimal.ZERO) <= 0){
|
|
|
+ if (gathering.subtract(newDelivery.add(oldDelivery)).compareTo(BigDecimal.ZERO) < 0) {
|
|
|
+ throw new RuntimeException("订单" + srcOrderNo + "发货金额超出 ,可发货金额为(CNY):" + (gathering.subtract(oldDelivery)).setScale(2, RoundingMode.UP));
|
|
|
}
|
|
|
/*if (gathering.compareTo((newDelivery.add(oldDelivery))) < 0){
|
|
|
throw new RuntimeException("订单"+srcOrderNo+"可发货金额为:"+gathering.subtract(oldDelivery.add(newDelivery)));
|
|
|
}*/
|
|
|
}
|
|
|
return R.success("可以发货");
|
|
|
- }else {
|
|
|
- throw new RuntimeException("未找到发货明细");
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("未找到发货明细");
|
|
|
}
|
|
|
|
|
|
}
|