From 4273d0efc04b3864e88415f8bbe90c105f09863f Mon Sep 17 00:00:00 2001 From: xupei Date: Mon, 30 Jun 2025 19:32:16 +0800 Subject: [PATCH] =?UTF-8?q?BUGFIX:=20=E7=B3=BB=E5=88=97=E8=AE=BE=E8=AE=A1?= =?UTF-8?q?=20=E4=BF=AE=E6=94=B9=E6=A8=A1=E7=89=B9=E5=90=8E=EF=BC=8C?= =?UTF-8?q?=E5=8E=9F=E6=A8=A1=E7=89=B9=E4=B8=A2=E5=A4=B1=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../primary/CollectionElementMapper.java | 3 + .../impl/CollectionElementServiceImpl.java | 54 ++++++------- .../impl/UserLikeGroupServiceImpl.java | 75 +++++++++++-------- .../primary/CollectionElementMapper.xml.xml | 7 ++ 4 files changed, 82 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/ai/da/mapper/primary/CollectionElementMapper.java b/src/main/java/com/ai/da/mapper/primary/CollectionElementMapper.java index d32a80b2..34543cbf 100644 --- a/src/main/java/com/ai/da/mapper/primary/CollectionElementMapper.java +++ b/src/main/java/com/ai/da/mapper/primary/CollectionElementMapper.java @@ -2,6 +2,7 @@ package com.ai.da.mapper.primary; import com.ai.da.common.config.mybatis.plus.CommonMapper; import com.ai.da.mapper.primary.entity.CollectionElement; +import com.ai.da.mapper.primary.entity.CollectionElementRelModel; import java.util.List; @@ -14,4 +15,6 @@ import java.util.List; public interface CollectionElementMapper extends CommonMapper { List selectDeleteList(); + + List selectByProject(Long projectId); } diff --git a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java index ef7c2b40..ab140819 100644 --- a/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/CollectionElementServiceImpl.java @@ -562,33 +562,33 @@ public class CollectionElementServiceImpl extends ServiceImpl printBoardIds = designDTO.getMarketingSketchs().stream() -// .filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName())) -// .map(DesignCollectionElementDTO::getId) -// .collect(Collectors.toList()); -// if(!CollectionUtils.isEmpty(printBoardIds)){ -// List marketingSketchElements = collectionElementMapper.selectBatchIds(printBoardIds); -// Assert.isTrue(CollectionUtil.isNotEmpty(marketingSketchElements) -// && marketingSketchElements.size() == printBoardIds.size(), "get marketingSketch data is mismatch"); -// elementVO.setMarketingSketchElements(marketingSketchElements); -// usedElementIds.addAll(printBoardIds); -// } -// //library -// List libraryIds = designDTO.getMarketingSketchs().stream() -// .filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName())) -// .map(DesignCollectionElementDTO::getId) -// .collect(Collectors.toList()); -// if(!CollectionUtils.isEmpty(libraryIds)){ -// List librarys = libraryService.getByIds(libraryIds); -// //不校验了防止用户在library删除 对应不上 -// if(CollectionUtil.isNotEmpty(librarys)){ -// libraryCollectionElements.addAll(covertLibrarysToCollections(librarys,null)); -// } -// } -// } +/* if (CollectionUtil.isNotEmpty(designDTO.getMarketingSketchs())) { + //校验designType + validateDesignType(designDTO.getMarketingSketchs(),"marketingSketchs"); + List printBoardIds = designDTO.getMarketingSketchs().stream() + .filter(f ->f.getDesignType().equals(DesignTypeEnum.COLLECTION.getRealName())) + .map(DesignCollectionElementDTO::getId) + .collect(Collectors.toList()); + if(!CollectionUtils.isEmpty(printBoardIds)){ + List marketingSketchElements = collectionElementMapper.selectBatchIds(printBoardIds); + Assert.isTrue(CollectionUtil.isNotEmpty(marketingSketchElements) + && marketingSketchElements.size() == printBoardIds.size(), "get marketingSketch data is mismatch"); + elementVO.setMarketingSketchElements(marketingSketchElements); + usedElementIds.addAll(printBoardIds); + } + //library + List libraryIds = designDTO.getMarketingSketchs().stream() + .filter(f ->f.getDesignType().equals(DesignTypeEnum.LIBRARY.getRealName())) + .map(DesignCollectionElementDTO::getId) + .collect(Collectors.toList()); + if(!CollectionUtils.isEmpty(libraryIds)){ + List librarys = libraryService.getByIds(libraryIds); + //不校验了防止用户在library删除 对应不上 + if(CollectionUtil.isNotEmpty(librarys)){ + libraryCollectionElements.addAll(covertLibrarysToCollections(librarys,null)); + } + } + }*/ //校验控制生成类型 SingleOverallEnum singleOverall = SingleOverallEnum.of(designDTO.getSingleOverall()); if (Objects.isNull(singleOverall)) { 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 bc407d92..8e2c27af 100644 --- a/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java +++ b/src/main/java/com/ai/da/service/impl/UserLikeGroupServiceImpl.java @@ -2228,16 +2228,53 @@ public class UserLikeGroupServiceImpl extends ServiceImpl qw = new QueryWrapper<>(); - qw.lambda().eq(CollectionElement::getProjectId, projectId); - qw.lambda().eq(CollectionElement::getLevel1Type, CollectionLevel1TypeEnum.MODEL.getRealName()); - List collectionElements = collectionElementMapper.selectList(qw); - Set old = collectionElements.stream().map(CollectionElement::getId).collect(Collectors.toSet()); -// Set oldUrl = collectionElements.stream().map(CollectionElement::getUrl).collect(Collectors.toSet()); + List collectionElementRelModels = collectionElementMapper.selectByProject(projectId); List mannequin = moduleSaveDTO.getMannequin(); + List inputMannequinId = mannequin.stream().map(MannequinDTO::getId).collect(Collectors.toList()); + + // 创建relationId到Model的映射 + Map relationIdToModelMap = collectionElementRelModels.stream() + .collect(Collectors.toMap( + CollectionElementRelModel::getRelationId, + java.util.function.Function.identity(), + (existing, replacement) -> existing + )); + List newReletionIds = new ArrayList<>(); + List toBeDeletedRelationIds = new ArrayList<>(); + + if (collectionElementRelModels.isEmpty()) { + // 如果原本没有记录,所有输入的Mannequin都是新的 + newReletionIds = inputMannequinId; + } else { + // 获取所有已有的relationId集合 + Set relationIds = relationIdToModelMap.keySet(); + + // 1. 找出需要删除的:relationIds中有但inputMannequinId中没有的 + toBeDeletedRelationIds = relationIds.stream() + .filter(id -> !inputMannequinId.contains(id)) + .collect(Collectors.toList()); + + // 2. 找出新增的:inputMannequinId中有但relationIds中没有的 + newReletionIds = inputMannequinId.stream() + .filter(id -> !relationIds.contains(id)) + .collect(Collectors.toList()); + } + + if (!toBeDeletedRelationIds.isEmpty()){ + Set toBeDeletedElementIdList = toBeDeletedRelationIds.stream() + .map(relationIdToModelMap::get) // 获取对应的Model + .filter(Objects::nonNull) // 过滤掉可能为null的情况 + .map(CollectionElementRelModel::getCollectionElementId) // 提取collectionElementId + .collect(Collectors.toSet()); + collectionElementMapper.deleteBatchIds(toBeDeletedElementIdList); + // 删除关联关系 + deleteByCollectionElementIdList(toBeDeletedElementIdList); + } + for (MannequinDTO dto : mannequin) { - if (null != dto.getCollectionElementId()) { - old.remove(dto.getId()); + if (newReletionIds.isEmpty()){ + break; + }else if (!newReletionIds.contains(dto.getId())){ continue; } if (dto.getType().equals("System")) { @@ -2281,30 +2318,8 @@ public class UserLikeGroupServiceImpl extends ServiceImpl qw = new QueryWrapper<>(); diff --git a/src/main/resources/mapper/primary/CollectionElementMapper.xml.xml b/src/main/resources/mapper/primary/CollectionElementMapper.xml.xml index ab39eb67..9ed70871 100644 --- a/src/main/resources/mapper/primary/CollectionElementMapper.xml.xml +++ b/src/main/resources/mapper/primary/CollectionElementMapper.xml.xml @@ -9,4 +9,11 @@ WHERE collection_id != 0 GROUP BY collection_id) + +