TASK:AiDA模块化

This commit is contained in:
shahaibo
2025-03-16 13:09:50 +08:00
parent 1637db2fe3
commit 8fa76c6732
55 changed files with 3236 additions and 132 deletions

View File

@@ -1,9 +1,13 @@
package com.ai.da.service;
import com.ai.da.mapper.primary.entity.Collection;
import com.ai.da.mapper.primary.entity.CollectionElement;
import com.ai.da.model.vo.CollectionColorVO;
import com.ai.da.model.vo.UserLikeCollectionVO;
import com.baomidou.mybatisplus.extension.service.IService;
import java.util.List;
/**
* 服务类
*
@@ -25,4 +29,8 @@ public interface CollectionService extends IService<Collection> {
* 查询choose关联的collection
*/
UserLikeCollectionVO chooseCollection(Long id);
String getMoodboardPositionString(Long id);
List<CollectionColorVO> resolveColorBoard(List<CollectionElement> collectionElements);
}

View File

@@ -95,6 +95,8 @@ public interface DesignService extends IService<Design> {
Integer designProcess(String processId);
void parseMoodboardPosition(String moodboardPosition, Long collectionIdParam);
void relationImageId(DesignPythonObjects objects);
List<CollectionSketchVO> sketchesBoundingBox(ReDesignCollectionDTO reDesignCollectionDTO);

View File

@@ -60,4 +60,6 @@ public interface SysFileService extends IService<SysFile> {
List<SysFileVO> getByUrlList(List<String> urlList);
List<SysFile> getByIds(List<Long> ids);
SysFile getOneBySex(Long styleId, String sex);
}

View File

@@ -1,14 +1,14 @@
package com.ai.da.service;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.mapper.primary.entity.CanvasElementUpload;
import com.ai.da.mapper.primary.entity.ToProductImageResult;
import com.ai.da.mapper.primary.entity.TrialOrder;
import com.ai.da.mapper.primary.entity.UserLikeGroup;
import com.ai.da.model.dto.ExportSaveDTO;
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.vo.*;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
@@ -37,6 +37,8 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
*/
UserLikeChooseVO choose(Long userGroupId);
ProjectChooseVO choose(ProjectDTO projectDTO);
void deleteTrialData(Long id);
void updateDate(Long id,String timeZone);
@@ -72,4 +74,10 @@ public interface UserLikeGroupService extends IService<UserLikeGroup> {
String download();
Boolean productImageInitialize(ProductImageInitializeDTO productImageInitializeDTO);
IPage<ProjectVO> getPage(ProjectQueryDTO projectQueryDTO);
ModuleChooseVO getModuleContent(ProjectDTO projectDTO);
ModuleChooseVO saveModuleContent(ModuleSaveDTO moduleSaveDTO);
}

View File

@@ -3,6 +3,7 @@ package com.ai.da.service;
import com.ai.da.mapper.primary.entity.Style;
import com.ai.da.mapper.primary.entity.Workspace;
import com.ai.da.model.dto.ProjectDTO;
import com.ai.da.model.dto.WorkspaceDTO;
import com.ai.da.model.dto.WorkspaceSaveDTO;
import com.ai.da.model.enums.BizJson;
@@ -11,6 +12,7 @@ import com.ai.da.model.vo.StyleVO;
import com.ai.da.model.vo.WorkspaceVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.transaction.annotation.Transactional;
import java.io.FileNotFoundException;
import java.util.List;
@@ -53,4 +55,9 @@ public interface WorkspaceService extends IService<Workspace> {
Workspace getCurrentWorkspace();
List<StyleVO> styleList();
@Transactional
Long saveOrUpdateProject(ProjectDTO projectDTO);
Long getByProjectId(Long projectId);
}

View File

@@ -19,7 +19,6 @@ import com.ai.da.model.vo.UserLikeCollectionVO;
import com.ai.da.service.CollectionElementService;
import com.ai.da.service.CollectionService;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
@@ -196,7 +195,8 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
return response;
}
private String getMoodboardPositionString(Long id) {
@Override
public String getMoodboardPositionString(Long id) {
QueryWrapper<MoodboardPosition> qw = new QueryWrapper<>();
qw.lambda().eq(MoodboardPosition::getCollectionId, id);
List<MoodboardPosition> moodboardPositions = moodboardPositionMapper.selectList(qw);
@@ -258,7 +258,8 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
}
}
private List<CollectionColorVO> resolveColorBoard(List<CollectionElement> collectionElements) {
@Override
public List<CollectionColorVO> resolveColorBoard(List<CollectionElement> collectionElements) {
return CopyUtil.copyList(collectionElements, CollectionColorVO.class, (o, d) -> {
String name = o.getName();
if (StringUtils.isBlank(name)) {

View File

@@ -6,7 +6,9 @@ import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.enums.SysFileLevel1TypeEnum;
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
import com.ai.da.common.utils.*;
import com.ai.da.mapper.primary.StyleMapper;
import com.ai.da.mapper.primary.SysFileMapper;
import com.ai.da.mapper.primary.entity.Style;
import com.ai.da.mapper.primary.entity.SysFile;
import com.ai.da.model.vo.SysFileVO;
import com.ai.da.service.SysFileService;
@@ -43,6 +45,8 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
private SysFileMapper sysFileMapper;
@Resource
private FileProperties fileProperties;
@Resource
private StyleMapper styleMapper;
@Transactional(rollbackFor = Exception.class)
@Override
@@ -267,4 +271,30 @@ public class SysFileServiceImpl extends ServiceImpl<SysFileMapper, SysFile> impl
queryWrapper.in("id", ids);
return sysFileMapper.selectList(queryWrapper);
}
@Override
public SysFile getOneBySex(Long styleId, String sex) {
Style style = new Style();
if (styleId != null) {
style = styleMapper.selectById(styleId);
}
QueryWrapper<SysFile> qw = new QueryWrapper<>();
qw.lambda().eq(SysFile::getLevel1Type, "Models");
qw.lambda().eq(SysFile::getLevel2Type, sex);
if (style.getId() != null) {
qw.lambda().eq(SysFile::getLevel3Type, style.getName());
}
List<SysFile> sysFileList = sysFileMapper.selectList(qw);
if (!CollectionUtils.isEmpty(sysFileList)) {
return sysFileList.get(0);
}
return null;
}
public static void main(String[] args) {
Style style = new Style();
if (Objects.nonNull(style)) {
System.out.println("buxing");
}
}
}

View File

@@ -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;
}
}

View File

@@ -8,20 +8,24 @@ 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.model.dto.ProjectDTO;
import com.ai.da.model.dto.WorkspaceDTO;
import com.ai.da.model.dto.WorkspaceSaveDTO;
import com.ai.da.model.enums.*;
import com.ai.da.model.vo.*;
import com.ai.da.service.SysFileService;
import com.ai.da.service.WorkspaceService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
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.sun.org.apache.bcel.internal.generic.NEW;
import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.FileItemFactory;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
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;
@@ -30,6 +34,7 @@ import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import java.io.*;
import java.nio.file.Files;
import java.time.LocalDateTime;
import java.util.*;
import java.util.stream.Collectors;
@@ -46,6 +51,9 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
@Resource
private WorkspaceMapper workspaceMapper;
@Resource
private ProjectMapper projectMapper;
@Resource
private StyleMapper styleMapper;
@@ -67,6 +75,9 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
@Value("${minio.bucketName.users}")
private String users;
@Resource
private SysFileService sysFileService;
@Override
public IPage<WorkspaceVO> selectWorkspacePage(IPage<WorkspaceVO> page, WorkspaceVO workspace) {
@@ -583,6 +594,107 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
return styleVOS;
}
@Override
@Transactional
public Long saveOrUpdateProject(ProjectDTO projectDTO) {
AuthPrincipalVo userInfo = UserContext.getUserHolder();
if (projectDTO.getId() != null) {
Long projectId = projectDTO.getId();
if (projectDTO.getName() != null) {
Project project = projectMapper.selectById(projectId);
project.setName(projectDTO.getName());
projectMapper.updateById(project);
}
QueryWrapper<Workspace> qw = new QueryWrapper<>();
qw.lambda().eq(Workspace::getProjectId, projectDTO.getId());
List<Workspace> workspaces = workspaceMapper.selectList(qw);
if (CollectionUtils.isEmpty(workspaces)) {
throw new BusinessException("Lack of associated workspace.");
}else {
Workspace workspace = workspaces.get(0);
Workspace workspaceNew = CopyUtil.copyObject(projectDTO.getWorkspace(), Workspace.class);
workspaceNew.setId(workspace.getId());
workspace.setUpdateTime(LocalDateTime.now());
workspaceMapper.updateById(workspaceNew);
}
if (projectDTO.getStyleId() != null) {
QueryWrapper<WorkspaceRelStyle> wRSQW = new QueryWrapper<>();
wRSQW.lambda().eq(WorkspaceRelStyle::getWorkspaceId, projectDTO.getWorkspace().getId());
List<WorkspaceRelStyle> workspaceRelStyles = workspaceRelStyleMapper.selectList(wRSQW);
if (CollectionUtils.isEmpty(workspaceRelStyles)) {
WorkspaceRelStyle rel = new WorkspaceRelStyle();
rel.setWorkspaceId(projectDTO.getWorkspace().getId());
rel.setStyleId(projectDTO.getStyleId());
workspaceRelStyleMapper.insert(rel);
}else {
WorkspaceRelStyle workspaceRelStyleOld = workspaceRelStyles.get(0);
if (!Objects.equals(workspaceRelStyleOld.getStyleId(), projectDTO.getStyleId())) {
workspaceRelStyleOld.setStyleId(projectDTO.getStyleId());
workspaceRelStyleMapper.updateById(workspaceRelStyleOld);
}
}
}else {
QueryWrapper<WorkspaceRelStyle> wRSQW = new QueryWrapper<>();
wRSQW.lambda().eq(WorkspaceRelStyle::getWorkspaceId, projectDTO.getWorkspace().getId());
List<WorkspaceRelStyle> workspaceRelStyles = workspaceRelStyleMapper.selectList(wRSQW);
if (!CollectionUtils.isEmpty(workspaceRelStyles)) {
workspaceRelStyleMapper.deleteBatchIds(workspaceRelStyles);
}
}
return projectId;
}else {
Project project = CopyUtil.copyObject(projectDTO, Project.class);
project.setAccountId(userInfo.getId());
LocalDateTime now = LocalDateTime.now();
project.setCreateTime(now);
project.setUpdateTime(now);
projectMapper.insert(project);
Workspace workspace = CopyUtil.copyObject(projectDTO.getWorkspace(), Workspace.class);
workspace.setIsLastIndex(0);
workspace.setAccountId(userInfo.getId());
workspace.setProjectId(project.getId());
workspace.setCreateTime(LocalDateTime.now());
workspace.setUpdateTime(LocalDateTime.now());
if (projectDTO.getProcess().equals(DesignProcess.SERIES_DESIGN.name())) {
SysFile sysFile = sysFileService.getOneBySex(projectDTO.getStyleId(), projectDTO.getWorkspace().getSex());
if (projectDTO.getWorkspace().getSex().equals(Sex.FEMALE.getValue())) {
workspace.setMannequinFemaleId(sysFile.getId());
workspace.setMannequinFemaleType("System");
}else {
workspace.setMannequinMaleId(sysFile.getId());
workspace.setMannequinMaleType("System");
}
}
workspaceMapper.insert(workspace);
if (projectDTO.getStyleId() != null) {
WorkspaceRelStyle rel = new WorkspaceRelStyle();
rel.setWorkspaceId(workspace.getId());
rel.setStyleId(projectDTO.getStyleId());
workspaceRelStyleMapper.insert(rel);
}
return project.getId();
}
}
@Override
public Long getByProjectId(Long projectId) {
QueryWrapper<Workspace> qw = new QueryWrapper<>();
qw.lambda().eq(Workspace::getProjectId, projectId);
List<Workspace> workspaceList = workspaceMapper.selectList(qw);
if (CollectionUtils.isEmpty(workspaceList)) {
throw new BusinessException("Lack of associated workspace.");
}
return workspaceList.get(0).getId();
}
public static List<File> getPNGFiles(String directoryPath) {
List<File> pngFiles = new ArrayList<>();
File directory = new File(directoryPath);