@@ -4,17 +4,20 @@ import cn.hutool.core.collection.CollectionUtil;
import com.ai.da.common.config.exception.BusinessException ;
import com.ai.da.common.constant.CommonConstant ;
import com.ai.da.common.context.UserContext ;
import com.ai.da.common.enums.CollectionLevel1TypeEnum ;
import com.ai.da.common.enums.CreditsEventsEnum ;
import com.ai.da.common.enums.DesignTypeEnum ;
import com.ai.da.common.response.PageBaseResponse ;
import com.ai.da.common.response.Response ;
import com.ai.da.common.response.ResultEnum ;
import com.ai.da.common.utils.* ;
import com.ai.da.mapper.primary.* ;
import com.ai.da.mapper.primary.entity.* ;
import com.ai.da.mapper.primary.entity.Collection ;
import com.ai.da.mapper.secondary.AttributeRetrievalMapper ;
import com.ai.da.mapper.secondary.entity.AttributeRecognitionJSON ;
import com.ai.da.model.dto.PortfolioDTO ;
import com.ai.da.model.dto.ProductImageInitializeDTO ;
import com.ai.da.model.dto.ProductImageLikeDTO ;
import com.ai.da.model.dto.ToProductImageDTO ;
import com.ai.da.model.dto.* ;
import com.ai.da.model.enums.Module ;
import com.ai.da.model.vo.* ;
import com.ai.da.python.PythonService ;
import com.ai.da.service.* ;
@@ -24,19 +27,24 @@ import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature ;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper ;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper ;
import com.baomidou.mybatisplus.core.metadata.IPage ;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page ;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl ;
import com.google.common.base.Function ;
import com.google.gson.Gson ;
import io.netty.util.internal.StringUtil ;
import lombok.extern.slf4j.Slf4j ;
import org.springframework.beans.factory.annotation.Value ;
import org.springframework.stereotype.Service ;
import org.springframework.transaction.annotation.Transactional ;
import org.springframework.util.CollectionUtils ;
import org.springframework.util.StringUtils ;
import org.springframework.web.multipart.MultipartFile ;
import javax.annotation.Resource ;
import java.io.* ;
import java.time.LocalDateTime ;
import java.time.ZoneId ;
import java.util.* ;
import java.util.stream.Collectors ;
@@ -58,6 +66,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
@Resource
private UserLikeService userLikeService ;
@Resource
private WorkspaceService workspaceService ;
@Resource
private UserLikeMapper userLikeMapper ;
@@ -69,10 +80,14 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
@Resource
private DesignMapper designMapper ;
@Resource
private DesignService designService ;
@Resource
private SysFileMapper sysFileMapper ;
@Resource
private LibraryMapper libraryMapper ;
@Resource
private GenerateDetailMapper generateDetailMapper ;
@Resource
private PortfolioMapper portfolioMapper ;
@Resource
private TagsMapper tagsMapper ;
@@ -86,6 +101,12 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
private ProductImageAttributeMapper productImageAttributeMapper ;
@Resource
private UserLikeSortMapper userLikeSortMapper ;
@Resource
private ClassificationService classificationService ;
@Resource
private ProjectMapper projectMapper ;
@Resource
private PortfolioService portfolioService ;
@Override
public void deleteUserGroup ( Long userGroupId ) {
@@ -208,6 +229,94 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
return new UserLikeChooseVO ( userGroupId , userLikeVOS , userLikeCollection , sex , beenPublished , portfolioDTO ) ;
}
@Override
public ProjectChooseVO choose ( ProjectDTO projectDTO ) {
Project project = projectMapper . selectById ( projectDTO . getId ( ) ) ;
// List<String> moduleList = projectDTO.getModuleList();
// for (String module : moduleList) {
//
// }
Long workspaceId = workspaceService . getByProjectId ( project . getId ( ) ) ;
WorkspaceVO workspaceVO = workspaceService . getByIdNew ( workspaceId ) ;
String process = project . getProcess ( ) ;
// UserLikeGroup group = getByProjectId(projectDTO.getId());
// if (Objects.isNull(group)) {
// throw new BusinessException("history.not.found");
// }
// List<UserLikeVO> userLikeVOS = userLikeService.getGroupDetail(group.getId());
// String sex = null;
//
// QueryWrapper<UserLikeSort> userLikeSortQw = new QueryWrapper<>();
// userLikeSortQw.lambda().eq(UserLikeSort::getUserLikeGroupId, group.getId());
// List<UserLikeSort> userLikeSortList = userLikeSortMapper.selectList(userLikeSortQw);
// if (CollectionUtil.isEmpty(userLikeSortList)) {
// Integer sort = 1;
// for (UserLikeVO userLikeVO : userLikeVOS) {
// UserLikeSort userLikeSort = new UserLikeSort();
// userLikeSort.setUserLikeId(userLikeVO.getId());
// userLikeSort.setUserLikeGroupId(group.getId());
// userLikeSort.setSort(sort);
// userLikeSortMapper.insert(userLikeSort);
// sort ++;
// }
// }
//
// userLikeVOS.forEach(o -> {
// TDesignPythonOutfit tDesignPythonOutfit1 = designPythonOutfitMapper.selectById(o.getDesignOutfitId());
// o.setUrl(tDesignPythonOutfit1.getDesignUrl());
// if (o.getUrl().contains("/")) {
// int index = o.getUrl().lastIndexOf("/");
// o.setPictureName(o.getUrl().substring(index + 1));
// }
// o.setDesignOutfitUrl(minioUtil.getPreSignedUrl(o.getUrl(), 24 * 60));
// QueryWrapper<TDesignPythonOutfit> qw = new QueryWrapper<>();
// qw.lambda().eq(TDesignPythonOutfit::getDesignItemId, o.getDesignItemId());
// List<TDesignPythonOutfit> tDesignPythonOutfits = designPythonOutfitMapper.selectList(qw);
// if (CollectionUtil.isNotEmpty(tDesignPythonOutfits)) {
// TDesignPythonOutfit tDesignPythonOutfit = tDesignPythonOutfits.get(0);
// o.setDesignOutfitId(tDesignPythonOutfit.getId());
// }
//
// QueryWrapper<UserLikeSort> userLikeSortQueryWrapper = new QueryWrapper<>();
// userLikeSortQueryWrapper.lambda().eq(UserLikeSort::getUserLikeId, o.getId());
// List<UserLikeSort> userLikeSorts = userLikeSortMapper.selectList(userLikeSortQueryWrapper);
// if (CollectionUtil.isNotEmpty(userLikeSorts)) {
// UserLikeSort userLikeSort = userLikeSorts.get(0);
// o.setSort(userLikeSort.getSort());
// o.setUserLikeSortId(userLikeSort.getId());
// }
// });
// UserLikeCollectionVO userLikeCollection = collectionService.chooseCollection(group.getCollectionId());
// Integer beenPublished = 0;
// QueryWrapper<Portfolio> qw = new QueryWrapper<>();
// qw.lambda().eq(Portfolio::getUserLikeGroupSourceId, group.getId());
// List<Portfolio> portfolios = portfolioMapper.selectList(qw);
//// Portfolio portfolio = new Portfolio();
// PortfolioDTO portfolioDTO = new PortfolioDTO();
// if (CollectionUtil.isNotEmpty(portfolios)) {
//// portfolio = portfolios.get(0);
// portfolioDTO = CopyUtil.copyObject(portfolios.get(0), PortfolioDTO.class);
// beenPublished = 1;
// portfolioDTO.setTagsDTO(tagsMapper.getTagByPortfolioId(portfolioDTO.getId()));
// }
return new ProjectChooseVO ( projectDTO . getId ( ) , workspaceVO , process ) ;
}
private UserLikeGroup getByProjectId ( Long projectId ) {
QueryWrapper < UserLikeGroup > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( UserLikeGroup : : getProjectId , projectId ) ;
List < UserLikeGroup > userLikeGroupList = userLikeGroupMapper . selectList ( qw ) ;
if ( CollectionUtil . isEmpty ( userLikeGroupList ) ) {
throw new BusinessException ( " Lack of associated userLikeGroup. " ) ;
}
return userLikeGroupList . get ( 0 ) ;
}
@Override
public void deleteTrialData ( Long userId ) {
QueryWrapper < UserLikeGroup > qw = new QueryWrapper < > ( ) ;
@@ -1022,4 +1131,560 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
}
return attributeRetrieval ;
}
@Override
public IPage < ProjectVO > getPage ( ProjectQueryDTO query ) {
AuthPrincipalVo authPrincipalVo = UserContext . getUserHolder ( ) ;
// 分页数据
QueryWrapper < Project > queryWrapper = new QueryWrapper < > ( ) ;
queryWrapper . eq ( " account_id " , authPrincipalVo . getId ( ) ) ;
if ( ! StringUtils . isEmpty ( query . getProjectName ( ) ) ) {
queryWrapper . like ( " name " , query . getProjectName ( ) ) ;
}
if ( Objects . nonNull ( query . getStartDate ( ) ) ) {
queryWrapper . ge ( " update_time " , new Date ( query . getStartDate ( ) ) ) ;
}
if ( Objects . nonNull ( query . getEndDate ( ) ) ) {
queryWrapper . le ( " update_time " , new Date ( query . getEndDate ( ) ) ) ;
}
// 新增分类过滤
if ( CollectionUtil . isNotEmpty ( query . getClassificationIdList ( ) ) ) {
List < Long > projectIdList = new ArrayList < > ( ) ;
if ( query . getIntersection ( ) = = 0 ) {
for ( Long classificationId : query . getClassificationIdList ( ) ) {
projectIdList . addAll ( classificationService . getLibraryIdListByClassificationId ( classificationId ) ) ;
}
if ( CollectionUtil . isNotEmpty ( projectIdList ) ) {
queryWrapper . in ( " id " , projectIdList ) ;
} else {
return new Page < > ( ) ;
}
} else {
for ( int i = 0 ; i < query . getClassificationIdList ( ) . size ( ) ; i + + ) {
List < Long > historyIdListByClassificationId = classificationService . getLibraryIdListByClassificationId ( query . getClassificationIdList ( ) . get ( i ) ) ;
if ( i = = 0 ) {
projectIdList . addAll ( historyIdListByClassificationId ) ;
} else {
projectIdList . retainAll ( historyIdListByClassificationId ) ;
}
if ( CollectionUtil . isEmpty ( projectIdList ) ) {
return new Page < > ( ) ;
}
}
queryWrapper . in ( " id " , projectIdList ) ;
}
}
queryWrapper . orderByDesc ( " update_date " ) ;
IPage < Project > page = projectMapper . selectPage (
new Page < > ( query . getPage ( ) , query . getSize ( ) ) , queryWrapper ) ;
if ( CollectionUtils . isEmpty ( page . getRecords ( ) ) ) {
return new Page < > ( ) ;
}
Set < Long > projectIdSet = page . getRecords ( ) . stream ( ) . map ( Project : : getId ) . collect ( Collectors . toSet ( ) ) ;
QueryWrapper < UserLikeGroup > userLikeGroupQueryWrapper = new QueryWrapper < > ( ) ;
userLikeGroupQueryWrapper . lambda ( ) . in ( UserLikeGroup : : getProjectId , projectIdSet ) ;
List < UserLikeGroup > userLikeGroups = userLikeGroupMapper . selectList ( userLikeGroupQueryWrapper ) ;
List < Long > groupIds = userLikeGroups . stream ( ) . map ( UserLikeGroup : : getId ) . collect ( Collectors . toList ( ) ) ;
List < UserLikeVO > groupDetails = userLikeService . getGroupDetails ( groupIds ) ;
// if (CollectionUtils.isEmpty(groupDetails)) {
// throw new BusinessException("groupDetails.not.found");
// }
Map < Long , List < UserLikeVO > > groupDetailMap = groupDetails . stream ( )
. collect ( Collectors . groupingBy ( UserLikeVO : : getUserLikeGroupId ) ) ;
Account account = accountService . getById ( authPrincipalVo . getId ( ) ) ;
IPage < ProjectVO > convert = page . convert ( ( Function < Project , ProjectVO > ) project - > {
if ( project ! = null ) {
ProjectVO projectVO = CopyUtil . copyObject ( project , ProjectVO . class ) ;
projectVO . setUpdateDate ( project . getUpdateTime ( ) . atZone ( ZoneId . systemDefault ( ) ) . toInstant ( ) . toEpochMilli ( ) ) ;
QueryWrapper < UserLikeGroup > userLikeGroupQueryWrapper1 = new QueryWrapper < > ( ) ;
userLikeGroupQueryWrapper1 . lambda ( ) . eq ( UserLikeGroup : : getProjectId , projectVO . getId ( ) ) ;
UserLikeGroup userLikeGroup = userLikeGroupMapper . selectOne ( userLikeGroupQueryWrapper1 ) ;
UserLikeGroupVO userLikeGroupVO = CopyUtil . copyObject ( userLikeGroup , UserLikeGroupVO . class ) ;
userLikeGroupVO . setAuthor ( account . getUserName ( ) ) ;
//count 和detail
if ( groupDetailMap . keySet ( ) . contains ( userLikeGroupVO . getId ( ) ) ) {
List < UserLikeVO > details = groupDetailMap . get ( userLikeGroupVO . getId ( ) ) ;
for ( UserLikeVO detail : details ) {
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper . selectById ( detail . getDesignOutfitId ( ) ) ;
detail . setUrl ( minioUtil . getPreSignedUrl ( tDesignPythonOutfit . getDesignUrl ( ) , 24 * 60 ) ) ;
}
userLikeGroupVO . setGroupDetails ( details ) ;
userLikeGroupVO . setSketchCount ( CollectionUtils . isEmpty ( details ) ? 0 : details . size ( ) ) ;
} else {
userLikeGroupVO . setSketchCount ( 0 ) ;
}
if ( userLikeGroupVO . getOriginal ( ) = = 0 ) {
userLikeGroupVO . setOriginalAccountName ( accountService . getById ( userLikeGroupVO . getOriginalAccountId ( ) ) . getUserName ( ) ) ;
Portfolio byId = portfolioService . getByIdAll ( userLikeGroupVO . getOriginalPortfolioId ( ) ) ;
if ( Objects . nonNull ( byId ) ) {
String portfolioName = byId . getPortfolioName ( ) ;
userLikeGroupVO . setOriginalPortfolioName ( portfolioName ) ;
}
}
projectVO . setUserLikeGroupVO ( userLikeGroupVO ) ;
return projectVO ;
}
return null ;
} ) ;
return convert ;
}
@Override
public ModuleChooseVO getModuleContent ( ProjectDTO projectDTO ) {
ModuleChooseVO moduleChooseVO = new ModuleChooseVO ( ) ;
moduleChooseVO . setProjectId ( projectDTO . getId ( ) ) ;
// UserLikeCollectionVO userLikeCollectionVO = new UserLikeCollectionVO();
for ( String module : projectDTO . getModuleList ( ) ) {
if ( module . equals ( Module . colorBoard . name ( ) ) ) {
QueryWrapper < CollectionElement > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( CollectionElement : : getProjectId , projectDTO . getId ( ) ) ;
qw . lambda ( ) . eq ( CollectionElement : : getLevel1Type , CollectionLevel1TypeEnum . COLOR_BOARD . getRealName ( ) ) ;
List < CollectionElement > collectionElements = collectionElementMapper . selectList ( qw ) ;
moduleChooseVO . setColorBoard ( collectionService . resolveColorBoard ( collectionElements ) ) ;
} else if ( module . equals ( Module . moodBoard . name ( ) ) ) {
MoodBoardModuleChooseVO moodBoardModuleChooseVO = new MoodBoardModuleChooseVO ( ) ;
QueryWrapper < CollectionElement > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( CollectionElement : : getProjectId , projectDTO . getId ( ) ) ;
qw . lambda ( ) . ne ( CollectionElement : : getCollectionId , 0 ) ;
qw . lambda ( ) . eq ( CollectionElement : : getLevel1Type , CollectionLevel1TypeEnum . MOOD_BOARD . getRealName ( ) ) ;
List < CollectionElement > collectionElements = collectionElementMapper . selectList ( qw ) ;
Long collectionId = null ;
for ( CollectionElement collectionElement : collectionElements ) {
if ( collectionElement . getCollectionId ( ) ! = null ) {
collectionId = collectionElement . getCollectionId ( ) ;
break ;
}
}
Collection collection = collectionService . getById ( collectionId ) ;
if ( null ! = collection . getMoodboardPosition ( ) ) {
String moodboardPositionString = collectionService . getMoodboardPositionString ( collection . getId ( ) ) ;
if ( StringUtils . isEmpty ( moodboardPositionString ) ) {
moodBoardModuleChooseVO . setMoodboardPosition ( collection . getMoodboardPosition ( ) ) ;
} else {
moodBoardModuleChooseVO . setMoodboardPosition ( moodboardPositionString ) ;
}
}
if ( collection . getMoodTemplateId ( ) ! = null ) {
CollectionElement layoutElement = collectionElementMapper . selectById ( collection . getMoodTemplateId ( ) ) ;
moodBoardModuleChooseVO . setMoodTemplateId ( collection . getMoodTemplateId ( ) ) ;
moodBoardModuleChooseVO . setMoodTemplateName ( layoutElement . getName ( ) ) ;
moodBoardModuleChooseVO . setMoodTemplateUrl ( minioUtil . getPreSignedUrl ( layoutElement . getUrl ( ) , 24 * 60 ) ) ;
}
List < CollectionElementVO > list = new ArrayList < > ( ) ;
for ( CollectionElement collectionElement : collectionElements ) {
CollectionElementVO collectionElementVO = CopyUtil . copyObject ( collectionElement , CollectionElementVO . class ) ;
collectionElementVO . setDesignType ( DesignTypeEnum . COLLECTION . getRealName ( ) ) ;
String url = collectionElement . getUrl ( ) ;
collectionElementVO . setOriginalUrl ( url ) ;
if ( minioUtil . doesObjectExist ( url ) ) {
collectionElementVO . setUrl ( minioUtil . getPreSignedUrl ( url , 24 * 60 ) ) ;
}
if ( minioUtil . doesObjectExist ( collectionElementVO . getOriginalUrl ( ) ) ) {
list . add ( collectionElementVO ) ;
}
}
moodBoardModuleChooseVO . setMoodBoards ( list ) ;
moduleChooseVO . setMoodBoard ( moodBoardModuleChooseVO ) ;
} else if ( module . equals ( Module . printBoard . name ( ) ) ) {
QueryWrapper < CollectionElement > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( CollectionElement : : getProjectId , projectDTO . getId ( ) ) ;
qw . lambda ( ) . eq ( CollectionElement : : getLevel1Type , CollectionLevel1TypeEnum . PRINT_BOARD . getRealName ( ) ) ;
List < CollectionElement > collectionElements = collectionElementMapper . selectList ( qw ) ;
List < CollectionElementVO > list = new ArrayList < > ( ) ;
for ( CollectionElement collectionElement : collectionElements ) {
CollectionElementVO collectionElementVO = CopyUtil . copyObject ( collectionElement , CollectionElementVO . class ) ;
collectionElementVO . setIsPin ( collectionElement . getHasPin ( ) ) ;
collectionElementVO . setDesignType ( DesignTypeEnum . COLLECTION . getRealName ( ) ) ;
String url = collectionElement . getUrl ( ) ;
collectionElementVO . setOriginalUrl ( url ) ;
if ( minioUtil . doesObjectExist ( url ) ) {
collectionElementVO . setUrl ( minioUtil . getPreSignedUrl ( url , 24 * 60 ) ) ;
}
if ( minioUtil . doesObjectExist ( collectionElementVO . getOriginalUrl ( ) ) ) {
list . add ( collectionElementVO ) ;
}
}
moduleChooseVO . setPrintBoard ( list ) ;
} else if ( module . equals ( Module . sketchBoard . name ( ) ) ) {
QueryWrapper < CollectionElement > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( CollectionElement : : getProjectId , projectDTO . getId ( ) ) ;
qw . lambda ( ) . eq ( CollectionElement : : getLevel1Type , CollectionLevel1TypeEnum . SKETCH_BOARD . getRealName ( ) ) ;
List < CollectionElement > collectionElements = collectionElementMapper . selectList ( qw ) ;
List < CollectionElementVO > list = new ArrayList < > ( ) ;
for ( CollectionElement collectionElement : collectionElements ) {
CollectionElementVO collectionElementVO = CopyUtil . copyObject ( collectionElement , CollectionElementVO . class ) ;
collectionElementVO . setIsPin ( collectionElement . getHasPin ( ) ) ;
collectionElementVO . setDesignType ( DesignTypeEnum . COLLECTION . getRealName ( ) ) ;
String url = collectionElement . getUrl ( ) ;
collectionElementVO . setOriginalUrl ( url ) ;
if ( minioUtil . doesObjectExist ( url ) ) {
collectionElementVO . setUrl ( minioUtil . getPreSignedUrl ( url , 24 * 60 ) ) ;
if ( url . contains ( " . " ) ) {
String [ ] split = url . split ( " \\ . " ) ;
collectionElementVO . setUrlWithWhiteSide ( minioUtil . getPreSignedUrl ( split [ 0 ] + " -show. " + split [ 1 ] , 24 * 60 ) ) ;
} else {
collectionElementVO . setUrlWithWhiteSide ( minioUtil . getPreSignedUrl ( url + " -show " , 24 * 60 ) ) ;
}
}
if ( minioUtil . doesObjectExist ( collectionElementVO . getOriginalUrl ( ) ) ) {
list . add ( collectionElementVO ) ;
}
}
moduleChooseVO . setSketchBoard ( list ) ;
} else if ( module . equals ( Module . design . name ( ) ) ) {
DesignModuleChooseVO vo = new DesignModuleChooseVO ( ) ;
UserLikeGroup group = getByProjectId ( projectDTO . getId ( ) ) ;
Long userGroupId = group . getId ( ) ;
// if (Objects.isNull(group)) {
// throw new BusinessException("history.not.found");
// }
List < UserLikeVO > userLikeVOS = userLikeService . getGroupDetail ( userGroupId ) ;
String sex = null ;
QueryWrapper < UserLikeSort > userLikeSortQw = new QueryWrapper < > ( ) ;
userLikeSortQw . lambda ( ) . eq ( UserLikeSort : : getUserLikeGroupId , userGroupId ) ;
List < UserLikeSort > userLikeSortList = userLikeSortMapper . selectList ( userLikeSortQw ) ;
if ( CollectionUtil . isEmpty ( userLikeSortList ) ) {
Integer sort = 1 ;
for ( UserLikeVO userLikeVO : userLikeVOS ) {
UserLikeSort userLikeSort = new UserLikeSort ( ) ;
userLikeSort . setUserLikeId ( userLikeVO . getId ( ) ) ;
userLikeSort . setUserLikeGroupId ( userGroupId ) ;
userLikeSort . setSort ( sort ) ;
userLikeSortMapper . insert ( userLikeSort ) ;
sort + + ;
}
}
userLikeVOS . forEach ( o - > {
TDesignPythonOutfit tDesignPythonOutfit1 = designPythonOutfitMapper . selectById ( o . getDesignOutfitId ( ) ) ;
o . setUrl ( tDesignPythonOutfit1 . getDesignUrl ( ) ) ;
if ( o . getUrl ( ) . contains ( " / " ) ) {
int index = o . getUrl ( ) . lastIndexOf ( " / " ) ;
o . setPictureName ( o . getUrl ( ) . substring ( index + 1 ) ) ;
}
o . setDesignOutfitUrl ( minioUtil . getPreSignedUrl ( o . getUrl ( ) , 24 * 60 ) ) ;
QueryWrapper < TDesignPythonOutfit > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( TDesignPythonOutfit : : getDesignItemId , o . getDesignItemId ( ) ) ;
List < TDesignPythonOutfit > tDesignPythonOutfits = designPythonOutfitMapper . selectList ( qw ) ;
if ( CollectionUtil . isNotEmpty ( tDesignPythonOutfits ) ) {
TDesignPythonOutfit tDesignPythonOutfit = tDesignPythonOutfits . get ( 0 ) ;
o . setDesignOutfitId ( tDesignPythonOutfit . getId ( ) ) ;
}
QueryWrapper < UserLikeSort > userLikeSortQueryWrapper = new QueryWrapper < > ( ) ;
userLikeSortQueryWrapper . lambda ( ) . eq ( UserLikeSort : : getUserLikeId , o . getId ( ) ) ;
List < UserLikeSort > userLikeSorts = userLikeSortMapper . selectList ( userLikeSortQueryWrapper ) ;
if ( CollectionUtil . isNotEmpty ( userLikeSorts ) ) {
UserLikeSort userLikeSort = userLikeSorts . get ( 0 ) ;
o . setSort ( userLikeSort . getSort ( ) ) ;
o . setUserLikeSortId ( userLikeSort . getId ( ) ) ;
}
} ) ;
vo . setUserGroupId ( userGroupId ) ;
vo . setUserLikeDetails ( userLikeVOS ) ;
} else if ( module . equals ( Module . canvas . name ( ) ) ) {
CavasModuleChooseVO vo = new CavasModuleChooseVO ( ) ;
UserLikeGroup userLikeGroup = getByProjectId ( projectDTO . getId ( ) ) ;
Integer beenPublished = 0 ;
QueryWrapper < Portfolio > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( Portfolio : : getUserLikeGroupSourceId , userLikeGroup . getId ( ) ) ;
List < Portfolio > portfolios = portfolioMapper . selectList ( qw ) ;
PortfolioDTO portfolioDTO = new PortfolioDTO ( ) ;
if ( CollectionUtil . isNotEmpty ( portfolios ) ) {
portfolioDTO = CopyUtil . copyObject ( portfolios . get ( 0 ) , PortfolioDTO . class ) ;
beenPublished = 1 ;
portfolioDTO . setTagsDTO ( tagsMapper . getTagByPortfolioId ( portfolioDTO . getId ( ) ) ) ;
}
vo . setBeenPublished ( beenPublished ) ;
vo . setPortfolioDTO ( portfolioDTO ) ;
moduleChooseVO . setCanvas ( vo ) ;
} else if ( module . equals ( Module . toProduct . name ( ) ) ) {
UserLikeGroup userLikeGroup = getByProjectId ( projectDTO . getId ( ) ) ;
Long userLikeGroupId = userLikeGroup . getId ( ) ;
QueryWrapper < ToProductImageResult > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( ToProductImageResult : : getIsLike , 1 ) ;
qw . lambda ( ) . eq ( ToProductImageResult : : getUserLikeGroupId , userLikeGroupId ) ;
qw . lambda ( ) . eq ( ToProductImageResult : : getResultType , " ToProductImage " ) ;
List < ToProductImageResult > toProductImageResults = toProductImageResultMapper . selectList ( qw ) ;
for ( ToProductImageResult toProductImageResult : toProductImageResults ) {
toProductImageResult . setUrl ( minioUtil . getPreSignedUrl ( toProductImageResult . getUrl ( ) , 24 * 60 ) ) ;
}
List < ToProductImageResultVO > toProductImageResultVOS = CopyUtil . copyList ( toProductImageResults , ToProductImageResultVO . class ) ;
for ( ToProductImageResultVO toProductImageResultVO : toProductImageResultVOS ) {
if ( toProductImageResultVO . getElementType ( ) . equals ( " ProductElement " ) ) {
ToProductElement toProductElement = toProductElementMapper . selectById ( toProductImageResultVO . getElementId ( ) ) ;
toProductImageResultVO . setSourceUrl ( minioUtil . getPreSignedUrl ( toProductElement . getUrl ( ) , 24 * 60 ) ) ;
} else if ( ( toProductImageResultVO . getElementType ( ) . equals ( " DesignOutfit " ) ) ) {
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper . selectById ( toProductImageResultVO . getElementId ( ) ) ;
toProductImageResultVO . setSourceUrl ( minioUtil . getPreSignedUrl ( tDesignPythonOutfit . getDesignUrl ( ) , 24 * 60 ) ) ;
} else {
ToProductImageResult toProductImageResult1 = toProductImageResultMapper . selectById ( toProductImageResultVO . getElementId ( ) ) ;
toProductImageResultVO . setSourceUrl ( minioUtil . getPreSignedUrl ( toProductImageResult1 . getUrl ( ) , 24 * 60 ) ) ;
}
}
moduleChooseVO . setToProduct ( toProductImageResultVOS ) ;
} else if ( module . equals ( Module . relight . name ( ) ) ) {
UserLikeGroup userLikeGroup = getByProjectId ( projectDTO . getId ( ) ) ;
Long userLikeGroupId = userLikeGroup . getId ( ) ;
QueryWrapper < ToProductImageResult > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( ToProductImageResult : : getIsLike , 1 ) ;
qw . lambda ( ) . eq ( ToProductImageResult : : getUserLikeGroupId , userLikeGroupId ) ;
qw . lambda ( ) . eq ( ToProductImageResult : : getResultType , " Relight " ) ;
List < ToProductImageResult > toProductImageResults = toProductImageResultMapper . selectList ( qw ) ;
for ( ToProductImageResult toProductImageResult : toProductImageResults ) {
toProductImageResult . setUrl ( minioUtil . getPreSignedUrl ( toProductImageResult . getUrl ( ) , 24 * 60 ) ) ;
}
List < ToProductImageResultVO > toProductImageResultVOS = CopyUtil . copyList ( toProductImageResults , ToProductImageResultVO . class ) ;
for ( ToProductImageResultVO toProductImageResultVO : toProductImageResultVOS ) {
if ( toProductImageResultVO . getElementType ( ) . equals ( " ProductElement " ) ) {
ToProductElement toProductElement = toProductElementMapper . selectById ( toProductImageResultVO . getElementId ( ) ) ;
toProductImageResultVO . setSourceUrl ( minioUtil . getPreSignedUrl ( toProductElement . getUrl ( ) , 24 * 60 ) ) ;
} else if ( ( toProductImageResultVO . getElementType ( ) . equals ( " DesignOutfit " ) ) ) {
TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper . selectById ( toProductImageResultVO . getElementId ( ) ) ;
toProductImageResultVO . setSourceUrl ( minioUtil . getPreSignedUrl ( tDesignPythonOutfit . getDesignUrl ( ) , 24 * 60 ) ) ;
} else {
ToProductImageResult toProductImageResult1 = toProductImageResultMapper . selectById ( toProductImageResultVO . getElementId ( ) ) ;
toProductImageResultVO . setSourceUrl ( minioUtil . getPreSignedUrl ( toProductImageResult1 . getUrl ( ) , 24 * 60 ) ) ;
}
}
moduleChooseVO . setToProduct ( toProductImageResultVOS ) ;
}
}
return moduleChooseVO ;
}
@Override
public ModuleChooseVO saveModuleContent ( ModuleSaveDTO moduleSaveDTO ) {
Long accountId = UserContext . getUserHolder ( ) . getId ( ) ;
Long projectId = moduleSaveDTO . getProjectId ( ) ;
if ( Objects . nonNull ( moduleSaveDTO . getMoodBoard ( ) ) ) {
MoodBoardModuleSaveDTO moodBoard = moduleSaveDTO . getMoodBoard ( ) ;
if ( moodBoard . getMoodTemplateId ( ) ! = null ) {
// moodboard合成图存储
QueryWrapper < CollectionElement > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( CollectionElement : : getProjectId , moduleSaveDTO . getProjectId ( ) ) ;
qw . lambda ( ) . eq ( CollectionElement : : getLevel1Type , CollectionLevel1TypeEnum . MOOD_BOARD . getRealName ( ) ) ;
qw . lambda ( ) . eq ( CollectionElement : : getCollectionId , 0 ) ;
List < CollectionElement > compositeImageList = collectionElementMapper . selectList ( qw ) ;
if ( CollectionUtils . isEmpty ( compositeImageList ) ) {
CollectionElement collectionElement = collectionElementMapper . selectById ( moodBoard . getMoodTemplateId ( ) ) ;
collectionElement . setProjectId ( moduleSaveDTO . getProjectId ( ) ) ;
collectionElementMapper . updateById ( collectionElement ) ;
if ( ! StringUtils . isEmpty ( moodBoard . getMoodboardPosition ( ) ) ) {
// 合成图位置信息通过collectElementId关联( 旧逻辑通过collectionId关联)
designService . parseMoodboardPosition ( moodBoard . getMoodboardPosition ( ) , collectionElement . getId ( ) ) ;
}
} else {
CollectionElement compositeImage = compositeImageList . get ( 0 ) ;
if ( ! Objects . equals ( compositeImage . getId ( ) , moodBoard . getMoodTemplateId ( ) ) ) {
compositeImage . setProjectId ( null ) ;
CollectionElement collectionElement = collectionElementMapper . selectById ( moodBoard . getMoodTemplateId ( ) ) ;
collectionElement . setProjectId ( moduleSaveDTO . getProjectId ( ) ) ;
collectionElementMapper . updateById ( collectionElement ) ;
if ( ! StringUtils . isEmpty ( moodBoard . getMoodboardPosition ( ) ) ) {
// 合成图位置信息通过collectElementId关联( 旧逻辑通过collectionId关联)
designService . parseMoodboardPosition ( moodBoard . getMoodboardPosition ( ) , collectionElement . getId ( ) ) ;
}
}
}
}
List < DesignCollectionElementDTO > moodBoards = moodBoard . getMoodBoards ( ) ;
if ( CollectionUtil . isNotEmpty ( moodBoards ) ) {
QueryWrapper < CollectionElement > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( CollectionElement : : getProjectId , projectId ) ;
qw . lambda ( ) . eq ( CollectionElement : : getLevel1Type , CollectionLevel1TypeEnum . MOOD_BOARD . getRealName ( ) ) ;
qw . lambda ( ) . ne ( CollectionElement : : getCollectionId , 0 ) ;
List < CollectionElement > collectionElements = collectionElementMapper . selectList ( qw ) ;
Set < Long > old = collectionElements . stream ( ) . map ( CollectionElement : : getId ) . collect ( Collectors . toSet ( ) ) ;
for ( DesignCollectionElementDTO board : moodBoards ) {
if ( board . getDesignType ( ) . equals ( DesignTypeEnum . LIBRARY . getRealName ( ) ) ) {
Library library = libraryMapper . selectById ( board . getId ( ) ) ;
CollectionElement collectionElement = new CollectionElement ( ) ;
collectionElement . setAccountId ( accountId ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElement . setLevel1Type ( CollectionLevel1TypeEnum . MOOD_BOARD . getRealName ( ) ) ;
collectionElement . setName ( library . getName ( ) ) ;
collectionElement . setUrl ( library . getUrl ( ) ) ;
collectionElement . setHasPin ( ( byte ) 0 ) ;
collectionElement . setMd5 ( library . getMd5 ( ) ) ;
collectionElement . setCreateDate ( new Date ( ) ) ;
collectionElementMapper . insert ( collectionElement ) ;
} else if ( board . getDesignType ( ) . equals ( DesignTypeEnum . GENERATE . getRealName ( ) ) ) {
GenerateDetail generateDetail = generateDetailMapper . selectById ( board . getId ( ) ) ;
CollectionElement collectionElement = new CollectionElement ( ) ;
collectionElement . setAccountId ( accountId ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElement . setLevel1Type ( CollectionLevel1TypeEnum . MOOD_BOARD . getRealName ( ) ) ;
// collectionElement.setName(generateDetail.get());
collectionElement . setUrl ( generateDetail . getUrl ( ) ) ;
collectionElement . setHasPin ( ( byte ) 0 ) ;
collectionElement . setMd5 ( generateDetail . getMd5 ( ) ) ;
collectionElement . setCreateDate ( new Date ( ) ) ;
collectionElementMapper . insert ( collectionElement ) ;
} else {
if ( old . contains ( board . getId ( ) ) ) {
old . remove ( board . getId ( ) ) ;
} else {
CollectionElement collectionElement = collectionElementMapper . selectById ( board . getId ( ) ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElementMapper . updateById ( collectionElement ) ;
}
}
}
collectionElementMapper . deleteBatchIds ( old ) ;
}
}
if ( CollectionUtils . isEmpty ( moduleSaveDTO . getPrintBoard ( ) ) ) {
List < DesignCollectionPrintElementDTO > printBoards = moduleSaveDTO . getPrintBoard ( ) ;
QueryWrapper < CollectionElement > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( CollectionElement : : getProjectId , projectId ) ;
qw . lambda ( ) . eq ( CollectionElement : : getLevel1Type , CollectionLevel1TypeEnum . PRINT_BOARD . getRealName ( ) ) ;
List < CollectionElement > collectionElements = collectionElementMapper . selectList ( qw ) ;
Set < Long > old = collectionElements . stream ( ) . map ( CollectionElement : : getId ) . collect ( Collectors . toSet ( ) ) ;
for ( DesignCollectionPrintElementDTO board : printBoards ) {
if ( board . getDesignType ( ) . equals ( DesignTypeEnum . LIBRARY . getRealName ( ) ) ) {
Library library = libraryMapper . selectById ( board . getId ( ) ) ;
CollectionElement collectionElement = new CollectionElement ( ) ;
collectionElement . setAccountId ( accountId ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElement . setLevel1Type ( CollectionLevel1TypeEnum . PRINT_BOARD . getRealName ( ) ) ;
collectionElement . setLevel2Type ( board . getLevel2Type ( ) ) ;
collectionElement . setName ( library . getName ( ) ) ;
collectionElement . setUrl ( library . getUrl ( ) ) ;
collectionElement . setHasPin ( board . getIsPin ( ) ) ;
collectionElement . setMd5 ( library . getMd5 ( ) ) ;
collectionElement . setCreateDate ( new Date ( ) ) ;
collectionElementMapper . insert ( collectionElement ) ;
} else if ( board . getDesignType ( ) . equals ( DesignTypeEnum . GENERATE . getRealName ( ) ) ) {
GenerateDetail generateDetail = generateDetailMapper . selectById ( board . getId ( ) ) ;
CollectionElement collectionElement = new CollectionElement ( ) ;
collectionElement . setAccountId ( accountId ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElement . setLevel1Type ( CollectionLevel1TypeEnum . PRINT_BOARD . getRealName ( ) ) ;
// collectionElement.setLevel2Type(board.getLevel2Type());
// collectionElement.setName(generateDetail.get());
collectionElement . setUrl ( generateDetail . getUrl ( ) ) ;
collectionElement . setHasPin ( board . getIsPin ( ) ) ;
collectionElement . setMd5 ( generateDetail . getMd5 ( ) ) ;
collectionElement . setCreateDate ( new Date ( ) ) ;
collectionElementMapper . insert ( collectionElement ) ;
} else {
if ( old . contains ( board . getId ( ) ) ) {
CollectionElement collectionElement = collectionElementMapper . selectById ( board . getId ( ) ) ;
// collectionElement.setLevel2Type(board.getLevel2Type());
collectionElement . setHasPin ( board . getIsPin ( ) ) ;
collectionElement . setUpdateDate ( new Date ( ) ) ;
collectionElementMapper . updateById ( collectionElement ) ;
old . remove ( board . getId ( ) ) ;
} else {
CollectionElement collectionElement = collectionElementMapper . selectById ( board . getId ( ) ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElement . setHasPin ( board . getIsPin ( ) ) ;
collectionElement . setUpdateDate ( new Date ( ) ) ;
collectionElementMapper . updateById ( collectionElement ) ;
}
}
}
collectionElementMapper . deleteBatchIds ( old ) ;
}
if ( CollectionUtils . isEmpty ( moduleSaveDTO . getColorBoard ( ) ) ) {
List < CollectionColorDTO > colorBoards = moduleSaveDTO . getColorBoard ( ) ;
QueryWrapper < CollectionElement > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( CollectionElement : : getProjectId , projectId ) ;
qw . lambda ( ) . eq ( CollectionElement : : getLevel1Type , CollectionLevel1TypeEnum . COLOR_BOARD . getRealName ( ) ) ;
List < CollectionElement > collectionElements = collectionElementMapper . selectList ( qw ) ;
Set < Long > old = collectionElements . stream ( ) . map ( CollectionElement : : getId ) . collect ( Collectors . toSet ( ) ) ;
for ( CollectionColorDTO board : colorBoards ) {
if ( old . contains ( Long . valueOf ( board . getId ( ) ) ) ) {
old . remove ( Long . valueOf ( board . getId ( ) ) ) ;
} else {
CollectionElement collectionElement = new CollectionElement ( ) ;
collectionElement . setAccountId ( accountId ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElement . setLevel2Type ( CollectionLevel1TypeEnum . COLOR_BOARD . getRealName ( ) ) ;
collectionElement . setName ( board . getName ( ) ) ;
collectionElement . setHasPin ( ( byte ) 0 ) ;
collectionElement . setColorRgb ( board . getRgbValue ( ) ) ;
collectionElement . setMd5 ( " 0 " ) ;
collectionElement . setGradientString ( board . getGradientString ( ) ) ;
collectionElement . setCreateDate ( new Date ( ) ) ;
collectionElementMapper . insert ( collectionElement ) ;
}
}
collectionElementMapper . deleteBatchIds ( old ) ;
}
if ( CollectionUtils . isEmpty ( moduleSaveDTO . getSketchBoard ( ) ) ) {
QueryWrapper < CollectionElement > qw = new QueryWrapper < > ( ) ;
qw . lambda ( ) . eq ( CollectionElement : : getProjectId , projectId ) ;
qw . lambda ( ) . eq ( CollectionElement : : getLevel1Type , CollectionLevel1TypeEnum . SKETCH_BOARD . getRealName ( ) ) ;
List < CollectionElement > collectionElements = collectionElementMapper . selectList ( qw ) ;
Set < Long > old = collectionElements . stream ( ) . map ( CollectionElement : : getId ) . collect ( Collectors . toSet ( ) ) ;
List < CollectionSketchDTO > sketchBoards = moduleSaveDTO . getSketchBoard ( ) ;
for ( CollectionSketchDTO board : sketchBoards ) {
if ( board . getDesignType ( ) . equals ( DesignTypeEnum . LIBRARY . getRealName ( ) ) ) {
Library library = libraryMapper . selectById ( board . getSketchBoardId ( ) ) ;
CollectionElement collectionElement = new CollectionElement ( ) ;
collectionElement . setAccountId ( accountId ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElement . setLevel1Type ( CollectionLevel1TypeEnum . PRINT_BOARD . getRealName ( ) ) ;
collectionElement . setLevel2Type ( board . getLevel2Type ( ) ) ;
collectionElement . setName ( library . getName ( ) ) ;
collectionElement . setUrl ( library . getUrl ( ) ) ;
collectionElement . setHasPin ( board . getIsPin ( ) ) ;
collectionElement . setMd5 ( library . getMd5 ( ) ) ;
collectionElement . setCreateDate ( new Date ( ) ) ;
collectionElementMapper . insert ( collectionElement ) ;
} else if ( board . getDesignType ( ) . equals ( DesignTypeEnum . GENERATE . getRealName ( ) ) ) {
GenerateDetail generateDetail = generateDetailMapper . selectById ( board . getSketchBoardId ( ) ) ;
CollectionElement collectionElement = new CollectionElement ( ) ;
collectionElement . setAccountId ( accountId ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElement . setLevel1Type ( CollectionLevel1TypeEnum . PRINT_BOARD . getRealName ( ) ) ;
collectionElement . setLevel2Type ( board . getLevel2Type ( ) ) ;
// collectionElement.setName(generateDetail.get());
collectionElement . setUrl ( generateDetail . getUrl ( ) ) ;
collectionElement . setHasPin ( board . getIsPin ( ) ) ;
collectionElement . setMd5 ( generateDetail . getMd5 ( ) ) ;
collectionElement . setCreateDate ( new Date ( ) ) ;
collectionElementMapper . insert ( collectionElement ) ;
} else {
if ( old . contains ( board . getSketchBoardId ( ) ) ) {
CollectionElement collectionElement = collectionElementMapper . selectById ( board . getSketchBoardId ( ) ) ;
collectionElement . setLevel2Type ( board . getLevel2Type ( ) ) ;
collectionElement . setHasPin ( board . getIsPin ( ) ) ;
collectionElement . setUpdateDate ( new Date ( ) ) ;
collectionElementMapper . updateById ( collectionElement ) ;
old . remove ( board . getSketchBoardId ( ) ) ;
} else {
CollectionElement collectionElement = collectionElementMapper . selectById ( board . getSketchBoardId ( ) ) ;
collectionElement . setProjectId ( projectId ) ;
collectionElement . setLevel2Type ( board . getLevel2Type ( ) ) ;
collectionElement . setHasPin ( board . getIsPin ( ) ) ;
collectionElement . setUpdateDate ( new Date ( ) ) ;
collectionElementMapper . updateById ( collectionElement ) ;
}
}
}
collectionElementMapper . deleteBatchIds ( old ) ;
}
return null ;
}
}