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
|
{
|
/// <summary>
|
/// 监测
|
/// </summary>
|
[AllowAnonymous]
|
[Route("LargeScreen/Demo/Monitor")]
|
[ApiDescriptionSettings("LargeScreen", Name = "Demo(监测)", Order = 666)]
|
public class DemoMonitor_Controller : IDynamicApiController, ITransient
|
{
|
private readonly IHttpContextAccessor _httpContextAccessor;
|
|
/// <summary>
|
///
|
/// </summary>
|
public DemoMonitor_Controller(IHttpContextAccessor httpContextAccessor)
|
{
|
_httpContextAccessor = httpContextAccessor;
|
}
|
|
|
|
/// <summary>
|
/// 通过 StationID 获取Master常规实时列表
|
/// </summary>
|
[Route("GetMasterGeneralRealMonitorPointListByStationID")]
|
[HttpGet]
|
public List<DemoMonitorPointExSignalListDto> GetMasterGeneralRealMonitorPointListByStationID([FromQuery][Required] StationIDUnderCorpInput input)
|
{
|
var corpId = input.CorpID;
|
var belongType = IStation.ObjectType.Station;
|
var belongId = input.StationID;
|
var cacheKey = $"LargeScreen_Demo_Monitor_GetMasterGeneralRealMonitorPointListByStationID_{corpId}_{belongId}";
|
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
|
{
|
var allGroupList = new Service.MonitorPointGroup().GetByBelongTypeAndBelongID(corpId, belongType, belongId);
|
if (allGroupList == null || allGroupList.Count < 1)
|
{
|
var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID(corpId, belongType, belongId);
|
var vmCacheList = monitorList?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
|
return vmCacheList;
|
}
|
else
|
{
|
var groupList = allGroupList.Where(x => x.Flags != null && x.Flags.Contains(LogicFlags.总站)).ToList();
|
if (groupList == null || groupList.Count < 1)
|
{
|
var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID(corpId, belongType, belongId);
|
var vmCacheList = monitorList?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
|
return vmCacheList;
|
}
|
else
|
{
|
var monitorList = new Service.MonitorPoint().GetExSignalWithSignalTypeByGroupIds(corpId, groupList.Select(x => x.ID), Model.eMonitorType.General, Model.Monitor.eCronType.Real);
|
var vmCacheList = monitorList?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
|
return vmCacheList;
|
}
|
}
|
|
|
}, CacheHelper.CacheLevel3);
|
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 ProductID 获取常规实时测点列表
|
/// </summary>
|
[Route("GetGeneralRealMonitorPointListByProductID")]
|
[HttpGet]
|
public List<DemoMonitorPointExSignalListDto> GetGeneralRealMonitorPointListByProductID([FromQuery][Required] ProductIDUnderCorpInput input)
|
{
|
var corpId = input.CorpID;
|
var productId = input.ProductID;
|
var cacheKey = $"LargeScreen_Demo_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 DemoMonitorPointExSignalListDto(x)).ToList();
|
return vmCacheList;
|
|
}, CacheHelper.CacheLevel3);
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取常规实时列表
|
/// </summary>
|
[Route("GetGeneralRealMonitorPointListByStationID")]
|
[HttpGet]
|
public List<DemoMonitorPointExSignalListDto> GetGeneralRealMonitorPointListByStationID([FromQuery][Required] StationIDUnderCorpInput input)
|
{
|
var corpId = input.CorpID;
|
var belongType = IStation.ObjectType.Station;
|
var belongId = input.StationID;
|
var cacheKey = $"LargeScreen_Demo_Monitor_GetGeneralRealMonitorPointListByStationID_{corpId}_{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 DemoMonitorPointExSignalListDto(x)).ToList();
|
return vmCacheList;
|
|
}, CacheHelper.CacheLevel3);
|
|
return vm_list;
|
}
|
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取常规测点逻辑树
|
/// </summary>
|
[Route("GetGeneralMonitorPointLogicalTreeByBelongTypeAndBelongID")]
|
[HttpGet]
|
public List<LogicalTreeItemDto> GetGeneralMonitorPointLogicalTreeByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input)
|
{
|
var corpId = input.CorpID;
|
var belongType = input.BelongType;
|
var belongId = input.BelongID;
|
|
var cacheKey = $"LargeScreen_Demo_Monitor_GetGeneralMonitorPointLogicalTreeByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}";
|
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
|
{
|
|
#region 监测点组
|
|
var group_list = new Service.MonitorPointGroup().GetByBelongTypeAndBelongID(corpId, belongType, belongId);
|
var vm_group_list = group_list?.Select(x => new DemoMonitorPointGroupDto(x)).ToList();
|
var vm_cache_group_list = vm_group_list?.Select(x =>
|
{
|
var vm_cache_group = new LogicalTreeItemDto();
|
vm_cache_group.ID = $"{ObjectType.MonitorPointGroup}_{x.ID}";
|
vm_cache_group.ParentID = $"{ObjectType.MonitorPointGroup}_{x.ParentID}";
|
vm_cache_group.LogicalName = x.Name;
|
vm_cache_group.LogicalType = ObjectType.MonitorPointGroup;
|
vm_cache_group.LogicalID = x.ID;
|
vm_cache_group.LogicalModel = x;
|
vm_cache_group.Children = new List<LogicalTreeItemDto>();
|
return vm_cache_group;
|
}).ToList();
|
|
#endregion
|
|
#region 监测点
|
|
var monitor_list = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID(corpId, belongType, belongId, Model.eMonitorType.General);
|
var vm_monitor_list = monitor_list?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
|
var vm_cache_monitor_list = vm_monitor_list?.Select(x =>
|
{
|
var vm_cache_monitor = new LogicalTreeItemDto();
|
vm_cache_monitor.ID = $"{ObjectType.MonitorPoint}_{x.ID}";
|
vm_cache_monitor.ParentID = $"{ObjectType.MonitorPointGroup}_{x.GroupID}";
|
vm_cache_monitor.LogicalName = x.Name;
|
vm_cache_monitor.LogicalType = ObjectType.MonitorPoint;
|
vm_cache_monitor.LogicalID = x.ID;
|
vm_cache_monitor.LogicalModel = x;
|
vm_cache_monitor.Children = null;
|
return vm_cache_monitor;
|
}).ToList();
|
|
#endregion
|
|
#region 生成树
|
|
var vm_cache_list = new List<LogicalTreeItemDto>();
|
|
//遍历测点
|
if (vm_cache_monitor_list != null && vm_cache_monitor_list.Count > 0)
|
{
|
foreach (var vm_cache_monitor in vm_cache_monitor_list)
|
{
|
var vm_cache_monitor_parent = vm_cache_group_list?.Find(t => t.ID == vm_cache_monitor.ParentID);
|
if (vm_cache_monitor_parent == null)
|
{
|
vm_cache_list.Add(vm_cache_monitor);
|
}
|
else
|
{
|
vm_cache_monitor_parent.Children.Add(vm_cache_monitor);
|
}
|
}
|
}
|
|
//遍历测点组
|
if (vm_cache_group_list != null && vm_cache_group_list.Count > 0)
|
{
|
foreach (var vm_cache_group in vm_cache_group_list)
|
{
|
var vm_cahce_group_parent = vm_cache_group_list.Find(t => t.ID == vm_cache_group.ParentID);
|
if (vm_cahce_group_parent == null)
|
{
|
vm_cache_list.Add(vm_cache_group);
|
}
|
else
|
{
|
vm_cahce_group_parent.Children.Add(vm_cache_group);
|
}
|
}
|
}
|
|
return vm_cache_list;
|
|
#endregion
|
|
}, CacheHelper.CacheLevel2);
|
|
return vm_list;
|
}
|
|
/// <summary>
|
/// 通过 BelongType 和 BelongID 获取常规实时测点逻辑树
|
/// </summary>
|
[Route("GetGeneralRealMonitorPointLogicalTreeByBelongTypeAndBelongID")]
|
[HttpGet]
|
public List<LogicalTreeItemDto> GetGeneralRealMonitorPointLogicalTreeByBelongTypeAndBelongID([FromQuery][Required] BelongUnderCorpInput input)
|
{
|
var corpId = input.CorpID;
|
var belongType = input.BelongType;
|
var belongId = input.BelongID;
|
|
var cacheKey = $"LargeScreen_Demo_Monitor_GetGeneralRealMonitorPointLogicalTreeByBelongTypeAndBelongID_{corpId}_{belongType}_{belongId}";
|
var vm_list = MemoryCacheHelper.GetSet(cacheKey, () =>
|
{
|
|
#region 监测点组
|
|
var group_list = new Service.MonitorPointGroup().GetByBelongTypeAndBelongID(corpId, belongType, belongId);
|
var vm_group_list = group_list?.Select(x => new DemoMonitorPointGroupDto(x)).ToList();
|
var vm_cache_group_list = vm_group_list?.Select(x =>
|
{
|
var vm_cache_group = new LogicalTreeItemDto();
|
vm_cache_group.ID = $"{ObjectType.MonitorPointGroup}_{x.ID}";
|
vm_cache_group.ParentID = $"{ObjectType.MonitorPointGroup}_{x.ParentID}";
|
vm_cache_group.LogicalName = x.Name;
|
vm_cache_group.LogicalType = ObjectType.MonitorPointGroup;
|
vm_cache_group.LogicalID = x.ID;
|
vm_cache_group.LogicalModel = x;
|
vm_cache_group.Children = new List<LogicalTreeItemDto>();
|
return vm_cache_group;
|
}).ToList();
|
|
#endregion
|
|
#region 监测点
|
|
var monitor_list = new Service.MonitorPoint().GetExSignalWithSignalTypeByBelongTypeAndBelongID
|
(corpId, belongType, belongId, Model.eMonitorType.General, Model.Monitor.eCronType.Real);
|
var vm_monitor_list = monitor_list?.Select(x => new DemoMonitorPointExSignalListDto(x)).ToList();
|
var vm_cache_monitor_list = vm_monitor_list?.Select(x =>
|
{
|
var vm_cache_monitor = new LogicalTreeItemDto();
|
vm_cache_monitor.ID = $"{ObjectType.MonitorPoint}_{x.ID}";
|
vm_cache_monitor.ParentID = $"{ObjectType.MonitorPointGroup}_{x.GroupID}";
|
vm_cache_monitor.LogicalName = x.Name;
|
vm_cache_monitor.LogicalType = ObjectType.MonitorPoint;
|
vm_cache_monitor.LogicalID = x.ID;
|
vm_cache_monitor.LogicalModel = x;
|
vm_cache_monitor.Children = null;
|
return vm_cache_monitor;
|
}).ToList();
|
|
#endregion
|
|
#region 生成树
|
|
var vm_cache_list = new List<LogicalTreeItemDto>();
|
|
//遍历测点
|
if (vm_cache_monitor_list != null && vm_cache_monitor_list.Count > 0)
|
{
|
foreach (var vm_cache_monitor in vm_cache_monitor_list)
|
{
|
var vm_cache_monitor_parent = vm_cache_group_list?.Find(t => t.ID == vm_cache_monitor.ParentID);
|
if (vm_cache_monitor_parent == null)
|
{
|
vm_cache_list.Add(vm_cache_monitor);
|
}
|
else
|
{
|
vm_cache_monitor_parent.Children.Add(vm_cache_monitor);
|
}
|
}
|
}
|
|
//遍历测点组
|
if (vm_cache_group_list != null && vm_cache_group_list.Count > 0)
|
{
|
foreach (var vm_cache_group in vm_cache_group_list)
|
{
|
var vm_cahce_group_parent = vm_cache_group_list.Find(t => t.ID == vm_cache_group.ParentID);
|
if (vm_cahce_group_parent == null)
|
{
|
vm_cache_list.Add(vm_cache_group);
|
}
|
else
|
{
|
vm_cahce_group_parent.Children.Add(vm_cache_group);
|
}
|
}
|
}
|
|
return vm_cache_list;
|
|
#endregion
|
|
}, CacheHelper.CacheLevel2);
|
|
return vm_list;
|
}
|
|
}
|
}
|