From 346d463346701e8714b3a3a3ebb21e21960b5484 Mon Sep 17 00:00:00 2001
From: gongchunyi <deslre0381@gmail.com>
Date: 星期五, 20 三月 2026 15:06:47 +0800
Subject: [PATCH] feat: 查看生产订单对应的生产计划来源
---
src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java | 47 ++++++++++++++++++++++++++---------------------
1 files changed, 26 insertions(+), 21 deletions(-)
diff --git a/src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java b/src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java
index 6b43c18..f694dad 100644
--- a/src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java
+++ b/src/main/java/com/ruoyi/production/service/impl/ProductStructureServiceImpl.java
@@ -25,13 +25,14 @@
@Override
@Transactional
- public Boolean addProductStructureDto(ProductStructureDto dto) {
+ public Boolean addProductStructureDto(Integer bomId, List<ProductStructureDto> list) {
- Long bomId = dto.getBomId();
-
- // 灏嗘爲鎵佸钩鍖�
+ // 鎵佸钩鍖栦紶鍏ョ殑鏍�
List<ProductStructureDto> flatDtoList = new ArrayList<>();
- flattenTree(dto.getChildren(), flatDtoList);
+ for (ProductStructureDto root : list) {
+ flatDtoList.add(root);
+ flattenTree(root.getChildren(), flatDtoList);
+ }
// 鏌ヨ鏁版嵁搴撲腑宸叉湁鐨� BOM 鏁版嵁
List<ProductStructure> dbList = this.list(new LambdaQueryWrapper<ProductStructure>().eq(ProductStructure::getBomId, bomId));
@@ -65,13 +66,13 @@
entity.setBomId(bomId);
if (psDto.getId() == null) {
- // 鏂板
entity.setId(null);
entity.setParentId(null);
insertList.add(entity);
- tempEntityMap.put(psDto.getTempId(), entity);
+ if (psDto.getTempId() != null) {
+ tempEntityMap.put(psDto.getTempId(), entity);
+ }
} else {
- // 鏇存柊
updateList.add(entity);
}
}
@@ -83,28 +84,32 @@
// 鍥炲啓鏂板鑺傜偣 parentId
List<ProductStructure> parentFixList = new ArrayList<>();
- // 鐪熷疄鐨勭埗鑺傜偣 ID
Long realParentId;
for (ProductStructureDto psDto : flatDtoList) {
- if (psDto.getId() == null && psDto.getParentTempId() != null) {
- ProductStructure child = tempEntityMap.get(psDto.getTempId());
- if (tempEntityMap.containsKey(psDto.getParentTempId())) {
- // 鐖惰妭鐐规槸鏂拌妭鐐�
- realParentId = tempEntityMap.get(psDto.getParentTempId()).getId();
+ if (psDto.getId() != null) continue;
+ ProductStructure child = tempEntityMap.get(psDto.getTempId());
+ if (child == null) continue;
+ String parentTempId = psDto.getParentTempId();
+ if (parentTempId != null && !parentTempId.isEmpty()) {
+ if (tempEntityMap.containsKey(parentTempId)) {
+ realParentId = tempEntityMap.get(parentTempId).getId();
} else {
- // 鐖惰妭鐐规槸鑰佽妭鐐�
- realParentId = Long.valueOf(psDto.getParentTempId());
+ try {
+ realParentId = Long.valueOf(parentTempId);
+ } catch (NumberFormatException e) {
+ realParentId = 0L;
+ }
}
-
child.setParentId(realParentId);
- parentFixList.add(child);
+ } else {
+ child.setParentId(0L);
}
+ parentFixList.add(child);
}
if (!parentFixList.isEmpty()) {
this.updateBatchById(parentFixList);
}
-
if (!updateList.isEmpty()) {
this.updateBatchById(updateList);
}
@@ -130,8 +135,8 @@
@Override
- public List<ProductStructureDto> listBybomId(Long bomId) {
- List<ProductStructureDto> list = productStructureMapper.listBybomId(bomId);
+ public List<ProductStructureDto> listByBomId(Integer bomId) {
+ List<ProductStructureDto> list = productStructureMapper.listByBomId(bomId);
Map<Long, ProductStructureDto> map = new HashMap<>();
for (ProductStructureDto node : list) {
--
Gitblit v1.9.3