【优化】处理 todo 运行异常 action 不能操作问题

This commit is contained in:
cherishsince 2024-06-17 21:38:17 +08:00
parent 70cbab9aeb
commit d332c0b175
5 changed files with 20 additions and 12 deletions

View File

@ -1,8 +1,9 @@
package cn.iocoder.yudao.framework.ai.config;
package cn.iocoder.yudao.module.ai.config;
import cn.iocoder.yudao.framework.ai.core.model.midjourney.MidjourneyConfig;
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

View File

@ -1,4 +1,4 @@
package cn.iocoder.yudao.framework.ai.config;
package cn.iocoder.yudao.module.ai.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

View File

@ -4,7 +4,10 @@ import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.ai.core.enums.AiPlatformEnum;
import cn.iocoder.yudao.framework.ai.core.model.midjourney.api.MidjourneyApi;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.module.ai.controller.admin.image.vo.MidjourneyNotifyReqVO;
import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO;
import cn.iocoder.yudao.module.ai.dal.mysql.image.AiImageMapper;
import cn.iocoder.yudao.module.ai.enums.image.AiImageStatusEnum;
@ -38,7 +41,7 @@ public class MidjourneyJob implements JobHandler {
// TODO @fan这个方法建议实现到 AiImageService例如说 midjourneySync返回 int 同步数量
@Override
public String execute(String param) throws Exception {
public String execute(String param) {
// 1获取 midjourney 平台状态在 进行中 image
List<AiImageDO> imageList = imageMapper.selectByStatusAndPlatform(AiImageStatusEnum.IN_PROGRESS, AiPlatformEnum.MIDJOURNEY);
log.info("Midjourney 同步 - 任务数量 {}!", imageList.size());
@ -61,10 +64,12 @@ public class MidjourneyJob implements JobHandler {
}
// TODO @ 3.1 3.2 是不是融合下get然后判空continue
// 3.2 获取通知对象
// MidjourneyNotifyReqVO notifyReqVO = taskIdMap.get(aiImageDO.getTaskId());
MidjourneyApi.NotifyRequest notifyRequest = taskIdMap.get(aiImageDO.getTaskId());
// 3.2 构建更新对象
// TODO @fan建议 List<MidjourneyNotifyReqVO> 作为 imageService 去更新
// updateImageList.add(imageService.buildUpdateImage(aiImageDO.getId(), notifyReqVO));
// TODO @芋艿 BeanUtils.toBean 转换为 null
updateImageList.add(imageService.buildUpdateImage(aiImageDO.getId(),
JsonUtils.parseObject(JsonUtils.toJsonString(notifyRequest), MidjourneyNotifyReqVO.class)));
}
// 4批了更新 updateImageList
imageMapper.updateBatch(updateImageList);

View File

@ -186,11 +186,13 @@ public class AiImageServiceImpl implements AiImageService {
public AiImageDO buildUpdateImage(Long imageId, MidjourneyNotifyReqVO notifyReqVO) {
// 1转换状态
String imageStatus = null;
MidjourneyApi.TaskStatusEnum taskStatusEnum = MidjourneyApi.TaskStatusEnum.valueOf(notifyReqVO.getStatus());
if (MidjourneyApi.TaskStatusEnum.SUCCESS == taskStatusEnum) {
imageStatus = AiImageStatusEnum.SUCCESS.getStatus();
} else if (MidjourneyApi.TaskStatusEnum.FAILURE == taskStatusEnum) {
imageStatus = AiImageStatusEnum.FAIL.getStatus();
if (StrUtil.isNotBlank(notifyReqVO.getStatus())) {
MidjourneyApi.TaskStatusEnum taskStatusEnum = MidjourneyApi.TaskStatusEnum.valueOf(notifyReqVO.getStatus());
if (MidjourneyApi.TaskStatusEnum.SUCCESS == taskStatusEnum) {
imageStatus = AiImageStatusEnum.SUCCESS.getStatus();
} else if (MidjourneyApi.TaskStatusEnum.FAILURE == taskStatusEnum) {
imageStatus = AiImageStatusEnum.FAIL.getStatus();
}
}
// 2上传图片
@ -261,7 +263,7 @@ public class AiImageServiceImpl implements AiImageService {
break;
}
}
if (isTrue) {
if (!isTrue) {
throw exception(AI_IMAGE_CUSTOM_ID_NOT_EXISTS);
}
}

View File

@ -202,7 +202,7 @@ public class MidjourneyApi {
public enum ModelEnum {
MIDJOURNEY("midjourney", "midjourney"),
NIJI("Niji", "Niji"),
NIJI("niji", "niji"),
;