design Single 允许画笔修改sketch后进行design
This commit is contained in:
@@ -8,6 +8,8 @@ import io.minio.http.Method;
|
|||||||
import io.minio.messages.DeleteError;
|
import io.minio.messages.DeleteError;
|
||||||
import io.minio.messages.DeleteObject;
|
import io.minio.messages.DeleteObject;
|
||||||
import io.minio.messages.Item;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
@@ -26,6 +28,7 @@ import java.util.stream.Collectors;
|
|||||||
* @description: minio工具类
|
* @description: minio工具类
|
||||||
* @version:3.0
|
* @version:3.0
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
@Component
|
@Component
|
||||||
public class MinioUtil {
|
public class MinioUtil {
|
||||||
@Autowired
|
@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[] parts = base64.split(",");
|
||||||
String imageType = parts[0].split("/")[1].split(";")[0];
|
String imageType = parts[0].split("/")[1].split(";")[0];
|
||||||
String base64Data = parts[1];
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class DesignSingleItemDTO implements Serializable {
|
|||||||
private String designType;
|
private String designType;
|
||||||
|
|
||||||
@NotBlank(message = "type.cannot.be.empty")
|
@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;
|
private String type;
|
||||||
|
|
||||||
@ApiModelProperty("对应的图片的minIO路径")
|
@ApiModelProperty("对应的图片的minIO路径")
|
||||||
@@ -53,4 +53,7 @@ public class DesignSingleItemDTO implements Serializable {
|
|||||||
@ApiModelProperty("渐变 颜色")
|
@ApiModelProperty("渐变 颜色")
|
||||||
private Gradient gradient;
|
private Gradient gradient;
|
||||||
|
|
||||||
|
@ApiModelProperty("画笔修改过的sketch图片的base64格式的数据")
|
||||||
|
private String sketchString;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ public class GenerateLikeDTO {
|
|||||||
@ApiModelProperty("一级类型 Sketchboard Printboard")
|
@ApiModelProperty("一级类型 Sketchboard Printboard")
|
||||||
private String level1Type;
|
private String level1Type;
|
||||||
|
|
||||||
@ApiModelProperty("当一级类型为Sketchboard时,二级类型 Outwear Dress Blouse Skirt Trousers")
|
@ApiModelProperty("当一级类型为Sketchboard时,二级类型 Outwear Dress Blouse Skirt Trousers;当一级类型为Printboard时,二级类型 Slogan Logo Pattern")
|
||||||
private String level2Type;
|
private String level2Type;
|
||||||
|
|
||||||
@ApiModelProperty("性别")
|
@ApiModelProperty("性别")
|
||||||
|
|||||||
@@ -2626,7 +2626,7 @@ public class PythonService {
|
|||||||
if (StringUtil.isNullOrEmpty(colorImg)){
|
if (StringUtil.isNullOrEmpty(colorImg)){
|
||||||
throw new BusinessException("The base64 data of the image is empty");
|
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);
|
designSingleItem.getGradient().setColorImg(null);
|
||||||
gradientString = JSONObject.toJSONString(designSingleItem.getGradient());
|
gradientString = JSONObject.toJSONString(designSingleItem.getGradient());
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import com.google.common.collect.Lists;
|
|||||||
import io.netty.util.internal.StringUtil;
|
import io.netty.util.internal.StringUtil;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.apache.commons.lang3.SerializationUtils;
|
import org.apache.commons.lang3.SerializationUtils;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
@@ -81,6 +82,9 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
|||||||
@Resource
|
@Resource
|
||||||
private UserLikeGroupService userLikeGroupService;
|
private UserLikeGroupService userLikeGroupService;
|
||||||
|
|
||||||
|
@Value("${minio.bucketName.modifiedSketch}")
|
||||||
|
private String modifiedSketchBucket;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long saveOne(DesignItem designItem) {
|
public Long saveOne(DesignItem designItem) {
|
||||||
if (designItemMapper.insertDesignItem(designItem) <= 0) {
|
if (designItemMapper.insertDesignItem(designItem) <= 0) {
|
||||||
@@ -419,9 +423,16 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
|||||||
// 记录入参 base64数据太长,所以这里去掉
|
// 记录入参 base64数据太长,所以这里去掉
|
||||||
DesignSingleIncludeLayersDTO clone = SerializationUtils.clone(designSingleIncludeLayersDTO);
|
DesignSingleIncludeLayersDTO clone = SerializationUtils.clone(designSingleIncludeLayersDTO);
|
||||||
clone.getDesignSingleItemDTOList().forEach( i -> {
|
clone.getDesignSingleItemDTOList().forEach( i -> {
|
||||||
|
// 渐变色
|
||||||
if (!Objects.isNull(i.getGradient()) && !StringUtil.isNullOrEmpty(i.getGradient().getColorImg())){
|
if (!Objects.isNull(i.getGradient()) && !StringUtil.isNullOrEmpty(i.getGradient().getColorImg())){
|
||||||
|
log.info("set gradient colorImage为空,便于日志打印");
|
||||||
i.getGradient().setColorImg(null);
|
i.getGradient().setColorImg(null);
|
||||||
}
|
}
|
||||||
|
// 画笔修改过的sketch
|
||||||
|
if (!StringUtil.isNullOrEmpty(i.getSketchString())){
|
||||||
|
log.info("set sketchString为空,便于日志打印");
|
||||||
|
i.setSketchString(null);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
log.info("designSingle request入参 ==> " + JSONObject.toJSONString(clone));
|
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);
|
designLibraryModelPointVO = collectionElementService.calculateTemplatePoint(modelPoint, high, width, modelUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 画笔修改的sketch截图 上传后替换path
|
||||||
|
// 由于用户在系统或自己上传sketch的基础上修改过的衣服,再次修改后,第一次修改的衣服不会回到某个池子被再次利用,
|
||||||
|
// 所以,这里选择使用system或collection相同的地址,只是放在不同的桶,这样能保证图片服务器上,类似的sketch不会存在很多
|
||||||
|
sketchBase64ToPath(designSingleIncludeLayersDTO);
|
||||||
|
|
||||||
// 组装入参
|
// 组装入参
|
||||||
DesignPythonObjects objects = pythonService.covertDesignSingleParam(
|
DesignPythonObjects objects = pythonService.covertDesignSingleParam(
|
||||||
designSingleIncludeLayersDTO, design.getSingleOverall(), design.getSwitchCategory(), designLibraryModelPointVO);
|
designSingleIncludeLayersDTO, design.getSingleOverall(), design.getSwitchCategory(), designLibraryModelPointVO);
|
||||||
@@ -527,6 +543,26 @@ public class DesignItemServiceImpl extends ServiceImpl<DesignItemMapper, DesignI
|
|||||||
design.getSingleOverall());
|
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
|
@Override
|
||||||
@Transactional(rollbackFor = Exception.class)
|
@Transactional(rollbackFor = Exception.class)
|
||||||
public ComposeLayersVO editLayersPositionAndScale(EditLayersPositionAndScaleVO positionAndScaleVO) throws IOException {
|
public ComposeLayersVO editLayersPositionAndScale(EditLayersPositionAndScaleVO positionAndScaleVO) throws IOException {
|
||||||
|
|||||||
@@ -134,6 +134,7 @@ priority.cannot.be.repeated=priority cannot be repeated.
|
|||||||
model.not.found=model not found.
|
model.not.found=model not found.
|
||||||
libraryIdList.cannot.be.empty=libraryIdList cannot be empty.
|
libraryIdList.cannot.be.empty=libraryIdList cannot be empty.
|
||||||
the.value.range.of.seed=The value range of seed is 0-99999
|
the.value.range.of.seed=The value range of seed is 0-99999
|
||||||
|
image.modify.failed=Image modification failed, please try again later.
|
||||||
|
|
||||||
# 可能会报异常
|
# 可能会报异常
|
||||||
# Informative:
|
# Informative:
|
||||||
|
|||||||
Reference in New Issue
Block a user