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 GoodsOrdersRepository extends JpaRepository<GoodsOrders, Integer>, JpaSpecificationExecutor<GoodsOrders> {

    /**
     * 根据订单ID找到订单记录
     *
     * @param orderId 订单ID
     * @return {@link GoodsOrders}
     */
    @Query(value = "select * from goods_orders where deleted = 0 and order_id = ? limit 1;", nativeQuery = true)
    GoodsOrders findByOrderId(int orderId);
    /**
     * 根据主键ID找到订单记录
     *
     * @param id 订单主键ID
     * @return {@link GoodsOrders}
     */
    @Query(value = "select * from goods_orders where deleted = 0 and id = ? limit 1;", nativeQuery = true)
    GoodsOrders findById(int id);

    @Query(value = "select count(1) from goods_orders where deleted = 0 and user_id = ?;", nativeQuery = true)
    int getCount(int userId);

    //查询支付方式
    @Query(value = "select DISTINCT payment_channel from goods_orders where deleted = 0 and payment_channel is not null", nativeQuery = true)
    List <Integer> findPaymentChannel();


}