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

@@ -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 {