From 392428d2f009b4ab8005520e2e5aaf20e82e071e Mon Sep 17 00:00:00 2001 From: xydkj Date: Mon, 27 Apr 2026 17:02:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E7=BD=91=E7=BB=9C=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/NetworkConfigController.java | 8 +++ .../device/service/NetworkConfigService.java | 52 +++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/main/java/com/cisd/tms/modules/device/controller/NetworkConfigController.java b/src/main/java/com/cisd/tms/modules/device/controller/NetworkConfigController.java index ecd0d4b..7e6b903 100644 --- a/src/main/java/com/cisd/tms/modules/device/controller/NetworkConfigController.java +++ b/src/main/java/com/cisd/tms/modules/device/controller/NetworkConfigController.java @@ -14,6 +14,8 @@ import jakarta.validation.Valid; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; +import java.util.List; + @Tag(name = "网络配置管理", description = "提供设备网络信息查询、IPv4/IPv6配置、Bond配置及路由管理等接口") @RestController @RequestMapping("/api/v1/device/network") @@ -25,6 +27,12 @@ public class NetworkConfigController { this.networkConfigService = networkConfigService; } + @Operation(summary = "获取所有网卡名", description = "获取系统中所有网卡名称") + @GetMapping("/card/eth-names") + public ApiResponse> getEthDeviceNames() { + return ApiResponse.success(networkConfigService.getEthDeviceNames()); + } + @Operation(summary = "分页查询网卡配置", description = "分页查询设备网卡配置列表,支持按网卡名称、状态等条件筛选") @PostMapping("/card/Page") public ApiResponse> getNetworkTablePage(@RequestBody NetworkTableQueryRequest request) { diff --git a/src/main/java/com/cisd/tms/modules/device/service/NetworkConfigService.java b/src/main/java/com/cisd/tms/modules/device/service/NetworkConfigService.java index 86efd55..0c6114f 100644 --- a/src/main/java/com/cisd/tms/modules/device/service/NetworkConfigService.java +++ b/src/main/java/com/cisd/tms/modules/device/service/NetworkConfigService.java @@ -108,6 +108,58 @@ public class NetworkConfigService { } + public List getEthDeviceNames() { + List result = new ArrayList<>(); + + List lines = executeCommand( + "nmcli", + "-t", + "-f", + "DEVICE,TYPE", + "device", + "status" + ); + + for (String line : lines) { + if (line == null || line.trim().isEmpty()) { + continue; + } + + String[] parts = line.split("(? getNetworkTablePage(NetworkTableQueryRequest req) { List resultList = new ArrayList<>(); String targetDeviceName = trim(req.getDeviceName());