Merge remote-tracking branch 'origin/dev_shb' into dev-xp

# Conflicts:
#	src/main/java/com/ai/da/model/vo/DesignPythonOutfitVO.java
#	src/main/java/com/ai/da/python/PythonService.java
#	src/main/java/com/ai/da/service/impl/TDesignPythonOutfitDetailServiceImpl.java
This commit is contained in:
xupei
2023-09-14 14:19:34 +08:00
36 changed files with 777 additions and 192 deletions

View File

@@ -0,0 +1,33 @@
package com.ai.da.common.config;
import io.minio.MinioClient;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
@Data
@Component
public class MinIoClientConfig {
@Value("${minio.endpoint}")
private String endpoint;
@Value("${minio.accessKey}")
private String accessKey;
@Value("${minio.secretKey}")
private String secretKey;
/**
* 注入minio 客户端
* @return
*/
@Bean
public MinioClient minioClient(){
return MinioClient.builder()
.endpoint(endpoint)
.credentials(accessKey, secretKey)
.build();
}
}

View File

@@ -0,0 +1,216 @@
package com.ai.da.common.utils;
import com.ai.da.mapper.entity.ObjectItem;
import io.minio.*;
import io.minio.messages.DeleteError;
import io.minio.messages.DeleteObject;
import io.minio.messages.Item;
import org.apache.tomcat.util.http.fileupload.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
/**
* @description minio工具类
* @version3.0
*/
@Component
public class MinioUtil {
@Autowired
private MinioClient minioClient;
@Value("${minio.bucketName}")
private String bucketName;
/**
* description: 判断bucket是否存在不存在则创建
*
* @return: void
*/
public void existBucket(String name) {
try {
boolean exists = minioClient.bucketExists(BucketExistsArgs.builder().bucket(name).build());
if (!exists) {
minioClient.makeBucket(MakeBucketArgs.builder().bucket(name).build());
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 创建存储bucket
* @param bucketName 存储bucket名称
* @return Boolean
*/
public Boolean makeBucket(String bucketName) {
try {
minioClient.makeBucket(MakeBucketArgs.builder()
.bucket(bucketName)
.build());
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* 删除存储bucket
* @param bucketName 存储bucket名称
* @return Boolean
*/
public Boolean removeBucket(String bucketName) {
try {
minioClient.removeBucket(RemoveBucketArgs.builder()
.bucket(bucketName)
.build());
} catch (Exception e) {
e.printStackTrace();
return false;
}
return true;
}
/**
* description: 上传文件
*
* @param multipartFile
* @return: java.lang.String
*/
public List<String> upload(MultipartFile[] multipartFile) {
List<String> names = new ArrayList<>(multipartFile.length);
for (MultipartFile file : multipartFile) {
String fileName = file.getOriginalFilename();
String[] split = fileName.split("\\.");
if (split.length > 1) {
fileName = split[0] + "_" + System.currentTimeMillis() + "." + split[1];
} else {
fileName = fileName + System.currentTimeMillis();
}
InputStream in = null;
try {
in = file.getInputStream();
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName)
.object(fileName)
.stream(in, in.available(), -1)
.contentType(file.getContentType())
.build()
);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
names.add(fileName);
}
return names;
}
/**
* description: 下载文件
*
* @param fileName
* @return: org.springframework.http.ResponseEntity<byte [ ]>
*/
public ResponseEntity<byte[]> download(String fileName) {
ResponseEntity<byte[]> responseEntity = null;
InputStream in = null;
ByteArrayOutputStream out = null;
try {
in = minioClient.getObject(GetObjectArgs.builder().bucket(bucketName).object(fileName).build());
out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
//封装返回值
byte[] bytes = out.toByteArray();
HttpHeaders headers = new HttpHeaders();
try {
headers.add("Content-Disposition", "attachment;filename=" + URLEncoder.encode(fileName, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
headers.setContentLength(bytes.length);
headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
headers.setAccessControlExposeHeaders(Arrays.asList("*"));
responseEntity = new ResponseEntity<byte[]>(bytes, headers, HttpStatus.OK);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (out != null) {
out.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
return responseEntity;
}
/**
* 查看文件对象
* @param bucketName 存储bucket名称
* @return 存储bucket内文件对象信息
*/
public List<ObjectItem> listObjects(String bucketName) {
Iterable<Result<Item>> results = minioClient.listObjects(
ListObjectsArgs.builder().bucket(bucketName).build());
List<ObjectItem> objectItems = new ArrayList<>();
try {
for (Result<Item> result : results) {
Item item = result.get();
ObjectItem objectItem = new ObjectItem();
objectItem.setObjectName(item.objectName());
objectItem.setSize(item.size());
objectItems.add(objectItem);
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return objectItems;
}
/**
* 批量删除文件对象
* @param bucketName 存储bucket名称
* @param objects 对象名称集合
*/
public Iterable<Result<DeleteError>> removeObjects(String bucketName, List<String> objects) {
List<DeleteObject> dos = objects.stream().map(e -> new DeleteObject(e)).collect(Collectors.toList());
Iterable<Result<DeleteError>> results = minioClient.removeObjects(RemoveObjectsArgs.builder().bucket(bucketName).objects(dos).build());
return results;
}
}

View File

@@ -27,7 +27,7 @@ public class DesignController {
@ApiOperation(value = "设计 Conllection")
@PostMapping("/designCollection")
public Response<JSONObject> designCollection(@Valid @RequestBody DesignCollectionDTO designDTO) {
public Response<DesignCollectionVO> designCollection(@Valid @RequestBody DesignCollectionDTO designDTO) {
return Response.success(designService.designCollection(designDTO));
}

View File

@@ -1,25 +1,12 @@
package com.ai.da.controller;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.common.response.Response;
import com.ai.da.common.utils.CopyUtil;
import com.ai.da.mapper.entity.Account;
import com.ai.da.mapper.entity.UserLikeGroup;
import com.ai.da.common.utils.MinioUtil;
import com.ai.da.mapper.entity.Workspace;
import com.ai.da.model.dto.QueryHistoryPageDTO;
import com.ai.da.model.dto.WorkspaceDTO;
import com.ai.da.model.enums.BizJson;
import com.ai.da.model.vo.AuthPrincipalVo;
import com.ai.da.model.vo.UserLikeGroupVO;
import com.ai.da.model.vo.UserLikeVO;
import com.ai.da.model.vo.WorkspaceVO;
import com.ai.da.service.WorkspaceService;
import com.baomidou.mybatisplus.core.conditions.query.Query;
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.google.common.base.Function;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
@@ -27,19 +14,12 @@ import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import org.springframework.web.multipart.MultipartFile;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
/**
* 控制器
@@ -56,6 +36,23 @@ public class WorkspaceController {
@Resource
private WorkspaceService workspaceService;
@Resource
private MinioUtil minIoUtil;
@Value("${minio.endpoint}")
private static String address;
@Value("${minio.bucketName}")
private static String bucketName;
@PostMapping("/upload")
public Object upload(MultipartFile file) {
List<String> upload = minIoUtil.upload(new MultipartFile[]{file});
return address+"/"+bucketName+"/"+upload.get(0);
}
/**
* 详情
*/
@@ -63,19 +60,19 @@ public class WorkspaceController {
@ApiOperationSupport(order = 1)
@ApiOperation(value = "详情", notes = "传入workspace")
public Response<Workspace> detail(@ApiParam(value = "主键集合", required = true) @RequestParam Long id) {
Workspace detail = workspaceService.getById(id);
Workspace detail = workspaceService.getByIdNew(id);
return Response.success(detail);
}
/**
* 分页
*/
@GetMapping("/list")
@PostMapping("/list")
@ApiOperationSupport(order = 2)
@ApiOperation(value = "分页", notes = "传入workspace")
public Response<PageBaseResponse<Workspace>> list(@Valid @RequestBody WorkspaceDTO query) {
IPage<Workspace> convert = workspaceService.getPage(query);
return Response.success(PageBaseResponse.success(convert));
public Response<WorkspaceVO> list(@Valid @RequestBody WorkspaceDTO query) {
WorkspaceVO response = workspaceService.getPage(query);
return Response.success(response);
}
/**

View File

@@ -0,0 +1,19 @@
package com.ai.da.mapper;
import com.ai.da.common.config.mybatis.plus.CommonMapper;
import com.ai.da.mapper.entity.PythonTAllInfo;
import org.apache.ibatis.annotations.Param;
import org.springframework.data.domain.Pageable;
import java.util.List;
/**
* (PythonTAllInfo)表数据库访问层
*
* @author SHAHAIBO
* @since 2023-09-08 17:05:24
*/
public interface PythonTAllInfoMapper extends CommonMapper<PythonTAllInfo> {
}

View File

@@ -0,0 +1,10 @@
package com.ai.da.mapper.entity;
import lombok.Data;
@Data
public class ObjectItem {
private String objectName;
private Long size;
}

View File

@@ -0,0 +1,86 @@
package com.ai.da.mapper.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import java.io.Serializable;
/**
* (PythonTAllInfo)实体类
*
* @author SHAHAIBO
* @since 2023-09-08 17:05:25
*/
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@TableName("python_t_all_info")
public class PythonTAllInfo implements Serializable {
private static final long serialVersionUID = 1L;
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private String imagePath;
private String imageCategory;
private String necklineLeft;
private String necklineRight;
private String centerFront;
private String shoulderLeft;
private String shoulderRight;
private String armpitLeft;
private String armpitRight;
private String waistlineLeft;
private String waistlineRight;
private String cuffLeftIn;
private String cuffLeftOut;
private String cuffRightIn;
private String cuffRightOut;
private String topHemLeft;
private String topHemRight;
private String waistbandLeft;
private String waistbandRight;
private String hemlineLeft;
private String hemlineRight;
private String crotch;
private String bottomLeftIn;
private String bottomLeftOut;
private String bottomRightIn;
private String bottomRightOut;
private String md5;
private String maskPath;
private String segResultPath;
}

View File

@@ -31,6 +31,11 @@ public class TDesignPythonOutfit implements Serializable {
@TableId(value = "id", type = IdType.AUTO)
private Long id;
private Long designItemId;
/**
* designItemId
*/
@ApiModelProperty(value = "designItemId")
private Long designItemId;
/**
* 关联的design ID

View File

@@ -53,6 +53,11 @@ public class TDesignPythonOutfitDetail implements Serializable {
@ApiModelProperty(value = "图层大小")
private String imageSize;
/**
* imageSize
*/
@ApiModelProperty(value = "imageSize")
private String imageSize;
/**
* 对应的图片的绝对路径
*/

View File

@@ -62,6 +62,11 @@ public class Workspace implements Serializable {
*/
@ApiModelProperty(value = "人体模型")
private String mannequin;
/**
* 最后使用的工作空间标识
*/
@ApiModelProperty(value = "最后使用的工作空间标识")
private Integer isLastIndex;
/**
* 创建时间
*/

View File

@@ -9,7 +9,7 @@ import lombok.EqualsAndHashCode;
/**
* 数据传输对象实体类
*
* @author Arcana
* @author SHAHAIBO
* @since 2023-08-01
*/
@Data

View File

@@ -9,8 +9,8 @@ import com.fasterxml.jackson.annotation.JsonValue;
*/
public enum Position implements IEnumDisplay {
OVERALL("整体"),
SINGLE("部位")
OVERALL("overall"),
SINGLE("single")
;
private String value;

View File

@@ -9,9 +9,9 @@ import com.fasterxml.jackson.annotation.JsonValue;
*/
public enum Sex implements IEnumDisplay {
MALE("男装"),
FEMALE("女装"),
CHILD("童装")
MALE("male"),
FEMALE("female"),
CHILD("child")
;
private String value;

View File

@@ -16,6 +16,13 @@ public class DesignCollectionItemVO {
@ApiModelProperty("design生成的图片地址 绝对路径")
private String designItemUrl;
@ApiModelProperty("t_design_python_outfit id")
private Long designOutfitId;
@ApiModelProperty("t_design_python_outfit id")
private String designOutfitUrl;
public DesignCollectionItemVO() {
}
}

View File

@@ -9,7 +9,7 @@ import io.swagger.annotations.ApiModel;
/**
* design item详情表视图实体类
*
* @author Arcana
* @author SHAHAIBO
* @since 2023-09-04
*/
@Data

View File

@@ -10,7 +10,7 @@ import io.swagger.annotations.ApiModel;
/**
* design item表 存对应design的8张图片视图实体类
*
* @author Arcana
* @author SHAHAIBO
* @since 2023-09-04
*/
@Data

View File

@@ -1,6 +1,7 @@
package com.ai.da.model.vo;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.mapper.entity.Workspace;
import lombok.Data;
import lombok.EqualsAndHashCode;
@@ -9,13 +10,18 @@ import io.swagger.annotations.ApiModel;
/**
* 视图实体类
*
* @author Arcana
* @author SHAHAIBO
* @since 2023-08-01
*/
@Data
@EqualsAndHashCode(callSuper = true)
@ApiModel(value = "WorkspaceVO对象", description = "WorkspaceVO对象")
public class WorkspaceVO extends Workspace {
private static final long serialVersionUID = 1L;
private Long currentId;
private PageBaseResponse<Workspace> page;
}

File diff suppressed because one or more lines are too long

View File

@@ -52,6 +52,10 @@ public class DesignPythonItem {
* body 对应路径(后面去掉)
*/
private String body_mask_path;
/**
* python_t_all_info image_id
*/
private Long imageId;
/**
* url在t_sys_file中的id

View File

@@ -22,7 +22,7 @@ public interface DesignService extends IService<Design> {
* @param designDTO
* @return
*/
JSONObject designCollection(DesignCollectionDTO designDTO);
DesignCollectionVO designCollection(DesignCollectionDTO designDTO);
/**
* redesign

View File

@@ -12,7 +12,7 @@ import java.util.List;
/**
* design item详情表 服务类
*
* @author Arcana
* @author SHAHAIBO
* @since 2023-09-04
*/
public interface ITDesignPythonOutfitDetailService extends IService<TDesignPythonOutfitDetail> {

View File

@@ -8,7 +8,7 @@ import com.baomidou.mybatisplus.core.metadata.IPage;
/**
* design item表 存对应design的8张图片 服务类
*
* @author Arcana
* @author SHAHAIBO
* @since 2023-09-04
*/
public interface ITDesignPythonOutfitService extends IService<TDesignPythonOutfit> {

View File

@@ -0,0 +1,18 @@
package com.ai.da.service;
import com.ai.da.mapper.entity.PythonTAllInfo;
import com.baomidou.mybatisplus.extension.service.IService;
/**
* (PythonTAllInfo)表服务接口
*
* @author SHAHAIBO
* @since 2023-09-08 17:03:47
*/
public interface PythonTAllInfoService extends IService<PythonTAllInfo> {
Long getImageIdByPath(String path);
}

View File

@@ -14,7 +14,7 @@ import java.util.List;
/**
* 服务类
*
* @author Arcana
* @author SHAHAIBO
* @since 2023-08-01
*/
public interface WorkspaceService extends IService<Workspace> {
@@ -30,7 +30,9 @@ public interface WorkspaceService extends IService<Workspace> {
boolean saveOrUpdate(Workspace workspace);
IPage<Workspace> getPage(WorkspaceDTO query);
WorkspaceVO getPage(WorkspaceDTO query);
List<BizJson> getEnumValues(String enumName);
Workspace getByIdNew(Long id);
}

View File

@@ -337,33 +337,34 @@ public class CollectionElementServiceImpl extends ServiceImpl<CollectionElementM
}
}
//校验marketingSketch
if (CollectionUtil.isNotEmpty(designDTO.getMarketingSketchs())) {
//校验designType
validateDesignType(designDTO.getMarketingSketchs(),"marketingSketchs");
List<Long> printBoardIds = designDTO.getMarketingSketchs().stream()
.filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
.map(DesignCollectionElementDTO::getId)
.collect(Collectors.toList());
if(!CollectionUtils.isEmpty(printBoardIds)){
List<CollectionElement> marketingSketchElements = collectionElementMapper.selectBatchIds(printBoardIds);
Assert.isTrue(CollectionUtil.isNotEmpty(marketingSketchElements)
&& marketingSketchElements.size() == printBoardIds.size(), "get marketingSketch data is mismatch");
elementVO.setMarketingSketchElements(marketingSketchElements);
usedElementIds.addAll(printBoardIds);
}
//library
List<Long> libraryIds = designDTO.getMarketingSketchs().stream()
.filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
.map(DesignCollectionElementDTO::getId)
.collect(Collectors.toList());
if(!CollectionUtils.isEmpty(libraryIds)){
List<Library> librarys = libraryService.getByIds(libraryIds);
//不校验了防止用户在library删除 对应不上
if(CollectionUtil.isNotEmpty(librarys)){
libraryCollectionElements.addAll(covertLibrarysToCollections(librarys,null));
}
}
}
// 2023.12版本去掉了这个入参
// if (CollectionUtil.isNotEmpty(designDTO.getMarketingSketchs())) {
// //校验designType
// validateDesignType(designDTO.getMarketingSketchs(),"marketingSketchs");
// List<Long> printBoardIds = designDTO.getMarketingSketchs().stream()
// .filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName()))
// .map(DesignCollectionElementDTO::getId)
// .collect(Collectors.toList());
// if(!CollectionUtils.isEmpty(printBoardIds)){
// List<CollectionElement> marketingSketchElements = collectionElementMapper.selectBatchIds(printBoardIds);
// Assert.isTrue(CollectionUtil.isNotEmpty(marketingSketchElements)
// && marketingSketchElements.size() == printBoardIds.size(), "get marketingSketch data is mismatch");
// elementVO.setMarketingSketchElements(marketingSketchElements);
// usedElementIds.addAll(printBoardIds);
// }
// //library
// List<Long> libraryIds = designDTO.getMarketingSketchs().stream()
// .filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName()))
// .map(DesignCollectionElementDTO::getId)
// .collect(Collectors.toList());
// if(!CollectionUtils.isEmpty(libraryIds)){
// List<Library> librarys = libraryService.getByIds(libraryIds);
// //不校验了防止用户在library删除 对应不上
// if(CollectionUtil.isNotEmpty(librarys)){
// libraryCollectionElements.addAll(covertLibrarysToCollections(librarys,null));
// }
// }
// }
//校验控制生成类型
SingleOverallEnum singleOverall = SingleOverallEnum.of(designDTO.getSingleOverall());
Assert.notNull(singleOverall, "unknown parameter singleOverall!");

View File

@@ -16,7 +16,9 @@ import com.ai.da.mapper.entity.Collection;
import com.ai.da.model.dto.*;
import com.ai.da.model.vo.*;
import com.ai.da.python.PythonService;
import com.ai.da.python.vo.DesignPythonItem;
import com.ai.da.python.vo.DesignPythonItemPrint;
import com.ai.da.python.vo.DesignPythonObject;
import com.ai.da.python.vo.DesignPythonObjects;
import com.ai.da.service.*;
import com.alibaba.fastjson.JSON;
@@ -27,6 +29,7 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.google.common.collect.Lists;
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.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -36,6 +39,7 @@ import javax.annotation.Resource;
import java.io.File;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.stream.Collectors;
import static com.ai.da.python.vo.DesignPythonItem.*;
@@ -79,10 +83,16 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
private ITDesignPythonOutfitDetailService designPythonOutfitDetailService;
@Resource
private PanToneService panToneService;
@Resource
private PythonTAllInfoService pythonTAllInfoService;
@Value("${minio.endpoint}")
private String endpoint;
@Value("${minio.bucketName}")
private String bucketName;
// @Transactional
@Override
public JSONObject designCollection(DesignCollectionDTO designDTO) {
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
AuthPrincipalVo userInfo = UserContext.getUserHolder();
//校验collection element
ValidateElementVO elementVO =collectionElementService.validateElement(designDTO);
@@ -180,12 +190,12 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
//计算library
calculateLibraryAndSysFile(designDTO,elementVO,userInfo);
//组装design入参
DesignPythonObjects pythonObjects =pythonService.covertDesignParam(designDTO.getSystemScale(),
DesignPythonObjects pythonObjects = pythonService.covertDesignParam(designDTO.getSystemScale(),
designDTO.getSingleOverall(),designDTO.getSwitchCategory(),elementVO);
//缓存保存的文件 方便后面处理进度问题
setDesignProcess(userInfo.getId(),pythonObjects);
//design
JSONObject responseJSONObject= pythonService.designNew(pythonObjects);
pythonService.design(pythonObjects);
//生成library
generateLibrary(elementVO,designDTO.getTimeZone());
//处理关联关系,修复element覆盖得情况
@@ -198,7 +208,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
}
private JSONObject designOrRedesignOperateNew(DesignCollectionDTO designDTO,AuthPrincipalVo userInfo,
private DesignCollectionVO designOrRedesignOperateNew(DesignCollectionDTO designDTO,AuthPrincipalVo userInfo,
Long collectionIdParam,ValidateElementVO elementVO){
if(CollectionUtil.isNotEmpty(designDTO.getSketchBoards())){
//编辑sketchBoard
@@ -211,7 +221,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
//保存collection
Long collectionId = (null == collectionIdParam) ?
collectionService.saveCollection(userInfo.getId(),designDTO.getTimeZone(),designDTO.getMoodTemplateId()) : collectionIdParam;
List<Long> elementIds =getElementId(elementVO);
List<Long> elementIds = getElementId(elementVO);
//批量关联element 到 collection
collectionElementService.relationCollection(elementIds,collectionId);
//library转化为collection(生成)
@@ -227,8 +237,10 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
designDTO.getSingleOverall(),designDTO.getSwitchCategory(),elementVO);
//缓存保存的文件 方便后面处理进度问题
setDesignProcess(userInfo.getId(),pythonObjects);
// pythonObjects增加image_id关联
relationImageId(pythonObjects);
//design
JSONObject responseJSONObject= pythonService.designNew(pythonObjects);
JSONObject responseJSONObject = pythonService.designNew(pythonObjects);
//生成library
generateLibrary(elementVO,designDTO.getTimeZone());
//处理关联关系,修复element覆盖得情况
@@ -240,6 +252,28 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
//保存designItem 和detail
// return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
}
private void relationImageId(DesignPythonObjects pythonObjects) {
if(Objects.isNull(pythonObjects)) {
return;
}
pythonObjects.getObjects().forEach(
o -> {
for (DesignPythonItem item : o.getItems()) {
String path = item.getPath();
if (StringUtils.isEmpty(path)) {
String bodyPath = item.getBody_path();
Long imageId = pythonTAllInfoService.getImageIdByPath(bodyPath);
item.setImageId(imageId);
}else {
Long imageId = pythonTAllInfoService.getImageIdByPath(path);
item.setImageId(imageId);
}
}
}
);
}
private void handleCollectionElementRelation(Long collectionId ,Boolean isEdit,List<Long> elementIds ){
if (CollectionUtils.isEmpty(elementIds) || collectionId == null){
return;
@@ -310,15 +344,16 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
return object.getBasic().getSave_name();}).collect(Collectors.toList());
LocalCacheUtils.setDesignProcessCache(userId,saveNames);
}
private JSONObject savePythonDesignItemAndDetail(DesignPythonObjects pythonObjects
private DesignCollectionVO savePythonDesignItemAndDetail(DesignPythonObjects pythonObjects
,Long designId,Long collectionId,AuthPrincipalVo userInfo,String timeZone, JSONObject responseJSONObject){
DesignCollectionVO response = new DesignCollectionVO();
response.setDesignId(designId);
response.setCollectionId(collectionId);
List<DesignCollectionItemVO> designCollectionItems = Lists.newArrayList();
response.setDesignCollectionItems(designCollectionItems);
pythonObjects.getObjects().forEach(item ->{
JSONObject data = responseJSONObject.getJSONObject("data");
for (int i = 0; i < pythonObjects.getObjects().size(); i++) {
DesignPythonObject item = pythonObjects.getObjects().get(i);
DesignItem designItem = new DesignItem();
designItem.setAccountId(userInfo.getId());
designItem.setCollectionId(collectionId);
@@ -329,8 +364,63 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
designItem.setHasLike((byte)0);
//生成designItem
Long designItemId = designItemService.saveOne(designItem);
// python design返回入库及封装
JSONObject outfit = data.getJSONObject(i + "");
if (null == outfit) {
continue;
}
TDesignPythonOutfit designPythonOutfit = new TDesignPythonOutfit();
designPythonOutfit.setDesignItemId(designItemId);
designPythonOutfit.setUserId(userInfo.getId());
designPythonOutfit.setDesignId(designId);
designPythonOutfit.setCollectionId(collectionId);
designPythonOutfit.setDesignUrl(outfit.getString("synthesis_url"));
designPythonOutfitService.save(designPythonOutfit);
JSONArray layers = outfit.getJSONArray("layers");
List<TDesignPythonOutfitDetail> list = new ArrayList<>();
for (int i1 = 0; i1 < layers.size(); i1++) {
JSONObject jsonObject = layers.getJSONObject(i1);
TDesignPythonOutfitDetail designPythonOutfitDetail = new TDesignPythonOutfitDetail();
designPythonOutfitDetail.setDesignId(designId);
designPythonOutfitDetail.setDesignPythonOutfitId(designPythonOutfit.getId());
JSONArray position = jsonObject.getJSONArray("position");
if (position != null && !CollectionUtils.isEmpty(position)) {
StringBuilder builder = null;
for (int i2 = 0; i2 < position.size(); i2++) {
if (i2 != position.size() - 1) {
builder.append(position.getInteger(i2)).append(",");
}else {
builder.append(position.getInteger(i2));
}
}
designPythonOutfitDetail.setPosition(builder.toString());
}
JSONArray imageSize = jsonObject.getJSONArray("image_size");
if (imageSize != null && !CollectionUtils.isEmpty(position)) {
StringBuilder builder = null;
for (int i2 = 0; i2 < imageSize.size(); i2++) {
if (i2 != imageSize.size() - 1) {
builder.append(imageSize.getInteger(i2)).append(",");
}else {
builder.append(imageSize.getInteger(i2));
}
}
designPythonOutfitDetail.setImageSize(builder.toString());
}
designPythonOutfitDetail.setImageUrl(jsonObject.getString("image_url"));
designPythonOutfitDetail.setImageCategory(jsonObject.getString("image_category"));
designPythonOutfitDetail.setMaskUrl(jsonObject.getString("mask_url"));
designPythonOutfitDetail.setUserId(userInfo.getId());
list.add(designPythonOutfitDetail);
}
designPythonOutfitDetailService.saveBatch(list);
DesignCollectionItemVO designCollectionItemVO = new DesignCollectionItemVO();
designCollectionItemVO.setDesignItemId(designItemId);
designCollectionItemVO.setDesignItemUrl(designItem.getDesignUrl());
designCollectionItemVO.setDesignOutfitId(designPythonOutfit.getId());
designCollectionItemVO.setDesignOutfitUrl(endpoint + "/" + bucketName + "/" + designPythonOutfit.getDesignUrl());
//response
designCollectionItems.add(new DesignCollectionItemVO(designItemId,designItem.getDesignUrl()));
designCollectionItems.add(designCollectionItemVO);
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
item.getItems().forEach(detail ->{
@@ -354,33 +444,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
designItemDetails.add(designItemDetail);
});
designItemDetailService.saveBatch(designItemDetails);
});
JSONObject data = responseJSONObject.getJSONObject("data");
for (int i = 0; i < 8; i++) {
JSONObject outfit = data.getJSONObject(i + "");
TDesignPythonOutfit designPythonOutfit = new TDesignPythonOutfit();
designPythonOutfit.setUserId(userInfo.getId());
designPythonOutfit.setDesignId(designId);
designPythonOutfit.setCollectionId(collectionId);
designPythonOutfit.setDesignUrl(outfit.getString("synthesis_url"));
designPythonOutfitService.save(designPythonOutfit);
JSONArray layers = outfit.getJSONArray("layers");
List<TDesignPythonOutfitDetail> list = new ArrayList<>();
for (int i1 = 0; i1 < layers.size(); i1++) {
JSONObject jsonObject = layers.getJSONObject(i1);
TDesignPythonOutfitDetail designPythonOutfitDetail = new TDesignPythonOutfitDetail();
designPythonOutfitDetail.setDesignId(designId);
designPythonOutfitDetail.setDesignPythonOutfitId(designPythonOutfit.getId());
designPythonOutfitDetail.setPosition(jsonObject.getString("position"));
designPythonOutfitDetail.setImageUrl(jsonObject.getString("image_url"));
designPythonOutfitDetail.setImageCategory(jsonObject.getString("image_category"));
designPythonOutfitDetail.setMaskUrl(jsonObject.getString("mask_url"));
designPythonOutfitDetail.setUserId(userInfo.getId());
list.add(designPythonOutfitDetail);
}
designPythonOutfitDetailService.saveBatch(list);
}
return responseJSONObject;
return response;
}
private DesignCollectionVO saveDesignItemAndDetail(DesignPythonObjects pythonObjects
@@ -403,7 +469,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
//生成designItem
Long designItemId = designItemService.saveOne(designItem);
//response
designCollectionItems.add(new DesignCollectionItemVO(designItemId,designItem.getDesignUrl()));
designCollectionItems.add(new DesignCollectionItemVO(designItemId,designItem.getDesignUrl(), null, null));
List<DesignItemDetail> designItemDetails = Lists.newArrayList();
item.getItems().forEach(detail ->{
@@ -432,6 +498,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
}
private List<Long> getElementId(ValidateElementVO elementVO){
List<Long> elementIds = Lists.newArrayList();
// collection type
if(CollectionUtil.isNotEmpty(elementVO.getSketchBoardElements())){
elementIds.addAll(elementVO.getSketchBoardElements().stream().map(CollectionElement::getId).collect(Collectors.toList()));
}
@@ -441,9 +508,9 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
if(CollectionUtil.isNotEmpty(elementVO.getPrintBoardElements())){
elementIds.addAll(elementVO.getPrintBoardElements().stream().map(CollectionElement::getId).collect(Collectors.toList()));
}
if(CollectionUtil.isNotEmpty(elementVO.getMarketingSketchElements())){
elementIds.addAll(elementVO.getMarketingSketchElements().stream().map(CollectionElement::getId).collect(Collectors.toList()));
}
// if(CollectionUtil.isNotEmpty(elementVO.getMarketingSketchElements())){
// elementIds.addAll(elementVO.getMarketingSketchElements().stream().map(CollectionElement::getId).collect(Collectors.toList()));
// }
return elementIds;
}
@@ -499,7 +566,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
private List<DesignCollectionItemVO> coverDesignItemToVO( List<DesignItem> designItems){
List<DesignCollectionItemVO> response = Lists.newArrayList();
designItems.forEach(designItem -> {
response.add(new DesignCollectionItemVO(designItem.getId(),designItem.getDesignUrl()));
response.add(new DesignCollectionItemVO(designItem.getId(),designItem.getDesignUrl(), null, null));
});
return response;
}

View File

@@ -122,8 +122,8 @@ public class PanToneServiceImpl extends ServiceImpl<PanToneMapper, PanTone> impl
@Override
public List<PantoneVO> getRgbByHsvBatch(List<GetRgbByHsvBatchDTO> hsvBatch) {
if(hsvBatch.size() >15){
throw new BusinessException("hsv value cannot exceed the maximum of 15");
if(hsvBatch.size() >8){
throw new BusinessException("hsv value cannot exceed the maximum of 8");
}
List<Integer> colorValues = Lists.newArrayList();
Map<Integer,GetRgbByHsvBatchDTO> valueToHsv = Maps.newHashMap();

View File

@@ -0,0 +1,51 @@
package com.ai.da.service.impl;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.mapper.PythonTAllInfoMapper;
import com.ai.da.mapper.entity.PythonTAllInfo;
import com.ai.da.service.PythonTAllInfoService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.List;
/**
* (PythonTAllInfo)表服务实现类
*
* @author SHAHAIBO
* @since 2023-09-08 17:03:47
*/
@Service
@Slf4j
public class PythonTAllInfoServiceImpl extends ServiceImpl<PythonTAllInfoMapper, PythonTAllInfo> implements PythonTAllInfoService {
@Resource
private PythonTAllInfoMapper pythonTAllInfoMapper;
@Override
public Long getImageIdByPath(String path) {
if (StringUtils.isEmpty(path)) {
throw new BusinessException("path不能为空");
}
QueryWrapper<PythonTAllInfo> qw = new QueryWrapper<>();
qw.lambda().eq(PythonTAllInfo::getImagePath, path);
qw.lambda().last("limit 1");
List<PythonTAllInfo> pythonTAllInfos = pythonTAllInfoMapper.selectList(qw);
if (!CollectionUtils.isEmpty(pythonTAllInfos)) {
return pythonTAllInfos.get(0).getId();
}
PythonTAllInfo pythonTAllInfo = new PythonTAllInfo();
pythonTAllInfo.setImagePath(path);
int insert = pythonTAllInfoMapper.insert(pythonTAllInfo);
if (insert != 1) {
throw new BusinessException("插入失败");
}
return pythonTAllInfo.getId();
}
}

View File

@@ -38,6 +38,15 @@ public class TDesignPythonOutfitDetailServiceImpl extends ServiceImpl<TDesignPyt
}
@Override
public DesignPythonOutfitVO convertToDesignPythonOutfitVO(TDesignPythonOutfitDetail detail){
if (Objects.isNull(detail)) {
return null;
}
return CopyUtil.copyObject(detail,DesignPythonOutfitVO.class);
}
@Override
public DesignPythonOutfitVO convertToDesignPythonOutfitVO(TDesignPythonOutfitDetail detail){
if (Objects.isNull(detail)) {
return null;

View File

@@ -1,12 +1,16 @@
package com.ai.da.service.impl;
import com.ai.da.common.config.exception.BusinessException;
import com.ai.da.common.context.UserContext;
import com.ai.da.common.response.PageBaseResponse;
import com.ai.da.mapper.WorkspaceMapper;
import com.ai.da.mapper.entity.Account;
import com.ai.da.mapper.entity.Workspace;
import com.ai.da.model.dto.WorkspaceDTO;
import com.ai.da.model.enums.BizJson;
import com.ai.da.model.enums.IEnumDisplay;
import com.ai.da.model.enums.Position;
import com.ai.da.model.enums.Sex;
import com.ai.da.model.vo.AuthPrincipalVo;
import com.ai.da.model.vo.WorkspaceVO;
import com.ai.da.service.WorkspaceService;
@@ -29,7 +33,7 @@ import java.util.List;
/**
* 服务实现类
*
* @author Arcana
* @author SHAHAIBO
* @since 2023-08-01
*/
@Service
@@ -47,20 +51,61 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
public boolean saveOrUpdate(Workspace workspace) {
AuthPrincipalVo userInfo = UserContext.getUserHolder();
workspace.setUserName(userInfo.getUsername());
workspace.setIsLastIndex(0);
if (null == workspace.getId()) {
return workspaceMapper.insert(workspace) == 1;
int insert = workspaceMapper.insert(workspace);
if (insert <= 0) {
throw new BusinessException("insert workspace failed");
}
return true;
}else {
return workspaceMapper.updateById(workspace) == 1;
int update = workspaceMapper.updateById(workspace);
if (update <= 0) {
throw new BusinessException("update workspace failed");
}
return true;
}
}
private final static String WORKSPACE_NAME = "默认workspace名称";
private final static Integer SYSTEM_DESIGNER_PERCENTAGE = 30;
@Override
public IPage<Workspace> getPage(WorkspaceDTO query) {
public WorkspaceVO getPage(WorkspaceDTO query) {
WorkspaceVO vo = new WorkspaceVO();
String userName = UserContext.getUserHolder().getUsername();
QueryWrapper<Workspace> qw = new QueryWrapper<>();
qw.lambda().eq(Workspace::getUserName, userName);
IPage<Workspace> page = workspaceMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw);
return page;
if (page.getTotal() == 0L) {
// 给用户新建默认workspace
Workspace workspace = new Workspace();
workspace.setWorkSpaceName(WORKSPACE_NAME);
workspace.setSex(Sex.MALE.getValue());
workspace.setSystemDesignerPercentage(SYSTEM_DESIGNER_PERCENTAGE);
workspace.setPosition(Position.OVERALL.getValue());
workspace.setUserName(userName);
workspace.setIsLastIndex(1);
int insert = workspaceMapper.insert(workspace);
if (insert <= 0) {
throw new BusinessException("save workspace failed");
}
page = workspaceMapper.selectPage(new Page<>(query.getPage(), query.getSize()), qw);
vo.setPage(PageBaseResponse.success(page));
vo.setId(workspace.getId());
return vo;
}
vo.setPage(PageBaseResponse.success(page));
QueryWrapper<Workspace> qwIsLastIndex = new QueryWrapper<>();
qwIsLastIndex.lambda().eq(Workspace::getUserName, userName);
qwIsLastIndex.lambda().eq(Workspace::getIsLastIndex, 1);
qwIsLastIndex.last("limit 1");
List<Workspace> workspaces = workspaceMapper.selectList(qwIsLastIndex);
if (CollectionUtils.isEmpty(workspaces)) {
throw new BusinessException("用户工作空间未查询到最后使用标识");
}
vo.setId(workspaces.get(0).getId());
return vo;
}
@Override
@@ -74,6 +119,21 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
return getEnumValues(clazz);
}
@Override
public Workspace getByIdNew(Long id) {
String userName = UserContext.getUserHolder().getUsername();
QueryWrapper<Workspace> qwOld = new QueryWrapper<>();
qwOld.lambda().eq(Workspace::getUserName, userName);
qwOld.lambda().eq(Workspace::getIsLastIndex, 1);
Workspace oldIsLastIndex = workspaceMapper.selectOne(qwOld);
oldIsLastIndex.setIsLastIndex(0);
workspaceMapper.updateById(oldIsLastIndex);
Workspace newIsLastIndex= workspaceMapper.selectById(id);
newIsLastIndex.setIsLastIndex(1);
workspaceMapper.updateById(newIsLastIndex);
return newIsLastIndex;
}
private List<BizJson> getEnumValues(Class clazz) {
List<BizJson> kvs = new ArrayList<BizJson>();
IEnumDisplay[] items = (IEnumDisplay[]) clazz.getEnumConstants();

View File

@@ -31,7 +31,8 @@ file.mac.path=~/file/
file.linux.path=/workspace/home/aida/file/
#linux服务器域名(预览和下载用)
#file.linuxDomain=http://18.162.111.141:5568/download/
file.linuxDomain=http://18.167.251.121:5568/download/
#file.linuxDomain=http://18.167.251.121:5568/download/
file.linuxDomain=https://www.aida.com.hk/download/
file.windows.path=D:\\upload\\
spring.servlet.multipart.max-file-size = 5MB

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.ai.da.mapper.PythonTAllInfoMapper">
<resultMap type="com.ai.da.mapper.entity.PythonTAllInfo" id="PythonTAllInfoMap">
<id column="id" property="id"/>
<result property="imagePath" column="image_path"/>
<result property="imageCategory" column="image_category"/>
<result property="necklineLeft" column="neckline_left"/>
<result property="necklineRight" column="neckline_right"/>
<result property="centerFront" column="center_front"/>
<result property="shoulderLeft" column="shoulder_left"/>
<result property="shoulderRight" column="shoulder_right"/>
<result property="armpitLeft" column="armpit_left"/>
<result property="armpitRight" column="armpit_right"/>
<result property="waistlineLeft" column="waistline_left"/>
<result property="waistlineRight" column="waistline_right"/>
<result property="cuffLeftIn" column="cuff_left_in"/>
<result property="cuffLeftOut" column="cuff_left_out"/>
<result property="cuffRightIn" column="cuff_right_in"/>
<result property="cuffRightOut" column="cuff_right_out"/>
<result property="topHemLeft" column="top_hem_left"/>
<result property="topHemRight" column="top_hem_right"/>
<result property="waistbandLeft" column="waistband_left"/>
<result property="waistbandRight" column="waistband_right"/>
<result property="hemlineLeft" column="hemline_left"/>
<result property="hemlineRight" column="hemline_right"/>
<result property="crotch" column="crotch"/>
<result property="bottomLeftIn" column="bottom_left_in"/>
<result property="bottomLeftOut" column="bottom_left_out"/>
<result property="bottomRightIn" column="bottom_right_in"/>
<result property="bottomRightOut" column="bottom_right_out"/>
<result property="md5" column="md5"/>
<result property="maskPath" column="mask_path"/>
<result property="segResultPath" column="seg_result_path"/>
</resultMap>
</mapper>

View File

@@ -13,6 +13,7 @@
<result column="image_url" property="imageUrl"/>
<result column="mask_url" property="maskUrl"/>
<result column="position" property="position"/>
<result column="imageSize" property="image_size"/>
<result column="user_id" property="userId"/>
<result column="create_date" property="createDate"/>
<result column="update_date" property="updateDate"/>

View File

@@ -5,6 +5,7 @@
<!-- 通用查询映射结果 -->
<resultMap id="tDesignPythonOutfitResultMap" type="com.ai.da.mapper.entity.TDesignPythonOutfit">
<id column="id" property="id"/>
<result column="design_item_id" property="designItemId"/>
<result column="design_id" property="designId"/>
<result column="collection_id" property="collectionId"/>
<result column="design_url" property="designUrl"/>