using Abp.Authorization; using Microsoft.AspNetCore.Mvc; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ToolLibrary.LogHelper; using YunDa.ISAS.Application.Core.SwaggerHelper; using YunDa.ISAS.DataTransferObject; using YunDa.ISAS.DataTransferObject.DataMonitoring.DMAlarmCategoryDto; using YunDa.ISAS.DataTransferObject.DataMonitoring.DMAlarmCategoryDto.SearchCondition; using YunDa.ISAS.DataTransferObject.DataMonitoring.EnvironmentLiveDataDto; using YunDa.ISAS.DataTransferObject.EquipmentLiveData; using YunDa.ISAS.Entities.GeneralInformation; using YunDa.ISAS.Redis.Entities.AlarmCategory; using YunDa.ISAS.Redis.Repositories; namespace YunDa.ISAS.Application.DataMonitoring { public class EnvironmentLiveDataAppService: IEnvironmentLiveDataAppService { private readonly IRedisRepository, string> _equipmentDataModelDicRedis; public EnvironmentLiveDataAppService( IRedisRepository, string> equipmentDataModelDicRedis ) { _equipmentDataModelDicRedis = equipmentDataModelDicRedis; } /// /// 获取实时环境数据 /// /// [HttpGet] [AbpAllowAnonymous] [ShowApi] public async Task> GetEnvironmentLiveData() { RequestResult rst = new RequestResult(); try { var data = new EnvironmentLiveDataOutPut(); var dic = await _equipmentDataModelDicRedis.GetOneAsync(ConstantModel.EquipmentDataModelDicRedisKey); var meteorologicalStation = dic.Values.FirstOrDefault(t => t.EquipmentTypeName == "微气象站" && t.Telemeterings.Count() > 4); if (meteorologicalStation != null) { data.Temperature = GetTelemeteringValue(meteorologicalStation, "温度"); data.WindVelocity = GetTelemeteringValue(meteorologicalStation, "风速"); data.Wind = GetTelemeteringValue(meteorologicalStation, "风向"); data.Humidity = GetTelemeteringValue(meteorologicalStation, "湿度"); data.RainfullOfMinute = GetTelemeteringValue(meteorologicalStation, "分钟雨量"); } rst.ResultData = data; rst.Flag = true; } catch (Exception ex) { Log4Helper.Error(this.GetType(), "获取实时环境数据出错", ex); } return rst; } private float GetTelemeteringValue(EquipmentDataModel meteorologicalStation, string telemeteringName) { var telemetering = meteorologicalStation.Telemeterings.FirstOrDefault(t => t.Name == telemeteringName); return telemetering?.ResultValue ?? 0; } #region 未开放接口 public Task> CreateOrUpdateAsync(EditDMAlarmCategoryInput input) { throw new NotImplementedException(); } public Task DeleteByIdAsync(Guid id) { throw new NotImplementedException(); } public Task DeleteByIdsAsync(List ids) { throw new NotImplementedException(); } public RequestPageResult FindDatas(PageSearchCondition searchCondition) { throw new NotImplementedException(); } #endregion } }