1.change collect journal_song id to song_id

main
Gary 9 months ago
parent 198ec60de1
commit fd551ec9a0

@ -21,6 +21,7 @@ public class Constants {
public static final String RESOURCE_PREFIX = "http://cdn.indie.cn/";
public static final String MUSIC_RESOURCE_PREFIX = RESOURCE_PREFIX + "music/";
public static final String SONG_RESOURCE_PREFIX = RESOURCE_PREFIX + "song/";
public static final String TAG_RESOURCE_PREFIX = RESOURCE_PREFIX + "tag/";

@ -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);
}
}

@ -27,6 +27,12 @@ public interface SongInfoDao extends JpaRepository<SongInfo,String>, JpaSpecific
List<SongInfo> findByIdIn(List<String> ids);
@Query(value = "select * from tb_song_info where id in ?1 order by field(id,?1)", nativeQuery = true)
@Query(value = "select * from tb_song_info where id in ?1 and state='1' order by field(id,?1)", nativeQuery = true)
List<SongInfo> orderByField(List<String> objectIds);
@Query(value = "select * from tb_song_info where state='1' order by rand() limit ?1 ", nativeQuery = true)
List<SongInfo> random(Integer limit);
@Query(value = "select * from tb_song_info where id=?1", nativeQuery = true)
SongInfo getSongById(String id);
}

@ -5,8 +5,10 @@ import java.util.Set;
import com.luoo.music.dto.response.SongRespDTO;
import com.luoo.music.pojo.JournalSong;
import com.luoo.music.pojo.SongInfo;
import constants.Constants;
import util.StringTools;
public class SongMapper {
public static SongRespDTO getSongRespDTO(JournalSong song, Set<String> songCollectSet) {
@ -14,11 +16,15 @@ public class SongMapper {
songRespDTO.setJournalNo(song.getJournalNo());
songRespDTO.setAlbum(song.getAlbum());
songRespDTO.setArtist(song.getArtist());
songRespDTO.setId(song.getId());
songRespDTO.setId(song.getSongId());
songRespDTO.setTitle(song.getName());
songRespDTO.setSrc(Constants.RESOURCE_PREFIX + song.getUrl());
songRespDTO.setPic(Constants.RESOURCE_PREFIX + song.getImage());
songRespDTO.setLrc(Constants.RESOURCE_PREFIX + song.getLyricUrl());
String lyric=song.getLyricUrl();
if(!StringTools.isEmpty(lyric)) {
songRespDTO.setLrc(Constants.RESOURCE_PREFIX + lyric);
}
songRespDTO.setSongNo(song.getSongNo());
songRespDTO.setHaveCollect(songCollectSet.contains(songRespDTO.getId()));
return songRespDTO;
@ -27,4 +33,24 @@ public class SongMapper {
public static SongRespDTO getSongRespDTO(JournalSong song) {
return getSongRespDTO(song, Collections.emptySet());
}
public static SongRespDTO getSongRespDTO(SongInfo song, Set<String> songCollectSet) {
SongRespDTO songRespDTO = new SongRespDTO();
songRespDTO.setAlbum(song.getAlbum());
songRespDTO.setArtist(song.getArtist());
songRespDTO.setId(song.getId());
songRespDTO.setTitle(song.getName());
songRespDTO.setSrc(Constants.SONG_RESOURCE_PREFIX + song.getUrl());
songRespDTO.setPic(Constants.SONG_RESOURCE_PREFIX + song.getImage());
String lyric=song.getLyricUrl();
if(!StringTools.isEmpty(lyric)) {
songRespDTO.setLrc(Constants.SONG_RESOURCE_PREFIX + lyric);
}
songRespDTO.setHaveCollect(songCollectSet.contains(songRespDTO.getId()));
return songRespDTO;
}
public static SongRespDTO getSongRespDTO(SongInfo song) {
return getSongRespDTO(song, Collections.emptySet());
}
}

@ -0,0 +1,27 @@
package com.luoo.music.service;
import com.luoo.music.dao.SongInfoDao;
import com.luoo.music.pojo.SongInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class SongInfoService {
@Autowired
private SongInfoDao songInfoDao;
public List<SongInfo> random(Integer limit) {
return songInfoDao.random(limit);
}
public List<SongInfo> orderByField(List<String> objectIds) {
return songInfoDao.orderByField(objectIds);
}
public SongInfo findById(String id) {
return songInfoDao.getSongById(id);
}
}
Loading…
Cancel
Save