diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java b/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java index 85a6741..033448f 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/ArtistAlbum.java @@ -60,7 +60,7 @@ public class ArtistAlbum implements Serializable { /** * 主要风格 */ - @ApiModelProperty("风格") + @ApiModelProperty("风格str") private String mainStyle; /** @@ -119,6 +119,10 @@ public class ArtistAlbum implements Serializable { @ApiModelProperty("价格") private Float price; + @Transient + @ApiModelProperty("风格列表") + private List style; + } diff --git a/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java index b1c9ea8..b0c74ce 100644 --- a/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java +++ b/luoo_music/src/main/java/com/luoo/music/pojo/SongInfo.java @@ -10,12 +10,10 @@ import org.springframework.data.annotation.CreatedDate; import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import javax.persistence.Entity; -import javax.persistence.EntityListeners; -import javax.persistence.Id; -import javax.persistence.Table; +import javax.persistence.*; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.List; /** * 歌曲表 @@ -111,7 +109,12 @@ public class SongInfo implements Serializable { private String mvUrl; @ApiModelProperty("语种") - private Integer language; + @Transient + private List language; + + @ApiModelProperty("风格") + @Transient + private List style; @ApiModelProperty("歌曲版本") private Integer version; diff --git a/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java b/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java index fedeaad..4484add 100644 --- a/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java +++ b/luoo_music/src/main/java/com/luoo/music/service/AlbumService.java @@ -1,18 +1,12 @@ package com.luoo.music.service; import api.PageResult; -import com.luoo.music.dao.ArtistAlbumDao; -import com.luoo.music.dao.ArtistAlbumSongDao; -import com.luoo.music.dao.SongInfoDao; -import com.luoo.music.dao.SongTagDao; +import com.luoo.music.dao.*; import com.luoo.music.dto.response.AlbumAddDTO; import com.luoo.music.dto.response.AlbumSearchDTO; import com.luoo.music.dto.response.AlbumSongAddDTO; import com.luoo.music.dto.response.AlbumUpdateDTO; -import com.luoo.music.pojo.ArtistAlbum; -import com.luoo.music.pojo.ArtistAlbumSong; -import com.luoo.music.pojo.SongInfo; -import com.luoo.music.pojo.SongTag; +import com.luoo.music.pojo.*; import com.luoo.music.util.Constants; import dto.UserLoginDto; import enums.AlbumStateEnum; @@ -38,7 +32,9 @@ import javax.persistence.criteria.Root; import java.time.LocalDate; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.stream.Collectors; /** * @Author: yawei.huang @@ -51,6 +47,8 @@ import java.util.Objects; @Service @Slf4j public class AlbumService { + @Autowired + private TagDao tagDao; @Autowired private ArtistAlbumDao artistAlbumDao; @@ -171,7 +169,56 @@ public class AlbumService { if (artistAlbum == null) { throw new RuntimeException("专辑不存在,请刷新后重试"); } + + // 整个数据库所有的tag + List tagAllList = tagDao.findAll(); + Map tagMap = tagAllList.stream().collect(Collectors.toMap(Tag::getId, item -> item)); + log.info("------tagMap:{}",tagMap); + + // 处理album基础信息 + if(StringUtils.isNotBlank(artistAlbum.getMainStyle())) { + List style = new ArrayList<>(); + String[] mainStyleArr = artistAlbum.getMainStyle().split(","); + for (String s : mainStyleArr) { + if(StringUtils.isNotBlank(s)) { + style.add(tagMap.get(s)); + } + } + artistAlbum.setStyle(style); + } + + // 处理歌曲list List songInfoList = songInfoDao.findByAlbumId(id); + for (SongInfo songInfo : songInfoList) { + String songInfoId = songInfo.getId(); + List language = new ArrayList<>(); + List style = new ArrayList<>(); + + // 查询所有的tagId + List tagIdsBySongId = songTagDao.findTagIdsBySongId(songInfoId); + for (String tagId : tagIdsBySongId) { + Tag currentTag = tagMap.get(tagId); + if (StringUtils.isNotBlank(currentTag.getParentId())) { + // 二级标签 + Tag parentTag = tagMap.get(currentTag.getParentId()); + if (ObjectUtils.notEqual("Language", parentTag.getNameEn())) { + style.add(currentTag); + } else { + language.add(currentTag); + } + } else { + // 一级标签 + if (ObjectUtils.notEqual("Language", currentTag.getNameEn())) { + style.add(currentTag); + } else { + language.add(currentTag); + } + } + } + songInfo.setLanguage(language); + songInfo.setStyle(style); + + } artistAlbum.setSongList(songInfoList); return artistAlbum; } diff --git a/luoo_music/src/main/resources/sql/20240428.sql b/luoo_music/src/main/resources/sql/20240428.sql index 989ff50..fecc1d8 100644 --- a/luoo_music/src/main/resources/sql/20240428.sql +++ b/luoo_music/src/main/resources/sql/20240428.sql @@ -40,9 +40,6 @@ alter table tb_song_info alter table tb_song_info add mv_url varchar(50) null comment 'mv'; -alter table tb_song_info - add language int null comment '语种'; - alter table tb_song_info add price float null comment '价格';