From a5f944c2bc0107e5df936937f1c33e5e03eb8fed Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期六, 06 九月 2025 19:15:48 +0800
Subject: [PATCH] 解锁增加解锁原因和展示

---
 blade-service/blade-mdm/src/main/java/org/springblade/mdm/task/MachineFileScanTask.java |  182 ++++----------------------------------------
 1 files changed, 19 insertions(+), 163 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 4f95154..c49cee9 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
@@ -1,28 +1,16 @@
 package org.springblade.mdm.task;
 
 import lombok.extern.slf4j.Slf4j;
-import org.apache.commons.codec.digest.DigestUtils;
-import org.springblade.core.secure.utils.AuthUtil;
-import org.springblade.core.tool.utils.FileUtil;
-import org.springblade.mdm.basesetting.machine.MachineService;
-import org.springblade.mdm.basesetting.machine.entity.Machine;
-import org.springblade.mdm.gkw.programnode.entity.MachineFile;
-import org.springblade.mdm.gkw.programnode.service.MachineFileService;
+import org.springblade.mdm.basesetting.machine.service.MachineService;
+import org.springblade.mdm.commons.service.ParamService;
+import org.springblade.mdm.machinefile.service.MachineFileScanService;
+import org.springblade.mdm.machinefile.service.MachineFileService;
+import org.springblade.mdm.program.service.ProgramAnnotationService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Component;
-
-import java.io.File;
 import java.io.IOException;
-import java.io.InputStream;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.nio.file.attribute.BasicFileAttributes;
-import java.nio.file.attribute.FileTime;
-import java.util.Date;
-import java.util.List;
 
 @Slf4j
 @Component
@@ -32,158 +20,26 @@
 	private MachineFileService machineFileService;
 	@Autowired
 	private MachineService machineService;
+	@Autowired
+	private ParamService paramService;
+	@Autowired
+	private ProgramAnnotationService programAnnotationService;
+	@Autowired
+	private MachineFileScanService machineFileScanService;
 	// 姣�5绉掓墽琛屼竴娆�
 	//@Scheduled(fixedRate = 1000000)
 	//@Scheduled(cron = "0 1 0 * * ?") // 姣忓ぉ涓婂崍0鐐�1鍒嗘墽琛�
-	@Scheduled(cron = "0 15 19 * * ?") //test
-	public void executeEvery5Seconds() {
-		scanMachineFile();
-	}
+	//@Scheduled(cron = "0 */5 * * * ?")
+	//@Scheduled(cron = "0 15 19 * * ?") //test
+	@Scheduled(cron = "${task.cron.machine_file_scan:0 1 * * * ?}")
+	public void execute() {
+		String networkType = paramService.getParamValue(ParamService.NETWORK_TYPE,ParamService.NETWORK_TYPE_SHEMI);
 
-
-	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) {
-				log.error("REC鎵弿鏂囦欢寮傚父,鏈哄簥"+machine.getCode(),e);
-			}
-			try {
-				scanDir(machine,MachineFile.DIR_TYPE_SEND);
-			}catch(Exception e) {
-				log.error("SEND鎵弿鏂囦欢寮傚父,鏈哄簥"+machine.getCode(),e);
-			}
-			try {
-				scanDir(machine,MachineFile.DIR_TYPE_TEMP);
-			}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);
-			}
+		if(!ParamService.NETWORK_TYPE_SHEMI.equals(networkType)){
+			//闈炴秹瀵嗙綉锛屾墠鎵弿鐩綍鏂囦欢
+			machineFileScanService.scanMachineFile();
 		}
 
 	}
 
-
-	/**
-	 * 鎵弿鐩綍
-	 * @param machine 鏈哄簥淇℃伅
-	 * @param dirType 鐩綍绫诲瀷
-	 * @throws IOException
-	 */
-	public void scanDir(Machine machine,String dirType) throws IOException {
-		String basePath = MachineFileService.getBasePath(machine,dirType);
-		if(basePath == null) {
-			log.warn("鐩綍绫诲瀷涓嶅尮閰�:{}",dirType);
-			return;
-		}
-		Path dirPath = Paths.get(basePath);
-		if(!dirPath.toFile().exists()){
-			log.warn("鎵弿鐩綍:{} 涓嶅瓨鍦�",dirPath);
-			return;
-		}
-		// 鍙寘鍚櫘閫氭枃浠�
-		List<Path> files = Files.list(dirPath)
-			.filter(Files::isRegularFile).toList();
-
-		byte[] buffer = new byte[2048];
-
-		boolean exists;//鏂囦欢鏄惁瀛樺湪浜庢暟鎹簱涓�
-		for (Path filePath : files) {
-
-			exists = false;
-
-			MachineFile mf = new MachineFile();
-
-			mf.setTenantId("000000");
-			mf.setName(filePath.toFile().getName());
-			mf.setDirType(dirType);
-			mf.setMachineCode(machine.getCode());
-
-			try {
-				BasicFileAttributes attrs = Files.readAttributes(
-					filePath,
-					BasicFileAttributes.class
-				);
-
-				FileTime creationTime = attrs.creationTime();
-				Date creationDate = new Date(creationTime.toMillis());
-				mf.setFileCreateTime(creationDate);
-
-				FileTime modifyTime = attrs.lastModifiedTime();
-				mf.setFileModifyDate(new Date(modifyTime.toMillis()));
-				mf.setFileSize(Files.size(filePath));
-				try (InputStream inputStream = Files.newInputStream(filePath)) {
-					// 浣跨敤杈撳叆娴佽鍙栨枃浠跺唴瀹�
-					int bytesRead = inputStream.read(buffer);
-					mf.setMd5(DigestUtils.md5Hex(buffer));
-				} catch (IOException e) {
-					log.error("璇诲彇鏂囦欢md5澶辫触",e);
-					continue;//鏈夐敊璇�,鎺犺繃
-				}
-
-				exists = machineFileService.fileExists(mf.getName(),mf.getMd5(),machine.getCode());
-				System.out.println("鏂囦欢鍒涘缓鏃堕棿: " + creationDate);
-			} catch (IOException e) {
-				log.error("璇诲彇鏂囦欢淇℃伅澶辫触",e);
-			}
-			if(!exists) {
-				machineFileService.save(mf);
-			}else{
-				log.info("鏂囦欢宸插鏋滄帬杩�:{}",filePath.getFileName());
-			}
-
-		}
-
-
-	}
-
-	/**
-	 * 娓呯悊宸茬粡鍒犻櫎浜嗘枃浠剁殑璁板綍
-	 * @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 -> filePath.toFile().getName().equals(mf.getName())).count();
-			if(findCount == 0){
-				//鏂囦欢澶瑰唴娌℃壘鍒帮紝闇�瑕佸垹闄よ褰�
-				//this.machineFileService.save(mf);
-				mf.markFileDeleted();
-				this.machineFileService.updateById(mf);
-			}
-		}
-	}
 }

--
Gitblit v1.9.3