mirror of https://github.com/jeecgboot/jeecg-boot
Merge pull request #24 from LQYBill/fix/shippingCalculation
fix: shipping fee calculation precisionpull/6221/head
commit
0eb6aadbff
|
@ -6,6 +6,7 @@ import lombok.Data;
|
||||||
import org.jeecg.modules.business.entity.LogisticChannelPrice;
|
import org.jeecg.modules.business.entity.LogisticChannelPrice;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,45 +24,34 @@ public class CostTrialCalculation {
|
||||||
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
|
||||||
private final Date effectiveDate;
|
private final Date effectiveDate;
|
||||||
|
|
||||||
private final double unitPrice;
|
private final BigDecimal unitPrice;
|
||||||
|
|
||||||
private final double shippingCost;
|
private final BigDecimal shippingCost;
|
||||||
|
|
||||||
private final double registrationCost;
|
private final BigDecimal registrationCost;
|
||||||
|
|
||||||
private final double additionalCost;
|
private final BigDecimal additionalCost;
|
||||||
|
|
||||||
|
|
||||||
private CostTrialCalculation(String countryCode, String logisticsChannelName, String logisticChannelCode, double unitPrice, double shippingCost,
|
private CostTrialCalculation(String countryCode, String logisticsChannelName, String logisticChannelCode, BigDecimal unitPrice, BigDecimal shippingCost,
|
||||||
double registrationCost, double additionalCost, Date effectiveDate) {
|
BigDecimal registrationCost, BigDecimal additionalCost, Date effectiveDate) {
|
||||||
this.countryCode = countryCode;
|
this.countryCode = countryCode;
|
||||||
this.logisticsChannelName = logisticsChannelName;
|
this.logisticsChannelName = logisticsChannelName;
|
||||||
this.logisticChannelCode = logisticChannelCode;
|
this.logisticChannelCode = logisticChannelCode;
|
||||||
this.unitPrice = unitPrice;
|
this.unitPrice = unitPrice;
|
||||||
this.shippingCost = format(shippingCost);
|
this.shippingCost = shippingCost;
|
||||||
this.registrationCost = format(registrationCost);
|
this.registrationCost = registrationCost;
|
||||||
this.additionalCost = format(additionalCost);
|
this.additionalCost = additionalCost;
|
||||||
this.effectiveDate = effectiveDate;
|
this.effectiveDate = effectiveDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CostTrialCalculation(LogisticChannelPrice price, int weight, String logisticsChannelName, String code) {
|
public CostTrialCalculation(LogisticChannelPrice price, int weight, String logisticsChannelName, String code) {
|
||||||
this(price.getEffectiveCountry(), logisticsChannelName, code, price.getCalUnitPrice().doubleValue(), price.calculateShippingPrice(BigDecimal.valueOf(weight)).doubleValue(),
|
this(price.getEffectiveCountry(), logisticsChannelName, code, price.getCalUnitPrice(), price.calculateShippingPrice(BigDecimal.valueOf(weight)),
|
||||||
price.getRegistrationFee().doubleValue(), price.getAdditionalCost().doubleValue(), price.getEffectiveDate());
|
price.getRegistrationFee(), price.getAdditionalCost(), price.getEffectiveDate());
|
||||||
}
|
}
|
||||||
|
|
||||||
@JsonProperty("TotalCost")
|
@JsonProperty("TotalCost")
|
||||||
public double getTotalCost() {
|
public double getTotalCost() {
|
||||||
return format(shippingCost + registrationCost + additionalCost);
|
return shippingCost.add(registrationCost).add(additionalCost).setScale(2, RoundingMode.CEILING).doubleValue();
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Format a decimal with 2 unit.
|
|
||||||
*
|
|
||||||
* @param n the number to format
|
|
||||||
* @return the number formatted
|
|
||||||
*/
|
|
||||||
private double format(double n) {
|
|
||||||
return BigDecimal.valueOf(n).setScale(2, BigDecimal.ROUND_UP).doubleValue();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue