Files
IOT/WebAPI/Controllers/EnovaDataController.cs
2026-06-10 10:53:10 +08:00

45 lines
1.4 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using DeviceCommand.Base;
using Microsoft.AspNetCore.Mvc;
using Model.Model;
[ApiController]
[Route("api/enova")] // 路由可以自己定,定好后把完整的 URL 提供给上位机配置
public class EnovaDataController : ControllerBase
{
/// <summary>
/// 接收下位机 POST 上报的通道数据,并联动分发到所有匹配的 EnovaDataReporter 实例(如 CTS3
/// </summary>
[HttpPost("upload-status")]
public IActionResult ReceiveChannelStatus([FromBody] List<EnovaChannelData> rawDataList)
{
// 1. 基础校验
if (rawDataList == null || rawDataList.Count == 0)
{
return Ok(new ApiResponse
{
Success = false,
ErrorInfo = "接收到的数据为空"
});
}
try
{
// 2. 联动设备:将数据分发到所有已注册的 EnovaDataReporter 实例
// (包括 CTS3 等派生类,由它们自行通过事件处理)
ApiResponse dispatchResult = EnovaDataReporter.Dispatch(rawDataList);
// 3. 严格按照文档 Page 6 的格式返回响应
return Ok(dispatchResult);
}
catch (Exception ex)
{
// 系统内部异常处理
return Ok(new ApiResponse
{
Success = false,
ErrorInfo = $"服务器内部错误: {ex.Message}"
});
}
}
}