Fixiaobai
2023-11-07 940f06f6d8e5508f39bd7f8ce7791d60bfc0686c
mes-technology/src/main/java/com/chinaztt/mes/technology/service/impl/BomServiceImpl.java
@@ -40,6 +40,7 @@
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;
@@ -66,6 +67,7 @@
@Service
@AllArgsConstructor
@Transactional(rollbackFor = Exception.class)
@Slf4j
public class BomServiceImpl extends ServiceImpl<BomMapper, Bom> implements BomService {
   private NumberGenerator<Bom> numberGenerator;
@@ -162,10 +164,13 @@
         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();
@@ -184,6 +189,18 @@
      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());
   }
@@ -209,12 +226,14 @@
         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());
@@ -227,6 +246,18 @@
         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());
      }
@@ -239,6 +270,7 @@
    */
   @Override
   public StructureTree getAllBomExt(Bom bom, int bomLayers) {
      log.info("生成树=======》");
      Long partId = bom.getPartId();
      String version = bom.getVersion();
      String alternativeNo = bom.getAlternativeNo();
@@ -264,7 +296,9 @@
    * @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());
@@ -328,13 +362,16 @@
   @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);
@@ -496,6 +533,18 @@
      child.setStructureId(structure.getId());
      child.setPartId(component.getPartId());
      child.setColor(component.getColor());
      child.setSharpenerNo(component.getSharpenerNo());
      child.setCaveNum(component.getCaveNum());
      child.setGramWeight(component.getGramWeight());
      child.setGateGramWeight(component.getGateGramWeight());
      child.setMoldingCycle(component.getMoldingCycle());
      child.setMachine(component.getMachine());
      child.setScale(component.getScale());
      child.setDryingTime(component.getDryingTime());
      child.setDryingTemperature(component.getDryingTemperature());
      child.setPackingInfo(component.getPackingInfo());
      child.setPartNo(part.getPartNo());
      child.setPartName(part.getPartName());
      child.setExpand(true);
@@ -521,6 +570,7 @@
    */
   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;
@@ -529,8 +579,21 @@
      }
      //根据零件找到结构主表
      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())
@@ -550,6 +613,7 @@
               }
               // 填充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-虚拟件