lixiaojun
2022-09-02 d5a3d08601fa59498edc092cec23c7ca166a0d15
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
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/Szjt/Monitor")]
    [ApiDescriptionSettings("LargeScreen", Name = "苏州金庭(监测)", Order = 999)]
    public class SzjtMonitor_Controller : IDynamicApiController, ITransient
    {
        private readonly IHttpContextAccessor _httpContextAccessor; 
 
        /// <summary>
        /// 
        /// </summary>
        public SzjtMonitor_Controller(IHttpContextAccessor httpContextAccessor)
        {
            _httpContextAccessor = httpContextAccessor;
        }
 
        private const long _corpId = 3;
 
        /// <summary>
        ///  通过 StationID 获取KPI
        /// </summary>
        /// <param name="StationID">泵站标识</param>
        /// <param name="Count">KPI数量</param>
        [Route("GetMonitorPointKpiListByStationID")]
        [HttpGet]
        public List<SzjtMonitorPointExSignalListDto> 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<SzjtMonitorPointExSignalListDto>();
                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;
 
        }
 
 
        /// <summary>
        /// 通过 ProductID 获取常规实时测点列表
        /// </summary>
        [Route("GetGeneralRealMonitorPointListByProductID")]
        [HttpGet]
        public List<SzjtMonitorPointExSignalListDto> 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;
        }
 
        /// <summary>
        /// 通过 BelongType 和 BelongID 获取常规实时列表
        /// </summary>
        [Route("GetGeneralRealMonitorPointListByBelongTypeAndBelongID")]
        [HttpGet]
        public List<SzjtMonitorPointExSignalListDto> 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;
        }
 
 
 
 
    }
}