Merge remote-tracking branch 'origin/dev_shb' into develop
# Conflicts: # src/main/java/com/ai/da/service/impl/DesignServiceImpl.java
This commit is contained in:
6
pom.xml
6
pom.xml
@@ -145,6 +145,12 @@
|
||||
<artifactId>minio</artifactId>
|
||||
<version>8.0.3</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-fileupload</groupId>
|
||||
<artifactId>commons-fileupload</artifactId>
|
||||
<version>1.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
||||
@@ -5,27 +5,19 @@ import cn.hutool.core.util.IdUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.model.vo.FileVO;
|
||||
import org.apache.tomcat.util.http.fileupload.FileUtils;
|
||||
import org.apache.tomcat.util.http.fileupload.IOUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.FileSystemUtils;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
import org.springframework.web.multipart.commons.CommonsMultipartFile;
|
||||
|
||||
import javax.imageio.ImageIO;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.awt.image.BufferedImage;
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.security.MessageDigest;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
//import org.apache.poi.util.IOUtils;
|
||||
//import org.apache.poi.xssf.streaming.SXSSFSheet;
|
||||
|
||||
public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(com.ai.da.common.utils.FileUtil.class);
|
||||
@@ -297,5 +289,20 @@ public class FileUtil extends cn.hutool.core.io.FileUtil {
|
||||
return files;
|
||||
}
|
||||
|
||||
// 判断文件是否存在
|
||||
public static boolean isFileExists(String filePath) {
|
||||
File file = new File(filePath);
|
||||
return file.exists() && file.isFile();
|
||||
}
|
||||
|
||||
// 根据路径获取文件
|
||||
public static File getFile(String filePath) {
|
||||
File file = new File(filePath);
|
||||
if (file.exists() && file.isFile()) {
|
||||
return file;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -172,6 +172,31 @@ public class MinioUtil {
|
||||
return fileName;
|
||||
}
|
||||
|
||||
// public String upload(String bucketName, String path, File file) {
|
||||
// InputStream in = null;
|
||||
// try {
|
||||
// in = new FileInputStream(file);
|
||||
// minioClient.putObject(PutObjectArgs.builder()
|
||||
// .bucket(bucketName)
|
||||
// .object(path)
|
||||
// .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();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return fileName;
|
||||
// }
|
||||
|
||||
/**
|
||||
* description: 下载文件
|
||||
*
|
||||
|
||||
@@ -143,6 +143,7 @@ public class LibraryController {
|
||||
String day = DateUtil.dateToStr(new Date(), DateUtil.YYYYMM);
|
||||
return rootPath + day + File.separator + "tmp" + File.separator + userId + File.separator+ UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
private String calculateTemplateUrl(File uploadFile){
|
||||
String linuxDomain = fileProperties.getLinuxDomain();
|
||||
if (!StringUtils.isEmpty(linuxDomain)) {
|
||||
|
||||
@@ -99,5 +99,13 @@ public class WorkspaceController {
|
||||
return Response.success(modelsVO);
|
||||
}
|
||||
|
||||
|
||||
@PostMapping("system_file_copy")
|
||||
@ApiOperationSupport(order = 7)
|
||||
@ApiOperation(value = "文件复制", notes = "传入id")
|
||||
public Response<Boolean> systemFileCopy() {
|
||||
workspaceService.systemFileCopy();
|
||||
return Response.success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -67,6 +67,8 @@ public class SysFile implements Serializable {
|
||||
*/
|
||||
private Date updateDate;
|
||||
|
||||
private Integer isCopy;
|
||||
|
||||
public SysFile() {
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,12 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||
public enum Position implements IEnumDisplay {
|
||||
|
||||
OVERALL("Overall"),
|
||||
SINGLE("Single")
|
||||
OUTWEAR("Outwear"),
|
||||
BLOUSE("Blouse"),
|
||||
DRESS("Dress"),
|
||||
TROUSERS("Trousers"),
|
||||
SKIRT("Skirt")
|
||||
// SINGLE("Single"),
|
||||
;
|
||||
|
||||
private String value;
|
||||
|
||||
@@ -9,8 +9,10 @@ import com.fasterxml.jackson.annotation.JsonValue;
|
||||
*/
|
||||
public enum Sex implements IEnumDisplay {
|
||||
|
||||
MALE("Male"),
|
||||
FEMALE("Female"),
|
||||
|
||||
MALE("Male"),
|
||||
|
||||
CHILD("Child")
|
||||
;
|
||||
|
||||
|
||||
@@ -18,4 +18,7 @@ public class UserLikeVO {
|
||||
private Long designItemId;
|
||||
@ApiModelProperty("图片路径")
|
||||
private String url;
|
||||
@ApiModelProperty("图片路径")
|
||||
private String designOutfitUrl;
|
||||
|
||||
}
|
||||
|
||||
@@ -38,4 +38,6 @@ public interface WorkspaceService extends IService<Workspace> {
|
||||
Workspace getByIdNew(Long id);
|
||||
|
||||
List<ModelsVO> getMannequins();
|
||||
|
||||
void systemFileCopy();
|
||||
}
|
||||
|
||||
@@ -5,9 +5,11 @@ import com.ai.da.common.config.FileProperties;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
||||
import com.ai.da.common.enums.SingleOverallEnum;
|
||||
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
|
||||
import com.ai.da.common.utils.*;
|
||||
import com.ai.da.mapper.DesignMapper;
|
||||
import com.ai.da.mapper.TDesignPythonOutfitMapper;
|
||||
import com.ai.da.mapper.entity.*;
|
||||
import com.ai.da.mapper.entity.Collection;
|
||||
import com.ai.da.model.dto.*;
|
||||
@@ -18,6 +20,7 @@ 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;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
@@ -25,12 +28,14 @@ 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;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.constraints.NotBlank;
|
||||
import java.io.File;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.*;
|
||||
@@ -82,6 +87,14 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
@Resource
|
||||
private DesignItemDetailPrintService designItemDetailPrintService;
|
||||
|
||||
@Resource
|
||||
private TDesignPythonOutfitMapper designPythonOutfitMapper;
|
||||
|
||||
@Value("${minio.endpoint}")
|
||||
private String endpoint;
|
||||
@Value("${minio.bucketName.results}")
|
||||
private String bucketName;
|
||||
|
||||
// @Transactional
|
||||
@Override
|
||||
public DesignCollectionVO designCollection(DesignCollectionDTO designDTO) {
|
||||
@@ -297,7 +310,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
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);
|
||||
return savePythonDesignItemAndDetail(pythonObjects, designId, collectionId, userInfo, designDTO.getTimeZone(), responseJSONObject, designDTO.getSingleOverall());
|
||||
//保存designItem 和detail
|
||||
// return saveDesignItemAndDetail(pythonObjects,designId,collectionId,userInfo,designDTO.getTimeZone());
|
||||
}
|
||||
@@ -401,7 +414,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
private MinioUtil minIoUtil;
|
||||
|
||||
private DesignCollectionVO savePythonDesignItemAndDetail(DesignPythonObjects pythonObjects
|
||||
, Long designId, Long collectionId, AuthPrincipalVo userInfo, String timeZone, JSONObject responseJSONObject) {
|
||||
, Long designId, Long collectionId, AuthPrincipalVo userInfo, String timeZone, JSONObject responseJSONObject, String singleOverall) {
|
||||
DesignCollectionVO response = new DesignCollectionVO();
|
||||
response.setDesignId(designId);
|
||||
response.setCollectionId(collectionId);
|
||||
@@ -433,11 +446,11 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
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<>();
|
||||
DesignCollectionItemVO designCollectionItemVO = new DesignCollectionItemVO();
|
||||
for (int i1 = 0; i1 < layers.size(); i1++) {
|
||||
JSONObject jsonObject = layers.getJSONObject(i1);
|
||||
TDesignPythonOutfitDetail designPythonOutfitDetail = new TDesignPythonOutfitDetail();
|
||||
@@ -470,13 +483,15 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
// }
|
||||
designPythonOutfitDetail.setImageSize(jsonObject.getString("image_size"));
|
||||
designPythonOutfitDetail.setImageUrl(jsonObject.getString("image_url"));
|
||||
if (singleOverall.equals(SingleOverallEnum.SINGLE.getRealName())) {
|
||||
designCollectionItemVO.setDesignItemUrl(designItem.getDesignUrl());
|
||||
}
|
||||
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());
|
||||
@@ -666,15 +681,28 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
|
||||
collectionElementService.relationCollection(newElementIds, userLikeGroup.getCollectionId());
|
||||
//处理关联关系,修复element覆盖得情况
|
||||
handleCollectionElementRelation(userLikeGroup.getCollectionId(), false, newElementIds);
|
||||
|
||||
QueryWrapper<TDesignPythonOutfit> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(TDesignPythonOutfit::getDesignItemId, designLikeDTO.getDesignItemId());
|
||||
List<TDesignPythonOutfit> tDesignPythonOutfits = designPythonOutfitMapper.selectList(qw);
|
||||
if (CollectionUtils.isEmpty(tDesignPythonOutfits)) {
|
||||
throw new BusinessException("DesignItemId not found elements for ax elements to like! ["+designLikeDTO.getDesignItemId());
|
||||
}
|
||||
UserLike userLike = resolveUserLike(designLikeDTO.getUserGroupId(), designItem.getDesignId(),
|
||||
designLikeDTO.getDesignItemId(), designItem.getDesignUrl(), designLikeDTO.getTimeZone());
|
||||
designLikeDTO.getDesignItemId(), tDesignPythonOutfits.get(0).getDesignUrl(), designLikeDTO.getTimeZone());
|
||||
userLikeService.save(userLike);
|
||||
groupDetailId = userLike.getId();
|
||||
} else {
|
||||
//第一次like
|
||||
userGroupId = userLikeGroupService.insertUserGroup(userInfo.getId(), designItem.getCollectionId(), designLikeDTO.getTimeZone());
|
||||
QueryWrapper<TDesignPythonOutfit> qw = new QueryWrapper<>();
|
||||
qw.lambda().eq(TDesignPythonOutfit::getDesignItemId, designLikeDTO.getDesignItemId());
|
||||
List<TDesignPythonOutfit> tDesignPythonOutfits = designPythonOutfitMapper.selectList(qw);
|
||||
if (CollectionUtils.isEmpty(tDesignPythonOutfits)) {
|
||||
throw new BusinessException("DesignItemId not found elements for ax elements to like! ["+designLikeDTO.getDesignItemId());
|
||||
}
|
||||
UserLike userLike = resolveUserLike(userGroupId,
|
||||
designItem.getDesignId(), designLikeDTO.getDesignItemId(), designItem.getDesignUrl(), designLikeDTO.getTimeZone());
|
||||
designItem.getDesignId(), designLikeDTO.getDesignItemId(), tDesignPythonOutfits.get(0).getDesignUrl(), designLikeDTO.getTimeZone());
|
||||
userLikeService.save(userLike);
|
||||
groupDetailId = userLike.getId();
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.ai.da.service.impl;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.mapper.UserLikeGroupMapper;
|
||||
import com.ai.da.mapper.entity.Account;
|
||||
import com.ai.da.mapper.entity.UserLikeGroup;
|
||||
@@ -40,6 +41,9 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
@Resource
|
||||
private UserLikeService userLikeService;
|
||||
|
||||
@Resource
|
||||
private MinioUtil minioUtil;
|
||||
|
||||
@Override
|
||||
public void deleteUserGroup(Long userGroupId) {
|
||||
UserLikeGroup group = getById(userGroupId);
|
||||
@@ -96,6 +100,11 @@ public class UserLikeGroupServiceImpl extends ServiceImpl<UserLikeGroupMapper, U
|
||||
UserLikeGroup group = getById(userGroupId);
|
||||
Assert.notNull(group,"History does not exist!");
|
||||
List<UserLikeVO> userLikeVOS = userLikeService.getGroupDetail(userGroupId);
|
||||
userLikeVOS.forEach(o -> {
|
||||
if (o.getUrl().startsWith("aida-")) {
|
||||
o.setDesignOutfitUrl(minioUtil.getPresignedUrl(o.getUrl(), 5));
|
||||
}
|
||||
});
|
||||
UserLikeCollectionVO userLikeCollection = collectionService.chooseCollection(group.getCollectionId());
|
||||
return new UserLikeChooseVO(userGroupId,userLikeVOS,userLikeCollection);
|
||||
}
|
||||
|
||||
@@ -41,12 +41,13 @@ public class UserLikeServiceImpl extends ServiceImpl<UserLikeMapper, UserLike> i
|
||||
if(CollectionUtils.isEmpty(userLikes)){
|
||||
return Lists.newArrayList();
|
||||
}
|
||||
List<Long> designItemIds = userLikes.stream().map(UserLike::getDesignItemId).collect(Collectors.toList());
|
||||
List<DesignItem> designItems = designItemService.listByIds(designItemIds);
|
||||
Map<Long,String> idToUrlMap = designItems.stream().collect(Collectors.toMap(DesignItem::getId,DesignItem::getDesignUrl));
|
||||
return CopyUtil.copyList(userLikes,UserLikeVO.class,(o,d) ->{
|
||||
d.setUrl(idToUrlMap.get(o.getDesignItemId()));
|
||||
});
|
||||
return CopyUtil.copyList(userLikes,UserLikeVO.class);
|
||||
// List<Long> designItemIds = userLikes.stream().map(UserLike::getDesignItemId).collect(Collectors.toList());
|
||||
// List<DesignItem> designItems = designItemService.listByIds(designItemIds);
|
||||
// Map<Long,String> idToUrlMap = designItems.stream().collect(Collectors.toMap(DesignItem::getId,DesignItem::getDesignUrl));
|
||||
// return CopyUtil.copyList(userLikes,UserLikeVO.class,(o,d) ->{
|
||||
// d.setUrl(idToUrlMap.get(o.getDesignItemId()));
|
||||
// });
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -6,6 +6,7 @@ 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.FileUtil;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.mapper.LibraryMapper;
|
||||
import com.ai.da.mapper.SysFileMapper;
|
||||
@@ -26,9 +27,19 @@ 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 org.apache.commons.fileupload.FileItem;
|
||||
import org.apache.commons.fileupload.FileItemFactory;
|
||||
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
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.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -216,6 +227,50 @@ public class WorkspaceServiceImpl extends ServiceImpl<WorkspaceMapper, Workspace
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void systemFileCopy() {
|
||||
QueryWrapper<SysFile> sysFileQueryWrapper = new QueryWrapper<>();
|
||||
List<SysFile> sysFiles = sysFileMapper.selectList(sysFileQueryWrapper);
|
||||
sysFiles.forEach(o -> {
|
||||
String url = o.getUrl();
|
||||
String[] downloads = url.split("/download/");
|
||||
if (downloads.length == 2) {
|
||||
String path = "/workspace/home/aida/file/" + downloads[1];
|
||||
File file = FileUtil.getFile("");
|
||||
if (file != null) {
|
||||
String uploadMinioPath = o.getLevel1Type().toLowerCase() + "/" + o.getLevel2Type().toLowerCase() + "/" + file.getName();
|
||||
String bucketName = "aida-sys-image";
|
||||
FileItem a = getMultipartFile(file, "A");
|
||||
MultipartFile multipartFile = new CommonsMultipartFile(a);
|
||||
minioUtil.upload(bucketName, uploadMinioPath, multipartFile);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private FileItem getMultipartFile(File file, String fieldName){
|
||||
// 使用 DiskFileItemFactory 创建一个 FileItemFactory
|
||||
FileItemFactory factory = new DiskFileItemFactory(16, null);
|
||||
|
||||
// 使用 FileItemFactory 创建一个 FileItem 对象
|
||||
FileItem item = factory.createItem(fieldName, "text/plain", true, file.getName());
|
||||
|
||||
byte[] buffer = new byte[8192];
|
||||
int bytesRead;
|
||||
|
||||
try (FileInputStream fis = new FileInputStream(file);
|
||||
OutputStream os = item.getOutputStream()) {
|
||||
// 从文件中读取数据并写入 FileItem
|
||||
while ((bytesRead = fis.read(buffer)) != -1) {
|
||||
os.write(buffer, 0, bytesRead);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return item;
|
||||
}
|
||||
|
||||
private List<BizJson> getEnumValues(Class clazz) {
|
||||
List<BizJson> kvs = new ArrayList<BizJson>();
|
||||
IEnumDisplay[] items = (IEnumDisplay[]) clazz.getEnumConstants();
|
||||
|
||||
Reference in New Issue
Block a user