| | |
| | | |
| | | 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.flow.service.CureFlowService; |
| | | import org.springblade.mdm.flow.service.FlowCommonService; |
| | | import org.springblade.mdm.flow.service.FlowProgramFileService; |
| | | import org.springblade.mdm.program.entity.DncBackFile; |
| | | import org.springblade.mdm.program.entity.NcNode; |
| | | 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.EntityUtil; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springblade.mdm.program.vo.DncSendBackFile; |
| | | import org.springblade.mdm.utils.FileContentUtil; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | |
| | | private final OssTemplate ossTemplate; |
| | | private final BladeRedis bladeRedis; |
| | | private final FlowCommonService flowCommonService; |
| | | |
| | | private final DncBackFileService dncBackFileService; |
| | | private final ProgramFlowStatusQueryService programFlowStatusQueryService; |
| | | private String getFileKey(){ |
| | | return "dncexpfile-"+ AuthUtil.getUserId(); |
| | | return "dncimpfile-"+ AuthUtil.getUserId(); |
| | | } |
| | | /** |
| | | * dnc回传文件上传 |
| | |
| | | } |
| | | |
| | | if(!StringUtils.endsWith(file.getOriginalFilename(),".zip")){ |
| | | throw new ServiceException("文件必须为zip包 "); |
| | | throw new ServiceException("文件必须为zip包"); |
| | | } |
| | | try { |
| | | BladeFile bfile = ossTemplate.putFile(file);//上传,供后续入库使用 |
| | | //设置一个缓存,2小时过期 |
| | | bladeRedis.setEx(getFileKey(),bfile.getName(), Duration.ofHours(2)); |
| | | |
| | | InputStream zipFileInputStream = file.getInputStream();//test |
| | | |
| | | //byte[] bytes = FileUtil.copyToByteArray(zipFileInputStream); |
| | | list = parseProgramListFromZip(zipFileInputStream); |
| | | |
| | | try(InputStream zipFileInputStream = ossTemplate.statFileStream(bfile.getName());) { |
| | | //InputStream zipFileInputStream = file.getInputStream();//test |
| | | list = parseProgramListFromZip(zipFileInputStream); |
| | | } |
| | | } catch (IOException e) { |
| | | log.error("上传dnc回传文件失败",e); |
| | | throw new ServiceException("解析DNC回传数据失败"); |
| | |
| | | List<DncSendBackData> list = new ArrayList<>(); |
| | | Path tempZipFile = createTempFile(inputStream); |
| | | |
| | | List<String> fileEntryNameList = new ArrayList<>(); |
| | | List<String> dirEntryNameList = new ArrayList<>();//程序包名+工序版次 作为文件夹名 |
| | | try (ZipFile zipFile = new ZipFile(tempZipFile.toFile())) { |
| | | |
| | | Enumeration<? extends ZipEntry> zipEntries = zipFile.entries(); |
| | | ZipEntry entry; |
| | | Enumeration<? extends ZipEntry> zipEntris = zipFile.entries(); |
| | | while (zipEntris.hasMoreElements()) { |
| | | entry = zipEntris.nextElement(); |
| | | DncSendBackData progData = new DncSendBackData(); |
| | | String entryName = entry.getName(); |
| | | if (entry.isDirectory()){ |
| | | //目录,才是程序包, |
| | | //查询数据库,对应上才能确认时有效的程序包 |
| | | String packageName = StringUtils.removeEnd(entryName,"/"); |
| | | NcNode programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName); |
| | | NcNode curedProgramPkg = ncNodeService.getLastEditionCuredProgramPackage(packageName); |
| | | //获取所有的entry名称 |
| | | while (zipEntries.hasMoreElements()) { |
| | | entry = zipEntries.nextElement(); |
| | | |
| | | if(programPackageNode!=null && curedProgramPkg == null) {//无固化程序,才放入列表 |
| | | //NcNode programPackageNode = pkgList.get(0); |
| | | progData.setId(programPackageNode.getId()); |
| | | progData.setProgramName(packageName); |
| | | |
| | | progData.setFileBackTime(DateUtil.fromInstant(entry.getLastModifiedTime().toInstant())); |
| | | progData.setProgramNo(programPackageNode.getProgramNo()); |
| | | list.add(progData); |
| | | } |
| | | |
| | | if(entry.isDirectory()){ |
| | | dirEntryNameList.add(entry.getName()); |
| | | }else{ |
| | | fileEntryNameList.add(entry.getName()); |
| | | } |
| | | } |
| | | |
| | | NcNode programPackageNode; |
| | | //目录列表,即程序包列表 |
| | | for(String entryName : dirEntryNameList){ |
| | | DncSendBackData progData = new DncSendBackData(); |
| | | 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(entryName)).findFirst(); |
| | | if(optFilename.isPresent()){ |
| | | entry = zipFile.getEntry(optFilename.get()); |
| | | InputStream ins = zipFile.getInputStream(entry); |
| | | progData.setFileBackTime(DateUtil.fromInstant(entry.getLastModifiedTime().toInstant())); |
| | | statusLine = FileContentUtil.readLineAt(ins,2); |
| | | if(statusLine.contains("SQ")){ |
| | | //试切 |
| | | programPackageNode = ncNodeService.getLastEditionTryingProgramPackage(packageName,processEdition); |
| | | }else if(statusLine.contains("GH")){ |
| | | //固化 |
| | | programPackageNode = ncNodeService.getLastEditionCuredProgramPackage(packageName,processEdition); |
| | | }else if(statusLine.contains("PL")){ |
| | | //偏离 |
| | | programPackageNode =ncNodeService.getLastEditionDeviationProgramPackage(packageName,processEdition); |
| | | }else{ |
| | | throw new ServiceException("未找到程序文件中的状态注释"); |
| | | } |
| | | if(programPackageNode != null) { |
| | | progData.setId(programPackageNode.getId()); |
| | | progData.setProgramNo(programPackageNode.getProgramNo()); |
| | | |
| | | List<String> fileEntryNames = fileEntryNameList.stream().filter(n -> n.startsWith(packageName)).toList(); |
| | | List<DncSendBackFile> programFiles = new ArrayList<>(); |
| | | fileEntryNames.forEach( filePath ->{ |
| | | DncSendBackFile backFile = new DncSendBackFile(); |
| | | backFile.setEntryName(filePath); |
| | | backFile.setName(StringUtils.removeStart(filePath,entryName)); |
| | | programFiles.add(backFile); |
| | | }); |
| | | |
| | | progData.setFiles(programFiles); |
| | | list.add(progData); |
| | | }else{ |
| | | throw new ServiceException("找不到程序包名:"+packageName+statusLine); |
| | | } |
| | | }else{ |
| | | throw new ServiceException(entryName+"包下未找到文件"+statusLine); |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | | * 入库回传文件,并启动固化流程 |
| | |
| | | */ |
| | | @Transactional |
| | | public void dncFileAccept(String ids) throws IOException { |
| | | List<Long> idList = Func.toLongList(ids); |
| | | List<Long> acceptIdList = Func.toLongList(ids); |
| | | // |
| | | NcProgramExchange exchange; |
| | | String filekey = getFileKey(); |
| | | String pkgFileName = bladeRedis.get(filekey); |
| | | log.info("filekey={},文件名={}",filekey,pkgFileName); |
| | | String zipFileName = bladeRedis.get(filekey); |
| | | log.info("filekey={},文件名={}",filekey,zipFileName); |
| | | |
| | | Map<Long,List<NcNode>> programPackageSubMap = new HashMap<>(); |
| | | List<NcNode> newProgramPckageList = updateNodeDataByDNCBackData(pkgFileName,idList,programPackageSubMap); |
| | | log.info("需要启动固化流程的程序包名数量:{}",newProgramPckageList.size()); |
| | | for(NcNode pkgNode :newProgramPckageList){ |
| | | //Map<Long,List<NcNode>> programPackageSubMap = new HashMap<>(); |
| | | |
| | | Map<Long,List<FlowProgramFile>> pkgIdFileMap = dealWithBackFile(zipFileName,acceptIdList); |
| | | |
| | | ///List<NcNode> newProgramPackageList = updateNodeDataByDNCBackData(pkgFileName,idList,programPackageSubMap); |
| | | //updateNodeDataByDNCBackData(pkgFileName,idList,programPackageSubMap); |
| | | /* |
| | | log.info("需要启动固化流程的程序包名数量:{}",newProgramPackageList.size()); |
| | | for(NcNode pkgNode :newProgramPackageList){ |
| | | exchange = new NcProgramExchange(); |
| | | exchange.setName(pkgNode.getName()); |
| | | exchange.setExchangeType(2);//回传 |
| | | exchange.setNcNodeId(pkgNode.getId()); |
| | | |
| | | this.save(exchange); |
| | | } |
| | | bladeRedis.del(filekey); |
| | | this.ossTemplate.removeFile(pkgFileName); |
| | | log.info("删除oss文件:{}",pkgFileName); |
| | | }*/ |
| | | //bladeRedis.del(filekey); |
| | | //this.ossTemplate.removeFile(zipFileName); |
| | | //log.info("删除oss文件:{}",zipFileName); |
| | | |
| | | cureFlowService.startCure(newProgramPckageList,programPackageSubMap); |
| | | //cureFlowService.startCure(newProgramPackageList,programPackageSubMap); |
| | | cureFlowService.startCureNew(pkgIdFileMap); |
| | | |
| | | } |
| | | |
| | | /** |
| | | * 处理回传文件 |
| | | * @param ossFileName |
| | | * @param acceptIdList |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | private Map<Long, List<FlowProgramFile>> dealWithBackFile(String ossFileName, List<Long> acceptIdList) throws IOException{ |
| | | Map<Long, List<FlowProgramFile>> pkgIdFileMap = new HashMap<>(); |
| | | |
| | | InputStream inputStream = this.ossTemplate.statFileStream(ossFileName); |
| | | Path tempZipFile = createTempFile(inputStream); |
| | | List<String> entryNameList = new ArrayList<>(); |
| | | |
| | | 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(); |
| | | entryNameList.add(entry.getName()); |
| | | } |
| | | log.info("allentrynames:{}",entryNameList); |
| | | |
| | | List<NcNode> allAcceptPackages = this.ncNodeService.lambdaQuery().in(NcNode::getId,acceptIdList).list(); |
| | | //根据内部文件,读取和分析程序包和程序文件数据 |
| | | List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList(); |
| | | for(String dir : dirList){ |
| | | 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()){ |
| | | throw new ServiceException("找不到程序"+programPackageName); |
| | | } |
| | | |
| | | NcNode packageNode = optPackageNode.get(); |
| | | if(packageNode.hasCured()) { |
| | | throw new ServiceException(programPackageName + "已经固化,请勿重复入库。"); |
| | | } |
| | | |
| | | //检查是否在审批过程中 |
| | | //根据节点信息查询流程 |
| | | boolean active = flowCommonService.isProcessInstanceActive(packageNode.getProcessInstanceId()); |
| | | if(active){ |
| | | throw new ServiceException(programPackageName+"正在审批中,请勿等待审批完成。"); |
| | | } |
| | | |
| | | //验证都过了,保存dncbackFile |
| | | DncBackFile backFile = new DncBackFile(); |
| | | backFile.setNcNodeId(packageNode.getId()); |
| | | backFile.setOssName(ossFileName); |
| | | dncBackFileService.save(backFile); |
| | | |
| | | List<FlowProgramFile> flowFiles = new ArrayList<>(); |
| | | //查找包下的文件数据, |
| | | entryNameList.stream().filter(s -> s.startsWith(dir)).forEach(entryName -> { |
| | | log.info("{}下的文件:{}",dir,entryName); |
| | | |
| | | if(!entryName.endsWith("/")){ |
| | | //实际的文件 |
| | | String fileName = StringUtils.removeStart(entryName,dir);//去除文件名路径部分 |
| | | |
| | | try { |
| | | FlowProgramFile newFlowFile = new FlowProgramFile(); |
| | | newFlowFile.setProgramName(packageNode.getName()); |
| | | newFlowFile.setProcessInstanceId(null);//先置为空,启动流程后设置该值 |
| | | newFlowFile.setFileType("program"); |
| | | newFlowFile.setName(fileName); |
| | | InputStream ins = zipFile.getInputStream(zipFile.getEntry(entryName)); |
| | | BladeFile newOssFile = ossTemplate.putFile("mdm",fileName,ins); |
| | | newFlowFile.setOssName(newOssFile.getName()); |
| | | |
| | | flowFiles.add(newFlowFile); |
| | | } catch (IOException e) { |
| | | throw new RuntimeException(e); |
| | | } |
| | | } |
| | | |
| | | }); |
| | | |
| | | pkgIdFileMap.put(packageNode.getId(),flowFiles); |
| | | } |
| | | |
| | | } |
| | | |
| | | return pkgIdFileMap; |
| | | } |
| | | |
| | | /** |
| | |
| | | * @param programPackageSubMap 新的 程序包节点id -> =文件列表 map,用于回传数据 |
| | | * @throws IOException 访问文件异常 |
| | | */ |
| | | /* |
| | | List<NcNode> updateNodeDataByDNCBackData(String pkgFileName, List<Long> programPackageIdList,Map<Long,List<NcNode>> programPackageSubMap) throws IOException { |
| | | InputStream inputStream = this.ossTemplate.statFileStream(pkgFileName); |
| | | Path tempZipFile = createTempFile(inputStream); |
| | |
| | | |
| | | ZipEntry entry; |
| | | try (java.util.zip.ZipFile zipFile = new java.util.zip.ZipFile(tempZipFile.toFile())) { |
| | | Enumeration<? extends ZipEntry> entris = zipFile.entries(); |
| | | while(entris.hasMoreElements()) { |
| | | entry = entris.nextElement(); |
| | | Enumeration<? extends ZipEntry> entries = zipFile.entries(); |
| | | while(entries.hasMoreElements()) { |
| | | entry = entries.nextElement(); |
| | | entryNameList.add(entry.getName()); |
| | | } |
| | | log.info("allentrynames:{}",entryNameList); |
| | | |
| | | List<NcNode> allAcceptPackages = this.ncNodeService.lambdaQuery().in(NcNode::getId,programPackageIdList).list(); |
| | | //根据内部文件,读取和分析程序包和程序文件数据 |
| | | List<String> dirList = entryNameList.stream().filter(s -> s.endsWith("/")).toList(); |
| | | for(String dir : dirList){ |
| | | String programPackageName = StringUtils.removeEnd(dir,"/"); |
| | | Optional<NcNode> optPackageNode = allAcceptPackages.stream().filter(node -> StringUtils.equals(node.getName(),programPackageName)).findFirst(); |
| | | |
| | | NcNode oriProgramPkg = this.ncNodeService.getLastEditionTryingProgramPackage(programPackageName); |
| | | NcNode curedProgramPkg = ncNodeService.getLastEditionCuredProgramPackage(programPackageName); |
| | | if(curedProgramPkg != null){ |
| | | throw new ServiceException(programPackageName+"已经固化,请勿重复入库。"); |
| | | if(optPackageNode.isEmpty()){ |
| | | throw new ServiceException("找不到程序"+programPackageName); |
| | | } |
| | | if(oriProgramPkg == null){ |
| | | log.warn("文件夹未发现匹配的程序包名{}",dir); |
| | | continue; |
| | | |
| | | NcNode packageNode = optPackageNode.get(); |
| | | if(packageNode.hasCured()) { |
| | | throw new ServiceException(programPackageName + "已经固化,请勿重复入库。"); |
| | | } |
| | | |
| | | //检查是否在审批过程中 |
| | | //根据节点信息查询流程 |
| | | boolean active = flowCommonService.isProcessInstanceActive(oriProgramPkg.getProcessInstanceId()); |
| | | boolean active = flowCommonService.isProcessInstanceActive(packageNode.getProcessInstanceId()); |
| | | if(active){ |
| | | throw new ServiceException(programPackageName+"正在审批中,请勿重复入库。"); |
| | | } |
| | | /* |
| | | if(oriProgramPkg.hasCured()){ |
| | | throw new ServiceException(programPackageName+"已经固化,请勿重复入库。"); |
| | | }*/ |
| | | |
| | | if(!programPackageIdList.contains(oriProgramPkg.getId())){ |
| | | //不在勾选的范围内 |
| | | log.info("{}不在勾选范围内",programPackageName); |
| | | continue; |
| | | } |
| | | NcNode newProgramPkg = new NcNode(); |
| | | BeanUtils.copyProperties(oriProgramPkg, newProgramPkg); |
| | | BeanUtils.copyProperties(packageNode, newProgramPkg); |
| | | EntityUtil.clearBaseProperties(newProgramPkg); |
| | | newProgramPkg.setIsLastEdition(1); |
| | | ncNodeService.save(newProgramPkg); |
| | | newProgramPackageNodeList.add(newProgramPkg); |
| | | |
| | | //旧数据更新为老版本 |
| | | oriProgramPkg.setIsLocked(1);//旧版自动锁定 |
| | | oriProgramPkg.setIsLastEdition(0);; |
| | | ncNodeService.updateById(oriProgramPkg); |
| | | packageNode.setIsLocked(1);//旧版自动锁定 |
| | | packageNode.setIsLastEdition(0);; |
| | | ncNodeService.updateById(packageNode); |
| | | |
| | | //List<FlowProgramFile> newFlowFiles = new ArrayList<>(); |
| | | List<NcNode> newProgramNodes = new ArrayList<>(); |
| | |
| | | if(!entryName.endsWith("/")){ |
| | | //实际的文件 |
| | | String fileName = StringUtils.removeStart(entryName,dir);//去除文件名路径部分 |
| | | NcNode oldProgramNode = this.ncNodeService.getLastEditionProgramFile(fileName,oriProgramPkg.getId()); |
| | | NcNode oldProgramNode = this.ncNodeService.getLastEditionProgramFile(fileName,packageNode.getId()); |
| | | if(oldProgramNode == null){ |
| | | log.info("{}找不到程序文件",entryName); |
| | | return; |
| | | throw new ServiceException(programPackageName+"下找不到程序文件"+fileName); |
| | | } |
| | | |
| | | //创建新版本的程序节点 |
| | | NcNode newProgramNode = new NcNode(); |
| | | BeanUtils.copyProperties(oldProgramNode, newProgramNode); |
| | | EntityUtil.clearBaseProperties(newProgramNode); |
| | | newProgramNode.setIsLastEdition(1); |
| | | newProgramNode.setParentId(newProgramPkg.getId()); |
| | | newProgramNode.setParentIds(newProgramPkg.getParentIds()+","+newProgramPkg.getId()); |
| | | //ncNodeService.save(newProgramNode); |
| | | //将回传文件上传,并记录到数据库 |
| | | |
| | | FlowProgramFile oldFlowFile = flowProgramFileService.getById(newProgramNode.getFlowProgramFileId()); |
| | | |
| | | FlowProgramFile newFlowFile = new FlowProgramFile(); |
| | | BeanUtils.copyProperties(oldFlowFile, newFlowFile); |
| | | newFlowFile.setProcessInstanceId(null); |
| | | newFlowFile.setProcessInstanceId(null);//先置为空,启动流程后设置该值 |
| | | EntityUtil.clearBaseProperties(newFlowFile); |
| | | |
| | | try { |
| | |
| | | newProgramNode.setVersionNumber(oldProgramNode.genNewVersionNumber()); |
| | | newProgramNodes.add(newProgramNode); |
| | | //旧节点处理,咋办?如果导出工控网 重复导出呢?,isLastEdition不用设置了,因为 程序包节点 是新的 |
| | | //TODO 待验证 |
| | | //oldProgramNode.setIsLastEdition(原来是0); |
| | | //oldProgramNode.setIsLocked(1); |
| | | //ncNodeService.updateById(oldProgramNode); |
| | | } |
| | | }); |
| | | |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | return newProgramPackageNodeList; |
| | | } |
| | | |
| | | */ |
| | | /** |
| | | * 创建一个临时zip文件 |
| | | * @param inputStream 文件的输入流 |
| | |
| | | |
| | | return tempFile; |
| | | } |
| | | void setBaseProperties(BizEntity entity, JSONObject jsonObject){ |
| | | entity.setCreateTime(jsonObject.getDate("createTime")); |
| | | entity.setUpdateTime(jsonObject.getDate("updateTime")); |
| | | entity.setStatus(jsonObject.getInteger("status")); |
| | | entity.setCreateUser(jsonObject.getLong("createUser")); |
| | | entity.setUpdateUser(jsonObject.getLong("updateUser")); |
| | | |
| | | /** |
| | | * 获取回传文件的内容 |
| | | * @param entryName 文件在压缩包内的路径 |
| | | * @return 文件内容文本 |
| | | */ |
| | | public String getEntryFileContent(String entryName) throws IOException { |
| | | String result = ""; |
| | | String zipFileName = bladeRedis.get(getFileKey()); |
| | | 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; |
| | | } |
| | | /* |
| | | void clearBaseProperties(BizEntity entity){ |
| | | entity.setId(null); |
| | | entity.setCreateTime(null); |
| | | entity.setUpdateTime(null); |
| | | entity.setStatus(null); |
| | | entity.setCreateUser(null); |
| | | entity.setUpdateUser(null); |
| | | }*/ |
| | | |
| | | } |
| | | |
| | | @Data |
| | | class PackageAndProcessEdition{ |
| | | private String programPackageName; |
| | | private String processEdition; |
| | | |
| | | } |