859 lines
33 KiB
C#
859 lines
33 KiB
C#
using Abp.Dependency;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Helper;
|
|
using Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model;
|
|
using Yunda.ISAS.DataMonitoringServer.DataCenter;
|
|
using Yunda.SOMS.DataMonitoringServer.Service.DataAnalysis.Model;
|
|
using YunDa.ISAS.DataTransferObject.CommonDto;
|
|
using YunDa.ISAS.DataTransferObject.DataMonitoring.TelecommandConfigurationDto;
|
|
using YunDa.ISAS.DataTransferObject.DataMonitoring.TelecommandConfigurationDto.SearchCondition;
|
|
using YunDa.ISAS.DataTransferObject.DataMonitoring.TelecommandPlanDto.TelecommandPlanTimeDto;
|
|
using YunDa.ISAS.DataTransferObject.EquipmentLiveData;
|
|
using YunDa.ISAS.DataTransferObject.GeneralInformation.EquipmentInfoDto;
|
|
using YunDa.ISAS.DataTransferObject.GeneralInformation.TransformerSubstationDto;
|
|
using YunDa.ISAS.DataTransferObject.Iec104;
|
|
using YunDa.ISAS.DataTransferObject.PatternRecognition;
|
|
using YunDa.ISAS.DataTransferObject.System.FunctionDto;
|
|
using YunDa.ISAS.DataTransferObject.VideoSurveillance.MeasureTemperatureResultDto;
|
|
using YunDa.ISAS.DataTransferObject.VideoSurveillance.PresetPointDto;
|
|
using YunDa.ISAS.DataTransferObject.VideoSurveillance.VideoDevDto;
|
|
using YunDa.ISAS.Entities.DataMonitoring;
|
|
using YunDa.ISAS.ExternalInteraction.DataTransferObject.InspectionEquipment;
|
|
using YunDa.ISAS.ExternalInteraction.DataTransferObject.InspectionEquipment.RequestInput;
|
|
using ConstantModel = Yunda.ISAS.DataMonitoringServer.DataAnalysis.Model.ConstantModel;
|
|
|
|
namespace Yunda.ISAS.DataMonitoringServer.DataAnalysis
|
|
{
|
|
public class WebApiRequest : ISingletonDependency
|
|
{
|
|
private readonly Content _settingModel;
|
|
private readonly ConfigurationHepler _configurationHepler;
|
|
private readonly RunningDataCache _runningDataCache;
|
|
private readonly RedisDataRepository _redisDataRepository;
|
|
private readonly Content _content;
|
|
|
|
public WebApiRequest(Content settingModel,
|
|
ConfigurationHepler configurationHepler,
|
|
RunningDataCache runningDataCache,
|
|
RedisDataRepository redisDataRepository,
|
|
Content content
|
|
)
|
|
{
|
|
_runningDataCache = runningDataCache;
|
|
_settingModel = settingModel;
|
|
_configurationHepler = configurationHepler;
|
|
_redisDataRepository = redisDataRepository;
|
|
_content = content;
|
|
}
|
|
/// <summary>
|
|
/// 更新安放信息
|
|
/// </summary>
|
|
public void UpdateEuipmentSafetyData()
|
|
{
|
|
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper
|
|
.HttpGetRequest<JObject>(ConstantModel
|
|
.RequestEquipmentInfoEquipmenSafetyStateTypetGetAllsUri + "?id=" + _configurationHepler.SubstationId);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst != null)
|
|
{
|
|
var equipmentData = rst.ToObject<List<EquipmentInfoOutput>>();
|
|
equipmentData?.ForEach(t =>
|
|
{
|
|
if (_runningDataCache.EquipmentDataDic.ContainsKey(t.Id))
|
|
{
|
|
_runningDataCache.EquipmentDataDic[t.Id].SafetyStateType = t.SafetyStateType;
|
|
}
|
|
});
|
|
// _redisDataRepository.EquipmentDataModelDicRedis.HashSetUpdateManyAsync(ConstantModel.EquipmentDataModelDicRedisKey, EquipmentDataDic.Keys.ToList(), EquipmentDataDic.Values.ToList());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine(ex.Message);
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取遥控配置数据
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
/// <returns></returns>
|
|
public void GetTelecommandModels(Guid transformerSubstationId)
|
|
{
|
|
var req = new
|
|
{
|
|
transformerSubstationId
|
|
};
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpPostRequest<JObject>(ConstantModel.RequestTelecommandConfigurationFindDatasToNopageListUri, req);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst != null)
|
|
{
|
|
List<TelecommandModel> telecommandModels = rst.ToObject<List<TelecommandModel>>();
|
|
telecommandModels.ForEach(t => _runningDataCache.TelecommandModels.Add(t));
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取视频设备配置数据
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
/// <returns></returns>
|
|
public void GetVideoDevs(Guid transformerSubstationId)
|
|
{
|
|
var req = new
|
|
{
|
|
transformerSubstationId
|
|
};
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpPostRequest<JObject>(ConstantModel.RequestVideoDevFindDatasToNopageListUri, req);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst != null)
|
|
{
|
|
_runningDataCache.VideoDevs.Clear();
|
|
var list = rst.ToObject<List<VideoDev>>().ToList();
|
|
list.ForEach(t => { _runningDataCache.VideoDevs.Add(t); });
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取车站数据
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public List<SelectModelOutput> GetTransubstationDatas()
|
|
{
|
|
var req = new
|
|
{
|
|
};
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpPostRequest<JObject>(ConstantModel.RequestTransformerSubstationFindTransformerSubstationForSelectUri, req);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst != null)
|
|
{
|
|
var jsonB = JsonConvert.SerializeObject(rst);
|
|
var transformerSubstations = JsonConvert.DeserializeObject<List<SelectModelOutput>>(jsonB);
|
|
return transformerSubstations;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|
}
|
|
|
|
return null;
|
|
}
|
|
public void GetTransubstationInfo(Guid id)
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpGetRequest<JObject>(ConstantModel.RequestTransformerSubstationFindTransformerSubstationByIdUri + "?id="+ id);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst != null)
|
|
{
|
|
var jsonB = JsonConvert.SerializeObject(rst);
|
|
_runningDataCache._transformerSubstation = JsonConvert.DeserializeObject<TransformerSubstationOutput>(jsonB);
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 写布防设备到数据库 - 交由web处理
|
|
/// </summary>
|
|
/// <param name="armingDisarmingModel"></param>
|
|
public void SendArmsEquipmentsUpdate(ArmingDisarmingModel armingDisarmingModel, int state)
|
|
{
|
|
try
|
|
{
|
|
JObject rstDataJObject1 = ToolLibrary.HttpHelper.HttpPostRequest<JObject>(ConstantModel.RequestEquipmentsSafetyStateUpdateUri + "?seconds=" + armingDisarmingModel.DelaySeconds + "&safetyState=" + state, armingDisarmingModel.EquipmentIds);
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|
}
|
|
}
|
|
|
|
public int GetEquipmentSafetyState(Guid guid)
|
|
{
|
|
try
|
|
{
|
|
JObject rstDataJObject1 = ToolLibrary.HttpHelper.HttpGetRequest<JObject>(ConstantModel.RequestEquipmentInfoSafetyStateTypetGetUri + "?id=" + guid);
|
|
var rst1 = rstDataJObject1?["result"]?["resultData"];//获取结果集
|
|
if (rst1 != null)
|
|
{
|
|
return int.Parse(rst1.ToString());
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|
}
|
|
return 0;
|
|
}
|
|
/// <summary>
|
|
/// 获取设备下所有三遥数据配置
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
public void GetEquipmentData(Guid? transformerSubstationId)
|
|
{
|
|
var req = new
|
|
{
|
|
transformerSubstationId,
|
|
};
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper
|
|
.HttpPostRequestWithRetry<JObject>(ConstantModel.RequestEquipmentInfoGetMonitoringEquipmentInfosUri, req);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst != null)
|
|
{
|
|
var equipmentData = rst.ToObject<List<EquipmentDataModel>>();
|
|
equipmentData?.ForEach(t =>
|
|
{
|
|
t.TransformerSubstationId = (Guid)transformerSubstationId;
|
|
if (!_runningDataCache.EquipmentDataDic.ContainsKey(t.EquipmentInfoId))
|
|
{
|
|
_runningDataCache.EquipmentDataDic.TryAdd(t.EquipmentInfoId, t);
|
|
}
|
|
else
|
|
{
|
|
_runningDataCache.EquipmentDataDic[t.EquipmentInfoId] = t;
|
|
}
|
|
t.Telemeterings.ForEach((m) =>
|
|
{
|
|
TelemeteringHourStatisticsModel hourSt = new TelemeteringHourStatisticsModel();
|
|
hourSt.TelemeteringConfigurationId = m.Id;
|
|
if (_runningDataCache.TelemeteringHourStatisticsDic.ContainsKey(m.Id))
|
|
{
|
|
_runningDataCache.TelemeteringHourStatisticsDic[m.Id] = hourSt;
|
|
}
|
|
else
|
|
{
|
|
_runningDataCache.TelemeteringHourStatisticsDic.Add(m.Id, hourSt);
|
|
}
|
|
});
|
|
});
|
|
}
|
|
var count = _runningDataCache.TelemeteringHourStatisticsDic.Count();
|
|
MonitoringEventBus.LogHandler($"从服务器获取了{count}条遥测小时统计配置数据", "服务器数据更新");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.ToString(), "异常信息");
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取联动策略数据
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
public void GetLinkageStrategyData(Guid? transformerSubstationId)
|
|
{
|
|
var req = new
|
|
{
|
|
transformerSubstationId,
|
|
};
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpPostRequestWithRetry<JObject>(ConstantModel.RequestLinkageStrategyGetMonitoringLinkageStrategiesUri, req);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst != null)
|
|
{
|
|
var data = rst.ToObject<List<LinkageStrategyModel>>();
|
|
_runningDataCache.LinkageStrategys.Clear();
|
|
data.ForEach(t =>
|
|
{
|
|
_runningDataCache.LinkageStrategys.Add(t);
|
|
});
|
|
}
|
|
var count = _runningDataCache.LinkageStrategys.Count;
|
|
MonitoringEventBus.LogHandler($"从服务器获取了{count}条联动配置数据", "服务器数据更新");
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.ToString(), "异常信息");
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取设备信息
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
public EquipmentInfoOutput GetEquipmentInfo(Guid id)
|
|
{
|
|
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpGetRequest<JObject>(ConstantModel.RequestEquipmentInfoUri + "?id=" + id);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst != null)
|
|
{
|
|
return rst.ToObject<EquipmentInfoOutput>();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.ToString(), "异常信息");
|
|
}
|
|
return null;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取视频设备信息
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
public VideoDevOutput GetVideoDevInfo(Guid id)
|
|
{
|
|
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpPostRequestWithRetry<JObject>(ConstantModel.RequestEquipmentInfoUri + "?id=" + id);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst != null)
|
|
{
|
|
return rst.ToObject<VideoDevOutput>();
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.ToString(), "异常信息");
|
|
}
|
|
return null;
|
|
|
|
}
|
|
/// <summary>
|
|
/// 获取摄像机权限
|
|
/// </summary>
|
|
/// <param name="camId"></param>
|
|
/// <param name="time"></param>
|
|
/// <param name="code"></param>
|
|
/// <returns></returns>
|
|
public bool GetApplyControlToExternalstr(Guid camId, int time, string code)
|
|
{
|
|
|
|
var rst = true;
|
|
if (!_content.IsAuthority)
|
|
{
|
|
return rst;
|
|
}
|
|
var req = new CameraControlInput
|
|
{
|
|
SubId = _configurationHepler.SubstationId,
|
|
CamNames = new List<CameraCa>() { new CameraCa() { CamId = camId, OperatingTime = time, UseDesc = "联动" } },
|
|
Code = code
|
|
};
|
|
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpPostRequest<JObject>(ConstantModel.RequestcameraControlRequestToExternalstrUri, req);
|
|
|
|
bool.TryParse(rstDataJObject?["flag"].ToString(), out rst);
|
|
if (rst)
|
|
{
|
|
ApplyCamAuResult applyCamAuResult = JsonConvert.DeserializeObject<ApplyCamAuResult>(rstDataJObject?["resultData"].ToString());
|
|
|
|
if (applyCamAuResult.Success.FirstOrDefault(t => t.Id == camId) != null)
|
|
{
|
|
rst = true;
|
|
}
|
|
else
|
|
{
|
|
rst = false;
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.ToString(), "异常信息");
|
|
rst = false;
|
|
}
|
|
|
|
return rst;
|
|
}
|
|
public bool GetCamAuthToExternalstr(string camName)
|
|
{
|
|
var rst = true;
|
|
|
|
var req = new
|
|
{
|
|
subName = _configurationHepler.SubstationName,
|
|
camName,
|
|
useDesc = "联动"
|
|
};
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpPostRequest<JObject>(ConstantModel.RequestApplyControlToExternalstrUri, req);
|
|
bool.TryParse(rstDataJObject?["flag"].ToString(), out rst);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.ToString(), "异常信息");
|
|
}
|
|
return rst;
|
|
}
|
|
public bool SendFreeCamAuth(ApplyControlToExternalInput req)
|
|
{
|
|
var rst = true;
|
|
req.SubName = _configurationHepler.SubstationName;
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary.HttpHelper.HttpPostRequest<JObject>(ConstantModel.RequestCameraAuthFreeToExternalstrUri, req);
|
|
bool.TryParse(rstDataJObject?["flag"].ToString(), out rst);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|
}
|
|
|
|
return rst;
|
|
}
|
|
/// <summary>
|
|
/// 初始化相机权限
|
|
/// </summary>
|
|
public void InitCamAuthCache()
|
|
{
|
|
try
|
|
{
|
|
ToolLibrary.HttpHelper.HttpGetRequestWithRetry<JObject>(ConstantModel.RequestUpdateRedisVideoDataToExternalstrUri);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取系统配置
|
|
/// </summary>
|
|
/// <param name="substationId"></param>
|
|
/// <returns></returns>
|
|
public JObject GetSysCfg(Guid substationId)
|
|
{
|
|
try
|
|
{
|
|
var res = ToolLibrary.HttpHelper.HttpGetRequestWithRetry<JObject>
|
|
(ConstantModel.RequestConfigurationGetCfgUri
|
|
+ $"?name={ConstantModel.configurationName}&" + $"stationId={substationId}");
|
|
return res;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|
}
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
/// 修改系统配置
|
|
/// </summary>
|
|
/// <param name="substationId"></param>
|
|
/// <returns></returns>
|
|
public void SetSysCfg(EditSysConfigurationInput input)
|
|
{
|
|
try
|
|
{
|
|
var res = ToolLibrary.HttpHelper.HttpPostRequest<JObject>
|
|
(ConstantModel.RequestConfigurationSetCfgUri, input);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "异常信息");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 创建联动结果并从服务器获取联动文件存储相对路径
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public string GetRelativePath(ref LinkageResultInput req)
|
|
{
|
|
JObject rstDataCreateOrUpdate = ToolLibrary.HttpHelper.HttpPostRequest<JObject>(ConstantModel.RequestLinkageResultCreateOrUpdateUri, req);
|
|
|
|
var rstCreateOrUpdate = rstDataCreateOrUpdate?["result"]?["resultData"];//获取结果集
|
|
|
|
var fileRelative = rstCreateOrUpdate["relativePath"];
|
|
return fileRelative.ToString();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 从服务器获取测温点信息
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public List<MeasureTemperaturePoint> GetMeasurePointInfoByPresetPointId(Guid PresetPointId)
|
|
{
|
|
var req = new { PresetPointId };
|
|
JObject rst = ToolLibrary.HttpHelper.HttpGetRequest<JObject>(ConstantModel.RequestMeasureTemperaturePointGetDatasByPresetPointIdUri + "?presetPointId=" + PresetPointId);
|
|
|
|
var res = rst?["result"]?["resultData"];//获取结果集
|
|
|
|
var datas = res.ToObject<List<MeasureTemperaturePoint>>();
|
|
return datas;
|
|
}
|
|
/// <summary>
|
|
/// 从服务器获取某个测温点的最近测温数据
|
|
/// </summary>
|
|
/// <param name="req"></param>
|
|
/// <returns></returns>
|
|
public float GetMeasurePointNearestValue(Guid PresetPointId, int number)
|
|
{
|
|
try
|
|
{
|
|
JObject rst = ToolLibrary.HttpHelper.HttpPostRequest<JObject>(ConstantModel.RequestMeasureTemperaturePointGetNearestDataUri, new { PresetPointId, number });
|
|
|
|
var res = rst?["result"]?["resultData"];//获取结果集
|
|
var datas = res.ToObject<MeasureTemperatureResultOutput>();
|
|
return (float)datas.TemperatureValue;
|
|
}
|
|
catch (Exception)
|
|
{
|
|
return -999;
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 根据预置点id 找到摄像头 及其 NVR
|
|
/// </summary>
|
|
/// <param name="presetPointId"></param>
|
|
/// <returns>返回 1 摄像头信息 2 预置点详细信息</returns>
|
|
public (VideoDev, PresetPointProperty) GetVideoDevData(Guid? presetPointId)
|
|
{
|
|
foreach (var video in _runningDataCache.VideoDevs)
|
|
{
|
|
var preset = video?.PresetPoints?.FirstOrDefault(t => t.Id == presetPointId);
|
|
if (preset != null)
|
|
{
|
|
var nvr = _runningDataCache.VideoDevs.FirstOrDefault(t => t.Id == video.VideoDevId);
|
|
var json = JsonConvert.SerializeObject(nvr);
|
|
video.Parent = JsonConvert.DeserializeObject<VideoDevProperty>(json);
|
|
return (video, preset);
|
|
}
|
|
}
|
|
return default;
|
|
}
|
|
/// <summary>
|
|
/// 查询摄像机信息
|
|
/// </summary>
|
|
/// <param name="cameraId"></param>
|
|
/// <returns>返回 1 摄像头信息 2 预置点详细信息</returns>
|
|
public VideoDevProperty GetVideoDevDataByCameraId(Guid? cameraId)
|
|
{
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary
|
|
.HttpHelper
|
|
.HttpGetRequest<JObject>
|
|
(ConstantModel
|
|
.RequestVideoDevFindVideoDevById + $"?id={cameraId}"
|
|
);
|
|
if (rstDataJObject == null)
|
|
{
|
|
return null;
|
|
}
|
|
var res = rstDataJObject?["result"]?["resultData"].ToObject<VideoDevProperty>();
|
|
return res;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "根据变电所Id修改变电所数据服务WebSocket地址信息");
|
|
return default;
|
|
}
|
|
|
|
}
|
|
/// <summary>
|
|
/// 根据变电所Id修改变电所服务WebSocket地址信息
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
/// <param name="webSocketConfig"></param>
|
|
/// <returns></returns>
|
|
public void UpdateMonitorServerAddressById()
|
|
{
|
|
try
|
|
{
|
|
|
|
var url = _configurationHepler.GetAppsettingsValue("ConnectionStrings", "Websocket", "Url");//.GetSection("DataMonitoring").GetSection("url").Value;
|
|
if (string.IsNullOrWhiteSpace(url))
|
|
{
|
|
url = "ws://192.168.81.32:9090/DataMonitoring";
|
|
}
|
|
var req = new
|
|
{
|
|
id = _configurationHepler.SubstationId,
|
|
dataMonitoringAddress = url
|
|
};
|
|
JObject rstDataJObject = ToolLibrary
|
|
.HttpHelper
|
|
.HttpPostRequestWithRetry<JObject>
|
|
(ConstantModel
|
|
.RequestTransformerSubstationUpdateDataMonitoringAddressByIdUri,
|
|
req);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "根据变电所Id修改变电所数据服务WebSocket地址信息");
|
|
}
|
|
}
|
|
/// <summary>
|
|
/// 获取灯光遥控数据
|
|
/// </summary>
|
|
public List<TelecommandConfigurationProperty> GetLightingControlTelecommand(Guid transformerSubstationId)
|
|
{
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary
|
|
.HttpHelper
|
|
.HttpGetRequest<JObject>
|
|
(ConstantModel
|
|
.RequestLightingControlTelemandUri + $"?substationId={transformerSubstationId}"
|
|
);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst == null)
|
|
{
|
|
return null;
|
|
}
|
|
var res = rst.ToObject<List<TelecommandConfigurationProperty>>();
|
|
return res;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "获取灯光遥控数据");
|
|
}
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
/// 获取遥控数据
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
/// <returns></returns>
|
|
public List<TelecommandConfigurationProperty> GetTelecommandDatas(Guid transformerSubstationId,int dispatcherAddress)
|
|
{
|
|
try
|
|
{
|
|
TelecommandConfigurationSearchConditionInput input = new TelecommandConfigurationSearchConditionInput();
|
|
input.TransformerSubstationId = transformerSubstationId;
|
|
input.DispatcherAddress = dispatcherAddress;
|
|
JObject rstDataJObject = ToolLibrary
|
|
.HttpHelper
|
|
.HttpPostRequest<JObject>
|
|
(ConstantModel
|
|
.RequestTelecommandUri , input
|
|
);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst == null)
|
|
{
|
|
return null;
|
|
}
|
|
var res = rst.ToObject<List<TelecommandConfigurationProperty>>();
|
|
return res;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "获取遥控计划数据");
|
|
}
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
/// 获取遥控计划数据
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
/// <returns></returns>
|
|
public List<TeleCommandPlanTimeProperty> GetTelecommandPlanDatas(Guid transformerSubstationId)
|
|
{
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary
|
|
.HttpHelper
|
|
.HttpGetRequest<JObject>
|
|
(ConstantModel
|
|
.RequestTelecommandPlanByIdUri + $"?substationId={transformerSubstationId}"
|
|
);
|
|
var rst = rstDataJObject?["result"]?["resultData"];//获取结果集
|
|
if (rst == null)
|
|
{
|
|
return null;
|
|
}
|
|
var res = rst.ToObject<List<TeleCommandPlanTimeProperty>>();
|
|
return res;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "获取遥控计划数据");
|
|
}
|
|
return null;
|
|
}
|
|
/// <summary>
|
|
/// 更新遥控计划执行时间
|
|
/// </summary>
|
|
/// <param name="transformerSubstationId"></param>
|
|
/// <returns></returns>
|
|
public bool UpdateTelecommandSendTime(Guid telecommandPlanTimeId, DateTime dateTime)
|
|
{
|
|
try
|
|
{
|
|
JObject rstDataJObject = ToolLibrary
|
|
.HttpHelper
|
|
.HttpGetRequest<JObject>
|
|
(ConstantModel
|
|
.RequestUpdateTelecommandSendTimeUri + $"?telecommandPlanTimeId={telecommandPlanTimeId}&dateTime={dateTime}"
|
|
);
|
|
var rst = rstDataJObject?["result"]?["flag"];//获取结果集
|
|
if (rst.ToObject<bool>())
|
|
{
|
|
return true;
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "更新遥控计划执行时间");
|
|
}
|
|
return false;
|
|
}
|
|
/// <summary>
|
|
/// 分批上传文件
|
|
/// </summary>
|
|
public string ResumeFile(string url, string fromFileFullPath, string toRelativePath, long startPoint, int byteCount)
|
|
{
|
|
string hostUrl = url;
|
|
string result = "上传成功!";
|
|
byte[] data;
|
|
string fileName = System.IO.Path.GetFileName(fromFileFullPath);
|
|
FileStream fs = new FileStream(fromFileFullPath, FileMode.Open, FileAccess.Read);
|
|
long fileLength = fs.Length;
|
|
BinaryReader bReader = new BinaryReader(fs);
|
|
try
|
|
{
|
|
#region 续传处理
|
|
|
|
if (startPoint == fileLength)
|
|
{
|
|
result = "文件秒传!";
|
|
}
|
|
if (startPoint >= 1 && startPoint <= fileLength - 1)
|
|
{
|
|
fs.Seek(startPoint, SeekOrigin.Current);
|
|
}
|
|
|
|
#endregion 续传处理
|
|
|
|
#region 分割文件上传
|
|
|
|
for (; startPoint <= fileLength - 1; startPoint = startPoint + byteCount)
|
|
{
|
|
int step = 0;
|
|
if (startPoint + byteCount > fileLength)
|
|
{
|
|
data = new byte[Convert.ToInt32(fileLength - startPoint)];
|
|
bReader.Read(data, 0, Convert.ToInt32(fileLength - startPoint));
|
|
step = Convert.ToInt32(fileLength - startPoint);
|
|
}
|
|
else
|
|
{
|
|
data = new byte[byteCount];
|
|
bReader.Read(data, 0, byteCount);
|
|
step = byteCount;
|
|
}
|
|
string contentRange = "bytes " + startPoint + "-" + (startPoint + step) + "/" + fs.Length;
|
|
var rst = ToolLibrary.HttpHelper
|
|
.HttpPostFormDataRequest<JObject>(hostUrl + "?fileName=" + fileName + "&relativePath=" + toRelativePath,
|
|
data, contentRange: contentRange, accessToken: null);
|
|
}
|
|
|
|
#endregion 分割文件上传
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
result = ex.Message;
|
|
}
|
|
bReader.Close();
|
|
fs.Close();
|
|
return result;
|
|
}
|
|
/// <summary>
|
|
/// 获取人员入侵识别结果
|
|
/// </summary>
|
|
/// <param name="filePath"></param>
|
|
/// <returns></returns>
|
|
public string GetPatternRecongnozeResult(string filePath)
|
|
{
|
|
try
|
|
{
|
|
int[] roi = new int[8];
|
|
var data = new
|
|
{
|
|
isNewAlgorithnm = true,
|
|
roi,
|
|
filePath ,
|
|
pluginName = "person"
|
|
};
|
|
JObject rstDataJObject = ToolLibrary
|
|
.HttpHelper
|
|
.HttpPostRequest<JObject>
|
|
(ConstantModel
|
|
.RequestPatternRecogbnizeUri, data
|
|
);
|
|
var res = rstDataJObject.ToObject<PaaternRecognitionResult>();
|
|
if (res.result.Contains("person"))
|
|
{
|
|
SendVisualYx("人员入侵");
|
|
return "人员入侵";
|
|
}
|
|
else if (res.result.Contains("fire"))
|
|
{
|
|
SendVisualYx("火情");
|
|
return "火情出现";
|
|
}
|
|
else
|
|
{
|
|
return "";
|
|
}
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MonitoringEventBus.LogHandler(ex.Message, "获取安防识别结果");
|
|
}
|
|
return "";
|
|
}
|
|
private void SendVisualYx(string name)
|
|
{
|
|
var telesign = _runningDataCache.GetTelesignalisationModel(name: name);
|
|
if (telesign != null)
|
|
{
|
|
var iecdata = new IecServerData();
|
|
iecdata.devAddr = (byte)telesign.InfoDeviceAddress;
|
|
iecdata.dateTime = DateTime.Now;
|
|
iecdata.devCpu = (byte)telesign.InfoCPUSector;
|
|
iecdata.inf = telesign.InfoAddress;
|
|
iecdata.dataType = 2;
|
|
iecdata.devName = "test";
|
|
iecdata.yxValue = telesign.RemoteType == RemoteTypeEnum.SinglePoint ? 1 : 2;
|
|
|
|
Task task = Task.Run(
|
|
() => ToolLibrary.HttpHelper
|
|
.HttpPostRequest(_runningDataCache._transformerSubstation.Iec104ServerUrl + "SendData", iecdata)
|
|
);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|