| | |
| | | if (bomStructure == null) { |
| | | return null; |
| | | } |
| | | // The root node is the first output node; other rows use their direct parent as the current operation output. |
| | | if (bomStructure.getParentId() == null) { |
| | | if (bomStructure.getParentId() == null || hasChildren(bomStructure, structureById)) { |
| | | return bomStructure; |
| | | } |
| | | ProductionBomStructure parent = structureById.get(bomStructure.getParentId()); |
| | | return parent != null ? parent : bomStructure; |
| | | } |
| | | |
| | | private boolean hasChildren(ProductionBomStructure bomStructure, |
| | | Map<Long, ProductionBomStructure> structureById) { |
| | | if (bomStructure == null || bomStructure.getId() == null || structureById == null) { |
| | | return false; |
| | | } |
| | | return structureById.values().stream() |
| | | .anyMatch(child -> child != null && Objects.equals(child.getParentId(), bomStructure.getId())); |
| | | } |
| | | |
| | | private Long resolveOutputProductModelId(ProductionBomStructure outputNode, |
| | | Long rootProductModelId) { |
| | | if (outputNode == null) { |