|
|
@ -1,10 +1,10 @@
|
|
|
|
package com.luoo.music.controller;
|
|
|
|
package com.luoo.music.controller;
|
|
|
|
|
|
|
|
|
|
|
|
import com.luoo.music.client.UserClient;
|
|
|
|
|
|
|
|
import com.luoo.music.dao.UserCollectDao;
|
|
|
|
import com.luoo.music.dao.UserCollectDao;
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
import com.luoo.music.dto.response.SongRespDTO;
|
|
|
|
import com.luoo.music.pojo.Article;
|
|
|
|
import com.luoo.music.pojo.Article;
|
|
|
|
import com.luoo.music.pojo.Song;
|
|
|
|
import com.luoo.music.pojo.Song;
|
|
|
|
|
|
|
|
import com.luoo.music.pojo.UserCollect;
|
|
|
|
import com.luoo.music.service.ArticleService;
|
|
|
|
import com.luoo.music.service.ArticleService;
|
|
|
|
import com.luoo.music.service.SongService;
|
|
|
|
import com.luoo.music.service.SongService;
|
|
|
|
|
|
|
|
|
|
|
@ -14,7 +14,6 @@ import api.PageResult;
|
|
|
|
import api.Result;
|
|
|
|
import api.Result;
|
|
|
|
import constants.Constants;
|
|
|
|
import constants.Constants;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import dto.UserLoginDto;
|
|
|
|
import enums.CollectTypeEnum;
|
|
|
|
|
|
|
|
import enums.VerifyRegexEnum;
|
|
|
|
import enums.VerifyRegexEnum;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
import io.swagger.annotations.ApiImplicitParams;
|
|
|
@ -29,6 +28,7 @@ import java.util.Collections;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.Set;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
|
@ -65,12 +65,19 @@ public class SongController {
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
return Result.unauthorized(null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
List<Song> songs = songService.findByVolid(journalNo);
|
|
|
|
List<Song> songs = songService.findByVolid(journalNo);
|
|
|
|
List<String> collectIds = getCollectIds(songs, user, CollectTypeEnum.SONG.getType());
|
|
|
|
Set<String> songCollectSet = null==user?Collections.emptySet():getCollectSet(user.getUserId());
|
|
|
|
Set<String> songCollectSet = getCollectSet(collectIds);
|
|
|
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet)).collect(Collectors.toList());
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet)).collect(Collectors.toList());
|
|
|
|
return Result.success(results);
|
|
|
|
return Result.success(results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Set<String> getCollectSet(String userId) {
|
|
|
|
|
|
|
|
Optional<UserCollect> optional=userCollectDao.findById(userId);
|
|
|
|
|
|
|
|
if(optional.isPresent()) {
|
|
|
|
|
|
|
|
return new HashSet<>(optional.get().getSongs());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Collections.emptySet();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private boolean isLatest10(String journalNo) {
|
|
|
|
private boolean isLatest10(String journalNo) {
|
|
|
|
return articleService.isLatest10(journalNo);
|
|
|
|
return articleService.isLatest10(journalNo);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -80,9 +87,12 @@ public class SongController {
|
|
|
|
@GetMapping("/random/{limit}")
|
|
|
|
@GetMapping("/random/{limit}")
|
|
|
|
@GlobalInterceptor
|
|
|
|
@GlobalInterceptor
|
|
|
|
public Result<List<SongRespDTO>> random(
|
|
|
|
public Result<List<SongRespDTO>> random(
|
|
|
|
|
|
|
|
@RequestHeader(value = "token", required = false) String token,
|
|
|
|
@PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
|
|
|
|
@PathVariable @VerifyParam(required = true, regex = VerifyRegexEnum.RANDOM_SONG_LIMIT) Integer limit) {
|
|
|
|
List<Song> songs = songService.random(limit);
|
|
|
|
List<Song> songs = songService.random(limit);
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s, Collections.emptySet())).collect(Collectors.toList());
|
|
|
|
UserLoginDto user = jwtUtil.getUserLoginDto(token);
|
|
|
|
|
|
|
|
Set<String> songCollectSet = null==user?Collections.emptySet():getCollectSet(user.getUserId());
|
|
|
|
|
|
|
|
List<SongRespDTO> results = songs.stream().map(s -> getSongRespDTO(s, songCollectSet)).collect(Collectors.toList());
|
|
|
|
return Result.success(results);
|
|
|
|
return Result.success(results);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -101,24 +111,6 @@ public class SongController {
|
|
|
|
return songRespDTO;
|
|
|
|
return songRespDTO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Set<String> getCollectSet(List<String> collectIds) {
|
|
|
|
|
|
|
|
if (collectIds.isEmpty()) {
|
|
|
|
|
|
|
|
return Collections.emptySet();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Set<String> set = new HashSet<>();
|
|
|
|
|
|
|
|
userCollectDao.findAllById(collectIds).forEach(u -> set.add(u.getObjectId()));
|
|
|
|
|
|
|
|
return set;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private List<String> getCollectIds(List<Song> list, UserLoginDto user, Integer type) {
|
|
|
|
|
|
|
|
if (null == user) {
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return list.stream().map(a -> getCollectId(user.getUserId(), a.getId(), type)).collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private String getCollectId(String userId, String objectId, Integer type) {
|
|
|
|
|
|
|
|
return userId + "_" + objectId + "_" + type;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 根据ID查询
|
|
|
|
* 根据ID查询
|
|
|
|
*
|
|
|
|
*
|
|
|
|