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 GoodsRepository extends JpaRepository<Goods, Integer>, JpaSpecificationExecutor<Goods> {

    @Query(value = "SELECT COUNT(1) FROM  goods WHERE  spec = ? AND  id != ? And shop_id = ? and deleted = 0 ", nativeQuery = true)
    public int checkGoodsSpecById(String spec, int id, int shopId);

    @Query(value = "SELECT COUNT(1) FROM  goods WHERE  spec = ? And shop_id = ? and deleted = 0 ", nativeQuery = true)
    public int checkGoodsBySpec(String spec, int shopId);

    @Query(value = "SELECT * FROM  goods WHERE  shop_id = ? AND  id = ? and deleted = 0 limit 1 ", nativeQuery = true)
    public Goods checkGoodsById(int shopId, int id);

    @Query(value = "SELECT * FROM  goods WHERE  shop_id = ? AND type_id = ? and status = 1  and deleted = 0 order by weight desc ", nativeQuery = true)
    public List<Goods> goodList (int shopId, int typeId);
}