| | |
| | | |
| | | package org.springblade.mdm.program.service; |
| | | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import io.netty.util.internal.StringUtil; |
| | | import lombok.AllArgsConstructor; |
| | | import lombok.Data; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | 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.oss.OssTemplate; |
| | | import org.springblade.core.oss.model.BladeFile; |
| | |
| | | import org.springblade.mdm.program.mapper.NcProgramExchangeMapper; |
| | | import org.springblade.mdm.program.vo.DncSendBackData; |
| | | import org.springblade.mdm.program.vo.DncSendBackFile; |
| | | import org.springblade.mdm.utils.EntityUtil; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | Path tempZipFile = createTempFile(inputStream); |
| | | |
| | | List<String> fileEntryNameList = new ArrayList<>(); |
| | | List<String> dirEntryNameList = new ArrayList<>(); |
| | | List<String> dirEntryNameList = new ArrayList<>();//程序包名+工序版次 作为文件夹名 |
| | | try (ZipFile zipFile = new ZipFile(tempZipFile.toFile())) { |
| | | |
| | | Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); |
| | |
| | | //目录列表,即程序包列表 |
| | | for(String entryName : dirEntryNameList){ |
| | | DncSendBackData progData = new DncSendBackData(); |
| | | String packageName = StringUtils.removeEnd(entryName,"/"); |
| | | String folderName = StringUtils.removeEnd(entryName,"/"); |
| | | |
| | | PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName); |
| | | String packageName = pkgAndEdition.getProgramPackageName(); |
| | | String processEdition = pkgAndEdition.getProcessEdition(); |
| | | if(StringUtils.isBlank(packageName) || StringUtils.isBlank(processEdition)){ |
| | | throw new ServiceException("包内文件夹名格式错误应该为[零组件号-工序号-工序版次]:"+folderName); |
| | | } |
| | | |
| | | progData.setProgramName(packageName); |
| | | String statusLine = ""; |
| | | Optional<String> optFilename = fileEntryNameList.stream().filter(n -> n.startsWith(packageName)).findFirst(); |
| | | Optional<String> optFilename = fileEntryNameList.stream().filter(n -> n.startsWith(entryName)).findFirst(); |
| | | if(optFilename.isPresent()){ |
| | | entry = zipFile.getEntry(optFilename.get()); |
| | | InputStream ins = zipFile.getInputStream(entry); |
| | |
| | | statusLine = FileContentUtil.readLineAt(ins,2); |
| | | if(statusLine.contains("SQ")){ |
| | | //试切 |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName); |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName,processEdition); |
| | | }else if(statusLine.contains("GH")){ |
| | | //固化 |
| | | programPackageNode = ncNodeService.getLastEditionCuredProgramPackage(packageName); |
| | | programPackageNode = ncNodeService.getLastEditionCuredProgramPackage(packageName,processEdition); |
| | | }else if(statusLine.contains("PL")){ |
| | | //偏离 |
| | | programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName); |
| | | programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName,processEdition); |
| | | }else{ |
| | | throw new ServiceException("未找到程序文件中的状态注释"); |
| | | } |
| | |
| | | progData.setId(programPackageNode.getId()); |
| | | progData.setProgramNo(programPackageNode.getProgramNo()); |
| | | |
| | | List<String> fileEtriyNames = fileEntryNameList.stream().filter(n -> n.startsWith(packageName)).toList(); |
| | | List<String> fileEntryNames = fileEntryNameList.stream().filter(n -> n.startsWith(packageName)).toList(); |
| | | List<DncSendBackFile> programFiles = new ArrayList<>(); |
| | | fileEtriyNames.forEach( filePath ->{ |
| | | fileEntryNames.forEach( filePath ->{ |
| | | DncSendBackFile backFile = new DncSendBackFile(); |
| | | backFile.setEntryName(filePath); |
| | | backFile.setName(StringUtils.removeStart(filePath,entryName)); |
| | |
| | | return list; |
| | | } |
| | | |
| | | /** |
| | | * 从文件夹名解析出程序包名和和工序版次 |
| | | * @param folderName 文件夹名 |
| | | * @return 结构数据 |
| | | */ |
| | | PackageAndProcessEdition parseProgramPackageFromFolderName(String folderName){ |
| | | int index = StringUtils.lastIndexOf(folderName,'-'); |
| | | String processEditon = ""; |
| | | String temp; |
| | | String packageName = ""; |
| | | if(index != -1){ |
| | | processEditon = folderName.substring(index+1); |
| | | packageName = folderName.substring(0,index); |
| | | } |
| | | |
| | | PackageAndProcessEdition result = new PackageAndProcessEdition();; |
| | | result.setProgramPackageName(packageName); |
| | | result.setProcessEdition(processEditon); |
| | | return result; |
| | | } |
| | | |
| | | /** |
| | | * 入库回传文件,并启动固化流程 |
| | |
| | | //根据内部文件,读取和分析程序包和程序文件数据 |
| | | List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList(); |
| | | for(String dir : dirList){ |
| | | String programPackageName = StringUtils.removeEnd(dir,"/"); |
| | | String programPackageName1 = StringUtils.removeEnd(dir,"/"); |
| | | String folderName = StringUtils.removeEnd(dir,"/"); |
| | | |
| | | PackageAndProcessEdition pkgAndEdition = parseProgramPackageFromFolderName(folderName); |
| | | String programPackageName = pkgAndEdition.getProgramPackageName(); |
| | | //111 |
| | | |
| | | Optional<NcNode> optPackageNode = allAcceptPackages.stream().filter(node -> StringUtils.equals(node.getName(),programPackageName)).findFirst(); |
| | | |
| | | if(optPackageNode.isEmpty()){ |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | @Data |
| | | class PackageAndProcessEdition{ |
| | | private String programPackageName; |
| | | private String processEdition; |
| | | |
| | | } |