release- 处理前端专辑/歌曲标签显示

release-2024-08-08
pikaqiudeshujia 7 months ago
parent ba2dd5043f
commit f8343b1f1f

@ -60,7 +60,7 @@ public class ArtistAlbum implements Serializable {
/** /**
* *
*/ */
@ApiModelProperty("风格") @ApiModelProperty("风格str")
private String mainStyle; private String mainStyle;
/** /**
@ -119,6 +119,10 @@ public class ArtistAlbum implements Serializable {
@ApiModelProperty("价格") @ApiModelProperty("价格")
private Float price; private Float price;
@Transient
@ApiModelProperty("风格列表")
private List<Tag> style;
} }

@ -10,12 +10,10 @@ import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate; import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener; import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import javax.persistence.Entity; import javax.persistence.*;
import javax.persistence.EntityListeners;
import javax.persistence.Id;
import javax.persistence.Table;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.List;
/** /**
* *
@ -111,7 +109,12 @@ public class SongInfo implements Serializable {
private String mvUrl; private String mvUrl;
@ApiModelProperty("语种") @ApiModelProperty("语种")
private Integer language; @Transient
private List<Tag> language;
@ApiModelProperty("风格")
@Transient
private List<Tag> style;
@ApiModelProperty("歌曲版本") @ApiModelProperty("歌曲版本")
private Integer version; private Integer version;

@ -1,18 +1,12 @@
package com.luoo.music.service; package com.luoo.music.service;
import api.PageResult; import api.PageResult;
import com.luoo.music.dao.ArtistAlbumDao; import com.luoo.music.dao.*;
import com.luoo.music.dao.ArtistAlbumSongDao;
import com.luoo.music.dao.SongInfoDao;
import com.luoo.music.dao.SongTagDao;
import com.luoo.music.dto.response.AlbumAddDTO; import com.luoo.music.dto.response.AlbumAddDTO;
import com.luoo.music.dto.response.AlbumSearchDTO; import com.luoo.music.dto.response.AlbumSearchDTO;
import com.luoo.music.dto.response.AlbumSongAddDTO; import com.luoo.music.dto.response.AlbumSongAddDTO;
import com.luoo.music.dto.response.AlbumUpdateDTO; import com.luoo.music.dto.response.AlbumUpdateDTO;
import com.luoo.music.pojo.ArtistAlbum; import com.luoo.music.pojo.*;
import com.luoo.music.pojo.ArtistAlbumSong;
import com.luoo.music.pojo.SongInfo;
import com.luoo.music.pojo.SongTag;
import com.luoo.music.util.Constants; import com.luoo.music.util.Constants;
import dto.UserLoginDto; import dto.UserLoginDto;
import enums.AlbumStateEnum; import enums.AlbumStateEnum;
@ -38,7 +32,9 @@ import javax.persistence.criteria.Root;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.stream.Collectors;
/** /**
* @Author: yawei.huang * @Author: yawei.huang
@ -51,6 +47,8 @@ import java.util.Objects;
@Service @Service
@Slf4j @Slf4j
public class AlbumService { public class AlbumService {
@Autowired
private TagDao tagDao;
@Autowired @Autowired
private ArtistAlbumDao artistAlbumDao; private ArtistAlbumDao artistAlbumDao;
@ -171,7 +169,56 @@ public class AlbumService {
if (artistAlbum == null) { if (artistAlbum == null) {
throw new RuntimeException("专辑不存在,请刷新后重试"); throw new RuntimeException("专辑不存在,请刷新后重试");
} }
// 整个数据库所有的tag
List<Tag> tagAllList = tagDao.findAll();
Map<String, Tag> tagMap = tagAllList.stream().collect(Collectors.toMap(Tag::getId, item -> item));
log.info("------tagMap:{}",tagMap);
// 处理album基础信息
if(StringUtils.isNotBlank(artistAlbum.getMainStyle())) {
List<Tag> 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<SongInfo> songInfoList = songInfoDao.findByAlbumId(id); List<SongInfo> songInfoList = songInfoDao.findByAlbumId(id);
for (SongInfo songInfo : songInfoList) {
String songInfoId = songInfo.getId();
List<Tag> language = new ArrayList<>();
List<Tag> style = new ArrayList<>();
// 查询所有的tagId
List<String> 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); artistAlbum.setSongList(songInfoList);
return artistAlbum; return artistAlbum;
} }

@ -40,9 +40,6 @@ alter table tb_song_info
alter table tb_song_info alter table tb_song_info
add mv_url varchar(50) null comment 'mv'; add mv_url varchar(50) null comment 'mv';
alter table tb_song_info
add language int null comment '语种';
alter table tb_song_info alter table tb_song_info
add price float null comment '价格'; add price float null comment '价格';

Loading…
Cancel
Save