112 lines
4.2 KiB
C#
112 lines
4.2 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.Entities.GeneralInformation;
|
|
using YunDa.ISAS.Redis.Entities.AlarmCategory;
|
|
using YunDa.ISAS.Redis.Repositories;
|
|
using YunDa.SOMS.DataTransferObject.GeneralInformation.EquipmentLiveData;
|
|
|
|
namespace YunDa.ISAS.Application.DataMonitoring
|
|
{
|
|
public class EnvironmentLiveDataAppService: IEnvironmentLiveDataAppService
|
|
{
|
|
private readonly IRedisRepository<EquipmentDataModel, string> _equipmentDataModelDicRedis;
|
|
|
|
public EnvironmentLiveDataAppService(
|
|
IRedisRepository<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.HashSetGetDicAllAsync(ConstantModel.EquipmentDataModelDicRedisKey);
|
|
|
|
var meteorologicalStation = dic?.Values?.FirstOrDefault(t => t.EquipmentTypeName.Contains("气象站") );
|
|
|
|
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)
|
|
{
|
|
var data = new EnvironmentLiveDataOutPut();
|
|
|
|
Random random = new Random();
|
|
data.Temperature = (float)random.NextDouble() * 40;
|
|
data.WindVelocity = (float)random.NextDouble() * 15;
|
|
data.Wind = (float)random.NextDouble() * 15;
|
|
data.Humidity = (float)random.NextDouble() * 100;
|
|
rst.ResultData = data;
|
|
rst.Flag = true;
|
|
|
|
Log4Helper.Error(this.GetType(), "获取实时环境数据出错,使用模拟数据", ex);
|
|
}
|
|
return rst;
|
|
}
|
|
|
|
private float GetTelemeteringValue(EquipmentDataModel meteorologicalStation, string telemeteringName)
|
|
{
|
|
var telemetering = meteorologicalStation.Telemeterings.FirstOrDefault(t => t.Name.Contains(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
|
|
}
|
|
}
|