parent
f5dd474ba0
commit
53eaac43e3
|
@ -21,7 +21,6 @@ public class NetConfigController : ControllerBase
|
|||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <param name="hostIp">主机IP地址</param>
|
||||
/// <param name="taskId">任务ID,默认为0</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetHostIP")]
|
||||
[EnableCors("Users")]
|
||||
|
@ -53,7 +52,7 @@ public class NetConfigController : ControllerBase
|
|||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IPAddr, board.Port, 0);
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetHostIP(ipAddress);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
|
@ -76,7 +75,6 @@ public class NetConfigController : ControllerBase
|
|||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <param name="boardIp">板卡IP地址</param>
|
||||
/// <param name="taskId">任务ID,默认为0</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetBoardIP")]
|
||||
[EnableCors("Users")]
|
||||
|
@ -108,7 +106,7 @@ public class NetConfigController : ControllerBase
|
|||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IPAddr, board.Port, 0);
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetBoardIP(ipAddress);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
|
@ -117,6 +115,13 @@ public class NetConfigController : ControllerBase
|
|||
return StatusCode(StatusCodes.Status500InternalServerError, $"设置失败: {result.Error}");
|
||||
}
|
||||
|
||||
var ret = db.UpdateBoardIpAddr(boardId, ipAddress.ToString());
|
||||
if (ret <= 0)
|
||||
{
|
||||
logger.Error($"数据库更新失败");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, $"数据库更新失败");
|
||||
}
|
||||
|
||||
return Ok(result.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -131,7 +136,6 @@ public class NetConfigController : ControllerBase
|
|||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <param name="hostMac">主机MAC地址(格式:AA:BB:CC:DD:EE:FF)</param>
|
||||
/// <param name="taskId">任务ID,默认为0</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetHostMAC")]
|
||||
[EnableCors("Users")]
|
||||
|
@ -164,7 +168,66 @@ public class NetConfigController : ControllerBase
|
|||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IPAddr, board.Port, 0);
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetHostMAC(macBytes);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
{
|
||||
logger.Error($"设置主机MAC地址失败: {result.Error}");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, $"设置失败: {result.Error}");
|
||||
}
|
||||
|
||||
return Ok(result.Value);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error(ex, "设置主机MAC地址时发生异常");
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "设置失败,请稍后重试");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新主机MAC地址
|
||||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("UpdateHostMAC")]
|
||||
[EnableCors("Users")]
|
||||
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
|
||||
[ProducesResponseType(StatusCodes.Status400BadRequest)]
|
||||
[ProducesResponseType(StatusCodes.Status404NotFound)]
|
||||
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
|
||||
public async Task<IActionResult> UpdateHostMAC(Guid boardId)
|
||||
{
|
||||
if (boardId == Guid.Empty)
|
||||
return BadRequest("板卡ID不能为空");
|
||||
|
||||
byte[]? macBytes = null;
|
||||
try
|
||||
{
|
||||
// 获取本机第一个可用的MAC地址
|
||||
macBytes = System.Net.NetworkInformation.NetworkInterface
|
||||
.GetAllNetworkInterfaces()
|
||||
.Where(nic => nic.OperationalStatus == System.Net.NetworkInformation.OperationalStatus.Up
|
||||
&& nic.NetworkInterfaceType != System.Net.NetworkInformation.NetworkInterfaceType.Loopback)
|
||||
.Select(nic => nic.GetPhysicalAddress()?.GetAddressBytes())
|
||||
.FirstOrDefault(bytes => bytes != null && bytes.Length == 6);
|
||||
|
||||
if (macBytes == null)
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "无法获取本机MAC地址");
|
||||
|
||||
// 获取板卡信息
|
||||
using var db = new Database.AppDataConnection();
|
||||
var boardRet = db.GetBoardByID(boardId);
|
||||
if (!boardRet.IsSuccessful)
|
||||
return StatusCode(StatusCodes.Status500InternalServerError, "数据库操作失败");
|
||||
if (!boardRet.Value.HasValue)
|
||||
return NotFound("未找到对应的板卡");
|
||||
|
||||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetHostMAC(macBytes);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
|
@ -187,7 +250,6 @@ public class NetConfigController : ControllerBase
|
|||
/// </summary>
|
||||
/// <param name="boardId">板卡ID</param>
|
||||
/// <param name="boardMac">板卡MAC地址(格式:AA:BB:CC:DD:EE:FF)</param>
|
||||
/// <param name="taskId">任务ID,默认为0</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost("SetBoardMAC")]
|
||||
[EnableCors("Users")]
|
||||
|
@ -220,7 +282,7 @@ public class NetConfigController : ControllerBase
|
|||
var board = boardRet.Value.Value;
|
||||
|
||||
// 创建网络配置客户端
|
||||
var netConfig = new NetConfig(board.IPAddr, board.Port, 0);
|
||||
var netConfig = new NetConfig(board.IpAddr, board.Port, 0);
|
||||
var result = await netConfig.SetBoardMAC(macBytes);
|
||||
|
||||
if (!result.IsSuccessful)
|
||||
|
@ -277,4 +339,4 @@ public class NetConfigController : ControllerBase
|
|||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -511,7 +511,7 @@ public class AppDataConnection : DataConnection
|
|||
{
|
||||
var board = boards[0];
|
||||
var user = this.UserTable.Where(u => u.ID == userId).FirstOrDefault();
|
||||
|
||||
|
||||
if (user == null)
|
||||
{
|
||||
logger.Error($"未找到用户: {userId}");
|
||||
|
@ -542,6 +542,22 @@ public class AppDataConnection : DataConnection
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新实验板的IP地址
|
||||
/// </summary>
|
||||
/// <param name="boardId">实验板的唯一标识符</param>
|
||||
/// <param name="newIpAddr">新的IP地址</param>
|
||||
/// <returns>更新的记录数</returns>
|
||||
public int UpdateBoardIpAddr(Guid boardId, string newIpAddr)
|
||||
{
|
||||
var result = this.BoardTable
|
||||
.Where(b => b.ID == boardId)
|
||||
.Set(b => b.IpAddr, newIpAddr)
|
||||
.Update();
|
||||
logger.Info($"实验板 {boardId} 的IP地址已更新为 {newIpAddr},更新记录数: {result}");
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 用户表
|
||||
/// </summary>
|
||||
|
|
8775
src/APIClient.ts
8775
src/APIClient.ts
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue