| | |
| | | ProductModel item = productModelList.get(i); |
| | | int rowNum = i + 2; |
| | | |
| | | if (StringUtils.isEmpty(item.getMaterialCode())) { |
| | | return AjaxResult.error("第 " + rowNum + " 行导入失败: [物料编号] 不能为空"); |
| | | } |
| | | |
| | | if (StringUtils.isEmpty(item.getModel())) { |
| | | return AjaxResult.error("第 " + rowNum + " 行导入失败: [规格型号] 不能为空"); |
| | | } |
| | |
| | | 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(); |
| | | } |
| | | } |