TASK:代码提交;

This commit is contained in:
shahaibo
2023-10-10 14:19:10 +08:00
parent 1f463aeaaa
commit 4a803d90f2
17 changed files with 405 additions and 143 deletions

View File

@@ -22,6 +22,8 @@ import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.FileNotFoundException;
import java.util.List;
/**
@@ -102,10 +104,25 @@ public class WorkspaceController {
@PostMapping("system_file_copy")
@ApiOperationSupport(order = 7)
@ApiOperation(value = "文件复制", notes = "传入id")
@ApiOperation(value = "minio数据迁移")
public Response<Boolean> systemFileCopy() {
workspaceService.systemFileCopy();
return Response.success(true);
}
@PostMapping("moveFile")
@ApiOperationSupport(order = 7)
@ApiOperation(value = "增加一级性别路径")
public Response<Boolean> moveFile() {
workspaceService.moveFile();
return Response.success(true);
}
@PostMapping("maleDataInsert")
@ApiOperationSupport(order = 7)
@ApiOperation(value = "男装数据入库入minio")
public Response<Boolean> maleDataInsert() throws FileNotFoundException {
workspaceService.maleDataInsert();
return Response.success(true);
}
}

View File

@@ -47,6 +47,8 @@ public class Library implements Serializable {
*/
private String level2Type;
private String level3Type;
/**
* 元素名
*/

View File

@@ -40,6 +40,8 @@ public class SysFile implements Serializable {
*/
private String level2Type;
private String level3Type;
/**
* 名字
*

View File

@@ -61,17 +61,16 @@ public class Workspace implements Serializable {
* 人体模型
*/
@ApiModelProperty(value = "人体模型ID")
private Long mannequinId;
/**
* 人体模型
*/
@ApiModelProperty(value = "人体模型URL")
private String mannequinUrl;
private Long mannequinFemaleId;
private Long mannequinMaleId;
private Long mannequinChildId;
/**
* 人体模型
*/
@ApiModelProperty(value = "人体模型类型")
private String mannequinType;
private String mannequinFemaleType;
private String mannequinMaleType;
private String mannequinChildType;
/**
* 最后使用的工作空间标识
*/

View File

@@ -36,6 +36,8 @@ public class DesignCollectionDTO {
private String modelType;
private String modelSex;
@ApiModelProperty("templateId")
private Long templateId;

View File

@@ -17,6 +17,8 @@ public class QueryLibraryPageServiceDTO extends PageQueryBaseVo {
@ApiModelProperty("二级类型")
private String level2Type;
private String modelSex;
@ApiModelProperty("类型 Top , Bottom ,Print ")
private String type;

View File

@@ -41,6 +41,8 @@ public class ReDesignCollectionDTO {
@ApiModelProperty("templateId")
private Long templateId;
private String modelType;
@NotBlank(message = "singleOverall cannot be empty!")
@ApiModelProperty("控制生成类型的参数两个选项outfit时候传 single , 另外一个传 overall")
private String singleOverall;

View File

@@ -7,19 +7,18 @@ import com.fasterxml.jackson.annotation.JsonValue;
* @Date: 2023/08/01 17:21
* @Description: 服装性别分类
*/
public enum Position implements IEnumDisplay {
public enum FemalePosition implements IEnumDisplay {
OUTWEAR("Outwear"),
BLOUSE("Blouse"),
DRESS("Dress"),
TROUSERS("Trousers"),
SKIRT("Skirt")
// SINGLE("Single"),
;
private String value;
Position(String value) {
FemalePosition(String value) {
this.value = value;
}

View File

@@ -0,0 +1,28 @@
package com.ai.da.model.enums;
import com.fasterxml.jackson.annotation.JsonValue;
/**
* @Author: SHAHAIBO
* @Date: 2023/08/01 17:21
* @Description: 服装性别分类
*/
public enum MalePosition implements IEnumDisplay {
TOPS("Tops"),
BOTTOMS("Bottoms"),
OUTWEAR("Outwear")
;
private String value;
MalePosition(String value) {
this.value = value;
}
@Override
@JsonValue
public String getValue() {
return this.value;
}
}

View File

@@ -22,6 +22,10 @@ public class WorkspaceVO extends Workspace {
private Long currentId;
private PageBaseResponse<Workspace> page;
private PageBaseResponse<WorkspaceVO> page;
private String femalePresignedUrl;
private String malePresignedUrl;
private String childPresignedUrl;
}

View File

@@ -1205,10 +1205,10 @@ public class PythonService {
MediaType mediaType = MediaType.parse("application/json");
RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content));
Request request = new Request.Builder()
// .url(accessPythonIp+":11112/aifda/api/v1.0/attribute_retrieval")
.url(accessPythonIp+":9991/aifda/api/v1.0/attribute_retrieval")
.url("http://18.167.251.121:9991/api/attribute_retrieve")
// .url(accessPythonIp+":9991/aifda/api/v1.0/attribute_retrieval")
.method("POST", body)
.addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")
.addHeader("Content-Type", "application/json")
.build();
Response response = null;

View File

@@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.IService;
import javax.servlet.http.HttpServletRequest;
import java.io.FileNotFoundException;
import java.util.List;
/**
@@ -40,4 +41,8 @@ public interface WorkspaceService extends IService<Workspace> {
List<ModelsVO> getMannequins(String sex);
void systemFileCopy();
void moveFile();
void maleDataInsert() throws FileNotFoundException;
}

View File

@@ -80,10 +80,9 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
CollectionLevel1TypeEnum level1TypeEnum = CollectionLevel1TypeEnum.uploadOf(uploadDTO.getLevel1Type());
Assert.notNull(level1TypeEnum, "unknown parameter level1Type!");
// String path = calculateFileUrl(level1TypeEnum, userInfo.getId());aida-collection-element
String objectName = userInfo.getId() + "/" + level1TypeEnum.getRealName();
String path = minioUtil.upload("aida-collection-element", objectName, uploadDTO.getFile());
// File file = FileUtil.upload(uploadDTO.getFile(), path);
//保存element元素
CollectionElement collectionElement = resolveData(uploadDTO, userInfo, path);
saveOne(collectionElement);

View File

@@ -75,7 +75,9 @@ public class CollectionServiceImpl extends ServiceImpl<CollectionMapper, Collect
Assert.notEmpty(collectionElements,"collection element does not exist!");
response.setCollectionId(id);
response.setMoodTemplateId(collection.getMoodTemplateId());
if (collection.getMoodTemplateId() != null) {
response.setMoodTemplateUrl(minioUtil.getPresignedUrl(collectionElementService.getById(response.getMoodTemplateId()).getUrl(), 10));
}
Map<String,List<CollectionElement>> maps = collectionElements
.stream()
.collect(Collectors.groupingBy(CollectionElement::getLevel1Type));

View File

@@ -110,24 +110,26 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
private void calculateLibraryAndSysFile(DesignCollectionDTO designDTO, ValidateElementVO elementVO, AuthPrincipalVo userInfo) {
//查询用户 sketch library
List<LibraryVo> libraryVos;
if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
List<String> sketchUrlList = elementVO.getSketchBoardElements()
.stream()
.map(CollectionElement::getUrl)
.collect(Collectors.toList());
DesignAttributeRetrievalDTO designAttributeRetrievalDTO =
pythonService.generateAttributeRetrieval(sketchUrlList, userInfo.getId());
if (CollectionUtils.isEmpty(designAttributeRetrievalDTO.getLibraryUrls())) {
libraryVos = null;
} else {
libraryVos = libraryService.getByUrlList(designAttributeRetrievalDTO.getLibraryUrls(), userInfo.getId());
}
List<SysFileVO> sysFileVOS = sysFileService.getByUrlList(designAttributeRetrievalDTO.getSysFileUrlS());
elementVO.setSysFileVo(sysFileVOS);
} else {
// if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
// List<String> sketchUrlList = elementVO.getSketchBoardElements()
// .stream()
// .map(CollectionElement::getUrl)
// .collect(Collectors.toList());
// DesignAttributeRetrievalDTO designAttributeRetrievalDTO =
// pythonService.generateAttributeRetrieval(sketchUrlList, userInfo.getId());
// if (CollectionUtils.isEmpty(designAttributeRetrievalDTO.getLibraryUrls())) {
// libraryVos = null;
// } else {
// libraryVos = libraryService.getByUrlList(designAttributeRetrievalDTO.getLibraryUrls(), userInfo.getId());
// }
// List<SysFileVO> sysFileVOS = sysFileService.getByUrlList(designAttributeRetrievalDTO.getSysFileUrlS());
// elementVO.setSysFileVo(sysFileVOS);
// } else {
// libraryVos = libraryService.selectByAccountIdAnd1TypeList(userInfo.getId(),
// Collections.singletonList(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName()));
// }
libraryVos = libraryService.selectByAccountIdAnd1TypeList(userInfo.getId(),
Collections.singletonList(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName()));
}
elementVO.setLibraryVos(libraryVos);
//校验比列
validateRatio(designDTO, libraryVos);
@@ -227,48 +229,48 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}
}
private DesignCollectionVO designOrRedesignOperate(DesignCollectionDTO designDTO, AuthPrincipalVo userInfo,
Long collectionIdParam, ValidateElementVO elementVO) {
if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
//编辑sketchBoard
collectionElementService.editSketchBoardsElement(elementVO, designDTO.getSketchBoards());
}
if (CollectionUtil.isNotEmpty(designDTO.getPrintBoards())) {
//编辑printBoard
collectionElementService.editPrintBoardsElement(elementVO, designDTO.getPrintBoards());
}
//保存collection
Long collectionId = (null == collectionIdParam) ?
collectionService.saveCollection(userInfo.getId(), designDTO.getTimeZone(), designDTO.getMoodTemplateId()) : collectionIdParam;
List<Long> elementIds = getElementId(elementVO);
//批量关联element 到 collection
collectionElementService.relationCollection(elementIds, collectionId);
//library转化为collection(生成)
saveCollectionElemntsByLibrarys(elementVO, collectionId);
//保存颜色版
List<CollectionElementVO> colorElementList = collectionElementService.saveColorBoard(designDTO.getColorBoards(), collectionId, designDTO.getTimeZone());
//保存design
Long designId = saveOne(designDTO, collectionId, userInfo.getId());
//计算library
calculateLibraryAndSysFile(designDTO, elementVO, userInfo);
//组装design入参
DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
designDTO.getSingleOverall(), designDTO.getSwitchCategory(), elementVO, designDTO.getProcessId());
//缓存保存的文件 方便后面处理进度问题 采用新的进度条获取方式 根据processId获取
// setDesignProcess(userInfo.getId(), pythonObjects);
//design
pythonService.design(pythonObjects);
//生成library
generateLibrary(elementVO, designDTO.getTimeZone());
//处理关联关系,修复element覆盖得情况
List<CollectionElement> reLationelements = collectionElementService.getByOnlyCollectionId(collectionId);
List<Long> reLationelementIds = reLationelements.stream().map(CollectionElement::getId).collect(Collectors.toList());
handleCollectionElementRelation(collectionId, (null == collectionIdParam) ? false : true, reLationelementIds);
//保存python返回信息
// return savePythonDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone(),responseJSONObject);
//保存designItem 和detail
return saveDesignItemAndDetail(pythonObjects, designId, collectionId, userInfo, designDTO.getTimeZone());
}
// private DesignCollectionVO designOrRedesignOperate(DesignCollectionDTO designDTO, AuthPrincipalVo userInfo,
// Long collectionIdParam, ValidateElementVO elementVO) {
// if (CollectionUtil.isNotEmpty(designDTO.getSketchBoards())) {
// //编辑sketchBoard
// collectionElementService.editSketchBoardsElement(elementVO, designDTO.getSketchBoards());
// }
// if (CollectionUtil.isNotEmpty(designDTO.getPrintBoards())) {
// //编辑printBoard
// collectionElementService.editPrintBoardsElement(elementVO, designDTO.getPrintBoards());
// }
// //保存collection
// Long collectionId = (null == collectionIdParam) ?
// collectionService.saveCollection(userInfo.getId(), designDTO.getTimeZone(), designDTO.getMoodTemplateId()) : collectionIdParam;
// List<Long> elementIds = getElementId(elementVO);
// //批量关联element 到 collection
// collectionElementService.relationCollection(elementIds, collectionId);
// //library转化为collection(生成)
// saveCollectionElemntsByLibrarys(elementVO, collectionId);
// //保存颜色版
// List<CollectionElementVO> colorElementList = collectionElementService.saveColorBoard(designDTO.getColorBoards(), collectionId, designDTO.getTimeZone());
// //保存design
// Long designId = saveOne(designDTO, collectionId, userInfo.getId());
// //计算library
// calculateLibraryAndSysFile(designDTO, elementVO, userInfo);
// //组装design入参
// DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
// designDTO.getSingleOverall(), designDTO.getSwitchCategory(), elementVO, designDTO.getProcessId());
// //缓存保存的文件 方便后面处理进度问题 采用新的进度条获取方式 根据processId获取
//// setDesignProcess(userInfo.getId(), pythonObjects);
// //design
// pythonService.design(pythonObjects);
// //生成library
// generateLibrary(elementVO, designDTO.getTimeZone());
// //处理关联关系,修复element覆盖得情况
// List<CollectionElement> reLationelements = collectionElementService.getByOnlyCollectionId(collectionId);
// List<Long> reLationelementIds = reLationelements.stream().map(CollectionElement::getId).collect(Collectors.toList());
// handleCollectionElementRelation(collectionId, (null == collectionIdParam) ? false : true, reLationelementIds);
// //保存python返回信息
//// return savePythonDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone(),responseJSONObject);
// //保存designItem 和detail
// return saveDesignItemAndDetail(pythonObjects, designId, collectionId, userInfo, designDTO.getTimeZone());
// }
private DesignCollectionVO designOrRedesignOperateNew(DesignCollectionDTO designDTO, AuthPrincipalVo userInfo,
Long collectionIdParam, ValidateElementVO elementVO) {
@@ -876,10 +878,10 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
MediaType mediaType = MediaType.parse("application/json");
//关闭FastJson的引用检测 防止出现$ref 现象
String param = JSON.toJSONString(object, SerializerFeature.DisableCircularReferenceDetect);
log.info("design请求python 参数:####{}", param);
log.info("designProcess请求python 参数:####{}", param);
RequestBody body = RequestBody.create(mediaType, param);
Request request = new Request.Builder()
.url("http://18.167.251.121:9991/api/model_process")
.url("http://18.167.251.121:9991/api/get_progress")
// .url(accessPythonIp + ":10200/aifda/api/v1.0/generate")
.method("POST", body)
// .addHeader("Authorization", "Basic YWlkbGFiOjEyMw==")

View File

@@ -8,7 +8,6 @@ import com.ai.da.common.enums.*;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.DateUtil;
import com.ai.da.common.utils.FileUtil;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.LibraryMapper;
import com.ai.da.mapper.SysFileMapper;
@@ -36,7 +35,6 @@ import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -91,6 +89,9 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
Assert.notNull(level1TypeEnum,"unknown level1Type " +query.getLevel1Type());
queryWrapper.eq("level1_type", query.getLevel1Type());
}
if (!StringUtils.isEmpty(query.getModelSex()) && query.getLevel1Type().equals(LibraryLevel1TypeEnum.SKETCH_BOARD.getRealName())) {
queryWrapper.eq("level3_type", query.getModelSex());
}
if(!StringUtils.isEmpty(query.getLevel2Type())){
CollectionLevel2TypeEnum level2TypeEnum = CollectionLevel2TypeEnum.of(query.getLevel2Type());
Assert.notNull(level2TypeEnum,"unknown level2Type " +query.getLevel2Type());
@@ -159,7 +160,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
}
Assert.isTrue(!( level1TypeEnum.equals(LibraryLevel1TypeEnum.SKETCH_BOARD)
&& StringUtils.isEmpty(libraryUploadDTO.getLevel2Type()) ),"level2Type cannot be empty!");
String path = calculateFileUrl(level1TypeEnum, libraryUploadDTO.getLevel2Type(), userInfo.getId());
String path = calculateFileUrl(level1TypeEnum, libraryUploadDTO.getLevel2Type(), libraryUploadDTO.getModelSex(), userInfo.getId());
String bucketName = null;
switch (level1TypeEnum) {
case MODELS:
@@ -174,7 +175,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
throw new BusinessException("unknown level1_type");
}
//保存element元素
if (libraryUploadDTO.getModelType() != null) {
if (!StringUtils.isEmpty(libraryUploadDTO.getModelType())) {
if (libraryUploadDTO.getModelType().equals(ModelType.LIBRARY.getValue())) {
String filePath = minioUtil.upload(bucketName, path, libraryUploadDTO.getFile());
String newFilePath = processMannequins(filePath);
@@ -185,7 +186,7 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
return libraryUpdateVo;
}else if (libraryUploadDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
bucketName = "aida-sys-image";
path = "models/" + libraryUploadDTO.getModelSex();
path = "models/" + libraryUploadDTO.getModelSex().toLowerCase();
String filePath = minioUtil.upload(bucketName, path, libraryUploadDTO.getFile());
String newFilePath = processMannequins(filePath);
Library library = resolveData(libraryUploadDTO, userInfo, newFilePath);
@@ -262,12 +263,11 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
library.setUrl(filePath);
//按时区计算
library.setCreateDate(DateUtil.getByTimeZone(uploadDTO.getTimeZone()));
// String linuxDomain = fileProperties.getLinuxDomain();
// if (!StringUtils.isEmpty(linuxDomain)) {
// //linux 系统
// String oldPath = fileProperties.getSys().getPath();
// library.setUrl(file.getAbsolutePath().replace(oldPath, linuxDomain));
// }
if (uploadDTO.getModelType().equals(ModelType.LIBRARY.getValue())) {
library.setLevel2Type(uploadDTO.getModelSex());
}else {
library.setLevel3Type(uploadDTO.getModelSex());
}
libraryMapper.insert(library);
return library;
}else if (uploadDTO.getModelType().equals(ModelType.SYSTEM.getValue())) {
@@ -288,10 +288,12 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
}
}
private String calculateFileUrl(LibraryLevel1TypeEnum level1TypeEnum, String level2Type, Long userId) {
// String rootPath = fileProperties.getSys().getPath();
// String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
private String calculateFileUrl(LibraryLevel1TypeEnum level1TypeEnum, String level2Type, String modelSex, Long userId) {
if (StringUtils.isEmpty(modelSex)) {
return StringUtils.isEmpty(level2Type) ? userId + "/" + level1TypeEnum.getRealName().toLowerCase() : userId + "/" + level1TypeEnum.getRealName().toLowerCase() + "/" + level2Type;
}else {
return StringUtils.isEmpty(level2Type) ? userId + "/" + level1TypeEnum.getRealName().toLowerCase() + "/" + modelSex : userId + "/" + level1TypeEnum.getRealName().toLowerCase() + "/" + modelSex + "/" + level2Type;
}
}
@Override

View File

@@ -6,7 +6,9 @@ import com.ai.da.common.enums.LibraryLevel1TypeEnum;
import com.ai.da.common.enums.SysFileLevel1TypeEnum;
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.common.utils.FileUtil;
import com.ai.da.common.utils.MD5Utils;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.LibraryMapper;
import com.ai.da.mapper.SysFileMapper;
@@ -37,12 +39,10 @@ import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;
import javax.annotation.Resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.*;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
@@ -85,9 +85,23 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
workspace.setUserName(userInfo.getUsername());
if (null == workspace.getId()) {
workspace.setIsLastIndex(0);
workspace.setMannequinUrl("aida-mannequins/model_1693218345.2714432.png");
workspace.setMannequinType(MannequinType.SYSTEM.getValue());
workspace.setSex(Sex.MALE.getValue());
QueryWrapper<SysFile> systemFemaleQw = new QueryWrapper<>();
systemFemaleQw.lambda().eq(SysFile::getLevel1Type, "Models");
systemFemaleQw.lambda().eq(SysFile::getLevel2Type, "Female");
List<SysFile> sysFemaleFiles = sysFileMapper.selectList(systemFemaleQw);
if (!CollectionUtils.isEmpty(sysFemaleFiles)) {
workspace.setMannequinFemaleId(sysFemaleFiles.get(0).getId());
workspace.setMannequinFemaleType(MannequinType.SYSTEM.getValue());
}
QueryWrapper<SysFile> systemMaleQw = new QueryWrapper<>();
systemMaleQw.lambda().eq(SysFile::getLevel1Type, "Models");
systemMaleQw.lambda().eq(SysFile::getLevel2Type, "Male");
List<SysFile> sysMaleFiles = sysFileMapper.selectList(systemFemaleQw);
if (!CollectionUtils.isEmpty(sysMaleFiles)) {
workspace.setMannequinMaleId(sysMaleFiles.get(0).getId());
workspace.setMannequinMaleType(MannequinType.SYSTEM.getValue());
}
workspace.setSex(Sex.FEMALE.getValue());
workspace.setPosition("Overall");
workspace.setSystemDesignerPercentage(SYSTEM_DESIGNER_PERCENTAGE);
int insert = workspaceMapper.insert(workspace);
@@ -115,22 +129,25 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
// 给用户新建默认workspace
Workspace workspace = new Workspace();
workspace.setWorkSpaceName(WORKSPACE_NAME);
workspace.setSex(Sex.MALE.getValue());
workspace.setSex(Sex.FEMALE.getValue());
workspace.setSystemDesignerPercentage(SYSTEM_DESIGNER_PERCENTAGE);
workspace.setPosition("Overall");
workspace.setUserName(userName);
QueryWrapper<SysFile> systemQw = new QueryWrapper<>();
systemQw.lambda().eq(SysFile::getLevel1Type, "Models");
systemQw.lambda().eq(SysFile::getLevel2Type, "Female");
List<SysFile> sysFiles = sysFileMapper.selectList(systemQw);
if (!CollectionUtils.isEmpty(sysFiles)) {
workspace.setMannequinId(sysFiles.get(0).getId());
workspace.setMannequinUrl(sysFiles.get(0).getUrl());
workspace.setMannequinType(MannequinType.SYSTEM.getValue());
}else {
workspace.setMannequinId(null);
workspace.setMannequinUrl("aida-mannequins/model_1693218345.2714432.png");
workspace.setMannequinType(MannequinType.SYSTEM.getValue());
QueryWrapper<SysFile> systemFemaleQw = new QueryWrapper<>();
systemFemaleQw.lambda().eq(SysFile::getLevel1Type, "Models");
systemFemaleQw.lambda().eq(SysFile::getLevel2Type, "Female");
List<SysFile> sysFemaleFiles = sysFileMapper.selectList(systemFemaleQw);
if (!CollectionUtils.isEmpty(sysFemaleFiles)) {
workspace.setMannequinFemaleId(sysFemaleFiles.get(0).getId());
workspace.setMannequinFemaleType(MannequinType.SYSTEM.getValue());
}
QueryWrapper<SysFile> systemMaleQw = new QueryWrapper<>();
systemMaleQw.lambda().eq(SysFile::getLevel1Type, "Models");
systemMaleQw.lambda().eq(SysFile::getLevel2Type, "Male");
List<SysFile> sysMaleFiles = sysFileMapper.selectList(systemMaleQw);
if (!CollectionUtils.isEmpty(sysMaleFiles)) {
workspace.setMannequinMaleId(sysMaleFiles.get(0).getId());
workspace.setMannequinMaleType(MannequinType.SYSTEM.getValue());
}
workspace.setIsLastIndex(1);
int insert = workspaceMapper.insert(workspace);
@@ -138,23 +155,51 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
throw new BusinessException("save workspace failed");
}
page = workspaceMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw);
page.getRecords().forEach(o -> {
String url = o.getMannequinUrl();
if (url.startsWith("aida-")) {
o.setMannequinUrl(minioUtil.getPresignedUrl(o.getMannequinUrl(), 60*24));
IPage<WorkspaceVO> convert = page.convert(
o -> {
WorkspaceVO workspaceVO = CopyUtil.copyObject(o, WorkspaceVO.class);
if (o.getMannequinFemaleId() != null) {
if (o.getMannequinFemaleType().equals(ModelType.SYSTEM.getValue())) {
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinFemaleId()).getUrl(), 60));
}else if (o.getMannequinFemaleType().equals(ModelType.LIBRARY.getValue())) {
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinFemaleId()).getUrl(), 60));
}
});
vo.setPage(PageBaseResponse.success(page));
}
if (o.getMannequinMaleId() != null) {
if (o.getMannequinMaleType().equals(ModelType.SYSTEM.getValue())) {
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinMaleId()).getUrl(), 60));
}else if (o.getMannequinMaleType().equals(ModelType.LIBRARY.getValue())) {
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinMaleId()).getUrl(), 60));
}
}
return workspaceVO;
}
);
vo.setPage(PageBaseResponse.success(convert));
vo.setId(workspace.getId());
return vo;
}
page.getRecords().forEach(o -> {
String url = o.getMannequinUrl();
if (url.startsWith("aida-")) {
o.setMannequinUrl(minioUtil.getPresignedUrl(o.getMannequinUrl(), 10));
IPage<WorkspaceVO> convert = page.convert(
o -> {
WorkspaceVO workspaceVO = CopyUtil.copyObject(o, WorkspaceVO.class);
if (o.getMannequinFemaleId() != null) {
if (o.getMannequinFemaleType().equals(ModelType.SYSTEM.getValue())) {
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinFemaleId()).getUrl(), 60));
}else if (o.getMannequinFemaleType().equals(ModelType.LIBRARY.getValue())) {
workspaceVO.setFemalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinFemaleId()).getUrl(), 60));
}
});
vo.setPage(PageBaseResponse.success(page));
}
if (o.getMannequinMaleId() != null) {
if (o.getMannequinMaleType().equals(ModelType.SYSTEM.getValue())) {
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(sysFileMapper.selectById(o.getMannequinMaleId()).getUrl(), 60));
}else if (o.getMannequinMaleType().equals(ModelType.LIBRARY.getValue())) {
workspaceVO.setMalePresignedUrl(minioUtil.getPresignedUrl(libraryMapper.selectById(o.getMannequinMaleId()).getUrl(), 60));
}
}
return workspaceVO;
}
);
vo.setPage(PageBaseResponse.success(convert));
QueryWrapper<Workspace> qwIsLastIndex = new QueryWrapper<>();
qwIsLastIndex.lambda().eq(Workspace::getUserName, userName);
qwIsLastIndex.lambda().eq(Workspace::getIsLastIndex, 1);
@@ -255,12 +300,12 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
if (file != null) {
String uploadMinioPath = sysFile.getLevel1Type().toLowerCase() + "/" + sysFile.getLevel2Type().toLowerCase() + "/" + file.getName();
String bucketName = "aida-sys-image";
// boolean b = minioUtil.doesObjectExist(bucketName, uploadMinioPath);
// if (!b) {
// FileItem a = getMultipartFile(file, file.getName());
// MultipartFile multipartFile = new CommonsMultipartFile(a);
// minioUtil.upload(bucketName, uploadMinioPath, multipartFile, "");
// }
boolean b = minioUtil.doesObjectExist(bucketName, uploadMinioPath);
if (!b) {
FileItem a = getMultipartFile(file, file.getName());
MultipartFile multipartFile = new CommonsMultipartFile(a);
minioUtil.upload(bucketName, uploadMinioPath, multipartFile, "");
}
sysFile.setUrl(bucketName + "/" + uploadMinioPath);
sysFileMapper.updateById(sysFile);
}
@@ -287,12 +332,12 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
sb.append(o.getAccountId() + "/").append(o.getLevel1Type().toLowerCase() + "/").append(o.getLevel2Type().toLowerCase() + "/").append(file.getName());
}
String bucketName = "aida-users";
// boolean b = minioUtil.doesObjectExist(bucketName, sb.toString());
// if (!b) {
// FileItem a = getMultipartFile(file, file.getName());
// MultipartFile multipartFile = new CommonsMultipartFile(a);
// minioUtil.upload(bucketName, sb.toString(), multipartFile, "");
// }
boolean b = minioUtil.doesObjectExist(bucketName, sb.toString());
if (!b) {
FileItem a = getMultipartFile(file, file.getName());
MultipartFile multipartFile = new CommonsMultipartFile(a);
minioUtil.upload(bucketName, sb.toString(), multipartFile, "");
}
o.setUrl(bucketName + "/" + sb);
libraryMapper.updateById(o);
}
@@ -309,7 +354,157 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
// }
}
private FileItem getMultipartFile(File file, String fieldName){
@Override
public void moveFile() {
QueryWrapper<SysFile> sysFileQw = new QueryWrapper<>();
sysFileQw.lambda().eq(SysFile::getLevel1Type, "Images");
List<SysFile> sysFiles = sysFileMapper.selectList(sysFileQw);
for (SysFile sysFile : sysFiles) {
if (sysFile.getUrl().contains("/female")) {
continue;
}
String[] urls = sysFile.getUrl().split("/images");
String newUrl = urls[0] + "/images/female" + urls[1];
sysFile.setUrl(newUrl);
sysFileMapper.updateById(sysFile);
}
QueryWrapper<Library> libraryQw = new QueryWrapper<>();
libraryQw.lambda().eq(Library::getLevel1Type, "Sketchboard");
List<Library> libraryList = libraryMapper.selectList(libraryQw);
for (Library library : libraryList) {
String oldUrl = library.getUrl();
if (oldUrl.contains("/sketchboard")) {
String[] oldUrls = oldUrl.split("/sketchboard");
String newUrl = oldUrls[0] + "/sketchboard/female" + oldUrls[1];
library.setUrl(newUrl);
libraryMapper.updateById(library);
}else if (oldUrl.contains("/images")) {
String[] oldUrls = oldUrl.split("/images");
String newUrl = oldUrls[0] + "/images/female" + oldUrls[1];
library.setUrl(newUrl);
libraryMapper.updateById(library);
}
}
QueryWrapper<Library> modelQw = new QueryWrapper<>();
modelQw.lambda().eq(Library::getLevel1Type, "Models");
List<Library> modelList = libraryMapper.selectList(modelQw);
for (Library library : modelList) {
String oldUrl = library.getUrl();
if (oldUrl.contains("/models")) {
String[] oldUrls = oldUrl.split("/models");
String newUrl = oldUrls[0] + "/models/female" + oldUrls[1];
library.setUrl(newUrl);
libraryMapper.updateById(library);
}
}
}
@Override
public void maleDataInsert() throws FileNotFoundException {
String directoryPath = "C:\\workspace\\fileData\\aida_men_library";
List<File> pngFiles = getPNGFiles(directoryPath);
for (File pngFile : pngFiles) {
SysFile sysFile = new SysFile();
String fileName = pngFile.getName();
sysFile.setName(fileName);
sysFile.setLevel1Type("Images");
sysFile.setLevel3Type("Male");
StringBuilder sb = new StringBuilder();
sb.append("aida-sys-image/images/male");
String absolutePath = pngFile.getAbsolutePath();
if (absolutePath.contains("bottom")) {
sysFile.setLevel2Type("Bottoms");
sb.append("/bottoms/");
}else if(absolutePath.contains("top")) {
sysFile.setLevel2Type("Tops");
sb.append("/tops/");
}else if(absolutePath.contains("outer")) {
sysFile.setLevel2Type("Outwear");
sb.append("/outwear/");
}
sb.append(fileName);
String url = sb.toString();
sysFile.setUrl(url);
sysFile.setMd5(MD5Utils.encryptFile(new FileInputStream(pngFile)));
// boolean b = minioUtil.doesObjectExist("aida-sys-image", uploadMinioPath);
// if (!b) {
// FileItem a = getMultipartFile(file, file.getName());
// MultipartFile multipartFile = new CommonsMultipartFile(a);
// minioUtil.upload(bucketName, uploadMinioPath, multipartFile, "");
// }
FileItem a = getMultipartFile(pngFile, fileName);
MultipartFile multipartFile = new CommonsMultipartFile(a);
minioUtil.upload(url.substring(0,14), url.substring(15), multipartFile, "");
sysFile.setCreateDate(new Date());
sysFileMapper.insert(sysFile);
}
}
// public static void main(String[] args) throws FileNotFoundException {
// String b = "C:\\workspace\\fileData\\aida_men_library\\top\\mens_test_9992.png";
// File pngFile = new File(b);
// SysFile sysFile = new SysFile();
// String fileName = pngFile.getName();
// sysFile.setName(fileName);
// sysFile.setLevel1Type("Images");
// sysFile.setLevel3Type("Male");
// StringBuilder sb = new StringBuilder();
// sb.append("aida-sys-image/images/male");
// String absolutePath = pngFile.getAbsolutePath();
// if (absolutePath.contains("bottom")) {
// sysFile.setLevel2Type("Bottoms");
// sb.append("/bottoms/");
// }else if(absolutePath.contains("top")) {
// sysFile.setLevel2Type("Tops");
// sb.append("/tops/");
// }else if(absolutePath.contains("outer")) {
// sysFile.setLevel2Type("Outwear");
// sb.append("/outwear/");
// }
// sb.append(fileName);
// String url = sb.toString();
// sysFile.setUrl(url);
// sysFile.setMd5(MD5Utils.encryptFile(new FileInputStream(pngFile)));
//// boolean b = minioUtil.doesObjectExist("aida-sys-image", uploadMinioPath);
//// if (!b) {
//// FileItem a = getMultipartFile(file, file.getName());
//// MultipartFile multipartFile = new CommonsMultipartFile(a);
//// minioUtil.upload(bucketName, uploadMinioPath, multipartFile, "");
//// }
// FileItem a = getMultipartFile(pngFile, fileName);
// MultipartFile multipartFile = new CommonsMultipartFile(a);
// System.out.println(url.substring(0,14));
// System.out.println(url.substring(15));
//// minioUtil.upload(url.substring(0,14), url.substring(15), multipartFile, "");
// sysFile.setCreateDate(new Date());
// }
public static List<File> getPNGFiles(String directoryPath) {
List<File> pngFiles = new ArrayList<>();
File directory = new File(directoryPath);
if (directory.isDirectory()) {
File[] subDirectories = directory.listFiles(File::isDirectory);
if (subDirectories != null) {
for (File subDirectory : subDirectories) {
File[] imageFiles = subDirectory.listFiles((dir, name) -> name.toLowerCase().endsWith(".png"));
if (imageFiles != null) {
for (File imageFile : imageFiles) {
pngFiles.add(imageFile);
}
}
}
}
}
return pngFiles;
}
private static FileItem getMultipartFile(File file, String fieldName){
// 使用 DiskFileItemFactory 创建一个 FileItemFactory
FileItemFactory factory = new DiskFileItemFactory(16, null);