From cbb066032eeb4007f982ab080ec29db64153c9ce Mon Sep 17 00:00:00 2001 From: Gauthier LO Date: Mon, 29 Jul 2024 11:56:01 +0200 Subject: [PATCH] Feat : shipping fee difference --- .../domain/logistic/CostTrialCalculation.java | 31 ++++++++++++++++--- .../mapper/LogisticChannelPriceMapper.java | 2 +- .../mapper/xml/LogisticChannelPriceMapper.xml | 2 +- .../service/ILogisticChannelService.java | 2 +- .../impl/LogisticChannelPriceServiceImpl.java | 7 +++-- .../impl/LogisticChannelServiceImpl.java | 12 +++++-- 6 files changed, 44 insertions(+), 12 deletions(-) diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/logistic/CostTrialCalculation.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/logistic/CostTrialCalculation.java index 2100661e7..9a5cdc5bf 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/logistic/CostTrialCalculation.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/domain/logistic/CostTrialCalculation.java @@ -32,9 +32,19 @@ public class CostTrialCalculation { private final BigDecimal additionalCost; + private final BigDecimal previousUnitPrice; - private CostTrialCalculation(String countryCode, String logisticsChannelName, String logisticChannelCode, BigDecimal unitPrice, BigDecimal shippingCost, - BigDecimal registrationCost, BigDecimal additionalCost, Date effectiveDate) { + private final BigDecimal previousShippingCost; + + private final BigDecimal previousRegistrationCost; + + private final BigDecimal previousAdditionalCost; + + + + private CostTrialCalculation(String countryCode, String logisticsChannelName, String logisticChannelCode, + BigDecimal unitPrice, BigDecimal shippingCost, BigDecimal registrationCost, BigDecimal additionalCost, Date effectiveDate, + BigDecimal previousUnitPrice,BigDecimal previousShippingCost, BigDecimal previousRegistrationCost, BigDecimal previousAdditionalCost) { this.countryCode = countryCode; this.logisticsChannelName = logisticsChannelName; this.logisticChannelCode = logisticChannelCode; @@ -43,15 +53,28 @@ public class CostTrialCalculation { this.registrationCost = registrationCost; this.additionalCost = additionalCost; this.effectiveDate = effectiveDate; + this.previousUnitPrice = previousUnitPrice; + this.previousShippingCost = previousShippingCost; + this.previousRegistrationCost = previousRegistrationCost; + this.previousAdditionalCost = previousAdditionalCost; } - public CostTrialCalculation(LogisticChannelPrice price, int weight, String logisticsChannelName, String code) { + public CostTrialCalculation(LogisticChannelPrice price, LogisticChannelPrice previousPrice,int weight, String logisticsChannelName, String code) { this(price.getEffectiveCountry(), logisticsChannelName, code, price.getCalUnitPrice(), price.calculateShippingPrice(BigDecimal.valueOf(weight)), - price.getRegistrationFee(), price.getAdditionalCost(), price.getEffectiveDate()); + price.getRegistrationFee(), price.getAdditionalCost(), price.getEffectiveDate(), + previousPrice.getCalUnitPrice(), previousPrice.calculateShippingPrice(BigDecimal.valueOf(weight)), previousPrice.getRegistrationFee(), previousPrice.getAdditionalCost() + ); } @JsonProperty("TotalCost") public double getTotalCost() { return shippingCost.add(registrationCost).add(additionalCost).setScale(2, RoundingMode.CEILING).doubleValue(); } + + @JsonProperty("CostDifference") + public double getCostDifference() { + double previousCost = previousShippingCost.add(previousRegistrationCost).add(previousAdditionalCost).setScale(2, RoundingMode.CEILING).doubleValue(); + BigDecimal diff = BigDecimal.valueOf((getTotalCost() - previousCost) / previousCost * 100); + return diff.setScale(2, RoundingMode.CEILING).doubleValue(); + } } diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/LogisticChannelPriceMapper.java b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/LogisticChannelPriceMapper.java index 7002cedd9..955969d8f 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/LogisticChannelPriceMapper.java +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/LogisticChannelPriceMapper.java @@ -34,7 +34,7 @@ public interface LogisticChannelPriceMapper extends BaseMapper findBy( @Param("channelName") String channelName, @Param("date") Date shippingTime, @Param("trueWeight") BigDecimal weight, diff --git a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/LogisticChannelPriceMapper.xml b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/LogisticChannelPriceMapper.xml index bdac56ddb..a36890c23 100644 --- a/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/LogisticChannelPriceMapper.xml +++ b/jeecg-module-system/jeecg-system-biz/src/main/java/org/jeecg/modules/business/mapper/xml/LogisticChannelPriceMapper.xml @@ -33,7 +33,7 @@ AND effective_date <= #{date} AND active = 1 ORDER BY effective_date DESC - LIMIT 1 + LIMIT 2