1.add find all song by collected jouranls

main
Gary 9 months ago
parent cef8b92cf0
commit 99e9fb3e91

@ -17,6 +17,7 @@ import com.luoo.music.dto.request.JournalQueryReq;
import com.luoo.music.dto.response.CommentDTO;
import com.luoo.music.dto.response.JournalFilterDTO;
import com.luoo.music.dto.response.JournalRespDTO;
import com.luoo.music.dto.response.SongRespDTO;
import com.luoo.music.dto.response.TagDTO;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
@ -28,6 +29,7 @@ import org.springframework.web.bind.annotation.*;
import com.luoo.music.pojo.Journal;
import com.luoo.music.pojo.Tag;
import com.luoo.music.service.JournalService;
import com.luoo.music.service.SongInfoService;
import com.luoo.music.service.TagService;
import com.luoo.music.service.UserCollectInfoService;
import annotation.GlobalInterceptor;
@ -58,6 +60,9 @@ public class JournalController {
@Autowired
private JournalService journalService;
@Autowired
private SongController songController;
@Autowired
private TagService tagService;
@ -143,6 +148,22 @@ public class JournalController {
return Result.success(new PageResult<JournalRespDTO>(Long.valueOf(list.size()), list));
}
@ApiOperation(value = "2.1 查询所有收藏期刊的歌曲信息", notes = "pageNum/pageSize不传或者小于1则返回所有收藏刊的歌曲")
@GetMapping("/collect/song")
@GlobalInterceptor(checkAppUserLogin = true)
public Result<PageResult<SongRespDTO>> collectJournalSongs(
@RequestHeader(value = "Authorization", required = true) String authorization,
@VerifyParam CollectQueryReq queryReq) {
List<String> objectIds= getJournalObjectIds(queryReq);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
return songController.getCollectSongs(user.getUserId(), queryReq.getUserId(),objectIds);
}
private List<String> getJournalObjectIds(CollectQueryReq queryReq) {
List<String> jouranlIds=userCollectInfoService.findByUserIdAndCollectType(queryReq.getUserId(), CollectTypeEnum.JOURNAL);
return journalService.orderByJournalIdField(jouranlIds);
}
private Set<String> getMyCollectSet(String loginUser, String checkUser, List<String> objectIds) {
if(loginUser.equals(checkUser)) {
return new HashSet<>(objectIds);

@ -90,17 +90,22 @@ public class SongController {
@RequestHeader(value = "Authorization", required = true) String authorization,
@VerifyParam CollectQueryReq queryReq) {
List<String> objectIds= getSongIds(queryReq);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
return getCollectSongs(user.getUserId(),queryReq.getUserId(),objectIds);
}
public Result<PageResult<SongRespDTO>> getCollectSongs(String loginUserId, String queryUserId, List<String> objectIds) {
if (objectIds.isEmpty()) {
return Result.success(new PageResult<SongRespDTO>(0L, Collections.emptyList()));
}
List<SongInfo> songs = songInfoService.orderByField(objectIds);
UserLoginDto user = jwtUtil.getUserLoginDto(authorization);
Set<String> songCollectSet = getMyCollectSet(user.getUserId(),queryReq.getUserId(),objectIds);
Set<String> songCollectSet = getMyCollectSet(loginUserId,queryUserId,objectIds);
List<SongRespDTO> results = songs.stream().map(s -> SongMapper.getSongRespDTO(s, songCollectSet))
.collect(Collectors.toList());
return Result.success(new PageResult<SongRespDTO>(Long.valueOf(results.size()), results));
}
private Set<String> getMyCollectSet(String loginUser, String checkUser, List<String> objectIds) {
if(loginUser.equals(checkUser)) {
return new HashSet<>(objectIds);

@ -48,4 +48,7 @@ public interface JournalSongDao extends JpaRepository<JournalSong,String>, JpaSp
public List<JournalSong> orderByField(List<String> idList);
List<JournalSong> findByJournalNoOrderBySongNo(String journalNo);
@Query(value = "select tbjs.song_id from tb_journal_song as tbjs,tb_journal as tbj where tbjs.journal_no=tbj.journal_no and tbj.id in ?1 order by field(tbj.id,?1), tbjs.song_no", nativeQuery = true)
List<String> orderByJournalIdField(List<String> jouranlIds);
}

@ -26,6 +26,7 @@ import org.springframework.stereotype.Service;
import util.IdWorker;
import com.luoo.music.dao.JournalDao;
import com.luoo.music.dao.JournalSongDao;
import com.luoo.music.dao.JournalTagDao;
import com.luoo.music.dao.TagDao;
import com.luoo.music.dto.request.JournalQueryReq;
@ -43,6 +44,9 @@ public class JournalService {
@Autowired
private JournalDao journalDao;
@Autowired
private JournalSongDao journalSongDao;
@Autowired
private IdWorker idWorker;
@Autowired
@ -340,4 +344,9 @@ public class JournalService {
}
return journalDao.orderByField(recommendIds);
}
public List<String> orderByJournalIdField(List<String> jouranlIds) {
return journalSongDao.orderByJournalIdField(jouranlIds);
}
}

Loading…
Cancel
Save