音乐列表关联期刊跳转

main
JH 10 months ago
parent 2fda1e8487
commit cd10c6d8e9

@ -0,0 +1,39 @@
package com.luoo.music.dto.response.cms;
import com.luoo.music.pojo.Journal;
import com.luoo.music.util.Constants;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.apache.commons.lang.StringUtils;
import java.util.List;
/**
* @author locust
*/
@Data
@ApiModel(description = "音乐列表音乐关联期刊跳转")
public class JournalJumpRespDto {
@ApiModelProperty(value = "主键ID")
private String id;
@ApiModelProperty(value = "期刊编号")
private String journalNo;
@ApiModelProperty(value = "期刊标题")
private String title;
@ApiModelProperty(value = "标号标题拼接")
private String joint;
public static JournalJumpRespDto convertPojo(Journal journal) {
JournalJumpRespDto response = new JournalJumpRespDto();
response.setId(journal.getId());
response.setJournalNo(journal.getJournalNo());
response.setTitle(journal.getTitle());
response.setJoint((Constants.JOURNAL_NO_PREF + journal.getJournalNo() + " " + journal.getTitle()));
return response;
}
}

@ -58,12 +58,16 @@ public class SongListRespDto {
@ApiModelProperty(value = "关联期刊") @ApiModelProperty(value = "关联期刊")
private List<String> journal; private List<String> journal;
@ApiModelProperty(value = "关联期刊信息")
private List<JournalJumpRespDto> journals;
@ApiModelProperty(value = "歌曲风格") @ApiModelProperty(value = "歌曲风格")
private List<String> tags; private List<String> tags;
public static SongListRespDto convertPojo(SongInfo song, public static SongListRespDto convertPojo(SongInfo song,
Map<String, List<String>> songJournalMap, Map<String, List<String>> songJournalMap1,
Map<String, List<String>> songTagMap) { Map<String, List<String>> songTagMap,
Map<String, List<JournalJumpRespDto>> songJournalMap) {
SongListRespDto response = new SongListRespDto(); SongListRespDto response = new SongListRespDto();
String id = song.getId(); String id = song.getId();
response.setId(id); response.setId(id);
@ -78,7 +82,8 @@ public class SongListRespDto {
} }
response.setSize(CommonUtil.formatSongSize(song.getSize())); response.setSize(CommonUtil.formatSongSize(song.getSize()));
response.setDuration(CommonUtil.formatSongDuration(song.getDuration())); response.setDuration(CommonUtil.formatSongDuration(song.getDuration()));
response.setJournal(songJournalMap.get(id)); response.setJournal(songJournalMap1.get(id));
response.setJournals(songJournalMap.get(id));
if (Objects.isNull(song.getUpdateTime())) { if (Objects.isNull(song.getUpdateTime())) {
response.setUpdateTime(""); response.setUpdateTime("");
} else { } else {

@ -3,13 +3,10 @@ package com.luoo.music.service;
import api.PageResult; import api.PageResult;
import api.Result; import api.Result;
import com.luoo.music.dao.*; import com.luoo.music.dao.*;
import com.luoo.music.dto.response.cms.*;
import com.luoo.music.pojo.*; import com.luoo.music.pojo.*;
import com.luoo.music.dto.request.cms.SongAddModel; import com.luoo.music.dto.request.cms.SongAddModel;
import com.luoo.music.dto.request.cms.SongQueryModel; import com.luoo.music.dto.request.cms.SongQueryModel;
import com.luoo.music.dto.response.cms.SongBaseRespDto;
import com.luoo.music.dto.response.cms.SongListRespDto;
import com.luoo.music.dto.response.cms.SongLyricRespDto;
import com.luoo.music.dto.response.cms.SongRespDto;
import com.luoo.music.util.CommonUtil; import com.luoo.music.util.CommonUtil;
import com.luoo.music.util.Constants; import com.luoo.music.util.Constants;
import dto.UserLoginDto; import dto.UserLoginDto;
@ -84,11 +81,12 @@ public class CMSSongService {
if (!CollectionUtils.isEmpty(content)) { if (!CollectionUtils.isEmpty(content)) {
List<String> ids = content.stream().map(SongInfo::getId).collect(Collectors.toList()); List<String> ids = content.stream().map(SongInfo::getId).collect(Collectors.toList());
// 查询歌曲对应的期刊信息 // 查询歌曲对应的期刊信息
Map<String, List<String>> songJournalMap = buildSongJournalInfo(ids); Map<String, List<String>> songJournalMap = buildSongJournalInfos(ids);
Map<String, List<JournalJumpRespDto>> songJournalMap1 = buildSongJournalInfo(ids);
// 查询歌曲对应的标签信息 // 查询歌曲对应的标签信息
Map<String, List<String>> songTagMap = buildSongTagInfo(ids); Map<String, List<String>> songTagMap = buildSongTagInfo(ids);
for (SongInfo item : content) { for (SongInfo item : content) {
SongListRespDto response = SongListRespDto.convertPojo(item, songJournalMap, songTagMap); SongListRespDto response = SongListRespDto.convertPojo(item, songJournalMap, songTagMap, songJournalMap1);
result.add(response); result.add(response);
} }
} }
@ -132,7 +130,7 @@ public class CMSSongService {
* @param ids * @param ids
* @return * @return
*/ */
private Map<String, List<String>> buildSongJournalInfo(List<String> ids) { private Map<String, List<String>> buildSongJournalInfos(List<String> ids) {
Map<String, List<String>> result = new HashMap<>(); Map<String, List<String>> result = new HashMap<>();
List<JournalSong> journalSongList = journalSongDao.findBySongIds(ids); List<JournalSong> journalSongList = journalSongDao.findBySongIds(ids);
if (!CollectionUtils.isEmpty(journalSongList)) { if (!CollectionUtils.isEmpty(journalSongList)) {
@ -158,6 +156,37 @@ public class CMSSongService {
return result; return result;
} }
/**
*
* @param ids
* @return
*/
private Map<String, List<JournalJumpRespDto>> buildSongJournalInfo(List<String> ids) {
Map<String, List<JournalJumpRespDto>> result = new HashMap<>();
List<JournalSong> journalSongList = journalSongDao.findBySongIds(ids);
if (!CollectionUtils.isEmpty(journalSongList)) {
Set<String> idSet = journalSongList.stream().map(JournalSong::getJournalNo).collect(Collectors.toSet());
List<Journal> journalList = journalDao.findByJournalNoIn(idSet);
Map<String, Journal> idJournalMap = journalList.stream().collect(Collectors.toMap(Journal::getJournalNo, obj -> obj));
for (JournalSong item : journalSongList) {
String songId = item.getSongId();
String journalNo = item.getJournalNo();
List<JournalJumpRespDto> list;
if (result.keySet().contains(songId)) {
list = result.get(songId);
} else {
list = new ArrayList<>();
}
if (idJournalMap.keySet().contains(journalNo)) {
Journal journal = idJournalMap.get(journalNo);
list.add(JournalJumpRespDto.convertPojo(journal));
}
result.put(songId, list);
}
}
return result;
}
/** /**
* *
* @param ids * @param ids

Loading…
Cancel
Save