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
|
||||
* @return one propre price
|
||||
*/
|
||||
LogisticChannelPrice findBy(
|
||||
List<LogisticChannelPrice> findBy(
|
||||
@Param("channelName") String channelName,
|
||||
@Param("date") Date shippingTime,
|
||||
@Param("trueWeight") BigDecimal weight,
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
AND effective_date <= #{date}
|
||||
AND active = 1
|
||||
ORDER BY effective_date DESC
|
||||
LIMIT 1
|
||||
LIMIT 2
|
||||
</select>
|
||||
<select id="findPrevious" resultType="org.jeecg.modules.business.entity.LogisticChannelPrice">
|
||||
WITH current_price AS
|
||||
|
|
|
@ -90,12 +90,16 @@ public class LogisticChannelPriceServiceImpl extends ServiceImpl<LogisticChannel
|
|||
|
||||
String countryCode = countryService.findByEnName(order.getCountry()).getCode();
|
||||
|
||||
LogisticChannelPrice price = logisticChannelPriceMapper.findBy(
|
||||
List<LogisticChannelPrice> priceList = logisticChannelPriceMapper.findBy(
|
||||
logisticChannelName,
|
||||
order.getShippingTime(),
|
||||
weight,
|
||||
Collections.singletonList(countryCode)
|
||||
);
|
||||
// find the one with latest effective date
|
||||
LogisticChannelPrice price = priceList.stream()
|
||||
.max(Comparator.comparing(LogisticChannelPrice::getEffectiveDate))
|
||||
.orElse(null);
|
||||
if (price == null) {
|
||||
throw new UserException("Can't find price for channel {}, shipped at {}, weight {}, country {}",
|
||||
logisticChannelName,
|
||||
|
|
|
@ -80,12 +80,18 @@ public class LogisticChannelServiceImpl extends ServiceImpl<LogisticChannelMappe
|
|||
@Override
|
||||
public List<LogisticChannelPrice> findLogisticsChannelPrice(String channelName, Date date, int trueWeight, List<String> countryList) {
|
||||
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) {
|
||||
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;
|
||||
|
|
Loading…
Reference in New Issue