design Single 允许画笔修改sketch后进行design

This commit is contained in:
2024-06-05 11:43:35 +08:00
parent 891f6fb15f
commit 954f6207ec
6 changed files with 70 additions and 5 deletions

View File

@@ -8,6 +8,8 @@ import io.minio.http.Method;
import io.minio.messages.DeleteError;
import io.minio.messages.DeleteObject;
import io.minio.messages.Item;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
@@ -26,6 +28,7 @@ import java.util.stream.Collectors;
* @description minio工具类
* @version3.0
*/
@Slf4j
@Component
public class MinioUtil {
@Autowired
@@ -437,11 +440,33 @@ public class MinioUtil {
}
}
public String base64Upload(String base64, String bucketName){
public String base64UploadToPath(String base64, String bucketName, String path){
String[] parts = base64.split(",");
String imageType = parts[0].split("/")[1].split(";")[0];
String base64Data = parts[1];
return uploadImageFromBase64(bucketName, base64Data, imageType);
byte[] imageBytes = Base64.getDecoder().decode(base64Data);
String fileName;
if (!StringUtil.isNullOrEmpty(path)){
fileName = path + "." + imageType; // or any other image format
}else {
fileName = UUID.randomUUID() + "." + imageType;
}
try (InputStream in = new ByteArrayInputStream(imageBytes)) {
minioClient.putObject(PutObjectArgs.builder()
.bucket(bucketName)
.object(fileName)
.stream(in, in.available(), -1)
.contentType("image/" + imageType) // Set the content type according to your image format
.build()
);
return bucketName + "/" + fileName;
} catch (Exception e) {
log.error(e.getMessage());
return null; // or throw an exception
}
}
}

View File

@@ -26,7 +26,7 @@ public class DesignSingleItemDTO implements Serializable {
private String designType;
@NotBlank(message = "type.cannot.be.empty")
@ApiModelProperty("生成item实际对应的类型 有:outwear,dress,blouse,skirt,trousers Shoes Hairstyle Earring")
@ApiModelProperty("生成item实际对应的类型 有:Outwear,Dress,Blouse,Skirt,Trousers Shoes Hairstyle Earring")
private String type;
@ApiModelProperty("对应的图片的minIO路径")
@@ -53,4 +53,7 @@ public class DesignSingleItemDTO implements Serializable {
@ApiModelProperty("渐变 颜色")
private Gradient gradient;
@ApiModelProperty("画笔修改过的sketch图片的base64格式的数据")
private String sketchString;
}

View File

@@ -19,7 +19,7 @@ public class GenerateLikeDTO {
@ApiModelProperty("一级类型 Sketchboard Printboard")
private String level1Type;
@ApiModelProperty("当一级类型为Sketchboard时二级类型 Outwear Dress Blouse Skirt Trousers")
@ApiModelProperty("当一级类型为Sketchboard时二级类型 Outwear Dress Blouse Skirt Trousers当一级类型为Printboard时二级类型 Slogan Logo Pattern")
private String level2Type;
@ApiModelProperty("性别")

View File

@@ -2626,7 +2626,7 @@ public class PythonService {
if (StringUtil.isNullOrEmpty(colorImg)){
throw new BusinessException("The base64 data of the image is empty");
}
minioPath = minioUtil.base64Upload(colorImg, gradientBucketName);
minioPath = minioUtil.base64UploadToPath(colorImg, gradientBucketName,null);
designSingleItem.getGradient().setColorImg(null);
gradientString = JSONObject.toJSONString(designSingleItem.getGradient());

View File

@@ -29,6 +29,7 @@ import com.google.common.collect.Lists;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.SerializationUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -81,6 +82,9 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
@Resource
private UserLikeGroupService userLikeGroupService;
@Value("${minio.bucketName.modifiedSketch}")
private String modifiedSketchBucket;
@Override
public Long saveOne(DesignItem designItem) {
if (designItemMapper.insertDesignItem(designItem) <= 0) {
@@ -419,9 +423,16 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
// 记录入参 base64数据太长所以这里去掉
DesignSingleIncludeLayersDTO clone = SerializationUtils.clone(designSingleIncludeLayersDTO);
clone.getDesignSingleItemDTOList().forEach( i -> {
// 渐变色
if (!Objects.isNull(i.getGradient()) && !StringUtil.isNullOrEmpty(i.getGradient().getColorImg())){
log.info("set gradient colorImage为空便于日志打印");
i.getGradient().setColorImg(null);
}
// 画笔修改过的sketch
if (!StringUtil.isNullOrEmpty(i.getSketchString())){
log.info("set sketchString为空便于日志打印");
i.setSketchString(null);
}
});
log.info("designSingle request入参 ==> " + JSONObject.toJSONString(clone));
@@ -470,6 +481,11 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
designLibraryModelPointVO = collectionElementService.calculateTemplatePoint(modelPoint, high, width, modelUrl);
}
// 画笔修改的sketch截图 上传后替换path
// 由于用户在系统或自己上传sketch的基础上修改过的衣服再次修改后第一次修改的衣服不会回到某个池子被再次利用
// 所以这里选择使用system或collection相同的地址只是放在不同的桶这样能保证图片服务器上,类似的sketch不会存在很多
sketchBase64ToPath(designSingleIncludeLayersDTO);
// 组装入参
DesignPythonObjects objects = pythonService.covertDesignSingleParam(
designSingleIncludeLayersDTO, design.getSingleOverall(), design.getSwitchCategory(), designLibraryModelPointVO);
@@ -527,6 +543,26 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
design.getSingleOverall());
}
private void sketchBase64ToPath(DesignSingleIncludeLayersDTO designSingleIncludeLayersDTO){
designSingleIncludeLayersDTO.getDesignSingleItemDTOList().forEach(item -> {
// 如果sketch截图不为空则将该截图上传并替换path
if (!StringUtil.isNullOrEmpty(item.getSketchString())){
if (StringUtil.isNullOrEmpty(item.getPath())){
throw new BusinessException("path.cannot.be.empty");
}
String sourcePath = item.getPath();
String path = sourcePath.substring(sourcePath.indexOf("/") + 1, sourcePath.lastIndexOf("."));
// 将原图地址作为修改后的图片地址,放在不同的桶
String newPath = minioUtil.base64UploadToPath(item.getSketchString(), modifiedSketchBucket, path);
if (StringUtil.isNullOrEmpty(newPath)){
log.error("修改过的sketch图片上传失败");
throw new BusinessException("image.modify.failed");
}
item.setPath(newPath);
}
});
}
@Override
@Transactional(rollbackFor = Exception.class)
public ComposeLayersVO editLayersPositionAndScale(EditLayersPositionAndScaleVO positionAndScaleVO) throws IOException {