Commit 8e7fc1ff964325ac5583e268f2c7792a54eed5e5

Authored by cherishsince
1 parent caca47b6

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

yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/dataobject/image/AiImageDO.java
@@ -49,8 +49,8 @@ public class AiImageDO extends BaseDO { @@ -49,8 +49,8 @@ public class AiImageDO extends BaseDO {
49 49
50 // ============ mj 需要字段 50 // ============ mj 需要字段
51 51
52 - @Schema(description = "用户操作的消息编号(MJ返回)")  
53 - private String mjMessageId; 52 + @Schema(description = "用户操作的Nonce编号(MJ返回)")
  53 + private String mjNonceId;
54 54
55 @Schema(description = "用户操作的操作编号(MJ返回)") 55 @Schema(description = "用户操作的操作编号(MJ返回)")
56 private String mjOperationId; 56 private String mjOperationId;
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/dal/mysql/AiImageMapper.java
1 package cn.iocoder.yudao.module.ai.dal.mysql; 1 package cn.iocoder.yudao.module.ai.dal.mysql;
2 2
3 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; 3 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
  4 +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
4 import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO; 5 import cn.iocoder.yudao.module.ai.dal.dataobject.image.AiImageDO;
5 import org.apache.ibatis.annotations.Mapper; 6 import org.apache.ibatis.annotations.Mapper;
6 import org.springframework.stereotype.Repository; 7 import org.springframework.stereotype.Repository;
@@ -17,4 +18,13 @@ import org.springframework.stereotype.Repository; @@ -17,4 +18,13 @@ import org.springframework.stereotype.Repository;
17 public interface AiImageMapper extends BaseMapperX<AiImageDO> { 18 public interface AiImageMapper extends BaseMapperX<AiImageDO> {
18 19
19 20
  21 + /**
  22 + * 更新 - 根据 messageId
  23 + *
  24 + * @param mjNonceId
  25 + * @param aiImageDO
  26 + */
  27 + default void updateByMjNonce(Long mjNonceId, AiImageDO aiImageDO) {
  28 + this.update(aiImageDO, new LambdaQueryWrapperX<AiImageDO>().eq(AiImageDO::getMjNonceId, mjNonceId));
  29 + }
20 } 30 }
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/impl/AiImageServiceImpl.java
@@ -145,7 +145,7 @@ public class AiImageServiceImpl implements AiImageService { @@ -145,7 +145,7 @@ public class AiImageServiceImpl implements AiImageService {
145 // 校验 OperateId 是否存在 145 // 校验 OperateId 是否存在
146 AiImageMidjourneyOperationsVO midjourneyOperationsVO = validateMidjourneyOperationsExists(midjourneyOperations, req.getOperateId()); 146 AiImageMidjourneyOperationsVO midjourneyOperationsVO = validateMidjourneyOperationsExists(midjourneyOperations, req.getOperateId());
147 // 校验 messageId 147 // 校验 messageId
148 - validateMessageId(aiImageDO.getMjMessageId(), req.getMessageId()); 148 + validateMessageId(aiImageDO.getMjNonceId(), req.getMessageId());
149 // 获取 mjOperationName 149 // 获取 mjOperationName
150 String mjOperationName = midjourneyOperationsVO.getLabel(); 150 String mjOperationName = midjourneyOperationsVO.getLabel();
151 // 保存一个 image 任务记录 151 // 保存一个 image 任务记录
@@ -222,7 +222,7 @@ public class AiImageServiceImpl implements AiImageService { @@ -222,7 +222,7 @@ public class AiImageServiceImpl implements AiImageService {
222 aiImageDO.setDrawingImageUrl(drawingImageUrl); 222 aiImageDO.setDrawingImageUrl(drawingImageUrl);
223 aiImageDO.setDrawingErrorMessage(drawingErrorMessage); 223 aiImageDO.setDrawingErrorMessage(drawingErrorMessage);
224 // 224 //
225 - aiImageDO.setMjMessageId(mjMessageId); 225 + aiImageDO.setMjNonceId(mjMessageId);
226 aiImageDO.setMjOperationId(mjOperationId); 226 aiImageDO.setMjOperationId(mjOperationId);
227 aiImageDO.setMjOperationName(mjOperationName); 227 aiImageDO.setMjOperationName(mjOperationName);
228 aiImageMapper.insert(aiImageDO); 228 aiImageMapper.insert(aiImageDO);
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/service/midjourneyHandler/YuDaoMidjourneyMessageHandler.java
@@ -62,12 +62,11 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler { @@ -62,12 +62,11 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
62 62
63 private void errorHandler(MidjourneyMessage midjourneyMessage) { 63 private void errorHandler(MidjourneyMessage midjourneyMessage) {
64 // image 编号 64 // image 编号
65 - Long aiImageId = Long.valueOf(midjourneyMessage.getNonce()); 65 + Long nonceId = Long.valueOf(midjourneyMessage.getNonce());
66 // 获取 error message 66 // 获取 error message
67 String errorMessage = getErrorMessage(midjourneyMessage); 67 String errorMessage = getErrorMessage(midjourneyMessage);
68 - aiImageMapper.updateById( 68 + aiImageMapper.updateByMjNonce(nonceId,
69 new AiImageDO() 69 new AiImageDO()
70 - .setId(aiImageId)  
71 .setDrawingErrorMessage(errorMessage) 70 .setDrawingErrorMessage(errorMessage)
72 .setDrawingStatus(AiImageDrawingStatusEnum.FAIL.getStatus()) 71 .setDrawingStatus(AiImageDrawingStatusEnum.FAIL.getStatus())
73 ); 72 );
@@ -83,7 +82,7 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler { @@ -83,7 +82,7 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
83 82
84 private void successHandler(MidjourneyMessage midjourneyMessage) { 83 private void successHandler(MidjourneyMessage midjourneyMessage) {
85 // 获取id 84 // 获取id
86 - Long aiImageId = Long.valueOf(midjourneyMessage.getNonce()); 85 + Long nonceId = Long.valueOf(midjourneyMessage.getNonce());
87 // 获取生成 url 86 // 获取生成 url
88 String imageUrl = null; 87 String imageUrl = null;
89 if (CollUtil.isNotEmpty(midjourneyMessage.getAttachments())) { 88 if (CollUtil.isNotEmpty(midjourneyMessage.getAttachments())) {
@@ -102,12 +101,11 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler { @@ -102,12 +101,11 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
102 // 获取 midjourneyOperations 101 // 获取 midjourneyOperations
103 List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperationsList(midjourneyMessage); 102 List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperationsList(midjourneyMessage);
104 // 更新数据库 103 // 更新数据库
105 - aiImageMapper.updateById( 104 + aiImageMapper.updateByMjNonce(nonceId,
106 new AiImageDO() 105 new AiImageDO()
107 - .setId(aiImageId)  
108 .setDrawingImageUrl(imageUrl) 106 .setDrawingImageUrl(imageUrl)
109 .setDrawingStatus(drawingStatusEnum == null ? null : drawingStatusEnum.getStatus()) 107 .setDrawingStatus(drawingStatusEnum == null ? null : drawingStatusEnum.getStatus())
110 - .setMjMessageId(midjourneyMessage.getId()) 108 + .setMjNonceId(midjourneyMessage.getId())
111 .setMjOperations(JsonUtils.toJsonString(midjourneyOperations)) 109 .setMjOperations(JsonUtils.toJsonString(midjourneyOperations))
112 ); 110 );
113 } 111 }
yudao-module-ai/yudao-module-ai-biz/src/main/resources/http/image.http
@@ -20,5 +20,5 @@ Content-Type: application/json @@ -20,5 +20,5 @@ Content-Type: application/json
20 Authorization: {{token}} 20 Authorization: {{token}}
21 21
22 { 22 {
23 - "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" 23 + "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."
24 } 24 }
25 \ No newline at end of file 25 \ No newline at end of file
yudao-module-ai/yudao-spring-boot-starter-ai/src/main/resources/requestTestJson/imageGenerationProcess/test2.json 0 → 100644
  1 +{
  2 + "type": 2,
  3 + "application_id": "936929561302675456",
  4 + "guild_id": "1237948819677904956",
  5 + "channel_id": "1237948819677904960",
  6 + "session_id": "4bdb0c32158f625bbd7f0a54bfbb54aa",
  7 + "data": {
  8 + "version": "1237876415471554623",
  9 + "id": "938956540159881230",
  10 + "name": "imagine",
  11 + "type": 1,
  12 + "options": [
  13 + {
  14 + "type": 3,
  15 + "name": "prompt",
  16 + "value": "哈哈哈"
  17 + }
  18 + ],
  19 + "application_command": {
  20 + "id": "938956540159881230",
  21 + "type": 1,
  22 + "application_id": "936929561302675456",
  23 + "version": "1237876415471554623",
  24 + "name": "imagine",
  25 + "description": "Create images with Midjourney",
  26 + "options": [
  27 + {
  28 + "type": 3,
  29 + "name": "prompt",
  30 + "description": "The prompt to imagine",
  31 + "required": true,
  32 + "description_localized": "The prompt to imagine",
  33 + "name_localized": "prompt"
  34 + }
  35 + ],
  36 + "dm_permission": true,
  37 + "contexts": [
  38 + 0,
  39 + 1,
  40 + 2
  41 + ],
  42 + "integration_types": [
  43 + 0,
  44 + 1
  45 + ],
  46 + "global_popularity_rank": 1,
  47 + "description_localized": "Create images with Midjourney",
  48 + "name_localized": "imagine"
  49 + },
  50 + "attachments": []
  51 + },
  52 + "nonce": "1238062212925358080",
  53 + "analytics_location": "slash_ui"
  54 +}
0 \ No newline at end of file 55 \ No newline at end of file
yudao-server/src/main/resources/application-local.yaml
@@ -52,7 +52,7 @@ spring: @@ -52,7 +52,7 @@ spring:
52 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ruoyi-vue-pro;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true;useUnicode=true;characterEncoding=utf-8 # SQLServer 连接的示例 52 # url: jdbc:sqlserver://127.0.0.1:1433;DatabaseName=ruoyi-vue-pro;SelectMethod=cursor;encrypt=false;rewriteBatchedStatements=true;useUnicode=true;characterEncoding=utf-8 # SQLServer 连接的示例
53 # url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例 53 # url: jdbc:dm://127.0.0.1:5236?schema=RUOYI_VUE_PRO # DM 连接的示例
54 username: root 54 username: root
55 - password: 123456 55 + password: root
56 # username: sa # SQL Server 连接的示例 56 # username: sa # SQL Server 连接的示例
57 # password: Yudao@2024 # SQL Server 连接的示例 57 # password: Yudao@2024 # SQL Server 连接的示例
58 # username: SYSDBA # DM 连接的示例 58 # username: SYSDBA # DM 连接的示例
@@ -61,7 +61,7 @@ spring: @@ -61,7 +61,7 @@ spring:
61 lazy: true # 开启懒加载,保证启动速度 61 lazy: true # 开启懒加载,保证启动速度
62 url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true 62 url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true
63 username: root 63 username: root
64 - password: 123456 64 + password: root
65 65
66 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优 66 # Redis 配置。Redisson 默认的配置足够使用,一般不需要进行调优
67 data: 67 data:
@@ -248,9 +248,9 @@ yudao: @@ -248,9 +248,9 @@ yudao:
248 style: vivid 248 style: vivid
249 midjourney: 249 midjourney:
250 enable: true 250 enable: true
251 - token: OTc1MzcyNDg1OTcxMzEyNzAw.G2iiSo.OqW9vToC5dokiyb1QOWnCwRPsYpOjLyNcf9--M  
252 - guild-id: 1234355413420347402  
253 - channel-id: 1234380679576424448 251 + token: MTE4MjE3MjY2MjkxNTY3ODIzOA.GEV1SG.c49F8lZoGCUHwsj8O0UdodmM6nyQHvuD2fXflw
  252 + guild-id: 1237948819677904956
  253 + channel-id: 1237948819677904960
254 captcha: 254 captcha:
255 enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试; 255 enable: false # 本地环境,暂时关闭图片验证码,方便登录等接口的测试;
256 security: 256 security:
@@ -267,6 +267,8 @@ yudao: @@ -267,6 +267,8 @@ yudao:
267 enable: false 267 enable: false
268 demo: false # 关闭演示模式 268 demo: false # 关闭演示模式
269 tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc 269 tencent-lbs-key: TVDBZ-TDILD-4ON4B-PFDZA-RNLKH-VVF6E # QQ 地图的密钥 https://lbs.qq.com/service/staticV2/staticGuide/staticDoc
  270 + tenant:
  271 + enable: false
270 272
271 justauth: 273 justauth:
272 enabled: true 274 enabled: true