markus / MarkusLogview / MARKUS_LOGVIEW / Controllers / LicenseAPIController.cs @ 84578b97
이력 | 보기 | 이력해설 | 다운로드 (7.37 KB)
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 LicenseAPIController : ApiController |
17 |
{ |
18 |
|
19 |
[HttpPost, Route("~/api/markuslog")] |
20 |
public async Task<ProcessingUsers> GetLicenseAll( [FromBody] DataTableParameters filter) |
21 |
{ |
22 |
#region 사용자를 모두 반환 |
23 |
|
24 |
ProcessingUsers dto = new ProcessingUsers(); |
25 |
dto.data = new List<LicenseLogList>(); |
26 |
dto.LicenseCount = new LicenseCountDTO(); |
27 |
|
28 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
29 |
{ |
30 |
dto.statusCode = 403; |
31 |
return dto; |
32 |
} |
33 |
else |
34 |
{ |
35 |
|
36 |
try |
37 |
{ |
38 |
|
39 |
filter.endDate = filter.endDate.AddHours(23).AddMinutes(59).AddSeconds(59); |
40 |
|
41 |
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
42 |
{ |
43 |
|
44 |
var logs = ent.LICENSE_LOG |
45 |
.Where(log => log.EVENT_TIME > filter.startDate && filter.endDate >= log.EVENT_TIME && (string.IsNullOrEmpty(filter.Search.Value)) ? string.IsNullOrEmpty(filter.Search.Value) : log.USER_ID.Contains(filter.Search.Value)) |
46 |
.OrderByDescending(order => order.EVENT_TIME) |
47 |
.ToList(); |
48 |
|
49 |
int logsCount = logs.Count; |
50 |
|
51 |
if (logs.Count > 0) |
52 |
{ |
53 |
|
54 |
// processing count box data |
55 |
logs.ForEach(ret => |
56 |
{ |
57 |
switch (ret.STATUS) |
58 |
{ |
59 |
case (int)MARKUS_CONNECTION_TYPE.PROCESSING: |
60 |
dto.LicenseCount.Processing += 1; |
61 |
break; |
62 |
case (int)MARKUS_CONNECTION_TYPE.REJECT: |
63 |
dto.LicenseCount.Reject += 1; |
64 |
break; |
65 |
case (int)MARKUS_CONNECTION_TYPE.TERMINATE: |
66 |
dto.LicenseCount.Terminate += 1; |
67 |
break; |
68 |
} |
69 |
}); |
70 |
|
71 |
|
72 |
// processing table data |
73 |
logs |
74 |
.Skip(filter.start) |
75 |
.Take(filter.Length) |
76 |
.ToList() |
77 |
.ForEach(ret => |
78 |
{ |
79 |
|
80 |
dto.data.Add(new LicenseLogList() |
81 |
{ |
82 |
NO = ret.ID, |
83 |
ID = ret.USER_ID, |
84 |
USER_NAME = ret.USER_NAME, |
85 |
DESCRIPTION = ret.DESCRIPTION, |
86 |
EVENT_TIME = ret.EVENT_TIME, |
87 |
STATUS = CommonController.GetLogStatusName(ret.STATUS), |
88 |
USER_ID = ret.USER_ID |
89 |
}); |
90 |
}); |
91 |
|
92 |
dto.draw = filter.Draw; |
93 |
dto.recordsFiltered = logsCount; |
94 |
dto.recordsTotal = logsCount; |
95 |
dto.length = filter.Length; |
96 |
|
97 |
return dto; |
98 |
|
99 |
} |
100 |
else |
101 |
{ |
102 |
return dto; |
103 |
} |
104 |
|
105 |
} |
106 |
|
107 |
} |
108 |
catch (Exception ex) |
109 |
{ |
110 |
Console.WriteLine(ex.Message); |
111 |
dto.statusCode = 500; |
112 |
return dto; |
113 |
|
114 |
} |
115 |
|
116 |
} |
117 |
|
118 |
#endregion |
119 |
} |
120 |
|
121 |
[HttpPost, Route("~/api/processing/chart")] |
122 |
public async Task<HttpResponseMessage> GetProcessingCount([FromBody] pDate filter) |
123 |
{ |
124 |
#region 차트 데이터 반환 |
125 |
HttpResponseMessage resp = new HttpResponseMessage(); |
126 |
List<ProcessingbyUserDTO> chartData = new List<ProcessingbyUserDTO>(); |
127 |
|
128 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
129 |
{ |
130 |
return CommonController.Forbidden(resp); |
131 |
} |
132 |
else |
133 |
{ |
134 |
|
135 |
try |
136 |
{ |
137 |
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
138 |
{ |
139 |
|
140 |
LicenseDTO licenseDTO = new LicenseDTO(); |
141 |
|
142 |
filter.endDate = filter.endDate.AddDays(1); |
143 |
|
144 |
var markusLogList = ent.LICENSE_LOG.Where(log => log.EVENT_TIME > filter.startDate && filter.endDate > log.EVENT_TIME).ToList(); |
145 |
|
146 |
licenseDTO.licenseCount = new LicenseCountDTO() |
147 |
{ |
148 |
Processing = markusLogList.Where(log => log.STATUS == (int)MARKUS_CONNECTION_TYPE.PROCESSING).Count(), |
149 |
Reject = markusLogList.Where(log => log.STATUS == (int)MARKUS_CONNECTION_TYPE.REJECT).Count(), |
150 |
Terminate = markusLogList.Where(log => log.STATUS == (int)MARKUS_CONNECTION_TYPE.TERMINATE).Count(), |
151 |
}; |
152 |
|
153 |
|
154 |
var users = ent.MEMBER.ToList(); |
155 |
licenseDTO.connection = markusLogList; |
156 |
|
157 |
users.ForEach(user => |
158 |
{ |
159 |
|
160 |
licenseDTO.userList.Add(new ProcessingUserList() |
161 |
{ |
162 |
licenseUser = new LicenseUSER() |
163 |
{ |
164 |
ID = user.ID, |
165 |
DEPARTMENT = user.DEPARTMENT, |
166 |
NAME = user.NAME, |
167 |
POSITION = user.POSITION, |
168 |
EMAIL_ADDRESS = user.EMAIL_ADDRESS, |
169 |
COMPANY = user.COMPANY, |
170 |
CREATE_DATETIME = user.CREATE_DATETIME, |
171 |
MODIFIED_DATETIME = user.MODIFIED_DATETIME, |
172 |
ISLICENSE = user.ISLICENSE |
173 |
}, |
174 |
processingCount = markusLogList.Where(item => item.USER_ID == user.ID && item.USER_NAME == user.NAME).Count() |
175 |
|
176 |
}); |
177 |
|
178 |
}); |
179 |
|
180 |
return await CommonController.OK<LicenseDTO>(resp, licenseDTO); |
181 |
|
182 |
} |
183 |
|
184 |
} |
185 |
catch (Exception) |
186 |
{ |
187 |
return CommonController.InternalServerError(resp, "server error"); |
188 |
} |
189 |
|
190 |
} |
191 |
#endregion |
192 |
} |
193 |
|
194 |
} |
195 |
|
196 |
} |