|
|
|
|
package com.youlai.boot.mini.controller;
|
|
|
|
|
|
|
|
|
|
import com.youlai.boot.common.annotation.Log;
|
|
|
|
|
import com.youlai.boot.common.annotation.RepeatSubmit;
|
|
|
|
|
import com.youlai.boot.common.enums.ActionTypeEnum;
|
|
|
|
|
import com.youlai.boot.common.enums.LogModuleEnum;
|
|
|
|
|
import com.youlai.boot.common.result.Result;
|
|
|
|
|
import com.youlai.boot.framework.security.util.SecurityUtils;
|
|
|
|
|
import com.youlai.boot.mini.model.form.*;
|
|
|
|
|
import com.youlai.boot.mini.model.vo.AiVideoCallbackVO;
|
|
|
|
|
import com.youlai.boot.mini.service.AiGenerationService;
|
|
|
|
|
import com.youlai.boot.mini.service.WxSubscribeService;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Hidden;
|
|
|
|
|
import io.swagger.v3.oas.annotations.Operation;
|
|
|
|
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
|
|
|
|
import jakarta.validation.Valid;
|
|
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
|
|
import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
import io.swagger.v3.oas.annotations.media.Schema;
|
|
|
|
|
import jakarta.validation.constraints.Pattern;
|
|
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
|
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage;
|
|
|
|
|
import com.youlai.boot.mini.model.query.AiTaskMediaQuery;
|
|
|
|
|
import com.youlai.boot.mini.model.vo.AiGenerationTaskVO;
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import com.youlai.boot.mini.model.vo.UserUploadMediaVO;
|
|
|
|
|
|
|
|
|
|
@Tag(name = "AI生成相关接口")
|
|
|
|
|
@RestController
|
|
|
|
|
@RequestMapping("/api/v1/mini/ai/generation")
|
|
|
|
|
@RequiredArgsConstructor
|
|
|
|
|
@Valid
|
|
|
|
|
public class AiGenerationController {
|
|
|
|
|
|
|
|
|
|
private final AiGenerationService aiGenerationService;
|
|
|
|
|
private final WxSubscribeService wxSubscribeService;
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "上传AI生成参考文件")
|
|
|
|
|
@PostMapping(value = "/upload/reference", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
|
|
|
|
|
@RepeatSubmit
|
|
|
|
|
@Log(module = LogModuleEnum.AI_TASK_MEDIA, value = ActionTypeEnum.INSERT)
|
|
|
|
|
public Result<List<String>> uploadReferenceFile(
|
|
|
|
|
@RequestParam(name = "images", required = false) List<MultipartFile> images,
|
|
|
|
|
@RequestParam(name = "videos", required = false) List<MultipartFile> videos
|
|
|
|
|
) {
|
|
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
|
|
List<String> urlList = aiGenerationService.uploadReferenceFile(images, videos, userId);
|
|
|
|
|
return Result.success(urlList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "提交单图生成任务")
|
|
|
|
|
@PostMapping("/generate-single-image")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.INSERT)
|
|
|
|
|
public Result<String> generateSingleImage(@Valid @RequestBody AiSingleImageGenerateForm form) {
|
|
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
|
|
String taskUuid = aiGenerationService.createAndGenerateImage(form, userId);
|
|
|
|
|
return Result.success(taskUuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "单图任务回调接口")
|
|
|
|
|
@PostMapping("/single-image/task/callback")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.UPDATE)
|
|
|
|
|
public Result<Boolean> singleImageTaskCallback(@Valid @RequestBody AiSingleImageCallbackForm form) {
|
|
|
|
|
boolean success = aiGenerationService.handleTaskCallback(form);
|
|
|
|
|
return Result.success(success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "提交四宫格漫画生成任务")
|
|
|
|
|
@PostMapping("/generate-four-panel")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.INSERT)
|
|
|
|
|
public Result<String> generateFourPanelImage(@Valid @RequestBody AiFourPanelGenerateForm form) {
|
|
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
|
|
String taskUuid = aiGenerationService.createAndGenerateFourPanel(form, userId);
|
|
|
|
|
return Result.success(taskUuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "四宫格漫画任务回调接口")
|
|
|
|
|
@PostMapping("/four-panel/task/callback")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.UPDATE)
|
|
|
|
|
public Result<Boolean> fourPanelTaskCallback(@Valid @RequestBody AiFourPanelCallbackForm form) {
|
|
|
|
|
boolean success = aiGenerationService.handleFourPanelCallback(form);
|
|
|
|
|
return Result.success(success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "提交视频生成任务")
|
|
|
|
|
@PostMapping("/generate-video")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.INSERT)
|
|
|
|
|
public Result<String> generateVideo(@Valid @RequestBody AiVideoGenerateForm form) {
|
|
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
|
|
String taskUuid = aiGenerationService.createAndGenerateVideo(form, userId);
|
|
|
|
|
return Result.success(taskUuid);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "视频任务回调接口")
|
|
|
|
|
@PostMapping("/video/task/callback")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.UPDATE)
|
|
|
|
|
public Result<Boolean> videoTaskCallback(@Valid @RequestBody AiVideoCallbackVO vo) {
|
|
|
|
|
boolean success = aiGenerationService.handleVideoTaskCallback(vo);
|
|
|
|
|
return Result.success(success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "上报微信订阅消息授权状态")
|
|
|
|
|
@PostMapping("/subscribe/auth/report")
|
|
|
|
|
@Log(module = LogModuleEnum.USER_SUBSCRIBE, value = ActionTypeEnum.UPDATE)
|
|
|
|
|
public Result<Void> reportSubscribeAuth(@Valid @RequestBody WxSubscribeAuthForm form) {
|
|
|
|
|
form.setUserId(SecurityUtils.getUserId());
|
|
|
|
|
wxSubscribeService.reportAuth(form);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Hidden
|
|
|
|
|
@Operation(summary = "发送微信订阅消息")
|
|
|
|
|
@PostMapping("/subscribe/send")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.INSERT)
|
|
|
|
|
public Result<Boolean> sendSubscribeMessage(@Valid @RequestBody WxSubscribeSendForm form) {
|
|
|
|
|
form.setUserId(SecurityUtils.getUserId());
|
|
|
|
|
Boolean result = wxSubscribeService.sendMessage(form);
|
|
|
|
|
return Result.success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "查询当前用户最近上传的图片视频")
|
|
|
|
|
@GetMapping("/my/recent-upload")
|
|
|
|
|
public Result<List<UserUploadMediaVO>> getMyRecentUpload() {
|
|
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
|
|
List<UserUploadMediaVO> voList = aiGenerationService.getRecentUploadVO(userId);
|
|
|
|
|
return Result.success(voList);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "删除用户上传的图片/视频")
|
|
|
|
|
@DeleteMapping("/my/upload/delete")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_TASK_MEDIA, value = ActionTypeEnum.DELETE)
|
|
|
|
|
public Result<Boolean> deleteMyUpload(@RequestParam String uuid) {
|
|
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
|
|
boolean success = aiGenerationService.deleteUploadMedia(userId, uuid);
|
|
|
|
|
return Result.success(success);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "查询我的AI生成任务历史")
|
|
|
|
|
@GetMapping("/my/history")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_TASK_MEDIA, value = ActionTypeEnum.LIST)
|
|
|
|
|
public Result<IPage<AiGenerationTaskVO>> getMyAiGenerateHistory(@Valid AiTaskMediaQuery query) {
|
|
|
|
|
Long userId = SecurityUtils.getUserId();
|
|
|
|
|
IPage<AiGenerationTaskVO> result = aiGenerationService.getMyAiGenerateHistory(query, userId);
|
|
|
|
|
return Result.success(result);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Operation(summary = "设置微信订阅消息跳转版本")
|
|
|
|
|
@PostMapping("/subscribe/mini-program-state/set")
|
|
|
|
|
@Log(module = LogModuleEnum.AI_GENERATION_TASK, value = ActionTypeEnum.UPDATE)
|
|
|
|
|
public Result<Void> setMiniProgramState(
|
|
|
|
|
@Schema(description = "跳转版本:developer=开发版 trial=体验版 formal=正式版,为空时删除配置")
|
|
|
|
|
@Pattern(regexp = "^(developer|trial|formal|)$", message = "参数只能是developer/trial/formal或为空")
|
|
|
|
|
@RequestParam(required = false) String miniProgramState
|
|
|
|
|
) {
|
|
|
|
|
aiGenerationService.setMiniProgramState(miniProgramState);
|
|
|
|
|
return Result.success();
|
|
|
|
|
}
|
|
|
|
|
}
|