package cn.ysk.cashier.repository.shop;

import cn.ysk.cashier.pojo.shop.TbShopTable;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-01-18
**/
public interface TbShopTableRepository extends JpaRepository<TbShopTable, Integer>, JpaSpecificationExecutor<TbShopTable> {

    @Query
    int countAllByShopId(@Param("shopId")Integer shopId);

    @Query("select table from TbShopTable table where table.qrcode = :qrcode")
    TbShopTable findByQrcode(@Param("qrcode") String qrcode);

//    @Query("select table from TbShopTable table where table.shopId = :qrcode")
//    List<TbShopTable> findByQrcode(@Param("qrcode") Integer shopId);

    @Query("select table from TbShopTable table where table.shopId = :shopId")
    List<TbShopTable> findByShopId(@Param("shopId") Integer shopId);

    @Query("delete from TbCashierCart cart where cart.tableId=:tableId and cart.shopId=:shopId and cart.status='create'")
    @Modifying
    @Transactional
    void deleteByTableIdAndShopId(Long tableId, String shopId);
}
