mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-24 16:05:08 +08:00
Merge remote-tracking branch 'origin/master-jdk21-ai' into master-jdk21-ai
This commit is contained in:
@ -17,6 +17,7 @@ import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
// TODO @xin:AI 前缀;都要加下哈
|
||||
@Tag(name = "管理后台 - AI 音乐生成")
|
||||
@RestController
|
||||
@RequestMapping("/ai/music")
|
||||
|
@ -4,12 +4,13 @@ import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@JsonInclude(value = JsonInclude.Include.NON_NULL)
|
||||
@JsonInclude(value = JsonInclude.Include.NON_NULL) // TODO @xin:不用加这个哈
|
||||
public class SunoReqVO {
|
||||
/**
|
||||
* 用于生成音乐音频的提示
|
||||
*/
|
||||
private String prompt;
|
||||
// TODO @xin:Boolean,不使用基本类型。
|
||||
/**
|
||||
* 是否纯音乐
|
||||
*/
|
||||
|
@ -18,6 +18,8 @@ import java.util.stream.Collectors;
|
||||
@TableName("ai_music")
|
||||
@Data
|
||||
public class AiMusicDO extends BaseDO {
|
||||
|
||||
// TODO @xin:@Schema 只在 VO 里使用,这里还是使用标准的注释哈
|
||||
@TableId(type = IdType.AUTO)
|
||||
@Schema(description = "编号")
|
||||
private Long id;
|
||||
@ -40,6 +42,7 @@ public class AiMusicDO extends BaseDO {
|
||||
@Schema(description = "视频地址")
|
||||
private String videoUrl;
|
||||
|
||||
// TODO @xin:需要关联下对应的枚举
|
||||
@Schema(description = "音乐状态")
|
||||
private String status;
|
||||
|
||||
@ -49,19 +52,24 @@ public class AiMusicDO extends BaseDO {
|
||||
@Schema(description = "提示词")
|
||||
private String prompt;
|
||||
|
||||
// TODO @xin:生成模式,需要记录下;歌词、描述
|
||||
|
||||
// TODO @xin:多存储一个平台,platform;考虑未来可能有别的音乐接口
|
||||
@Schema(description = "模型")
|
||||
private String model;
|
||||
|
||||
@Schema(description = "错误信息")
|
||||
private String errorMessage;
|
||||
|
||||
// TODO @xin:tags 要不要使用 List<String>
|
||||
|
||||
@Schema(description = "音乐风格标签")
|
||||
private String tags;
|
||||
|
||||
@Schema(description = "任务id")
|
||||
@Schema(description = "任务编号")
|
||||
private String taskId;
|
||||
|
||||
|
||||
// TODO @xin:转换不放在 DO 里面哈。
|
||||
|
||||
public static AiMusicDO convertFrom(SunoApi.MusicData musicData) {
|
||||
return new AiMusicDO()
|
||||
@ -84,5 +92,4 @@ public class AiMusicDO extends BaseDO {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -5,10 +5,9 @@ import cn.iocoder.yudao.module.ai.dal.dataobject.music.AiMusicDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* @Author xiaoxin
|
||||
* @Date 2024/6/5
|
||||
* AI 音乐 Mapper
|
||||
* @author xiaoxin
|
||||
*/
|
||||
@Mapper
|
||||
public interface AiMusicMapper extends BaseMapperX<AiMusicDO> {
|
||||
|
||||
}
|
||||
|
@ -31,26 +31,29 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti
|
||||
@Slf4j
|
||||
public class MusicServiceImpl implements MusicService {
|
||||
|
||||
// TODO @xin:使用 @Resource 注入,整个项目保持统一哈;
|
||||
private final SunoApi sunoApi;
|
||||
private final AiMusicMapper musicMapper;
|
||||
|
||||
private final Queue<String> taskQueue = new ConcurrentLinkedQueue<>();
|
||||
|
||||
// TODO @xin:要不把 descriptionMode、lyricMode 合并,同一个 generateMusic 方法,然后根据传入的 mode 模式:歌词、描述来区分?
|
||||
|
||||
@Override
|
||||
public List<Long> descriptionMode(SunoReqVO reqVO) {
|
||||
SunoApi.SunoReq sunoReq = new SunoApi.SunoReq(reqVO.getPrompt(), reqVO.getMv(), reqVO.isMakeInstrumental());
|
||||
//默认异步
|
||||
// 1. 异步生成
|
||||
SunoApi.SunoRequest sunoReq = new SunoApi.SunoRequest(reqVO.getPrompt(), reqVO.getMv(), reqVO.isMakeInstrumental());
|
||||
List<SunoApi.MusicData> musicDataList = sunoApi.generate(sunoReq);
|
||||
// 2. 插入数据库
|
||||
return insertMusicData(musicDataList);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public List<Long> lyricMode(SunoLyricModeVO reqVO) {
|
||||
SunoApi.SunoReq sunoReq = new SunoApi.SunoReq(reqVO.getPrompt(), reqVO.getMv(), reqVO.getTags(), reqVO.getTitle());
|
||||
//默认异步
|
||||
// 1. 异步生成
|
||||
SunoApi.SunoRequest sunoReq = new SunoApi.SunoRequest(reqVO.getPrompt(), reqVO.getMv(), reqVO.getTags(), reqVO.getTitle());
|
||||
List<SunoApi.MusicData> musicDataList = sunoApi.customGenerate(sunoReq);
|
||||
// 2. 插入数据库
|
||||
return insertMusicData(musicDataList);
|
||||
}
|
||||
|
||||
@ -64,6 +67,7 @@ public class MusicServiceImpl implements MusicService {
|
||||
if (CollUtil.isEmpty(musicDataList)) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
// TODO @xin:建议使用 insertBatch 方法,批量插入
|
||||
return AiMusicDO.convertFrom(musicDataList).stream()
|
||||
.peek(musicDO -> musicMapper.insert(musicDO.setUserId(getLoginUserId())))
|
||||
.peek(e -> Optional.of(e.getTaskId()).ifPresent(taskQueue::add))
|
||||
@ -71,6 +75,7 @@ public class MusicServiceImpl implements MusicService {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
// TODO @xin:这个,改成标准的 job 来实现哈。从数据库加载任务,然后执行。
|
||||
@Scheduled(fixedDelay = 5, timeUnit = TimeUnit.SECONDS)
|
||||
@Transactional
|
||||
public void flushSunoTask() {
|
||||
|
Reference in New Issue
Block a user