feat(music): 优化音乐和歌手相关数据结构和功能

- 在 MusicDTO 中添加 typeName 和 releaseDate 字段
- 在 SingerDTO 中将 type 替换为 typeId 和 typeName
- 更新 MusicServiceImpl 和 SingerServiceImpl 中的相关逻辑
- 在前端 SingerDetail 组件中使用 typeName 替换类型代码
This commit is contained in:
ikmkj
2025-07-26 22:12:39 +08:00
parent 6d944ad56a
commit 35db37ca12
5 changed files with 30 additions and 26 deletions

View File

@@ -86,6 +86,16 @@ public class MusicDTO {
*/ */
private List<String> typeNames; private List<String> typeNames;
/**
* 音乐类型名称(字符串)
*/
private String typeName;
/**
* 发行日期
*/
private LocalDateTime releaseDate;
/** /**
* 是否已收藏 * 是否已收藏
*/ */

View File

@@ -33,9 +33,14 @@ public class SingerDTO {
private String introduction; private String introduction;
/** /**
* 歌手类型 * 歌手类型ID
*/ */
private SingerTypeDTO type; private Long typeId;
/**
* 歌手类型名称
*/
private String typeName;
/** /**
* 音乐数量 * 音乐数量

View File

@@ -650,10 +650,15 @@ public class MusicServiceImpl implements MusicService {
// 设置类型ID和名称列表 // 设置类型ID和名称列表
if (!CollectionUtils.isEmpty(music.getTypes())) { 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.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和名称列表 // 设置歌手ID和名称列表
if (!CollectionUtils.isEmpty(music.getSingers())) { if (!CollectionUtils.isEmpty(music.getSingers())) {
musicDTO.setSingerIds(music.getSingers().stream().map(Singer::getId).collect(Collectors.toList())); musicDTO.setSingerIds(music.getSingers().stream().map(Singer::getId).collect(Collectors.toList()));

View File

@@ -217,8 +217,8 @@ public class SingerServiceImpl implements SingerService {
singer.setCollectCount(0); singer.setCollectCount(0);
// 设置歌手类型 // 设置歌手类型
if (singerDTO.getType() != null && singerDTO.getType().getId() != null) { if (singerDTO.getTypeId() != null) {
SingerType type = singerTypeRepository.findById(singerDTO.getType().getId()) SingerType type = singerTypeRepository.findById(singerDTO.getTypeId())
.orElseThrow(() -> new BusinessException("歌手类型不存在")); .orElseThrow(() -> new BusinessException("歌手类型不存在"));
singer.setType(type); singer.setType(type);
} }
@@ -259,8 +259,8 @@ public class SingerServiceImpl implements SingerService {
singer.setIntroduction(singerDTO.getIntroduction()); singer.setIntroduction(singerDTO.getIntroduction());
// 更新歌手类型 // 更新歌手类型
if (singerDTO.getType() != null && singerDTO.getType().getId() != null) { if (singerDTO.getTypeId() != null) {
SingerType type = singerTypeRepository.findById(singerDTO.getType().getId()) SingerType type = singerTypeRepository.findById(singerDTO.getTypeId())
.orElseThrow(() -> new BusinessException("歌手类型不存在")); .orElseThrow(() -> new BusinessException("歌手类型不存在"));
singer.setType(type); singer.setType(type);
} }
@@ -441,9 +441,8 @@ public class SingerServiceImpl implements SingerService {
// 设置类型信息 // 设置类型信息
if (singer.getType() != null) { if (singer.getType() != null) {
SingerTypeDTO typeDTO = new SingerTypeDTO(); singerDTO.setTypeId(singer.getType().getId());
BeanUtils.copyProperties(singer.getType(), typeDTO); singerDTO.setTypeName(singer.getType().getName());
singerDTO.setType(typeDTO);
} }
// 设置音乐数量 // 设置音乐数量

View File

@@ -404,21 +404,6 @@ const formatFans = (count) => {
} }
} }
// 获取歌手类型名称
const getSingerTypeName = (type) => {
const typeMap = {
1: '华语男歌手',
2: '华语女歌手',
3: '华语组合',
4: '欧美男歌手',
5: '欧美女歌手',
6: '欧美组合',
7: '日韩男歌手',
8: '日韩女歌手',
9: '日韩组合'
}
return typeMap[type] || '未知'
}
// WebSocket 订阅实例 // WebSocket 订阅实例
let commentSubscription = null; let commentSubscription = null;
@@ -480,7 +465,7 @@ onUnmounted(() => {
</div> </div>
<div class="singer-meta"> <div class="singer-meta">
<h1 class="singer-name">{{ singer.name }}</h1> <h1 class="singer-name">{{ singer.name }}</h1>
<div class="singer-type">类型{{ getSingerTypeName(singer.type) }}</div> <div class="singer-type">类型{{ singer.typeName }}</div>
<div class="singer-stats"> <div class="singer-stats">
<div class="stat-item"> <div class="stat-item">
<div class="stat-value">{{ singer.musicCount }}</div> <div class="stat-value">{{ singer.musicCount }}</div>