| | |
| | | import org.springblade.core.mp.support.Condition; |
| | | import org.springblade.core.mp.support.Query; |
| | | import org.springblade.core.tool.utils.FileUtil; |
| | | import org.springblade.mdm.basesetting.machine.vo.MachineVO; |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springblade.mdm.utils.CustomBinaryReader; |
| | | import org.springblade.mdm.utils.FileExchangeUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.IOException; |
| | | import java.io.InputStream; |
| | | import java.io.*; |
| | | import java.nio.file.Files; |
| | | import java.nio.file.Path; |
| | | import java.nio.file.Paths; |
| | | import java.util.ArrayList; |
| | | import java.util.Collections; |
| | | import java.util.Enumeration; |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * 下发/回传程序统计 |
| | | * 程序交换(dnc导入/导出) |
| | | * |
| | | * @author yangys |
| | | */ |
| | |
| | | |
| | | /** |
| | | * dnc回传文件上传 |
| | | * @param file |
| | | * @param file 文件 |
| | | * @return |
| | | */ |
| | | public void dncSendBackUpload(MultipartFile file) { |
| | | List<DncSendBackData> list=new ArrayList<>(); |
| | | public List<DncSendBackData> dncSendBackUpload(MultipartFile file) { |
| | | List<DncSendBackData> list ; |
| | | try { |
| | | String fileName = file.getOriginalFilename(); |
| | | InputStream fileInputStream = file.getInputStream(); |
| | | |
| | | byte[] bytes = FileUtil.copyToByteArray(fileInputStream); |
| | | //InputStream fileInputStream = file.getInputStream(); |
| | | InputStream zipFileInputStream = FileExchangeUtil.convertFileToZip(file.getInputStream()); |
| | | byte[] bytes = FileUtil.copyToByteArray(zipFileInputStream); |
| | | list = parseDncZipFromByteArray(bytes); |
| | | for(DncSendBackData dncSendBackData:list){ |
| | | NcProgramExchange exchange=new NcProgramExchange(); |
| | |
| | | |
| | | } catch (IOException e) { |
| | | log.error("上传dnc文件失败",e); |
| | | list = Collections.emptyList(); |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | InputStream convertFileToZip(InputStream inputStream) throws IOException { |
| | | |
| | | File tempFile = createTempFile(); |
| | | FileOutputStream fos = new FileOutputStream(tempFile); |
| | | CustomBinaryReader.read(inputStream,fos); |
| | | |
| | | |
| | | FileInputStream dInstream = new FileInputStream(tempFile); |
| | | |
| | | return dInstream; |
| | | } |
| | | |
| | | /** |
| | | * 创建一个临时文件 |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | File createTempFile() throws IOException { |
| | | Path tempDir = Paths.get(System.getProperty("java.io.tmpdir")); |
| | | // 在临时目录中创建文件 |
| | | String tfilename = "t"+System.currentTimeMillis(); |
| | | Path tempFile = Files.createTempFile(tempDir, tfilename, ".tmp"); |
| | | System.out.println("创建的临时文件: " + tempFile); |
| | | return tempFile.toFile(); |
| | | } |
| | | public static List<DncSendBackData> parseDncZipFromByteArray(byte[] zipData) throws IOException { |
| | | //List<DncSendBackData> datas = new ArrayList<>(); |
| | | List<DncSendBackData> datas = ZipFileDirectoryScanner.getFilesInDirectoryRecursive(zipData, ""); |
| | |
| | | * @param query 查询参数 |
| | | * @return |
| | | */ |
| | | |
| | | public IPage<DncSendBackData> dncSendBackPageQuery(Query query) { |
| | | |
| | | IPage<DncSendBackData> page = this.getBaseMapper().dncSendBackpageQuery(Condition.getPage(query),query); |