| | |
| | | package org.springblade.mdm.machineback.filewatch; |
| | | |
| | | import lombok.SneakyThrows; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.springblade.core.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | | import org.springblade.mdm.machineback.entity.MachineBackFile; |
| | | import org.springblade.mdm.machineback.service.MachineBackFileService; |
| | | import org.springblade.mdm.program.entity.NcProgram; |
| | | import org.springblade.mdm.program.service.NcProgramService; |
| | | |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | | import java.nio.file.Path; |
| | | |
| | |
| | | public class MachineFileBackListener implements FileWatcherService.FileChangeListener{ |
| | | private final MachineBackFileService machineBackFileService; |
| | | private final NcProgramService ncProgramService; |
| | | public MachineFileBackListener(MachineBackFileService backService, NcProgramService aNcProgramService) { |
| | | private final OssTemplate ossTemplate; |
| | | public MachineFileBackListener(MachineBackFileService backService, NcProgramService aNcProgramService,OssTemplate aOssTemplate) { |
| | | this.machineBackFileService = backService; |
| | | this.ncProgramService = aNcProgramService; |
| | | this.ossTemplate = aOssTemplate; |
| | | } |
| | | @Override |
| | | public void onFileCreated(Path filePath) { |
| | |
| | | return; |
| | | } |
| | | backFile.setNcProgramId(prog.getId()); |
| | | |
| | | //更新程序的文件地址 |
| | | try(FileInputStream fins = new FileInputStream(filePath.toFile());){ |
| | | BladeFile bfile = ossTemplate.putFile(programName, fins); |
| | | backFile.setOssName(bfile.getName()); |
| | | } |
| | | |
| | | |
| | | machineBackFileService.save(backFile); |
| | | }else{ |
| | | log.warn("文件传输中,后续再操作{}",filePath); |
| | |
| | | log.error("回传文件操作IO错误",e); |
| | | throw new RuntimeException(e); |
| | | } catch (InterruptedException e) { |
| | | log.error("sleep出错"); |
| | | log.error("sleep出错",e); |
| | | } catch (Exception e) { |
| | | log.error("机床回传文件处理异常",e); |
| | | } |