designSingle 加入渐变色

This commit is contained in:
2024-05-13 16:23:37 +08:00
parent 718198bcfe
commit d1fab003d2
7 changed files with 51 additions and 43 deletions

View File

@@ -436,6 +436,13 @@ public class MinioUtil {
return false;
}
}
public String base64Upload(String base64, String bucketName){
String[] parts = base64.split(",");
String imageType = parts[0].split("/")[1].split(";")[0];
String base64Data = parts[1];
return uploadImageFromBase64(bucketName, base64Data, imageType);
}
}

View File

@@ -1,5 +1,6 @@
package com.ai.da.model.dto;
import com.ai.da.mapper.primary.entity.Gradient;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@@ -48,9 +49,7 @@ public class DesignSingleItemDTO {
@ApiModelProperty("图层优先级")
private Integer priority;
@ApiModelProperty("渐变 起始/目标 颜色")
private String gradient;
@ApiModelProperty("渐变 颜色")
private Gradient gradient;
@ApiModelProperty("渐变角度")
private Float gradient_angle;
}

View File

@@ -1,5 +1,6 @@
package com.ai.da.model.vo;
import com.ai.da.mapper.primary.entity.Gradient;
import com.ai.da.model.dto.DesignSinglePrintDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@@ -51,6 +52,9 @@ public class DesignItemClothesDetailVO {
@ApiModelProperty("衣服所在图层")
private Integer priority;
@ApiModelProperty("渐变色信息")
private Gradient gradient;
public DesignItemClothesDetailVO() {
}

View File

@@ -31,6 +31,7 @@ import com.alibaba.fastjson.serializer.SerializerFeature;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
@@ -67,10 +68,15 @@ public class PythonService {
private String accessPythonPort;
@Value("${access.python.sr}")
private String srPythonPort;
@Value("${minio.bucketName.gradient}")
private String gradientBucketName;
@Resource
private PythonTAllInfoService pythonTAllInfoService;
@Resource
private MinioUtil minioUtil;
/**
* 生成打印的图片 二合一 (废弃于2024/01/02)
*
@@ -2611,6 +2617,22 @@ public class PythonService {
}else {
businessId = designSingleItem.getId();
}
// 判断是否是渐变色
String minioPath = null;
String gradientString = null;
if (!Objects.isNull(designSingleItem.getGradient())){
String colorImg = designSingleItem.getGradient().getColorImg();
if (StringUtil.isNullOrEmpty(colorImg)){
throw new BusinessException("The base64 data of the image is empty");
}
minioPath = minioUtil.base64Upload(colorImg, gradientBucketName);
designSingleItem.getGradient().setColorImg(null);
gradientString = JSONObject.toJSONString(designSingleItem.getGradient());
// todo 当渐变色不为空时,是否需要将颜色置为 0 0 0
}
response.add(new DesignPythonItem(
designSingleItem.getType(),
designSingleItem.getPath(),
@@ -2622,7 +2644,9 @@ public class PythonService {
pythonTAllInfoService.getImageIdByPath(designSingleItem.getPath()),
designSingleItem.getOffset(),
designSingleItem.getScale(),
designSingleItem.getPriority()));
designSingleItem.getPriority(),
minioPath,
gradientString));
});

View File

@@ -78,10 +78,6 @@ public class DesignPythonItem {
*/
private Integer priority;
// private List<List<Integer>> gradient;
private Float gradient_angle;
public static List<String> OUTWEAR_DRESS_BLOUSE = Arrays.asList(CollectionLevel2TypeEnum.OUTWEAR.getRealName(),
CollectionLevel2TypeEnum.DRESS.getRealName(), CollectionLevel2TypeEnum.BLOUSE.getRealName());
@@ -117,7 +113,8 @@ public class DesignPythonItem {
this.image_id = image_id;
}
public DesignPythonItem(String type, String path, String color, DesignPythonItemPrint print, Long businessId, Long image_id, List<Long> offset, Float resize_scale,Integer priority) {
public DesignPythonItem(String type, String path, String color, DesignPythonItemPrint print, Long businessId,
Long image_id, List<Long> offset, Float resize_scale, Integer priority, String gradient, String gradientString) {
this.type = type;
this.path = path;
this.color = color;
@@ -128,23 +125,10 @@ public class DesignPythonItem {
this.offset = offset;
this.resize_scale = resize_scale;
this.priority = priority;
this.gradient = gradient;
this.gradientString = gradientString;
}
// public DesignPythonItem(String type, String path, String color, DesignPythonItemPrint print, Long businessId, Long image_id, List<Long> offset, Float resize_scale,Integer priority) {
// this.type = type;
// this.path = path;
// this.color = color;
// this.print = print;
//// this.icon = icon;
// this.businessId = businessId;
// this.image_id = image_id;
// this.offset = offset;
// this.resize_scale = resize_scale;
// this.priority = priority;
//// this.gradient = gradient;
//// this.gradient_angle = gradient_angle;
// }
public DesignPythonItem(String type, String path, String color, DesignPythonItemPrint print, String icon, Long businessId, Long image_id) {
this.type = type;
this.path = path;

View File

@@ -309,7 +309,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
}
private List<TDesignPythonOutfitDetail> saveDesignSingleItemDetailAndLayers(DesignPythonObjects pythonObjects
, Long designId, Long designItemId, AuthPrincipalVo userInfo
, Long designId, Long designItemId, Long userId
, JSONObject outfit, String timeZone, List<DesignSingleItemDTO> designSingleItemDTOList) {
DesignItem designItem = new DesignItem();
@@ -328,7 +328,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
return;
}
DesignItemDetail designItemDetail = CopyUtil.copyObject(detail, DesignItemDetail.class);
designItemDetail.setAccountId(userInfo.getId());
designItemDetail.setAccountId(userId);
designItemDetail.setDesignId(designId);
designItemDetail.setDesignItemId(designItemId);
designItemDetail.setCollectionElementId(detail.getElementId());
@@ -367,12 +367,9 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
// 7、将新生成的图层信息存入designPythonOutfitDetail表
JSONArray layers = outfit.getJSONArray("layers");
// 需要将request中的offset也存入数据库通过priority与image_category将sketch与layers关联
// Map<String, List<Long>> typeOffset = designSingleItemDTOList.stream()
// .collect(Collectors.toMap(d -> d.getType().toLowerCase(), DesignSingleItemDTO::getOffset));
Map<Integer, List<Long>> priorityOffset = designSingleItemDTOList.stream()
.collect(Collectors.toMap(DesignSingleItemDTO::getPriority, DesignSingleItemDTO::getOffset));
List<TDesignPythonOutfitDetail> list = setTDesignPythonOutfitDetailList(layers, designId, designPythonOutfit.getId(), userInfo.getId(), priorityOffset);
List<TDesignPythonOutfitDetail> list = setTDesignPythonOutfitDetailList(layers, designId, designPythonOutfit.getId(), userId, priorityOffset);
designPythonOutfitDetailService.saveBatch(list);
@@ -420,7 +417,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
public DesignSingleVO designSingleIncludeLayers(DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO) {
log.info("designSingle request入参 ==> " + designSingleIncludeLayersDTO.toString());
AuthPrincipalVo userInfo = UserContext.getUserHolder();
Long userId = UserContext.getUserHolder().getId();
DesignItem designItem = selectById(designSingleIncludeLayersDTO.getDesignItemId());
if (Objects.isNull(designItem)) {
throw new BusinessException("designItem.not.found");
@@ -477,8 +474,6 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
}
JSONObject outfit = data.getJSONObject("0");
// 通过priority将offset关联到layers
// Map<String, List<Long>> typeOffset = designSingleIncludeLayersDTO.getDesignSingleItemDTOList().stream()
// .collect(Collectors.toMap(d -> d.getType().toLowerCase(), DesignSingleItemDTO::getOffset));
Map<Integer, List<Long>> priorityOffset = new HashMap<>();
try{
priorityOffset = designSingleIncludeLayersDTO.getDesignSingleItemDTOList().stream()
@@ -492,12 +487,12 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
if (!designSingleIncludeLayersDTO.getIsPreview()) {
// 更新及保存图层信息
tDesignPythonOutfitDetails = saveDesignSingleItemDetailAndLayers(objects, design.getId(), designSingleIncludeLayersDTO.getDesignItemId(),
userInfo, outfit, designSingleIncludeLayersDTO.getTimeZone(), designSingleIncludeLayersDTO.getDesignSingleItemDTOList());
userId, outfit, designSingleIncludeLayersDTO.getTimeZone(), designSingleIncludeLayersDTO.getDesignSingleItemDTOList());
saveCollectionElement(designSingleIncludeLayersDTO);
} else {
JSONArray layers = outfit.getJSONArray("layers");
tDesignPythonOutfitDetails = setTDesignPythonOutfitDetailList(layers, designItem.getDesignId(), null, userInfo.getId(), priorityOffset);
tDesignPythonOutfitDetails = setTDesignPythonOutfitDetailList(layers, designItem.getDesignId(), null, userId, priorityOffset);
}
List<DesignPythonOutfitVO> detailsVO = new ArrayList<>();
@@ -644,6 +639,7 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
layers -> (singleItem.getType().toLowerCase().equals(layers.getImageCategory().split("_")[0])
&& (flag ? Boolean.TRUE : singleItem.getPriority().equals(layers.getPriority())))
).collect(Collectors.toList()));
designItemClothesDetailVO.setGradient(singleItem.getGradient());
body.setLayersObject(layersObject.stream().filter(layers -> layers.getImageCategory().equals("body")).collect(Collectors.toList()));
clothes.add(designItemClothesDetailVO);

View File

@@ -993,6 +993,7 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
d.setPath(minioUtil.getPresignedUrl(o.getPath(), 24 * 60));
d.setMinIOPath(o.getPath());
d.setLevel1Type(converTypeToLevel1(o.getType()));
d.setGradient(JSONObject.parseObject(o.getGradientString(), Gradient.class));
// 根据designItemDetailId获取印花
List<DesignItemDetailPrint> prints = designItemDetailPrintService.getByDesignItemDetailId(o.getId());
// 判断有无印花
@@ -1000,13 +1001,6 @@ public class DesignServiceImpl extends ServiceImpl<DesignMapper, Design> impleme
// 有印花
d.setPrintObject(convertToDesignSinglePrintDTO(prints));
}
// String printJson = o.getPrintJson();
// if (StringUtils.isEmpty(printJson)) {
// d.setPrintObject(new DesignPythonItemPrint(o.getPrintPath(),
// CollectionLevel1TypeEnum.PRINT_BOARD.getRealName(), 0.3f, Boolean.FALSE));
// } else {
// d.setPrintObject(JSON.parseObject(printJson, DesignPythonItemPrint.class));
// }
}));
//single 和 Models(模特)时候 系统元素为空
List<DesignItemDetail> filterDetail2 = designItemDetails.stream()