diff --git a/src/main/java/com/ai/da/python/PythonService.java b/src/main/java/com/ai/da/python/PythonService.java index 83a0fcca..65e171e5 100644 --- a/src/main/java/com/ai/da/python/PythonService.java +++ b/src/main/java/com/ai/da/python/PythonService.java @@ -4402,7 +4402,7 @@ public class PythonService { throw new BusinessException("poseTransferBatch.interface.exception"); } - public JSONObject getProjectParam(String prompt, String fileUrl, List imageUrlList) { + public JSONObject getProjectParam(String prompt, String fileUrl, List imageUrlList, String process) { OkHttpClient client = new OkHttpClient().newBuilder() .connectTimeout(30, TimeUnit.SECONDS) .pingInterval(5, TimeUnit.SECONDS)//websocket轮训间隔(单位:秒) @@ -4412,6 +4412,7 @@ public class PythonService { MediaType mediaType = MediaType.parse("application/json"); Map content = Maps.newHashMap(); content.put("prompt", prompt); + content.put("process", process); content.put("image_list", !CollectionUtils.isEmpty(imageUrlList) ? imageUrlList : new ArrayList<>()); content.put("file_list", !StringUtils.isEmpty(fileUrl) ? Collections.singletonList(fileUrl) : new ArrayList<>()); RequestBody body = RequestBody.create(mediaType, JSON.toJSONString(content)); 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 4f196adf..89268db6 100644 --- a/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/GenerateServiceImpl.java @@ -60,6 +60,7 @@ import java.util.*; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; +import java.util.function.Consumer; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -1220,15 +1221,13 @@ public class GenerateServiceImpl extends ServiceImpl i if (!StringUtil.isNullOrEmpty(resultJson)){ PoseTransformationVO poseTransformationVO = new Gson().fromJson(redisUtil.getFromString(key), PoseTransformationVO.class); if (poseTransformationVO.getStatus().equals("Success")){ - if (!poseTransformationVO.getGifUrl().equals("None")){ - poseTransformationVO.setGifUrl(minioUtil.getPreSignedUrl(poseTransformationVO.getGifUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - } - if (!poseTransformationVO.getVideoUrl().equals("None")){ - poseTransformationVO.setVideoUrl(minioUtil.getPreSignedUrl(poseTransformationVO.getVideoUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - } - if (!poseTransformationVO.getFirstFrameUrl().equals("None")){ - poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(poseTransformationVO.getFirstFrameUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - } + // 处理各种URL + processUrl(poseTransformationVO.getGifUrl(), url -> + poseTransformationVO.setGifUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(poseTransformationVO.getVideoUrl(), url -> + poseTransformationVO.setVideoUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(poseTransformationVO.getFirstFrameUrl(), url -> + poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); } poseTransformationVO.setResultType(CollectionType.POSE_TRANSFORM.getValue()); return poseTransformationVO; @@ -1242,50 +1241,70 @@ public class GenerateServiceImpl extends ServiceImpl i List vos = new ArrayList<>(); // if (poseTransformations != null && poseTransformations.size() > 1){ if (!CollectionUtils.isEmpty(poseTransformations)){ - poseTransformations.forEach(item -> { + for (PoseTransformation item : poseTransformations) { String taskId = item.getUniqueId(); String key = generateResultKey + ":" + taskId; String resultJson = redisUtil.getFromString(key); + PoseTransformationVO poseTransformationVO; + if (!StringUtil.isNullOrEmpty(resultJson)) { - PoseTransformationVO poseTransformationVO = new Gson().fromJson(redisUtil.getFromString(key), PoseTransformationVO.class); + // 从Redis获取并转换数据 + poseTransformationVO = new Gson().fromJson(resultJson, PoseTransformationVO.class); poseTransformationVO.setId(item.getId()); poseTransformationVO.setIsLiked(item.getIsLiked()); - if (poseTransformationVO.getStatus().equals("Success")) { - poseTransformationVO.setProductImage(minioUtil.getPreSignedUrl(item.getProductImage(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - if (!poseTransformationVO.getGifUrl().equals("None")) { - poseTransformationVO.setGifUrl(minioUtil.getPreSignedUrl(poseTransformationVO.getGifUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - } - if (!poseTransformationVO.getVideoUrl().equals("None")) { - poseTransformationVO.setVideoUrl(minioUtil.getPreSignedUrl(poseTransformationVO.getVideoUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - } - if (!poseTransformationVO.getFirstFrameUrl().equals("None")) { - poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(poseTransformationVO.getFirstFrameUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - } + + // 处理成功状态的数据 + if ("Success".equals(poseTransformationVO.getStatus())) { + poseTransformationVO.setProductImage( + minioUtil.getPreSignedUrl(item.getProductImage(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); + + // 处理各种URL + processUrl(poseTransformationVO.getGifUrl(), url -> + poseTransformationVO.setGifUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(poseTransformationVO.getVideoUrl(), url -> + poseTransformationVO.setVideoUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(poseTransformationVO.getFirstFrameUrl(), url -> + poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); } - if (!poseTransformationVO.getStatus().equals("Invalid") && !poseTransformationVO.getStatus().equals("Failed")) { + + // 添加有效数据到结果列表 + if (!"Invalid".equals(poseTransformationVO.getStatus()) && !"Failed".equals(poseTransformationVO.getStatus())) { vos.add(poseTransformationVO); } - }else { - PoseTransformationVO poseTransformationVO = CopyUtil.copyObject(item, PoseTransformationVO.class); - poseTransformationVO.setTaskId(item.getUniqueId()); - poseTransformationVO.setProductImage(minioUtil.getPreSignedUrl(item.getProductImage(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - if (!StringUtil.isNullOrEmpty(poseTransformationVO.getGifUrl())) { - poseTransformationVO.setGifUrl(minioUtil.getPreSignedUrl(poseTransformationVO.getGifUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - } - if (!StringUtil.isNullOrEmpty(poseTransformationVO.getVideoUrl())) { - poseTransformationVO.setVideoUrl(minioUtil.getPreSignedUrl(poseTransformationVO.getVideoUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); - } - if (!StringUtil.isNullOrEmpty(poseTransformationVO.getFirstFrameUrl())) { - poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(poseTransformationVO.getFirstFrameUrl(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); + } else { + // 处理Redis中没有缓存的情况 + poseTransformationVO = CopyUtil.copyObject(item, PoseTransformationVO.class); + // todo 面对没有生成成功的情况 如何处理? + if (StringUtil.isNullOrEmpty(item.getVideoUrl())){ + continue; } + poseTransformationVO.setTaskId(taskId); + poseTransformationVO.setProductImage( + minioUtil.getPreSignedUrl(item.getProductImage(), CommonConstant.MINIO_IMAGE_EXPIRE_TIME)); + + // 处理各种URL + processUrl(poseTransformationVO.getGifUrl(), url -> + poseTransformationVO.setGifUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(poseTransformationVO.getVideoUrl(), url -> + poseTransformationVO.setVideoUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + processUrl(poseTransformationVO.getFirstFrameUrl(), url -> + poseTransformationVO.setFirstFrameUrl(minioUtil.getPreSignedUrl(url, CommonConstant.MINIO_IMAGE_EXPIRE_TIME))); + vos.add(poseTransformationVO); } - }); + } } return vos; } + // 辅助方法:处理URL + private void processUrl(String url, Consumer processor) { + if (!StringUtil.isNullOrEmpty(url) && !"None".equals(url)) { + processor.accept(url); + } + } + public Object disOrLikePose(Long transformedId, String likeOrDislike, Long projectId, Long collectionSortParentId){ PoseTransformation poseTransformation = poseTransformationMapper.selectById(transformedId); Long collectionSortId = null; diff --git a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java index ab404067..8bb8e980 100644 --- a/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/LLMServiceImpl.java @@ -515,7 +515,7 @@ public class LLMServiceImpl implements LLMService { @Override public Long chatCreateProject(String prompt, String process, String fileUrl, List imageUrlList) { AuthPrincipalVo userHolder = UserContext.getUserHolder(); - JSONObject jsonObject = pythonService.getProjectParam(prompt, fileUrl, imageUrlList); + JSONObject jsonObject = pythonService.getProjectParam(prompt, fileUrl, imageUrlList, process); JSONObject data = jsonObject.getJSONObject("data"); Project project = new Project(); LocalDateTime now = LocalDateTime.now();