1
|
using IKCOM;
|
2
|
using MARKUS_LOGVIEW.Common;
|
3
|
using MarkusDataModel.Common;
|
4
|
using MarkusDataModel.DataModel;
|
5
|
using MarkusDataModel.DTOs;
|
6
|
using System;
|
7
|
using System.Collections.Generic;
|
8
|
using System.Linq;
|
9
|
using System.Net;
|
10
|
using System.Net.Http;
|
11
|
using System.Threading.Tasks;
|
12
|
using System.Web.Http;
|
13
|
|
14
|
namespace MARKUS_LOGVIEW.Controllers
|
15
|
{
|
16
|
public class DashboardAPIController : ApiController
|
17
|
{
|
18
|
/// <summary>
|
19
|
/// 차트 데이터 반환
|
20
|
/// </summary>
|
21
|
/// <param name="filter"></param>
|
22
|
/// <returns></returns>
|
23
|
[HttpPost, Route("~/api/dashboard/all/chart")]
|
24
|
public async Task<HttpResponseMessage> GetAll([FromBody] pFilterData filter)
|
25
|
{
|
26
|
#region 대시보드 차트 데이터 불러오기
|
27
|
HttpResponseMessage resp = new HttpResponseMessage();
|
28
|
GET_PROJECT_TYPE docType = new GET_PROJECT_TYPE();
|
29
|
DashboardDTO dto = new DashboardDTO();
|
30
|
FilterDatetime filterDate = SetFilterDate(filter.firstMonth, filter.lastMonth);
|
31
|
|
32
|
|
33
|
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
|
34
|
{
|
35
|
return CommonController.Forbidden(resp);
|
36
|
}
|
37
|
else
|
38
|
{
|
39
|
try
|
40
|
{
|
41
|
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
|
42
|
{
|
43
|
|
44
|
dto.CONVERT = ent.CONVERTER_DOC
|
45
|
.Where(conv => conv.CREATE_DATETIME > filterDate.FIRST_DATE && conv.CREATE_DATETIME < filterDate.LAST_DATE)
|
46
|
.OrderByDescending(order => order.CREATE_DATETIME)
|
47
|
.ToList();
|
48
|
|
49
|
dto.MERGE = ent.FINAL_PDF
|
50
|
.Where(merge => merge.CREATE_DATETIME > filterDate.FIRST_DATE && merge.CREATE_DATETIME < filterDate.LAST_DATE)
|
51
|
.OrderByDescending(order => order.CREATE_DATETIME)
|
52
|
.ToList();
|
53
|
|
54
|
dto.LICENSE_LOG = ent.LICENSE_LOG
|
55
|
.Where(log => log.EVENT_TIME > filterDate.FIRST_DATE && log.EVENT_TIME < filterDate.LAST_DATE)
|
56
|
.OrderByDescending(order => order.EVENT_TIME)
|
57
|
.ToList();
|
58
|
|
59
|
dto.STATUS = ent.PROPERTIES.Where(p => p.TYPE == "PDFStatus").ToList();
|
60
|
|
61
|
|
62
|
return await CommonController.OK<DashboardDTO>(resp, dto);
|
63
|
|
64
|
}
|
65
|
}
|
66
|
catch (Exception ex)
|
67
|
{
|
68
|
Console.WriteLine(ex.Message);
|
69
|
return CommonController.InternalServerError(resp, "server error");
|
70
|
}
|
71
|
|
72
|
}
|
73
|
#endregion
|
74
|
}
|
75
|
|
76
|
/// <summary>
|
77
|
/// 컨버팅 데이터 반환
|
78
|
/// </summary>
|
79
|
/// <param name="filterData"></param>
|
80
|
/// <returns></returns>
|
81
|
[HttpPost, Route("~/api/dashboard/convert/table")]
|
82
|
public async Task<TableData> GetConvertTableData([FromBody] DataTableParameters filterData)
|
83
|
{
|
84
|
#region 컨버팅 문서 가져오기
|
85
|
|
86
|
TableData dto = new TableData();
|
87
|
|
88
|
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
|
89
|
{
|
90
|
|
91
|
dto.statusCode = 403;
|
92
|
return dto;
|
93
|
|
94
|
}
|
95
|
else
|
96
|
{
|
97
|
|
98
|
try
|
99
|
{
|
100
|
|
101
|
|
102
|
FilterDatetime filter = SetFilterDate(filterData.startDate, filterData.endDate);
|
103
|
|
104
|
|
105
|
List<TableDataDTO> dataList = new List<TableDataDTO>();
|
106
|
|
107
|
|
108
|
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
|
109
|
{
|
110
|
|
111
|
var items = ent.CONVERTER_DOC
|
112
|
.Where(conv => conv.CREATE_DATETIME > filter.FIRST_DATE && conv.CREATE_DATETIME < filter.LAST_DATE)
|
113
|
.OrderByDescending(order => order.CREATE_DATETIME)
|
114
|
.ToList();
|
115
|
|
116
|
int count = items.Count();
|
117
|
|
118
|
var limitItems = (filterData.Length != -1) ? items.Skip(filterData.start).Take(filterData.Length).OrderByDescending(order => order.CREATE_DATETIME).ToList() : items.OrderByDescending(order => order.CREATE_DATETIME).ToList();
|
119
|
|
120
|
int index = filterData.start;
|
121
|
|
122
|
limitItems.ForEach(ret =>
|
123
|
{
|
124
|
|
125
|
dataList.Add(new TableDataDTO()
|
126
|
{
|
127
|
NO = (index++).ToString(),
|
128
|
PROJECT_NO = ret.PROJECT_NO,
|
129
|
DOCUMENT_ID = ret.DOCUMENT_ID,
|
130
|
TOTAL_PAGE = ret.TOTAL_PAGE.ToString(),
|
131
|
CREATE_DATETIME = ret.CREATE_DATETIME.ToString("MM\\/dd\\/yyyy HH:mm:ss"),
|
132
|
STATUS = CommonController.GetStatusName(ret.STATUS)
|
133
|
});
|
134
|
|
135
|
});
|
136
|
|
137
|
dto.draw = filterData.Draw;
|
138
|
dto.recordsTotal = count;
|
139
|
dto.recordsFiltered = count;
|
140
|
dto.length = filterData.Length;
|
141
|
dto.data = dataList;
|
142
|
|
143
|
return dto;
|
144
|
|
145
|
}
|
146
|
}
|
147
|
catch (Exception ex)
|
148
|
{
|
149
|
|
150
|
dto.statusCode = 500;
|
151
|
return dto;
|
152
|
|
153
|
}
|
154
|
|
155
|
}
|
156
|
#endregion
|
157
|
}
|
158
|
|
159
|
/// <summary>
|
160
|
/// 파이널 데이터 반환
|
161
|
/// </summary>
|
162
|
/// <param name="filterData"></param>
|
163
|
/// <returns></returns>
|
164
|
[HttpPost, Route("~/api/dashboard/final/table")]
|
165
|
public async Task<TableData> GetMergeTableData([FromBody] DataTableParameters filterData)
|
166
|
{
|
167
|
#region Final 데이터 가져오기
|
168
|
TableData dto = new TableData();
|
169
|
|
170
|
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
|
171
|
{
|
172
|
dto.statusCode = 403;
|
173
|
return dto;
|
174
|
}
|
175
|
else
|
176
|
{
|
177
|
|
178
|
try
|
179
|
{
|
180
|
|
181
|
|
182
|
FilterDatetime filter = SetFilterDate(filterData.startDate, filterData.endDate);
|
183
|
List<TableDataDTO> dataList = new List<TableDataDTO>();
|
184
|
|
185
|
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
|
186
|
{
|
187
|
|
188
|
var items = ent.FINAL_PDF
|
189
|
.Where(conv => conv.CREATE_DATETIME > filter.FIRST_DATE && conv.CREATE_DATETIME < filter.LAST_DATE)
|
190
|
.OrderByDescending(order => order.CREATE_DATETIME)
|
191
|
.ToList();
|
192
|
|
193
|
int count = items.Count();
|
194
|
|
195
|
var limitItems = (filterData.Length != -1) ? items.Skip(filterData.start).Take(filterData.Length).OrderByDescending(order => order.CREATE_DATETIME).ToList() : items.OrderByDescending(order => order.CREATE_DATETIME).ToList();
|
196
|
|
197
|
int index = filterData.start;
|
198
|
|
199
|
limitItems.ForEach(ret =>
|
200
|
{
|
201
|
|
202
|
dataList.Add(new TableDataDTO()
|
203
|
{
|
204
|
NO = (index++).ToString(),
|
205
|
PROJECT_NO = ret.PROJECT_NO,
|
206
|
DOCUMENT_ID = ret.DOCUMENT_ID,
|
207
|
TOTAL_PAGE = ret.TOTAL_PAGE.ToString(),
|
208
|
CREATE_DATETIME = ret.CREATE_DATETIME.ToString("MM\\/dd\\/yyyy HH:mm:ss"),
|
209
|
STATUS = CommonController.GetStatusName(ret.STATUS)
|
210
|
});
|
211
|
|
212
|
});
|
213
|
|
214
|
dto.draw = filterData.Draw;
|
215
|
dto.recordsTotal = count;
|
216
|
dto.recordsFiltered = count;
|
217
|
dto.length = filterData.Length;
|
218
|
dto.data = dataList;
|
219
|
|
220
|
return dto;
|
221
|
|
222
|
}
|
223
|
|
224
|
}
|
225
|
catch (Exception ex)
|
226
|
{
|
227
|
|
228
|
dto.statusCode = 500;
|
229
|
return dto;
|
230
|
|
231
|
}
|
232
|
|
233
|
}
|
234
|
#endregion
|
235
|
|
236
|
}
|
237
|
|
238
|
/// <summary>
|
239
|
/// 로그 리스트 반환
|
240
|
/// </summary>
|
241
|
/// <param name="filterData"></param>
|
242
|
/// <returns></returns>
|
243
|
[HttpPost, Route("~/api/dashboard/log/table")]
|
244
|
public async Task<LogData> GetDashboardLog([FromBody] DataTableParameters filterData)
|
245
|
{
|
246
|
#region 로그 리스트 가져오기
|
247
|
|
248
|
LogData logList = new LogData();
|
249
|
|
250
|
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString()))
|
251
|
{
|
252
|
logList.statusCode = 403;
|
253
|
return logList;
|
254
|
}
|
255
|
else
|
256
|
{
|
257
|
|
258
|
try
|
259
|
{
|
260
|
|
261
|
FilterDatetime filter = SetFilterDate(filterData.startDate, filterData.endDate);
|
262
|
|
263
|
List<LogTableDataDTO> dataList = new List<LogTableDataDTO>();
|
264
|
|
265
|
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString()))
|
266
|
{
|
267
|
|
268
|
var items = ent.LICENSE_LOG
|
269
|
.Where(conv => conv.EVENT_TIME > filter.FIRST_DATE && conv.EVENT_TIME < filter.LAST_DATE)
|
270
|
.OrderByDescending(order => order.EVENT_TIME)
|
271
|
.ToList();
|
272
|
|
273
|
int count = items.Count();
|
274
|
|
275
|
var limitItems = (filterData.Length != -1) ? items.Skip(filterData.start).Take(filterData.Length).OrderByDescending(order => order.EVENT_TIME).ToList() : items.OrderByDescending(order => order.EVENT_TIME).ToList();
|
276
|
|
277
|
int index = filterData.start;
|
278
|
|
279
|
limitItems.ForEach(ret =>
|
280
|
{
|
281
|
|
282
|
dataList.Add(new LogTableDataDTO()
|
283
|
{
|
284
|
NO = (index++).ToString(),
|
285
|
ID = ret.USER_ID,
|
286
|
NAME = ret.USER_NAME,
|
287
|
EVENT_TIME = ret.EVENT_TIME.ToString("MM\\/dd\\/yyyy HH:mm:ss"),
|
288
|
STATUS = CommonController.GetLogStatusName(ret.STATUS)
|
289
|
});
|
290
|
|
291
|
});
|
292
|
|
293
|
logList.draw = filterData.Draw;
|
294
|
logList.recordsTotal = count;
|
295
|
logList.recordsFiltered = count;
|
296
|
logList.length = filterData.Length;
|
297
|
logList.data = dataList;
|
298
|
|
299
|
}
|
300
|
|
301
|
return logList;
|
302
|
|
303
|
}
|
304
|
catch (Exception ex)
|
305
|
{
|
306
|
|
307
|
logList.statusCode = 500;
|
308
|
return logList;
|
309
|
|
310
|
}
|
311
|
|
312
|
}
|
313
|
|
314
|
#endregion
|
315
|
}
|
316
|
|
317
|
/// <summary>
|
318
|
/// 선택한 월 마지막 날짜 구하기 메서드
|
319
|
/// </summary>
|
320
|
/// <param name="first"></param>
|
321
|
/// <param name="last"></param>
|
322
|
/// <returns></returns>
|
323
|
[NonAction]
|
324
|
public FilterDatetime SetFilterDate(DateTime first, DateTime last)
|
325
|
{
|
326
|
#region 해당 월 마지막 날짜 구하기
|
327
|
FilterDatetime filterDate = new FilterDatetime();
|
328
|
int thisMonthDays = DateTime.DaysInMonth(DateTime.Now.Year, last.Month);
|
329
|
|
330
|
|
331
|
filterDate.FIRST_DATE = new DateTime(first.Year, first.Month, 1);
|
332
|
filterDate.LAST_DATE = new DateTime(last.Year, last.Month, thisMonthDays);
|
333
|
|
334
|
return filterDate;
|
335
|
#endregion
|
336
|
}
|
337
|
|
338
|
}
|
339
|
|
340
|
}
|