mirror of https://github.com/jeecgboot/jeecg-boot
Feat : shipping fee difference
parent
7a773aa3dc
commit
cbb066032e
|
@ -32,9 +32,19 @@ public class CostTrialCalculation {
|
||||||
|
|
||||||
private final BigDecimal additionalCost;
|
private final BigDecimal additionalCost;
|
||||||
|
|
||||||
|
private final BigDecimal previousUnitPrice;
|
||||||
|
|
||||||
private CostTrialCalculation(String countryCode, String logisticsChannelName, String logisticChannelCode, BigDecimal unitPrice, BigDecimal shippingCost,
|
private final BigDecimal previousShippingCost;
|
||||||
BigDecimal registrationCost, BigDecimal additionalCost, Date effectiveDate) {
|
|
||||||
|
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.countryCode = countryCode;
|
||||||
this.logisticsChannelName = logisticsChannelName;
|
this.logisticsChannelName = logisticsChannelName;
|
||||||
this.logisticChannelCode = logisticChannelCode;
|
this.logisticChannelCode = logisticChannelCode;
|
||||||
|
@ -43,15 +53,28 @@ public class CostTrialCalculation {
|
||||||
this.registrationCost = registrationCost;
|
this.registrationCost = registrationCost;
|
||||||
this.additionalCost = additionalCost;
|
this.additionalCost = additionalCost;
|
||||||
this.effectiveDate = effectiveDate;
|
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)),
|
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")
|
@JsonProperty("TotalCost")
|
||||||
public double getTotalCost() {
|
public double getTotalCost() {
|
||||||
return shippingCost.add(registrationCost).add(additionalCost).setScale(2, RoundingMode.CEILING).doubleValue();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public interface LogisticChannelPriceMapper extends BaseMapper<LogisticChannelPr
|
||||||
* @param countryList the country, represented by 2 letters code
|
* @param countryList the country, represented by 2 letters code
|
||||||
* @return one propre price
|
* @return one propre price
|
||||||
*/
|
*/
|
||||||
LogisticChannelPrice findBy(
|
List<LogisticChannelPrice> findBy(
|
||||||
@Param("channelName") String channelName,
|
@Param("channelName") String channelName,
|
||||||
@Param("date") Date shippingTime,
|
@Param("date") Date shippingTime,
|
||||||
@Param("trueWeight") BigDecimal weight,
|
@Param("trueWeight") BigDecimal weight,
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
AND effective_date <= #{date}
|
AND effective_date <= #{date}
|
||||||
AND active = 1
|
AND active = 1
|
||||||
ORDER BY effective_date DESC
|
ORDER BY effective_date DESC
|
||||||
LIMIT 1 </select>
|
LIMIT 2 </select>
|
||||||
|
|
||||||
<select id="findPricesBy" resultType="org.jeecg.modules.business.entity.LogisticChannelPrice">
|
<select id="findPricesBy" resultType="org.jeecg.modules.business.entity.LogisticChannelPrice">
|
||||||
SELECT lcp.id, lcp.create_by, lcp.create_time, lcp.update_by, lcp.update_time,
|
SELECT lcp.id, lcp.create_by, lcp.create_time, lcp.update_by, lcp.update_time,
|
||||||
|
|
|
@ -47,7 +47,7 @@ public interface ILogisticChannelService extends IService<LogisticChannel> {
|
||||||
* @param country 2 letters code of the destination country
|
* @param country 2 letters code of the destination country
|
||||||
* @return one suitable logistic channel price
|
* @return one suitable logistic channel price
|
||||||
*/
|
*/
|
||||||
LogisticChannelPrice findLogisticsChannelPrice(String channelName, Date date, int trueWeight, List<String> country);
|
List<LogisticChannelPrice> findLogisticsChannelPrice(String channelName, Date date, int trueWeight, List<String> country);
|
||||||
|
|
||||||
|
|
||||||
List<CostTrialCalculation> logisticChannelTrial(int weight, int volume, List<String> countryList);
|
List<CostTrialCalculation> logisticChannelTrial(int weight, int volume, List<String> countryList);
|
||||||
|
|
|
@ -90,13 +90,16 @@ public class LogisticChannelPriceServiceImpl extends ServiceImpl<LogisticChannel
|
||||||
|
|
||||||
String countryCode = countryService.findByEnName(order.getCountry()).getCode();
|
String countryCode = countryService.findByEnName(order.getCountry()).getCode();
|
||||||
|
|
||||||
LogisticChannelPrice price = logisticChannelPriceMapper.findBy(
|
List<LogisticChannelPrice> priceList = logisticChannelPriceMapper.findBy(
|
||||||
logisticChannelName,
|
logisticChannelName,
|
||||||
order.getShippingTime(),
|
order.getShippingTime(),
|
||||||
weight,
|
weight,
|
||||||
Collections.singletonList(countryCode)
|
Collections.singletonList(countryCode)
|
||||||
);
|
);
|
||||||
|
// find the one with latest effective date
|
||||||
|
LogisticChannelPrice price = priceList.stream()
|
||||||
|
.max(Comparator.comparing(LogisticChannelPrice::getEffectiveDate))
|
||||||
|
.orElse(null);
|
||||||
if (price == null) {
|
if (price == null) {
|
||||||
throw new UserException("Can't find price for channel {}, shipped at {}, weight {}, country {}",
|
throw new UserException("Can't find price for channel {}, shipped at {}, weight {}, country {}",
|
||||||
logisticChannelName,
|
logisticChannelName,
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class LogisticChannelServiceImpl extends ServiceImpl<LogisticChannelMappe
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LogisticChannelPrice findLogisticsChannelPrice(String channelName, Date date, int trueWeight, List<String> countryList) {
|
public List<LogisticChannelPrice> findLogisticsChannelPrice(String channelName, Date date, int trueWeight, List<String> countryList) {
|
||||||
return logisticChannelPriceMapper.findBy(channelName, new java.util.Date(), BigDecimal.valueOf(trueWeight), countryList);
|
return logisticChannelPriceMapper.findBy(channelName, new java.util.Date(), BigDecimal.valueOf(trueWeight), countryList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +98,15 @@ public class LogisticChannelServiceImpl extends ServiceImpl<LogisticChannelMappe
|
||||||
} else {
|
} else {
|
||||||
trueWeight = weight;
|
trueWeight = weight;
|
||||||
}
|
}
|
||||||
LogisticChannelPrice price = findLogisticsChannelPrice(channelName, new Date(), trueWeight, countryList);
|
List<LogisticChannelPrice> priceList = findLogisticsChannelPrice(channelName, new Date(), trueWeight, countryList);
|
||||||
|
LogisticChannelPrice price = priceList.stream()
|
||||||
|
.max(Comparator.comparing(LogisticChannelPrice::getEffectiveDate))
|
||||||
|
.orElse(null);
|
||||||
|
LogisticChannelPrice previousPrice = priceList.stream()
|
||||||
|
.min(Comparator.comparing(LogisticChannelPrice::getEffectiveDate))
|
||||||
|
.orElse(null);
|
||||||
if (price != null) {
|
if (price != null) {
|
||||||
return new CostTrialCalculation(price, trueWeight, internalName, code);
|
return new CostTrialCalculation(price, previousPrice, trueWeight, internalName, code);
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue