From fb01250142ef8371b176f2242d09562b54fc308d Mon Sep 17 00:00:00 2001 From: xupei Date: Tue, 15 Jul 2025 13:02:59 +0800 Subject: [PATCH] =?UTF-8?q?BUGFIX:=20=E9=80=9A=E8=BF=87projectId=E8=8E=B7?= =?UTF-8?q?=E5=8F=96pose=20transfer=E7=BB=93=E6=9E=9C=E8=B7=AF=E5=BE=84?= =?UTF-8?q?=E5=87=BA=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/GenerateServiceImpl.java | 131 +++++++++++++++++- 1 file changed, 127 insertions(+), 4 deletions(-) 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 1996913d..3a31b5a2 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -1316,7 +1316,130 @@ public class GenerateServiceImpl extends ServiceImpl i if (flag) creditsService.updateChangedCredits(accountId, taskId); } - public List getPoseTransformationResult(List taskIdList) { + public List getPoseTransformationResult(List taskIdList, Long projectId, Boolean like) { + List resultList = new ArrayList<>(); + + // 处理按taskId列表查询的情况 + if (taskIdList != null && !taskIdList.isEmpty()) { + for (String taskId : taskIdList) { + PoseTransformationVO vo = buildPoseTransformationVO(taskId, null); + if (vo != null) { + resultList.add(vo); + } + } + } + // 处理按projectId和like查询的情况 + else if (projectId != null) { + QueryWrapper queryWrapper = new QueryWrapper() + .eq("project_id", projectId) + .ne("task_status", "Fail"); + + if (like != null) { + queryWrapper.eq("is_liked", like ? 1 : 0); + } + + List poseTransformations = poseTransformationMapper.selectList(queryWrapper); + + if (!CollectionUtils.isEmpty(poseTransformations)) { + for (PoseTransformation item : poseTransformations) { + PoseTransformationVO vo = buildPoseTransformationVO(item.getUniqueId(), item); + if (vo != null && !isInvalidStatus(vo.getStatus())) { + resultList.add(vo); + } + } + } + } + + return resultList; + } + + private PoseTransformationVO buildPoseTransformationVO(String taskId, PoseTransformation dbItem) { + String type = resolveModelType(taskId, CreditsEventsEnum.POSE_TRANSFORMATION.getValue()); + String key = generateResultKey + ":" + taskId; + String resultJson = redisUtil.getFromString(key); + + PoseTransformationVO vo; + + // 1. 优先从Redis获取数据 + if (!StringUtil.isNullOrEmpty(resultJson)) { + vo = new Gson().fromJson(resultJson, PoseTransformationVO.class); + + // 设置数据库中的额外字段 + if (dbItem != null) { + vo.setId(dbItem.getId()); + vo.setIsLiked(dbItem.getIsLiked()); + } + + // 处理成功状态的数据 + if ("Success".equals(vo.getStatus()) && !"wx".equals(type)) { + processAllUrls(vo, dbItem); + } + + vo.setResultType(CollectionType.POSE_TRANSFORM.getValue()); + } + // 2. 处理wx类型的情况 + else if ("wx".equals(type)) { + vo = getAnimateResult(taskId); + } + // 3. 处理既没有Redis数据也不是wx类型的情况 + else { + // 如果有数据库记录 + if (dbItem != null) { + vo = CopyUtil.copyObject(dbItem, PoseTransformationVO.class); + vo.setTaskId(taskId); + + // 设置产品图片URL + if (dbItem.getProductImage() != null) { + vo.setProductImage(minioUtil.getPreSignedUrl( + dbItem.getProductImage(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); + } + + // 如果视频URL为空,直接返回 + if (StringUtil.isNullOrEmpty(dbItem.getVideoUrl())) { + return vo; + } + + processAllUrls(vo, dbItem); + } + // 如果没有数据库记录 + else { + vo = new PoseTransformationVO(taskId, "Executing"); + } + } + + // 处理父ID逻辑 + processParentId(vo, dbItem != null ? dbItem : + poseTransformationMapper.selectOne(new QueryWrapper().eq("unique_id", taskId))); + + return vo; + } + + private void processAllUrls(PoseTransformationVO vo, PoseTransformation dbItem) { + // 处理各种URL + processUrl(vo.getGifUrl(), url -> + vo.setGifUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(vo.getVideoUrl(), url -> + vo.setVideoUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(vo.getFirstFrameUrl(), url -> + vo.setFirstFrameUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + } + + private void processParentId(PoseTransformationVO vo, PoseTransformation poseTransformation) { + if (poseTransformation != null) { + ToProductImageResult productResult = getProductResultByPath(poseTransformation.getProductImage()); + if (productResult != null) { + Long parentId = userLikeGroupService.getParentIdByElementIdAndElementType( + productResult.getId(), CollectionType.TO_PRODUCT_IMAGE.getValue()); + vo.setParentId(parentId); + } + } + } + + private boolean isInvalidStatus(String status) { + return "Invalid".equals(status) || "Fail".equals(status); + } + + /* public List getPoseTransformationResult(List taskIdList) { ArrayList poseTransformationVOS = new ArrayList<>(); for (String taskId : taskIdList) { String type = resolveModelType(taskId, CreditsEventsEnum.POSE_TRANSFORMATION.getValue()); @@ -1353,7 +1476,7 @@ public class GenerateServiceImpl extends ServiceImpl i poseTransformationVOS.add(poseTransformationVO); } return poseTransformationVOS; - } + }*/ public void updatePoseTransferStatus(String taskId, String status){ PoseTransformation poseTransformation = poseTransformationMapper.selectOne(new QueryWrapper().eq("unique_id", taskId)); @@ -1371,7 +1494,7 @@ public class GenerateServiceImpl extends ServiceImpl i return toProductImageResultMapper.selectOne(qw); } - public List getPoseTransformationResultList(Long projectId, boolean like) { + /*public List getPoseTransformationResultList(Long projectId, boolean like) { List poseTransformations = poseTransformationMapper.selectList(new QueryWrapper().eq("project_id", projectId) .eq("is_liked", like ? 1 : 0).ne("task_status", "Fail")); List vos = new ArrayList<>(); @@ -1434,7 +1557,7 @@ public class GenerateServiceImpl extends ServiceImpl i } } return vos; - } + }*/ // 辅助方法:处理URL private void processUrl(String url, Consumer processor) {