diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageRespVO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageRespVO.java index 4e924463d..8499692e2 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageRespVO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/admin/image/vo/AiImageRespVO.java @@ -51,7 +51,12 @@ public class AiImageRespVO { @Schema(description = "mj buttons 按钮") private List buttons; + @Schema(description = "完成时间") + private LocalDateTime finishTime; + @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) private LocalDateTime createTime; + + } diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java index 9f928d60e..b5acec987 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java @@ -16,6 +16,7 @@ import lombok.Data; import org.springframework.ai.openai.OpenAiImageOptions; import org.springframework.ai.stabilityai.api.StabilityAiImageOptions; +import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -111,6 +112,11 @@ public class AiImageDO extends BaseDO { */ private String taskId; + /** + * 完成时间 + */ + private LocalDateTime finishTime; + public static class ButtonTypeHandler extends AbstractJsonTypeHandler { @Override diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java index 948d75c68..d3054d80d 100644 --- a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/image/AiImageServiceImpl.java @@ -35,6 +35,7 @@ import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.time.LocalDateTime; import java.util.Collections; import java.util.List; import java.util.Map; @@ -106,11 +107,12 @@ public class AiImageServiceImpl implements AiImageService { // 3. 更新数据库 imageMapper.updateById(new AiImageDO().setId(image.getId()).setStatus(AiImageStatusEnum.SUCCESS.getStatus()) - .setPicUrl(filePath)); + .setPicUrl(filePath).setFinishTime(LocalDateTime.now())); } catch (Exception ex) { log.error("[doDall][image({}) 生成异常]", image, ex); imageMapper.updateById(new AiImageDO().setId(image.getId()) - .setStatus(AiImageStatusEnum.FAIL.getStatus()).setErrorMessage(ex.getMessage())); + .setStatus(AiImageStatusEnum.FAIL.getStatus()) + .setErrorMessage(ex.getMessage()).setFinishTime(LocalDateTime.now())); } } @@ -254,12 +256,15 @@ public class AiImageServiceImpl implements AiImageService { private void updateMidjourneyStatus(AiImageDO image, MidjourneyApi.Notify notify) { // 1. 转换状态 Integer status = null; + LocalDateTime finishTime = null; if (StrUtil.isNotBlank(notify.status())) { MidjourneyApi.TaskStatusEnum taskStatusEnum = MidjourneyApi.TaskStatusEnum.valueOf(notify.status()); if (MidjourneyApi.TaskStatusEnum.SUCCESS == taskStatusEnum) { status = AiImageStatusEnum.SUCCESS.getStatus(); + finishTime = LocalDateTime.now(); } else if (MidjourneyApi.TaskStatusEnum.FAILURE == taskStatusEnum) { status = AiImageStatusEnum.FAIL.getStatus(); + finishTime = LocalDateTime.now(); } } @@ -276,7 +281,8 @@ public class AiImageServiceImpl implements AiImageService { // 3. 更新 image 状态 imageMapper.updateById(new AiImageDO().setId(image.getId()).setStatus(status) - .setPicUrl(picUrl).setButtons(notify.buttons()).setErrorMessage(notify.failReason())); + .setPicUrl(picUrl).setButtons(notify.buttons()).setErrorMessage(notify.failReason()) + .setFinishTime(finishTime)); } @Override