src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
@@ -155,4 +155,51 @@
            throw new ServiceException("导入失败");
        }
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int downCopy(ProductModelDto productModelDto) {
        if (productModelDto == null || productModelDto.getProductId() == null || productModelDto.getTargetProductId() == null) {
            throw new ServiceException("源产品ID和目标产品ID不能为空");
        }
        Long sourceProductId = productModelDto.getProductId();
        Long targetProductId = productModelDto.getTargetProductId();
        if (sourceProductId.equals(targetProductId)) {
            throw new ServiceException("源产品和目标产品不能相同");
        }
        Product sourceProduct = productMapper.selectById(sourceProductId);
        if (sourceProduct == null) {
            throw new ServiceException("源产品不存在");
        }
        Product targetProduct = productMapper.selectById(targetProductId);
        if (targetProduct == null) {
            throw new ServiceException("目标产品不存在");
        }
        List<ProductModel> sourceModels = productModelMapper.selectList(
                new LambdaQueryWrapper<ProductModel>()
                        .eq(ProductModel::getProductId, sourceProductId)
                        .orderByAsc(ProductModel::getId)
        );
        if (CollectionUtils.isEmpty(sourceModels)) {
            throw new ServiceException("源产品下没有可复制的型号");
        }
        List<ProductModel> copyList = new ArrayList<>();
        for (ProductModel sourceModel : sourceModels) {
            ProductModel copy = new ProductModel();
            BeanUtils.copyProperties(sourceModel, copy);
            copy.setId(null);
            copy.setProductId(targetProductId);
            copy.setTenantId(null);
            copyList.add(copy);
        }
        saveBatch(copyList);
        return copyList.size();
    }
}