From 98ea6004b4ce73fd44d9ecac41d679c3eb1217c8 Mon Sep 17 00:00:00 2001 From: xupei Date: Wed, 18 Jun 2025 14:19:45 +0800 Subject: [PATCH] =?UTF-8?q?TASK:=20=E6=96=B0=E5=A2=9Epose=20transfer?= =?UTF-8?q?=E6=A8=A1=E7=89=B9=E5=A7=BF=E5=8A=BF=E9=80=89=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/ai/da/common/enums/PoseEnum.java | 72 +++++++++++++++++++ .../com/ai/da/common/utils/RedisUtil.java | 2 - .../da/service/impl/GenerateServiceImpl.java | 28 ++++---- 3 files changed, 86 insertions(+), 16 deletions(-) create mode 100644 src/main/java/com/ai/da/common/enums/PoseEnum.java diff --git a/src/main/java/com/ai/da/common/enums/PoseEnum.java b/src/main/java/com/ai/da/common/enums/PoseEnum.java new file mode 100644 index 00000000..713e791e --- /dev/null +++ b/src/main/java/com/ai/da/common/enums/PoseEnum.java @@ -0,0 +1,72 @@ +package com.ai.da.common.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.*; +import java.util.function.Function; +import java.util.stream.Collectors; + +@AllArgsConstructor +@Getter +public enum PoseEnum { + + POSE_1(1L, "aida-sys-image/pose/pose-1.mp4", "aida-sys-image/pose/pose-1.gif", "aida-sys-image/pose/pose-1-first_frame.jpeg", "AACT.8090e67b.-E3pujumEfCbDTI_rjSH-A.LwIlGT3j"), + POSE_2(2L, "aida-sys-image/pose/pose-2.mp4", "aida-sys-image/pose/pose-2.gif", "aida-sys-image/pose/pose-2-first_frame.jpeg", "AACT.8090e67b.TwJLxEv3EfCbDTI_rjSH-A.IOQZCYhf"), + POSE_3(3L, "aida-sys-image/pose/pose-3.mp4", "aida-sys-image/pose/pose-3.gif", "aida-sys-image/pose/pose-3-first_frame.jpeg", "AACT.8090e67b.gd3OCkv4EfCxyZo8eQGF2Q.qMm-a1XI"), + POSE_4(4L, "aida-sys-image/pose/pose-4.mp4", "aida-sys-image/pose/pose-4.gif", "aida-sys-image/pose/pose-4-first_frame.jpeg", "AACT.8090e67b.AUDnuEwDEfCEHBaRJeW4dg.rlx36xEY"), + POSE_5(5L, "aida-sys-image/pose/pose-5.mp4", "aida-sys-image/pose/pose-5.gif", "aida-sys-image/pose/pose-5-first_frame.jpeg", "AACT.8090e67b.G8BvkEwEEfCxyZo8eQGF2Q.fo4ryrgR"), + POSE_6(6L, "aida-sys-image/pose/pose-6.mp4", "aida-sys-image/pose/pose-6.gif", "aida-sys-image/pose/pose-6-first_frame.jpeg", "AACT.8090e67b.yBIPnEwEEfCxyZo8eQGF2Q.boSFwTG9"); + + + private final Long id; + + private final String videoPath; + + private final String gifPath; + + private final String firstFramePath; + + private final String templateId; + + private static final List> PROPERTY_LIST; + + static { + PROPERTY_LIST = Arrays.stream(values()) + .map(PoseEnum::toMap) + .collect(Collectors.toList()); + } + + private static final Map BY_ID = Arrays.stream(values()) + .collect(Collectors.toMap(PoseEnum::getId, Function.identity())); + + private static final Map BY_VIDEO_PATH = Arrays.stream(values()) + .collect(Collectors.toMap(PoseEnum::getVideoPath, Function.identity())); + + private static final List VIDEO_PATH = Arrays.stream(values()) + .map(PoseEnum::getVideoPath).collect(Collectors.toList()); + + public static PoseEnum getById(Long id) { + return BY_ID.get(id); + } + + public static PoseEnum getByVideoPath(String videoPath) { + return BY_VIDEO_PATH.get(videoPath); + } + + private Map toMap() { + Map map = new HashMap<>(); + map.put("id", String.valueOf(id)); + map.put("gif", gifPath); + map.put("firstFrame", firstFramePath); + return map; + } + + public static List> getPropertyList() { + return new ArrayList<>(PROPERTY_LIST); // 返回副本以保证不可变性 + } + + public static List getVideoList() { + return new ArrayList<>(VIDEO_PATH); // 返回副本以保证不可变性 + } +} diff --git a/src/main/java/com/ai/da/common/utils/RedisUtil.java b/src/main/java/com/ai/da/common/utils/RedisUtil.java index 72d70588..e65366ee 100644 --- a/src/main/java/com/ai/da/common/utils/RedisUtil.java +++ b/src/main/java/com/ai/da/common/utils/RedisUtil.java @@ -498,8 +498,6 @@ public class RedisUtil { public final static String STRIPE_EXCEPTION_LOG = "StripeException:"; - public final static String ANIMATE_ANYONE_TEMPLATE_ID = "AnimateAnyoneTemplateId:"; - public void batchDeleteKeysWithSamePrefix(String prefix){ Set keys = redisTemplate.keys(prefix + "*"); assert keys != null; diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index 0a220a8e..dfe4dd30 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -1416,13 +1416,12 @@ public class GenerateServiceImpl extends ServiceImpl i } public List> getAllPose(){ - String posePath = "aida-sys-image/pose/pose-1.gif"; - String firstFramePath = "aida-sys-image/pose/pose-1-first_frame.jpeg"; - HashMap resp = new HashMap<>(); - // todo 以后要返回poseId - resp.put("gif", minioUtil.getPreSignedUrl(posePath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - resp.put("firstFrame", minioUtil.getPreSignedUrl(firstFramePath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - return Arrays.asList(resp); + List> propertyList = PoseEnum.getPropertyList(); + propertyList.forEach(item -> { + item.put("gif", minioUtil.getPreSignedUrl(item.get("gif"), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); + item.put("firstFrame", minioUtil.getPreSignedUrl(item.get("firstFrame"), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); + }); + return propertyList; } @Override @@ -1687,13 +1686,13 @@ public class GenerateServiceImpl extends ServiceImpl i // 轮询配置 private static final int MAX_RETRIES = 30; // 最大重试次数 - private static final int POLL_INTERVAL = 2000; // 轮询间隔(毫秒) + private static final int POLL_INTERVAL = 20000; // 轮询间隔(毫秒) public String getVideoTemplateId(String videoPath){ - String key = RedisUtil.ANIMATE_ANYONE_TEMPLATE_ID + videoPath; - String templateId = redisUtil.getFromString(key); + boolean contains = PoseEnum.getVideoList().contains(videoPath); - if (StringUtil.isNullOrEmpty(templateId)){ + String templateId; + if (!contains){ String videoUrl = minioUtil.getPreSignedUrl(videoPath, CommonConstant.MINIO_IMAGE_EXPIRE_TIME); JSONObject requestBody = new JSONObject(); requestBody.set("model", "animate-anyone-template-gen2"); @@ -1703,8 +1702,8 @@ public class GenerateServiceImpl extends ServiceImpl i requestBody.set("input", input); requestBody.set("parameters", parameters); - String resp = sendRequestUtil.sendPost(TEMPLATE_ID_GEN, requestBody.toString()); - + log.info("获取pose的模板id 请求数据:{}", requestBody); + String resp = sendRequestUtil.sendAliYunPostAsync(TEMPLATE_ID_GEN, requestBody.toString()); if (StringUtil.isNullOrEmpty(resp)){ throw new BusinessException("请求获取video template id失败"); } @@ -1719,7 +1718,8 @@ public class GenerateServiceImpl extends ServiceImpl i throw new BusinessException("获取动作模板失败"); } // templateId = "AACT.8090e67b.-E3pujumEfCbDTI_rjSH-A.LwIlGT3j"; - redisUtil.addToString(key, templateId); + } else { + templateId = PoseEnum.getByVideoPath(videoPath).getTemplateId(); } return templateId;