markus / MarkusLogview / MARKUS_LOGVIEW / Controllers / ConvertAPIController.cs @ a0d58556
이력 | 보기 | 이력해설 | 다운로드 (28.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.IO; |
9 |
using System.Linq; |
10 |
using System.Net; |
11 |
using System.Net.Http; |
12 |
using System.Net.Http.Headers; |
13 |
using System.Threading.Tasks; |
14 |
using System.Web; |
15 |
using System.Web.Http; |
16 |
using System.Web.Services; |
17 |
using static ServiceInterface.LogView_Interface; |
18 |
|
19 |
namespace MARKUS_LOGVIEW.Controllers |
20 |
{ |
21 |
|
22 |
public class ConvertAPIController : ApiController |
23 |
{ |
24 |
|
25 |
/// <summary> |
26 |
/// 컨버팅 데이블 데이터 반환 |
27 |
/// </summary> |
28 |
/// <param name="filter"></param> |
29 |
/// <returns></returns> |
30 |
[HttpPost, Route("~/api/project/GetConvertDocument")] |
31 |
public async Task<ConvertTableData> GetConvertDocument([FromBody] DataTableParameters filter) |
32 |
{ |
33 |
#region Convert Table data 반환 |
34 |
ConvertTableData dto = new ConvertTableData(); |
35 |
List<TableData_Convert> tableData = new List<TableData_Convert>(); |
36 |
|
37 |
DateTime prjDocStartDate = Convert.ToDateTime(filter.startDate); |
38 |
DateTime prjDocEndDate = Convert.ToDateTime(filter.endDate).AddHours(23).AddMinutes(59).AddSeconds(59); |
39 |
|
40 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
41 |
{ |
42 |
dto.statusCode = 403; |
43 |
return dto; |
44 |
} |
45 |
else |
46 |
{ |
47 |
|
48 |
try |
49 |
{ |
50 |
|
51 |
string token = Request.Headers.Authorization.ToString(); |
52 |
|
53 |
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
54 |
{ |
55 |
|
56 |
var convDocList = ent.CONVERTER_DOC |
57 |
.Where( |
58 |
cd => cd.CREATE_DATETIME >= prjDocStartDate && |
59 |
cd.CREATE_DATETIME <= prjDocEndDate && |
60 |
cd.PROJECT_NO == filter.projectNo && |
61 |
(string.IsNullOrEmpty(filter.Search.Value)) ? string.IsNullOrEmpty(filter.Search.Value) : cd.DOCUMENT_ID.Contains(filter.Search.Value) |
62 |
) |
63 |
.OrderByDescending(t => t.CREATE_DATETIME) |
64 |
.ToList(); |
65 |
|
66 |
if (convDocList.Count > 0) |
67 |
{ |
68 |
|
69 |
int count = convDocList.Count; |
70 |
int index = filter.start; |
71 |
|
72 |
var limitList = convDocList.Skip(filter.start).Take(filter.Length).ToList(); |
73 |
|
74 |
limitList.ForEach(ret => |
75 |
{ |
76 |
tableData.Add(new TableData_Convert() |
77 |
{ |
78 |
ID = ret.ID, |
79 |
DeleteDocument = "<input type=\"checkbox\" name=\"deleteDocument[]\" value=\"" + ret.DOCUMENT_ID + "\" />", |
80 |
OpenMarkusURL = "<a href=\"kcom://" + CommonController.CreateMarkusParam(ret.PROJECT_NO, ret.DOCUMENT_ID, token) + "\">open</a>", |
81 |
DocumentID = ret.DOCUMENT_ID, |
82 |
InterfaceID = ent.DOCUMENT_ITEM.Where(d =>d.DOCUMENT_ID == ret.DOCUMENT_ID).FirstOrDefault().ID, |
83 |
CurrentPage = ret.CURRENT_PAGE, |
84 |
TotalPage = ret.TOTAL_PAGE, |
85 |
CreateDate = ret.CREATE_DATETIME, |
86 |
StartDateTime = ret.START_DATETIME, |
87 |
EndDateTime = ret.END_DATETIME, |
88 |
ConvertTime = null, |
89 |
Status = CommonController.GetStatusName(ret.STATUS), |
90 |
DocumentURL = "<a href=\"" + ret.DOCUMENT_URL + "\" target=\"_blank\">PDF</a>", |
91 |
}); |
92 |
|
93 |
}); |
94 |
|
95 |
dto.draw = filter.Draw; |
96 |
dto.recordsTotal = count; |
97 |
dto.recordsFiltered = count; |
98 |
dto.length = filter.Length; |
99 |
dto.data = tableData; |
100 |
|
101 |
return dto; |
102 |
|
103 |
} |
104 |
else |
105 |
{ |
106 |
dto.draw = filter.Draw; |
107 |
dto.recordsFiltered = 0; |
108 |
dto.recordsTotal = 0; |
109 |
dto.length = 0; |
110 |
dto.data = new List<TableData_Convert>(); |
111 |
|
112 |
return dto; |
113 |
|
114 |
} |
115 |
|
116 |
|
117 |
} |
118 |
|
119 |
} |
120 |
catch (Exception) |
121 |
{ |
122 |
dto.statusCode = 500; |
123 |
return dto; |
124 |
} |
125 |
|
126 |
} |
127 |
#endregion |
128 |
} |
129 |
|
130 |
/// <summary> |
131 |
/// Get Revision Document List |
132 |
/// </summary> |
133 |
/// <param name="param"></param> |
134 |
/// <returns></returns> |
135 |
[HttpPost,Route("~/api/GetDocumentItemList")] |
136 |
public async Task<HttpResponseMessage> GetDocumentItemList(pGetDocumentItemList param) |
137 |
{ |
138 |
#region 해당 프로젝트의 DocumentItem 가져오기 ( 파일 업로드 시 - 리비전 업 ) |
139 |
HttpResponseMessage resp = new HttpResponseMessage(); |
140 |
List<DocumentItemInfoList> docItemList = new List<DocumentItemInfoList>(); |
141 |
|
142 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
143 |
{ |
144 |
return CommonController.Forbidden(resp); |
145 |
} |
146 |
else |
147 |
{ |
148 |
try |
149 |
{ |
150 |
|
151 |
using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
152 |
{ |
153 |
|
154 |
var docItems = entity.DOCUMENT_ITEM |
155 |
.Where(doc => doc.PROJECT_NO.Equals(param.ProjectNO)) |
156 |
.GroupBy(g => g.DOCUMENT_NO, (key, docNO) => docNO.FirstOrDefault()) |
157 |
.Select(ret => new DocumentItemInfoList() |
158 |
{ |
159 |
DocumentItemNO = ret.DOCUMENT_NO, |
160 |
DocumentItemID = ret.DOCUMENT_ID, |
161 |
DocumentItemName = ret.DOCUMENT_NAME |
162 |
|
163 |
}).ToList(); |
164 |
|
165 |
if (docItems.Count > 0) |
166 |
{ |
167 |
resp = await CommonController.OK<List<DocumentItemInfoList>>(resp, docItems); |
168 |
} |
169 |
else |
170 |
{ |
171 |
resp = await CommonController.NotFound<pGetDocumentItemList>(resp, new pGetDocumentItemList() |
172 |
{ |
173 |
ProjectNO = param.ProjectNO |
174 |
}); |
175 |
} |
176 |
|
177 |
return resp; |
178 |
} |
179 |
} |
180 |
catch (Exception ex) |
181 |
{ |
182 |
resp = CommonController.InternalServerError(resp, ex.Message); |
183 |
return resp; |
184 |
} |
185 |
} |
186 |
#endregion |
187 |
} |
188 |
|
189 |
/// <summary> |
190 |
/// Get Document Message and Original URL |
191 |
/// </summary> |
192 |
/// <param name="pDocInfo"></param> |
193 |
/// <returns></returns> |
194 |
[HttpPost,Route("~/api/convert/GetDocumentMessage")] |
195 |
public async Task<HttpResponseMessage> GetDocumentItemMessage([FromBody] pDocumentMessage pDocInfo) |
196 |
{ |
197 |
#region 도큐먼트 Message, Original URL 가져오기 |
198 |
HttpResponseMessage resp = new HttpResponseMessage(); |
199 |
|
200 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
201 |
{ |
202 |
return CommonController.Forbidden(resp); |
203 |
} |
204 |
else |
205 |
{ |
206 |
try |
207 |
{ |
208 |
|
209 |
ViewInfo getDocument = CommonController.ParamDecoding(pDocInfo.pDocumentInfo); |
210 |
|
211 |
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
212 |
{ |
213 |
|
214 |
var convMessage = ent.CONVERTER_DOC.Where(cd => cd.DOCUMENT_ID == getDocument.DocumentItemID).Select(ret => ret.EXCEPTION).FirstOrDefault(); |
215 |
|
216 |
DocumentMessage docMessage = ent.DOCUMENT_ITEM |
217 |
.Where(di => di.DOCUMENT_ID == getDocument.DocumentItemID) |
218 |
.Select(ret => new DocumentMessage() |
219 |
{ |
220 |
OriginalURL = ret.ORIGINAL_FILE, |
221 |
Message = convMessage |
222 |
}) |
223 |
.FirstOrDefault(); |
224 |
|
225 |
return await CommonController.OK<DocumentMessage>(resp, docMessage); |
226 |
|
227 |
|
228 |
} |
229 |
|
230 |
} |
231 |
catch (Exception ex) |
232 |
{ |
233 |
|
234 |
Console.WriteLine(ex.Message); |
235 |
throw ex; |
236 |
|
237 |
} |
238 |
} |
239 |
#endregion |
240 |
} |
241 |
|
242 |
/// <summary> |
243 |
/// Upload PDF File |
244 |
/// </summary> |
245 |
private string folder_increaseNumber; |
246 |
[HttpPost] |
247 |
[Route("~/api/pdf/upload")] |
248 |
public async Task<HttpResponseMessage> UploadFile() |
249 |
{ |
250 |
#region 파일 리비전 메서드 |
251 |
int uploadType = 0; |
252 |
string initFolderName = "40000000"; |
253 |
|
254 |
// 파일 저장 경로 |
255 |
// Web Server 000000_app/VPCS_DOCLIB/ |
256 |
string serverPath = "../../Doc_Manager/"; |
257 |
string originalFileDefaultURL = "/Doc_Manager/"; |
258 |
|
259 |
// Local Test |
260 |
//string serverPath = "/pdfUpload/"; |
261 |
//string originalFileDefaultURL = "/pdfUpload/"; |
262 |
|
263 |
HttpResponseMessage resp = new HttpResponseMessage(); |
264 |
DocumentItemDTO revDoc = new DocumentItemDTO(); |
265 |
|
266 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
267 |
{ |
268 |
return CommonController.Forbidden(resp); |
269 |
} |
270 |
else |
271 |
{ |
272 |
|
273 |
if (!Request.Content.IsMimeMultipartContent()) |
274 |
{ |
275 |
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); |
276 |
} |
277 |
|
278 |
try |
279 |
{ |
280 |
|
281 |
string defaultSaveFilePath = HttpContext.Current.Server.MapPath(serverPath); |
282 |
|
283 |
if (!Directory.Exists(defaultSaveFilePath)) |
284 |
{ |
285 |
Directory.CreateDirectory(defaultSaveFilePath); |
286 |
} |
287 |
|
288 |
|
289 |
var provider = new MultipartFormDataStreamProvider(HttpContext.Current.Server.MapPath(serverPath)); |
290 |
|
291 |
await Request.Content.ReadAsMultipartAsync(provider); |
292 |
|
293 |
foreach (var key in provider.FormData.AllKeys) |
294 |
{ |
295 |
foreach (var val in provider.FormData.GetValues(key)) |
296 |
{ |
297 |
|
298 |
switch (key) |
299 |
{ |
300 |
case "ProjectNO": |
301 |
revDoc.ProjectNO = val; |
302 |
break; |
303 |
case "DocumentID": |
304 |
revDoc.DocumentID = (val != "") ? val : null; |
305 |
break; |
306 |
case "DocumentName": |
307 |
revDoc.DocumentName = (val != "") ? val : null; |
308 |
break; |
309 |
case "DocumentNO": |
310 |
revDoc.DocumentNO = (val != "") ? val : null; |
311 |
break; |
312 |
case "UploadType": |
313 |
uploadType = Convert.ToInt32(val); |
314 |
break; |
315 |
|
316 |
} |
317 |
|
318 |
} |
319 |
|
320 |
} |
321 |
|
322 |
string storagePath = HttpContext.Current.Server.MapPath(serverPath); |
323 |
storagePath = storagePath + revDoc.ProjectNO + "_app/VPCS_DOCLIB/"; |
324 |
// 해당 폴더가 없으면 + initFolderName |
325 |
if (!Directory.Exists(storagePath + initFolderName)) |
326 |
{ |
327 |
// 폴더 생성 |
328 |
storagePath += initFolderName; |
329 |
Directory.CreateDirectory(storagePath); |
330 |
|
331 |
} |
332 |
else |
333 |
{ |
334 |
// 폴더 정보를 가져와서 내림차순으로 정렬 |
335 |
DirectoryInfo[] dicInfo = new DirectoryInfo(storagePath).GetDirectories(); |
336 |
Array.Sort(dicInfo, (x, y) => y.Name.CompareTo(x.Name)); |
337 |
|
338 |
// 저장경로에 폴더명 가져오기 ( 제일 높은 숫자의 폴더명 + 1 하여 폴더 생성 ) |
339 |
folder_increaseNumber = (Convert.ToInt32(dicInfo[0].Name) + 1).ToString(); |
340 |
storagePath += folder_increaseNumber; |
341 |
|
342 |
Directory.CreateDirectory(storagePath); |
343 |
|
344 |
} |
345 |
|
346 |
// project revision setting 가져오기 |
347 |
string strRevision; |
348 |
using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
349 |
{ |
350 |
strRevision = entity.PROJECT_SETTING.Where(ps => ps.PROJECT_NO.Equals(revDoc.ProjectNO)).Select(ret => ret.REVISION).FirstOrDefault(); |
351 |
|
352 |
|
353 |
// 리비전 업을 또는 생성을 위한 로직 |
354 |
// GroupNo은 해당 프로젝트의 GroupNo 의 마지막 값에서 증가. |
355 |
var grouping = entity.DOCUMENT_ITEM.Where(di => di.PROJECT_NO.Equals(revDoc.ProjectNO)).ToList(); |
356 |
|
357 |
if (grouping.Count() > 0) |
358 |
{ |
359 |
|
360 |
string descGroupNo = entity.DOCUMENT_ITEM.Where(di => di.PROJECT_NO.Equals(revDoc.ProjectNO)).OrderByDescending(x => x.GROUP_NO).Select(ret => ret).ToList().First().GROUP_NO; |
361 |
revDoc.GroupNO = (Int32.Parse(descGroupNo) + 1).ToString(); |
362 |
|
363 |
} |
364 |
else |
365 |
{ |
366 |
revDoc.GroupNO = "1"; |
367 |
} |
368 |
|
369 |
if (uploadType == (int)UPLOAD_TYPE.NEWDOCUMENT) |
370 |
{ |
371 |
// 새로운 리비전 파라미터 DocumentItemNO, DocumentItemName |
372 |
// 해당 이름이 먼저 있는지 체크를 해야함. |
373 |
var checkDocumentItem = entity.DOCUMENT_ITEM.Where(di => di.DOCUMENT_NO.Equals(revDoc.DocumentNO) && di.PROJECT_NO == revDoc.ProjectNO).ToList(); |
374 |
|
375 |
if (checkDocumentItem.Count > 0) |
376 |
{ |
377 |
|
378 |
resp.StatusCode = HttpStatusCode.InternalServerError; |
379 |
resp.Content = await CommonController.JsonSerialize<string>("The same document number exists"); |
380 |
|
381 |
return resp; |
382 |
|
383 |
} |
384 |
else |
385 |
{ |
386 |
revDoc.Revision = strRevision.Split(',')[0].ToString(); |
387 |
} |
388 |
} |
389 |
else if (uploadType == (int)UPLOAD_TYPE.REVISIONUP) |
390 |
{ |
391 |
|
392 |
// 기존 리비전 업 파라미터 DocumentItemNO |
393 |
var selectedDocumentItem = entity.DOCUMENT_ITEM |
394 |
.Where(di => di.DOCUMENT_ID.Equals(revDoc.DocumentID)) |
395 |
.OrderByDescending(x => x.REVISION) |
396 |
.Select(ret => ret) |
397 |
.ToList(); |
398 |
|
399 |
if (selectedDocumentItem.Count > 0) |
400 |
{ |
401 |
|
402 |
var getDocument = selectedDocumentItem.First(); |
403 |
if (strRevision.Split(',').Last() == getDocument.REVISION) |
404 |
{ |
405 |
resp.StatusCode = HttpStatusCode.InternalServerError; |
406 |
resp.Content = await CommonController.JsonSerialize<string>("Can not make any more revisions."); |
407 |
|
408 |
return resp; |
409 |
} |
410 |
else |
411 |
{ |
412 |
revDoc.Revision = ((char)(Convert.ToInt32((getDocument.REVISION.ToCharArray()[0])) + 1)).ToString(); |
413 |
revDoc.DocumentName = getDocument.DOCUMENT_NAME; |
414 |
} |
415 |
|
416 |
revDoc.DocumentNO = getDocument.DOCUMENT_NO; |
417 |
|
418 |
} |
419 |
|
420 |
} |
421 |
else |
422 |
{ |
423 |
|
424 |
resp.StatusCode = HttpStatusCode.InternalServerError; |
425 |
resp.Content = await CommonController.JsonSerialize<string>("PDF File Upload Error"); |
426 |
|
427 |
return resp; |
428 |
|
429 |
} |
430 |
|
431 |
} |
432 |
|
433 |
MultipartFileData fileData = provider.FileData[0]; |
434 |
|
435 |
if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName)) |
436 |
{ |
437 |
// type이 다르다. |
438 |
} |
439 |
|
440 |
if (string.IsNullOrEmpty(fileData.Headers.ContentDisposition.FileName)) |
441 |
{ |
442 |
return Request.CreateResponse(HttpStatusCode.NotAcceptable, "This request is not properly formatted"); |
443 |
} |
444 |
string fileName = fileData.Headers.ContentDisposition.FileName; |
445 |
if (fileName.StartsWith("\"") && fileName.EndsWith("\"")) |
446 |
{ |
447 |
fileName = fileName.Trim('"'); |
448 |
} |
449 |
if (fileName.Contains(@"/") || fileName.Contains(@"\")) |
450 |
{ |
451 |
fileName = Path.GetFileName(fileName); |
452 |
} |
453 |
|
454 |
// 파일 저장 |
455 |
File.Move(fileData.LocalFileName, Path.Combine(storagePath, fileName)); |
456 |
|
457 |
// 파일 저장을 성공하면 ConvertWebService 로 전송 |
458 |
using (ConvertWebService.Conversion convertService = new ConvertWebService.Conversion()) |
459 |
{ |
460 |
|
461 |
|
462 |
revDoc.DocumentID = (folder_increaseNumber != null) ? folder_increaseNumber : initFolderName; |
463 |
revDoc.OriginalFile = "http://" + Request.Headers.Host + originalFileDefaultURL + revDoc.ProjectNO + "_app/VPCS_DOCLIB/" + revDoc.DocumentID + "/" + fileName; |
464 |
revDoc.ID = CommonController.shortGuid(); |
465 |
|
466 |
// 디비에 저장 |
467 |
using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
468 |
{ |
469 |
|
470 |
entity.DOCUMENT_ITEM.AddObject(new DOCUMENT_ITEM() |
471 |
{ |
472 |
ID = revDoc.ID, |
473 |
REVISION = revDoc.Revision, |
474 |
DOCUMENT_NO = revDoc.DocumentNO, |
475 |
DOCUMENT_NAME = revDoc.DocumentName, |
476 |
GROUP_NO = revDoc.GroupNO, |
477 |
ORIGINAL_FILE = revDoc.OriginalFile, |
478 |
DOCUMENT_ID = revDoc.DocumentID, |
479 |
PROJECT_NO = revDoc.ProjectNO |
480 |
}); |
481 |
|
482 |
entity.SaveChanges(); |
483 |
|
484 |
} |
485 |
|
486 |
|
487 |
// 웹 서비스 호출 ( 컨버팅 서비스 호출 ) |
488 |
//convertService.Run(revDoc.ProjectNO, revDoc.OriginalFile, revDoc.DocumentID); |
489 |
|
490 |
resp.StatusCode = HttpStatusCode.OK; |
491 |
resp.Content = await CommonController.JsonSerialize<string>("Upload Success"); |
492 |
|
493 |
} |
494 |
|
495 |
return resp; |
496 |
|
497 |
|
498 |
|
499 |
} |
500 |
catch (Exception ex) |
501 |
{ |
502 |
|
503 |
Console.WriteLine(ex.Message); |
504 |
resp.StatusCode = HttpStatusCode.InternalServerError; |
505 |
resp.Content = await CommonController.JsonSerialize<string>("Upload Failed"); |
506 |
|
507 |
return resp; |
508 |
|
509 |
} |
510 |
|
511 |
} |
512 |
#endregion |
513 |
} |
514 |
|
515 |
/// <summary> |
516 |
/// Update Complete Convert Documnet URL, ViewInfo |
517 |
/// </summary> |
518 |
/// <param name="pComplete"></param> |
519 |
/// <returns></returns> |
520 |
[HttpPost, Route("~/api/convert/complete")] |
521 |
public async Task<HttpResponseMessage> Complete(CONVERTER_DOC pComplete) |
522 |
{ |
523 |
#region 컨버팅이 완료되면 ConvertURL , ViewInfo 데이터 생성 |
524 |
HttpResponseMessage resp = new HttpResponseMessage(); |
525 |
CompleteConvertDTO completeInfo = new CompleteConvertDTO(); |
526 |
|
527 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
528 |
{ |
529 |
return CommonController.Forbidden(resp); |
530 |
} |
531 |
else |
532 |
{ |
533 |
|
534 |
using (markusEntities entity = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
535 |
{ |
536 |
|
537 |
var convertDocument = entity.CONVERTER_DOC.Where(doc => doc.PROJECT_NO == pComplete.PROJECT_NO && doc.ID == pComplete.ID).FirstOrDefault(); |
538 |
if (convertDocument != null) |
539 |
{ |
540 |
|
541 |
completeInfo = new CompleteConvertDTO() |
542 |
{ |
543 |
ID = convertDocument.ID, |
544 |
ConvertURL = convertDocument.DOCUMENT_URL.ToString(), |
545 |
ViewInfo = CommonController.CreateMarkusParam(convertDocument.PROJECT_NO, convertDocument.DOCUMENT_ID, Request.Headers.Authorization.ToString()) |
546 |
}; |
547 |
|
548 |
resp = await CommonController.OK<CompleteConvertDTO>(resp, completeInfo); |
549 |
|
550 |
} |
551 |
else |
552 |
{ |
553 |
resp = await CommonController.NotFound<CompleteConvertDTO>(resp, completeInfo); |
554 |
} |
555 |
|
556 |
} |
557 |
|
558 |
} |
559 |
|
560 |
return resp; |
561 |
|
562 |
#endregion |
563 |
} |
564 |
|
565 |
/// <summary> |
566 |
/// 컨버팅 재시작 |
567 |
/// </summary> |
568 |
/// <param name="doc"></param> |
569 |
/// <returns></returns> |
570 |
[HttpPost, Route("~/api/retry/convert")] |
571 |
public async Task<HttpResponseMessage> Reconvert([FromBody] pRetryDocument doc) |
572 |
{ |
573 |
#region 컨버팅 재시작 |
574 |
|
575 |
HttpResponseMessage resp = new HttpResponseMessage(); |
576 |
|
577 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
578 |
{ |
579 |
return CommonController.Forbidden(resp); |
580 |
} |
581 |
else |
582 |
{ |
583 |
try |
584 |
{ |
585 |
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
586 |
{ |
587 |
// 웹 서비스 호출 ( 컨버팅 서비스 호출 ) |
588 |
var documentCount = doc.documentID.Count(); |
589 |
|
590 |
for (int i = 0; i < documentCount; i++) |
591 |
{ |
592 |
|
593 |
// 선택한 도큐먼트 아이디를 통해 정보 찾기 |
594 |
string targetDocumentID = doc.documentID[i].ToString(); |
595 |
// DOCUMENT_ITEM 에서 찾는 이유는 오리지널 파일 URL 을 찾기 위해서이다. |
596 |
//var targetDocument = ent.DOCUMENT_ITEM.Where(di => di.PROJECT_NO == doc.projectNO && di.DOCUMENT_ID == targetDocumentID).FirstOrDefault(); |
597 |
var targetDocument = ent.CONVERTER_DOC.Where(di => di.PROJECT_NO == doc.projectNO && di.DOCUMENT_ID == targetDocumentID).FirstOrDefault(); |
598 |
|
599 |
if (targetDocument != null) |
600 |
{ |
601 |
targetDocument.STATUS = (int)PDFStatus.Insert; |
602 |
targetDocument.RECONVERTER = 0; |
603 |
ent.SaveChanges(); |
604 |
//using (ConvertWebService.Conversion convertService = new ConvertWebService.Conversion()) |
605 |
//{ |
606 |
// convertService.ConvertRun(targetDocument.REVISION, targetDocument.DOCUMENT_NO, targetDocument.DOCUMENT_NAME, targetDocument.GROUP_NO, targetDocument.PROJECT_NO, targetDocument.ID, targetDocument.ORIGINAL_FILE); |
607 |
//} |
608 |
} |
609 |
else |
610 |
{ |
611 |
return await CommonController.NotFound<string>(resp, "Not found"); |
612 |
} |
613 |
|
614 |
} |
615 |
|
616 |
return await CommonController.OK<bool>(resp, true); |
617 |
|
618 |
} |
619 |
|
620 |
} |
621 |
catch (Exception ex) |
622 |
{ |
623 |
Console.WriteLine(ex.Message); |
624 |
return CommonController.InternalServerError(resp, "server error"); |
625 |
throw; |
626 |
} |
627 |
|
628 |
} |
629 |
|
630 |
#endregion |
631 |
} |
632 |
|
633 |
/// <summary> |
634 |
/// 컨버팅 재시작 |
635 |
/// </summary> |
636 |
/// <param name="doc"></param> |
637 |
/// <returns></returns> |
638 |
[HttpPost, Route("~/api/retry/coverconvert")] |
639 |
public async Task<HttpResponseMessage> Coverconvert([FromBody] pRetryDocument doc) |
640 |
{ |
641 |
#region 커버컨버팅 |
642 |
|
643 |
HttpResponseMessage resp = new HttpResponseMessage(); |
644 |
|
645 |
if (!AuthorizationController.UserAuthorization(Request.Headers.Authorization.ToString())) |
646 |
{ |
647 |
return CommonController.Forbidden(resp); |
648 |
} |
649 |
else |
650 |
{ |
651 |
try |
652 |
{ |
653 |
using (markusEntities ent = new markusEntities(ConnectStringBuilder.MarkusEntitiesConnectionString().ToString())) |
654 |
{ |
655 |
// 웹 서비스 호출 ( 컨버팅 서비스 호출 ) |
656 |
var documentCount = doc.documentID.Count(); |
657 |
|
658 |
for (int i = 0; i < documentCount; i++) |
659 |
{ |
660 |
|
661 |
// 선택한 도큐먼트 아이디를 통해 정보 찾기 |
662 |
string targetDocumentID = doc.documentID[i].ToString(); |
663 |
// DOCUMENT_ITEM 에서 찾는 이유는 오리지널 파일 URL 을 찾기 위해서이다. |
664 |
var targetDocument = ent.CONVERTER_DOC.Where(di => di.PROJECT_NO == doc.projectNO && di.DOCUMENT_ID == targetDocumentID).FirstOrDefault(); |
665 |
|
666 |
if (targetDocument != null) |
667 |
{ |
668 |
using (ConvertWebService.Conversion convertService = new ConvertWebService.Conversion()) |
669 |
{ |
670 |
convertService.CoverConvert(targetDocument.PROJECT_NO, targetDocument.ID);// (targetDocument.REVISION, targetDocument.DOCUMENT_NO, targetDocument.DOCUMENT_NAME, targetDocument.GROUP_NO, targetDocument.PROJECT_NO, targetDocument.ID, targetDocument.ORIGINAL_FILE); |
671 |
} |
672 |
|
673 |
} |
674 |
else |
675 |
{ |
676 |
return await CommonController.NotFound<string>(resp, "Not found"); |
677 |
} |
678 |
|
679 |
} |
680 |
|
681 |
return await CommonController.OK<bool>(resp, true); |
682 |
|
683 |
} |
684 |
|
685 |
} |
686 |
catch (Exception ex) |
687 |
{ |
688 |
Console.WriteLine(ex.Message); |
689 |
return CommonController.InternalServerError(resp, "server error"); |
690 |
throw; |
691 |
} |
692 |
|
693 |
} |
694 |
|
695 |
#endregion |
696 |
} |
697 |
} |
698 |
|
699 |
} |