package com.YuyeTech.TPlat.repository;

import com.YuyeTech.TPlat.dataobject.GameInfo;
import io.lettuce.core.dynamic.annotation.Param;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
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;

/**
 * @author:slambb
 * @date:2020/1/10
 */
public interface GameInfoRepository extends JpaRepository<GameInfo,String> , JpaSpecificationExecutor<GameInfo> {
    /**
     * In查询，根据参数列表顺序返回对象顺序
     * @param gameIdList
     * @return
     */
    @Query(value = "select * from game_info where `game_id` in :gameIdList order by FIELD(`game_id`,:gameIdList)" , nativeQuery = true)
    List<GameInfo> GIRepFindByGameIdInOrderByField(List<String> gameIdList);

    /**
     * In查询，根据参数列表返回对象列表
     * @param gameIdList
     * @return
     */
    @Query(value = "select * from game_info where `game_id` in :gameIdList" , nativeQuery = true)
    List<GameInfo> GIRepFindByGameIdIn(List<String> gameIdList);

    /**
     * 获取游戏详情
     * @param gameId
     * @return
     */
    GameInfo findByGameId(String gameId);

    /**
     * 根据类目查找列表
     * @param categoryType
     * @param pageable
     * @return
     */
    List<GameInfo> findByGameType(Integer categoryType,Pageable pageable);

    /**
     * 根据类目查找列表
     * @param categoryType
     * @param pageable
     * @return
     */
    Page<GameInfo> findPageByGameType(Integer categoryType, Pageable pageable);

    Page<GameInfo> findAllByGameRankingShow(Integer rankingShow, Pageable pageable);

    /**
     * 根据游戏名进行模糊搜索
     * @param pageable
     * @param gameName
     * @return
     */
    @Query(value = "select b from GameInfo b where (b.gameName like %:gameName%)")
    Page<GameInfo> fuzzySearchByUsername(Pageable pageable, @Param("gameName") String gameName);
}
