mirror of https://github.com/jeecgboot/jeecg-boot
fix
parent
8b144a43d4
commit
4f322a9290
|
@ -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
|
LIMIT 2
|
||||||
</select>
|
</select>
|
||||||
<select id="findPrevious" resultType="org.jeecg.modules.business.entity.LogisticChannelPrice">
|
<select id="findPrevious" resultType="org.jeecg.modules.business.entity.LogisticChannelPrice">
|
||||||
WITH current_price AS
|
WITH current_price AS
|
||||||
|
|
|
@ -90,12 +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,
|
||||||
|
|
|
@ -80,12 +80,18 @@ public class LogisticChannelServiceImpl extends ServiceImpl<LogisticChannelMappe
|
||||||
@Override
|
@Override
|
||||||
public List<LogisticChannelPrice> findLogisticsChannelPrice(String channelName, Date date, int trueWeight, List<String> countryList) {
|
public List<LogisticChannelPrice> findLogisticsChannelPrice(String channelName, Date date, int trueWeight, List<String> countryList) {
|
||||||
List<LogisticChannelPrice> priceList = new ArrayList<>();
|
List<LogisticChannelPrice> priceList = new ArrayList<>();
|
||||||
LogisticChannelPrice currentPrice = logisticChannelPriceMapper.findBy(channelName, new java.util.Date(), BigDecimal.valueOf(trueWeight), countryList);
|
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) {
|
if(currentPrice != null) {
|
||||||
priceList.add(currentPrice);
|
priceList.add(currentPrice);
|
||||||
LogisticChannelPrice previousPrice = logisticChannelPriceMapper.findPrevious(channelName, new java.util.Date(), BigDecimal.valueOf(trueWeight), countryList);
|
LogisticChannelPrice previousPrice = logisticChannelPriceMapper.findPrevious(channelName, new java.util.Date(), BigDecimal.valueOf(trueWeight), countryList);
|
||||||
if(previousPrice != null) {
|
if(previousPrice != null) {
|
||||||
priceList.add(previousPrice);
|
priceList.add(previousPrice);
|
||||||
|
} else {
|
||||||
|
currentPriceList.stream()
|
||||||
|
.min(Comparator.comparing(LogisticChannelPrice::getEffectiveDate)).ifPresent(priceList::add);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return priceList;
|
return priceList;
|
||||||
|
|
Loading…
Reference in New Issue