diff --git a/src/main/java/com/ai/da/common/utils/MinioUtil.java b/src/main/java/com/ai/da/common/utils/MinioUtil.java index 9341e3ea..300d68d3 100644 --- a/src/main/java/com/ai/da/common/utils/MinioUtil.java +++ b/src/main/java/com/ai/da/common/utils/MinioUtil.java @@ -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工具类 * @version:3.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 + } } } diff --git a/src/main/java/com/ai/da/model/dto/DesignSingleItemDTO.java b/src/main/java/com/ai/da/model/dto/DesignSingleItemDTO.java index 0716bf86..d5a0e94e 100644 --- a/src/main/java/com/ai/da/model/dto/DesignSingleItemDTO.java +++ b/src/main/java/com/ai/da/model/dto/DesignSingleItemDTO.java @@ -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; + } diff --git a/src/main/java/com/ai/da/model/dto/GenerateLikeDTO.java b/src/main/java/com/ai/da/model/dto/GenerateLikeDTO.java index 69b37038..58734272 100644 --- a/src/main/java/com/ai/da/model/dto/GenerateLikeDTO.java +++ b/src/main/java/com/ai/da/model/dto/GenerateLikeDTO.java @@ -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("性别") diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index 3610c7c2..f68a9d51 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -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()); diff --git a/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java b/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java index afb5d07e..d2349f5e 100644 --- a/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/DesignItemServiceImpl.java @@ -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 { + // 渐变色 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 { + // 如果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 { diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index b2ea358f..ac3becbc 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -134,6 +134,7 @@ priority.cannot.be.repeated=priority cannot be repeated. model.not.found=model not found. libraryIdList.cannot.be.empty=libraryIdList cannot be empty. the.value.range.of.seed=The value range of seed is 0-99999 +image.modify.failed=Image modification failed, please try again later. # 可能会报异常 # Informative: