using Microsoft.AspNetCore.Mvc; using System.Net; using System.Net.Http.Headers; using Microsoft.Extensions.Hosting.Internal; using Microsoft.AspNetCore.Http.Extensions; using IStation.Untity; using Furion.DynamicApiController; using System.ComponentModel.DataAnnotations; using Mapster; using Microsoft.AspNetCore.Http; using Furion.DependencyInjection; using Microsoft.AspNetCore.Authorization; using Furion.DataEncryption; using Furion.FriendlyException; namespace IStation.Application { /// /// 监测 /// [AllowAnonymous] [Route("LargeScreen/Szjt/Monitor")] [ApiDescriptionSettings("LargeScreen", Name = "苏州金庭(监测)", Order = 999)] public class SzjtMonitor_Controller : IDynamicApiController, ITransient { private readonly IHttpContextAccessor _httpContextAccessor; /// /// /// public SzjtMonitor_Controller(IHttpContextAccessor httpContextAccessor) { _httpContextAccessor = httpContextAccessor; } private const long _corpId = 3; /// /// 通过 StationID 获取KPI /// /// 泵站标识 /// KPI数量 [Route("GetMonitorPointKpiListByStationID")] [HttpGet] public List GetMonitorPointKpiListByStationID ( [Required, Range(1, long.MaxValue, ErrorMessage = "StationID 必须大于0")] long StationID, int Count = 2 ) { var cacheKey = $"LargeScreen_Szjt_Monitor_GetMonitorPointKpiListByStationID_{_corpId}_{StationID}_{Count}"; var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => { //最后kpi记录列表 var monitor_list = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID (_corpId, ObjectType.Station, StationID, Model.eMonitorType.General, Model.Monitor.eCronType.Real); var monitor_kpi_list = monitor_list?.Where(x => x.Flags != null && x.Flags.Contains(LogicFlags.KPI)) .OrderBy(x => x.ImportanceIndex == null ? int.MaxValue : x.ImportanceIndex.Value).ToList(); var vmCacheList = new List(); if (monitor_kpi_list != null) { var take_count = monitor_kpi_list.Count > Count ? Count : monitor_kpi_list.Count; monitor_kpi_list = monitor_kpi_list.Take(take_count).ToList(); foreach (var monitor_kpi in monitor_kpi_list) { var vm = new SzjtMonitorPointExSignalListDto(monitor_kpi); vmCacheList.Add(vm); } } return vmCacheList; }, CacheHelper.CacheLevel4); return vm_list; } /// /// 通过 ProductID 获取常规实时测点列表 /// [Route("GetGeneralRealMonitorPointListByProductID")] [HttpGet] public List GetGeneralRealMonitorPointListByProductID([FromQuery][Required] ProductIDInput input) { var productId = input.ProductID; var cacheKey = $"LargeScreen_Szjt_Monitor_GetGeneralRealMonitorPointListByProductID_{_corpId}_{productId}"; var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => { var monitorMappingList = new Service.MonitorPointMapping().GetByObjectTypeAndObjectID(_corpId, ObjectType.Product, productId); if (monitorMappingList == null || monitorMappingList.Count < 1) return default; var monitorIds = monitorMappingList.Select(x => x.MonitorPointID).Distinct().ToList(); var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByIds(_corpId, monitorIds, Model.eMonitorType.General, Model.Monitor.eCronType.Real); var vmCacheList = monitorList?.Select(x => new SzjtMonitorPointExSignalListDto(x)).ToList(); return vmCacheList; }, CacheHelper.CacheLevel3); return vm_list; } /// /// 通过 BelongType 和 BelongID 获取常规实时列表 /// [Route("GetGeneralRealMonitorPointListByBelongTypeAndBelongID")] [HttpGet] public List GetGeneralRealMonitorPointListByBelongTypeAndBelongID([FromQuery][Required] BelongInput input) { var corpId = _corpId; var belongType = input.BelongType; var belongId = input.BelongID; var cacheKey = $"LargeScreen_Szjt_Monitor_GetGeneralRealMonitorPointListByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}"; var vm_list = MemoryCacheHelper.GetSet(cacheKey, () => { var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID (corpId, belongType, belongId, Model.eMonitorType.General, Model.Monitor.eCronType.Real); var vmCacheList = monitorList?.Select(x => new SzjtMonitorPointExSignalListDto(x)).ToList(); return vmCacheList; }, CacheHelper.CacheLevel3); return vm_list; } } }