【优化】数据库增加 mjNonce 更新,生成好、或异常的图片信息

This commit is contained in:
cherishsince
2024-05-10 15:29:11 +08:00
parent caca47b6d7
commit 8e7fc1ff96
7 changed files with 81 additions and 17 deletions

View File

@ -49,8 +49,8 @@ public class AiImageDO extends BaseDO {
// ============ mj 需要字段
@Schema(description = "用户操作的消息编号(MJ返回)")
private String mjMessageId;
@Schema(description = "用户操作的Nonce编号(MJ返回)")
private String mjNonceId;
@Schema(description = "用户操作的操作编号(MJ返回)")
private String mjOperationId;

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.ai.dal.mysql;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.stereotype.Repository;
@ -17,4 +18,13 @@ import org.springframework.stereotype.Repository;
public interface AiImageMapper extends BaseMapperX<AiImageDO> {
/**
* 更新 - 根据 messageId
*
* @param mjNonceId
* @param aiImageDO
*/
default void updateByMjNonce(Long mjNonceId, AiImageDO aiImageDO) {
this.update(aiImageDO, new LambdaQueryWrapperX<AiImageDO>().eq(AiImageDO::getMjNonceId, mjNonceId));
}
}

View File

@ -145,7 +145,7 @@ public class AiImageServiceImpl implements AiImageService {
// 校验 OperateId 是否存在
AiImageMidjourneyOperationsVO midjourneyOperationsVO = validateMidjourneyOperationsExists(midjourneyOperations, req.getOperateId());
// 校验 messageId
validateMessageId(aiImageDO.getMjMessageId(), req.getMessageId());
validateMessageId(aiImageDO.getMjNonceId(), req.getMessageId());
// 获取 mjOperationName
String mjOperationName = midjourneyOperationsVO.getLabel();
// 保存一个 image 任务记录
@ -222,7 +222,7 @@ public class AiImageServiceImpl implements AiImageService {
aiImageDO.setDrawingImageUrl(drawingImageUrl);
aiImageDO.setDrawingErrorMessage(drawingErrorMessage);
//
aiImageDO.setMjMessageId(mjMessageId);
aiImageDO.setMjNonceId(mjMessageId);
aiImageDO.setMjOperationId(mjOperationId);
aiImageDO.setMjOperationName(mjOperationName);
aiImageMapper.insert(aiImageDO);

View File

@ -62,12 +62,11 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
private void errorHandler(MidjourneyMessage midjourneyMessage) {
// image 编号
Long aiImageId = Long.valueOf(midjourneyMessage.getNonce());
Long nonceId = Long.valueOf(midjourneyMessage.getNonce());
// 获取 error message
String errorMessage = getErrorMessage(midjourneyMessage);
aiImageMapper.updateById(
aiImageMapper.updateByMjNonce(nonceId,
new AiImageDO()
.setId(aiImageId)
.setDrawingErrorMessage(errorMessage)
.setDrawingStatus(AiImageDrawingStatusEnum.FAIL.getStatus())
);
@ -83,7 +82,7 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
private void successHandler(MidjourneyMessage midjourneyMessage) {
// 获取id
Long aiImageId = Long.valueOf(midjourneyMessage.getNonce());
Long nonceId = Long.valueOf(midjourneyMessage.getNonce());
// 获取生成 url
String imageUrl = null;
if (CollUtil.isNotEmpty(midjourneyMessage.getAttachments())) {
@ -102,12 +101,11 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
// 获取 midjourneyOperations
List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperationsList(midjourneyMessage);
// 更新数据库
aiImageMapper.updateById(
aiImageMapper.updateByMjNonce(nonceId,
new AiImageDO()
.setId(aiImageId)
.setDrawingImageUrl(imageUrl)
.setDrawingStatus(drawingStatusEnum == null ? null : drawingStatusEnum.getStatus())
.setMjMessageId(midjourneyMessage.getId())
.setMjNonceId(midjourneyMessage.getId())
.setMjOperations(JsonUtils.toJsonString(midjourneyOperations))
);
}

View File

@ -20,5 +20,5 @@ Content-Type: application/json
Authorization: {{token}}
{
"prompt": "Cute cartoon style mobile game scene, a colorful camping car with an outdoor table and chairs next to it on the road in a spring forest, the simple structure of the camper van, soft lighting, C4D rendering, 3d model in the style of a cartoon, cute shape, a pastel color scheme, closeup view from the side angle, high resolution, bright colors, a happy atmosphere. --ar 1:2 --v 6.0"
"prompt": "Cute cartoon style mobile game scene, a colorful camping car with an outdoor table and chairs next to it on the road in a spring forest, the simple structure of the camper van, soft lighting, C4D rendering, 3d model in the style of a cartoon, cute shape, a pastel color scheme, closeup view from the side angle, high resolution, bright colors, a happy atmosphere."
}