|
|
|
@ -1,13 +1,19 @@
|
|
|
|
|
package com.luoo.music.controller;
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
|
import java.util.concurrent.ExecutionException;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.dto.mapper.JournalMapper;
|
|
|
|
|
import com.luoo.music.dto.mapper.SongMapper;
|
|
|
|
|
import com.luoo.music.dto.request.AutoCompleteReq;
|
|
|
|
|
import com.luoo.music.dto.request.FuzzySearchReq;
|
|
|
|
|
import com.luoo.music.dto.response.JournalRespDTO;
|
|
|
|
|
import com.luoo.music.dto.response.SearchCategoryDTO;
|
|
|
|
|
import com.luoo.music.dto.response.SearchResultDTO;
|
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
|
|
|
|
|
|
import io.swagger.annotations.*;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
@ -59,19 +65,22 @@ public class SearchController {
|
|
|
|
|
return Result.success(searchCategoryDTOs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.搜索期刊/歌曲", notes = "根据关键词模糊搜索,如 期刊号,歌曲名 等")
|
|
|
|
|
@ApiImplicitParams({ @ApiImplicitParam(name = "keyword", value = "搜索关键词", required = true) })
|
|
|
|
|
@GetMapping("/fuzzy/{keyword}")
|
|
|
|
|
@ApiOperation(value = "2.搜索期刊/歌曲", notes = "根据关键词模糊搜索,如 期刊号,歌曲名 等, limit 默认查10条")
|
|
|
|
|
@GetMapping("/fuzzy")
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
public Result<SearchResultDTO> fuzzySearch(
|
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
|
@PathVariable @VerifyParam(required = true) String keyword) {
|
|
|
|
|
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
|
|
|
|
|
SearchResultDTO searchResultDTO = new SearchResultDTO();
|
|
|
|
|
List<Journal> journals = journalService.fuzzySearch(keyword);
|
|
|
|
|
List<JournalSong> songs = journalSongService.fuzzySearch(keyword);
|
|
|
|
|
searchResultDTO.setJournals(
|
|
|
|
|
journals.stream().map(j -> JournalMapper.getJournalRespDTO(j)).collect(Collectors.toList()));
|
|
|
|
|
searchResultDTO.setSongs(songs.stream().map(SongMapper::getSongRespDTO).collect(Collectors.toList()));
|
|
|
|
|
int limit = getLimit(query.getLimit());
|
|
|
|
|
|
|
|
|
|
CompletableFuture<List<JournalRespDTO>> cfa = CompletableFuture.supplyAsync(() -> journalService.fuzzySearch(query.getKeyword(),limit).stream().map(JournalMapper::getJournalRespDTO).collect(Collectors.toList()));
|
|
|
|
|
CompletableFuture<List<SongRespDTO>> cfb = CompletableFuture.supplyAsync(() -> journalSongService.fuzzySearch(query.getKeyword(),limit).stream().map(SongMapper::getSongRespDTO).collect(Collectors.toList()));
|
|
|
|
|
List<JournalRespDTO> journals = cfa.get();
|
|
|
|
|
List<SongRespDTO> songs = cfb.get();
|
|
|
|
|
|
|
|
|
|
searchResultDTO.setJournals(journals);
|
|
|
|
|
searchResultDTO.setSongs(songs);
|
|
|
|
|
return Result.success(searchResultDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|