package com.fdkankan.platform.order.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.fdkankan.platform.order.entity.OrderItem;
import com.fdkankan.platform.order.mapper.IOrderItemMapper;
import com.fdkankan.platform.order.service.IOrderItemService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fdkankan.platform.user.vo.ResponseOrderItem;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 订单项表 服务实现类
 * </p>
 *
 * @author 
 * @since 2021-12-24
 */
@Service
public class OrderItemServiceImpl extends ServiceImpl<IOrderItemMapper, OrderItem> implements IOrderItemService {

    @Resource
    private IOrderItemMapper orderItemMapper;

    @Override
    public List<ResponseOrderItem> getByOrderId(Long orderId) {
        return orderItemMapper.getByOrderId(orderId);
    }

    @Override
    public Integer getCountByOrderIdAndShipped(Long orderId, String status) {
        LambdaQueryWrapper<OrderItem> query = getQuery(orderId);
        query.eq(OrderItem::getShippingStatus,status);
        return Math.toIntExact(this.count(query));
    }

    @Override
    public Integer getCountByOrderId(Long orderId) {
        return Math.toIntExact(this.count(query()));
    }

    public LambdaQueryWrapper<OrderItem> getQuery(Long orderId){
        LambdaQueryWrapper<OrderItem> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderItem::getOrderId,orderId);
        return queryWrapper;
    }
}
