Merge pull request #101 from LQYBill/feat/previousLogisticChannelPrice

Feat/previous logistic channel price
pull/8040/head
Qiuyi LI 2024-08-05 14:20:46 +02:00 committed by GitHub
commit e58a5f209d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 95 additions and 6 deletions

View File

@ -24,6 +24,9 @@ public class CostTrialCalculation {
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
private final Date effectiveDate;
@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
private final Date previousEffectiveDate;
private final BigDecimal unitPrice;
private final BigDecimal shippingCost;
@ -44,7 +47,7 @@ public class CostTrialCalculation {
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) {
BigDecimal previousUnitPrice,BigDecimal previousShippingCost, BigDecimal previousRegistrationCost, BigDecimal previousAdditionalCost, Date previousEffectiveDate) {
this.countryCode = countryCode;
this.logisticsChannelName = logisticsChannelName;
this.logisticChannelCode = logisticChannelCode;
@ -57,12 +60,13 @@ public class CostTrialCalculation {
this.previousShippingCost = previousShippingCost;
this.previousRegistrationCost = previousRegistrationCost;
this.previousAdditionalCost = previousAdditionalCost;
this.previousEffectiveDate = previousEffectiveDate;
}
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(),
previousPrice.getCalUnitPrice(), previousPrice.calculateShippingPrice(BigDecimal.valueOf(weight)), previousPrice.getRegistrationFee(), previousPrice.getAdditionalCost()
previousPrice.getCalUnitPrice(), previousPrice.calculateShippingPrice(BigDecimal.valueOf(weight)), previousPrice.getRegistrationFee(), previousPrice.getAdditionalCost(), previousPrice.getEffectiveDate()
);
}

View File

@ -39,6 +39,11 @@ public interface LogisticChannelPriceMapper extends BaseMapper<LogisticChannelPr
@Param("date") Date shippingTime,
@Param("trueWeight") BigDecimal weight,
@Param("countryList") List<String> countryList);
LogisticChannelPrice findPrevious(
@Param("channelName") String channelName,
@Param("date") Date shippingTime,
@Param("trueWeight") BigDecimal weight,
@Param("countryList") List<String> countryList);
/**
* Find logistic channel price by indicating platform order's shipping time

View File

@ -33,8 +33,71 @@
AND effective_date &lt;= #{date}
AND active = 1
ORDER BY effective_date DESC
LIMIT 2 </select>
LIMIT 2
</select>
<select id="findPrevious" resultType="org.jeecg.modules.business.entity.LogisticChannelPrice">
WITH current_price AS
(
SELECT lcp.*
FROM logistic_channel_price lcp
JOIN logistic_channel lc ON lc.id = lcp.channel_id
WHERE zh_name = #{channelName}
AND weight_range_start &lt;= #{trueWeight}
AND weight_range_end &gt;= #{trueWeight}
AND effective_country IN
<foreach collection="countryList"
separator=","
open="("
close=")"
index="index"
item="country"
>
#{country}
</foreach>
AND effective_date &lt;= #{date}
AND active = 1
ORDER BY effective_date DESC
LIMIT 1
)
SELECT lcp.*
FROM logistic_channel_price lcp
JOIN logistic_channel lc ON lc.id = lcp.channel_id
WHERE lc.zh_name = #{channelName}
AND weight_range_start &lt;= #{trueWeight}
AND weight_range_end &gt;= #{trueWeight}
AND effective_country IN
<foreach collection="countryList"
separator=","
open="("
close=")"
index="index"
item="country"
>#{country}
</foreach>
AND effective_date &lt;= #{date}
AND active = 1
AND (
lcp.cal_unit_price != (
SELECT cal_unit_price
FROM current_price
WHERE effective_country = lcp.effective_country
)
OR
lcp.registration_fee != (
SELECT registration_fee
FROM current_price
WHERE effective_country = lcp.effective_country
)
OR
lcp.picking_fee_per_item != (
SELECT picking_fee_per_item
FROM current_price
WHERE effective_country = lcp.effective_country
)
)
ORDER BY effective_date DESC
LIMIT 1;
</select>
<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,
lc.id AS channel_id, effective_date, effective_country,

View File

@ -7,7 +7,7 @@
FROM client c
JOIN shop s ON c.id = s.owner_id
JOIN platform_order po on s.id = po.shop_id
WHERE po.shipping_invoice_number = #{invoiceNumber}
WHERE po.shipping_invoice_number = #{invoiceNumber} OR po.purchase_invoice_number = #{invoiceNumber};
</select>
<select id="fetchShippingInvoiceId" resultType="java.lang.String">
SELECT id

View File

@ -79,7 +79,22 @@ public class LogisticChannelServiceImpl extends ServiceImpl<LogisticChannelMappe
@Override
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);
List<LogisticChannelPrice> priceList = new ArrayList<>();
List<LogisticChannelPrice> currentPriceList = logisticChannelPriceMapper.findBy(channelName, new java.util.Date(), BigDecimal.valueOf(trueWeight), countryList);
LogisticChannelPrice currentPrice = currentPriceList.stream()
.max(Comparator.comparing(LogisticChannelPrice::getEffectiveDate))
.orElse(null);
if(currentPrice != null) {
priceList.add(currentPrice);
LogisticChannelPrice previousPrice = logisticChannelPriceMapper.findPrevious(channelName, new java.util.Date(), BigDecimal.valueOf(trueWeight), countryList);
if(previousPrice != null) {
priceList.add(previousPrice);
} else {
currentPriceList.stream()
.min(Comparator.comparing(LogisticChannelPrice::getEffectiveDate)).ifPresent(priceList::add);
}
}
return priceList;
}
@Override
@ -99,6 +114,8 @@ public class LogisticChannelServiceImpl extends ServiceImpl<LogisticChannelMappe
trueWeight = weight;
}
List<LogisticChannelPrice> priceList = findLogisticsChannelPrice(channelName, new Date(), trueWeight, countryList);
System.out.println("Price list for " + channelName + " is : ");
System.out.println(priceList);
LogisticChannelPrice price = priceList.stream()
.max(Comparator.comparing(LogisticChannelPrice::getEffectiveDate))
.orElse(null);