From 52d98d59dfa75bd18187e99e1e550701a1b27191 Mon Sep 17 00:00:00 2001
From: huminmin <mac@MacBook-Pro.local>
Date: 星期四, 23 四月 2026 17:03:21 +0800
Subject: [PATCH] Merge branch 'dev_衡阳_鹏创电子' of http://114.132.189.42:9002/r/product-inventory-management-after into dev_衡阳_鹏创电子
---
src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java | 111 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 111 insertions(+), 0 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java
index b7b67bb..b91ba31 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductBomServiceImpl.java
@@ -2,6 +2,7 @@
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.basic.pojo.Product;
@@ -20,6 +21,7 @@
import com.ruoyi.production.service.ProductBomService;
import com.ruoyi.production.service.ProductProcessService;
import com.ruoyi.production.service.ProductStructureService;
+import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -188,6 +190,115 @@
@Override
@Transactional(rollbackFor = Exception.class)
+ public AjaxResult copy(ProductBomDto productBom) {
+ Long copyId = productBom.getCopyId();
+ if (copyId == null) {
+ throw new ServiceException("澶嶅埗婧怋OM ID涓嶈兘涓虹┖");
+ }
+ ProductBom sourceBom = productBomMapper.selectById(copyId);
+ if (sourceBom == null) {
+ throw new ServiceException("澶嶅埗婧怋OM涓嶅瓨鍦�");
+ }
+
+
+ ProductBom newBom = getProductBom(productBom, sourceBom);
+ productBomMapper.insert(newBom);
+ newBom.setBomNo("BM." + String.format("%05d", newBom.getId()));
+ productBomMapper.updateById(newBom);
+
+
+
+ ProductModel productModel = productModelService.getById(newBom.getProductModelId());
+ if (productModel == null) {
+ throw new ServiceException("閫夋嫨鐨勪骇鍝佹ā鍨嬩笉瀛樺湪");
+ }
+
+ ProductStructure newRoot = getProductStructure(newBom, productModel);
+ productStructureService.save(newRoot);
+ List<ProductStructure> sourceStructures = productStructureMapper.selectList(
+ Wrappers.<ProductStructure>lambdaQuery()
+ .eq(ProductStructure::getBomId, copyId.intValue()));
+ if (sourceStructures == null || sourceStructures.isEmpty()) {
+ return AjaxResult.success();
+ }
+
+ ProductStructure oldRoot = sourceStructures.stream()
+ .filter(s -> s.getParentId() == null)
+ .findFirst().orElse(new ProductStructure());
+
+ List<ProductStructure> children = sourceStructures
+ .stream()
+ .filter(s -> !s.getId().equals(oldRoot.getId()))
+ .collect(Collectors.toList());
+
+ Map<Long, Long> oldNewIdMap = new HashMap<>();
+
+ oldNewIdMap.put(oldRoot.getId(), newRoot.getId());
+
+ List<ProductStructure> insertList = children
+ .stream()
+ .map(item -> getProductStructures(item, newBom))
+ .collect(Collectors.toList());
+
+ productStructureService.saveBatch(insertList);
+
+ for (int i = 0; i < children.size(); i++) {
+ oldNewIdMap.put(
+ children.get(i).getId(),
+ insertList.get(i).getId()
+ );
+ }
+
+ List<ProductStructure> updateList = new ArrayList<>();
+ for (int i = 0; i < children.size(); i++) {
+ ProductStructure source = children.get(i);
+ ProductStructure inserted = insertList.get(i);
+ Long newParentId = oldNewIdMap.get(source.getParentId());
+ if (newParentId != null) {
+ inserted.setParentId(newParentId);
+ updateList.add(inserted);
+ }
+ }
+ if (!updateList.isEmpty()) {
+ productStructureService.updateBatchById(updateList);
+ }
+
+ return AjaxResult.success();
+ }
+
+ @NotNull
+ private static ProductStructure getProductStructures(ProductStructure item, ProductBom newBom) {
+ ProductStructure copy = new ProductStructure();
+ copy.setProductModelId(item.getProductModelId());
+ copy.setProcessId(item.getProcessId());
+ copy.setUnitQuantity(item.getUnitQuantity());
+ copy.setDemandedQuantity(item.getDemandedQuantity());
+ copy.setUnit(item.getUnit());
+ copy.setBomId(newBom.getId());
+ return copy;
+ }
+
+ @NotNull
+ private static ProductStructure getProductStructure(ProductBom newBom, ProductModel productModel) {
+ ProductStructure newRoot = new ProductStructure();
+ newRoot.setProductModelId(newBom.getProductModelId());
+ newRoot.setUnitQuantity(BigDecimal.valueOf(1));
+ newRoot.setUnit(productModel.getUnit());
+ newRoot.setBomId(newBom.getId());
+ return newRoot;
+ }
+
+ @NotNull
+ private static ProductBom getProductBom(ProductBomDto productBom, ProductBom sourceBom) {
+ ProductBom newBom = new ProductBom();
+ newBom.setProductModelId(productBom.getProductModelId() != null ? productBom.getProductModelId() : sourceBom.getProductModelId());
+ newBom.setRemark(productBom.getRemark());
+ newBom.setVersion(productBom.getVersion() != null ? productBom.getVersion() : sourceBom.getVersion());
+ return newBom;
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
public AjaxResult uploadBom(MultipartFile file) {
ExcelUtil<BomImportDto> util = new ExcelUtil<>(BomImportDto.class);
List<BomImportDto> list;
--
Gitblit v1.9.3