markus / MarkusLogview / MARKUS_LOGVIEW / Controllers / MergeAPIController.cs @ 84578b97
이력 | 보기 | 이력해설 | 다운로드 (10.4 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.Net.Http.Headers; |
12 |
using System.Threading.Tasks; |
13 |
using System.Web.Http; |
14 |
|
15 |
namespace MARKUS_LOGVIEW.Controllers |
16 |
{ |
17 |
|
18 |
public class MergeAPIController : ApiController |
19 |
{ |
20 |
|
21 |
/// <summary> |
22 |
/// 파이널 도큐먼트 반환 |
23 |
/// </summary> |
24 |
/// <param name="filter"></param> |
25 |
/// <returns></returns> |
26 |
[HttpPost, Route("~/api/GetMergeDocument")] |
27 |
public async Task<MergeTableData> GetMergeDocumentList([FromBody] DataTableParameters filter ) |
28 |
{ |
29 |
#region 파이널 도큐먼트 리스트 반환 |
30 |
|
31 |
MergeTableData dto = new MergeTableData(); |
32 |
List<TableData_Merge> tableData = new List<TableData_Merge>(); |
33 |
|
34 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
35 |
{ |
36 |
dto.statusCode = 403; |
37 |
return dto; |
38 |
} |
39 |
else |
40 |
{ |
41 |
|
42 |
try |
43 |
{ |
44 |
|
45 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
46 |
{ |
47 |
return dto; |
48 |
} |
49 |
else |
50 |
{ |
51 |
|
52 |
DateTime prjDocStartDate = Convert.ToDateTime(filter.startDate); |
53 |
DateTime prjDocEndDate = Convert.ToDateTime(filter.endDate).AddHours(23).AddMinutes(59).AddSeconds(59); |
54 |
string token = Request.Headers.Authorization.ToString(); |
55 |
|
56 |
using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
57 |
{ |
58 |
|
59 |
var mergeDocList = entity.FINAL_PDF |
60 |
.Where( |
61 |
cd => cd.CREATE_DATETIME >= prjDocStartDate && |
62 |
cd.CREATE_DATETIME <= prjDocEndDate && |
63 |
cd.PROJECT_NO == filter.projectNo && |
64 |
(string.IsNullOrEmpty(filter.Search.Value)) ? string.IsNullOrEmpty(filter.Search.Value) : cd.DOCUMENT_ID.Contains(filter.Search.Value)) |
65 |
.OrderByDescending(t => t.CREATE_DATETIME) |
66 |
.ToList(); |
67 |
|
68 |
|
69 |
if (mergeDocList.Count > 0) |
70 |
{ |
71 |
|
72 |
List<DOCUMENT_ITEM> docItems = new List<DOCUMENT_ITEM>(); |
73 |
List<MEMBER> members = new List<MEMBER>(); |
74 |
docItems = entity.DOCUMENT_ITEM.Where(di => di.PROJECT_NO == filter.projectNo).ToList(); |
75 |
members = entity.MEMBER.ToList(); |
76 |
|
77 |
int count = mergeDocList.Count; |
78 |
int index = filter.start; |
79 |
|
80 |
var limitList = mergeDocList.Skip(filter.start).Take(filter.Length).ToList(); |
81 |
|
82 |
limitList.ForEach(ret => |
83 |
{ |
84 |
|
85 |
var mergeUrl = docItems.Where(di => di.DOCUMENT_ID == ret.DOCUMENT_ID && di.PROJECT_NO == ret.PROJECT_NO).FirstOrDefault(); |
86 |
string mergeFileURL = String.Empty; |
87 |
|
88 |
if (mergeUrl != null) |
89 |
{ |
90 |
mergeFileURL = "<a href=\"" + mergeUrl.RESULT_FILE + "\" target=\"_blank\">PDF</a>"; |
91 |
} |
92 |
|
93 |
tableData.Add(new TableData_Merge() |
94 |
{ |
95 |
ID = ret.ID, |
96 |
DeleteDocument = "<input type=\"checkbox\" name=\"deleteDocument[]\" value=\"" + ret.DOCUMENT_ID + "\" />", |
97 |
OpenMarkusURL = "<a href=\"kcom://" + CommonController.CreateMarkusParam(ret.PROJECT_NO, ret.DOCUMENT_ID, token) + "\">open</a>", |
98 |
CreateUserID = (members.Where(mem => mem.ID.ToLower() == ret.CREATE_USER_ID.ToLower()).FirstOrDefault() != null) ? members.Where(mem => mem.ID.ToLower() == ret.CREATE_USER_ID.ToLower()).FirstOrDefault().NAME : null, |
99 |
DocumentID = ret.DOCUMENT_ID, |
100 |
CurrentPage = ret.CURRENT_PAGE, |
101 |
TotalPage = ret.TOTAL_PAGE, |
102 |
CreateDate = ret.CREATE_DATETIME, |
103 |
StartDateTime = ret.START_DATETIME, |
104 |
EndDateTime = ret.END_DATETIME, |
105 |
ConvertTime = null, |
106 |
Status = CommonController.GetStatusName(ret.STATUS), |
107 |
DocumentURL = mergeFileURL, |
108 |
Message = ret.EXCEPTION |
109 |
}); |
110 |
|
111 |
}); |
112 |
|
113 |
dto.draw = filter.Draw; |
114 |
dto.recordsFiltered = count; |
115 |
dto.recordsTotal = count; |
116 |
dto.length = filter.Length; |
117 |
dto.data = tableData; |
118 |
|
119 |
return dto; |
120 |
|
121 |
} |
122 |
else |
123 |
{ |
124 |
dto.draw = filter.Draw; |
125 |
dto.recordsFiltered = 0; |
126 |
dto.recordsTotal = 0; |
127 |
dto.length = 0; |
128 |
dto.data = new List<TableData_Merge>(); |
129 |
|
130 |
return dto; |
131 |
} |
132 |
|
133 |
|
134 |
} |
135 |
} |
136 |
|
137 |
} |
138 |
catch (Exception) |
139 |
{ |
140 |
dto.statusCode = 500; |
141 |
return dto; |
142 |
throw; |
143 |
} |
144 |
|
145 |
} |
146 |
|
147 |
#endregion |
148 |
} |
149 |
|
150 |
/// <summary> |
151 |
/// Update Complete Convert Documnet URL, ViewInfo |
152 |
/// </summary> |
153 |
/// <param name="pComplete"></param> |
154 |
/// <returns></returns> |
155 |
[HttpPost, Route("~/api/merge/complete")] |
156 |
public async Task<HttpResponseMessage> Complete(FINAL_PDF pComplete) |
157 |
{ |
158 |
#region 컨버팅이 완료되면 ConvertURL , ViewInfo 데이터 생성 |
159 |
HttpResponseMessage resp = new HttpResponseMessage(); |
160 |
CompleteMergeDTO completeInfo = new CompleteMergeDTO(); |
161 |
|
162 |
try |
163 |
{ |
164 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
165 |
{ |
166 |
return CommonController.Forbidden(resp); |
167 |
} |
168 |
else |
169 |
{ |
170 |
|
171 |
using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
172 |
{ |
173 |
|
174 |
var mergeDocument = entity.FINAL_PDF.Where(doc => doc.PROJECT_NO == pComplete.PROJECT_NO && doc.ID == pComplete.ID).FirstOrDefault(); |
175 |
|
176 |
if (mergeDocument != null) |
177 |
{ |
178 |
|
179 |
completeInfo = new CompleteMergeDTO() |
180 |
{ |
181 |
ID = mergeDocument.ID, |
182 |
MergeURL = (entity.DOCUMENT_ITEM.Where(di => di.DOCUMENT_ID == pComplete.DOCUMENT_ID && di.PROJECT_NO == pComplete.PROJECT_NO).FirstOrDefault() != null) ? entity.DOCUMENT_ITEM.Where(di => di.DOCUMENT_ID == pComplete.DOCUMENT_ID && di.PROJECT_NO == pComplete.PROJECT_NO).FirstOrDefault().RESULT_FILE : null, |
183 |
ViewInfo = CommonController.CreateMarkusParam(mergeDocument.PROJECT_NO, mergeDocument.DOCUMENT_ID, Request.Headers.Authorization.ToString()) |
184 |
}; |
185 |
|
186 |
resp = await CommonController.OK<CompleteMergeDTO>(resp, completeInfo); |
187 |
|
188 |
} |
189 |
else |
190 |
{ |
191 |
resp = await CommonController.NotFound<CompleteMergeDTO>(resp, completeInfo); |
192 |
} |
193 |
} |
194 |
} |
195 |
|
196 |
return resp; |
197 |
|
198 |
} |
199 |
catch (Exception) |
200 |
{ |
201 |
resp = CommonController.InternalServerError(resp, "Error "); |
202 |
return resp; |
203 |
} |
204 |
#endregion |
205 |
} |
206 |
|
207 |
[HttpPost, Route("~/api/merge/GetDocumentMessage")] |
208 |
public async Task<HttpResponseMessage> GetDocumentItemMessage([FromBody] pDocumentMessage pDocInfo) |
209 |
{ |
210 |
#region 도큐먼트 Message, Original URL 가져오기 |
211 |
HttpResponseMessage resp = new HttpResponseMessage(); |
212 |
|
213 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
214 |
{ |
215 |
return CommonController.Forbidden(resp); |
216 |
} |
217 |
else |
218 |
{ |
219 |
try |
220 |
{ |
221 |
|
222 |
ViewInfo getDocument = CommonController.ParamDecoding(pDocInfo.pDocumentInfo); |
223 |
|
224 |
using (markusEntities cme = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
225 |
{ |
226 |
|
227 |
var finalMessage = cme.FINAL_PDF.Where(cd => cd.DOCUMENT_ID == pDocInfo.pDocumentInfo).Select(ret => ret.EXCEPTION).FirstOrDefault(); |
228 |
|
229 |
return await CommonController.OK<string>(resp, finalMessage); |
230 |
|
231 |
} |
232 |
|
233 |
} |
234 |
catch (Exception ex) |
235 |
{ |
236 |
|
237 |
Console.WriteLine(ex.Message); |
238 |
throw ex; |
239 |
|
240 |
} |
241 |
} |
242 |
#endregion |
243 |
} |
244 |
|
245 |
|
246 |
// 기능 없음 |
247 |
//[HttpPost, Route("~/api/remerge")] |
248 |
//public async Task<HttpResponseMessage> RetryMerge([FromBody] pRetryDocument) { |
249 |
// HttpResponseMessage resp = new HttpResponseMessage(); |
250 |
// try |
251 |
// { |
252 |
// using (cloud) |
253 |
// { |
254 |
// } |
255 |
// } |
256 |
// catch (Exception) |
257 |
// { |
258 |
// throw; |
259 |
// } |
260 |
//} |
261 |
|
262 |
} |
263 |
} |