diff --git a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java index 6e88c6c2..45946802 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -1950,133 +1950,137 @@ public class UserLikeGroupServiceImpl extends ServiceImpl userLikeSortQueryWrapper = new QueryWrapper<>(); + userLikeSortQueryWrapper.lambda().eq(CollectionSort::getProjectId, projectDTO.getId()); + userLikeSortQueryWrapper.lambda().isNull(CollectionSort::getParentId); + userLikeSortQueryWrapper.lambda().eq(CollectionSort::getRelationType, CollectionType.DESIGN.getValue()); + userLikeSortQueryWrapper.lambda().orderByAsc(CollectionSort::getSort); + List userLikeSortList = collectionSortMapper.selectList(userLikeSortQueryWrapper); - // 使用批量查询获取design模块的所有数据 - List relationTypes = Arrays.asList( - CollectionType.DESIGN.getValue(), - CollectionType.TO_PRODUCT_IMAGE.getValue(), - CollectionType.RELIGHT.getValue(), - CollectionType.POSE_TRANSFORM.getValue() - ); - - List> moduleContentList = userLikeGroupMapper.getModuleContentBatch( - null, projectDTO.getId(), relationTypes); - - if (CollectionUtils.isEmpty(moduleContentList)) { + if (CollectionUtils.isEmpty(userLikeSortList)) { moduleChooseVO.setDesign(vo); - } else { - // 按parent_id分组处理数据 - Map>> groupedByParent = moduleContentList.stream() - .collect(Collectors.groupingBy(item -> { - Object parentId = item.get("parent_id"); - return parentId == null ? 0L : ((Number) parentId).longValue(); - })); - + }else { List list = new ArrayList<>(); - // 处理顶级design项目(parent_id为null的) - List> topLevelDesigns = groupedByParent.get(0L); - if (topLevelDesigns != null) { - for (Map designData : topLevelDesigns) { - if (!CollectionType.DESIGN.getValue().equals(designData.get("relation_type"))) { - continue; - } - - UserLikeVO o = new UserLikeVO(); - o.setId(((Number) designData.get("user_like_id")).longValue()); - o.setDesignItemId(((Number) designData.get("design_item_id")).longValue()); - o.setDesignOutfitId(((Number) designData.get("design_outfit_id")).longValue()); - - String designUrl = (String) designData.get("design_url"); - o.setUrl(designUrl); - if (designUrl != null && designUrl.contains("/")) { - int index = designUrl.lastIndexOf("/"); - o.setPictureName(designUrl.substring(index + 1)); - } - o.setDesignOutfitUrl(getMinioUrl(designUrl)); - - o.setSort(((Number) designData.get("sort")).intValue()); - o.setUserLikeSortId(((Number) designData.get("sort_id")).longValue()); - o.setRelationType((String) designData.get("relation_type")); - o.setCollectionType(CollectionType.DESIGN.getValue()); - o.setResultType(CollectionType.DESIGN.getValue()); - - // 处理子项目 - List childList = new ArrayList<>(); - Long parentSortId = ((Number) designData.get("sort_id")).longValue(); - List> childItems = groupedByParent.get(parentSortId); - - if (childItems != null) { - for (Map childData : childItems) { - String relationType = (String) childData.get("relation_type"); - - if (CollectionType.TO_PRODUCT_IMAGE.getValue().equals(relationType) || - CollectionType.RELIGHT.getValue().equals(relationType)) { - - // 检查任务状态 - String status = (String) childData.get("result_status"); - Object createTimeObj = childData.get("result_create_time"); - LocalDateTime createTime = createTimeObj != null ? - ((java.sql.Timestamp) createTimeObj).toLocalDateTime() : null; - if (isGenerateTaskFailed(status, createTime)) { - continue; - } - - ToProductImageResultVO toProductImageResultVO = new ToProductImageResultVO(); - toProductImageResultVO.setId(((Number) childData.get("to_product_result_id")).longValue()); - toProductImageResultVO.setUrl(getMinioUrl((String) childData.get("result_url"))); - toProductImageResultVO.setElementType((String) childData.get("element_type")); - toProductImageResultVO.setElementId(((Number) childData.get("element_id")).longValue()); - toProductImageResultVO.setPrompt((String) childData.get("prompt")); - - // 设置sourceUrl - String elementType = (String) childData.get("element_type"); - if ("ProductElement".equals(elementType)) { - toProductImageResultVO.setSourceUrl(getMinioUrl((String) childData.get("element_url"))); - } else if ("DesignOutfit".equals(elementType)) { - toProductImageResultVO.setSourceUrl(getMinioUrl((String) childData.get("design_url"))); - } - - toProductImageResultVO.setSort(((Number) childData.get("sort")).intValue()); - toProductImageResultVO.setUserLikeSortId(((Number) childData.get("sort_id")).longValue()); - toProductImageResultVO.setRelationType(relationType); - toProductImageResultVO.setParentId(((Number) childData.get("parent_id")).longValue()); - childList.add(toProductImageResultVO); - - } else if (CollectionType.POSE_TRANSFORM.getValue().equals(relationType)) { - // 检查任务状态 - String status = (String) childData.get("pose_status"); - Object createTimeObj = childData.get("pose_create_time"); - LocalDateTime createTime = createTimeObj != null ? - ((java.sql.Timestamp) createTimeObj).toLocalDateTime() : null; - if (isGenerateTaskFailed(status, createTime)) { - continue; - } - - PoseTransformationVO poseTransformationVO = new PoseTransformationVO(); - poseTransformationVO.setId(((Number) childData.get("pose_id")).longValue()); - poseTransformationVO.setTaskId((String) childData.get("pose_unique_id")); - poseTransformationVO.setProductImage(getMinioUrl((String) childData.get("pose_product_image"))); - poseTransformationVO.setGifUrl(getMinioUrl((String) childData.get("pose_gif_url"))); - poseTransformationVO.setVideoUrl(getMinioUrl((String) childData.get("pose_video_url"))); - poseTransformationVO.setFirstFrameUrl(getMinioUrl((String) childData.get("pose_first_frame_url"))); - poseTransformationVO.setIsLiked(((Number) childData.get("pose_is_liked")).byteValue()); - poseTransformationVO.setCollectionType(CollectionType.POSE_TRANSFORM.getValue()); - poseTransformationVO.setSort(((Number) childData.get("sort")).intValue()); - poseTransformationVO.setUserLikeSortId(((Number) childData.get("sort_id")).longValue()); - poseTransformationVO.setRelationType(relationType); - poseTransformationVO.setResultType(CollectionType.POSE_TRANSFORM.getValue()); - poseTransformationVO.setParentId(((Number) childData.get("parent_id")).longValue()); - poseTransformationVO.setModelName((String) childData.get("pose_model_name")); - poseTransformationVO.setPoseId(((Number) childData.get("pose_pose_id")).intValue()); - poseTransformationVO.setStatus(status); - childList.add(poseTransformationVO); - } - } - } - o.setChildList(childList); - list.add(o); + for (CollectionSort collectionSort : userLikeSortList) { + UserLike userLike = userLikeMapper.selectById(collectionSort.getRelationId()); + UserLikeVO o = CopyUtil.copyObject(userLike, UserLikeVO.class); + TDesignPythonOutfit tDesignPythonOutfit1 = designPythonOutfitMapper.selectById(o.getDesignOutfitId()); + o.setUrl(tDesignPythonOutfit1.getDesignUrl()); + if (o.getUrl().contains("/")) { + int index = o.getUrl().lastIndexOf("/"); + o.setPictureName(o.getUrl().substring(index + 1)); } + o.setDesignOutfitUrl(getMinioUrl(o.getUrl())); + QueryWrapper qw = new QueryWrapper<>(); + qw.lambda().eq(TDesignPythonOutfit::getDesignItemId, o.getDesignItemId()); + List tDesignPythonOutfits = designPythonOutfitMapper.selectList(qw); + if (CollectionUtil.isNotEmpty(tDesignPythonOutfits)) { + TDesignPythonOutfit tDesignPythonOutfit = tDesignPythonOutfits.get(0); + o.setDesignOutfitId(tDesignPythonOutfit.getId()); + } + + o.setSort(collectionSort.getSort()); + o.setUserLikeSortId(collectionSort.getId()); + o.setRelationType(collectionSort.getRelationType()); + o.setCollectionType(CollectionType.DESIGN.getValue()); + o.setResultType(CollectionType.DESIGN.getValue()); + QueryWrapper childCollectionQw = new QueryWrapper<>(); + childCollectionQw.lambda().eq(CollectionSort::getParentId, collectionSort.getId()); + childCollectionQw.lambda().orderByAsc(CollectionSort::getSort); + List childSortList = collectionSortMapper.selectList(childCollectionQw); + List childList = new ArrayList<>(); + for (CollectionSort userLikeSort : childSortList) { + if (userLikeSort.getRelationType().equals(CollectionType.TO_PRODUCT_IMAGE.getValue())) { + ToProductImageResult toProductImageResult = toProductImageResultMapper.selectById(userLikeSort.getRelationId()); + if (isGenerateTaskFailed(toProductImageResult.getStatus(), toProductImageResult.getCreateTime())){ + continue; + } + toProductImageResult.setUrl(getMinioUrl(toProductImageResult.getUrl())); + ToProductImageResultVO toProductImageResultVO = CopyUtil.copyObject(toProductImageResult, ToProductImageResultVO.class); + + ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResult.getToProductImageRecordId()); + if (Objects.isNull(toProductImageRecord)) { + log.warn("toProductRecord不存在,projectId:{}, toProductImageResultId:{}", projectDTO.getId(), toProductImageResult.getId()); + continue; + } + toProductImageResultVO.setPrompt(toProductImageRecord.getPrompt()); + + if (toProductImageResultVO.getElementType().equals("ProductElement")) { + ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(toProductElement.getUrl())); + }else if ((toProductImageResultVO.getElementType().equals("DesignOutfit"))) { + TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(tDesignPythonOutfit.getDesignUrl())); + }else { + ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(toProductImageResult1.getUrl())); + } + toProductImageResultVO.setCollectionType(CollectionType.TO_PRODUCT_IMAGE.getValue()); + toProductImageResultVO.setSort(userLikeSort.getSort()); + toProductImageResultVO.setUserLikeSortId(userLikeSort.getId()); + toProductImageResultVO.setRelationType(userLikeSort.getRelationType()); + toProductImageResultVO.setParentId(userLikeSort.getParentId()); + childList.add(toProductImageResultVO); + } else if (userLikeSort.getRelationType().equals(CollectionType.RELIGHT.getValue())) { + ToProductImageResult toProductImageResult = toProductImageResultMapper.selectById(userLikeSort.getRelationId()); + if (isGenerateTaskFailed(toProductImageResult.getStatus(), toProductImageResult.getCreateTime())){ + continue; + } + toProductImageResult.setUrl(getMinioUrl(toProductImageResult.getUrl())); + ToProductImageResultVO toProductImageResultVO = CopyUtil.copyObject(toProductImageResult, ToProductImageResultVO.class); + + ToProductImageRecord toProductImageRecord = toProductImageRecordMapper.selectById(toProductImageResult.getToProductImageRecordId()); + if (Objects.isNull(toProductImageRecord)) { + log.warn("toProductRecord不存在,projectId:{}, toProductImageResultId:{}", projectDTO.getId(), toProductImageResult.getId()); + continue; + } + toProductImageResultVO.setPrompt(toProductImageRecord.getPrompt()); + + if (toProductImageResultVO.getElementType().equals("ProductElement")) { + ToProductElement toProductElement = toProductElementMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(toProductElement.getUrl())); + }else if ((toProductImageResultVO.getElementType().equals("DesignOutfit"))) { + TDesignPythonOutfit tDesignPythonOutfit = designPythonOutfitMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(tDesignPythonOutfit.getDesignUrl())); + }else { + ToProductImageResult toProductImageResult1 = toProductImageResultMapper.selectById(toProductImageResultVO.getElementId()); + toProductImageResultVO.setSourceUrl(getMinioUrl(toProductImageResult1.getUrl())); + } + toProductImageResultVO.setCollectionType(CollectionType.RELIGHT.getValue()); + toProductImageResultVO.setSort(userLikeSort.getSort()); + toProductImageResultVO.setUserLikeSortId(userLikeSort.getId()); + toProductImageResultVO.setRelationType(userLikeSort.getRelationType()); + toProductImageResultVO.setParentId(userLikeSort.getParentId()); + childList.add(toProductImageResultVO); + } else if (userLikeSort.getRelationType().equals(CollectionType.POSE_TRANSFORM.getValue())) { + PoseTransformation item = poseTransformationMapper.selectById(userLikeSort.getRelationId()); + if (isGenerateTaskFailed(item.getTaskStatus(), item.getCreateTime())){ + continue; + } + PoseTransformationVO poseTransformationVO = new PoseTransformationVO(); + poseTransformationVO.setId(item.getId()); + poseTransformationVO.setTaskId(item.getUniqueId()); + poseTransformationVO.setProductImage(getMinioUrl(item.getProductImage())); + poseTransformationVO.setGifUrl(getMinioUrl(item.getGifUrl())); + poseTransformationVO.setVideoUrl(getMinioUrl(item.getVideoUrl())); + poseTransformationVO.setFirstFrameUrl(getMinioUrl(item.getFirstFrameUrl())); + poseTransformationVO.setIsLiked(item.getIsLiked()); + poseTransformationVO.setCollectionType(CollectionType.POSE_TRANSFORM.getValue()); + poseTransformationVO.setSort(userLikeSort.getSort()); + poseTransformationVO.setUserLikeSortId(userLikeSort.getId()); + poseTransformationVO.setRelationType(userLikeSort.getRelationType()); + poseTransformationVO.setResultType(CollectionType.POSE_TRANSFORM.getValue()); + poseTransformationVO.setParentId(userLikeSort.getParentId()); + poseTransformationVO.setModelName(item.getModelName()); + poseTransformationVO.setPoseId(item.getPoseId()); + poseTransformationVO.setStatus(item.getTaskStatus()); + childList.add(poseTransformationVO); + } + } + o.setChildList(childList); + + list.add(o); } vo.setUserLikeDetails(list); } @@ -2122,28 +2126,6 @@ public class UserLikeGroupServiceImpl extends ServiceImpl recordIds = allResults.stream() - .map(ToProductImageResult::getToProductImageRecordId) - .filter(Objects::nonNull) - .distinct() - .collect(Collectors.toList()); - - Map recordPromptMap = new HashMap<>(); - if (!recordIds.isEmpty()) { - List> recordData = userLikeGroupMapper.getToProductImageRecordBatch(recordIds); - recordPromptMap = recordData.stream() - .collect(Collectors.toMap( - data -> ((Number) data.get("record_id")).longValue(), - data -> { - String prompt = (String) data.get("prompt"); - return prompt != null ? prompt : ""; // 提供默认值 - }, - (existing, replacement) -> existing - )); - } - - // 处理URL转换和分类 List likedList = new ArrayList<>(); List normalList = new ArrayList<>(); @@ -2155,10 +2137,10 @@ public class UserLikeGroupServiceImpl extends ServiceImpl list = new ArrayList<>(); if (CollectionUtil.isNotEmpty(collectionElements)) { - // 批量查询CollectionElementRelModel数据 - List collectionElementIds = collectionElements.stream() - .map(CollectionElement::getId) - .collect(Collectors.toList()); - List relModels = userLikeGroupMapper.getCollectionElementRelModelBatch(collectionElementIds); - Map relModelMap = relModels.stream() - .collect(Collectors.toMap(CollectionElementRelModel::getCollectionElementId, rel -> rel)); - for (CollectionElement collectionElement : collectionElements) { CollectionElementVO collectionElementVO = CopyUtil.copyObject(collectionElement, CollectionElementVO.class); - CollectionElementRelModel relModel = relModelMap.get(collectionElementVO.getId()); + CollectionElementRelModel relModel = getCollectionElementRelModel(collectionElementVO.getId()); collectionElementVO.setUrl(getMinioUrl(collectionElementVO.getUrl())); - if (relModel != null) { - collectionElementVO.setMannequinRelationId(relModel.getRelationId()); - collectionElementVO.setMannequinRelationType(relModel.getRelationType()); - } + collectionElementVO.setMannequinRelationId(relModel.getRelationId()); + collectionElementVO.setMannequinRelationType(relModel.getRelationType()); collectionElementVO.setCollectionId(collectionElement.getId()); list.add(collectionElementVO); }