@@ -905,15 +905,15 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
}
// 将构建好的结果对象添加到返回列表
results. add ( magicToolResultVO) ;
// results.add( magicToolResultVO) ;
} else if ( Objects . isNull ( magicToolResultVO ) ) {
// 如果Redis中没有结果对象, 创建执行中状态的结果对象
magicToolResultVO = new MagicToolResultVO ( taskId , " Executing " ) ;
results. add ( magicToolResultVO) ;
} else {
// results.add( magicToolResultVO) ;
} /* else {
// 如果Redis中有结果对象但URL为空, 直接添加到返回列表
results.add(magicToolResultVO);
}
}*/
// 收集任务状态用于统计
if ( ! StringUtil . isNullOrEmpty ( magicToolResultVO . getStatus ( ) ) ) collect . add ( magicToolResultVO . getStatus ( ) ) ;
@@ -1461,12 +1461,16 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
if ( StringUtil . isNullOrEmpty ( fluxResult ) ) {
toProductImageResult . setStatus ( " Fail " ) ;
toProductImageResultMapper . updateById ( toProductImageResult ) ;
sortRank ( toProductImageResult ) ;
if ( toProductImageResult . getIsLike ( ) ! = null & & toProductImageResult . getIsLike ( ) = = 1 ) {
sortRank ( toProductImageResult ) ;
}
results . add ( new MagicToolResultVO ( taskId , " Fail " ) ) ;
} else if ( fluxResult . equals ( " Fail " ) | | fluxResult . equals ( " Pending " ) ) {
toProductImageResult . setStatus ( fluxResult ) ;
toProductImageResultMapper . updateById ( toProductImageResult ) ;
sortRank ( toProductImageResult ) ;
if ( fluxResult . equals ( " Fail " ) & & toProductImageResult . getIsLike ( ) ! = null & & toProductImageResult . getIsLike ( ) = = 1 ) {
sortRank ( toProductImageResult ) ;
}
results . add ( new MagicToolResultVO ( taskId , fluxResult ) ) ;
} else {
results . add ( processFluxResult ( fluxResult , toProductImageResult , taskId , toProductImageRecord . getPrompt ( ) ) ) ;
@@ -2203,10 +2207,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
childCollectionQw . lambda ( ) . orderByAsc ( CollectionSort : : getSort ) ;
List < CollectionSort > childSortList = collectionSortMapper . selectList ( childCollectionQw ) ;
List < AllCollectionVO > childList = new ArrayList < > ( ) ;
// 收集需要删除的失败记录ID, 用于后续统一清理并重新排序
List < Long > 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 +2246,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
} else if ( userLikeSort . getRelationType ( ) . equals ( CollectionType . RELIGHT . getValue ( ) ) ) {
ToProductImageResult toProductImageResult = toProductImageResultMapper . selectById ( userLikeSort . getRelationId ( ) ) ;
if ( isGenerateTaskFailed ( toProductImageResult . getStatus ( ) , toProductImageResult . getCreateTime ( ) ) ) {
failedSortIds . add ( userLikeSort . getId ( ) ) ;
log . info ( " 【获取内容】RELIGHT结果失败, relationId={}, 即将从collection_sort中删除 " , userLikeSort . getRelationId ( ) ) ;
continue ;
}
toProductImageResult . setUrl ( getMinioUrl ( toProductImageResult . getUrl ( ) ) ) ;
@@ -2269,6 +2279,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
} else if ( userLikeSort . getRelationType ( ) . equals ( CollectionType . POSE_TRANSFORM . getValue ( ) ) ) {
PoseTransformation item = poseTransformationMapper . selectById ( userLikeSort . getRelationId ( ) ) ;
if ( isGenerateTaskFailed ( item . getTaskStatus ( ) , item . getCreateTime ( ) ) ) {
failedSortIds . add ( userLikeSort . getId ( ) ) ;
log . info ( " 【获取内容】POSE_TRANSFORM结果失败, relationId={}, 即将从collection_sort中删除 " , userLikeSort . getRelationId ( ) ) ;
continue ;
}
PoseTransformationVO poseTransformationVO = new PoseTransformationVO ( ) ;
@@ -2293,6 +2305,114 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
childList . add ( poseTransformationVO ) ;
}
}
// 统一处理失败的记录: 从collection_sort表中删除失败的记录, 并重新排序
if ( CollectionUtil . isNotEmpty ( failedSortIds ) ) {
Long parentId = collectionSort . getId ( ) ;
Long projectId = projectDTO . getId ( ) ;
log . info ( " 【获取内容】检测到{}条失败记录需要清理, parentId={}, projectId={} " , failedSortIds . size ( ) , parentId , projectId ) ;
for ( Long failedSortId : failedSortIds ) {
CollectionSort failedRecord = collectionSortMapper . selectById ( failedSortId ) ;
if ( failedRecord ! = null ) {
String relationType = failedRecord . getRelationType ( ) ;
Long relationId = failedRecord . getRelationId ( ) ;
collectionSortService . deleteCollectionSort ( relationId , relationType , projectId , parentId ) ;
log . info ( " 【获取内容】已删除失败记录, relationId={}, relationType={} " , relationId , relationType ) ;
}
}
// 重新查询子列表,获取更新后的排序
childSortList = collectionSortMapper . selectList ( childCollectionQw ) ;
// 重新构建childList, 使用更新后的sort值
childList = 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 ( ) ) ) {
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 ) ;