package com.ywt.domain.entity.glasses;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface GoodsOrdersDetailRepository extends JpaRepository<GoodsOrdersDetail, Integer>, JpaSpecificationExecutor<GoodsOrdersDetail> {

    /**
     * 根据商品订单表主键ID找到对应的订单详情记录
     *
     * @param goodsOrdersId 商品订单表主键ID
     * @return {@link List< GoodsOrdersDetail >}
     */
    @Query(value = "select * from goods_orders_detail where deleted = 0 and goods_orders_id = ? ;", nativeQuery = true)
    List<GoodsOrdersDetail> findByGoodsOrdersId(int goodsOrdersId);

    /**
     * 根据订单ID找到对应的订单详情记录
     *
     * @param orderId 订单表ID
     * @return {@link List< GoodsOrdersDetail >}
     */
    @Query(value = "select * from goods_orders_detail where deleted = 0 and order_id = ? ;", nativeQuery = true)
    List<GoodsOrdersDetail> findByOrderId(int orderId);

    @Query(value = "select * from goods_orders_detail where deleted = 0 and id = ? and goods_orders_id = ? limit 1 ;", nativeQuery = true)
    GoodsOrdersDetail findByIdAndOrderId(int id, int orderId);
}