package com.ywt.mg.domain.mealEntities;

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

import java.util.List;

/**
 * @author Walker
 * Created on 2019/3/6
 */
public interface ShopRepository extends JpaRepository<Shop, Integer> {
    @Query(value = "select * from shop where deleted = 0", nativeQuery = true)
    List<Shop> getUndeletedShops();

    @Query(value = "select * from shop order by weight desc; ", nativeQuery = true)
    List<Shop> getAllShops();

    @Query(value = "select * from shop where id = ? and deleted = 0 limit 1", nativeQuery = true)
    Shop getById(int id);

    @Query(value = "select * from shop where id = ? and deleted = 0 and available = 1 limit 1", nativeQuery = true)
    Shop getAvailableShopById(int id);

    @Query(value = "select * from shop where id = ? limit 1", nativeQuery = true)
    Shop getByIdIncludingDeleted(int id);

    @Query(value = "select * from shop where mobile = ? and psw = ? and deleted = 0 limit 1;", nativeQuery = true)
    Shop getByMobileAndPsw(String mobile, String paw);

    @Query(value = "select * from shop where mobile = ? and deleted = 0 limit 1;",nativeQuery = true)
    Shop findOneByMobile(String mobile);

    @Query(value = "select * from shop where name = ? and deleted = 0 limit 1;",nativeQuery = true)
    Shop findOneByName(String mobile);
}
