package com.rf.psychological.miniapp.searchhistory.repository;

import com.rf.psychological.base.repository.BaseRepository;
import com.rf.psychological.miniapp.searchhistory.model.SearchHistoryEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @Description:搜索历史接口
 * @Author: mimang
 * @Date: 2023/5/16
 */
public interface SearchHistoryRepository extends BaseRepository<SearchHistoryEntity, String> {

    /**
     * 根据用户查询所有搜索历史
     * @param userId
     * @param status
     * @return
     */
    List<SearchHistoryEntity> findAllByUserIdAndStatus(String userId,String status);

    @Modifying(clearAutomatically = true)
    @Query(nativeQuery = true,value = "SELECT DISTINCT(search_value) FROM t_search_history_log WHERE status=1 AND user_id=:userId limit 0,10")
    List<String> queryListByUserId(@Param(value = "userId") String userId);
}
