From 3df4433381323dcd9fda3c4bb65630819acd44d0 Mon Sep 17 00:00:00 2001 From: xupei Date: Thu, 27 Mar 2025 17:46:09 +0800 Subject: [PATCH] =?UTF-8?q?BUGFIX:=20sketch=E6=8B=BC=E8=B4=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../da/service/impl/GenerateServiceImpl.java | 31 +++++++++++++------ 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java index 0969b9bb..769b3eb7 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -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 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 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);