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