Commit 6f1bafb3 by dingkai

重量计算

parent 8109e09b
......@@ -25,6 +25,7 @@ import com.freemud.sdk.api.assortment.order.request.order.OrderDownloadRequest;
import com.freemud.sdk.api.assortment.order.request.order.*;
import com.freemud.sdk.api.assortment.order.response.order.*;
import com.freemud.sdk.api.assortment.order.response.payment.OrderPayResponse;
import com.freemud.sdk.api.assortment.order.util.WeightUtils;
import ma.glasnost.orika.MapperFacade;
import ma.glasnost.orika.impl.DefaultMapperFactory;
import org.apache.commons.collections4.CollectionUtils;
......@@ -2734,20 +2735,12 @@ public class OrderSdkAdapter {
if (ObjectUtils.equals(ProductTypeEnum.SETMEAL_PRODUCT.getCode(), productRequest.getProductType()) || ObjectUtils.equals(ProductTypeEnum.SETMEAL_UPPRICE_PRODUCT.getCode(), productRequest.getProductType())) {
if (CollectionUtils.isNotEmpty(productRequest.getComboProduct())) {
Double comboProductTotalWeight = productRequest.getComboProduct().stream().map(t -> {
Double productWeight = t.getWeight() == null ? 0D : t.getWeight();
if (ProductTypeEnum.WEIGHT_PRODUCT.getCode().equals(t.getProductType())) {
productWeight = productWeight * 500;
}
return productWeight;
return WeightUtils.changeToG(t.getWeight(), t.getUnit());
}).reduce(0D, Double::sum);
totalWeight += comboProductTotalWeight;
}
} else {
Double productWeight = productRequest.getWeight() == null ? 0D : productRequest.getWeight();
if (ProductTypeEnum.WEIGHT_PRODUCT.getCode().equals(productRequest.getProductType())) {
productWeight = productWeight * 500;
}
totalWeight += productWeight;
totalWeight += WeightUtils.changeToG(productRequest.getWeight(), productRequest.getUnit());;
}
}
return totalWeight;
......
package com.freemud.sdk.api.assortment.order.util;
import org.apache.commons.lang.StringUtils;
public class WeightUtils {
public static Double changeToG(Double weight, String unit) {
weight = weight == null ? 0D : weight;
if(unit == null) {
return weight;
}
switch (unit) {
case "g":
case "克":
return weight;
case "千克":
return weight * 1000;
case "两":
return weight * 50;
case "斤":
return weight * 500;
case "磅":
return weight * 453.59237d;
default:
return weight;
}
}
}
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