| | |
| | | |
| | | Long sourceProductId = productModelDto.getProductId(); |
| | | Long targetProductId = productModelDto.getTargetProductId(); |
| | | List<Long> modelListId = productModelDto.getModelListId(); |
| | | |
| | | if (sourceProductId.equals(targetProductId)) { |
| | | throw new ServiceException("源产品和目标产品不能相同"); |
| | |
| | | throw new ServiceException("目标产品不存在"); |
| | | } |
| | | |
| | | List<ProductModel> sourceModels = productModelMapper.selectList( |
| | | new LambdaQueryWrapper<ProductModel>() |
| | | .eq(ProductModel::getProductId, sourceProductId) |
| | | .orderByAsc(ProductModel::getId) |
| | | ); |
| | | LambdaQueryWrapper<ProductModel> queryWrapper = new LambdaQueryWrapper<ProductModel>() |
| | | .eq(ProductModel::getProductId, sourceProductId) |
| | | .orderByAsc(ProductModel::getId); |
| | | Set<Long> selectedModelIds = null; |
| | | if (CollectionUtils.isNotEmpty(modelListId)) { |
| | | selectedModelIds = new LinkedHashSet<>(modelListId); |
| | | queryWrapper.in(ProductModel::getId, selectedModelIds); |
| | | } |
| | | List<ProductModel> sourceModels = productModelMapper.selectList(queryWrapper); |
| | | if (CollectionUtils.isEmpty(sourceModels)) { |
| | | throw new ServiceException("源产品下没有可复制的型号"); |
| | | } |
| | | |
| | | if (selectedModelIds != null && sourceModels.size() != selectedModelIds.size()) { |
| | | throw new ServiceException("部分型号不存在或不属于源产品"); |
| | | } |
| | | |
| | | List<ProductModel> copyList = new ArrayList<>(); |
| | | for (ProductModel sourceModel : sourceModels) { |
| | | ProductModel copy = new ProductModel(); |