Commit 2ed6e031 by 缪晖

Merge branch 'KA-顺丰计算商品重量的情况-20220517' into 'master'

Ka 顺丰计算商品重量的情况 20220517

See merge request !139
parents 455bd194 8327b59c
...@@ -5,19 +5,23 @@ import cn.freemud.management.entities.dto.request.console.ConsoleResponseDTO; ...@@ -5,19 +5,23 @@ import cn.freemud.management.entities.dto.request.console.ConsoleResponseDTO;
import cn.freemud.management.entities.dto.request.console.StoreInfoDTO; import cn.freemud.management.entities.dto.request.console.StoreInfoDTO;
import com.freemud.application.sdk.api.deliverycenter.dto.CreateDeliveryOrderRequestDto; import com.freemud.application.sdk.api.deliverycenter.dto.CreateDeliveryOrderRequestDto;
import com.freemud.application.sdk.api.ordercenter.entities.v1.OrderBeanV1; import com.freemud.application.sdk.api.ordercenter.entities.v1.OrderBeanV1;
import com.freemud.application.sdk.api.ordercenter.entities.v1.ProductBeanV1;
import com.freemud.application.sdk.api.ordercenter.enums.OrderType; import com.freemud.application.sdk.api.ordercenter.enums.OrderType;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang.math.NumberUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.Date; import java.util.*;
import java.util.LinkedList;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@Component @Component
public class DeliverySdkAdapter { public class DeliverySdkAdapter {
@Value("${calculate.depatch.weight.partnerId:}")
private List<String> calculateWeightPartnerId;
/** /**
* 创建配送单请求对象 * 创建配送单请求对象
* *
...@@ -28,9 +32,8 @@ public class DeliverySdkAdapter { ...@@ -28,9 +32,8 @@ public class DeliverySdkAdapter {
*/ */
public CreateDeliveryOrderRequestDto buildDeliveryOrderRequestDto(OrderBeanV1 order public CreateDeliveryOrderRequestDto buildDeliveryOrderRequestDto(OrderBeanV1 order
, ConsoleResponseDTO<BizDTO> bizDTO, String deliveryCallBackUrl) { , ConsoleResponseDTO<BizDTO> bizDTO, String deliveryCallBackUrl) {
StoreInfoDTO storeInfo = bizDTO.getBizVO().getStoreInfo();
CreateDeliveryOrderRequestDto deliveryOrderRequestDto = new CreateDeliveryOrderRequestDto(); CreateDeliveryOrderRequestDto deliveryOrderRequestDto = new CreateDeliveryOrderRequestDto();
deliveryOrderRequestDto.setDepatchWeight(new BigDecimal(1)); deliveryOrderRequestDto.setDepatchWeight(this.getDepatchWeightByOrder(order.getProductList(), order.getCompanyId()));
deliveryOrderRequestDto.setSerialNumber(order.getOtherCode()); deliveryOrderRequestDto.setSerialNumber(order.getOtherCode());
deliveryOrderRequestDto.setOrderId(order.getOid()); deliveryOrderRequestDto.setOrderId(order.getOid());
deliveryOrderRequestDto.setOrderRemark(order.getRemark()); deliveryOrderRequestDto.setOrderRemark(order.getRemark());
...@@ -38,6 +41,7 @@ public class DeliverySdkAdapter { ...@@ -38,6 +41,7 @@ public class DeliverySdkAdapter {
deliveryOrderRequestDto.setOrderActualAmount(order.getAmount().intValue()); deliveryOrderRequestDto.setOrderActualAmount(order.getAmount().intValue());
deliveryOrderRequestDto.setPartnerId(order.getCompanyId()); deliveryOrderRequestDto.setPartnerId(order.getCompanyId());
deliveryOrderRequestDto.setOrderChannel(order.getSource()); deliveryOrderRequestDto.setOrderChannel(order.getSource());
StoreInfoDTO storeInfo = bizDTO.getBizVO().getStoreInfo();
deliveryOrderRequestDto.setStoreId(storeInfo.getStoreId()); deliveryOrderRequestDto.setStoreId(storeInfo.getStoreId());
deliveryOrderRequestDto.setStoreCode(storeInfo.getStoreCode()); deliveryOrderRequestDto.setStoreCode(storeInfo.getStoreCode());
StringBuffer address = new StringBuffer(storeInfo.getCity()) StringBuffer address = new StringBuffer(storeInfo.getCity())
...@@ -78,4 +82,46 @@ public class DeliverySdkAdapter { ...@@ -78,4 +82,46 @@ public class DeliverySdkAdapter {
}).collect(Collectors.toCollection(LinkedList::new)))); }).collect(Collectors.toCollection(LinkedList::new))));
return deliveryOrderRequestDto; return deliveryOrderRequestDto;
} }
private BigDecimal getDepatchWeightByOrder(List<ProductBeanV1> productList, String partnerId) {
if (CollectionUtils.isEmpty(calculateWeightPartnerId) || !calculateWeightPartnerId.contains(partnerId)) {
// 原始逻辑,都是默认传递 1kg给到配送
return new BigDecimal("1");
}
if (CollectionUtils.isEmpty(productList)) {
return new BigDecimal("0.5");
}
BigDecimal result = BigDecimal.ZERO;
for (ProductBeanV1 p : productList) {
// if (p.getIsSendGoods()) {
// continue;
// }
BigDecimal sum = p.getWeight().multiply(new BigDecimal(p.getNumber()));
BigDecimal comboSum = this.sumWeightByProduct(p.getComboProduct());
BigDecimal materSum = this.sumWeightByProduct(p.getMaterialProduct());
// BigDecimal sendSum = this.sumWeightByProduct(p.getSendProduct());
// result = result.add(sum).add(comboSum).add(materSum).add(sendSum);
result = result.add(sum).add(comboSum).add(materSum);
}
if (result.compareTo(BigDecimal.ZERO) <= 0) {
return new BigDecimal("0.5");
}
// 这里 计算的结果是 g 需要变成 kg 给接口 保留3位小数 后面多余直接舍弃
return result.divide(new BigDecimal("1000"), 3, BigDecimal.ROUND_DOWN);
}
private BigDecimal sumWeightByProduct(List<ProductBeanV1> productBeanV) {
BigDecimal result = BigDecimal.ZERO;
if (CollectionUtils.isEmpty(productBeanV)) {
return result;
}
for (ProductBeanV1 p : productBeanV) {
BigDecimal weight = p.getWeight();
int number = p.getNumber();
BigDecimal multiply = weight.multiply(new BigDecimal(number));
result = result.add(multiply);
}
return result;
}
} }
...@@ -21,6 +21,7 @@ import com.freemud.application.sdk.api.deliverycenter.service.DeliveryService; ...@@ -21,6 +21,7 @@ import com.freemud.application.sdk.api.deliverycenter.service.DeliveryService;
import com.freemud.application.sdk.api.log.ApiLog; import com.freemud.application.sdk.api.log.ApiLog;
import com.freemud.application.sdk.api.log.LogThreadLocal; import com.freemud.application.sdk.api.log.LogThreadLocal;
import com.freemud.application.sdk.api.ordercenter.entities.v1.OrderBeanV1; import com.freemud.application.sdk.api.ordercenter.entities.v1.OrderBeanV1;
import com.freemud.application.sdk.api.ordercenter.util.LogUtil;
import com.freemud.application.sdk.api.service.EmailAlertService; import com.freemud.application.sdk.api.service.EmailAlertService;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.ObjectUtils;
...@@ -70,7 +71,8 @@ public class DeliveryHandle { ...@@ -70,7 +71,8 @@ public class DeliveryHandle {
private DeliveryMCCafeClient deliveryMCCafeClient; private DeliveryMCCafeClient deliveryMCCafeClient;
@Autowired @Autowired
private EmailAlertService emailAlertService; private EmailAlertService emailAlertService;
@Autowired
private LogUtil logUtil;
/** /**
* 创建配送单 * 创建配送单
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment