【增加】增加 Midjourney 提交异常提示

This commit is contained in:
cherishsince 2024-06-04 17:39:29 +08:00
parent cea888b225
commit 541f6b9e6b
2 changed files with 19 additions and 14 deletions

View File

@ -43,5 +43,6 @@ public interface ErrorCodeConstants {
// ========== API 绘画 1-040-005-000 ==========
ErrorCode AI_IMAGE_NOT_EXISTS = new ErrorCode(1_022_005_000, "image 不存在!");
ErrorCode AI_IMAGE_MIDJOURNEY_SUBMIT_FAIL = new ErrorCode(1_022_005_001, "Midjourney 提交失败! {}");
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.ai.service.image;
import cn.hutool.core.codec.Base64;
import cn.hutool.core.exceptions.ExceptionUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
@ -39,6 +40,7 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.AI_IMAGE_MIDJOURNEY_SUBMIT_FAIL;
import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.AI_IMAGE_NOT_EXISTS;
/**
@ -157,19 +159,12 @@ public class AiImageServiceImpl implements AiImageService {
// 设置参数
imagineReqVO.setState(midjourneySizeParam.concat(midjourneyVersionParam).concat(midjourneyNijiParam));
MidjourneySubmitRespVO submitRespVO = midjourneyProxyClient.imagine(imagineReqVO);
// 4保存任务 id (状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误))
String updateStatus = null;
String errorMessage = null;
if (!MidjourneySubmitCodeEnum.SUCCESS_CODES.contains(submitRespVO.getCode())) {
updateStatus = AiImageStatusEnum.FAIL.getStatus();
errorMessage = submitRespVO.getDescription();
throw exception(AI_IMAGE_MIDJOURNEY_SUBMIT_FAIL, submitRespVO.getDescription());
}
imageMapper.updateById(new AiImageDO()
.setId(aiImageDO.getId())
.setStatus(updateStatus)
.setErrorMessage(errorMessage)
.setJobId(submitRespVO.getResult())
);
return aiImageDO.getId();
@ -194,24 +189,33 @@ public class AiImageServiceImpl implements AiImageService {
log.warn("midjourneyNotify 回调的 jobId 不存在! jobId: {}", notifyReqVO.getId());
return false;
}
//
// 2转换状态
String imageStatus = null;
if (MidjourneyTaskStatusEnum.SUCCESS == notifyReqVO.getStatus()) {
MidjourneyTaskStatusEnum taskStatusEnum = MidjourneyTaskStatusEnum.valueOf(notifyReqVO.getStatus());
if (MidjourneyTaskStatusEnum.SUCCESS == taskStatusEnum) {
imageStatus = AiImageStatusEnum.SUCCESS.getStatus();
} else if (MidjourneyTaskStatusEnum.FAILURE == notifyReqVO.getStatus()) {
} else if (MidjourneyTaskStatusEnum.FAILURE == taskStatusEnum) {
imageStatus = AiImageStatusEnum.FAIL.getStatus();
}
// 2上传图片
// 3上传图片
String filePath = null;
if (!StrUtil.isBlank(notifyReqVO.getImageUrl())) {
filePath = fileApi.createFile(HttpUtil.downloadBytes(notifyReqVO.getImageUrl()));
try {
filePath = fileApi.createFile(HttpUtil.downloadBytes(notifyReqVO.getImageUrl()));
} catch (Exception e) {
log.warn("midjourneyNotify 图片上传失败! {} 异常:{}", notifyReqVO.getImageUrl(), ExceptionUtil.getMessage(e));
}
}
// 2更新 image 状态
// 4更新 image 状态
imageMapper.updateById(
new AiImageDO()
.setId(image.getId())
.setStatus(imageStatus)
.setPicUrl(filePath)
.setProgress(notifyReqVO.getProgress())
.setResponse(notifyReqVO)
.setButtons(notifyReqVO.getButtons())
.setErrorMessage(notifyReqVO.getFailReason())
);
return true;
}