feat(music): 优化音乐和歌手相关数据结构和功能
- 在 MusicDTO 中添加 typeName 和 releaseDate 字段 - 在 SingerDTO 中将 type 替换为 typeId 和 typeName - 更新 MusicServiceImpl 和 SingerServiceImpl 中的相关逻辑 - 在前端 SingerDetail 组件中使用 typeName 替换类型代码
This commit is contained in:
@@ -86,6 +86,16 @@ public class MusicDTO {
|
||||
*/
|
||||
private List<String> typeNames;
|
||||
|
||||
/**
|
||||
* 音乐类型名称(字符串)
|
||||
*/
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 发行日期
|
||||
*/
|
||||
private LocalDateTime releaseDate;
|
||||
|
||||
/**
|
||||
* 是否已收藏
|
||||
*/
|
||||
|
||||
@@ -33,9 +33,14 @@ public class SingerDTO {
|
||||
private String introduction;
|
||||
|
||||
/**
|
||||
* 歌手类型
|
||||
* 歌手类型ID
|
||||
*/
|
||||
private SingerTypeDTO type;
|
||||
private Long typeId;
|
||||
|
||||
/**
|
||||
* 歌手类型名称
|
||||
*/
|
||||
private String typeName;
|
||||
|
||||
/**
|
||||
* 音乐数量
|
||||
|
||||
@@ -650,10 +650,15 @@ public class MusicServiceImpl implements MusicService {
|
||||
|
||||
// 设置类型ID和名称列表
|
||||
if (!CollectionUtils.isEmpty(music.getTypes())) {
|
||||
List<String> typeNames = music.getTypes().stream().map(MusicType::getName).collect(Collectors.toList());
|
||||
musicDTO.setTypeIds(music.getTypes().stream().map(MusicType::getId).collect(Collectors.toList()));
|
||||
musicDTO.setTypeNames(music.getTypes().stream().map(MusicType::getName).collect(Collectors.toList()));
|
||||
musicDTO.setTypeNames(typeNames);
|
||||
musicDTO.setTypeName(String.join("、", typeNames));
|
||||
}
|
||||
|
||||
// 设置发行日期
|
||||
musicDTO.setReleaseDate(music.getCreateTime());
|
||||
|
||||
// 设置歌手ID和名称列表
|
||||
if (!CollectionUtils.isEmpty(music.getSingers())) {
|
||||
musicDTO.setSingerIds(music.getSingers().stream().map(Singer::getId).collect(Collectors.toList()));
|
||||
|
||||
@@ -217,8 +217,8 @@ public class SingerServiceImpl implements SingerService {
|
||||
singer.setCollectCount(0);
|
||||
|
||||
// 设置歌手类型
|
||||
if (singerDTO.getType() != null && singerDTO.getType().getId() != null) {
|
||||
SingerType type = singerTypeRepository.findById(singerDTO.getType().getId())
|
||||
if (singerDTO.getTypeId() != null) {
|
||||
SingerType type = singerTypeRepository.findById(singerDTO.getTypeId())
|
||||
.orElseThrow(() -> new BusinessException("歌手类型不存在"));
|
||||
singer.setType(type);
|
||||
}
|
||||
@@ -259,8 +259,8 @@ public class SingerServiceImpl implements SingerService {
|
||||
singer.setIntroduction(singerDTO.getIntroduction());
|
||||
|
||||
// 更新歌手类型
|
||||
if (singerDTO.getType() != null && singerDTO.getType().getId() != null) {
|
||||
SingerType type = singerTypeRepository.findById(singerDTO.getType().getId())
|
||||
if (singerDTO.getTypeId() != null) {
|
||||
SingerType type = singerTypeRepository.findById(singerDTO.getTypeId())
|
||||
.orElseThrow(() -> new BusinessException("歌手类型不存在"));
|
||||
singer.setType(type);
|
||||
}
|
||||
@@ -441,9 +441,8 @@ public class SingerServiceImpl implements SingerService {
|
||||
|
||||
// 设置类型信息
|
||||
if (singer.getType() != null) {
|
||||
SingerTypeDTO typeDTO = new SingerTypeDTO();
|
||||
BeanUtils.copyProperties(singer.getType(), typeDTO);
|
||||
singerDTO.setType(typeDTO);
|
||||
singerDTO.setTypeId(singer.getType().getId());
|
||||
singerDTO.setTypeName(singer.getType().getName());
|
||||
}
|
||||
|
||||
// 设置音乐数量
|
||||
|
||||
Reference in New Issue
Block a user