yangys
2025-09-10 143e74027f8b68fb7fa4dcd0026ccfa1e0e16788
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java
@@ -5,7 +5,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.mp.base.BizServiceImpl;
import org.springblade.core.tool.utils.Func;
import org.springblade.mdm.basesetting.machine.MachineService;
import org.springblade.mdm.basesetting.machine.service.MachineService;
import org.springblade.mdm.basesetting.machine.entity.Machine;
import org.springblade.mdm.program.entity.NcNode;
import org.springblade.mdm.program.mapper.NcNodeMapper;
@@ -18,7 +18,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
 * 程序节点
@@ -96,28 +95,6 @@
      return this.getBaseMapper().getLastProgramNode(name);
   }
   /**
    * 车讯节点
    * @param queryVO
    * @return
    */
   /*
   public List<Long> searchDrawing(NcNodeQueryVO queryVO) {
      List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_DRAWING_NO)
         .eq(NcNode::getIsLastEdition,1)
         .eq(NcNode::getName,queryVO.getDrawingNo())
         .ge(queryVO.getCreateTimeBegin()!=null,NcNode::getCreateTime,queryVO.getCreateTimeBegin())
         .le(queryVO.getCreateTimeEnd()!=null,NcNode::getCreateTime,queryVO.getCreateTimeEnd())
         .and(i->{
            i.or().likeRight(queryVO.getProgramStatus().contains("1"),NcNode::getParentIds,"0,1,");
            i.or().likeRight(queryVO.getProgramStatus().contains("2"),NcNode::getParentIds,"0,2,");
            i.or().likeRight(queryVO.getProgramStatus().contains("3"),NcNode::getParentIds,"0,3,");
         }).list();
      return nodes.stream().map(NcNode::getId).toList();
   }*/
   /**
    * 首页树查询
    * @param queryVO
@@ -165,7 +142,6 @@
      }
      List<NcNodeVO> oriList = this.getBaseMapper().searchList2(queryVO);
      List<NcNodeVO> allVos = new ArrayList<>();//已经加入过的节点,用于去重
      List<NcNodeVO> rootVos = new ArrayList<>();
@@ -175,10 +151,13 @@
         List<NcNodeVO> parents = this.getBaseMapper().searchListInIds(Func.toLongList(vo.getParentIds()));
         for(NcNodeVO pvo : parents){
            if(pvo.getParentId() == 0L){
            if(pvo.getParentId() == 0L && !rootVos.contains(pvo)){
               rootVos.add(pvo);
            }
            allVos.add(pvo);
            if(!allVos.contains(pvo)){
               allVos.add(pvo);
            }
         }
      }
      for(NcNodeVO root : rootVos){
@@ -199,31 +178,6 @@
            addNodeChildren(child, allNodes);
         }
      }
   }
   NcNodeVO toNodeVO(NcNode node){
      NcNodeVO vo = new NcNodeVO();
      BeanUtils.copyProperties(node, vo);
      return vo;
   }
   /**
    * 获取程序包名的数据
    * @param programName 程序名称(程序包名)
    * @return 程序报包名的节点
    */
   public NcNode getProgramPackageByName(String programName) {
      List<NcNode> pkgs = this.lambdaQuery().eq(NcNode::getName, programName)
         .eq(NcNode::getIsLastEdition,1)
         .eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE).list();
      if(pkgs.isEmpty()){
         return null;
      }else{
         return pkgs.get(0);
      }
   }
   /**
@@ -290,8 +244,8 @@
    * @param processNo 工序版次
    * @return 程序包名/程序名称
    */
   public static String genProgramName(String drawingNo,String processNo){
      return drawingNo+"-"+processNo;
   public static String genProgramName(String drawingNo,String processNo,String processEdition){
      return drawingNo+"-"+processNo+"-"+processEdition;
   }
   /**
@@ -318,14 +272,39 @@
    * @param machineCode 机床编号
    * @return
    */
   public NcNode getCuredProgramPackage(String programPkgName,String machineCode) {
   public NcNode getCuredProgramPackage(String programPkgName,String processEdition,String machineCode) {
      Machine machine = machineService.getByCode(machineCode);
      List<Machine> sameGroupMachines = machineService.lambdaQuery().eq(Machine::getMachineGroupCode,machine.getMachineGroupCode()).list();
      List<String> machineCodesInGroup = sameGroupMachines.stream().map(Machine::getCode).toList();
      List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName, programPkgName).likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
         .eq(NcNode::getName, programPkgName)
         .eq(NcNode::getProcessEdition,processEdition)
         .likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
         .in(!machineCodesInGroup.isEmpty(),NcNode::getMachineCode,machineCodesInGroup)
         .eq(NcNode::getIsLastEdition,1).list();
      if(nodes.isEmpty()){
         return null;
      }else {
         return nodes.get(0);
      }
   }
   /**
    * 获取最新的固化程序,不用工序版次匹配
    * @param programPkgName
    * @param machineCode
    * @return
    */
   public NcNode getLastCuredProgramPackageWithoutProcessEdition(String programPkgName,String machineCode) {
      Machine machine = machineService.getByCode(machineCode);
      List<Machine> sameGroupMachines = machineService.lambdaQuery().eq(Machine::getMachineGroupCode,machine.getMachineGroupCode()).list();
      List<String> machineCodesInGroup = sameGroupMachines.stream().map(Machine::getCode).toList();
      List<NcNode> nodes = lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName, programPkgName)
         .likeRight(NcNode::getParentIds,"0,2,").eq(NcNode::getIsCured,1)
         .in(!machineCodesInGroup.isEmpty(),NcNode::getMachineCode,machineCodesInGroup)
         .eq(NcNode::getIsLastEdition,1).orderByDesc(NcNode::getCreateTime).list();
      if(nodes.isEmpty()){
         return null;
@@ -380,7 +359,6 @@
      return this.lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_FILE)
         .eq(NcNode::getParentId,packageNodeId).eq(NcNode::getIsLastEdition,1).list();
   }
   /**
    * 升级版本号(+1)
    * @param nodeId 节点id
@@ -404,9 +382,41 @@
      this.updateById(node);
    }
   @Transactional
   public void lock(Long id,String remark) {
      NcNode node = this.getById(id);
      node.lock(remark);
      this.updateById(node);
   }
   @Transactional
   public void unlock(Long id) {
      NcNode node = this.getById(id);
      node.unlock();
      this.updateById(node);
   }
   /**
    * 查询偏离单的序号
    * @param programPkgNode 偏离单的程序包名节点
    * @return 序号
    */
    public long getDeviationSerialForNode(NcNode programPkgNode) {
      return lambdaQuery().eq(NcNode::getNodeType,NcNode.TYPE_PROGRAM_PACKAGE)
         .eq(NcNode::getName,programPkgNode.getName())
         .eq(NcNode::getDrawingNo,programPkgNode.getDrawingNo())
         .eq(NcNode::getProcessNo,programPkgNode.getProcessNo())
         .eq(NcNode::getProcessEdition,programPkgNode.getProcessEdition())
         .isNotNull(NcNode::getDeviation)
         .le(NcNode::getCreateTime,programPkgNode.getCreateTime())  //时间小于等于当前节点
         .count();
    }
   /**
    * 根据上级节点id,移动下面的加工机床节点
    * @param parentId 上级节点id
    */
   public void deleteMachineNodeByParentId(Long parentId) {
      baseMapper.deleteMachineNodeByParentId(parentId);
   }
}