1097 lines
36 KiB
C#
1097 lines
36 KiB
C#
using Abp.Web.Models;
|
||
using Microsoft.Extensions.Logging;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using ToolLibrary;
|
||
using YunDa.Server.ISMSTcp.Models;
|
||
using YunDa.Server.ISMSTcp.Services;
|
||
using YunDa.SOMS.DataTransferObject;
|
||
using YunDa.SOMS.DataTransferObject.Account;
|
||
using YunDa.SOMS.DataTransferObject.DataMonitoring.SecondaryCircuitInspection;
|
||
using YunDa.SOMS.DataTransferObject.DataMonitoring.SecondaryCircuitInspection.Configurations;
|
||
using YunDa.SOMS.DataTransferObject.ExternalEntities.BeijingYounuo;
|
||
using YunDa.SOMS.DataTransferObject.GeneralInformation.ProtectionDeviceInfoDto;
|
||
using YunDa.SOMS.DataTransferObject.MaintenanceAndOperations.SecondaryEquipment;
|
||
using YunDa.SOMS.Entities.DataMonitoring;
|
||
using YunDa.SOMS.Entities.ExternalEntities.BeijingYounuo;
|
||
|
||
namespace YunDa.Server.ISMSTcp.Domain
|
||
{
|
||
public class WebApiRequest
|
||
{
|
||
private readonly IApiEndpoints _apiEndpoints;
|
||
private readonly ILogger<WebApiRequest> _logger;
|
||
|
||
// 认证相关字段
|
||
private string _authToken;
|
||
private DateTime _tokenExpiry;
|
||
private readonly object _authLock = new object();
|
||
private const string SERVICE_USERNAME = "admin"; // 服务账户用户名
|
||
private const string SERVICE_PASSWORD = "yunda123"; // 服务账户密码
|
||
|
||
/// <summary>
|
||
/// 构造函数
|
||
/// </summary>
|
||
/// <param name="apiEndpoints">API端点服务</param>
|
||
/// <param name="logger">日志记录器</param>
|
||
public WebApiRequest(IApiEndpoints apiEndpoints, ILogger<WebApiRequest> logger)
|
||
{
|
||
_apiEndpoints = apiEndpoints;
|
||
_logger = logger;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 服务启动时自动登录
|
||
/// </summary>
|
||
/// <returns>是否登录成功</returns>
|
||
public async Task<bool> InitializeAuthenticationAsync()
|
||
{
|
||
try
|
||
{
|
||
_logger.LogInformation("开始初始化服务认证");
|
||
var loginResult = await LoginAsync();
|
||
if (loginResult)
|
||
{
|
||
_logger.LogInformation("服务认证初始化成功");
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
_logger.LogError("服务认证初始化失败");
|
||
return false;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "初始化服务认证时发生异常");
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 用户登录
|
||
/// </summary>
|
||
/// <returns>是否登录成功</returns>
|
||
private async Task<bool> LoginAsync()
|
||
{
|
||
try
|
||
{
|
||
_logger.LogInformation("开始服务账户登录");
|
||
|
||
// 准备登录数据 - 按照AccountAppService的要求进行编码
|
||
var originalUsername = SERVICE_USERNAME;
|
||
var originalPassword = SERVICE_PASSWORD;
|
||
|
||
// 对用户名进行Base64编码然后反转
|
||
var usernameBytes = System.Text.Encoding.UTF8.GetBytes(originalUsername);
|
||
var usernameBase64 = Convert.ToBase64String(usernameBytes);
|
||
var usernameReversed = new string(usernameBase64.ToCharArray().Reverse().ToArray());
|
||
|
||
// 对密码进行Base64编码然后反转
|
||
var passwordBytes = System.Text.Encoding.UTF8.GetBytes(originalPassword);
|
||
var passwordBase64 = Convert.ToBase64String(passwordBytes);
|
||
var passwordReversed = new string(passwordBase64.ToCharArray().Reverse().ToArray());
|
||
|
||
var loginData = new
|
||
{
|
||
userName = usernameReversed,
|
||
password = passwordReversed
|
||
};
|
||
|
||
var response = await Task.Run(() =>
|
||
ToolLibrary.HttpHelper.HttpPostRequest<JObject>(
|
||
_apiEndpoints.LoginUri,
|
||
loginData));
|
||
|
||
if (response != null)
|
||
{
|
||
var loginResult = ExtractDataFromAbpResponse<LoginUserOutput>(response);
|
||
if (loginResult != null && IsAbpResponseSuccessful(response))
|
||
{
|
||
lock (_authLock)
|
||
{
|
||
_authToken = $"Bearer {loginResult.Id}"; // 使用用户ID作为简单的token
|
||
_tokenExpiry = DateTime.Now.AddHours(8); // 设置8小时过期
|
||
}
|
||
|
||
_logger.LogInformation("服务账户登录成功,用户: {UserName}", loginResult.UserName);
|
||
return true;
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("登录失败,响应: {Response}", response.ToString());
|
||
return false;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("登录API响应为null");
|
||
return false;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "服务账户登录时发生异常");
|
||
return false;
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 确保认证有效
|
||
/// </summary>
|
||
/// <returns>是否认证有效</returns>
|
||
private async Task<bool> EnsureAuthenticatedAsync()
|
||
{
|
||
lock (_authLock)
|
||
{
|
||
// 检查token是否存在且未过期
|
||
if (!string.IsNullOrEmpty(_authToken) && DateTime.Now < _tokenExpiry)
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
// Token无效或过期,重新登录
|
||
_logger.LogInformation("认证token无效或过期,重新登录");
|
||
return await LoginAsync();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取认证头信息
|
||
/// </summary>
|
||
/// <returns>认证头字典</returns>
|
||
private Dictionary<string, string> GetAuthHeaders()
|
||
{
|
||
var headers = new Dictionary<string, string>();
|
||
|
||
lock (_authLock)
|
||
{
|
||
if (!string.IsNullOrEmpty(_authToken))
|
||
{
|
||
headers.Add("Authorization", _authToken);
|
||
}
|
||
}
|
||
|
||
return headers;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 初始遥信遥测redis列表
|
||
/// </summary>
|
||
public async Task InitYXYCRedisListAsync(DataSourceCategoryEnum dataSourceCategory)
|
||
{
|
||
try
|
||
{
|
||
|
||
var headers = GetAuthHeaders();
|
||
|
||
var resObj = ToolLibrary
|
||
.HttpHelper
|
||
.HttpGetRequest<JObject>
|
||
(_apiEndpoints
|
||
.RequestInitYXRedisListUri + "?dataSourceCategory=" + (int)dataSourceCategory,
|
||
headers
|
||
);//在web端填充数据
|
||
var resObj1 = ToolLibrary
|
||
.HttpHelper
|
||
.HttpGetRequest<JObject>
|
||
(_apiEndpoints
|
||
.RequestInitYCRedisListUri + "?dataSourceCategory=" + (int)dataSourceCategory,
|
||
headers
|
||
);//在web端填充数据
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
// 记录异常信息,但不抛出,保持方法的稳定性
|
||
_logger.LogError(ex, "初始化遥信遥测Redis列表失败");
|
||
_ = ex; // 避免编译器警告
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取所有保护装置的简要信息
|
||
/// </summary>
|
||
/// <returns>保护装置简要信息列表</returns>
|
||
public async Task<List<ProtectionDeviceSummaryDto>> GetAllProtectionDevicesSummaryAsync()
|
||
{
|
||
try
|
||
{
|
||
_logger.LogInformation("开始获取保护装置简要信息");
|
||
|
||
// 调用 API 获取保护装置简要信息 - 使用 JObject 来处理 ABP 框架响应
|
||
var response = await Task.Run(() =>
|
||
ToolLibrary.HttpHelper.HttpGetRequest<JObject>(
|
||
_apiEndpoints.RequestProtectionDevicesSummaryUri));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
// 尝试解析 ABP 框架响应结构
|
||
var result = ExtractDataFromAbpResponse<List<ProtectionDeviceSummaryDto>>(response);
|
||
|
||
if (result != null && result.Count > 0)
|
||
{
|
||
_logger.LogInformation("成功获取保护装置简要信息,数量: {Count}", result.Count);
|
||
return result;
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("API返回的数据为空或解析失败");
|
||
return new List<ProtectionDeviceSummaryDto>();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("API响应为null");
|
||
return new List<ProtectionDeviceSummaryDto>();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "获取保护装置简要信息时发生异常");
|
||
return new List<ProtectionDeviceSummaryDto>();
|
||
}
|
||
}
|
||
/// <summary>
|
||
/// 获取装置通信地址
|
||
/// </summary>
|
||
/// <param name="stationName"></param>
|
||
/// <returns></returns>
|
||
public List<ProtectionDeviceCommInfoOutput> GetProtectionDeviceCommInfos()
|
||
{
|
||
try
|
||
{
|
||
JObject rstDataJObject = ToolLibrary
|
||
.HttpHelper
|
||
.HttpGetRequest<JObject>
|
||
(_apiEndpoints
|
||
.RequestProtectionDeviceCommInfos + "?stationName=神池南"
|
||
);
|
||
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
||
if (rst != null)
|
||
{
|
||
var res = rst.ToObject<List<ProtectionDeviceCommInfoOutput>>();
|
||
return res;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取所有保护装置的简要信息(带重试机制)
|
||
/// </summary>
|
||
/// <param name="maxRetries">最大重试次数</param>
|
||
/// <param name="retryDelayMs">重试间隔(毫秒)</param>
|
||
/// <returns>保护装置简要信息列表</returns>
|
||
public async Task<List<ProtectionDeviceSummaryDto>> GetAllProtectionDevicesSummaryWithRetryAsync(
|
||
int maxRetries = 3,
|
||
int retryDelayMs = 1000)
|
||
{
|
||
for (int attempt = 1; attempt <= maxRetries; attempt++)
|
||
{
|
||
try
|
||
{
|
||
var result = await GetAllProtectionDevicesSummaryAsync();
|
||
if (result != null && result.Count > 0)
|
||
{
|
||
_logger.LogInformation("第 {Attempt} 次尝试成功获取到 {Count} 条保护装置信息", attempt, result.Count);
|
||
return result;
|
||
}
|
||
|
||
if (attempt < maxRetries)
|
||
{
|
||
_logger.LogWarning("第 {Attempt} 次获取保护装置信息失败,{RetryDelayMs}ms 后重试", attempt, retryDelayMs);
|
||
await Task.Delay(retryDelayMs);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "第 {Attempt} 次获取保护装置信息时发生异常", attempt);
|
||
|
||
if (attempt < maxRetries)
|
||
{
|
||
_logger.LogInformation("等待 {RetryDelayMs}ms 后进行第 {NextAttempt} 次重试", retryDelayMs, attempt + 1);
|
||
await Task.Delay(retryDelayMs);
|
||
}
|
||
}
|
||
}
|
||
|
||
_logger.LogError("经过 {MaxRetries} 次重试后仍无法获取保护装置信息", maxRetries);
|
||
return new List<ProtectionDeviceSummaryDto>();
|
||
}
|
||
|
||
/// <summary>
|
||
/// 从 ABP 框架响应中提取数据
|
||
/// 支持多种可能的响应结构:
|
||
/// 1. ABP 标准响应: { "result": { "resultData": [...], "flag": true }, "success": true }
|
||
/// 2. 直接 RequestResult: { "resultData": [...], "flag": true }
|
||
/// 3. 直接数据数组: [...]
|
||
/// </summary>
|
||
/// <typeparam name="T">目标数据类型</typeparam>
|
||
/// <param name="response">API响应的JObject</param>
|
||
/// <returns>提取的数据,失败时返回default(T)</returns>
|
||
private T ExtractDataFromAbpResponse<T>(JObject response)
|
||
{
|
||
try
|
||
{
|
||
var resultToken = response["result"];
|
||
if (resultToken != null)
|
||
{
|
||
var resultDataToken = resultToken["resultData"];
|
||
if (resultDataToken != null)
|
||
{
|
||
return resultDataToken.ToObject<T>();
|
||
}
|
||
return resultToken.ToObject<T>();
|
||
}
|
||
|
||
var directResultDataToken = response["resultData"];
|
||
if (directResultDataToken != null)
|
||
{
|
||
return directResultDataToken.ToObject<T>();
|
||
}
|
||
return response.ToObject<T>();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "解析 ABP 响应时发生异常,响应内容: {Response}", response.ToString());
|
||
return default(T);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 检查 ABP 响应是否表示成功
|
||
/// </summary>
|
||
/// <param name="response">API响应的JObject</param>
|
||
/// <returns>是否成功</returns>
|
||
private bool IsAbpResponseSuccessful(JObject response)
|
||
{
|
||
try
|
||
{
|
||
// 检查 ABP 标准成功标志
|
||
var successToken = response["success"];
|
||
if (successToken != null && successToken.Type == JTokenType.Boolean)
|
||
{
|
||
return successToken.Value<bool>();
|
||
}
|
||
|
||
// 检查 result.flag
|
||
var resultToken = response["result"];
|
||
if (resultToken != null)
|
||
{
|
||
var flagToken = resultToken["flag"];
|
||
if (flagToken != null && flagToken.Type == JTokenType.Boolean)
|
||
{
|
||
return flagToken.Value<bool>();
|
||
}
|
||
}
|
||
|
||
// 检查直接的 flag
|
||
var directFlagToken = response["flag"];
|
||
if (directFlagToken != null && directFlagToken.Type == JTokenType.Boolean)
|
||
{
|
||
return directFlagToken.Value<bool>();
|
||
}
|
||
|
||
// 如果没有明确的成功标志,检查是否有错误信息
|
||
var errorToken = response["error"];
|
||
if (errorToken != null && errorToken.Type != JTokenType.Null)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
// 默认认为成功(如果有数据且没有错误)
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "检查 ABP 响应成功状态时发生异常");
|
||
return false;
|
||
}
|
||
}
|
||
|
||
internal async Task<Guid> GetTwIdAsync(string twinId)
|
||
{
|
||
try
|
||
{
|
||
JObject rstDataJObject = ToolLibrary
|
||
.HttpHelper
|
||
.HttpGetRequest<JObject>
|
||
(_apiEndpoints
|
||
.GetTwId + "?code="+ twinId
|
||
);
|
||
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
||
if (rst != null)
|
||
{
|
||
var res = rst.ToObject<Guid>();
|
||
return res;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
}
|
||
return default;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取网线配置数据列表
|
||
/// </summary>
|
||
/// <returns>网线配置数据列表</returns>
|
||
public async Task<List<NetworkCableDto>> GetNetworkCableListAsync()
|
||
{
|
||
try
|
||
{
|
||
_logger.LogInformation("开始获取网线配置数据");
|
||
|
||
var requestBody = new
|
||
{
|
||
searchCondition = new
|
||
{
|
||
isActive = true
|
||
},
|
||
pageIndex = 1,
|
||
pageSize = 10000 // 获取所有数据
|
||
};
|
||
|
||
var response = await Task.Run(() =>
|
||
ToolLibrary.HttpHelper.HttpPostRequest<JObject>(
|
||
$"{_apiEndpoints.RequestNetworkCableGetList}",
|
||
requestBody));
|
||
|
||
if (response != null)
|
||
{
|
||
var result = ExtractDataFromAbpResponse<List<NetworkCableDto>>(response);
|
||
if (result != null && result.Count > 0)
|
||
{
|
||
_logger.LogInformation("成功获取网线配置数据,数量: {Count}", result.Count);
|
||
return result;
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("网线配置数据为空或解析失败");
|
||
return new List<NetworkCableDto>();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("网线配置API响应为null");
|
||
return new List<NetworkCableDto>();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "获取网线配置数据时发生异常");
|
||
return new List<NetworkCableDto>();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取光缆配置数据列表
|
||
/// </summary>
|
||
/// <returns>光缆配置数据列表</returns>
|
||
public async Task<List<OpticalCableDto>> GetOpticalCableListAsync()
|
||
{
|
||
try
|
||
{
|
||
_logger.LogInformation("开始获取光缆配置数据");
|
||
|
||
var requestBody = new
|
||
{
|
||
searchCondition = new
|
||
{
|
||
isActive = true
|
||
},
|
||
pageIndex = 1,
|
||
pageSize = 10000 // 获取所有数据
|
||
};
|
||
|
||
var response = await Task.Run(() =>
|
||
ToolLibrary.HttpHelper.HttpPostRequest<JObject>(
|
||
$"{_apiEndpoints.RequestOpticalCableGetList}",
|
||
requestBody));
|
||
|
||
if (response != null)
|
||
{
|
||
var result = ExtractDataFromAbpResponse<List<OpticalCableDto>>(response);
|
||
if (result != null && result.Count > 0)
|
||
{
|
||
_logger.LogInformation("成功获取光缆配置数据,数量: {Count}", result.Count);
|
||
return result;
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("光缆配置数据为空或解析失败");
|
||
return new List<OpticalCableDto>();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("光缆配置API响应为null");
|
||
return new List<OpticalCableDto>();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "获取光缆配置数据时发生异常");
|
||
return new List<OpticalCableDto>();
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取光纤配置数据列表
|
||
/// </summary>
|
||
/// <returns>光纤配置数据列表</returns>
|
||
public async Task<List<OpticalFiberDto>> GetOpticalFiberListAsync()
|
||
{
|
||
try
|
||
{
|
||
_logger.LogInformation("开始获取光纤配置数据");
|
||
|
||
var requestBody = new
|
||
{
|
||
searchCondition = new
|
||
{
|
||
isActive = true
|
||
},
|
||
pageIndex = 1,
|
||
pageSize = 10000 // 获取所有数据
|
||
};
|
||
|
||
var response = await Task.Run(() =>
|
||
ToolLibrary.HttpHelper.HttpPostRequest<JObject>(
|
||
$"{_apiEndpoints.RequestOpticalFiberGetList}",
|
||
requestBody));
|
||
|
||
if (response != null)
|
||
{
|
||
var result = ExtractDataFromAbpResponse<List<OpticalFiberDto>>(response);
|
||
if (result != null && result.Count > 0)
|
||
{
|
||
_logger.LogInformation("成功获取光纤配置数据,数量: {Count}", result.Count);
|
||
return result;
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("光纤配置数据为空或解析失败");
|
||
return new List<OpticalFiberDto>();
|
||
}
|
||
}
|
||
else
|
||
{
|
||
_logger.LogWarning("光纤配置API响应为null");
|
||
return new List<OpticalFiberDto>();
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "获取光纤配置数据时发生异常");
|
||
return new List<OpticalFiberDto>();
|
||
}
|
||
}
|
||
|
||
internal async Task CallPushAlarmsApiAsync(YounuoAlert alarmData)
|
||
{
|
||
try
|
||
{
|
||
var response = await Task.Run(() =>
|
||
ToolLibrary.HttpHelper.HttpPostRequest<JObject>(
|
||
$"{_apiEndpoints.RequestBeijingYounuoApiPushYounuoAlert}",
|
||
alarmData));
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
internal async Task CallDeleteAlarmsByTwinIdApiAsync(string twinId)
|
||
{
|
||
try
|
||
{
|
||
var response = await Task.Run(() =>
|
||
ToolLibrary.HttpHelper.HttpGetRequest<JObject>(
|
||
$"{_apiEndpoints.RequestBeijingYounuoApiPushYounuoAlert}?twinId={twinId}"));
|
||
}
|
||
catch (Exception)
|
||
{
|
||
|
||
}
|
||
}
|
||
|
||
//上传报警
|
||
public async Task UploadAlertMessageAsync(List<AlertData> alertDatas)
|
||
{
|
||
try
|
||
{
|
||
//告警上传
|
||
foreach (var alert in alertDatas)
|
||
{
|
||
await HttpHelper.HttpPostRequestAsync<object>(_apiEndpoints.AlarmUploadUri, alert);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call UploadAlertMessageAsync Api");
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取二次回路巡检计划
|
||
/// </summary>
|
||
/// <returns>二次回路巡检计划列表</returns>
|
||
public async Task<List<SecondaryCircuitInspectionPlanOutput>> GetSecondaryCircuitInspectionPlanListAsync(int start)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await HttpHelper.HttpPostRequestAsync<JObject>(_apiEndpoints.SecondaryCircuitInspectionPlanUri, new { maxResultCount = 10, skipCount = start, includeInspectionItems = true });
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<SecondaryCircuitInspectionPlanOutput>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch(Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetSecondaryCircuitInspectionPlanListAsync Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取时间巡检的配置数据
|
||
/// </summary>
|
||
public async Task<List<SecondaryCircuitEventDrivenConfigOutput>> GetCircuitEventDrivenConfigAsync(int start)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await HttpHelper.HttpPostRequestAsync<JObject>(_apiEndpoints.GetCircuitEventDrivenConfigUri, new { maxResultCount = 10, skipCount = start, includeInspectionItems = true });
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<SecondaryCircuitEventDrivenConfigOutput>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetCircuitEventDrivenConfigAsync Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
/// <summary>
|
||
/// 获取孪生体与遥测数据绑定关系
|
||
/// </summary>
|
||
public async Task<List<ThingDeviceBindingModel>> GetThingDeviceBindingConfigAsync()
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await HttpHelper.HttpPostRequestAsync<JObject>(_apiEndpoints.ThingDeviceBindingConfigUri, new object());
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<ThingDeviceBindingModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetThingDeviceBindingConfigAsync Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取设备和孪生体的关联,使用这个关联关系,推送设备数据到是三维场景
|
||
/// </summary>
|
||
public async Task<List<TingSimDataModel>> GetThingSimDatasConfigAsync()
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => ToolLibrary.HttpHelper.HttpGetRequest<JObject>(_apiEndpoints.ThingSimDatasUri));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<TingSimDataModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetThingSimDatasConfigAsync Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询遥测
|
||
/// </summary>
|
||
public async Task<List<ZzDataResultModel>?> GetTelemetryInfoData(string id)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => ToolLibrary.HttpHelper.HttpGetRequest<JObject>($"{_apiEndpoints.GetTelemetryInfoDataUri}?id={id}"));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<ZzDataResultModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetTelemetryInfoData Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询遥信
|
||
/// </summary>
|
||
public async Task<List<ZzDataResultModel>?> GetTeleSignalData(string id)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => ToolLibrary.HttpHelper.HttpGetRequest<JObject>($"{_apiEndpoints.GetTeleSignalDataUri}?id={id}"));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<ZzDataResultModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetTeleSignalData Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询定值
|
||
/// </summary>
|
||
public async Task<List<DeviceDzData>?> GetDeviceDzData(string id)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => ToolLibrary.HttpHelper.HttpGetRequest<JObject>($"{_apiEndpoints.GetDeviceDzDataUri}?id={id}"));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<DeviceDzData>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetTeleSignalData Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询预置位的巡检结果
|
||
/// </summary>
|
||
public async Task<List<InspectionResultData>?> GetInspectionResultData(string id)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => ToolLibrary.HttpHelper.HttpGetRequest<JObject>($"{_apiEndpoints.GetInspectionResultDataUri}?id={id}"));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<InspectionResultData>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetTeleSignalData Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询网关数据
|
||
/// </summary>
|
||
public async Task<List<ZzDataResultModel>?> GetGatewayInfoData(string id)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => ToolLibrary.HttpHelper.HttpGetRequest<JObject>($"{_apiEndpoints.GetGatewayInfoDataUri}?id={id}"));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<ZzDataResultModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetTeleSignalData Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 查询虚点信息
|
||
/// </summary>
|
||
public async Task<List<ZzDataResultModel>?> GetVirtualPointInfoData(string id)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => ToolLibrary.HttpHelper.HttpGetRequest<JObject>($"{_apiEndpoints.GetVirtualPointInfoDataUri}?id={id}"));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<ZzDataResultModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetTeleSignalData Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取网线配置
|
||
/// </summary>
|
||
public async Task<List<OpticalFiberConfigModel>> GetNetworkCableConfigAsync()
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => HttpHelper.HttpPostRequestAsync<JObject>(_apiEndpoints.GetNetworkCableConfigUri, new object()));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<OpticalFiberConfigModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetNetworkCableConfigAsync Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取光纤配置
|
||
/// </summary>
|
||
public async Task<List<OpticalFiberConfigModel>> GetOpticalFiberConfigAsync()
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => HttpHelper.HttpPostRequestAsync<JObject>(_apiEndpoints.GetOpticalFiberConfigUri, new object()));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<OpticalFiberConfigModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetOpticalFiberConfigAsync Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 获取光缆配置
|
||
/// </summary>
|
||
public async Task<List<OpticalFiberConfigModel>> GetOpticalCableConfigAsync()
|
||
{
|
||
try
|
||
{
|
||
var response = await Task.Run(() => HttpHelper.HttpPostRequestAsync<JObject>(_apiEndpoints.GetOpticalCableConfigUri, new { includeInspectionItems = true }));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<OpticalFiberConfigModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetOpticalCableConfigAsync Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 保存巡检计划执行结果
|
||
/// </summary>
|
||
public async Task<string> SaveSecondaryCircuitInspectionPlanResultAsync(SecondaryCircuitInspectionResultSaveModel data)
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => HttpHelper.HttpPostRequestAsync<JObject>(_apiEndpoints.SaveSecondaryCircuitInspectionPlanResultUri, data));
|
||
|
||
if (response != null)
|
||
{
|
||
var result = ExtractDataFromAbpResponse<string>(response);
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetOpticalCableConfigAsync Api");
|
||
}
|
||
|
||
return string.Empty;
|
||
}
|
||
|
||
//调用Ai
|
||
public async Task<string> GetAIAnalysis(object data)
|
||
{
|
||
try
|
||
{
|
||
|
||
ThingWebClientHelper httpClient = new ThingWebClientHelper();
|
||
var result = await httpClient.PostJsonAsync(_apiEndpoints.GetAIAnalysisUri, data);
|
||
|
||
return result;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetOpticalCableConfigAsync Api");
|
||
}
|
||
|
||
return string.Empty;
|
||
}
|
||
|
||
|
||
//巡检计划执行结果AI诊断更新
|
||
public async Task<bool> UpdateReportWithAIAnalysisAsync(SecondaryCircuitInspectionAiSaveModel data)
|
||
{
|
||
try
|
||
{
|
||
var response = await Task.Run(() => HttpHelper.HttpPostRequestAsync<JObject>(_apiEndpoints.UpdateReportWithAIAnalysisUri, data));
|
||
|
||
if (response != null)
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetOpticalCableConfigAsync Api");
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
|
||
//获取虚点信息
|
||
public async Task<List<ZzDataHistoryModel>> GetVariantBaseinfoAsync()
|
||
{
|
||
try
|
||
{
|
||
|
||
var response = await Task.Run(() => ToolLibrary.HttpHelper.HttpGetRequest<JObject>(_apiEndpoints.GetVariantBaseinfoUri));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<ZzDataHistoryModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetOpticalCableConfigAsync Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
|
||
//获取网关信息
|
||
public async Task<List<ZzDataHistoryModel>> GetGateWayBaseInfoAsync()
|
||
{
|
||
try
|
||
{
|
||
var response = await Task.Run(() => ToolLibrary.HttpHelper.HttpGetRequest<JObject>(_apiEndpoints.GetGateWayBaseInfoUri));
|
||
|
||
if (response != null)
|
||
{
|
||
|
||
var result = ExtractDataFromAbpResponse<List<ZzDataHistoryModel>>(response);
|
||
|
||
return result;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
_logger.LogError(ex, "Error Call GetOpticalCableConfigAsync Api");
|
||
}
|
||
|
||
return null;
|
||
}
|
||
}
|
||
}
|