From 0c7b3a418906c2e5d63fc3960dfeee045af60edc Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期三, 13 八月 2025 00:43:46 +0800
Subject: [PATCH] mdm工控网导入功能

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/task/MachineFileScanTask.java |   53 +++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 49 insertions(+), 4 deletions(-)

diff --git a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/task/MachineFileScanTask.java b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/task/MachineFileScanTask.java
index 53a63fd..c66704b 100644
--- a/blade-service/blade-mdm/src/main/java/org/springblade/mdm/task/MachineFileScanTask.java
+++ b/blade-service/blade-mdm/src/main/java/org/springblade/mdm/task/MachineFileScanTask.java
@@ -37,7 +37,6 @@
 	//@Scheduled(cron = "0 1 0 * * ?") // 姣忓ぉ涓婂崍0鐐�1鍒嗘墽琛�
 	@Scheduled(cron = "0 15 19 * * ?") //test
 	public void executeEvery5Seconds() {
-		System.out.println("瀹氭椂浠诲姟鎵ц: " + System.currentTimeMillis());
 		scanMachineFile();
 	}
 
@@ -45,6 +44,8 @@
 	public void scanMachineFile() {
 		List<Machine> machines = machineService.lambdaQuery().eq(Machine::getStatus,Machine.STATUS_ENABLE).list();
 		for (Machine machine : machines) {
+
+			//鎵弿鏂伴椈鐣�
 			try {
 				scanDir(machine,MachineFile.DIR_TYPE_REC);
 			}catch(Exception e) {
@@ -60,10 +61,26 @@
 			}catch(Exception e) {
 				log.error("TEMP鎵弿鏂囦欢寮傚父,鏈哄簥"+machine.getCode(),e);
 			}
+
+			//娓呯悊鏁版嵁搴擄紝鍒犻櫎鏂囦欢涓嶅瓨鍦ㄧ殑鏁版嵁
+			try {
+				clearDeletedReccords(machine,MachineFile.DIR_TYPE_REC);
+			}catch(Exception e) {
+				log.error("REC鎵弿鏂囦欢寮傚父,鏈哄簥"+machine.getCode(),e);
+			}
+			try {
+				clearDeletedReccords(machine,MachineFile.DIR_TYPE_SEND);
+			}catch(Exception e) {
+				log.error("SEND鎵弿鏂囦欢寮傚父,鏈哄簥"+machine.getCode(),e);
+			}
+			try {
+				clearDeletedReccords(machine,MachineFile.DIR_TYPE_TEMP);
+			}catch(Exception e) {
+				log.error("TEMP鎵弿鏂囦欢寮傚父,鏈哄簥"+machine.getCode(),e);
+			}
 		}
 
 	}
-
 
 
 	/**
@@ -73,8 +90,6 @@
 	 * @throws IOException
 	 */
 	public void scanDir(Machine machine,String dirType) throws IOException {
-		//MachineFile.DIR_TYPE_REC
-
 		String basePath = MachineFileService.getBasePath(machine,dirType);
 		if(basePath == null) {
 			log.warn("鐩綍绫诲瀷涓嶅尮閰�:{}",dirType);
@@ -138,6 +153,36 @@
 
 		}
 
+
 	}
 
+	/**
+	 * 娓呯悊宸茬粡鍒犻櫎浜嗘枃浠剁殑璁板綍
+	 * @param machine
+	 * @param dirType
+	 * @throws IOException
+	 */
+	void clearDeletedReccords(Machine machine,String dirType) throws IOException {
+		List<MachineFile> machineFiles =  this.machineFileService.lambdaQuery().eq(MachineFile::getDirType,dirType)
+			.eq(MachineFile::getMachineCode,machine.getCode()).list();
+
+		String basePath = MachineFileService.getBasePath(machine,dirType);
+		if(basePath == null) {
+			log.warn("鐩綍绫诲瀷涓嶅尮閰�:{}",dirType);
+			return;
+		}
+		Path dirPath = Paths.get(basePath);
+
+		List<Path> files = Files.list(dirPath)
+			.filter(Files::isRegularFile).toList();
+
+		for(MachineFile mf : machineFiles){
+
+			long findCount = files.stream().filter(filePath -> {return filePath.toFile().getName().equals(mf.getName());}).count();
+			if(findCount == 0){
+				//鏂囦欢澶瑰唴娌℃壘鍒帮紝闇�瑕佸垹闄よ褰�
+				this.machineFileService.save(mf);
+			}
+		}
+	}
 }

--
Gitblit v1.9.3