From bc116c55a44bc344e5575b5bdd4c2591bc0475aa Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期二, 17 三月 2026 16:43:36 +0800
Subject: [PATCH] fix: BOM模块的导入、模板下载、新增、编辑修改
---
src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java | 68 +++++++++++++++++++--------------
1 files changed, 39 insertions(+), 29 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
index 678cfd2..1336736 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductMaterialServiceImpl.java
@@ -82,8 +82,6 @@
}
try {
-
-
JSONArray searchConditions = new JSONArray();
JSONObject statusCondition = new JSONObject();
statusCondition.put("key", "processInstanceStatus");
@@ -143,11 +141,14 @@
JSONObject formData = item.getJSONObject("formData");
// 澶勭悊鐗╂枡涓昏〃鏁版嵁
ProductMaterial material = new ProductMaterial();
- material.setMaterialName(formData.getString("textField_l92f36f5"));
- material.setBaseUnit(formData.getString("textField_la147lnw"));
+ material.setProductName(formData.getString("textField_l92f36f5"));
+ material.setUnit(formData.getString("textField_la147lnw"));
material.setRemark(formData.getString("textareaField_l92f36f9"));
String materialType = formData.getString("selectField_l92f36fb");
+ if ("鏉挎潗".equals(materialType) || "鐮屽潡".equals(materialType) || "鏍囩爾".equals(materialType)) {
+ materialType = "鎴愬搧";
+ }
String inventoryCat = formData.getString("selectField_la154noy");
material.setMaterialTypeId(getOrCreateConfigId(materialType, MaterialConfigTypeEnum.MATERIAL_TYPE.name()));
material.setInventoryCategoryId(getOrCreateConfigId(inventoryCat, MaterialConfigTypeEnum.INVENTORY_CAT.name()));
@@ -156,11 +157,11 @@
// 澶勭悊鐗╂枡瑙勬牸鏁版嵁
ProductMaterialSku sku = new ProductMaterialSku();
- sku.setMaterialId(materialId);
+ sku.setProductId(materialId);
sku.setFormInstanceId(formInstanceId);
sku.setIdentifierCode(formData.getString("textField_l92h77ju"));
sku.setMaterialCode(formData.getString("textField_l92f36f2"));
- sku.setSpecification(formData.getString("textField_l92f36f6"));
+ sku.setModel(formData.getString("textField_l92f36f6"));
sku.setSupplyType(formData.getString("selectField_la14k51j"));
sku.setOriginatorName(originatorName);
sku.setOriginatorOrg("瀹佸涓垱缁胯兘瀹炰笟闆嗗洟鏈夐檺鍏徃");
@@ -175,7 +176,7 @@
private Long getOrCreateMaterial(ProductMaterial material) {
LambdaQueryWrapper<ProductMaterial> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(ProductMaterial::getMaterialName, material.getMaterialName());
+ queryWrapper.eq(ProductMaterial::getProductName, material.getProductName());
ProductMaterial exist = this.getOne(queryWrapper);
if (exist == null) {
@@ -194,8 +195,8 @@
exist.setInventoryCategoryId(material.getInventoryCategoryId());
needUpdate = true;
}
- if (StringUtils.isNotEmpty(material.getBaseUnit()) && !material.getBaseUnit().equals(exist.getBaseUnit())) {
- exist.setBaseUnit(material.getBaseUnit());
+ if (StringUtils.isNotEmpty(material.getUnit()) && !material.getUnit().equals(exist.getUnit())) {
+ exist.setUnit(material.getUnit());
needUpdate = true;
}
if (needUpdate) {
@@ -224,13 +225,14 @@
if (list == null || list.isEmpty()) {
return 0;
}
- int affected = 0;
+
+ List<ProductMaterialSku> toSave = new ArrayList<>();
+ List<ProductMaterialSku> toUpdate = new ArrayList<>();
for (ProductMaterialSku sku : list) {
-
LambdaQueryWrapper<ProductMaterialSku> wrapper = new LambdaQueryWrapper<>();
- wrapper.eq(ProductMaterialSku::getMaterialId, sku.getMaterialId())
- .eq(ProductMaterialSku::getSpecification, sku.getSpecification());
+ wrapper.eq(ProductMaterialSku::getProductId, sku.getProductId())
+ .eq(ProductMaterialSku::getModel, sku.getModel());
if (StringUtils.isNotEmpty(sku.getMaterialCode())) {
wrapper.eq(ProductMaterialSku::getMaterialCode, sku.getMaterialCode());
@@ -240,20 +242,28 @@
ProductMaterialSku exist = productMaterialSkuService.getOne(wrapper);
if (exist == null) {
- productMaterialSkuService.save(sku);
- affected++;
- log.info("鏂板鐗╂枡瑙勬牸 {}", sku.getSpecification());
+ toSave.add(sku);
} else {
if (exist.getFormModifiedTime() == null || !exist.getFormModifiedTime().equals(sku.getFormModifiedTime())) {
sku.setId(exist.getId());
sku.setCreateTime(exist.getCreateTime());
- productMaterialSkuService.updateById(sku);
-
- affected++;
- log.info("鏇存柊鐗╂枡瑙勬牸 {}", sku.getSpecification());
+ toUpdate.add(sku);
}
}
}
+
+ int affected = 0;
+ if (!toSave.isEmpty()) {
+ productMaterialSkuService.saveBatch(toSave);
+ affected += toSave.size();
+ log.info("鎵归噺鏂板鐗╂枡瑙勬牸 {} 鏉�", toSave.size());
+ }
+ if (!toUpdate.isEmpty()) {
+ productMaterialSkuService.updateBatchById(toUpdate);
+ affected += toUpdate.size();
+ log.info("鎵归噺鏇存柊鐗╂枡瑙勬牸 {} 鏉�", toUpdate.size());
+ }
+
return affected;
}
@@ -273,7 +283,7 @@
ProductMaterial::getId,
ProductMaterial::getMaterialTypeId,
ProductMaterial::getInventoryCategoryId,
- ProductMaterial::getMaterialName
+ ProductMaterial::getProductName
)
);
materialMap = materialList.stream()
@@ -307,10 +317,10 @@
ProductMaterial::getId,
ProductMaterial::getMaterialTypeId,
ProductMaterial::getInventoryCategoryId,
- ProductMaterial::getMaterialName
+ ProductMaterial::getProductName
);
if (StringUtils.isNotEmpty(materialName)) {
- wrapper.like(ProductMaterial::getMaterialName, materialName);
+ wrapper.like(ProductMaterial::getProductName, materialName);
}
if (materialTypeId != null) {
wrapper.eq(ProductMaterial::getMaterialTypeId, materialTypeId);
@@ -345,7 +355,7 @@
private ProductMaterialDto convert(ProductMaterial m) {
ProductMaterialDto dto = new ProductMaterialDto();
dto.setId(m.getId());
- dto.setMaterialName(m.getMaterialName());
+ dto.setProductName(m.getProductName());
dto.setMaterialTypeId(m.getMaterialTypeId());
dto.setInventoryCategoryId(m.getInventoryCategoryId());
return dto;
@@ -355,7 +365,7 @@
@Transactional(rollbackFor = Exception.class)
public void addProductMaterial(ProductMaterial productMaterial) {
validateProductMaterial(productMaterial, false);
- if (existsMaterialName(productMaterial.getMaterialName(), null)) {
+ if (existsMaterialName(productMaterial.getProductName(), null)) {
throw new ServiceException("鐗╂枡鍚嶇О宸插瓨鍦�");
}
LocalDateTime now = LocalDateTime.now();
@@ -366,7 +376,7 @@
if (!this.save(productMaterial)) {
throw new ServiceException("鏂板鐗╂枡澶辫触");
}
- log.info("鏂板鐗╂枡鎴愬姛 materialName={}", productMaterial.getMaterialName());
+ log.info("鏂板鐗╂枡鎴愬姛 materialName={}", productMaterial.getProductName());
}
@Override
@@ -377,7 +387,7 @@
if (exist == null) {
throw new ServiceException("鐗╂枡涓嶅瓨鍦�");
}
- if (existsMaterialName(productMaterial.getMaterialName(), productMaterial.getId())) {
+ if (existsMaterialName(productMaterial.getProductName(), productMaterial.getId())) {
throw new ServiceException("鐗╂枡鍚嶇О宸插瓨鍦�");
}
productMaterial.setUpdateTime(LocalDateTime.now());
@@ -406,7 +416,7 @@
if (requireId && productMaterial.getId() == null) {
throw new ServiceException("涓婚敭ID涓嶈兘涓虹┖");
}
- if (StringUtils.isEmpty(productMaterial.getMaterialName())) {
+ if (StringUtils.isEmpty(productMaterial.getProductName())) {
throw new ServiceException("鐗╂枡鍚嶇О涓嶈兘涓虹┖");
}
}
@@ -416,7 +426,7 @@
return false;
}
LambdaQueryWrapper<ProductMaterial> queryWrapper = new LambdaQueryWrapper<>();
- queryWrapper.eq(ProductMaterial::getMaterialName, materialName);
+ queryWrapper.eq(ProductMaterial::getProductName, materialName);
if (excludeId != null) {
queryWrapper.ne(ProductMaterial::getId, excludeId);
}
--
Gitblit v1.9.3