|
|
|
@ -13,6 +13,7 @@ import com.luoo.music.dto.response.SearchCategoryDTO;
|
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
|
|
|
|
|
|
import io.swagger.annotations.*;
|
|
|
|
|
import util.JwtUtil;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.domain.PageRequest;
|
|
|
|
@ -23,10 +24,13 @@ import com.luoo.music.service.JournalService;
|
|
|
|
|
import com.luoo.music.service.JournalSongService;
|
|
|
|
|
import com.luoo.music.service.SearchService;
|
|
|
|
|
import com.luoo.music.service.TagService;
|
|
|
|
|
import com.luoo.music.util.DeviceTypeUtil;
|
|
|
|
|
|
|
|
|
|
import annotation.GlobalInterceptor;
|
|
|
|
|
import annotation.VerifyParam;
|
|
|
|
|
import api.PageResult;
|
|
|
|
|
import api.Result;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 控制器层
|
|
|
|
@ -54,6 +58,9 @@ public class SearchController {
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private TagService tagService;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "1.查询搜索大类", notes = "如 ‘民谣’,‘电子’")
|
|
|
|
|
@GetMapping("/category")
|
|
|
|
@ -64,12 +71,17 @@ public class SearchController {
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.1 搜索歌曲", notes = "根据关键词模糊搜索歌曲")
|
|
|
|
|
@GetMapping("/fuzzy/song")
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result<PageResult<SongRespDTO>> fuzzySearchSong(
|
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
|
@RequestHeader(value = "device_type", required = false) String deviceType,
|
|
|
|
|
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
if (!DeviceTypeUtil.isWeb(deviceType) && null == user) {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize()));
|
|
|
|
|
|
|
|
|
|
List<JournalSong> pageResults=journalSongService.fuzzySearch(query.getKeyword(),pageRequest);
|
|
|
|
|
List<SongRespDTO> list = pageResults.stream().map(SongMapper::getSongRespDTO)
|
|
|
|
|
.collect(Collectors.toList());
|
|
|
|
@ -86,10 +98,16 @@ public class SearchController {
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "2.2 搜索期刊", notes = "根据关键词模糊搜索期刊")
|
|
|
|
|
@GetMapping("/fuzzy/journal")
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result<PageResult<JournalRespDTO>> fuzzySearchJournal(
|
|
|
|
|
@RequestHeader(value = "device_type", required = false) String deviceType,
|
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
|
@VerifyParam(required = true) FuzzySearchReq query) throws InterruptedException, ExecutionException {
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
if (!DeviceTypeUtil.isWeb(deviceType) && null == user) {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PageRequest pageRequest = PageRequest.of(getPageNum(query.getPageNum()), getPageSize(query.getPageSize()));
|
|
|
|
|
List<Journal> pageResults=journalService.fuzzySearch(query.getKeyword(),pageRequest);
|
|
|
|
|
List<JournalRespDTO> list = pageResults.stream().map(journalMapper::getJournalRespDTO)
|
|
|
|
@ -99,10 +117,15 @@ public class SearchController {
|
|
|
|
|
|
|
|
|
|
@ApiOperation(value = "3.搜索自动补全", notes = "limit 默认查10条")
|
|
|
|
|
@GetMapping("/autoComplete")
|
|
|
|
|
@GlobalInterceptor(checkAppUserLogin = true)
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result<List<String>> autoComplete(
|
|
|
|
|
@RequestHeader(value = "Authorization", required = true) String authorization,
|
|
|
|
|
@RequestHeader(value = "device_type", required = false) String deviceType,
|
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
|
@VerifyParam(required = true) AutoCompleteReq query) {
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
if (!DeviceTypeUtil.isWeb(deviceType) && null == user) {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
int limit = getLimit(query.getLimit());
|
|
|
|
|
return Result.success(searchService.autoComplete(query.getQuery(), limit));
|
|
|
|
|
}
|
|
|
|
|