design single 在用户submit时将上传的图片保存到library
This commit is contained in:
@@ -3,11 +3,14 @@ package com.ai.da.service.impl;
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.util.ObjectUtil;
|
||||
import com.ai.da.common.config.exception.BusinessException;
|
||||
import com.ai.da.common.constant.CommonConstant;
|
||||
import com.ai.da.common.context.UserContext;
|
||||
import com.ai.da.common.enums.CollectionLevel1TypeEnum;
|
||||
import com.ai.da.common.enums.SingleOverallEnum;
|
||||
import com.ai.da.common.enums.SysFileLevel2TypeEnum;
|
||||
import com.ai.da.common.utils.CopyUtil;
|
||||
import com.ai.da.common.utils.DateUtil;
|
||||
import com.ai.da.common.utils.MD5Utils;
|
||||
import com.ai.da.common.utils.MinioUtil;
|
||||
import com.ai.da.mapper.primary.DesignItemMapper;
|
||||
import com.ai.da.mapper.primary.entity.*;
|
||||
@@ -30,8 +33,10 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.io.IOException;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@@ -488,6 +493,8 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
// 更新及保存图层信息
|
||||
tDesignPythonOutfitDetails = saveDesignSingleItemDetailAndLayers(objects, design.getId(), designSingleIncludeLayersDTO.getDesignItemId(),
|
||||
userInfo, outfit, designSingleIncludeLayersDTO.getTimeZone(), designSingleIncludeLayersDTO.getDesignSingleItemDTOList());
|
||||
|
||||
saveCollectionElement(designSingleIncludeLayersDTO);
|
||||
} else {
|
||||
JSONArray layers = outfit.getJSONArray("layers");
|
||||
tDesignPythonOutfitDetails = setTDesignPythonOutfitDetailList(layers, designItem.getDesignId(), null, userInfo.getId(), priorityOffset);
|
||||
@@ -537,10 +544,6 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
log.error(layer.getImageCategory() + " layer does not exists!");
|
||||
throw new BusinessException("layers.does.not.exists");
|
||||
}
|
||||
// Assert.notNull(detail, layer.getImageCategory() + " layer does not exists!");
|
||||
|
||||
/*layer.setImageUrl(detail.getImageUrl());
|
||||
layer.setMaskUrl(detail.getMaskUrl());*/
|
||||
});
|
||||
|
||||
// 3、组装python入参
|
||||
@@ -621,15 +624,21 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
designSingleVO.setCurrentFullBodyView(minioUtil.getPresignedUrl(currentFullBodyView, 24 * 60));
|
||||
designSingleVO.setClothes(clothes);
|
||||
|
||||
// 获取每个单品的id是否被改变过,该状态需要再返回给前端
|
||||
Map<Long, Boolean> idChanged = designSingleItemDTOList.stream().collect(Collectors.toMap(DesignSingleItemDTO::getId, DesignSingleItemDTO::getChanged));
|
||||
// 获取每个单品的designType,该状态需要再返回给前端
|
||||
Map<Long, String> idDesignType = designSingleItemDTOList.stream().collect(Collectors.toMap(DesignSingleItemDTO::getId, DesignSingleItemDTO::getDesignType));
|
||||
|
||||
boolean flag = singleOrOverall.equals("single");
|
||||
designSingleItemDTOList.forEach(singleItem -> {
|
||||
DesignItemClothesDetailVO designItemClothesDetailVO = new DesignItemClothesDetailVO();
|
||||
designItemClothesDetailVO.setId(singleItem.getId());
|
||||
designItemClothesDetailVO.setChanged(idChanged.get(singleItem.getId()));
|
||||
designItemClothesDetailVO.setDesignType(idDesignType.get(singleItem.getId()));
|
||||
designItemClothesDetailVO.setType(singleItem.getType());
|
||||
designItemClothesDetailVO.setPath(minioUtil.getPresignedUrl(singleItem.getPath(), 24 * 60));
|
||||
designItemClothesDetailVO.setMinIOPath(singleItem.getPath());
|
||||
designItemClothesDetailVO.setColor(panToneService.getPantoneByRgb(singleItem.getColor()));
|
||||
// designItemClothesDetailVO.setPrintObject(new DesignPythonItemPrint(singleItem.getPrintObject().getPath()));
|
||||
designItemClothesDetailVO.setPrintObject(singleItem.getPrintObject());
|
||||
designItemClothesDetailVO.setLayersObject(layersObject.stream().filter(
|
||||
layers -> (singleItem.getType().toLowerCase().equals(layers.getImageCategory().split("_")[0])
|
||||
@@ -703,4 +712,68 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
||||
queryWrapper.in("id",designItemIdList);
|
||||
return designItemMapper.selectList(queryWrapper);
|
||||
}
|
||||
|
||||
private void saveCollectionElement(DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO){
|
||||
|
||||
ArrayList<Library> libraries = new ArrayList<>();
|
||||
// 添加sketch到library
|
||||
designSingleIncludeLayersDTO.getDesignSingleItemDTOList().forEach(designSingleItem -> {
|
||||
|
||||
if (!StringUtil.isNullOrEmpty(designSingleItem.getDesignType()) && designSingleItem.getDesignType().equals("Collection")){
|
||||
String path = minioUtil.getPresignedUrl(designSingleItem.getPath(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME);
|
||||
try {
|
||||
String md5 = MD5Utils.encryptFile(path, false);
|
||||
// 先判断是否需要被加入到library
|
||||
Boolean needAdd = libraryService.checkMd5(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName(),
|
||||
designSingleItem.getType(),
|
||||
designSingleIncludeLayersDTO.getGender(),
|
||||
md5);
|
||||
// 加入到library
|
||||
if (needAdd){
|
||||
Library library = new Library();
|
||||
library.setAccountId(UserContext.getUserHolder().getId());
|
||||
library.setLevel1Type(CollectionLevel1TypeEnum.SKETCH_BOARD.getRealName());
|
||||
library.setLevel2Type(designSingleItem.getType());
|
||||
library.setLevel3Type(designSingleIncludeLayersDTO.getGender());
|
||||
library.setUrl(designSingleItem.getPath());
|
||||
library.setName(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")));
|
||||
library.setMd5(md5);
|
||||
library.setCreateDate(DateUtil.getByTimeZone(designSingleIncludeLayersDTO.getTimeZone()));
|
||||
libraries.add(library);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// 添加print到library
|
||||
designSingleItem.getPrintObject().getPrints().forEach(print -> {
|
||||
if (!StringUtil.isNullOrEmpty(print.getDesignType()) && print.getDesignType().equals("Collection")){
|
||||
String path = minioUtil.getPresignedUrl(print.getMinIOPath(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME);
|
||||
try {
|
||||
String md5 = MD5Utils.encryptFile(path, false);
|
||||
// 先判断是否已被加入到library
|
||||
Boolean needAdd = libraryService.checkMd5(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName(),
|
||||
null,
|
||||
null,
|
||||
md5);
|
||||
// 加入到library
|
||||
if (needAdd){
|
||||
Library library = new Library();
|
||||
library.setAccountId(UserContext.getUserHolder().getId());
|
||||
library.setLevel1Type(CollectionLevel1TypeEnum.PRINT_BOARD.getRealName());
|
||||
library.setUrl(print.getMinIOPath());
|
||||
library.setName(LocalDate.now().format(DateTimeFormatter.ofPattern("yyyyMMdd")));
|
||||
library.setMd5(md5);
|
||||
library.setCreateDate(DateUtil.getByTimeZone(designSingleIncludeLayersDTO.getTimeZone()));
|
||||
libraries.add(library);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
} );
|
||||
libraryService.saveBatch(libraries);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,7 +409,8 @@ public class LibraryServiceImpl extends ServiceImpl<LibraryMapper, Library> impl
|
||||
qw.lambda().eq(Library::getLevel2Type, level2Type);
|
||||
qw.lambda().eq(Library::getLevel3Type, sex);
|
||||
} else {
|
||||
qw.lambda().eq(Library::getLevel2Type, sex);
|
||||
// qw.lambda().eq(Library::getLevel2Type, sex);
|
||||
qw.lambda().eq(Library::getLevel3Type, sex);
|
||||
}
|
||||
}
|
||||
qw.lambda().eq(Library::getMd5, md5);
|
||||
|
||||
Reference in New Issue
Block a user