diff --git a/src/main/java/com/ai/da/controller/SavedCollectionController.java b/src/main/java/com/ai/da/controller/SavedCollectionController.java index 29a4b80f..94c247f9 100644 --- a/src/main/java/com/ai/da/controller/SavedCollectionController.java +++ b/src/main/java/com/ai/da/controller/SavedCollectionController.java @@ -253,7 +253,32 @@ public class SavedCollectionController { @Operation(summary = "relight") @PostMapping("/relight") public Response> relight(@Valid @RequestBody ToProductImageDTO toProductImageDTO) { - return Response.success(userLikeGroupService.relight(toProductImageDTO)); + log.info("【relight请求】收到relight请求, projectId={}, isDefaultLike={}, taskCount={}", + toProductImageDTO.getProjectId(), + toProductImageDTO.getIsDefaultLike(), + toProductImageDTO.getToProductImageVOList() != null ? toProductImageDTO.getToProductImageVOList().size() : 0); + long startTime = System.currentTimeMillis(); + List result = userLikeGroupService.relight(toProductImageDTO); + long costTime = System.currentTimeMillis() - startTime; + log.info("【relight请求】relight请求处理完成, projectId={}, 返回结果数={}, 耗时={}ms", + toProductImageDTO.getProjectId(), + result != null ? result.size() : 0, + costTime); + // 打印返回结果中的关键信息,用于追踪 collection_sort 变动 + if (result != null) { + for (int i = 0; i < result.size(); i++) { + ToProductImageResultVO vo = result.get(i); + log.info("【relight请求】第{}个结果: id={}, taskId={}, isLike={}, parentId={}, sort={}, status={}", + i + 1, + vo.getId(), + vo.getTaskId(), + vo.getIsLike(), + vo.getParentId(), + vo.getSort(), + vo.getStatus()); + } + } + return Response.success(result); } @Operation(summary = "转relight元素") @@ -265,7 +290,27 @@ public class SavedCollectionController { @Operation(summary = "获取relight结果") @PostMapping("/relightResult") public Response> getRelightResult(@Valid @RequestBody List taskIdList) { + log.info("【getRelightResult请求】收到获取relight结果请求, taskIdList={}", taskIdList); + long startTime = System.currentTimeMillis(); List magicToolResultVOList = userLikeGroupService.getRelightResult(taskIdList); + long costTime = System.currentTimeMillis() - startTime; + log.info("【getRelightResult请求】获取relight结果处理完成, taskIdList={}, 返回结果数={}, 耗时={}ms", + taskIdList, + magicToolResultVOList != null ? magicToolResultVOList.size() : 0, + costTime); + // 打印返回结果中的关键信息,用于追踪 collection_sort 变动 + if (magicToolResultVOList != null) { + for (int i = 0; i < magicToolResultVOList.size(); i++) { + MagicToolResultVO vo = magicToolResultVOList.get(i); + log.info("【getRelightResult请求】第{}个结果: taskId={}, status={}, id={}, parentId={}, url={}", + i + 1, + vo.getTaskId(), + vo.getStatus(), + vo.getId(), + vo.getParentId(), + vo.getUrl() != null ? (vo.getUrl().length() > 50 ? vo.getUrl().substring(0, 50) + "..." : vo.getUrl()) : null); + } + } return Response.success(magicToolResultVOList); } diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index 47e8b587..f06fdc21 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -905,15 +905,15 @@ public class UserLikeGroupServiceImpl extends ServiceImpl result = new ArrayList<>(); @@ -1352,20 +1353,30 @@ public class UserLikeGroupServiceImpl extends ServiceImpl results = new ArrayList<>(); Set collect = new HashSet<>(); taskIdList.forEach(taskId -> { + log.info("【getRelightResult方法】开始处理taskId={}", taskId); QueryWrapper qw = new QueryWrapper<>(); qw.lambda().eq(ToProductImageResult::getTaskId, taskId); ToProductImageResult toProductImageResult = toProductImageResultMapper.selectOne(qw); if (Objects.isNull(toProductImageResult)) { + log.error("【getRelightResult方法】未找到toProductImageResult记录, taskId={}", taskId); throw new BusinessException("source.image.does.not.exist"); } + log.info("【getRelightResult方法】找到toProductImageResult记录, id={}, taskId={}, status={}, modelName={}, isLike={}", + toProductImageResult.getId(), taskId, toProductImageResult.getStatus(), + toProductImageResult.getModelName(), toProductImageResult.getIsLike()); + + // 查询collection_sort记录,用于追踪 + QueryWrapper sortQw = new QueryWrapper<>(); + sortQw.lambda().eq(CollectionSort::getRelationId, toProductImageResult.getId()) + .eq(CollectionSort::getRelationType, CollectionType.RELIGHT.getValue()); + List beforeSorts = collectionSortMapper.selectList(sortQw); + log.info("【getRelightResult方法】处理前collection_sort记录数={}, resultId={}", beforeSorts.size(), toProductImageResult.getId()); + if (!beforeSorts.isEmpty()) { + for (CollectionSort cs : beforeSorts) { + log.info("【getRelightResult方法】处理前collection_sort记录: id={}, relationId={}, sort={}", cs.getId(), cs.getRelationId(), cs.getSort()); + } + } + ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResult.getToProductImageRecordId()); if (Objects.isNull(toProductImageRecord)) { + log.error("【getRelightResult方法】未找到toProductImageRecord记录, recordId={}", toProductImageResult.getToProductImageRecordId()); throw new BusinessException("This task does not exist."); } // 判断当任务从哪个模型获取结果 if (!StringUtil.isNullOrEmpty(toProductImageResult.getModelName()) && toProductImageResult.getModelName().equals("flux")) { + log.info("【getRelightResult方法】使用flux模型处理, resultId={}", toProductImageResult.getId()); Project project = projectService.getById(toProductImageResult.getProjectId()); if (Objects.isNull(project)) { + log.error("【getRelightResult方法】未找到project记录, projectId={}", toProductImageResult.getProjectId()); throw new BusinessException("unknown project"); } String fluxResult; if (toProductImageResult.getStatus().equals("Success") && !StringUtil.isNullOrEmpty(toProductImageResult.getUrl())) { + log.info("【getRelightResult方法】数据库中已有成功结果,直接使用, resultId={}", toProductImageResult.getId()); fluxResult = toProductImageResult.getUrl(); } else { String objectName = project.getAccountId() + "/relight_image/" + taskId + ".png"; + log.info("【getRelightResult方法】调用getFluxResult获取结果, resultId={}, objectName={}", toProductImageResult.getId(), objectName); fluxResult = generateService.getFluxResult(taskId, objectName); + log.info("【getRelightResult方法】getFluxResult返回结果, resultId={}, fluxResult={}", toProductImageResult.getId(), fluxResult); } if (StringUtil.isNullOrEmpty(fluxResult)) { + log.warn("【getRelightResult方法】fluxResult为null,判定为失败, resultId={}, isLike={}", toProductImageResult.getId(), toProductImageResult.getIsLike()); toProductImageResult.setStatus("Fail"); toProductImageResultMapper.updateById(toProductImageResult); - sortRank(toProductImageResult); + if (toProductImageResult.getIsLike() != null && toProductImageResult.getIsLike() == 1) { + log.info("【getRelightResult方法】isLike=1,准备调用sortRank删除collection_sort记录, resultId={}", toProductImageResult.getId()); + sortRank(toProductImageResult); + } else { + log.info("【getRelightResult方法】isLike不等于1,不删除collection_sort记录, resultId={}, isLike={}", toProductImageResult.getId(), toProductImageResult.getIsLike()); + } results.add(new MagicToolResultVO(taskId, "Fail")); } else if (fluxResult.equals("Fail") || fluxResult.equals("Pending")) { + log.warn("【getRelightResult方法】fluxResult为{},判定为失败/待处理, resultId={}, isLike={}", fluxResult, toProductImageResult.getId(), toProductImageResult.getIsLike()); toProductImageResult.setStatus(fluxResult); toProductImageResultMapper.updateById(toProductImageResult); - sortRank(toProductImageResult); + if (toProductImageResult.getIsLike() != null && toProductImageResult.getIsLike() == 1) { + log.info("【getRelightResult方法】isLike=1,准备调用sortRank删除collection_sort记录, resultId={}", toProductImageResult.getId()); + sortRank(toProductImageResult); + } else { + log.info("【getRelightResult方法】isLike不等于1,不删除collection_sort记录, resultId={}, isLike={}", toProductImageResult.getId(), toProductImageResult.getIsLike()); + } results.add(new MagicToolResultVO(taskId, fluxResult)); } else { + log.info("【getRelightResult方法】fluxResult有效,调用processFluxResult处理成功结果, resultId={}", toProductImageResult.getId()); results.add(processFluxResult(fluxResult, toProductImageResult, taskId, toProductImageRecord.getPrompt())); // 扣积分 Boolean flag = creditsService.taskCreditsDeduction(project.getAccountId(), taskId); @@ -1479,9 +1538,21 @@ public class UserLikeGroupServiceImpl extends ServiceImpl afterSorts = collectionSortMapper.selectList(sortQw); + log.info("【getRelightResult方法】处理后collection_sort记录数={}, resultId={}", afterSorts.size(), toProductImageResult.getId()); + if (!afterSorts.isEmpty()) { + for (CollectionSort cs : afterSorts) { + log.info("【getRelightResult方法】处理后collection_sort记录: id={}, relationId={}, sort={}", cs.getId(), cs.getRelationId(), cs.getSort()); + } + } else if (!beforeSorts.isEmpty()) { + log.warn("【getRelightResult方法】collection_sort记录被删除了! resultId={}, 处理前记录数={}, 处理后记录数=0", toProductImageResult.getId(), beforeSorts.size()); + } + return; } + log.info("【getRelightResult方法】非flux模型,从Redis获取结果, resultId={}", toProductImageResult.getId()); String key = relightResultKey + ":" + taskId; MagicToolResultVO magicToolResultVO = new Gson().fromJson(redisUtil.getFromString(key), MagicToolResultVO.class); if (!Objects.isNull(magicToolResultVO) && !StringUtil.isNullOrEmpty(magicToolResultVO.getUrl())) { @@ -1513,7 +1584,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl childSortList = collectionSortMapper.selectList(childCollectionQw); List childList = new ArrayList<>(); + // 收集需要删除的失败记录ID,用于后续统一清理并重新排序 + List failedSortIds = new ArrayList<>(); for (CollectionSort userLikeSort : childSortList) { if (userLikeSort.getRelationType().equals(CollectionType.TO_PRODUCT_IMAGE.getValue())) { ToProductImageResult toProductImageResult = toProductImageResultMapper.selectById(userLikeSort.getRelationId()); if (isGenerateTaskFailed(toProductImageResult.getStatus(), toProductImageResult.getCreateTime())) { + failedSortIds.add(userLikeSort.getId()); + log.info("【获取内容】TO_PRODUCT_IMAGE结果失败,relationId={},即将从collection_sort中删除", userLikeSort.getRelationId()); continue; } toProductImageResult.setUrl(getMinioUrl(toProductImageResult.getUrl())); @@ -2238,6 +2315,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl(); + for (CollectionSort userLikeSort : childSortList) { + if (userLikeSort.getRelationType().equals(CollectionType.TO_PRODUCT_IMAGE.getValue())) { + ToProductImageResult toProductImageResult = toProductImageResultMapper.selectById(userLikeSort.getRelationId()); + if (isGenerateTaskFailed(toProductImageResult.getStatus(), toProductImageResult.getCreateTime())) { + continue; + } + toProductImageResult.setUrl(getMinioUrl(toProductImageResult.getUrl())); + ToProductImageResultVO toProductImageResultVO = CopyUtil.copyObject(toProductImageResult, ToProductImageResultVO.class); + + ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResult.getToProductImageRecordId()); + if (Objects.isNull(toProductImageRecord)) { + continue; + } + toProductImageResultVO.setPrompt(toProductImageRecord.getPrompt()); + + if (toProductImageResultVO.getElementType().equals("ProductElement")) { + ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(toProductElement.getUrl())); + } else if ((toProductImageResultVO.getElementType().equals("DesignOutfit"))) { + TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(tDesignPythonOutfit.getDesignUrl())); + } else { + ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(toProductImageResult1.getUrl())); + } + toProductImageResultVO.setCollectionType(CollectionType.TO_PRODUCT_IMAGE.getValue()); + toProductImageResultVO.setSort(userLikeSort.getSort()); + toProductImageResultVO.setUserLikeSortId(userLikeSort.getId()); + toProductImageResultVO.setRelationType(userLikeSort.getRelationType()); + toProductImageResultVO.setParentId(userLikeSort.getParentId()); + childList.add(toProductImageResultVO); + } else if (userLikeSort.getRelationType().equals(CollectionType.RELIGHT.getValue())) { + ToProductImageResult toProductImageResult = toProductImageResultMapper.selectById(userLikeSort.getRelationId()); + if (isGenerateTaskFailed(toProductImageResult.getStatus(), toProductImageResult.getCreateTime())) { + continue; + } + toProductImageResult.setUrl(getMinioUrl(toProductImageResult.getUrl())); + ToProductImageResultVO toProductImageResultVO = CopyUtil.copyObject(toProductImageResult, ToProductImageResultVO.class); + + ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResult.getToProductImageRecordId()); + if (Objects.isNull(toProductImageRecord)) { + continue; + } + toProductImageResultVO.setPrompt(toProductImageRecord.getPrompt()); + + if (toProductImageResultVO.getElementType().equals("ProductElement")) { + ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(toProductElement.getUrl())); + } else if ((toProductImageResultVO.getElementType().equals("DesignOutfit"))) { + TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(tDesignPythonOutfit.getDesignUrl())); + } else { + ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(toProductImageResult1.getUrl())); + } + toProductImageResultVO.setCollectionType(CollectionType.RELIGHT.getValue()); + toProductImageResultVO.setSort(userLikeSort.getSort()); + toProductImageResultVO.setUserLikeSortId(userLikeSort.getId()); + toProductImageResultVO.setRelationType(userLikeSort.getRelationType()); + toProductImageResultVO.setParentId(userLikeSort.getParentId()); + childList.add(toProductImageResultVO); + } else if (userLikeSort.getRelationType().equals(CollectionType.POSE_TRANSFORM.getValue())) { + PoseTransformation item = poseTransformationMapper.selectById(userLikeSort.getRelationId()); + if (isGenerateTaskFailed(item.getTaskStatus(), item.getCreateTime())) { + continue; + } + PoseTransformationVO poseTransformationVO = new PoseTransformationVO(); + poseTransformationVO.setId(item.getId()); + poseTransformationVO.setTaskId(item.getUniqueId()); + poseTransformationVO.setProductImage(getMinioUrl(item.getProductImage())); + poseTransformationVO.setLastFrameProductImage(getMinioUrl(item.getLastFrameProductImage())); + poseTransformationVO.setPrompt(item.getPrompt()); + poseTransformationVO.setGifUrl(getMinioUrl(item.getGifUrl())); + poseTransformationVO.setVideoUrl(getMinioUrl(item.getVideoUrl())); + poseTransformationVO.setFirstFrameUrl(getMinioUrl(item.getFirstFrameUrl())); + poseTransformationVO.setIsLiked(item.getIsLiked()); + poseTransformationVO.setCollectionType(CollectionType.POSE_TRANSFORM.getValue()); + poseTransformationVO.setSort(userLikeSort.getSort()); + poseTransformationVO.setUserLikeSortId(userLikeSort.getId()); + poseTransformationVO.setRelationType(userLikeSort.getRelationType()); + poseTransformationVO.setResultType(CollectionType.POSE_TRANSFORM.getValue()); + poseTransformationVO.setParentId(userLikeSort.getParentId()); + poseTransformationVO.setModelName(item.getModelName()); + poseTransformationVO.setPoseId(item.getPoseId()); + poseTransformationVO.setStatus(item.getTaskStatus()); + childList.add(poseTransformationVO); + } + } + log.info("【获取内容】失败记录清理完成,重新排序后childList.size={}", childList.size()); + } o.setChildList(childList); list.add(o);