package com.bonus.core.order.common.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bonus.core.order.common.mapper.OrderDeliveryMapper;
import com.bonus.core.order.common.model.OrderDelivery;
import com.bonus.core.order.common.service.OrderDeliveryService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;

@Service
public class OrderDeliveryServiceImpl extends ServiceImpl<OrderDeliveryMapper, OrderDelivery> implements OrderDeliveryService {

   @Override
   public OrderDelivery getByOrderId(Long orderId, LocalDate orderDate) {
      return orderId == null ? null : (OrderDelivery)((OrderDeliveryMapper)this.baseMapper)
              .selectOne((Wrapper)((LambdaQueryWrapper)((LambdaQueryWrapper<OrderDelivery>)Wrappers.lambdaQuery(OrderDelivery.class)
                      .eq(OrderDelivery::getOrderId, orderId)).eq(orderDate != null,
                      OrderDelivery::getOrderDate, orderDate)).last("limit 1"));
   }
}
