markus / PemssAPI / PemssApi.cs @ a5b2c76f
이력 | 보기 | 이력해설 | 다운로드 (18.6 KB)
1 |
using Newtonsoft.Json.Linq; |
---|---|
2 |
using System; |
3 |
using System.Collections.Generic; |
4 |
using System.Linq; |
5 |
using System.Web; |
6 |
using PemssAPI.DataModel; |
7 |
using System.Collections.Specialized; |
8 |
using System.Net.Http; |
9 |
using System.Net.Http.Headers; |
10 |
using System.Net; |
11 |
using Newtonsoft.Json; |
12 |
|
13 |
namespace KCOM_API |
14 |
{ |
15 |
/// <summary> |
16 |
/// 등록은 POST, 삭제시 DELETE , LIST 는 GET 으로 호출해야 합니다. |
17 |
/// </summary> |
18 |
public class PemssApi : IDisposable |
19 |
{ |
20 |
private string gPemssUri; |
21 |
|
22 |
public PemssApi(string PemssApiUri) |
23 |
{ |
24 |
gPemssUri = PemssApiUri; |
25 |
} |
26 |
|
27 |
public void Dispose() |
28 |
{ |
29 |
} |
30 |
|
31 |
#region 정합성 목록 |
32 |
|
33 |
|
34 |
/// <summary> |
35 |
/// 정합성 목록 |
36 |
/// </summary> |
37 |
/// <param name="pId">프로젝트 ID</param> |
38 |
/// <param name="dId">Document ID</param> |
39 |
/// <returns></returns> |
40 |
public List<Requirement> GetRequirementItems(string pId,string dId) |
41 |
{ |
42 |
List<Requirement> result = new List<Requirement>(); |
43 |
|
44 |
try |
45 |
{ |
46 |
var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/list/requirement?pId={pId}&dId={dId}"); |
47 |
|
48 |
if (jsonObj != null) |
49 |
{ |
50 |
JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
51 |
|
52 |
foreach (var item in JArray.Parse(jObject["rows"].ToString())) |
53 |
{ |
54 |
List<VpCommant> VpComments = new List<VpCommant>(); |
55 |
|
56 |
if (item["vpComments"].HasValues) |
57 |
{ |
58 |
var comments = JArray.Parse(item["vpComments"].ToString()); |
59 |
|
60 |
foreach (var comment in comments) |
61 |
{ |
62 |
VpComments.Add(new VpCommant |
63 |
{ |
64 |
mdId = item["mdId"]?.ToObject<string>(), |
65 |
created = comment["created"]?.ToObject<string>(), |
66 |
comment = comment["comment"]?.ToObject<string>(), |
67 |
commentId = comment["commentId"]?.ToObject<string>(), |
68 |
condition = comment["condition"]?.ToObject<bool>() != null ? comment["condition"].ToObject<bool>() : false, |
69 |
createdBy = comment["createdBy"]?.ToObject<string>(), |
70 |
createdByName = comment["createdByName"]?.ToObject<string>(), |
71 |
}); |
72 |
} |
73 |
} |
74 |
|
75 |
result.Add(new Requirement |
76 |
{ |
77 |
mdId = item["mdId"]?.ToObject<string>(), |
78 |
mdText = item["mdText"]?.ToObject<string>(), |
79 |
MrComments = new List<MrCommant>(), |
80 |
VpComments = VpComments |
81 |
}); |
82 |
|
83 |
|
84 |
} |
85 |
} |
86 |
} |
87 |
catch (Exception ex) |
88 |
{ |
89 |
throw new Exception("GetRequirementItems",ex); |
90 |
} |
91 |
|
92 |
return result; |
93 |
} |
94 |
|
95 |
/// <summary> |
96 |
/// 정합성 코멘트 등록 |
97 |
/// </summary> |
98 |
/// <param name="pId">프로젝트 ID</param> |
99 |
/// <param name="dId">Document ID</param> |
100 |
/// <param name="mdId">MR 상세 아이템 ID</param> |
101 |
/// <param name="commentId"></param> |
102 |
/// <param name="comment"></param> |
103 |
/// <param name="condition"></param> |
104 |
/// <param name="uId"></param> |
105 |
/// <returns></returns> |
106 |
public bool SetRequirementComment(string pId, string dId,string mdId, string commentId,string comment,bool condition,string uId) |
107 |
{ |
108 |
bool result = false; |
109 |
|
110 |
try |
111 |
{ |
112 |
//http://pemss.i-on.net/rest/ext/comment/requirement?dId=116&mdId=MD0000000352&commentId=1&comment=test&condition=true&uId=admin |
113 |
|
114 |
var values = new NameValueCollection(){ |
115 |
{ "dId",dId}, |
116 |
{ "mdId", mdId}, |
117 |
{ "commentId" , commentId}, |
118 |
{ "comment" ,comment}, |
119 |
{ "condition" ,condition.ToString()}, |
120 |
{ "uId", uId} |
121 |
}; |
122 |
|
123 |
var jsonObj = SetWebClientString($"{gPemssUri}/rest/ext/comment/requirement", values); |
124 |
//var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/comment/requirement?" |
125 |
// + $"dId={dId}&mdId={mdId}&commentId={commentId}&comment={comment}&condition={condition}&uId={uId}"); |
126 |
|
127 |
if (jsonObj != null) |
128 |
{ |
129 |
JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
130 |
|
131 |
if (jObject.Property("status") != null) |
132 |
{ |
133 |
result = jObject.Property("status").ToObject<bool>(); |
134 |
} |
135 |
} |
136 |
} |
137 |
catch (Exception ex) |
138 |
{ |
139 |
throw new Exception("SetRequirementComment", ex); |
140 |
} |
141 |
|
142 |
return result; |
143 |
} |
144 |
|
145 |
/// <summary> |
146 |
/// 정합성 코멘트 삭제 |
147 |
/// </summary> |
148 |
/// <param name="pId">프로젝트 ID</param> |
149 |
/// <param name="dId">Document ID</param> |
150 |
/// <param name="mrId">MR 상세 아이템 ID</param> |
151 |
/// <param name="commentId"></param> |
152 |
/// <param name="uId"></param> |
153 |
/// <returns></returns> |
154 |
public bool RemoveRequirementComment(string pId, string dId, string mdId, string commentId, string uId) |
155 |
{ |
156 |
bool result = false; |
157 |
|
158 |
try |
159 |
{ |
160 |
//http://pemss.i-on.net/rest/ext/comment/requirement?dId=116&mdId=MD0000000352&commentId=1&uId=유저아이디 |
161 |
|
162 |
var values = new NameValueCollection(){ |
163 |
{ "pId",pId}, |
164 |
{ "dId",dId}, |
165 |
{ "mdId", mdId}, |
166 |
{ "commentId" , commentId}, |
167 |
{ "uId", uId} |
168 |
}; |
169 |
|
170 |
//var jsonObj = DeleteWebClientString($"{gPemssUri}/rest/ext/comment/requirement",values); |
171 |
var jsonObj = DeleteWebClientString($"{gPemssUri}/rest/ext/comment/requirement?dId={dId}&mdId={mdId}&commentId={commentId}&uId={uId}", values); |
172 |
// + $"dId={dId}&mdId={mdId}&commentId={commentId}&uId={uId}", values); |
173 |
|
174 |
// var jsonObj = DeleteWebClientString($"{gPemssUri}/rest/ext/comment/requirement", values); |
175 |
|
176 |
if (jsonObj != null) |
177 |
{ |
178 |
JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
179 |
|
180 |
if (jObject.Property("status") != null) |
181 |
{ |
182 |
result = jObject.Property("status").ToObject<bool>(); |
183 |
} |
184 |
} |
185 |
} |
186 |
catch (Exception ex) |
187 |
{ |
188 |
throw new Exception("RemoveRequirementComment", ex); |
189 |
} |
190 |
|
191 |
return result; |
192 |
} |
193 |
|
194 |
#endregion |
195 |
|
196 |
#region Bidders |
197 |
|
198 |
/// <summary> |
199 |
/// Bidders 목록 |
200 |
/// </summary> |
201 |
/// <param name="pId">프로젝트 ID</param> |
202 |
/// <param name="dId">Document ID</param> |
203 |
/// <returns></returns> |
204 |
public List<Bidders> GetBiddesItems(string pId, string dId) |
205 |
{ |
206 |
List<Bidders> result = new List<Bidders>(); |
207 |
|
208 |
try |
209 |
{ |
210 |
var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/list/bidders?pId={pId}&dId={dId}"); |
211 |
|
212 |
if (jsonObj != null) |
213 |
{ |
214 |
JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
215 |
|
216 |
foreach (var item in JArray.Parse(jObject["rows"].ToString())) |
217 |
{ |
218 |
List<VpCommant> VpComments = new List<VpCommant>(); |
219 |
|
220 |
if (item["vpComments"].HasValues) |
221 |
{ |
222 |
var comments = JArray.Parse(item["vpComments"].ToString()); |
223 |
|
224 |
foreach (var comment in comments) |
225 |
{ |
226 |
VpComments.Add(new VpCommant |
227 |
{ |
228 |
mdId = item["mdId"]?.ToObject<string>(), |
229 |
created = comment["created"]?.ToObject<string>(), |
230 |
comment = comment["comment"]?.ToObject<string>(), |
231 |
commentId = comment["commentId"]?.ToObject<string>(), |
232 |
condition = comment["condition"]?.ToObject<bool>() != null ? comment["condition"].ToObject<bool>() : false, |
233 |
createdBy = comment["createdBy"]?.ToObject<string>(), |
234 |
createdByName = comment["createdByName"]?.ToObject<string>(), |
235 |
}); |
236 |
} |
237 |
} |
238 |
|
239 |
result.Add(new Bidders |
240 |
{ |
241 |
//mdId = item["mdId"]?.ToObject<string>(), |
242 |
bdId = item["bdId"]?.ToObject<string>(), |
243 |
description1 = item["description1"]?.ToObject<string>(), |
244 |
dId = item["dId"]?.ToObject<string>(), |
245 |
docName = item["docName"]?.ToObject<string>(), |
246 |
equipmentName = item["equipmentName"]?.ToObject<string>(), |
247 |
name = item["name"]?.ToObject<string>(), |
248 |
no = item["no"]?.ToObject<string>(), |
249 |
orderNo = item["orderNo"]?.ToObject<string>(), |
250 |
trace = item["trace"]?.ToObject<string>(), |
251 |
unit = item["unit"]?.ToObject<string>(), |
252 |
attachmentType = item["attachmentType"]?.ToObject<string>(), |
253 |
|
254 |
MrComments = new List<MrCommant>(), |
255 |
VpComments = VpComments |
256 |
}); |
257 |
|
258 |
|
259 |
} |
260 |
} |
261 |
} |
262 |
catch (Exception ex) |
263 |
{ |
264 |
throw new Exception("GetBiddesItems", ex); |
265 |
} |
266 |
|
267 |
return result; |
268 |
} |
269 |
|
270 |
/// <summary> |
271 |
/// Biddes 코멘트 등록 |
272 |
/// </summary> |
273 |
/// <param name="pId">프로젝트 ID</param> |
274 |
/// <param name="dId">Document ID</param> |
275 |
/// <param name="bdId">Bidders ID</param> |
276 |
/// <param name="commentId"></param> |
277 |
/// <param name="comment"></param> |
278 |
/// <param name="condition"></param> |
279 |
/// <param name="uId"></param> |
280 |
/// <returns></returns> |
281 |
public bool SetBiddersComment(string pId, string dId, string bdId, string commentId, string comment, bool condition, string uId) |
282 |
{ |
283 |
bool result = false; |
284 |
|
285 |
try |
286 |
{ |
287 |
//http://pemss.i-on.net/rest/ext/comment/requirement?dId=116&mdId=MD0000000352&commentId=1&comment=test&condition=true&uId=admin |
288 |
|
289 |
var values = new NameValueCollection(){ |
290 |
{ "dId",dId}, |
291 |
{ "bdId", bdId}, |
292 |
{ "commentId" , commentId}, |
293 |
{ "comment" ,comment}, |
294 |
{ "condition" ,condition.ToString()}, |
295 |
{ "uId", uId} |
296 |
}; |
297 |
|
298 |
var jsonObj = SetWebClientString($"{gPemssUri}/rest/ext/comment/bidders", values); |
299 |
|
300 |
if (jsonObj != null) |
301 |
{ |
302 |
JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
303 |
|
304 |
if (jObject.Property("status") != null) |
305 |
{ |
306 |
result = jObject.Property("status").ToObject<bool>(); |
307 |
} |
308 |
} |
309 |
} |
310 |
catch (Exception ex) |
311 |
{ |
312 |
throw new Exception("SetBiddersComment", ex); |
313 |
} |
314 |
|
315 |
return result; |
316 |
} |
317 |
|
318 |
/// <summary> |
319 |
/// Bidders 코멘트 삭제 |
320 |
/// </summary> |
321 |
/// <param name="pId">프로젝트 ID</param> |
322 |
/// <param name="dId">Document ID</param> |
323 |
/// <param name="bdId">Bidders ID</param> |
324 |
/// <param name="commentId"></param> |
325 |
/// <param name="uId"></param> |
326 |
/// <returns></returns> |
327 |
public bool RemoveBiddersComment(string pId, string dId, string bdId, string commentId, string uId) |
328 |
{ |
329 |
bool result = false; |
330 |
|
331 |
try |
332 |
{ |
333 |
var values = new NameValueCollection(){ |
334 |
{ "pId",pId}, |
335 |
{ "dId",dId}, |
336 |
{ "bdId", bdId}, |
337 |
{ "commentId" , commentId}, |
338 |
{ "uId", uId} |
339 |
}; |
340 |
|
341 |
var jsonObj = DeleteWebClientString($"{gPemssUri}/rest/ext/comment/bidders?dId={dId}&bdid={bdId}&commentId={commentId}&uId={uId}", values); |
342 |
|
343 |
if (jsonObj != null) |
344 |
{ |
345 |
JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
346 |
|
347 |
if (jObject.Property("status") != null) |
348 |
{ |
349 |
result = jObject.Property("status").ToObject<bool>(); |
350 |
} |
351 |
} |
352 |
} |
353 |
catch (Exception ex) |
354 |
{ |
355 |
throw new Exception("RemoveBiddersComment", ex); |
356 |
} |
357 |
|
358 |
return result; |
359 |
} |
360 |
|
361 |
#endregion |
362 |
|
363 |
#region 기타 정보 |
364 |
|
365 |
/// <summary> |
366 |
/// 문서 정보 |
367 |
/// </summary> |
368 |
/// <param name="pId">프로젝트 ID</param> |
369 |
/// <param name="dId">Document ID</param> |
370 |
/// <returns></returns> |
371 |
public DocumentInfo GetDocumentInfo(string pId, string dId) |
372 |
{ |
373 |
DocumentInfo result = null; |
374 |
|
375 |
try |
376 |
{ |
377 |
var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/docinfo?pId={pId}&dId={dId}"); |
378 |
|
379 |
if (jsonObj != null) |
380 |
{ |
381 |
JObject jObject = JObject.Parse(jsonObj, new JsonLoadSettings()); |
382 |
|
383 |
result = new DocumentInfo |
384 |
{ |
385 |
slipNo = jObject.Property("slipNo")?.Value?.ToString(), |
386 |
dId = jObject.Property("dId")?.ToObject<int>() != null ? jObject.Property("dId").ToObject<int>() : -1, |
387 |
docName = jObject.Property("docName")?.Value?.ToString(), |
388 |
fileName = jObject.Property("fileName")?.Value?.ToString(), |
389 |
revision = jObject.Property("revision")?.Value?.ToString() |
390 |
}; |
391 |
} |
392 |
} |
393 |
catch (Exception ex) |
394 |
{ |
395 |
throw new Exception("GetDocumentInfo",ex); |
396 |
} |
397 |
|
398 |
return result; |
399 |
} |
400 |
|
401 |
/// <summary> |
402 |
/// 사용자 정보 목록 |
403 |
/// </summary> |
404 |
/// <param name="pId">프로젝트 ID</param> |
405 |
/// <param name="dId">Document ID</param> |
406 |
/// <returns></returns> |
407 |
public List<UserInfo> GetUserInfoItems(IEnumerable<string> userIdList) |
408 |
{ |
409 |
List<UserInfo> result = new List<UserInfo>(); |
410 |
|
411 |
try |
412 |
{ |
413 |
/// uIds=U00000000006&uIds=U00000000005 |
414 |
string param = string.Join("&",userIdList.Select(x => $"uIds={x}")); |
415 |
|
416 |
var jsonObj = GetWebClientString($"{gPemssUri}/rest/ext/userinfo?{param}"); |
417 |
|
418 |
if (jsonObj != null) |
419 |
{ |
420 |
JArray array = JArray.Parse(jsonObj, new JsonLoadSettings()); |
421 |
|
422 |
foreach (var item in array) |
423 |
{ |
424 |
result.Add(new UserInfo |
425 |
{ |
426 |
name = item["name"]?.ToObject<string>(), |
427 |
email = item["email"]?.ToObject<string>(), |
428 |
deptCode = item["deptCode"]?.ToObject<string>(), |
429 |
deptName = item["deptName"]?.ToObject<string>() |
430 |
}); |
431 |
} |
432 |
} |
433 |
} |
434 |
catch (Exception ex) |
435 |
{ |
436 |
throw new Exception("GetUserInfoItems", ex); |
437 |
} |
438 |
|
439 |
return result; |
440 |
} |
441 |
|
442 |
#endregion |
443 |
|
444 |
#region API 연결 |
445 |
|
446 |
public string GetWebClientString(string uri) |
447 |
{ |
448 |
try |
449 |
{ |
450 |
using (System.Net.WebClient client = new System.Net.WebClient { Encoding = System.Text.Encoding.UTF8 }) |
451 |
{ |
452 |
var result = client.DownloadString(uri); |
453 |
|
454 |
if (string.IsNullOrWhiteSpace(result.Replace("{", "").Replace("}", ""))) |
455 |
{ |
456 |
return null; |
457 |
} |
458 |
else |
459 |
{ |
460 |
return result; |
461 |
} |
462 |
} |
463 |
} |
464 |
catch (Exception ex) |
465 |
{ |
466 |
return null; |
467 |
} |
468 |
} |
469 |
|
470 |
public string SetWebClientString(string uri, NameValueCollection valus) |
471 |
{ |
472 |
try |
473 |
{ |
474 |
using (System.Net.WebClient client = new System.Net.WebClient { Encoding = System.Text.Encoding.UTF8 }) |
475 |
{ |
476 |
var response = client.UploadValues(uri,valus); |
477 |
|
478 |
var result = System.Text.Encoding.UTF8.GetString(response); |
479 |
|
480 |
if (string.IsNullOrWhiteSpace(result.Replace("{", "").Replace("}", ""))) |
481 |
{ |
482 |
return null; |
483 |
} |
484 |
else |
485 |
{ |
486 |
return result; |
487 |
} |
488 |
} |
489 |
} |
490 |
catch (Exception ex) |
491 |
{ |
492 |
return null; |
493 |
} |
494 |
} |
495 |
|
496 |
private string DeleteWebClientString(string RestApi, NameValueCollection valus) |
497 |
{ |
498 |
try |
499 |
{ |
500 |
|
501 |
using (System.Net.WebClient client = new System.Net.WebClient { Encoding = System.Text.Encoding.UTF8 }) |
502 |
{ |
503 |
var response = client.UploadValues(RestApi, "DELETE", valus); |
504 |
var result = System.Text.Encoding.UTF8.GetString(response); |
505 |
|
506 |
if (string.IsNullOrWhiteSpace(result.Replace("{", "").Replace("}", ""))) |
507 |
{ |
508 |
return null; |
509 |
} |
510 |
else |
511 |
{ |
512 |
return result; |
513 |
} |
514 |
} |
515 |
} |
516 |
catch (Exception ex) |
517 |
{ |
518 |
return null; |
519 |
} |
520 |
} |
521 |
|
522 |
#endregion |
523 |
} |
524 |
} |