yangys
2025-08-23 77461af6ea87f73b2273739ac7dfcd468251da5d
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcNodeService.java
@@ -18,6 +18,7 @@
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;
/**
 * 程序节点
@@ -95,13 +96,12 @@
      return this.getBaseMapper().getLastProgramNode(name);
   }
   /**
    * 首页树查询
    * @param queryVO
    * @return
    */
   public List<NcNodeVO> searchList(NcNodeQueryVO queryVO) {
   public List<NcNodeVO> searchList(NcNodeOldQueryVO queryVO) {
      //1.根据关进字和节点类型查询初始列表,查询的原始列表,需要hasChild字段,所以使用mapper.xml
      List<NcNodeVO> oriList = this.getBaseMapper().searchList(queryVO);
      if ("10".equals(queryVO.getNodeType())) {
@@ -111,8 +111,6 @@
      List<NcNodeVO> allVos = new ArrayList<NcNodeVO>();//已经加入过的节点,用于去重
      List<NcNodeVO> rootVos = new ArrayList<NcNodeVO>();
      //List<NcNode> rootNodes = new ArrayList<>();
      for(NcNodeVO vo : oriList){
         allVos.add(vo);
@@ -133,6 +131,42 @@
      return rootVos;
   }
   /**
    * 首页搜索 新的
    * @param queryVO 查询参数
    * @return
    */
   public List<NcNodeVO> searchList2(NcNodeQueryVO queryVO) {
      //1.根据零组件号和创建时间查询初始列表,查询的原始列表,需要hasChild字段,所以使用mapper.xml
      if(queryVO.getCreateTimeEnd()!=null){
         queryVO.setCreateTimeEnd(queryVO.getCreateTimeEnd().plusDays(1));
      }
      List<NcNodeVO> oriList = this.getBaseMapper().searchList2(queryVO);
      List<NcNodeVO> allVos = new ArrayList<>();//已经加入过的节点,用于去重
      List<NcNodeVO> rootVos = new ArrayList<>();
      for(NcNodeVO vo : oriList){
         allVos.add(vo);
         //上级各级的节点
         List<NcNodeVO> parents = this.getBaseMapper().searchListInIds(Func.toLongList(vo.getParentIds()));
         for(NcNodeVO pvo : parents){
            if(pvo.getParentId() == 0L && !rootVos.contains(pvo)){
               rootVos.add(pvo);
            }
            if(!allVos.contains(pvo)){
               allVos.add(pvo);
            }
         }
      }
      for(NcNodeVO root : rootVos){
         addNodeChildren(root, allVos);
      }
      return rootVos;
   }
   void addNodeChildren(NcNodeVO node, List<NcNodeVO> allNodes) {
      for(NcNodeVO vo : allNodes){
         if(Objects.equals(vo.getParentId(), node.getId())){
@@ -145,31 +179,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);
      }
   }
   /**
@@ -264,12 +273,14 @@
    * @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();