From c449e0d7e5e537cd8dfb5928572db31d0310bc0e Mon Sep 17 00:00:00 2001
From: buhuazhen <hua100783@gmail.com>
Date: 星期六, 16 五月 2026 10:59:38 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/dev_New_pro' into dev_New_pro
---
src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java | 72 +++++++++++++++++++++++++++++++++--
1 files changed, 67 insertions(+), 5 deletions(-)
diff --git a/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java b/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
index 16a45b1..be34fc0 100644
--- a/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
+++ b/src/main/java/com/ruoyi/basic/service/impl/ProductModelServiceImpl.java
@@ -3,6 +3,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.dto.ProductDto;
@@ -12,20 +13,25 @@
import com.ruoyi.basic.pojo.Product;
import com.ruoyi.basic.pojo.ProductModel;
import com.ruoyi.basic.service.IProductModelService;
+import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.bean.BeanUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.domain.AjaxResult;
+import com.ruoyi.sales.dto.LossProductModelDto;
import com.ruoyi.sales.mapper.SalesLedgerProductMapper;
import com.ruoyi.sales.pojo.SalesLedgerProduct;
+import com.ruoyi.technology.mapper.TechnologyBomMapper;
+import com.ruoyi.technology.pojo.TechnologyBom;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
+import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
-import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
/**
@@ -40,10 +46,16 @@
private final ProductMapper productMapper;
private final SalesLedgerProductMapper salesLedgerProductMapper;
+ private final TechnologyBomMapper technologyBomMapper;
private ProductModelMapper productModelMapper;
@Override
public int addOrEditProductModel(ProductModelDto productModelDto) {
+ String model = StringUtils.trim(productModelDto.getModel());
+ String productCode = StringUtils.trim(productModelDto.getProductCode());
+ productModelDto.setModel(model);
+ productModelDto.setProductCode(productCode);
+ checkModelAndProductCodeUnique(model, productCode, productModelDto.getId());
if (productModelDto.getId() == null) {
ProductModel productModel = new ProductModel();
@@ -51,6 +63,21 @@
return productModelMapper.insert(productModel);
} else {
return productModelMapper.updateById(productModelDto);
+ }
+ }
+
+ private void checkModelAndProductCodeUnique(String model, String productCode, Long currentId) {
+ if (StringUtils.isEmpty(model) || StringUtils.isEmpty(productCode)) {
+ return;
+ }
+ LambdaQueryWrapper<ProductModel> queryWrapper = new LambdaQueryWrapper<>();
+ queryWrapper.eq(ProductModel::getModel, model)
+ .eq(ProductModel::getProductCode, productCode)
+ .ne(currentId != null, ProductModel::getId, currentId)
+ .last("limit 1");
+ ProductModel duplicateProductModel = productModelMapper.selectOne(queryWrapper);
+ if (duplicateProductModel != null) {
+ throw new ServiceException("瀵瑰簲鐨勫瀷鍙�" + model + "鐨勪骇鍝佺紪鐮�" + productCode + "宸茬粡瀛樺湪");
}
}
@@ -63,6 +90,14 @@
throw new RuntimeException("宸茬粡瀛樺湪璇ヤ骇鍝佺殑閿�鍞彴璐﹀拰閲囪喘鍙拌处");
}
+
+ // 鏄惁瀛樺湪BOM
+ List<TechnologyBom> technologyBoms = technologyBomMapper.selectList(new QueryWrapper<TechnologyBom>()
+ .lambda().in(TechnologyBom::getProductModelId, ids));
+ if (CollectionUtils.isNotEmpty(technologyBoms)) {
+ throw new RuntimeException("宸茬粡瀛樺湪璇ヤ骇鍝佺殑BOM鏁版嵁");
+ }
+
return productModelMapper.deleteBatchIds(Arrays.asList(ids));
}
@@ -103,28 +138,55 @@
ExcelUtil<ProductModel> productModelExcelUtil = new ExcelUtil<>(ProductModel.class);
List<ProductModel> productModelList = productModelExcelUtil.importExcel(file.getInputStream());
- if (productModelList == null || productModelList.isEmpty()) {
+ if (CollectionUtils.isEmpty(productModelList)) {
return AjaxResult.error("瀵煎叆鏁版嵁涓嶈兘涓虹┖");
}
+
+ // 鑾峰彇褰撳墠浜у搧涓嬫墍鏈夌殑瑙勬牸鍨嬪彿鍚�
+ List<ProductModel> existingModels = list(new LambdaQueryWrapper<ProductModel>().eq(ProductModel::getProductId, productId));
+ Set<String> existingModelNames = existingModels.stream().map(ProductModel::getModel).collect(Collectors.toSet());
+
+ List<ProductModel> waitToSaveList = new ArrayList<>();
+ int skipCount = 0;
for (int i = 0; i < productModelList.size(); i++) {
ProductModel item = productModelList.get(i);
int rowNum = i + 2;
+ if (StringUtils.isEmpty(item.getProductCode())) {
+ return AjaxResult.error("绗� " + rowNum + " 琛屽鍏ュけ璐�: [浜у搧缂栫爜] 涓嶈兘涓虹┖");
+ }
if (StringUtils.isEmpty(item.getModel())) {
return AjaxResult.error("绗� " + rowNum + " 琛屽鍏ュけ璐�: [瑙勬牸鍨嬪彿] 涓嶈兘涓虹┖");
}
if (StringUtils.isEmpty(item.getUnit())) {
return AjaxResult.error("绗� " + rowNum + " 琛屽鍏ュけ璐�: [鍗曚綅] 涓嶈兘涓虹┖");
}
+
+ // 鍘婚噸,濡傛灉宸插寘鍚鍨嬪彿,鍒欒烦杩�
+ if (existingModelNames.contains(item.getModel())) {
+ skipCount++;
+ continue;
+ }
+
item.setProductId(product.getId());
+ waitToSaveList.add(item);
+
+ existingModelNames.add(item.getModel());
}
- saveOrUpdateBatch(productModelList);
- return AjaxResult.success("鎴愬姛瀵煎叆 " + productModelList.size() + " 鏉℃暟鎹�");
+ if (!waitToSaveList.isEmpty()) {
+ saveBatch(waitToSaveList);
+ }
+
+ if (skipCount == 0) {
+ return AjaxResult.success(String.format("鎴愬姛瀵煎叆 %d 鏉℃暟鎹�", waitToSaveList.size()));
+ } else {
+ return AjaxResult.success(String.format("鎴愬姛瀵煎叆 %d 鏉★紝璺宠繃宸插瓨鍦ㄦ暟鎹� %d 鏉�", waitToSaveList.size(), skipCount));
+ }
} catch (Exception e) {
log.error("瀵煎叆浜у搧瑙勬牸寮傚父", e);
- return AjaxResult.error("瀵煎叆澶辫触");
+ throw new ServiceException("瀵煎叆澶辫触");
}
}
}
--
Gitblit v1.9.3