| | |
| | | import org.apache.commons.io.FileUtils; |
| | | import org.apache.commons.lang3.StringUtils; |
| | | import org.springblade.core.log.exception.ServiceException; |
| | | import org.springblade.core.mp.base.BizEntity; |
| | | import org.springblade.core.mp.base.BizServiceImpl; |
| | | import org.springblade.core.redis.cache.BladeRedis; |
| | | import org.springblade.core.secure.utils.AuthUtil; |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.machine.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.machinefile.entity.FileSendRecord; |
| | | import org.springblade.mdm.machinefile.service.FileSendRecordService; |
| | | import org.springblade.mdm.program.entity.NcProgramExchange; |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.vo.MdmProgramImportVO; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.scheduling.support.SimpleTriggerContext; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | |
| | | @Autowired |
| | | private MachineService machineService; |
| | | |
| | | @Autowired |
| | | private FileSendRecordService fileSendRecordService; |
| | | |
| | | private String getFileKey(){ |
| | | return "mdmgkwimpfile-"+ AuthUtil.getUserId(); |
| | | } |
| | |
| | | |
| | | // 创建解压目标目录(在临时目录下创建一个唯一子目录) |
| | | Path tempZipFile = Files.createTempFile("mdmimpfile-"+System.currentTimeMillis(), ".zip"); |
| | | //Path extractDir = Files.createTempDirectory(tempPath, "unzip_"); |
| | | |
| | | file.transferTo(tempZipFile); |
| | | |
| | |
| | | for (Path subPath : subStream) { |
| | | if (Files.isRegularFile(subPath)) { |
| | | System.out.println("找到文件: " + subPath); |
| | | //files.add(subPath.getFileName().toString()); |
| | | // 这里可以添加对文件的处理逻辑 |
| | | } |
| | | } |
| | | } |
| | |
| | | byte[] buffer = new byte[2000]; |
| | | inputStream.read(buffer); |
| | | vo.setMd5(DigestUtils.md5Hex(buffer)); |
| | | |
| | | |
| | | } catch (IOException e) { |
| | | log.error("读取文件md5失败",e); |
| | | } |
| | |
| | | if (matchedMachine != null) { |
| | | vo.setName(parseProgramName(vo.getFilename())); |
| | | vo.setMachineCode(matchedMachine.getCode()); |
| | | //String sendPath = programAnnotationService.removeAnnotation(matchedMachine.getMachineGroupCode(),line1,"(",")"); |
| | | |
| | | vo.setFullPath(path.toString());//文件地址 |
| | | vo.setSendPath(matchedMachine.getProgSendDir()); |
| | | vo.setId(vo.getFullPath()); |
| | | vo.setProgramStatus(programAnnotationService.removeAnnotation(matchedMachine.getMachineGroupCode(),line2,"(",")")); |
| | | vo.setProgramStatus(programAnnotationService.removeAnnotation(matchedMachine.getControlSystem(),line2)); |
| | | |
| | | list.add(vo); |
| | | } |
| | |
| | | } catch (IOException e) { |
| | | log.error("读取文件md5失败",e); |
| | | } |
| | | |
| | | |
| | | //List<String> files = new ArrayList<>(); |
| | | |
| | | |
| | | // 这里可以添加对文件的处理逻辑 |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | return list; |
| | | } |
| | | |
| | |
| | | |
| | | List<String> idList = Func.toStrList(ids); |
| | | |
| | | String ditStr = bladeRedis.get(getFileKey()); |
| | | Path extractDir = Paths.get(ditStr); |
| | | String dictStr = bladeRedis.get(getFileKey()); |
| | | Path extractDir = Paths.get(dictStr); |
| | | |
| | | List<MdmProgramImportVO> list = readTempDir(extractDir); |
| | | |
| | | String destFileFull; |
| | | for(String str : idList){ |
| | | System.out.println(str); |
| | | //System.out.println(str); |
| | | for(MdmProgramImportVO vo : list){ |
| | | if(StringUtils.equals(vo.getFullPath(),str)){ |
| | | destFileFull = vo.getSendPath()+File.separator+vo.getFilename(); |
| | | File destFile = new File(destFileFull); |
| | | FileUtils.forceMkdirParent(destFile); |
| | | FileUtils.copyFile(new File(str),destFile); |
| | | |
| | | FileSendRecord record = new FileSendRecord(); |
| | | record.setName(destFile.getName()); |
| | | Path destPath = Paths.get(destFileFull); |
| | | record.setMachineCode(vo.getMachineCode()); |
| | | record.setFileSize(Files.size(destPath)); |
| | | fileSendRecordService.save(record); |
| | | break; |
| | | } |
| | | } |