|
|
|
@ -4,13 +4,16 @@ import com.luoo.music.dto.mapper.SongMapper;
|
|
|
|
|
import com.luoo.music.dto.request.CollectQueryReq;
|
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
|
import com.luoo.music.pojo.JournalSong;
|
|
|
|
|
import com.luoo.music.pojo.SongInfo;
|
|
|
|
|
import com.luoo.music.service.JournalService;
|
|
|
|
|
import com.luoo.music.service.JournalSongService;
|
|
|
|
|
import com.luoo.music.service.SongInfoService;
|
|
|
|
|
import com.luoo.music.service.UserCollectInfoService;
|
|
|
|
|
import annotation.GlobalInterceptor;
|
|
|
|
|
import annotation.VerifyParam;
|
|
|
|
|
import api.PageResult;
|
|
|
|
|
import api.Result;
|
|
|
|
|
import api.StatusCode;
|
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
|
import enums.VerifyRegexEnum;
|
|
|
|
@ -42,6 +45,8 @@ public class SongController {
|
|
|
|
|
@Autowired
|
|
|
|
|
private JournalService journalService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private SongInfoService songInfoService;
|
|
|
|
|
@Autowired
|
|
|
|
|
private JwtUtil jwtUtil;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -65,7 +70,7 @@ public class SongController {
|
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
|
}
|
|
|
|
|
List<JournalSong> songs = journalSongService.findByVolid(journalNo);
|
|
|
|
|
List<String> ids=songs.stream().map(JournalSong::getId).collect(Collectors.toList());
|
|
|
|
|
List<String> ids=songs.stream().map(JournalSong::getSongId).collect(Collectors.toList());
|
|
|
|
|
Set<String> songCollectSet = null == user ? Collections.emptySet()
|
|
|
|
|
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.SONG);
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
|
|
|
|
@ -87,7 +92,7 @@ public class SongController {
|
|
|
|
|
if (objectIds.isEmpty()) {
|
|
|
|
|
return Result.success(new PageResult<SongRespDTO>(0L, Collections.emptyList()));
|
|
|
|
|
}
|
|
|
|
|
List<JournalSong> songs = journalSongService.orderByField(objectIds);
|
|
|
|
|
List<SongInfo> songs = songInfoService.orderByField(objectIds);
|
|
|
|
|
|
|
|
|
|
Set<String> songCollectSet = new HashSet<>(objectIds);
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
|
|
|
|
@ -110,10 +115,10 @@ public class SongController {
|
|
|
|
|
public Result<List<SongRespDTO>> random(
|
|
|
|
|
@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
|
@PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
|
|
|
|
|
List<JournalSong> songs = journalSongService.random(limit);
|
|
|
|
|
List<SongInfo> songs = songInfoService.random(limit);
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
|
|
|
|
|
List<String> ids=songs.stream().map(JournalSong::getId).collect(Collectors.toList());
|
|
|
|
|
List<String> ids=songs.stream().map(SongInfo::getId).collect(Collectors.toList());
|
|
|
|
|
Set<String> songCollectSet = null == user ? Collections.emptySet()
|
|
|
|
|
: userCollectInfoService.getCollectSet(user.getUserId(),ids, CollectTypeEnum.SONG);
|
|
|
|
|
|
|
|
|
@ -127,14 +132,14 @@ public class SongController {
|
|
|
|
|
@GlobalInterceptor
|
|
|
|
|
public Result<SongRespDTO> findById(@RequestHeader(value = "Authorization", required = false) String authorization,
|
|
|
|
|
@PathVariable @VerifyParam(required = true) String id) {
|
|
|
|
|
SongInfo song = songInfoService.findById(id);
|
|
|
|
|
if(null==song) {
|
|
|
|
|
return Result.failed(StatusCode.MUSIC_COMMON_FAILED,"找不到歌曲, id: "+id);
|
|
|
|
|
}
|
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
|
|
|
|
|
JournalSong song = journalSongService.findById(id);
|
|
|
|
|
|
|
|
|
|
SongRespDTO songRespDTO=SongMapper.getSongRespDTO(song);
|
|
|
|
|
boolean isCollect=null == user ? false:userCollectInfoService.isCollect(user.getUserId(),id, CollectTypeEnum.SONG);
|
|
|
|
|
songRespDTO.setHaveCollect(isCollect);
|
|
|
|
|
return Result.success(songRespDTO);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|