| | |
| | | import com.chinaztt.mes.technology.state.bom.constant.BomStates; |
| | | import com.chinaztt.ztt.common.core.util.R; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.messaging.Message; |
| | | import org.springframework.messaging.support.MessageBuilder; |
| | |
| | | @Service |
| | | @AllArgsConstructor |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Slf4j |
| | | public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomService { |
| | | |
| | | private NumberGenerator<Bom> numberGenerator; |
| | |
| | | bom.setVersion(structure.getVersion()); |
| | | bom.setAlternativeNo(structure.getAlternativeNo()); |
| | | bom.setAlternativeDesc(structure.getAlternativeDesc()); |
| | | StructureTree tree = getAllBomExt(bom, 998); |
| | | //log.info("第一层========================》"+bom); |
| | | StructureTree tree = getAllBomExt(bom, 999); |
| | | BomDTO bomDTO = new BomDTO(); |
| | | BeanUtils.copyProperties(bom, bomDTO); |
| | | bomDTO.setTree(tree); |
| | | //BomDTO bomDTO = getBomDtoById(structure.getPartId()); |
| | | log.info("bomDto============>"+bomDTO); |
| | | saveBom(bomDTO); |
| | | }); |
| | | return R.ok(); |
| | |
| | | bomComp.setPlanningMethod(structureTree.getPlanningMethod()); |
| | | bomComp.setColor(structureTree.getColor()); |
| | | bomComp.setOperationId(structureTree.getOperationId()); |
| | | |
| | | bomComp.setSharpenerNo(structureTree.getSharpenerNo()); |
| | | bomComp.setCaveNum(structureTree.getCaveNum()); |
| | | bomComp.setGramWeight(structureTree.getGramWeight()); |
| | | bomComp.setGateGramWeight(structureTree.getGateGramWeight()); |
| | | bomComp.setMoldingCycle(structureTree.getMoldingCycle()); |
| | | bomComp.setMachine(structureTree.getMachine()); |
| | | bomComp.setScale(structureTree.getScale()); |
| | | bomComp.setDryingTime(structureTree.getDryingTime()); |
| | | bomComp.setDryingTemperature(structureTree.getDryingTemperature()); |
| | | bomComp.setPackingInfo(structureTree.getPackingInfo()); |
| | | |
| | | bomComponentMapper.insert(bomComp); |
| | | saveChildren(structureTree.getChildren(), bomComp.getId(), bom, structureTree.getPartId()); |
| | | } |
| | |
| | | return; |
| | | } |
| | | Part parentPart = partMapper.selectById(parentPartId); |
| | | //"P" 虚拟件的意思 在一个BOM中,除根节点外,其余节点若不是虚拟件(零件【计划方法】不为P 和 K),则禁止为其增加子件。 |
| | | if (!bom.getPartId().equals(parentPartId)) { |
| | | if (!"P".equals(parentPart.getPlanningMethod()) && !"K".equals(parentPart.getPlanningMethod())) { |
| | | throw new RuntimeException(parentPart.getPartNo() + parentPart.getPartName() + "为非虚拟件,不可添加子件"); |
| | | } |
| | | } |
| | | log.error("parentId=======>"+parentPartId); |
| | | log.error("bomParentId====>"+bom); |
| | | ////"P" 虚拟件的意思 在一个BOM中,除根节点外,其余节点若不是虚拟件(零件【计划方法】不为P 和 K),则禁止为其增加子件。 |
| | | //if (!bom.getPartId().equals(parentPartId)) { |
| | | // if (!"P".equals(parentPart.getPlanningMethod()) && !"K".equals(parentPart.getPlanningMethod())) { |
| | | // throw new RuntimeException(parentPart.getPartNo() + parentPart.getPartName() + "为非虚拟件,不可添加子件"); |
| | | // } |
| | | //} |
| | | for (StructureTree child : children) { |
| | | BomComponent bomComp = new BomComponent(); |
| | | bomComp.setQpa(child.getQpa()); |
| | |
| | | bomComp.setOperationId(child.getOperationId()); |
| | | bomComp.setPlanningMethod(child.getPlanningMethod()); |
| | | bomComp.setDiscNum(child.getDiscNum()); |
| | | |
| | | bomComp.setSharpenerNo(child.getSharpenerNo()); |
| | | bomComp.setCaveNum(child.getCaveNum()); |
| | | bomComp.setGramWeight(child.getGramWeight()); |
| | | bomComp.setGateGramWeight(child.getGateGramWeight()); |
| | | bomComp.setMoldingCycle(child.getMoldingCycle()); |
| | | bomComp.setMachine(child.getMachine()); |
| | | bomComp.setScale(child.getScale()); |
| | | bomComp.setDryingTime(child.getDryingTime()); |
| | | bomComp.setDryingTemperature(child.getDryingTemperature()); |
| | | bomComp.setPackingInfo(child.getPackingInfo()); |
| | | |
| | | bomComponentMapper.insert(bomComp); |
| | | saveChildren(child.getChildren(), bomComp.getId(), bom, child.getPartId()); |
| | | } |
| | |
| | | */ |
| | | @Override |
| | | public StructureTree getAllBomExt(Bom bom, int bomLayers) { |
| | | log.info("生成树=======》"); |
| | | Long partId = bom.getPartId(); |
| | | String version = bom.getVersion(); |
| | | String alternativeNo = bom.getAlternativeNo(); |
| | |
| | | StructureTree root = getRootNode(partId); |
| | | //通过产品结构查工序 |
| | | Map<Long, Integer> cache = new HashMap<>(80); |
| | | |
| | | getStructureByPartId(root, partId, cache, version, alternativeNo, bomType, bomLayers); |
| | | return root; |
| | | } |
| | |
| | | * @Date: 2022-06-01 |
| | | */ |
| | | private StructureTree getRootNode(Long partId) { |
| | | log.info("获取bom根节点====》"+partId); |
| | | Part part = partMapper.selectById(partId); |
| | | log.info("父级零件====》"+part); |
| | | StructureTree root = new StructureTree(); |
| | | root.setPartName(part.getPartName()); |
| | | root.setPlanningMethod(part.getPlanningMethod()); |
| | |
| | | @Override |
| | | public BomDTO getBomDtoById(Long id) { |
| | | Bom bom = baseMapper.selectById(id); |
| | | log.info("getBomDtoById=>>>"+bom); |
| | | //如果存在未绑定工序的 工艺路线 则会为空 |
| | | List<StructureTree> nodes = baseMapper.getBomComponents4Tree(id); |
| | | if (CollectionUtil.isEmpty(nodes)) { |
| | | return null; |
| | | } |
| | | StructureTree root = nodes.stream().filter(e -> e.getParentId() == null || e.getParentId() == 0).findFirst().get(); |
| | | log.info("root=======>"+root); |
| | | setChildren(root, nodes); |
| | | log.info("setChildren后========》"+root); |
| | | Part part = partMapper.selectById(bom.getPartId()); |
| | | BomDTO bomDto = new BomDTO(); |
| | | BeanUtils.copyProperties(bom, bomDto); |
| | |
| | | */ |
| | | private void getStructureByPartId(StructureTree parent, Long partId, Map<Long, Integer> cache, String version, |
| | | String alternativeNo, String bomType, int bomLayers) { |
| | | log.info("每层树===================》"+parent); |
| | | Integer cycleCount = cache.get(partId) == null ? 0 : cache.get(partId); |
| | | if (cycleCount >= CYCLE_DEEP) { |
| | | return; |
| | |
| | | } |
| | | //根据零件找到结构主表 |
| | | List<Structure> structures = getRootNodes(partId, version, alternativeNo, bomType); |
| | | log.info("得到结构=========》"+structures); |
| | | if (CollectionUtil.isNotEmpty(structures)) { |
| | | for (Structure structure : structures) { |
| | | |
| | | parent.setSharpenerNo(structure.getSharpenerNo()); |
| | | parent.setCaveNum(structure.getCaveNum()); |
| | | parent.setGramWeight(structure.getGramWeight()); |
| | | parent.setGateGramWeight(structure.getGateGramWeight()); |
| | | parent.setMoldingCycle(structure.getMoldingCycle()); |
| | | parent.setMachine(structure.getMachine()); |
| | | parent.setScale(structure.getScale()); |
| | | parent.setDryingTime(structure.getDryingTime()); |
| | | parent.setDryingTemperature(structure.getDryingTemperature()); |
| | | parent.setPackingInfo(structure.getPackingInfo()); |
| | | |
| | | // 查询BOM子节点 |
| | | List<StructureComponent> components = structureComponentMapper.selectList(Wrappers.<StructureComponent>lambdaQuery(). |
| | | eq(StructureComponent::getStructureId, structure.getId()) |
| | |
| | | } |
| | | // 填充child节点数据 |
| | | StructureTree child = fillChildNode(parent, component, structure, part); |
| | | log.info("节点数据====================》"+child); |
| | | if (bomLayers == 999) { |
| | | getStructureByPartId(child, component.getPartId(), cache, "ALL", "ALL", bomType, bomLayers); |
| | | // 判断到第几层了,制造类型为1-已制造,计划方法为P-虚拟件 |
| | | } else if (bomLayers > 0 && (part.getMaterialType().equals("1") && !part.getPlanningMethod().equals( |
| | | } else if (bomLayers > 0 && (part.getMaterialType().equals("1") && part.getPlanningMethod().equals( |
| | | "A"))) { |
| | | getStructureByPartId(child, component.getPartId(), cache, "ALL", "ALL", bomType, bomLayers); |
| | | } |