98 lines
3.7 KiB
C#
98 lines
3.7 KiB
C#
![]() |
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<Dictionary<Guid, EquipmentDataModel>, string> _equipmentDataModelDicRedis;
|
|||
|
|
|||
|
public EnvironmentLiveDataAppService(
|
|||
|
IRedisRepository<Dictionary<Guid, EquipmentDataModel>, string> equipmentDataModelDicRedis
|
|||
|
)
|
|||
|
{
|
|||
|
_equipmentDataModelDicRedis = equipmentDataModelDicRedis;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 获取实时环境数据
|
|||
|
/// </summary>
|
|||
|
/// <returns></returns>
|
|||
|
[HttpGet]
|
|||
|
[AbpAllowAnonymous]
|
|||
|
[ShowApi]
|
|||
|
public async Task<RequestResult<EnvironmentLiveDataOutPut>> GetEnvironmentLiveData()
|
|||
|
{
|
|||
|
RequestResult<EnvironmentLiveDataOutPut> rst = new RequestResult<EnvironmentLiveDataOutPut>();
|
|||
|
|
|||
|
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<RequestResult<DMAlarmCategoryOutput>> CreateOrUpdateAsync(EditDMAlarmCategoryInput input)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
|
|||
|
public Task<RequestEasyResult> DeleteByIdAsync(Guid id)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
|
|||
|
public Task<RequestEasyResult> DeleteByIdsAsync(List<Guid> ids)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
|
|||
|
public RequestPageResult<DMAlarmCategoryOutput> FindDatas(PageSearchCondition<DMAlarmCategorySearchConditionInput> searchCondition)
|
|||
|
{
|
|||
|
throw new NotImplementedException();
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|