lixiaojun
2022-11-30 af918c1c2ebd53e4c9e1fee0da47e1a6c63a18bf
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
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>
    /// MonitorRecord
    /// </summary>
    [AllowAnonymous]
    [Route("LinuxTest/MonitorRecord")]
    [ApiDescriptionSettings("LinuxTest", Name = "监测记录", Order = 999)]
    public class MonitorRecord_Controller : IDynamicApiController, ITransient 
    {
        private readonly IHttpContextAccessor _httpContextAccessor;
 
        /// <summary>
        /// 
        /// </summary>
        public MonitorRecord_Controller(IHttpContextAccessor httpContextAccessor) 
        {
            _httpContextAccessor = httpContextAccessor; 
        }
 
        //服务
        private readonly Service.MonitorRecord _service = new Service.MonitorRecord();
 
        #region Insert
 
        /// <summary>
        /// 插入一条
        /// </summary>
        [Route("Insert@V1.0")]
        [HttpPost]
        public bool Insert([Required] AddMonitorRecordInput input)
        {
            if (input == null)
                return default;
            var model = input.Adapt<AddMonitorRecordInput, Model.MonitorRecord>();
            var bol = _service.InsertLastRecord(model, out bool redis);
            if (!redis)
            {
                throw Oops.Oh("Redis 创建失败!");
            }
            return bol;
        }
 
        /// <summary>
        /// 插入多条
        /// </summary>
        [Route("Inserts@V1.0")]
        [HttpPost]
        public bool Inserts([Required] List<AddMonitorRecordInput> inputList)
        {
            if (inputList == null || inputList.Count < 1)
                return false;
            var list = inputList.Select(x => x.Adapt<AddMonitorRecordInput, Model.MonitorRecord>()).ToList();
            var bol = _service.InsertsLastRecord(list);
            return bol;
        }
 
        #endregion
 
        #region 获取所有
 
        /// <summary>
        /// 获取所有
        /// </summary>
        [Route("GetAll")]
        [HttpGet]
        public List<MonitorRecordDto> GetAll()
        {
            var list = _service.GetAll();
            var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
            return vmList;
        }
 
        #endregion
 
        #region 获取最近记录
 
        /// <summary>
        /// 通过 MonitorPointID 获取最近一条数据
        /// </summary>
        [Route("GetLastRecordByMonitorPointID")]
        [HttpGet]
        public MonitorRecordDto GetLastRecordByMonitorPointID([FromQuery][Required] MonitorPointIDInput input)
        {
            var model = _service.GetLastRecord( input.MonitorPointID);
            if (model == null)
                return default;
            return new MonitorRecordDto(model);
        }
 
        /// <summary>
        /// 通过 MonitorPointIds  获取最近一条数据
        /// </summary>
        [Route("GetLastRecordByMonitorPointIds")]
        [HttpGet]
        public List<MonitorRecordDto> GetLastRecordByMonitorPointIds([FromQuery][Required] MonitorPointIdsInput input) 
        {
            var ids = LongListHelper.ToList(input.MonitorPointIds);
            var list = _service.GetLastRecord(ids);
            var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
            return vmList;
        }
 
        #endregion
 
        #region 通过测点标识获取
 
        /// <summary>
        /// 通过 MonitorPointID 获取某天的数据
        /// </summary>
        [Route("GetByMonitorPointIDOfDay")]
        [HttpGet]
        public List<MonitorRecordDto> GetByMonitorPointIDOfDay
            (
                [Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
                long MonitorPointID,
                [Required]
                DateTime Day
            )
        {
            var list = _service.GetByMonitorPointIDOfDay( MonitorPointID, Day);
            var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
            return vmList;
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取日期区间内的数据
        /// </summary>
        [Route("GetByMonitorPointIDOfDayRange")]
        [HttpGet]
        public List<MonitorRecordDto> GetByMonitorPointIDOfDayRange
            (
                [Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
                long MonitorPointID,
                [Required]
                DateTime StartDay,
                [Required]
                DateTime EndDay
            )
        {
            if (StartDay.Date > EndDay.Date)
            {
                return default;
            }
            var list = _service.GetByMonitorPointIDOfDayRange( MonitorPointID, StartDay, EndDay);
            var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
            return vmList;
        }
 
        /// <summary>
        /// 通过 MonitorPointID 获取时间区间内的数据
        /// </summary>
        [Route("GetByMonitorPointIDOfTimeRange")]
        [HttpGet]
        public List<MonitorRecordDto> GetByMonitorPointIDOfTimeRange
            (
                [Required, Range(1, long.MaxValue, ErrorMessage = "MonitorPointID 必须大于0")]
                long MonitorPointID,
                [Required]
                DateTime StartTime,
                [Required]
                DateTime EndTime
            )
        {
            if (StartTime > EndTime)
            {
                return default;
            }
            var list = _service.GetByMonitorPointIDOfTimeRange( MonitorPointID, StartTime, EndTime);
            var vmList = list?.Select(x => new MonitorRecordDto(x)).ToList();
            return vmList;
        }
 
        #endregion
 
 
 
 
 
 
 
 
 
 
 
    }
}