yangys
2025-07-09 785f3d5be63e723a947a2b35dc0ca89297073d7f
blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/NcProgramService.java
@@ -31,7 +31,9 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.*;
import org.springblade.core.mp.base.BizServiceImpl;
import org.springblade.core.mp.support.Condition;
@@ -53,12 +55,14 @@
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
 * 工作流服务实现类
@@ -71,20 +75,18 @@
public class NcProgramService  extends BizServiceImpl<NcProgramMapper, NcProgram> {
   private final MachineService machineService;
   private final OssTemplate ossTemplate;
   private final NcNodeService nodeService;
   private final ProgramSeqMapper seqMapper;
   /**
    * 查询现有固化的程序,暂定条件:零组件号相同,且是同一机床组
    * @param partNo
    * @param drwaingNo
    * @param machineCode
    * @return
    */
   public List<NcProgram> getCuredNcProgram(String partNo,String machineCode) {
   public List<NcProgram> getCuredNcProgram(String drwaingNo,String machineCode) {
      Machine machine = machineService.getByCode(machineCode);
      return this.getBaseMapper().getCuredNcProgram(partNo,machine.getMachineGroupCode());
      return this.getBaseMapper().getCuredNcProgram(drwaingNo,machine.getMachineGroupCode());
   }
@@ -103,7 +105,7 @@
      prog.setName(file.getOriginalFilename());
      prog.setNcNodeId(uploadVO.getNodeId());
      prog.setOssName(bfile.getName());
      prog.setPartNo(uploadVO.getPartNo());
      prog.setDrawingNo(uploadVO.getDrawingNo());
      prog.setProcessEdition(uploadVO.getProcessEdition());
      prog.setIsLastEdition(1);
      boolean isTextFile = false;
@@ -134,10 +136,11 @@
      prog.setName(file.getOriginalFilename());
      prog.setNcNodeId(uploadVO.getNodeId());
      prog.setOssName(bfile.getName());
      prog.setPartNo(uploadVO.getPartNo());
      prog.setDrawingNo(uploadVO.getDrawingNo());
      prog.setProcessEdition(uploadVO.getProcessEdition());
      prog.setIsLastEdition(1);
      prog.setMachineCode(uploadVO.getMachineCode());
      prog.setProcessName(uploadVO.getProcessName());
      boolean isTextFile = false;
      try {
         isTextFile = FileContentUtil.isTextFile(file.getInputStream());
@@ -153,7 +156,7 @@
      node.setName(prog.getName());
      node.setMachineCode(uploadVO.getMachineCode());
      node.setParentId(uploadVO.getNodeId());
      node.setPartNo(uploadVO.getPartNo());
      node.setDrawingNo(uploadVO.getDrawingNo());
      node.setProcessName(uploadVO.getProcessName());
      nodeService.save(node);
@@ -266,4 +269,50 @@
   public IPage<NcProgramVO> pageQuery(NcNodeProgramQueryVO query) {
      return this.getBaseMapper().pageQuery(Condition.getPage(query),query);
   }
   /**
    * 下发给你机床
    * @param bindNcNodeId 与程序绑定的节点id
    */
   public void sendByBindNodeId(Long bindNcNodeId) throws IOException {
      //NcNode node = this.nodeService.getById(bindNodeId);
      LambdaQueryWrapper<NcProgram> wrapper = new LambdaQueryWrapper<>();
      wrapper.eq(NcProgram::getBindNcNodeId, bindNcNodeId);
      wrapper.eq(NcProgram::getIsLastEdition,1);
      NcProgram prog = this.getOne(wrapper);
      String filePath = prog.getName();
      try(InputStream ins = ossTemplate.statFileStream(prog.getOssName());){
         File targetFile = new File(filePath);
         FileUtils.copyInputStreamToFile(ins, targetFile);
      }
   }
   String getFilePath(NcProgram prog){
      Machine machine = machineService.getByCode(prog.getMachineCode());
      String dirPath = machine.getProgSendDir();
      dirPath = StringUtils.removeEnd(StringUtils.removeEnd(dirPath,"/"),"\\");
      File dirs = new File(dirPath);
      if(!dirs.exists()){
         dirs.mkdirs();
      }
      return dirPath+File.separator+prog.getName();
   }
   /**
    *
    * @param bindNcNodeId
    * @return
    */
   public NcProgram getByBindNodeId(Long bindNcNodeId) {
      LambdaQueryWrapper<NcProgram> wrapper = new LambdaQueryWrapper<>();
      wrapper.eq(NcProgram::getBindNcNodeId, bindNcNodeId);
      wrapper.eq(NcProgram::getIsLastEdition,1);
      Optional<NcProgram> progOpt = this.getOneOpt(wrapper);
      return progOpt.orElse(null);
   }
}