From 4f118b548e5bc741e372fdcc035bb23f9e0ce0bb Mon Sep 17 00:00:00 2001
From: yangys <y_ys79@sina.com>
Date: 星期日, 24 八月 2025 12:15:07 +0800
Subject: [PATCH] 增加异常流程的界面和处理
---
blade-service/blade-mdm/src/main/java/org/springblade/mdm/task/MachineFileScanTask.java | 66 ++++++++++++++++++++++++--------
1 files changed, 49 insertions(+), 17 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 c66704b..a573dd5 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,19 +1,17 @@
package org.springblade.mdm.task;
+import com.alibaba.excel.util.StringUtils;
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.commons.service.ParamService;
import org.springblade.mdm.gkw.programnode.entity.MachineFile;
import org.springblade.mdm.gkw.programnode.service.MachineFileService;
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;
@@ -32,15 +30,27 @@
private MachineFileService machineFileService;
@Autowired
private MachineService machineService;
+ @Autowired
+ private ParamService paramService;
// 姣�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);
+
+ if(!ParamService.NETWORK_TYPE_SHEMI.equals(networkType)){
+ //闈炴秹瀵嗙綉锛屾墠鎵弿鐩綍鏂囦欢
+ scanMachineFile();
+ }
+
}
-
+ /**
+ * 鎵弿鎵�鏈夋満搴婄殑閰嶇疆涔嬬洰褰�
+ */
public void scanMachineFile() {
List<Machine> machines = machineService.lambdaQuery().eq(Machine::getStatus,Machine.STATUS_ENABLE).list();
for (Machine machine : machines) {
@@ -106,10 +116,12 @@
byte[] buffer = new byte[2048];
- boolean exists;//鏂囦欢鏄惁瀛樺湪浜庢暟鎹簱涓�
+ MachineFile existFileInDb;
+ //boolean exists;//鏂囦欢鏄惁瀛樺湪浜庢暟鎹簱涓�
for (Path filePath : files) {
- exists = false;
+ existFileInDb = null;
+ //exists = false;
MachineFile mf = new MachineFile();
@@ -129,7 +141,7 @@
mf.setFileCreateTime(creationDate);
FileTime modifyTime = attrs.lastModifiedTime();
- mf.setFileModifyDate(new Date(modifyTime.toMillis()));
+ mf.setFileModifyTime(new Date(modifyTime.toMillis()));
mf.setFileSize(Files.size(filePath));
try (InputStream inputStream = Files.newInputStream(filePath)) {
// 浣跨敤杈撳叆娴佽鍙栨枃浠跺唴瀹�
@@ -140,15 +152,31 @@
continue;//鏈夐敊璇�,鎺犺繃
}
- exists = machineFileService.fileExists(mf.getName(),mf.getMd5(),machine.getCode());
+ //exists = machineFileService.fileExists(mf.getName(),dirType,machine.getCode());
+
+ existFileInDb = machineFileService.getExistsFile(mf.getName(),dirType,machine.getCode());
System.out.println("鏂囦欢鍒涘缓鏃堕棿: " + creationDate);
} catch (IOException e) {
log.error("璇诲彇鏂囦欢淇℃伅澶辫触",e);
}
- if(!exists) {
+ if(existFileInDb == null) {
machineFileService.save(mf);
}else{
- log.info("鏂囦欢宸插鏋滄帬杩�:{}",filePath.getFileName());
+ log.info("鏂囦欢宸插瓨鍦ㄦ帬杩�:{}",filePath.getFileName());
+ //宸插瓨鍦ㄥ拫鏁淬��
+ existFileInDb.setFileSize(mf.getFileSize());
+
+ existFileInDb.setFileCreateTime(mf.getFileCreateTime());
+ existFileInDb.setFileModifyTime(mf.getFileModifyTime());
+ if(!StringUtils.equals(existFileInDb.getMd5(),mf.getMd5())){
+ //鏂囦欢鍐呭鍙戠敓鍙樺寲浜�,璁剧疆鐘舵�佷负鍒濆鐘舵��
+ existFileInDb.setStatus(MachineFile.STATUS_NORMAL);
+ }
+ existFileInDb.setMd5(mf.getMd5());
+
+
+ machineFileService.updateById(existFileInDb);
+
}
}
@@ -172,16 +200,20 @@
return;
}
Path dirPath = Paths.get(basePath);
+ if(!dirPath.toFile().exists()){
+ log.warn("鎵弿鐩綍:{} 涓嶅瓨鍦�",dirPath);
+ return;
+ }
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();
+ 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