|
|
|
@ -18,6 +18,8 @@ import io.swagger.annotations.*;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.Page;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import com.luoo.music.pojo.Journal;
|
|
|
|
|
import com.luoo.music.pojo.JournalSong;
|
|
|
|
@ -28,6 +30,7 @@ import com.luoo.music.service.SearchService;
|
|
|
|
|
import com.luoo.music.service.TagService;
|
|
|
|
|
import annotation.GlobalInterceptor;
|
|
|
|
|
import annotation.VerifyParam;
|
|
|
|
|
import api.PageResult;
|
|
|
|
|
import api.Result;
|
|
|
|
|
import constants.Constants;
|
|
|
|
|
|
|
|
|
@ -65,23 +68,39 @@ public class SearchController {
|
|
|
|
|
return Result.success(searchCategoryDTOs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.搜索期刊/歌曲", notes = "根据关键词模糊搜索,如 期刊号,歌曲名 等, limit 默认查10条")
|
|
|
|
|
@GetMapping("/fuzzy")
|
|
|
|
|
@ApiOperation(value = "2.1 搜索歌曲", notes = "根据关键词模糊搜索歌曲")
|
|
|
|
|
@GetMapping("/fuzzy/song")
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
public Result<SearchResultDTO> fuzzySearch(
|
|
|
|
|
public Result<PageResult<SongRespDTO>> fuzzySearchSong(
|
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
|
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
|
|
|
|
|
SearchResultDTO searchResultDTO = new SearchResultDTO();
|
|
|
|
|
int limit = getLimit(query.getLimit());
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize()));
|
|
|
|
|
|
|
|
|
|
Page<JournalSong> pageResults=journalSongService.fuzzySearch(query.getKeyword(),pageRequest);
|
|
|
|
|
List<SongRespDTO> list = pageResults.stream().map(SongMapper::getSongRespDTO)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
return Result.success(new PageResult<SongRespDTO>(Long.valueOf(list.size()), list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
private int getPageSize(Integer pageSize) {
|
|
|
|
|
return null==pageSize||0==pageSize?10:pageSize;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
searchResultDTO.setJournals(journals);
|
|
|
|
|
searchResultDTO.setSongs(songs);
|
|
|
|
|
return Result.success(searchResultDTO);
|
|
|
|
|
private int getPageNum(Integer pageNum) {
|
|
|
|
|
return null==pageNum?0:pageNum-1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.2 搜索期刊", notes = "根据关键词模糊搜索期刊")
|
|
|
|
|
@GetMapping("/fuzzy/journal")
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
public Result<PageResult<JournalRespDTO>> fuzzySearchJournal(
|
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
|
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize()));
|
|
|
|
|
Page<Journal> pageResults=journalService.fuzzySearch(query.getKeyword(),pageRequest);
|
|
|
|
|
List<JournalRespDTO> list = pageResults.stream().map(JournalMapper::getJournalRespDTO)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
|
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "3.搜索自动补全", notes = "limit 默认查10条")
|
|
|
|
|