yangys
2025-08-22 9810791a41d381a10451f3e9770cfcfedf98e886
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramService.java
@@ -89,38 +89,6 @@
      return this.getBaseMapper().getCuredNcProgram(drwaingNo,machine.getMachineGroupCode());
   }
   /**
    * 上传程序文件到指定节点
    * @param uploadVO 上传文件表单数据
    */
   public void uploadProgramFile(NcProgramUploadVO uploadVO) {
      MultipartFile file = uploadVO.getFile();
      BladeFile bfile = ossTemplate.putFile(uploadVO.getFile());
      String link = bfile.getLink();
      //保存profame
      NcProgram prog = new NcProgram();
      prog.setCode(generageCode());
      prog.setName(file.getOriginalFilename());
      prog.setNcNodeId(uploadVO.getNodeId());
      prog.setOssName(bfile.getName());
      prog.setDrawingNo(uploadVO.getDrawingNo());
      prog.setProcessEdition(uploadVO.getProcessEdition());
      prog.setIsLastEdition(1);
      boolean isTextFile = false;
      try {
         isTextFile = FileContentUtil.isTextFile(file.getInputStream());
      } catch (IOException e) {
         log.warn("判断是否文本文件异常",e);
      }
      prog.setIsTextFile(isTextFile);
      prog.setUrl(link);
      prog.setCategory(uploadVO.getCategory());
      this.save(prog);
   }
   /**
    * 上传程序文件到指定节点
    * @param uploadVO 上传文件表单数据
@@ -176,50 +144,7 @@
      DecimalFormat df = new DecimalFormat("0000000000");
      return df.format(program.getId());
   }
   /**
    * 删除一个程序
    * @param id 程序id
    */
   public String getFileContent(Long id) {
      String result  ="";
      NcProgram prog = this.getById(id);
      if(prog.getIsTextFile()!=null && prog.getIsTextFile()){
         String fileName = prog.getOssName();
         try (InputStream inputStream = ossTemplate.statFileStream(fileName)) {
            result = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
         } catch (IOException e) {
            throw new RuntimeException(e);
         }
      }else{
         result = "非文本格式文件";
      }
      return result;
   }
   /**
    * 获取文件内饿哦那个
    * @param ncNodeId 节点id
    */
   public String getFileContentByNodeId(Long ncNodeId) {
      String result  ="";
      NcNode node = this.nodeService.getById(ncNodeId);
      LambdaQueryWrapper<NcProgram> wrapper = new LambdaQueryWrapper<>();
      wrapper.eq(NcProgram::getBindNcNodeId, ncNodeId);
      wrapper.eq(NcProgram::getIsLastEdition,1);
      NcProgram prog = this.getOne(wrapper);
      if(prog.getIsTextFile()!=null && prog.getIsTextFile()){
         String fileName = prog.getOssName();
         try (InputStream inputStream = ossTemplate.statFileStream(fileName)) {
            result = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
         } catch (IOException e) {
            throw new RuntimeException(e);
         }
      }else{
         result = "非文本格式文件";
      }
      return result;
   }
   /**
    * 删除一个程序
    * @param id
@@ -370,6 +295,7 @@
    * @param bindNodeId
    * @return
    */
   /*
   public List<NcProgramVO> historyByBindNode(Long bindNodeId) {
      NcProgram program = this.getByBindNodeId(bindNodeId);
@@ -380,5 +306,5 @@
         NcProgramVO vo = new NcProgramVO();
         BeanUtils.copyProperties(p,vo);
         return vo;}).toList();
   }
   }*/
}