From 4c7296d45efe849dc70a3b2e2240c905481a91c9 Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期一, 29 九月 2025 17:44:46 +0800
Subject: [PATCH] 工控网涉密网联调

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java |  598 +++++++++++++++++++++++++++++++----------------------------
 1 files changed, 311 insertions(+), 287 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
index 25af59b..6f91428 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/program/service/MdmProgramImportService.java
@@ -1,375 +1,399 @@
 
 package org.springblade.mdm.program.service;
 
-import com.alibaba.fastjson.JSONArray;
-import com.alibaba.fastjson.JSONObject;
-import lombok.AllArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.codec.digest.DigestUtils;
-import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
-import org.apache.commons.compress.archivers.zip.ZipFile;
-import org.apache.commons.compress.utils.SeekableInMemoryByteChannel;
-import org.springblade.core.mp.base.BizEntity;
+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.BizServiceImpl;
 import org.springblade.core.oss.OssTemplate;
 import org.springblade.core.oss.model.BladeFile;
 import org.springblade.core.redis.cache.BladeRedis;
 import org.springblade.core.secure.utils.AuthUtil;
-import org.springblade.core.tool.utils.FileUtil;
 import org.springblade.core.tool.utils.Func;
-import org.springblade.core.tool.utils.IoUtil;
-import org.springblade.mdm.flow.entity.ApproveRecord;
-import org.springblade.mdm.flow.service.ApproveRecordService;
-import org.springblade.mdm.flow.service.CureFlowService;
-import org.springblade.mdm.program.entity.NcNode;
-import org.springblade.mdm.program.entity.NcProgram;
+import org.springblade.mdm.basesetting.machine.service.MachineService;
+import org.springblade.mdm.basesetting.machine.entity.Machine;
+import org.springblade.mdm.commons.contants.ZipConstants;
+import org.springblade.mdm.gkw.programnode.vo.ProgramNameVO;
+import org.springblade.mdm.gkw.task.entity.MachineBackTask;
+import org.springblade.mdm.gkw.task.service.MachineBackTaskService;
+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.service.programannotation.*;
 import org.springblade.mdm.program.vo.MdmProgramImportVO;
-import org.springblade.mdm.utils.CustomBinaryReader;
+import org.springblade.mdm.utils.FileContentUtil;
+import org.springblade.mdm.utils.ProgramFileNameParser;
+import org.springblade.system.pojo.entity.DictBiz;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.*;
+import java.nio.charset.Charset;
+import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.time.Duration;
 import java.util.*;
-
+import java.nio.file.*;
+import java.util.stream.Stream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
 /**
  * MDM绋嬪簭瀵煎叆锛堝伐鎺х綉鍔熻兘锛�
- *
+ * 鐩墠宸ユ帶缃戝睍鐜板舰寮忔湭瀹氾紝鏆傛椂瀹炵幇鏆傚仠
  * @author yangys
  */
 @Slf4j
 @Service
-@AllArgsConstructor
 public class MdmProgramImportService extends BizServiceImpl<NcProgramExchangeMapper, NcProgramExchange> {
-	private final CureFlowService cureFlowService;
-	private final NcProgramService ncProgramService;
-	private final NcNodeService ncNodeService;
-	private final ApproveRecordService approveRecordService;
-	private final BladeRedis bladeRedis;
-	private final OssTemplate ossTemplate;
+	@Autowired
+	private BladeRedis bladeRedis;
+	@Autowired
+	private ProgramAnnotationService programAnnotationService;
+	@Autowired
+	private MachineService machineService;
+	@Autowired
+	private FileSendRecordService fileSendRecordService;
+	@Autowired
+	private OssTemplate ossTemplate;
+	@Autowired
+	private AnnotationProcessorHelper annotationProcessorHelper;
+	@Autowired
+	private MachineBackTaskService machineBackTaskService;
 
 	private String getFileKey(){
-		return "mdmimpfile-"+ AuthUtil.getUserId();
+		return "mdmgkwimpfile-"+ AuthUtil.getUserId();
 	}
 	/**
-	 * MDM瀵煎叆鏂囦欢涓婁紶
+	 * 宸ユ帶MDM瀵煎叆鏂囦欢涓婁紶
 	 * @param file MDM娑夊瘑缃戝鍑烘枃浠�
 	 * @return
 	 */
 	public List<MdmProgramImportVO> mdmImportUpload(MultipartFile file) {
 		List<MdmProgramImportVO> list;
 		try {
-			BladeFile bfile = ossTemplate.putFile(file);//涓婁紶锛屼緵鍚庣画鍏ュ簱浣跨敤
+			if(file == null || file.isEmpty()){
+				throw new ServiceException("鏂囦欢涓虹┖");
+			}
+			/*
+			if(!StringUtils.endsWith(file.getOriginalFilename(),".zip")){
+				throw new ServiceException("鏂囦欢蹇呴』涓簔ip鍖�");
+			}*/
+			String tempDir = System.getProperty("java.io.tmpdir");
+			Path tempPath = Paths.get(tempDir);
+			Path extractDir = Files.createTempDirectory(tempPath, "unzip_"+System.currentTimeMillis());
+			bladeRedis.setEx(getFileKey(),extractDir.toString(), Duration.ofHours(2));
+			if(StringUtils.endsWithIgnoreCase(file.getOriginalFilename(),".zip")){
+				// 鍒涘缓瑙e帇鐩爣鐩綍锛堝湪涓存椂鐩綍涓嬪垱寤轰竴涓敮涓�瀛愮洰褰曪級
+				Path tempZipFile = Files.createTempFile("mdmimpfile-"+System.currentTimeMillis(), ".zip");
+				file.transferTo(tempZipFile);
+				extractZipToTempDir(tempZipFile,extractDir);
+			}else{
+				//鏅�氭枃浠讹紝鐩存帴鏀惧叆extract鏂囦欢澶�
+				file.transferTo(Paths.get(extractDir.toString()+File.separator+file.getOriginalFilename()));
+			}
 
-			//璁剧疆涓�涓紦瀛橈紝2灏忔椂杩囨湡
-			bladeRedis.setEx(getFileKey(),bfile.getName(), Duration.ofHours(2));
-			String pkgFileName = bladeRedis.get(getFileKey());
-			//String fileName = file.getOriginalFilename();
-			//InputStream zipFileInputStream = FileExchangeUtil.convertFileToZip(file.getInputStream());
-			InputStream zipFileInputStream = file.getInputStream();//test
-
-			byte[] bytes = FileUtil.copyToByteArray(zipFileInputStream);
-			list = parseMdmZipFromByteArray(bytes);
-
-
+			//璇诲彇鏂囦欢鐩綍
+			list = readTempDir(extractDir);
 		} catch (IOException e) {
-			log.error("涓婁紶dnc鍥炰紶鏂囦欢澶辫触",e);
-			list = Collections.emptyList();
+			log.error("瀵煎叆娑夊瘑缃戞憜娓℃枃浠跺け璐�",e);
+			throw new ServiceException("瑙f瀽DNC鍥炰紶鏁版嵁澶辫触");
 		}
 		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
+	 * 瑙e帇zip鍖呭埌涓存椂璺緞
+	 * @param zipFilePath zip鍖呮枃浠舵湇鍔″櫒涓婄殑璺緞
+	 * @param extractDir 鐩爣鐩綍
+	 * @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 void extractZipToTempDir(Path zipFilePath,Path extractDir) throws IOException{
+		for (String encoding : ZipConstants.TRY_ENCODINGS) {
+			try {
+				extractZipToTempDirWithCharset(zipFilePath,extractDir,Charset.forName(encoding));
+				log.error("浣跨敤缂栫爜 {} 瑙f瀽鎴愬姛 ",encoding);
+				break;
+			} catch (Exception e) {
+				log.error("浣跨敤缂栫爜 {} 瑙f瀽澶辫触: ",encoding,e);
+			}
+		}
 	}
-	public static List<MdmProgramImportVO> parseMdmZipFromByteArray(byte[] zipData) throws IOException {
-		List<MdmProgramImportVO> list = new ArrayList<>();
-		Map<String,String> fileMd5Map = new HashMap<>();
-		Map<String,MdmProgramImportVO> fileDataMap = new HashMap<>();
-		try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(zipData);
-			 ZipFile zipFile = new ZipFile(channel)) {
+	public void extractZipToTempDirWithCharset(Path zipFilePath, Path extractDir, Charset charset) throws IOException {
+		// 鑾峰彇绯荤粺涓存椂鐩綍
+		String tempDir = System.getProperty("java.io.tmpdir");
 
-			ZipArchiveEntry entry;
-			Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
-			while (entries.hasMoreElements()) {
-				entry = entries.nextElement();
+		// 鍒涘缓瑙e帇鐩爣鐩綍锛堝湪涓存椂鐩綍涓嬪垱寤轰竴涓敮涓�瀛愮洰褰曪級
+		try (InputStream fis = Files.newInputStream(zipFilePath);
+			 ZipInputStream zis = new ZipInputStream(fis,charset)) {
 
-				String entryName = entry.getName();
+			ZipEntry zipEntry = zis.getNextEntry();
+			while (zipEntry != null) {
+				Path newPath = zipSlipProtect(zipEntry, extractDir);
 
-				if (!entry.isDirectory()) {
-					//鐩存帴瑙f瀽绋嬪簭鐨刯son鏂囦欢
-					if(entryName.equals(NcProgramExportDNCService.PROGRAM_JSON_FILE)){
-
-						try (InputStream inputStream = zipFile.getInputStream(entry)) {
-							String jsonStr = IoUtil.readToString(inputStream);
-
-							JSONArray jsonArray = JSONArray.parseArray(jsonStr);
-							for(int i=0;i<jsonArray.size();i++){
-								JSONObject jsonObject = jsonArray.getJSONObject(i);
-								MdmProgramImportVO d = new MdmProgramImportVO();
-								d.setName(jsonObject.getString("name"));
-								d.setId(jsonObject.getLong("id"));
-								d.setCode(jsonObject.getString("code"));
-								d.setDescription(jsonObject.getString("description"));
-								d.setCategory(jsonObject.getString("category"));
-								d.setBindNcNodeId(jsonObject.getLong("bindNcNodeId"));
-								d.setIsLastEdition(jsonObject.getInteger("isLastEdition"));
-								d.setIsLocked(jsonObject.getInteger("isLocked"));
-								d.setIsTest(jsonObject.getInteger("isTest"));
-								d.setMachineCode(jsonObject.getString("machineCode"));
-								d.setNcNodeId(jsonObject.getLong("ncNodeId"));
-								d.setDrawingNo(jsonObject.getString("drawingNo"));
-								d.setProcessEdition(jsonObject.getString("processEdition"));
-
-								fileDataMap.put(d.getName(),d);
-
-								list.add(d);
-							}
-
-						}
-					}else{
-						try (InputStream inputStream = zipFile.getInputStream(entry)) {
-							fileMd5Map.put(entryName,DigestUtils.md5Hex(inputStream));//鑾峰彇鏂囦欢MD5
-						}
-
+				if (zipEntry.isDirectory()) {
+					Files.createDirectories(newPath);
+				} else {
+					// 纭繚鐖剁洰褰曞瓨鍦�
+					if (newPath.getParent() != null) {
+						Files.createDirectories(newPath.getParent());
 					}
 
+					// 鍐欏叆鏂囦欢
+					try (OutputStream fos = Files.newOutputStream(newPath)) {
+						byte[] buffer = new byte[1024];
+						int len;
+						while ((len = zis.read(buffer)) > 0) {
+							fos.write(buffer, 0, len);
+						}
+					}
 				}
-
+				zipEntry = zis.getNextEntry();
 			}
-
+			zis.closeEntry();
 		}
-		//璁剧疆md5鍊�
-		fileDataMap.forEach((k,v)->{
-			if(fileMd5Map.containsKey(k)){
-				v.setMd5(fileMd5Map.get(k));
-			}
-		});
-		return list;
 	}
 
+	/**
+	 * 闃叉ZIP Slip鏀诲嚮
+	 * @param zipEntry zip鍐呴儴鏂囦欢璺緞
+	 * @param targetDir 鐩爣鏂囦欢澶�
+	 * @return 鏂囦欢璺緞
+	 * @throws IOException 鎿嶄綔鏂囦欢IO寮傚父
+	 */
+	Path zipSlipProtect(ZipEntry zipEntry, Path targetDir) throws IOException {
+		Path targetDirResolved = targetDir.resolve(zipEntry.getName());
+
+		// 瑙勮寖鍖栬矾寰�
+		Path normalizePath = targetDirResolved.normalize();
+
+		if (!normalizePath.startsWith(targetDir)) {
+			throw new IOException("鎭舵剰ZIP鏉$洰: " + zipEntry.getName());
+		}
+
+		return normalizePath;
+	}
+
+	/**
+	 * 璇诲彇瑙e帇鏂囦欢澶逛笅鎵�鏈夋枃浠� 瑙f瀽鎴恦o鍒楄〃
+	 * @param extractDir 瑙e帇鏂囦欢澶�
+	 * @return vo鍒楄〃
+	 * @throws IOException 瑙f瀽鏂囦欢鐨勫紓甯�
+	 */
+	public List<MdmProgramImportVO> readTempDir(Path extractDir) throws IOException {
+		List<MdmProgramImportVO> list = new ArrayList<>();
+		try (Stream<Path> paths = Files.walk(extractDir)) {
+			List<Path> filePathList = paths
+				.filter(Files::isRegularFile).toList();  // 鍙繚鐣欐櫘閫氭枃浠讹紝鎺掗櫎鐩綍
+
+			for(Path path : filePathList){
+				list.add(readFileToVO(path));
+			}
+		}
+		/*
+		//璇诲彇鎵�鏈夋枃浠跺す
+		try (DirectoryStream<Path> stream = Files.newDirectoryStream(extractDir)) {
+			for (Path path : stream) {
+				if (Files.isDirectory(path)) {
+					// 濡傛灉鏄瓙鐩綍锛岃鍙栧叾涓殑鏂囦欢
+					try (DirectoryStream<Path> subStream = Files.newDirectoryStream(path)) {
+						for (Path subPath : subStream) {
+							if (Files.isRegularFile(subPath)) {
+								System.out.println("鎵惧埌鏂囦欢: " + subPath);
+							}
+						}
+					}
+				} else if (Files.isRegularFile(path)) {
+					System.out.println("鎵惧埌鏂囦欢2: " + path);
+					//杩欓噷 鎵惧埌鐨勬枃浠朵笉鏄�
+					list.add(readFileToVO(path));
+				}
+			}
+		}*/
+		return list;
+	}
+	public static byte[] getUTF8BytesFromGBKString(String gbkStr) {
+		int n = gbkStr.length();
+		byte[] utfBytes = new byte[3 * n];
+		int k = 0;
+		for (int i = 0; i < n; i++) {
+			int m = gbkStr.charAt(i);
+			if (m < 128 && m >= 0) {
+				utfBytes[k++] = (byte) m;
+				continue;
+			}
+			utfBytes[k++] = (byte) (0xe0 | (m >> 12));
+			utfBytes[k++] = (byte) (0x80 | ((m >> 6) & 0x3f));
+			utfBytes[k++] = (byte) (0x80 | (m & 0x3f));
+		}
+		if (k < utfBytes.length) {
+			byte[] tmp = new byte[k];
+			System.arraycopy(utfBytes, 0, tmp, 0, k);
+			return tmp;
+		}
+		return utfBytes;
+	}
+
+	ProgramNameVO tryParseProgramName(String fiilename){
+		ProgramNameVO pnmameVO = ProgramFileNameParser.parseProgramName(fiilename);//鏍囧噯utf8缂栫爜
+		if(pnmameVO.getDrawingNo() == null) {
+			//浣跨敤GBK缂栫爜瑙f瀽
+			pnmameVO = ProgramFileNameParser.parseProgramName(new String(getUTF8BytesFromGBKString(fiilename), StandardCharsets.UTF_8));
+		}
+		return pnmameVO;
+	}
+	/**
+	 * 灏嗘枃浠剁粍缁囨垚VO
+	 * @param path 鏂囦欢path
+	 * @return vo
+	 */
+	MdmProgramImportVO readFileToVO(Path path) throws UnsupportedEncodingException {
+		MdmProgramImportVO vo = new MdmProgramImportVO();
+		vo.setFilename(path.getFileName().toString());
+
+		ProgramNameVO progNmameVO = tryParseProgramName(vo.getFilename());
+		vo.setDrawingNo(progNmameVO.getDrawingNo());
+
+		try (InputStream inputStream = Files.newInputStream(path)) {
+			// 浣跨敤杈撳叆娴佽鍙栨枃浠跺唴瀹�
+			byte[] buffer = new byte[2000];
+			inputStream.read(buffer);
+			vo.setMd5(DigestUtils.md5Hex(buffer));
+		} catch (IOException e) {
+			log.error("璇诲彇鏂囦欢md5澶辫触",e);
+		}
+
+		try (InputStream inputStream = Files.newInputStream(path, StandardOpenOption.READ)) {
+			// 浣跨敤杈撳叆娴佽鍙栨枃浠跺唴瀹�
+			ByteArrayInputStream bas = new ByteArrayInputStream(inputStream.readAllBytes());
+
+			AnnotationProperties defAnnoProperties = AnnotationProperties.getDefault();
+			String sendPathLine = FileContentUtil.readLineAt(bas,defAnnoProperties.getSendPathLineIndex());
+
+			bas.reset();
+			String statusLine = FileContentUtil.readLineAt(bas,defAnnoProperties.getStatusLineIndex());
+			log.info("sendPathLine={}", sendPathLine);
+
+			Machine matchedMachine = machineService.getMachineBySendPathAnnotation(sendPathLine);
+
+			if (matchedMachine != null) {
+				vo.setName(progNmameVO.logicProgramName());
+				vo.setMachineCode(matchedMachine.getCode());
+
+				vo.setFullPath(path.toString());//鏂囦欢鍦板潃
+				vo.setSendPath(matchedMachine.getProgSendDir());
+				vo.setId(vo.getFullPath());
+				vo.setProgramStatus(programAnnotationService.removeAnnotation(matchedMachine.getControlSystem(),statusLine));
+			}
+		} catch (IOException e) {
+			log.error("璇诲彇鏂囦欢澶辫触",e);
+			throw new ServiceException("瀵煎叆绋嬪簭澶辫触"+path.getFileName().toString()+","+e.getMessage());
+		}
+		return vo;
+	}
 
 	/**
 	 * 鍏ュ簱mdm娑夊瘑缃戞枃浠�
 	 * @param ids id鍒楄〃閫楀彿鍒嗛殧
-	 * @return
 	 */
 	public void mdmFileAccept(String ids) throws IOException {
 
-		String pkgFileName = bladeRedis.get(getFileKey());
+		List<FileSendRecord>  importedRecords = new ArrayList<>();
+		List<String> idList = Func.toStrList(ids);
 
-		List<Long> idList = Func.toLongList(ids);
-		//
-		updateProgramFile(pkgFileName,idList);
+		String dictStr = bladeRedis.get(getFileKey());
+		if(dictStr == null){
+			throw new ServiceException("鏂囦欢缂撳瓨宸茶繃鏈燂紝璇烽噸鏂颁笂浼犳枃浠躲��");
+		}
+		Path extractDir = Paths.get(dictStr);
+		List<MdmProgramImportVO> list = readTempDir(extractDir);
 
-		List<NcProgram> progList = ncProgramService.listByIds(idList);
-		NcProgramExchange exchange;
+		//List<DictBiz> annoDictList = programAnnotationService.getAnnotionDictList();
+		String destFileFull;
+		for(String str : idList){
+			Optional<MdmProgramImportVO> optVO = list.stream().filter(vo -> vo.getId().equals(str)).findFirst();
 
-		for(NcProgram prog:progList){
-			exchange = new NcProgramExchange();
-			exchange.setName(prog.getName());
-			exchange.setExchangeType(2);//鍥炰紶
-			exchange.setNcProgramId(prog.getId());
+			if(optVO.isEmpty()){
+				continue;
+			}
 
+			MdmProgramImportVO vo = optVO.get();
 
-			this.save(exchange);
+			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));
+
+			try(InputStream inputStream = new FileInputStream(destFile)){
+				BladeFile bFile = ossTemplate.putFile(record.getName(), inputStream);
+				record.setOssName(bFile.getName());
+			}
+
+			try(InputStream inputStream = ossTemplate.statFileStream(record.getOssName())){
+				//璇诲彇绋嬪簭鐘舵��
+				Machine machine = this.machineService.getByCode(record.getMachineCode());
+				AnnotationProcessor processor = annotationProcessorHelper.getProcessor(machine.getControlSystem());
+				AnnotationData annotationData = processor.readAnnotationData(inputStream);
+
+				record.setDeviation(annotationData.getDeviation());
+				ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName());
+				record.setDeviationSerial(nameVO.lgSerial());
+
+				record.setProgramStatus(annotationData.getProgramStatus());
+			}
+			fileSendRecordService.save(record);
+
+			importedRecords.add(record);
 		}
 
-
+		machineBackTaskService.saveBatch(parseMachineBackTask(importedRecords));
 	}
 
 	/**
-	 * 鏇存柊绋嬪簭鏂囦欢
-	 * @param pkgFileName mdm绋嬪簭鍖�
-	 * @param idList 閫夊畾鍏ュ簱鐨�
+	 * 鍒涘缓鏈哄簥鍥炰紶浠诲姟
+	 * @param importedRecords 瀵煎叆璁板綍鍒楄〃
 	 */
-	private void updateProgramFile(String pkgFileName,List<Long> idList) throws IOException {
-		InputStream inputStream = this.ossTemplate.statFileStream(pkgFileName);
-		byte[] bytes = FileUtil.copyToByteArray(inputStream);
+	List<MachineBackTask> parseMachineBackTask(List<FileSendRecord>  importedRecords){
+		List<FileSendRecord> recList = importedRecords.stream().filter(r -> AnnotationUtil.SQ.equals(r.getProgramStatus())
+			|| AnnotationUtil.LG.equals(r.getProgramStatus())).toList();
 
-		List<NcNode> nodeList = new ArrayList<>();
-		List<NcProgram> progList = new ArrayList<>();
-		List<ApproveRecord> recordList = new ArrayList<>();
+		Map<String,FileSendRecord> map = new HashMap<>();
+		for(FileSendRecord record : recList){
+			ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName());
+			String key = record.getMachineCode()+","+nameVO.logicProgramName();
 
-		try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes);
-			 ZipFile zipFile = new ZipFile(channel)) {
-
-			ZipArchiveEntry entry;
-			Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
-			while (entries.hasMoreElements()) {
-				entry = entries.nextElement();
-
-				String entryName = entry.getName();
-
-				if (!entry.isDirectory()) {
-					if(entryName.equals(NcProgramExportDNCService.PROGRAM_JSON_FILE)){
-
-						try (InputStream insJson = zipFile.getInputStream(entry)) {
-							String jsonStr = IoUtil.readToString(insJson);
-
-							JSONArray jsonArray = JSONArray.parseArray(jsonStr);
-							for(int i=0;i<jsonArray.size();i++){
-								JSONObject jsonObject = jsonArray.getJSONObject(i);
-								NcProgram d = new NcProgram();
-								d.setId(jsonObject.getLong("id"));
-								d.setName(jsonObject.getString("name"));
-
-								d.setCode(jsonObject.getString("code"));
-								d.setDescription(jsonObject.getString("description"));
-								d.setCategory(jsonObject.getString("category"));
-								d.setBindNcNodeId(jsonObject.getLong("bindNcNodeId"));
-								d.setIsLastEdition(jsonObject.getInteger("isLastEdition"));
-								d.setIsLocked(jsonObject.getInteger("isLocked"));
-								d.setIsTest(jsonObject.getInteger("isTest"));
-								d.setMachineCode(jsonObject.getString("machineCode"));
-								d.setNcNodeId(jsonObject.getLong("ncNodeId"));
-								d.setDrawingNo(jsonObject.getString("drawingNo"));
-								d.setProcessEdition(jsonObject.getString("processEdition"));
-
-								setBaseProperties(d,jsonObject);
-
-								progList.add(d);
-							}
-
-						}
-					}else if(entryName.equals(NcProgramExportDNCService.NODE_JSON_FILE)){
-						try (InputStream insJson = zipFile.getInputStream(entry)) {
-							String jsonStr = IoUtil.readToString(insJson);
-							JSONArray jsonArray = JSONArray.parseArray(jsonStr);
-							for (int i = 0; i < jsonArray.size(); i++) {
-								JSONObject jsonObject = jsonArray.getJSONObject(i);
-								NcNode node = new NcNode();
-								node.setId(jsonObject.getLong("id"));
-								node.setName(jsonObject.getString("name"));
-								node.setDescription(jsonObject.getString("description"));
-								node.setNodeType(jsonObject.getString("nodeType"));
-								node.setProcessName(jsonObject.getString("processName"));
-								node.setDrawingNo(jsonObject.getString("drawingNo"));
-								node.setMachineCode(jsonObject.getString("machineCode"));
-								node.setParentId(jsonObject.getLong("parentId"));
-								node.setParentIds(jsonObject.getString("parentIds"));
-								node.setIsCured(jsonObject.getInteger("isCured"));
-
-								setBaseProperties(node,jsonObject);
-
-								nodeList.add(node);
-							}
-						}
-					}else if(entryName.equals(NcProgramExportDNCService.APPROVE_RECORD_JSON_FILE)){
-						try (InputStream insJson = zipFile.getInputStream(entry)) {
-							String jsonStr = IoUtil.readToString(insJson);
-							JSONArray jsonArray = JSONArray.parseArray(jsonStr);
-							for (int i = 0; i < jsonArray.size(); i++) {
-								JSONObject jsonObject = jsonArray.getJSONObject(i);
-								ApproveRecord record = new ApproveRecord();
-								record.setId(jsonObject.getLong("id"));
-								record.setNcProgramId(jsonObject.getLong("ncProgramId"));
-								record.setUserId(jsonObject.getLong("userId"));
-								record.setUserNickname(jsonObject.getString("userNickname"));
-								record.setOperateResult(jsonObject.getString("operateResult"));
-								record.setOperateTime(jsonObject.getDate("operateTime"));
-								setBaseProperties(record,jsonObject);
-
-								recordList.add(record);
-							}
-						}
-					}
-
-				}
-			}
-
+			map.put(key,record);
 		}
 
+		List<MachineBackTask> backTasks = new ArrayList<>();
+		for(String key : map.keySet()){
+			MachineBackTask task = new MachineBackTask();
+			task.setTaskType(MachineBackTask.TASK_TYPE_PROGRAM);
 
-		try (SeekableInMemoryByteChannel channel = new SeekableInMemoryByteChannel(bytes);
-			 ZipFile zipFile = new ZipFile(channel)) {
+			FileSendRecord record = map.get(key);
+			task.setMachineCode(record.getMachineCode());
 
-			ZipArchiveEntry entry;
-			Enumeration<ZipArchiveEntry> entries = zipFile.getEntries();
-			while (entries.hasMoreElements()) {
-				entry = entries.nextElement();
+			ProgramNameVO nameVO = ProgramFileNameParser.parseProgramName(record.getName());
+			task.setDeviation(record.getDeviation());
+			task.setDeviationSerial(record.getDeviationSerial());
 
-				String entryName = entry.getName();
-
-				if (!entry.isDirectory() && !entryName.equals(NcProgramExportDNCService.PROGRAM_JSON_FILE)) {
-
-					for(NcProgram prog:progList){
-						if(prog.getName().equals(entryName)){
-							try (InputStream ncFileStream = zipFile.getInputStream(entry)) {
-								BladeFile bfile = this.ossTemplate.putFile(prog.getName(),ncFileStream);
-								prog.setOssName(bfile.getName());
-								prog.setUrl(bfile.getLink());
-							}
-							break;
-						}
-					}
-
-				}
-			}
+			task.setProgramName(nameVO.logicProgramName());
+			task.setSegCount(nameVO.getSegmentCount());
+			backTasks.add(task);
 		}
-
-		for(NcNode node:nodeList){
-			NcNode nodeTemp = this.ncNodeService.getById(node.getId());
-			if(nodeTemp == null){
-				ncNodeService.save(node);
-			}else{
-				ncNodeService.updateById(node);
-			}
-		}
-
-		for(NcProgram prog:progList){
-			NcProgram ncTemp = ncProgramService.getById(prog.getId());
-			if(ncTemp == null){
-				ncProgramService.save(prog);
-			}else{
-				ncProgramService.updateById(prog);
-			}
-		}
-
-		for(ApproveRecord record:recordList) {
-			ApproveRecord recordTemp = this.approveRecordService.getById(record.getId());
-			if (recordTemp == null) {
-				approveRecordService.save(record);
-			} else {
-				approveRecordService.updateById(record);
-			}
-		}
-
-	}
-
-	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"));
+		//鎻愬彇绋嬪簭鍖呭悕锛屾満搴婄紪鐮侀泦鍚�
+		return backTasks;
 	}
 }

--
Gitblit v1.9.3