package cn.ysk.cashier.repository.order;

import cn.ysk.cashier.pojo.order.TbCashierCart;
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 javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;

/**
* @website https://eladmin.vip
* @author lyf
* @date 2024-03-02
**/
public interface TbCashierCartRepository extends JpaRepository<TbCashierCart, Integer>, JpaSpecificationExecutor<TbCashierCart> {

    @Query(value = "update tb_cashier_cart set status='final' where order_id = :id",nativeQuery = true)
    @Modifying
    void updateToFinal(@Param("id") Integer id);


    @Query("delete from TbCashierCart cart where cart.shopId=:shopId and cart.id=:cartId and cart.tableId=:tableId and cart.status='create'")
    @Modifying
    @Transactional
    void deleteByIdAndShopId(@NotNull String shopId, @NotNull Integer cartId, Long tableId);

}
