【解决todo】删除 mj 相关字段,抽离到 drawRequest 和 drwaResponse

This commit is contained in:
cherishsince 2024-05-29 10:32:00 +08:00
parent ed372cffc7
commit f347b15a1e
4 changed files with 44 additions and 34 deletions

View File

@ -24,7 +24,8 @@ public interface AiImageMapper extends BaseMapperX<AiImageDO> {
* @param aiImageDO * @param aiImageDO
*/ */
default void updateByMjNonce(Long mjNonceId, AiImageDO aiImageDO) { default void updateByMjNonce(Long mjNonceId, AiImageDO aiImageDO) {
this.update(aiImageDO, new LambdaQueryWrapperX<AiImageDO>().eq(AiImageDO::getMjNonceId, mjNonceId)); // this.update(aiImageDO, new LambdaQueryWrapperX<AiImageDO>().eq(AiImageDO::getMjNonceId, mjNonceId));
return;
} }
} }

View File

@ -26,7 +26,7 @@ public interface AiImageService {
* @param id * @param id
* @return * @return
*/ */
AiImageListRespVO get(Long id); AiImageListRespVO getMy(Long id);
/** /**
* ai绘画 - dall2/dall3 绘画 * ai绘画 - dall2/dall3 绘画
@ -54,7 +54,8 @@ public interface AiImageService {
* 删除 - image 记录 * 删除 - image 记录
* *
* @param id * @param id
* @param loginUserId
*/ */
void delete(Long id); void deleteMy(Long id, Long loginUserId);
} }

View File

@ -39,6 +39,9 @@ import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
// TODO @fan注释优化下哈 // TODO @fan注释优化下哈
/** /**
* ai 作图 * ai 作图
@ -105,7 +108,7 @@ public class AiImageServiceImpl implements AiImageService {
// TODO @fan1返回 DOVO 的翻译交给 Controller2还有使用 BeanUtils 替代哈 // TODO @fan1返回 DOVO 的翻译交给 Controller2还有使用 BeanUtils 替代哈
@Override @Override
public AiImageListRespVO get(Long id) { public AiImageListRespVO getMy(Long id) {
AiImageDO aiImageDO = aiImageMapper.selectById(id); AiImageDO aiImageDO = aiImageMapper.selectById(id);
return AiImageConvert.INSTANCE.convertAiImageListRespVO(aiImageDO); return AiImageConvert.INSTANCE.convertAiImageListRespVO(aiImageDO);
} }
@ -172,34 +175,37 @@ public class AiImageServiceImpl implements AiImageService {
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@Override @Override
public void midjourneyOperate(AiImageMidjourneyOperateReqVO req) { public void midjourneyOperate(AiImageMidjourneyOperateReqVO req) {
// 校验是否存在 // // 校验是否存在
AiImageDO aiImageDO = validateExists(req.getId()); // AiImageDO aiImageDO = validateExists(req.getId());
// 获取 midjourneyOperations // // 获取 midjourneyOperations
List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperations(aiImageDO); // List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperations(aiImageDO);
// 校验 OperateId 是否存在 // // 校验 OperateId 是否存在
AiImageMidjourneyOperationsVO midjourneyOperationsVO = validateMidjourneyOperationsExists(midjourneyOperations, req.getOperateId()); // AiImageMidjourneyOperationsVO midjourneyOperationsVO = validateMidjourneyOperationsExists(midjourneyOperations, req.getOperateId());
// 校验 messageId // // 校验 messageId
validateMessageId(aiImageDO.getMjNonceId(), req.getMessageId()); // validateMessageId(aiImageDO.getMjNonceId(), req.getMessageId());
// 获取 mjOperationName // // 获取 mjOperationName
String mjOperationName = midjourneyOperationsVO.getLabel(); // String mjOperationName = midjourneyOperationsVO.getLabel();
// 保存一个 image 任务记录 // // 保存一个 image 任务记录
// todo // // todo
// doSave(aiImageDO.getPrompt(), aiImageDO.getSize(), aiImageDO.getModel(), //// doSave(aiImageDO.getPrompt(), aiImageDO.getSize(), aiImageDO.getModel(),
// null, null, AiImageStatusEnum.SUBMIT, null, //// null, null, AiImageStatusEnum.SUBMIT, null,
// req.getMessageId(), req.getOperateId(), mjOperationName); //// req.getMessageId(), req.getOperateId(), mjOperationName);
// 提交操作 // // 提交操作
midjourneyInteractionsApi.reRoll( // midjourneyInteractionsApi.reRoll(
new ReRollReq() // new ReRollReq()
.setCustomId(req.getOperateId()) // .setCustomId(req.getOperateId())
.setMessageId(req.getMessageId()) // .setMessageId(req.getMessageId())
); // );
} }
// TODO @fan1需要校验存在2需要校验属于我 // TODO @fan1需要校验存在2需要校验属于我
@Override @Override
public void delete(Long id) { public void deleteMy(Long id, Long loginUserId) {
// 校验记录是否存在 // 校验记录是否存在
AiImageDO aiImageDO = validateExists(id); AiImageDO aiImageDO = validateExists(id);
if (!aiImageDO.getUserId().equals(loginUserId)) {
throw exception(ErrorCodeConstants.AI_IMAGE_NOT_CREATE_USER);
}
// 删除记录 // 删除记录
aiImageMapper.deleteById(id); aiImageMapper.deleteById(id);
} }
@ -221,10 +227,11 @@ public class AiImageServiceImpl implements AiImageService {
private List<AiImageMidjourneyOperationsVO> getMidjourneyOperations(AiImageDO aiImageDO) { private List<AiImageMidjourneyOperationsVO> getMidjourneyOperations(AiImageDO aiImageDO) {
if (StrUtil.isBlank(aiImageDO.getMjOperations())) { // if (StrUtil.isBlank(aiImageDO.getMjOperations())) {
return Collections.emptyList(); // return Collections.emptyList();
} // }
return JsonUtils.parseArray(aiImageDO.getMjOperations(), AiImageMidjourneyOperationsVO.class); // return JsonUtils.parseArray(aiImageDO.getMjOperations(), AiImageMidjourneyOperationsVO.class);
return null;
} }
private AiImageDO validateExists(Long id) { private AiImageDO validateExists(Long id) {

View File

@ -96,9 +96,10 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
drawingStatusEnum = AiImageStatusEnum.COMPLETE; drawingStatusEnum = AiImageStatusEnum.COMPLETE;
} else if (MidjourneyGennerateStatusEnum.IN_PROGRESS.getStatus().equals(generateStatus)) { } else if (MidjourneyGennerateStatusEnum.IN_PROGRESS.getStatus().equals(generateStatus)) {
drawingStatusEnum = AiImageStatusEnum.IN_PROGRESS; drawingStatusEnum = AiImageStatusEnum.IN_PROGRESS;
} else if (MidjourneyGennerateStatusEnum.WAITING.getStatus().equals(generateStatus)) {
drawingStatusEnum = AiImageStatusEnum.WAITING;
} }
// else if (MidjourneyGennerateStatusEnum.WAITING.getStatus().equals(generateStatus)) {
// drawingStatusEnum = AiImageStatusEnum.WAITING;
// }
// 获取 midjourneyOperations // 获取 midjourneyOperations
List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperationsList(midjourneyMessage); List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperationsList(midjourneyMessage);
// 更新数据库 // 更新数据库
@ -106,8 +107,8 @@ public class YuDaoMidjourneyMessageHandler implements MidjourneyMessageHandler {
new AiImageDO() new AiImageDO()
.setOriginalPicUrl(imageUrl) .setOriginalPicUrl(imageUrl)
.setStatus(drawingStatusEnum == null ? null : drawingStatusEnum.getStatus()) .setStatus(drawingStatusEnum == null ? null : drawingStatusEnum.getStatus())
.setMjNonceId(midjourneyMessage.getId()) // .setMjNonceId(midjourneyMessage.getId())
.setMjOperations(JsonUtils.toJsonString(midjourneyOperations)) // .setMjOperations(JsonUtils.toJsonString(midjourneyOperations))
); );
} }