@@ -1315,45 +1315,6 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
if ( flag ) creditsService . updateChangedCredits ( accountId , taskId ) ;
}
public List < PoseTransformationVO > getPoseTransformationResult ( List < String > taskIdList ) {
ArrayList < PoseTransformationVO > poseTransformationVOS = new ArrayList < > ( ) ;
for ( String taskId : taskIdList ) {
String type = resolveModelType ( taskId , CreditsEventsEnum . POSE_TRANSFORMATION . getValue ( ) ) ;
String key = generateResultKey + " : " + taskId ;
String resultJson = redisUtil . getFromString ( key ) ;
PoseTransformationVO poseTransformationVO ;
if ( ! StringUtil . isNullOrEmpty ( resultJson ) ) {
poseTransformationVO = new Gson ( ) . fromJson ( redisUtil . getFromString ( key ) , PoseTransformationVO . class ) ;
if ( poseTransformationVO . getStatus ( ) . equals ( " Success " ) & & ! type . equals ( " wx " ) ) {
// 处理各种URL
processUrl ( poseTransformationVO . getGifUrl ( ) , url - >
poseTransformationVO . setGifUrl ( minioUtil . getPreSignedUrl ( url , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ) ;
processUrl ( poseTransformationVO . getVideoUrl ( ) , url - >
poseTransformationVO . setVideoUrl ( minioUtil . getPreSignedUrl ( url , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ) ;
processUrl ( poseTransformationVO . getFirstFrameUrl ( ) , url - >
poseTransformationVO . setFirstFrameUrl ( minioUtil . getPreSignedUrl ( url , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ) ;
}
poseTransformationVO . setResultType ( CollectionType . POSE_TRANSFORM . getValue ( ) ) ;
} else if ( type . equals ( " wx " ) ) {
poseTransformationVO = getAnimateResult ( taskId ) ;
} else {
poseTransformationVO = new PoseTransformationVO ( taskId , " Executing " ) ;
}
PoseTransformation poseTransformation = poseTransformationMapper . selectOne ( new QueryWrapper < PoseTransformation > ( ) . eq ( " unique_id " , taskId ) ) ;
if ( Objects . nonNull ( poseTransformation ) ) {
ToProductImageResult productResultByPath = getProductResultByPath ( poseTransformation . getProductImage ( ) ) ;
if ( Objects . nonNull ( productResultByPath ) ) {
Long parentId = userLikeGroupService . getParentIdByElementIdAndElementType ( productResultByPath . getId ( ) , CollectionType . TO_PRODUCT_IMAGE . getValue ( ) ) ;
poseTransformationVO . setParentId ( parentId ) ;
}
}
poseTransformationVOS . add ( poseTransformationVO ) ;
}
return poseTransformationVOS ;
}
public void updatePoseTransferStatus ( String taskId , String status ) {
PoseTransformation poseTransformation = poseTransformationMapper . selectOne ( new QueryWrapper < PoseTransformation > ( ) . eq ( " unique_id " , taskId ) ) ;
@@ -1370,66 +1331,114 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
return toProductImageResultMapper . selectOne ( qw ) ;
}
public List < PoseTransformationVO > getPoseTransformationResultList ( Long projectId , b oolean like ) {
List < PoseTransformation > poseTransformations = poseTransformationMapper . selectList ( new QueryWrapper < PoseTransformation > ( ) . eq ( " project_id " , projectId ) . eq ( " is_liked " , like ? 1 : 0 ) ) ;
List < PoseTransformationVO > vos = new ArrayList < > ( ) ;
// if (poseTransformations != null && poseTransformations.size() > 1){
if ( ! CollectionUtils . isEmpty ( poseTransformations ) ) {
for ( PoseTransformation item : poseTransformations ) {
String taskId = item . getUniqueId ( ) ;
String key = generateResultKey + " : " + taskId ;
String resultJson = redisUtil . getFromString ( key ) ;
public List < PoseTransformationVO > getPoseTransformationResult (List < String > taskIdList , Long projectId , B oolean like ) {
List < PoseTransformationVO > result = new ArrayList < > ( ) ;
PoseTransformationVO poseTransformationVO ;
// 处理通过taskIdList查询的情况
if ( taskIdList ! = null & & ! taskIdList . isEmpty ( ) ) {
for ( String taskId : taskIdList ) {
result . add ( getSinglePoseTransformationResult ( taskId ) ) ;
}
}
// 处理通过projectId和like查询的情况
else if ( projectId ! = null ) {
QueryWrapper < PoseTransformation > queryWrapper = new QueryWrapper < PoseTransformation > ( )
. eq ( " project_id " , projectId ) ;
if ( like ! = null ) {
queryWrapper . eq ( " is_liked " , like ? 1 : 0 ) ;
}
if ( ! StringUtil . isNullOrEmpty ( resultJson ) ) {
// 从Redis获取并转换数据
poseTransformationVO = new Gson ( ) . fromJson ( resultJson , PoseTransformationVO . class ) ;
poseTransformationVO . setId ( item . getId ( ) ) ;
poseTransformationVO . setIsLiked ( item . getIsLiked ( ) ) ;
List < PoseTransformation > poseTransformations = poseTransformationMapper . selectList ( queryWrapper ) ;
// 处理成功状态的数据
if ( " Success " . equals ( poseTransformationVO . getStatus ( ) ) ) {
p oseTransformationVO. setProductImage (
minioUtil . getPreSignedUrl ( item . getProductImage ( ) , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
// 处理各种URL
processUrl ( poseTransformationVO . getGifUrl ( ) , url - >
poseTransformationVO . setGifUrl ( minioUtil . getPreSignedUrl ( url , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ) ;
processUrl ( poseTransformationVO . getVideoUrl ( ) , url - >
poseTransformationVO . setVideoUrl ( minioUtil . getPreSignedUrl ( url , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ) ;
processUrl ( poseTransformationVO . getFirstFrameUrl ( ) , url - >
poseTransformationVO . setFirstFrameUrl ( minioUtil . getPreSignedUrl ( url , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ) ;
if ( ! CollectionUtils . isEmpty ( poseTransformations ) ) {
for ( PoseTransformation item : poseTransformations ) {
P oseTransformationVO vo = getSinglePoseTransformationResult ( item . getUniqueId ( ) , item ) ;
if ( vo ! = null & & ! " Invalid " . equals ( vo . getStatus ( ) ) & & ! " Failed " . equals ( vo . getStatus ( ) ) ) {
result . add ( vo ) ;
}
// 添加有效数据到结果列表
if ( ! " Invalid " . equals ( poseTransformationVO . getStatus ( ) ) & & ! " Failed " . equals ( poseTransformationVO . getStatus ( ) ) ) {
vos . add ( poseTransformationVO ) ;
}
} else {
// 处理Redis中没有缓存的情况
poseTransformationVO = CopyUtil . copyObject ( item , PoseTransformationVO . class ) ;
// todo 面对没有生成成功的情况 如何处理?
if ( StringUtil . isNullOrEmpty ( item . getVideoUrl ( ) ) ) {
continue ;
}
poseTransformationVO . setTaskId ( taskId ) ;
poseTransformationVO . setProductImage (
minioUtil . getPreSignedUrl ( item . getProductImage ( ) , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
// 处理各种URL
processUrl ( poseTransformationVO . getGifUrl ( ) , url - >
poseTransformationVO . setGifUrl ( minioUtil . getPreSignedUrl ( url , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ) ;
processUrl ( poseTransformationVO . getVideoUrl ( ) , url - >
poseTransformationVO . setVideoUrl ( minioUtil . getPreSignedUrl ( url , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ) ;
processUrl ( poseTransformationVO . getFirstFrameUrl ( ) , url - >
poseTransformationVO . setFirstFrameUrl ( minioUtil . getPreSignedUrl ( url , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ) ;
vos . add ( poseTransformationVO ) ;
}
}
}
return vos ;
return result ;
}
private PoseTransformationVO getSinglePoseTransformationResult ( String taskId ) {
return getSinglePoseTransformationResult ( taskId , null ) ;
}
private PoseTransformationVO getSinglePoseTransformationResult ( String taskId , PoseTransformation dbItem ) {
String type = resolveModelType ( taskId , CreditsEventsEnum . POSE_TRANSFORMATION . getValue ( ) ) ;
String key = generateResultKey + " : " + taskId ;
String resultJson = redisUtil . getFromString ( key ) ;
PoseTransformationVO poseTransformationVO ;
if ( ! StringUtil . isNullOrEmpty ( resultJson ) ) {
// 从Redis获取并转换数据
poseTransformationVO = new Gson ( ) . fromJson ( resultJson , PoseTransformationVO . class ) ;
// 如果是从数据库查询的路径,设置额外字段
if ( dbItem ! = null ) {
poseTransformationVO . setId ( dbItem . getId ( ) ) ;
poseTransformationVO . setIsLiked ( dbItem . getIsLiked ( ) ) ;
}
// 处理成功状态的数据
if ( " Success " . equals ( poseTransformationVO . getStatus ( ) ) & & ! " wx " . equals ( type ) ) {
// 处理产品图片URL
if ( dbItem ! = null & & dbItem . getProductImage ( ) ! = null ) {
poseTransformationVO . setProductImage (
minioUtil . getPreSignedUrl ( dbItem . getProductImage ( ) , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
}
// 处理各种URL
processUrls ( poseTransformationVO ) ;
}
poseTransformationVO . setResultType ( CollectionType . POSE_TRANSFORM . getValue ( ) ) ;
} else if ( " wx " . equals ( type ) ) {
poseTransformationVO = getAnimateResult ( taskId ) ;
} else {
// 如果没有Redis数据但有数据库记录
if ( dbItem ! = null ) {
poseTransformationVO = CopyUtil . copyObject ( dbItem , PoseTransformationVO . class ) ;
if ( StringUtil . isNullOrEmpty ( dbItem . getVideoUrl ( ) ) ) {
return null ;
}
poseTransformationVO . setTaskId ( taskId ) ;
poseTransformationVO . setProductImage (
minioUtil . getPreSignedUrl ( dbItem . getProductImage ( ) , CommonConstant . MINIO_IMAGE_EXPIRE_TIME ) ) ;
processUrls ( poseTransformationVO ) ;
} else {
poseTransformationVO = new PoseTransformationVO ( taskId , " Executing " ) ;
}
}
// 处理父ID逻辑
PoseTransformation poseTransformation = dbItem ! = null ? dbItem :
poseTransformationMapper . selectOne ( new QueryWrapper < PoseTransformation > ( ) . eq ( " unique_id " , taskId ) ) ;
if ( poseTransformation ! = null ) {
ToProductImageResult productResultByPath = getProductResultByPath ( poseTransformation . getProductImage ( ) ) ;
if ( productResultByPath ! = null ) {
Long parentId = userLikeGroupService . getParentIdByElementIdAndElementType (
productResultByPath . getId ( ) , CollectionType . TO_PRODUCT_IMAGE . getValue ( ) ) ;
poseTransformationVO . setParentId ( parentId ) ;
}
}
return poseTransformationVO ;
}
private void processUrls ( PoseTransformationVO vo ) {
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 ) ) ) ;
}
// 辅助方法: 处理URL