Commit 541f6b9e6b3f5bd48a5cbc3658aa7749e7f4d825
1 parent
cea888b2
【增加】增加 Midjourney 提交异常提示
Showing
2 changed files
with
19 additions
and
14 deletions
yudao-module-ai/yudao-module-ai-api/src/main/java/cn/iocoder/yudao/module/ai/enums/ErrorCodeConstants.java
| @@ -43,5 +43,6 @@ public interface ErrorCodeConstants { | @@ -43,5 +43,6 @@ public interface ErrorCodeConstants { | ||
| 43 | // ========== API 绘画 1-040-005-000 ========== | 43 | // ========== API 绘画 1-040-005-000 ========== |
| 44 | 44 | ||
| 45 | ErrorCode AI_IMAGE_NOT_EXISTS = new ErrorCode(1_022_005_000, "image 不存在!"); | 45 | ErrorCode AI_IMAGE_NOT_EXISTS = new ErrorCode(1_022_005_000, "image 不存在!"); |
| 46 | + ErrorCode AI_IMAGE_MIDJOURNEY_SUBMIT_FAIL = new ErrorCode(1_022_005_001, "Midjourney 提交失败! {}"); | ||
| 46 | 47 | ||
| 47 | } | 48 | } |
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java
| 1 | package cn.iocoder.yudao.module.ai.service.image; | 1 | package cn.iocoder.yudao.module.ai.service.image; |
| 2 | 2 | ||
| 3 | import cn.hutool.core.codec.Base64; | 3 | import cn.hutool.core.codec.Base64; |
| 4 | +import cn.hutool.core.exceptions.ExceptionUtil; | ||
| 4 | import cn.hutool.core.map.MapUtil; | 5 | import cn.hutool.core.map.MapUtil; |
| 5 | import cn.hutool.core.util.ObjUtil; | 6 | import cn.hutool.core.util.ObjUtil; |
| 6 | import cn.hutool.core.util.StrUtil; | 7 | import cn.hutool.core.util.StrUtil; |
| @@ -39,6 +40,7 @@ import org.springframework.stereotype.Service; | @@ -39,6 +40,7 @@ import org.springframework.stereotype.Service; | ||
| 39 | import org.springframework.transaction.annotation.Transactional; | 40 | import org.springframework.transaction.annotation.Transactional; |
| 40 | 41 | ||
| 41 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | 42 | import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; |
| 43 | +import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.AI_IMAGE_MIDJOURNEY_SUBMIT_FAIL; | ||
| 42 | import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.AI_IMAGE_NOT_EXISTS; | 44 | import static cn.iocoder.yudao.module.ai.enums.ErrorCodeConstants.AI_IMAGE_NOT_EXISTS; |
| 43 | 45 | ||
| 44 | /** | 46 | /** |
| @@ -157,19 +159,12 @@ public class AiImageServiceImpl implements AiImageService { | @@ -157,19 +159,12 @@ public class AiImageServiceImpl implements AiImageService { | ||
| 157 | // 设置参数 | 159 | // 设置参数 |
| 158 | imagineReqVO.setState(midjourneySizeParam.concat(midjourneyVersionParam).concat(midjourneyNijiParam)); | 160 | imagineReqVO.setState(midjourneySizeParam.concat(midjourneyVersionParam).concat(midjourneyNijiParam)); |
| 159 | MidjourneySubmitRespVO submitRespVO = midjourneyProxyClient.imagine(imagineReqVO); | 161 | MidjourneySubmitRespVO submitRespVO = midjourneyProxyClient.imagine(imagineReqVO); |
| 160 | - | ||
| 161 | // 4、保存任务 id (状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误)) | 162 | // 4、保存任务 id (状态码: 1(提交成功), 21(已存在), 22(排队中), other(错误)) |
| 162 | - String updateStatus = null; | ||
| 163 | - String errorMessage = null; | ||
| 164 | - | ||
| 165 | if (!MidjourneySubmitCodeEnum.SUCCESS_CODES.contains(submitRespVO.getCode())) { | 163 | if (!MidjourneySubmitCodeEnum.SUCCESS_CODES.contains(submitRespVO.getCode())) { |
| 166 | - updateStatus = AiImageStatusEnum.FAIL.getStatus(); | ||
| 167 | - errorMessage = submitRespVO.getDescription(); | 164 | + throw exception(AI_IMAGE_MIDJOURNEY_SUBMIT_FAIL, submitRespVO.getDescription()); |
| 168 | } | 165 | } |
| 169 | imageMapper.updateById(new AiImageDO() | 166 | imageMapper.updateById(new AiImageDO() |
| 170 | .setId(aiImageDO.getId()) | 167 | .setId(aiImageDO.getId()) |
| 171 | - .setStatus(updateStatus) | ||
| 172 | - .setErrorMessage(errorMessage) | ||
| 173 | .setJobId(submitRespVO.getResult()) | 168 | .setJobId(submitRespVO.getResult()) |
| 174 | ); | 169 | ); |
| 175 | return aiImageDO.getId(); | 170 | return aiImageDO.getId(); |
| @@ -194,24 +189,33 @@ public class AiImageServiceImpl implements AiImageService { | @@ -194,24 +189,33 @@ public class AiImageServiceImpl implements AiImageService { | ||
| 194 | log.warn("midjourneyNotify 回调的 jobId 不存在! jobId: {}", notifyReqVO.getId()); | 189 | log.warn("midjourneyNotify 回调的 jobId 不存在! jobId: {}", notifyReqVO.getId()); |
| 195 | return false; | 190 | return false; |
| 196 | } | 191 | } |
| 197 | - // | 192 | + // 2、转换状态 |
| 198 | String imageStatus = null; | 193 | String imageStatus = null; |
| 199 | - if (MidjourneyTaskStatusEnum.SUCCESS == notifyReqVO.getStatus()) { | 194 | + MidjourneyTaskStatusEnum taskStatusEnum = MidjourneyTaskStatusEnum.valueOf(notifyReqVO.getStatus()); |
| 195 | + if (MidjourneyTaskStatusEnum.SUCCESS == taskStatusEnum) { | ||
| 200 | imageStatus = AiImageStatusEnum.SUCCESS.getStatus(); | 196 | imageStatus = AiImageStatusEnum.SUCCESS.getStatus(); |
| 201 | - } else if (MidjourneyTaskStatusEnum.FAILURE == notifyReqVO.getStatus()) { | 197 | + } else if (MidjourneyTaskStatusEnum.FAILURE == taskStatusEnum) { |
| 202 | imageStatus = AiImageStatusEnum.FAIL.getStatus(); | 198 | imageStatus = AiImageStatusEnum.FAIL.getStatus(); |
| 203 | } | 199 | } |
| 204 | - // 2、上传图片 | 200 | + // 3、上传图片 |
| 205 | String filePath = null; | 201 | String filePath = null; |
| 206 | if (!StrUtil.isBlank(notifyReqVO.getImageUrl())) { | 202 | if (!StrUtil.isBlank(notifyReqVO.getImageUrl())) { |
| 207 | - filePath = fileApi.createFile(HttpUtil.downloadBytes(notifyReqVO.getImageUrl())); | 203 | + try { |
| 204 | + filePath = fileApi.createFile(HttpUtil.downloadBytes(notifyReqVO.getImageUrl())); | ||
| 205 | + } catch (Exception e) { | ||
| 206 | + log.warn("midjourneyNotify 图片上传失败! {} 异常:{}", notifyReqVO.getImageUrl(), ExceptionUtil.getMessage(e)); | ||
| 207 | + } | ||
| 208 | } | 208 | } |
| 209 | - // 2、更新 image 状态 | 209 | + // 4、更新 image 状态 |
| 210 | imageMapper.updateById( | 210 | imageMapper.updateById( |
| 211 | new AiImageDO() | 211 | new AiImageDO() |
| 212 | .setId(image.getId()) | 212 | .setId(image.getId()) |
| 213 | .setStatus(imageStatus) | 213 | .setStatus(imageStatus) |
| 214 | .setPicUrl(filePath) | 214 | .setPicUrl(filePath) |
| 215 | + .setProgress(notifyReqVO.getProgress()) | ||
| 216 | + .setResponse(notifyReqVO) | ||
| 217 | + .setButtons(notifyReqVO.getButtons()) | ||
| 218 | + .setErrorMessage(notifyReqVO.getFailReason()) | ||
| 215 | ); | 219 | ); |
| 216 | return true; | 220 | return true; |
| 217 | } | 221 | } |