| | |
| | | import org.springblade.core.tool.utils.Func; |
| | | import org.springblade.mdm.basesetting.machine.entity.Machine; |
| | | import org.springblade.mdm.basesetting.machine.service.MachineService; |
| | | import org.springblade.mdm.basesetting.producedivision.entity.QinzheFgb; |
| | | import org.springblade.mdm.basesetting.producedivision.service.QinzheFgbService; |
| | | import org.springblade.mdm.commons.contants.RegExpConstants; |
| | | import org.springblade.mdm.commons.service.ParamService; |
| | | import org.springblade.mdm.flow.entity.FlowProgramFile; |
| | | import org.springblade.mdm.flow.service.CureFlowService; |
| | |
| | | import org.springblade.mdm.program.vo.DncSendBackFile; |
| | | import org.springblade.mdm.program.vo.ProgramAnnotation; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springblade.mdm.utils.ProgramFileNameParser; |
| | | import org.springblade.mdm.utils.ZipTextFileContentUtil; |
| | | import org.springblade.system.pojo.entity.DictBiz; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | import java.nio.file.StandardOpenOption; |
| | | import java.time.Duration; |
| | | import java.util.*; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipFile; |
| | | |
| | |
| | | @AllArgsConstructor |
| | | public class DNCSendBackService extends BizServiceImpl<NcProgramExchangeMapper, NcProgramExchange> { |
| | | private final CureFlowService cureFlowService; |
| | | private final ProgramAnnotationService programAnnotationService; |
| | | private final QinzheFgbService qinzheFbgService; |
| | | private final NcNodeService ncNodeService; |
| | | private final OssTemplate ossTemplate; |
| | | private final BladeRedis bladeRedis; |
| | |
| | | } |
| | | } |
| | | |
| | | List<DictBiz> annotionDictList = programAnnotationService.getAnnotionDictList(); |
| | | NcNode programPackageNode; |
| | | //目录列表,即程序包列表 |
| | | for(String entryName : dirEntryNameList){ |
| | | DncSendBackData progData = new DncSendBackData(); |
| | | String packageName = StringUtils.removeEnd(entryName,"/"); |
| | | |
| | | progData.setProgramName(packageName); |
| | | Optional<String> optFilename = fileEntryNameList.stream().filter(n -> n.startsWith(entryName)).findFirst(); |
| | | if(optFilename.isPresent()){ |
| | | entry = zipFile.getEntry(optFilename.get()); |
| | | InputStream ins = zipFile.getInputStream(entry); |
| | | ByteArrayInputStream bais = new ByteArrayInputStream(IOUtils.toByteArray(ins));; |
| | | ByteArrayInputStream byteArrayIns = new ByteArrayInputStream(IOUtils.toByteArray(ins)); |
| | | |
| | | //解析机床 |
| | | progData.setFileBackTime(DateUtil.fromInstant(entry.getLastModifiedTime().toInstant())); |
| | | |
| | | AnnotationProperties defAnnoProperties =AnnotationProperties.getDefault(); |
| | | String statusLine = FileContentUtil.readLineAt(bais,defAnnoProperties.getStatusLineIndex());//状态注释行 |
| | | bais.reset(); |
| | | String sendPathLine = FileContentUtil.readLineAt(bais,defAnnoProperties.getSendPathLineIndex());//状态注释行 |
| | | bais.reset(); |
| | | String statusLine = FileContentUtil.readLineAt(byteArrayIns,defAnnoProperties.getStatusLineIndex());//状态注释行 |
| | | byteArrayIns.reset(); |
| | | String sendPathLine = FileContentUtil.readLineAt(byteArrayIns,defAnnoProperties.getSendPathLineIndex());//状态注释行 |
| | | byteArrayIns.reset(); |
| | | |
| | | if(statusLine.contains("GH")){ |
| | | if(statusLine.contains(AnnotationUtil.GH)){ |
| | | //固化,不应回传,忽略 |
| | | log.warn("状态{},不应回传,忽略",statusLine); |
| | | continue; |
| | |
| | | if(machine == null){ |
| | | throw new ServiceException("根据下发路径未找到程序对应的机床:"+sendPathLine); |
| | | } |
| | | |
| | | progData.setProgramName(packageName); |
| | | |
| | | if(statusLine.contains(AnnotationUtil.SQ)){ |
| | | //试切 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 从文件夹名解析出程序包名和和工序版次 |
| | | * @param folderName 文件夹名 |
| | | * @return 结构数据 |
| | | * 修复程序包名,fanuc不识别下划线,下发时转换为了-,这里需要确认。应该是从导出记录中查找修改后的包名,但是现场编制的没有咋办? |
| | | * @param packageNameInZip |
| | | * @return |
| | | */ |
| | | /* |
| | | PackageAndProcessEdition parseProgramPackageFromFolderName(String folderName){ |
| | | int index = StringUtils.lastIndexOf(folderName,'-'); |
| | | String processEditon = ""; |
| | | String packageName = ""; |
| | | if(index != -1){ |
| | | processEditon = folderName.substring(index+1); |
| | | packageName = folderName.substring(0,index); |
| | | private String fixProgramPackageName(String packageNameInZip) { |
| | | Matcher matcher = RegExpConstants.PROGRAM_PACKAGE_PATTERN.matcher(packageNameInZip); |
| | | |
| | | String drawingNo = null; |
| | | if(matcher.find()) { |
| | | drawingNo = matcher.group(1); |
| | | } |
| | | String processNo = null; |
| | | if(matcher.find()) { |
| | | processNo = matcher.group(2); |
| | | } |
| | | |
| | | PackageAndProcessEdition result = new PackageAndProcessEdition();; |
| | | result.setProgramPackageName(packageName); |
| | | result.setProcessEdition(processEditon); |
| | | return result; |
| | | }*/ |
| | | String processEdition = null; |
| | | if(matcher.find()) { |
| | | processEdition = matcher.group(3); |
| | | } |
| | | if(drawingNo != null && processNo != null && processEdition != null) { |
| | | if(drawingNo.contains("_")) { |
| | | |
| | | } |
| | | } |
| | | return packageNameInZip; |
| | | } |
| | | */ |
| | | |
| | | /** |
| | | * 入库回传文件,并启动固化流程 |
| | |
| | | String zipFileName = bladeRedis.get(getFileKey()); |
| | | return ZipTextFileContentUtil.getTextContent(this.ossTemplate.statFileStream(zipFileName),entryName); |
| | | |
| | | /* |
| | | try(InputStream inputStream = this.ossTemplate.statFileStream(zipFileName);){ |
| | | Path tempZipFile = createTempFile(inputStream); |
| | | |
| | | ZipEntry entry; |
| | | try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(tempZipFile.toFile())) { |
| | | Enumeration<? extends ZipEntry> entries = zipFile.entries(); |
| | | while (entries.hasMoreElements()) { |
| | | entry = entries.nextElement(); |
| | | if (!entryName.equals(entry.getName())) { |
| | | continue; |
| | | } |
| | | try (InputStream fileIns = zipFile.getInputStream(zipFile.getEntry(entryName))) { |
| | | ByteArrayInputStream bos = new ByteArrayInputStream(fileIns.readAllBytes()); |
| | | boolean isText = StringUtils.endsWithIgnoreCase(entryName,".txt") || StringUtils.endsWithIgnoreCase(entryName,".nc")|| StringUtils.endsWithIgnoreCase(entryName,".xml"); |
| | | if(!isText) { |
| | | isText = FileContentUtil.isTextFile(bos); |
| | | } |
| | | if (isText) { |
| | | bos.reset(); |
| | | result = FileContentUtil.getContentFromStream(bos); |
| | | } else { |
| | | result = "<非文本文件>"; |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | return result;*/ |
| | | } |
| | | |
| | | } |
| | |
| | | return programPackageName+"-"+processEdition; |
| | | } |
| | | } |
| | | |