mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2025-01-19 03:30:06 +08:00
【增加】增加 Midjourney 提交异常提示
This commit is contained in:
parent
cea888b225
commit
541f6b9e6b
@ -43,5 +43,6 @@ public interface ErrorCodeConstants {
|
|||||||
// ========== API 绘画 1-040-005-000 ==========
|
// ========== API 绘画 1-040-005-000 ==========
|
||||||
|
|
||||||
ErrorCode AI_IMAGE_NOT_EXISTS = new ErrorCode(1_022_005_000, "image 不存在!");
|
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 提交失败! {}");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.iocoder.yudao.module.ai.service.image;
|
package cn.iocoder.yudao.module.ai.service.image;
|
||||||
|
|
||||||
import cn.hutool.core.codec.Base64;
|
import cn.hutool.core.codec.Base64;
|
||||||
|
import cn.hutool.core.exceptions.ExceptionUtil;
|
||||||
import cn.hutool.core.map.MapUtil;
|
import cn.hutool.core.map.MapUtil;
|
||||||
import cn.hutool.core.util.ObjUtil;
|
import cn.hutool.core.util.ObjUtil;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
@ -39,6 +40,7 @@ import org.springframework.stereotype.Service;
|
|||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
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;
|
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));
|
imagineReqVO.setState(midjourneySizeParam.concat(midjourneyVersionParam).concat(midjourneyNijiParam));
|
||||||
MidjourneySubmitRespVO submitRespVO = midjourneyProxyClient.imagine(imagineReqVO);
|
MidjourneySubmitRespVO submitRespVO = midjourneyProxyClient.imagine(imagineReqVO);
|
||||||
|
|
||||||
// 4、保存任务 id (状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误))
|
// 4、保存任务 id (状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误))
|
||||||
String updateStatus = null;
|
|
||||||
String errorMessage = null;
|
|
||||||
|
|
||||||
if (!MidjourneySubmitCodeEnum.SUCCESS_CODES.contains(submitRespVO.getCode())) {
|
if (!MidjourneySubmitCodeEnum.SUCCESS_CODES.contains(submitRespVO.getCode())) {
|
||||||
updateStatus = AiImageStatusEnum.FAIL.getStatus();
|
throw exception(AI_IMAGE_MIDJOURNEY_SUBMIT_FAIL, submitRespVO.getDescription());
|
||||||
errorMessage = submitRespVO.getDescription();
|
|
||||||
}
|
}
|
||||||
imageMapper.updateById(new AiImageDO()
|
imageMapper.updateById(new AiImageDO()
|
||||||
.setId(aiImageDO.getId())
|
.setId(aiImageDO.getId())
|
||||||
.setStatus(updateStatus)
|
|
||||||
.setErrorMessage(errorMessage)
|
|
||||||
.setJobId(submitRespVO.getResult())
|
.setJobId(submitRespVO.getResult())
|
||||||
);
|
);
|
||||||
return aiImageDO.getId();
|
return aiImageDO.getId();
|
||||||
@ -194,24 +189,33 @@ public class AiImageServiceImpl implements AiImageService {
|
|||||||
log.warn("midjourneyNotify 回调的 jobId 不存在! jobId: {}", notifyReqVO.getId());
|
log.warn("midjourneyNotify 回调的 jobId 不存在! jobId: {}", notifyReqVO.getId());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//
|
// 2、转换状态
|
||||||
String imageStatus = null;
|
String imageStatus = null;
|
||||||
if (MidjourneyTaskStatusEnum.SUCCESS == notifyReqVO.getStatus()) {
|
MidjourneyTaskStatusEnum taskStatusEnum = MidjourneyTaskStatusEnum.valueOf(notifyReqVO.getStatus());
|
||||||
|
if (MidjourneyTaskStatusEnum.SUCCESS == taskStatusEnum) {
|
||||||
imageStatus = AiImageStatusEnum.SUCCESS.getStatus();
|
imageStatus = AiImageStatusEnum.SUCCESS.getStatus();
|
||||||
} else if (MidjourneyTaskStatusEnum.FAILURE == notifyReqVO.getStatus()) {
|
} else if (MidjourneyTaskStatusEnum.FAILURE == taskStatusEnum) {
|
||||||
imageStatus = AiImageStatusEnum.FAIL.getStatus();
|
imageStatus = AiImageStatusEnum.FAIL.getStatus();
|
||||||
}
|
}
|
||||||
// 2、上传图片
|
// 3、上传图片
|
||||||
String filePath = null;
|
String filePath = null;
|
||||||
if (!StrUtil.isBlank(notifyReqVO.getImageUrl())) {
|
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(
|
imageMapper.updateById(
|
||||||
new AiImageDO()
|
new AiImageDO()
|
||||||
.setId(image.getId())
|
.setId(image.getId())
|
||||||
.setStatus(imageStatus)
|
.setStatus(imageStatus)
|
||||||
.setPicUrl(filePath)
|
.setPicUrl(filePath)
|
||||||
|
.setProgress(notifyReqVO.getProgress())
|
||||||
|
.setResponse(notifyReqVO)
|
||||||
|
.setButtons(notifyReqVO.getButtons())
|
||||||
|
.setErrorMessage(notifyReqVO.getFailReason())
|
||||||
);
|
);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user