【增加】ai image 生成记录删除

This commit is contained in:
cherishsince 2024-05-08 15:10:57 +08:00
parent e8cf40a82a
commit b6096b76d2
4 changed files with 21 additions and 4 deletions

View File

@ -59,12 +59,14 @@ public class AiImageController {
@Operation(summary = "取消 midjourney 绘画", description = "取消 midjourney 绘画") @Operation(summary = "取消 midjourney 绘画", description = "取消 midjourney 绘画")
@PostMapping("/cancel-midjourney") @PostMapping("/cancel-midjourney")
public CommonResult<Void> cancelMidjourney(@RequestParam("id") Long id) { public CommonResult<Void> cancelMidjourney(@RequestParam("id") Long id) {
// @范 这里实现mj取消逻辑
return success(null); return success(null);
} }
@Operation(summary = "删除绘画记录", description = "") @Operation(summary = "删除绘画记录", description = "")
@DeleteMapping("/delete") @DeleteMapping("/delete")
public CommonResult<Void> delete(@RequestParam("id") Long id) { public CommonResult<Void> delete(@RequestParam("id") Long id) {
aiImageService.delete(id);
return success(null); return success(null);
} }
} }

View File

@ -19,7 +19,7 @@ public class AiImageMidjourneyOperateReqVO {
@NotNull(message = "图片编号不能为空") @NotNull(message = "图片编号不能为空")
@Schema(description = "编号") @Schema(description = "编号")
private String id; private Long id;
@NotNull(message = "消息编号不能为空") @NotNull(message = "消息编号不能为空")
@Schema(description = "消息编号") @Schema(description = "消息编号")

View File

@ -44,4 +44,11 @@ public interface AiImageService {
*/ */
void midjourneyOperate(AiImageMidjourneyOperateReqVO req); void midjourneyOperate(AiImageMidjourneyOperateReqVO req);
/**
* 删除 - image 记录
*
* @param id
*/
void delete(Long id);
} }

View File

@ -137,7 +137,7 @@ public class AiImageServiceImpl implements AiImageService {
@Override @Override
public void midjourneyOperate(AiImageMidjourneyOperateReqVO req) { public void midjourneyOperate(AiImageMidjourneyOperateReqVO req) {
// 校验是否存在 // 校验是否存在
AiImageDO aiImageDO = validateExists(req); AiImageDO aiImageDO = validateExists(req.getId());
// 获取 midjourneyOperations // 获取 midjourneyOperations
List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperations(aiImageDO); List<AiImageMidjourneyOperationsVO> midjourneyOperations = getMidjourneyOperations(aiImageDO);
// 校验 OperateId 是否存在 // 校验 OperateId 是否存在
@ -158,6 +158,14 @@ public class AiImageServiceImpl implements AiImageService {
); );
} }
@Override
public void delete(Long id) {
// 校验记录是否存在
AiImageDO aiImageDO = validateExists(id);
// 删除记录
aiImageMapper.deleteById(id);
}
private void validateMessageId(String mjMessageId, String messageId) { private void validateMessageId(String mjMessageId, String messageId) {
if (!mjMessageId.equals(messageId)) { if (!mjMessageId.equals(messageId)) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MIDJOURNEY_MESSAGE_ID_INCORRECT); throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MIDJOURNEY_MESSAGE_ID_INCORRECT);
@ -181,8 +189,8 @@ public class AiImageServiceImpl implements AiImageService {
return JsonUtils.parseArray(aiImageDO.getMjOperations(), AiImageMidjourneyOperationsVO.class); return JsonUtils.parseArray(aiImageDO.getMjOperations(), AiImageMidjourneyOperationsVO.class);
} }
private AiImageDO validateExists(AiImageMidjourneyOperateReqVO req) { private AiImageDO validateExists(Long id) {
AiImageDO aiImageDO = aiImageMapper.selectById(req.getId()); AiImageDO aiImageDO = aiImageMapper.selectById(id);
if (aiImageDO == null) { if (aiImageDO == null) {
throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MIDJOURNEY_IMAGINE_FAIL); throw ServiceExceptionUtil.exception(ErrorCodeConstants.AI_MIDJOURNEY_IMAGINE_FAIL);
} }