sketch拼贴 获取画布走统一接口

This commit is contained in:
2025-03-25 14:37:38 +08:00
parent a38c15005e
commit 619d0e817f
5 changed files with 9 additions and 69 deletions

View File

@@ -124,15 +124,8 @@ public class GenerateController {
return Response.success(generateResultVO); return Response.success(generateResultVO);
} }
@ApiOperation(value = "拼贴图画布保存") @ApiOperation(value = "获取拼贴图最后一次生成结果")
@GetMapping("/saveReconCanvas") @GetMapping("/getReconLastResult")
public Response<String> sketchReconstructionSave(@RequestParam("file") MultipartFile file, @RequestParam("projectId") Long projectId){
generateService.sketchReconstructionSave(file, projectId);
return Response.success("success");
}
@ApiOperation(value = "获取拼贴图画布")
@GetMapping("/getReconCanvas")
public Response<SketchReconstructionVO> getSketchReconstruction(@RequestParam("projectId") Long projectId){ public Response<SketchReconstructionVO> getSketchReconstruction(@RequestParam("projectId") Long projectId){
SketchReconstructionVO sketchReconstruction = generateService.getSketchReconstruction(projectId); SketchReconstructionVO sketchReconstruction = generateService.getSketchReconstruction(projectId);
return Response.success(sketchReconstruction); return Response.success(sketchReconstruction);

View File

@@ -15,6 +15,4 @@ public class SketchReconstruction extends BaseEntity{
private Long generateDetailId; private Long generateDetailId;
private String canvasUrl;
} }

View File

@@ -6,8 +6,6 @@ import lombok.Data;
@Data @Data
public class SketchReconstructionVO { public class SketchReconstructionVO {
private JSONObject canvasFile;
private String collageSketchUrl; private String collageSketchUrl;
private boolean isLiked; private boolean isLiked;

View File

@@ -56,7 +56,5 @@ public interface GenerateService extends IService<Generate> {
GenerateResultVO sketchReconstructionGenerate(SketchReconstructionDTO sketchReconstructionDTO); GenerateResultVO sketchReconstructionGenerate(SketchReconstructionDTO sketchReconstructionDTO);
String sketchReconstructionSave(MultipartFile multipartFile, Long projectId);
SketchReconstructionVO getSketchReconstruction(Long projectId); SketchReconstructionVO getSketchReconstruction(Long projectId);
} }

View File

@@ -1123,68 +1123,21 @@ public class GenerateServiceImpl extends ServiceImpl<GenerateMapper, Generate> i
return generateResultVO; return generateResultVO;
} }
public String sketchReconstructionSave(MultipartFile multipartFile, Long projectId){
Long accountId = UserContext.getUserHolder().getId();
// 元素都在画布上,不用额外保存
String object = accountId + "/CollageSketchFile/" + projectId;
String canvasFilePath = minioUtil.upload("aida-users", object, multipartFile,null);
// 将画布文件上传到minio,地址保存到project表中
QueryWrapper<SketchReconstruction> qw = new QueryWrapper<>();
qw.eq("project_id", projectId).isNotNull("canvas_url").orderByDesc("id");
SketchReconstruction sketchReconstruction = sketchReconstructionMapper.selectOne(qw);
if (Objects.isNull(sketchReconstruction)){
sketchReconstruction = new SketchReconstruction();
sketchReconstruction.setProjectId(projectId);
sketchReconstruction.setCanvasUrl(canvasFilePath);
sketchReconstruction.setCreateTime(LocalDateTime.now());
sketchReconstructionMapper.insert(sketchReconstruction);
}else if (StringUtil.isNullOrEmpty(sketchReconstruction.getCanvasUrl())){
sketchReconstruction.setCanvasUrl(canvasFilePath);
sketchReconstructionMapper.updateById(sketchReconstruction);
}
// 需要返回哪些信息呢?
return null;
}
public SketchReconstructionVO getSketchReconstruction(Long projectId){ public SketchReconstructionVO getSketchReconstruction(Long projectId){
QueryWrapper<SketchReconstruction> qw = new QueryWrapper<>(); QueryWrapper<SketchReconstruction> qw = new QueryWrapper<>();
qw.eq("project_id", projectId); qw.eq("project_id", projectId);
SketchReconstruction sketchReconstruction = sketchReconstructionMapper.selectOne(qw); SketchReconstruction sketchReconstruction = sketchReconstructionMapper.selectOne(qw);
if (Objects.isNull(sketchReconstruction) || StringUtil.isNullOrEmpty(sketchReconstruction.getCanvasUrl())){ if (Objects.isNull(sketchReconstruction)){
return null; return null;
} }
try { SketchReconstructionVO vo = new SketchReconstructionVO();
InputStream download = minioUtil.download(sketchReconstruction.getCanvasUrl()); if (Objects.nonNull(sketchReconstruction.getGenerateDetailId())){
String convert = convert(download); GenerateDetail generateDetail = generateDetailMapper.selectById(sketchReconstruction.getGenerateDetailId());
JSONObject jsonObject = JSONObject.parseObject(convert); vo.setCollageSketchUrl(minioUtil.getPreSignedUrl(generateDetail.getUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
JSONArray objects = jsonObject.getJSONArray("objects"); vo.setLiked(generateDetail.getIsLike().equals((byte)1));
for (int i = 0; i < objects.size(); i++) {
JSONObject jsonObject1 = objects.getJSONObject(i);
String type = jsonObject1.getString("type");
if (type.equals("image")) {
String minioUrl = jsonObject1.getString("minioUrl");
jsonObject1.put("src", minioUtil.getPreSignedUrl(minioUrl, 24 * 60));
}
objects.set(i, jsonObject1);
}
jsonObject.put("objects", objects);
log.info(String.valueOf(jsonObject));
// 除返回jsonObject之外,还要返回最后一次生成的线稿图以及like状态
SketchReconstructionVO vo = new SketchReconstructionVO();
vo.setCanvasFile(jsonObject);
if (Objects.nonNull(sketchReconstruction.getGenerateDetailId())){
GenerateDetail generateDetail = generateDetailMapper.selectById(sketchReconstruction.getGenerateDetailId());
vo.setCollageSketchUrl(minioUtil.getPreSignedUrl(generateDetail.getUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME));
vo.setLiked(generateDetail.getIsLike().equals((byte)1));
}
return vo;
}catch (Exception e){
return null;
} }
return vo;
} }
} }