@@ -373,7 +373,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
private PoseTransformationMapper poseTransformationMapper ;
@Override
@Transactional ( rollbackFor = Exception . class )
public List < ToProductImageResult > toProduct ( ToProductImageDTO toProductImageDTO ) {
public List < ToProductImageResultVO > toProduct ( ToProductImageDTO toProductImageDTO ) {
// 判断用户当前积分是否够本次生成消耗
boolean fluxTask = ! StringUtil . isNullOrEmpty ( toProductImageDTO . getModelName ( ) )
& & toProductImageDTO . getModelName ( ) . equals ( " flux " ) ;
@@ -412,7 +412,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
toProductImageRecordMapper . insert ( toProductImageRecord ) ;
List < ToProductImageResult > result = new ArrayList < > ( ) ;
List < ToProductImageResultVO > result = new ArrayList < > ( ) ;
boolean childFlag = ! StringUtil . isNullOrEmpty ( toProductImageDTO . getAgeGroup ( ) )
& & toProductImageDTO . getAgeGroup ( ) . equals ( " Child " ) ;
int i = 0 ;
@@ -456,7 +456,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
} else {
sb . append ( " ,high quality clothing details, " ) . append ( prompt ) . append ( " ,8K realistic,HDR " ) ;
}
ToProductImageResult toProductImageResult = new ToProductImageResult ( ) ;
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO ( ) ;
if ( fluxTask ) {
if ( childFlag ) {
sb . append ( " , Children's face " ) ;
@@ -488,11 +488,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult . setResultType ( CollectionType . TO_PRODUCT_IMAGE . getValue ( ) ) ;
toProductImageResultMapper . insert ( toProductImageResult ) ;
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result . add ( toProductImageResult ) ;
// 满足条件情况下默认添加到like
addToProductLike ( toProductImageVO . getParentId ( ) , toProductImageResult . getId ( ) , toProductImageDTO . getProjectId ( ) ) ;
Integer sort = addToProductLike( toProductImageVO . getParentId ( ) , toProductImageResult . getId ( ) , toProductImageDTO . getProjectId ( ) ) ;
// 重新排序
reArrangeSort ( projectId , toProductImageResult . getId ( ) , CollectionType . TO_PRODUCT_IMAGE . getValue ( ) , toProductImageVO . getParentId ( ) ) ;
Integer reSort = rearrangeChildSort ( toProductImageResult . getId ( ) , CollectionType . TO_PRODUCT_IMAGE . getValue ( ) ,
toProductImageVO . getParentId ( ) , toProductImageVO . getUserLikeSortId ( ) ) ;
// 将生成结果的排序返回
toProductImageResult . setSort ( Objects . isNull ( reSort ) ? sort : reSort ) ;
result . add ( toProductImageResult ) ;
} else {
if ( StringUtils . isEmpty ( prompt ) ) {
sb . append ( " ,high quality clothing details,8K realistic,HDR " ) ;
@@ -502,7 +505,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
taskId = UUID . randomUUID ( ) + " - " + i + " - " + userHolder . getId ( ) ;
ToProductElement toProductElement = toProductElementMapper . selectById ( toProductImageVO . getElementId ( ) ) ;
ToProductImageResult toProductImageResult = new ToProductImageResult ( ) ;
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO ( ) ;
if ( fluxTask ) {
taskId = generateService . flux ( creditsEventsEnum , sb . toString ( ) , toProductElement . getUrl ( ) , childFlag ) ;
@@ -532,11 +535,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult . setResultType ( CollectionType . TO_PRODUCT_IMAGE . getValue ( ) ) ;
toProductImageResultMapper . insert ( toProductImageResult ) ;
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result . add ( toProductImageResult ) ;
// 满足条件情况下默认添加到like
addToProductLike ( toProductImageVO . getParentId ( ) , toProductImageResult . getId ( ) , toProductImageDTO . getProjectId ( ) ) ;
Integer sort = addToProductLike( toProductImageVO . getParentId ( ) , toProductImageResult . getId ( ) , toProductImageDTO . getProjectId ( ) ) ;
// 重新排序
reArrangeSort ( projectId , toProductImageResult . getId ( ) , CollectionType . TO_PRODUCT_IMAGE . getValue ( ) , toProductImageVO . getParentId ( ) ) ;
Integer reSort = rearrangeChildSort ( toProductImageResult . getId ( ) , CollectionType . TO_PRODUCT_IMAGE . getValue ( ) ,
toProductImageVO . getParentId ( ) , toProductImageVO . getUserLikeSortId ( ) ) ;
// 将生成结果的排序返回
toProductImageResult . setSort ( Objects . isNull ( reSort ) ? sort : reSort ) ;
result . add ( toProductImageResult ) ;
}
i + + ;
sb = new StringBuilder ( " The best quality, masterpiece, real image. " ) ;
@@ -548,57 +554,39 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return result ;
}
private void addToProductLike ( Long parentId , Long toProductImageResultId , Long projectId ) {
if ( Objects . nonNull ( parentId )
& & ! parentId . equals ( 0L ) ) {
productImageLike ( new ProductImageLikeDTO ( Collections . singletonList ( toProductImageResultId ) ,
private Integer addToProductLike ( Long parentId , Long toProductImageResultId , Long projectId ) {
if ( Objects . nonNull ( parentId ) & & ! parentId . equals ( 0L ) ) {
CollectionSort collectionSort = productImageLike ( new ProductImageLikeDTO ( Collections . singletonList ( toProductImageResultId ) ,
projectId , parentId ) ) ;
return Objects . nonNull ( collectionSort ) ? collectionSort . getSort ( ) : null ;
}
return null ;
}
/**
* 只有当使用子集中的元素进行生成时,才需要重新排序
* @param childId 生成元素的id
* @param parentId 父级id
* @param relationType 生成功能
* @param userLikeSortId 子集排序表中的id
*/
@Transactional
public void reA rrangeSort ( Long project Id, Long generateResultId , String relationType , Long parentId ) {
// 1. 处理子集排序
rearrangeChildSort ( generateResultId , parentId , relationType ) ;
// 2. 处理父级排序
rearrangeParentSort ( projectId , parentId ) ;
}
private void rearrangeChildSort ( Long childId , Long parentId , String relationType ) {
if ( Objects . isNull ( childId ) ) {
return ;
public Integer rea rrangeChild Sort ( Long child Id, String relationType , Long parentId , Long userLikeSortId ) {
if ( Objects . isNull ( userLikeSortId ) ) {
return null ;
}
CollectionSort child = collectionSortMapper . selectOne ( new QueryWrapper < CollectionSort > ( ) . eq ( " relation_id " , childId ) ) ;
if ( child = = null | | ! child . getRelationType ( ) . equals ( relationType ) ) {
return ;
if ( ! child . getRelationType ( ) . equals ( relationType ) ) {
return null ;
}
if ( child . getSort ( ) = = 1 ) {
return ; // 已经是第一位,无需处理
}
// 更新其他子集的排序
if ( ! " Design " . equals ( relationType ) ) {
collectionSortMapper . increaseGenerateSortBelow ( parentId , relationType , child . getSort ( ) ) ;
}
// 更新当前子集为第一位
child . setSort ( 1 ) ;
CollectionSort collectionSort = collectionSortMapper . selectById ( userLikeSortId ) ;
child . setSort ( collectionSort . getSort ( ) ) ;
// 原来排序的大于等于userLikeSortId的排序的, 都要+ 1
collectionSortMapper . increaseGenerateSortAbove ( parentId , relationType , collectionSort . getSort ( ) - 1 ) ;
// 当前的生成结果则填入userLikeSortId的排序位置
child . setUpdateTime ( LocalDateTime . now ( ) ) ;
collectionSortMapper . updateById ( child ) ;
}
private void rearrangeParentSort ( Long projectId , Long parentId ) {
CollectionSort parent = collectionSortMapper . selectById ( parentId ) ;
if ( parent = = null | | ! " Design " . equals ( parent . getRelationType ( ) ) ) {
return ;
}
if ( parent . getSort ( ) = = 1 ) {
return ; // 已经是第一位,无需处理
}
// 更新其他父级的排序
collectionSortMapper . increaseDesignSortBelow ( projectId , " Design " , parent . getSort ( ) ) ;
// 更新当前父级为第一位
parent . setSort ( 1 ) ;
parent . setUpdateTime ( LocalDateTime . now ( ) ) ;
collectionSortMapper . updateById ( parent ) ;
return collectionSort . getSort ( ) ;
}
@Override
@@ -690,7 +678,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
@Override
public Long productImageLike ( ProductImageLikeDTO productImageLikeDTO ) {
public CollectionSort productImageLike ( ProductImageLikeDTO productImageLikeDTO ) {
List < Long > toProductImageResultId = productImageLikeDTO . getToProductImageResultId ( ) ;
QueryWrapper < ToProductImageResult > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . in ( ToProductImageResult : : getId , toProductImageResultId ) ;
@@ -698,19 +686,17 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult . setIsLike ( 1 ) ;
toProductImageResultMapper . update ( toProductImageResult , qw ) ;
ToProductImageResult toProductImageResult1 = toProductImageResultMapper . selectById ( toProductImageResultId . get ( 0 ) ) ;
Long collectionSortId = null ;
CollectionSort collectionSort = null ;
if ( toProductImageResult1 . getResultType ( ) . equals ( " Relight " ) ) {
if ( null ! = productImageLikeDTO . getCollectionSortParentId ( ) ) {
CollectionSort collectionSort = designService . addCollectionSort ( toProductImageResult1 . getId ( ) , CollectionType . RELIGHT . getValue ( ) , productImageLikeDTO . getProjectId ( ) , productImageLikeDTO . getCollectionSortParentId ( ) ) ;
collectionSortId = collectionSort . getId ( ) ;
collectionSort = designService . addCollectionSort ( toProductImageResult1 . getId ( ) , CollectionType . RELIGHT . getValue ( ) , productImageLikeDTO . getProjectId ( ) , productImageLikeDTO . getCollectionSortParentId ( ) ) ;
}
} else {
if ( null ! = productImageLikeDTO . getCollectionSortParentId ( ) ) {
CollectionSort collectionSort = designService . addCollectionSort ( toProductImageResult1 . getId ( ) , CollectionType . TO_PRODUCT_IMAGE . getValue ( ) , productImageLikeDTO . getProjectId ( ) , productImageLikeDTO . getCollectionSortParentId ( ) ) ;
collectionSortId = collectionSort . getId ( ) ;
collectionSort = designService . addCollectionSort ( toProductImageResult1 . getId ( ) , CollectionType . TO_PRODUCT_IMAGE . getValue ( ) , productImageLikeDTO . getProjectId ( ) , productImageLikeDTO . getCollectionSortParentId ( ) ) ;
}
}
return collectionSortId ;
return collectionSort ;
}
@Resource
private RedisUtil redisUtil ;
@@ -1046,7 +1032,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
@Override
@Transactional ( rollbackFor = Exception . class )
public List < ToProductImageResult > relight ( ToProductImageDTO toProductImageDTO ) {
public List < ToProductImageResultVO > relight ( ToProductImageDTO toProductImageDTO ) {
// 判断用户当前积分是否够本次生成消耗
boolean fluxTask = ! StringUtil . isNullOrEmpty ( toProductImageDTO . getModelName ( ) )
& & toProductImageDTO . getModelName ( ) . equals ( " flux " ) ;
@@ -1089,7 +1075,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
toProductImageRecordMapper . insert ( toProductImageRecord ) ;
List < ToProductImageResult > result = new ArrayList < > ( ) ;
List < ToProductImageResultVO > result = new ArrayList < > ( ) ;
int i = 0 ;
@@ -1108,7 +1094,7 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
}
ToProductImageResult toProductImageResult = new ToProductImageResult ( ) ;
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO ( ) ;
if ( fluxTask ) {
taskId = generateService . flux ( creditsEventsEnum , s , toProductImageResult1 . getUrl ( ) , false ) ;
toProductImageResult . setModelName ( " flux " ) ;
@@ -1135,14 +1121,18 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult . setResultType ( CollectionType . RELIGHT . getValue ( ) ) ;
toProductImageResultMapper . insert ( toProductImageResult ) ;
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result . add ( toProductImageResult ) ;
// 满足条件情况下默认添加到like
addToProductLike ( toProductImageVO . getParentId ( ) , toProductImageResult . getId ( ) , toProductImageDTO . getProjectId ( ) ) ;
Integer sort = addToProductLike( toProductImageVO . getParentId ( ) , toProductImageResult . getId ( ) , toProductImageDTO . getProjectId ( ) ) ;
// 重新排序
reArrangeSort ( projectId , toProductImageResult . getId ( ) , CollectionType . RELIGHT . getValue ( ) , toProductImageVO . getParentId ( ) ) ;
Integer reSort = rearrangeChildSort ( toProductImageResult . getId ( ) , CollectionType . RELIGHT . getValue ( ) ,
toProductImageVO . getParentId ( ) , toProductImageVO . getUserLikeSortId ( ) ) ;
// 将生成结果的排序返回
toProductImageResult . setSort ( Objects . isNull ( reSort ) ? sort : reSort ) ;
result . add ( toProductImageResult ) ;
} else {
ToProductElement toProductElement = toProductElementMapper . selectById ( toProductImageVO . getElementId ( ) ) ;
ToProductImageResult toProductImageResult = new ToProductImageResult ( ) ;
ToProductImageResultVO toProductImageResult = new ToProductImageResultVO ( ) ;
if ( fluxTask ) {
taskId = generateService . flux ( CreditsEventsEnum . RELIGHT_FLUX , s , toProductElement . getUrl ( ) , false ) ;
toProductImageResult . setModelName ( " flux " ) ;
@@ -1169,11 +1159,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
toProductImageResult . setResultType ( CollectionType . RELIGHT . getValue ( ) ) ;
toProductImageResultMapper . insert ( toProductImageResult ) ;
// toProductImageResult.setUrl(minioUtil.getPresignedUrl(toProductImageResult.getUrl(), 24 * 60));
result . add ( toProductImageResult ) ;
// 满足条件情况下默认添加到like
addToProductLike ( toProductImageVO . getParentId ( ) , toProductImageResult . getId ( ) , toProductImageDTO . getProjectId ( ) ) ;
Integer sort = addToProductLike( toProductImageVO . getParentId ( ) , toProductImageResult . getId ( ) , toProductImageDTO . getProjectId ( ) ) ;
// 重新排序
reArrangeSort ( projectId , toProductImageResult . getId ( ) , CollectionType . RELIGHT . getValue ( ) , toProductImageVO . getParentId ( ) ) ;
Integer reSort = rearrangeChildSort ( toProductImageResult . getId ( ) , CollectionType . RELIGHT . getValue ( ) ,
toProductImageVO . getParentId ( ) , toProductImageVO . getUserLikeSortId ( ) ) ;
// 将生成结果的排序返回
toProductImageResult . setSort ( Objects . isNull ( reSort ) ? sort : reSort ) ;
result . add ( toProductImageResult ) ;
}
// 添加需要扣除的积分到预扣除区
creditsService . addRecordToCreditsDeduction ( userHolder . getId ( ) , taskId , creditsEventsEnum ) ;