BUGFIX: sketch拼贴

This commit is contained in:
2025-03-27 17:46:09 +08:00
parent 20b15c0b78
commit 3df4433381

View File

@@ -24,6 +24,7 @@ import io.minio.errors.MinioException;
import io.netty.util.internal.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -1115,6 +1116,8 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
*/
@Transactional(rollbackFor = Exception.class)
public GenerateResultVO sketchReconstructionGenerate(SketchReconstructionDTO sketchReconstructionDTO){
log.info("sketchReconstructionGenerate params: {}", sketchReconstructionDTO);
Long accountId = UserContext.getUserHolder().getId();
// 1、线稿生成
String collagePictureBase64 = sketchReconstructionDTO.getCollagePicture();
@@ -1136,15 +1139,25 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
// 截取目标部分
String targetPath = url.substring(pathStartIndex + 1, queryStartIndex);
if (Objects.isNull(sketchReconstruction)){
sketchReconstruction = new SketchReconstruction();
sketchReconstruction.setProjectId(projectId);
sketchReconstruction.setCollageImgSketchUrl(targetPath);
sketchReconstruction.setGenerateDetailId(generateResultVO.getId());
sketchReconstruction.setGender(sketchReconstructionDTO.getGender());
sketchReconstruction.setCreateTime(LocalDateTime.now());
sketchReconstructionMapper.insert(sketchReconstruction);
}else {
try {
if (Objects.isNull(sketchReconstruction)){
sketchReconstruction = new SketchReconstruction();
sketchReconstruction.setProjectId(projectId);
sketchReconstruction.setCollageImgSketchUrl(targetPath);
sketchReconstruction.setGenerateDetailId(generateResultVO.getId());
sketchReconstruction.setGender(sketchReconstructionDTO.getGender());
sketchReconstruction.setCreateTime(LocalDateTime.now());
sketchReconstructionMapper.insert(sketchReconstruction);
}else {
sketchReconstruction.setCollageImgSketchUrl(targetPath);
sketchReconstruction.setGenerateDetailId(generateResultVO.getId());
sketchReconstructionMapper.updateById(sketchReconstruction);
}
} catch (DuplicateKeyException e) {
// 如果发生唯一键冲突,说明其他请求已经创建了记录
// 重新查询并更新
log.info("sketch拼贴唯一键project_id冲突改为更新");
sketchReconstruction = sketchReconstructionMapper.selectOne(qw);
sketchReconstruction.setCollageImgSketchUrl(targetPath);
sketchReconstruction.setGenerateDetailId(generateResultVO.getId());
sketchReconstructionMapper.updateById(sketchReconstruction);