hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 993feace
이력 | 보기 | 이력해설 | 다운로드 (33.9 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
|
7 |
using System.Data; |
8 |
|
9 |
using ID2.Manager.Data.Models; |
10 |
|
11 |
using Dapper; |
12 |
using System.ComponentModel; |
13 |
using System.Reflection; |
14 |
|
15 |
namespace ID2.Manager.Dapper.Repository |
16 |
{ |
17 |
public class DocumentRepository : BaseRepository |
18 |
{ |
19 |
public DocumentRepository(string connectionStr) : base(connectionStr) { } |
20 |
|
21 |
public IEnumerable<Documents> GetAllDocuments(string projectGroupID) |
22 |
{ |
23 |
var dynamicParameters = new DynamicParameters(); |
24 |
StringBuilder sbWhere = new StringBuilder(); |
25 |
var parameters = new Dictionary<string, object>(); |
26 |
if (!string.IsNullOrEmpty(projectGroupID)) |
27 |
{ |
28 |
sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) "); |
29 |
parameters.Add("RefGroupID", projectGroupID); |
30 |
} |
31 |
|
32 |
try |
33 |
{ |
34 |
string query = $@" |
35 |
select doc.* |
36 |
from dbo.Documents doc |
37 |
where doc.IsDeleted=0 {sbWhere} |
38 |
order by doc.Seq;"; |
39 |
|
40 |
if (parameters.Count > 0) |
41 |
{ |
42 |
dynamicParameters.AddDynamicParams(parameters); |
43 |
} |
44 |
|
45 |
return Query<Documents>(query, dynamicParameters); |
46 |
} |
47 |
catch (Exception ex) |
48 |
{ |
49 |
throw ex; |
50 |
} |
51 |
} |
52 |
static string GetDescriptionFromAttribute(MemberInfo member) |
53 |
{ |
54 |
if (member == null) return null; |
55 |
|
56 |
var attrib = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(DescriptionAttribute), false); |
57 |
return (attrib?.Description ?? member.Name).ToLower(); |
58 |
} |
59 |
|
60 |
|
61 |
public (IEnumerable<Documents> dwgs, int totalCnt) GetDocuments(string projectGroupID, List<string> dateTypes, DateTime? frDate, DateTime? toDate, string projectCode, string personIncharge, string jobLevel, string documentNo, string isToIsDiscussion, string isFrReviewStatus, string id2Status, string id2Issues, string avevaStatus, string avevaIssues, string prodIsResult, string clientIsResult, string isGateWay, string isRegSystem) |
62 |
{ |
63 |
var map = new CustomPropertyTypeMap(typeof(AttFileInfo), (type, columnName) |
64 |
=> type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName.ToLower())); |
65 |
SqlMapper.SetTypeMap(typeof(AttFileInfo), map); |
66 |
|
67 |
|
68 |
var dynamicParameters = new DynamicParameters(); |
69 |
dynamicParameters.Add("Total", dbType: DbType.Int32, direction: ParameterDirection.Output); |
70 |
|
71 |
StringBuilder sbWhere = new StringBuilder(); |
72 |
StringBuilder sbTotalWhere = new StringBuilder(); |
73 |
var parameters = new Dictionary<string, object>(); |
74 |
if (dateTypes.Count > 0 && (frDate != null || toDate != null)) |
75 |
{ |
76 |
List<string> subWheres = new List<string>(); |
77 |
foreach (string dateType in dateTypes) |
78 |
{ |
79 |
StringBuilder sbSubWhere = new StringBuilder(); |
80 |
if (frDate != null) |
81 |
{ |
82 |
sbSubWhere.Insert(0, $@"convert(datetime, '{Convert.ToDateTime(frDate).AddDays(-1):yyyy-MM-dd 23:59:59.997}') < doc.{dateType}"); |
83 |
} |
84 |
if (toDate != null) |
85 |
{ |
86 |
if (frDate != null) |
87 |
sbSubWhere.Append($@" and "); |
88 |
sbSubWhere.Append($@"doc.{dateType} < convert(datetime, '{Convert.ToDateTime(toDate).AddDays(1):yyyy-MM-dd 00:00:00.000}')"); |
89 |
} |
90 |
|
91 |
if (sbSubWhere.Length > 0) |
92 |
{ |
93 |
subWheres.Add("(" + sbSubWhere.ToString() + ")"); |
94 |
} |
95 |
} |
96 |
|
97 |
if (subWheres.Count > 0) |
98 |
{ |
99 |
sbWhere.Append(" and (" + string.Join(" or ", subWheres) + ") "); |
100 |
} |
101 |
} |
102 |
if (string.IsNullOrEmpty(projectCode)) |
103 |
{ |
104 |
sbWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') "); |
105 |
sbTotalWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') "); |
106 |
parameters.Add("RefGroupID", projectGroupID); |
107 |
} |
108 |
else |
109 |
{ |
110 |
sbTotalWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') "); |
111 |
parameters.Add("RefGroupID", projectGroupID); |
112 |
|
113 |
sbWhere.Append(" and doc.RefProjectCode=@RefProjectCode "); |
114 |
parameters.Add("RefProjectCode", projectCode); |
115 |
} |
116 |
if (!string.IsNullOrEmpty(personIncharge)) |
117 |
{ |
118 |
sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge "); |
119 |
parameters.Add("PersonInCharge", personIncharge); |
120 |
} |
121 |
if (!string.IsNullOrEmpty(jobLevel)) |
122 |
{ |
123 |
sbWhere.Append(" and doc.JobLevel=@JobLevel "); |
124 |
parameters.Add("JobLevel", jobLevel); |
125 |
} |
126 |
if (!string.IsNullOrEmpty(documentNo)) |
127 |
{ |
128 |
sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' "); |
129 |
parameters.Add("DocumentNo", documentNo); |
130 |
} |
131 |
|
132 |
if (!string.IsNullOrEmpty(isToIsDiscussion)) |
133 |
{ |
134 |
sbWhere.Append(" and doc.ToIsDiscussion=@ToIsDiscussion "); |
135 |
parameters.Add("ToIsDiscussion", isToIsDiscussion); |
136 |
} |
137 |
|
138 |
if (!string.IsNullOrEmpty(isFrReviewStatus)) |
139 |
{ |
140 |
sbWhere.Append(" and doc.FrReviewStatus=@FrReviewStatus "); |
141 |
parameters.Add("FrReviewStatus", isFrReviewStatus); |
142 |
} |
143 |
|
144 |
if (!string.IsNullOrEmpty(id2Status)) |
145 |
{ |
146 |
sbWhere.Append(" and doc.ID2Status=@ID2Status "); |
147 |
parameters.Add("ID2Status", id2Status); |
148 |
} |
149 |
|
150 |
if (!string.IsNullOrEmpty(id2Issues)) |
151 |
{ |
152 |
sbWhere.Append(" and (case when isnull(ltrim(rtrim(doc.ID2Issues)),'') = '' then 'No' else 'Yes' end)=@ID2Issues "); |
153 |
parameters.Add("ID2Issues", id2Issues); |
154 |
} |
155 |
|
156 |
if (!string.IsNullOrEmpty(avevaStatus)) |
157 |
{ |
158 |
sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus "); |
159 |
parameters.Add("AVEVAStatus", avevaStatus); |
160 |
} |
161 |
|
162 |
if (!string.IsNullOrEmpty(avevaIssues)) |
163 |
{ |
164 |
sbWhere.Append(" and (case when isnull(ltrim(rtrim(doc.AVEVAIssues)),'') = '' then 'No' else 'Yes' end)=@AVEVAIssues "); |
165 |
parameters.Add("AVEVAIssues", avevaIssues); |
166 |
} |
167 |
|
168 |
if (!string.IsNullOrEmpty(prodIsResult)) |
169 |
{ |
170 |
sbWhere.Append(" and doc.ProdIsResult=@ProdIsResult "); |
171 |
parameters.Add("ProdIsResult", prodIsResult); |
172 |
} |
173 |
if (!string.IsNullOrEmpty(clientIsResult)) |
174 |
{ |
175 |
sbWhere.Append(" and doc.ClientIsResult=@ClientIsResult "); |
176 |
parameters.Add("ClientIsResult", clientIsResult); |
177 |
} |
178 |
if (!string.IsNullOrEmpty(isGateWay)) |
179 |
{ |
180 |
sbWhere.Append(" and doc.DTIsGateWay=@DTIsGateWay "); |
181 |
parameters.Add("DTIsGateWay", isGateWay); |
182 |
} |
183 |
if (!string.IsNullOrEmpty(isRegSystem)) |
184 |
{ |
185 |
sbWhere.Append(" and doc.DTIsRegSystem=@DTIsRegSystem "); |
186 |
parameters.Add("DTIsRegSystem", isRegSystem); |
187 |
} |
188 |
|
189 |
try |
190 |
{ |
191 |
|
192 |
//files.[FileID],files.[FileID] as AttFileID, files.RefID, files.Category, files.FileType, files.FileName, files.FilePath, files.FileExtension, files.FileData, files.Remark, files.CreatedDate, files.Creator, |
193 |
string query = $@" |
194 |
select doc.*, |
195 |
files.[FileID] as FileID, files.*, |
196 |
markus.PROJECT_NO as PROJECT_NO, markus.* |
197 |
from dbo.Documents doc |
198 |
LEFT OUTER JOIN AttachFIles files ON doc.DocID = fIles.RefID |
199 |
LEFT OUTER JOIN |
200 |
(SELECT [PROJECT_NO] as PROJECT_NO |
201 |
,[DOCUMENT_ID] as DocumentNo |
202 |
|
203 |
,[PAGENUMBER] |
204 |
,[Text] as TEXT |
205 |
,[CREATE_DATE] as CREATE_DATE |
206 |
,[NAME] as CREATE_USER |
207 |
FROM ViewMarkupData) markus |
208 |
ON doc.DocumentNo = markus.DocumentNo |
209 |
where doc.IsDeleted=0 {sbWhere} |
210 |
order by doc.Seq |
211 |
|
212 |
select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere} |
213 |
select @Total;"; |
214 |
|
215 |
if (parameters.Count > 0) |
216 |
{ |
217 |
dynamicParameters.AddDynamicParams(parameters); |
218 |
} |
219 |
|
220 |
var docDictionary = new Dictionary<string, Documents>(); |
221 |
|
222 |
var ret = MultiQuery<Documents, AttFileInfo, MarkupText, Documents>(query, |
223 |
(document, attfile, markusText) => |
224 |
{ |
225 |
Documents doc; |
226 |
|
227 |
if (!docDictionary.TryGetValue(document.DocID, out doc)) |
228 |
{ |
229 |
doc = document; |
230 |
docDictionary.Add(doc.DocID, doc); |
231 |
} |
232 |
|
233 |
if (markusText != null) |
234 |
{ |
235 |
doc.Markups = doc.Markups ?? new List<MarkupText>(); |
236 |
|
237 |
if (!doc.Markups.Any(x => x.Equals(markusText))) |
238 |
{ |
239 |
doc.Markups.Add(markusText); |
240 |
} |
241 |
} |
242 |
|
243 |
if (attfile != null) |
244 |
{ |
245 |
doc.AttFiles = doc.AttFiles ?? new List<AttFileInfo>(); |
246 |
System.Diagnostics.Debug.WriteLine(attfile.FileName); |
247 |
if (!doc.AttFiles.Any(x => x.FileID == attfile.FileID)) |
248 |
{ |
249 |
switch (attfile.Category) |
250 |
{ |
251 |
case "toreview": |
252 |
doc.ToCapture++; |
253 |
break; |
254 |
case "frreview": |
255 |
doc.FrCapture++; |
256 |
break; |
257 |
//case "prodvalidation": |
258 |
// doc.ProdCapture++; |
259 |
// break; |
260 |
//case "clientvalidation": |
261 |
// doc.ClientCapture++; |
262 |
// break; |
263 |
case "id2work": |
264 |
doc.ID2Capture++; |
265 |
break; |
266 |
} |
267 |
|
268 |
doc.AttFiles.Add(attfile); |
269 |
} |
270 |
} |
271 |
|
272 |
return doc; |
273 |
|
274 |
}, dynamicParameters, splitOn: "DocID,FileID,PROJECT_NO").Distinct(); |
275 |
|
276 |
int totalCount = dynamicParameters.Get<int>("Total"); |
277 |
|
278 |
return (ret, totalCount); |
279 |
} |
280 |
catch (Exception ex) |
281 |
{ |
282 |
throw ex; |
283 |
} |
284 |
} |
285 |
|
286 |
public int ExistsDocument(string projectGroupID, List<string> newDwgNos) |
287 |
{ |
288 |
int existCount = 0; |
289 |
|
290 |
int paramMaxCount = 2000; |
291 |
int execCount = (newDwgNos.Count / paramMaxCount) + 1; |
292 |
|
293 |
for (int i = 0; i < execCount; i++) |
294 |
{ |
295 |
var dynamicParameters = new DynamicParameters(); |
296 |
StringBuilder sbWhere = new StringBuilder(); |
297 |
var parameters = new Dictionary<string, object>(); |
298 |
if (!string.IsNullOrEmpty(projectGroupID)) |
299 |
{ |
300 |
sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) "); |
301 |
parameters.Add("RefGroupID", projectGroupID); |
302 |
} |
303 |
|
304 |
var limitDwgNos = newDwgNos.Skip(paramMaxCount * i).Take(paramMaxCount).ToList(); |
305 |
sbWhere.Append($@" and doc.DocumentNo in @limitDwgNos "); |
306 |
parameters.Add("limitDwgNos", limitDwgNos); |
307 |
|
308 |
try |
309 |
{ |
310 |
string query = $@" |
311 |
select count(*) cnt |
312 |
from dbo.Documents doc |
313 |
where doc.IsDeleted=0 {sbWhere}"; |
314 |
|
315 |
if (parameters.Count > 0) |
316 |
{ |
317 |
dynamicParameters.AddDynamicParams(parameters); |
318 |
} |
319 |
|
320 |
existCount += ExecuteScalar<int>(query, dynamicParameters); |
321 |
} |
322 |
catch (Exception ex) |
323 |
{ |
324 |
throw ex; |
325 |
} |
326 |
} |
327 |
|
328 |
return existCount; |
329 |
} |
330 |
|
331 |
public bool SetDocumentData(string projectGroupID, List<Documents> docList, List<Documents> delDocList, string userId) |
332 |
{ |
333 |
bool isSuccess = false; |
334 |
|
335 |
try |
336 |
{ |
337 |
|
338 |
#region merge 주석처리 |
339 |
/* |
340 |
{ |
341 |
docList.ForEach(x => |
342 |
{ |
343 |
x.RegisteredUser = userId; |
344 |
x.ModifiedUser = userId; |
345 |
}); |
346 |
string query = $@" |
347 |
merge into dbo.Documents as tg |
348 |
using |
349 |
( |
350 |
values |
351 |
( |
352 |
@DocumentNo |
353 |
,@RevisonNo |
354 |
,@System |
355 |
,@SubSystemCode |
356 |
,@RefProjectCode |
357 |
,@JobLevel |
358 |
,@PersonInCharge |
359 |
,@RegisteredUser |
360 |
,@ModifiedUser |
361 |
,@ToIsDiscussion |
362 |
,@ToRemarks |
363 |
,@ToCreator |
364 |
,@FrReviewStatus |
365 |
,@FrRemarks |
366 |
,@FrCreator |
367 |
,@ID2StartDate |
368 |
,@ID2EndDate |
369 |
,@ID2Status |
370 |
,@ID2Issues |
371 |
,@ReplyModifications |
372 |
,@ReplyRequester |
373 |
,@IsConvert |
374 |
,@AVEVAPersonInCharge |
375 |
,@AVEVAWorker |
376 |
,@AVEVAConvertDate |
377 |
,@AVEVAReviewDate |
378 |
,@AVEVAWorkDate |
379 |
,@AVEVAStatus |
380 |
,@AVEVAIssues |
381 |
,@ProdReviewer |
382 |
,@ProdIsResult |
383 |
,@ProdRemarks |
384 |
,@ClientReviewer |
385 |
,@ClientIsResult |
386 |
,@ClientRemarks |
387 |
,@DTIsGateWay |
388 |
,@DTIsImport |
389 |
,@DTIsRegSystem |
390 |
,@DTRemarks |
391 |
) |
392 |
) as sc |
393 |
( |
394 |
DocumentNo |
395 |
,RevisonNo |
396 |
,[System] |
397 |
,SubSystemCode |
398 |
,RefProjectCode |
399 |
,JobLevel |
400 |
,PersonInCharge |
401 |
,RegisteredUser |
402 |
,ModifiedUser |
403 |
,ToIsDiscussion |
404 |
,ToRemarks |
405 |
,ToCreator |
406 |
,FrReviewStatus |
407 |
,FrRemarks |
408 |
,FrCreator |
409 |
,ID2StartDate |
410 |
,ID2EndDate |
411 |
,ID2Status |
412 |
,ID2Issues |
413 |
,ReplyModifications |
414 |
,ReplyRequester |
415 |
,IsConvert |
416 |
,AVEVAPersonInCharge |
417 |
,AVEVAWorker |
418 |
,AVEVAConvertDate |
419 |
,AVEVAReviewDate |
420 |
,AVEVAWorkDate |
421 |
,AVEVAStatus |
422 |
,AVEVAIssues |
423 |
,ProdReviewer |
424 |
,ProdIsResult |
425 |
,ProdRemarks |
426 |
,ClientReviewer |
427 |
,ClientIsResult |
428 |
,ClientRemarks |
429 |
,DTIsGateWay |
430 |
,DTIsImport |
431 |
,DTIsRegSystem |
432 |
,DTRemarks |
433 |
) |
434 |
ON sc.DocumentNo=tg.DocumentNo |
435 |
when matched and tg.IsDeleted=0 then |
436 |
|
437 |
update |
438 |
set tg.DocumentNo=sc.DocumentNo |
439 |
,tg.RevisonNo=sc.RevisonNo |
440 |
,tg.[System]=sc.[System] |
441 |
,tg.SubSystemCode=sc.SubSystemCode |
442 |
,tg.RefProjectCode=sc.RefProjectCode |
443 |
,tg.JobLevel=sc.JobLevel |
444 |
,tg.PersonInCharge=sc.PersonInCharge |
445 |
,tg.ModifiedDate=getdate() |
446 |
,tg.ModifiedUser=sc.ModifiedUser |
447 |
,tg.ToIsDiscussion=sc.ToIsDiscussion |
448 |
,tg.ToRemarks=sc.ToRemarks |
449 |
,tg.ToCreator=sc.ToCreator |
450 |
,tg.FrReviewStatus=sc.FrReviewStatus |
451 |
,tg.FrRemarks=sc.FrRemarks |
452 |
,tg.FrCreator=sc.FrCreator |
453 |
,tg.ID2StartDate=sc.ID2StartDate |
454 |
,tg.ID2EndDate=sc.ID2EndDate |
455 |
,tg.ID2Status=sc.ID2Status |
456 |
,tg.ID2Issues=sc.ID2Issues |
457 |
,tg.ReplyModifications=sc.ReplyModifications |
458 |
,tg.ReplyRequester=sc.ReplyRequester |
459 |
,tg.IsConvert=sc.IsConvert |
460 |
,tg.AVEVAPersonInCharge=sc.AVEVAPersonInCharge |
461 |
,tg.AVEVAWorker=sc.AVEVAWorker |
462 |
,tg.AVEVAConvertDate=sc.AVEVAConvertDate |
463 |
,tg.AVEVAReviewDate=sc.AVEVAReviewDate |
464 |
,tg.AVEVAWorkDate=sc.AVEVAWorkDate |
465 |
,tg.AVEVAStatus=sc.AVEVAStatus |
466 |
,tg.AVEVAIssues=sc.AVEVAIssues |
467 |
,tg.ProdReviewer=sc.ProdReviewer |
468 |
,tg.ProdIsResult=sc.ProdIsResult |
469 |
,tg.ProdRemarks=sc.ProdRemarks |
470 |
,tg.ClientReviewer=sc.ClientReviewer |
471 |
,tg.ClientIsResult=sc.ClientIsResult |
472 |
,tg.ClientRemarks=sc.ClientRemarks |
473 |
,tg.DTIsGateWay=sc.DTIsGateWay |
474 |
,tg.DTIsImport=sc.DTIsImport |
475 |
,tg.DTIsRegSystem=sc.DTIsRegSystem |
476 |
,tg.DTRemarks=sc.DTRemarks |
477 |
when not matched then |
478 |
|
479 |
|
480 |
insert |
481 |
( |
482 |
DocID |
483 |
,DocumentNo |
484 |
,RevisonNo |
485 |
,[System] |
486 |
,SubSystemCode |
487 |
,RefProjectCode |
488 |
,JobLevel |
489 |
,PersonInCharge |
490 |
,RegisteredDate |
491 |
,RegisteredUser |
492 |
,ToIsDiscussion |
493 |
,ToRemarks |
494 |
,ToCreator |
495 |
,FrReviewStatus |
496 |
,FrRemarks |
497 |
,FrCreator |
498 |
,ID2StartDate |
499 |
,ID2EndDate |
500 |
,ID2Status |
501 |
,ID2Issues |
502 |
,ReplyModifications |
503 |
,ReplyRequester |
504 |
,IsConvert |
505 |
,AVEVAPersonInCharge |
506 |
,AVEVAWorker |
507 |
,AVEVAConvertDate |
508 |
,AVEVAReviewDate |
509 |
,AVEVAWorkDate |
510 |
,AVEVAStatus |
511 |
,AVEVAIssues |
512 |
,ProdReviewer |
513 |
,ProdIsResult |
514 |
,ProdRemarks |
515 |
,ClientReviewer |
516 |
,ClientIsResult |
517 |
,ClientRemarks |
518 |
,DTIsGateWay |
519 |
,DTIsImport |
520 |
,DTIsRegSystem |
521 |
,DTRemarks |
522 |
) |
523 |
values |
524 |
( |
525 |
lower(newid()) |
526 |
,sc.DocumentNo |
527 |
,case when isnull(sc.RevisonNo,'')='' then '0' else sc.RevisonNo end |
528 |
,sc.System |
529 |
,sc.SubSystemCode |
530 |
,sc.RefProjectCode |
531 |
,sc.JobLevel |
532 |
,sc.PersonInCharge |
533 |
,getdate() |
534 |
,sc.RegisteredUser |
535 |
,sc.ToIsDiscussion |
536 |
,sc.ToRemarks |
537 |
,sc.ToCreator |
538 |
,sc.FrReviewStatus |
539 |
,sc.FrRemarks |
540 |
,sc.FrCreator |
541 |
,sc.ID2StartDate |
542 |
,sc.ID2EndDate |
543 |
,sc.ID2Status |
544 |
,sc.ID2Issues |
545 |
,sc.ReplyModifications |
546 |
,sc.ReplyRequester |
547 |
,sc.IsConvert |
548 |
,sc.AVEVAPersonInCharge |
549 |
,sc.AVEVAWorker |
550 |
,sc.AVEVAConvertDate |
551 |
,sc.AVEVAReviewDate |
552 |
,sc.AVEVAWorkDate |
553 |
,sc.AVEVAStatus |
554 |
,sc.AVEVAIssues |
555 |
,sc.ProdReviewer |
556 |
,sc.ProdIsResult |
557 |
,sc.ProdRemarks |
558 |
,sc.ClientReviewer |
559 |
,sc.ClientIsResult |
560 |
,sc.ClientRemarks |
561 |
,sc.DTIsGateWay |
562 |
,sc.DTIsImport |
563 |
,sc.DTIsRegSystem |
564 |
,sc.DTRemarks |
565 |
) |
566 |
output $action;"; |
567 |
//base.Query QueryFirstOrDefault<string>(query, docList, transaction); |
568 |
//var test = base.Query<string>(query, docList); |
569 |
var test = base.QueryFirstOrDefault<string>(query, docList); |
570 |
} |
571 |
*/ |
572 |
#endregion |
573 |
|
574 |
using (var transaction = base.BeginTransaction()) |
575 |
{ |
576 |
string query = string.Empty; |
577 |
|
578 |
if (delDocList.Count > 0) |
579 |
{ |
580 |
int paramMaxCount = 2000; |
581 |
int execCount = (delDocList.Count / paramMaxCount) + 1; |
582 |
|
583 |
for (int i = 0; i < execCount; i++) |
584 |
{ |
585 |
var dynamicParameters = new DynamicParameters(); |
586 |
StringBuilder sbWhere = new StringBuilder(); |
587 |
var parameters = new Dictionary<string, object>(); |
588 |
|
589 |
parameters.Add("DeletedUser", userId); |
590 |
|
591 |
var limitDwgNos = delDocList.Skip(paramMaxCount * i).Take(paramMaxCount).Select(x => x.DocID).ToList(); |
592 |
sbWhere.Append($@" DocID in @limitDwgNos "); |
593 |
parameters.Add("limitDwgNos", limitDwgNos); |
594 |
|
595 |
query = $@" |
596 |
update dbo.Documents |
597 |
set IsDeleted=1 |
598 |
,DeletedDate=getdate() |
599 |
,DeletedUser=@DeletedUser |
600 |
where {sbWhere}"; |
601 |
if (parameters.Count > 0) |
602 |
{ |
603 |
dynamicParameters.AddDynamicParams(parameters); |
604 |
} |
605 |
|
606 |
base.Execute(query, dynamicParameters, transaction); |
607 |
} |
608 |
} |
609 |
|
610 |
foreach (Documents doc in docList) |
611 |
{ |
612 |
if (string.IsNullOrEmpty(doc.DocID)) |
613 |
{ |
614 |
doc.RegisteredUser = userId; |
615 |
doc.ModifiedUser = userId; |
616 |
|
617 |
query = $@" |
618 |
if exists(select * from dbo.Documents where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo) |
619 |
begin |
620 |
--update |
621 |
update dbo.Documents |
622 |
set RevisonNo=case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
623 |
,System=@System |
624 |
,SubSystemCode=@SubSystemCode |
625 |
,JobLevel=@JobLevel |
626 |
,PersonInCharge=@PersonInCharge |
627 |
,ModifiedDate=getdate() |
628 |
,ModifiedUser=@ModifiedUser |
629 |
,ToIsDiscussion=@ToIsDiscussion |
630 |
,ToRemarks=@ToRemarks |
631 |
,ToCreator=@ToCreator |
632 |
,FrReviewStatus=@FrReviewStatus |
633 |
,FrRemarks=@FrRemarks |
634 |
,FrCreator=@FrCreator |
635 |
,ID2StartDate=@ID2StartDate |
636 |
,ID2EndDate=@ID2EndDate |
637 |
,ID2Status=@ID2Status |
638 |
,ID2Issues=@ID2Issues |
639 |
,ReplyModifications=@ReplyModifications |
640 |
,ReplyRequester=@ReplyRequester |
641 |
,IsConvert=@IsConvert |
642 |
,AVEVAPersonInCharge=@AVEVAPersonInCharge |
643 |
,AVEVAWorker=@AVEVAWorker |
644 |
,AVEVAConvertDate=@AVEVAConvertDate |
645 |
,AVEVAReviewDate=@AVEVAReviewDate |
646 |
,AVEVAWorkDate=@AVEVAWorkDate |
647 |
,AVEVAStatus=@AVEVAStatus |
648 |
,AVEVAIssues=@AVEVAIssues |
649 |
,ProdReviewer=@ProdReviewer |
650 |
,ProdIsResult=@ProdIsResult |
651 |
,ProdRemarks=@ProdRemarks |
652 |
,ClientReviewer=@ClientReviewer |
653 |
,ClientIsResult=@ClientIsResult |
654 |
,ClientRemarks=@ClientRemarks |
655 |
,DTIsGateWay=@DTIsGateWay |
656 |
,DTIsImport=@DTIsImport |
657 |
,DTIsRegSystem=@DTIsRegSystem |
658 |
,DTRemarks=@DTRemarks |
659 |
where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo |
660 |
|
661 |
if @@rowcount > 0 |
662 |
begin |
663 |
select '' |
664 |
end |
665 |
else |
666 |
begin |
667 |
select '' |
668 |
end |
669 |
end |
670 |
else |
671 |
begin |
672 |
--insert |
673 |
declare @tbdoc table(docid varchar(36)) |
674 |
insert into dbo.Documents |
675 |
( |
676 |
DocID |
677 |
,DocumentNo |
678 |
,RevisonNo |
679 |
,System |
680 |
,SubSystemCode |
681 |
,RefProjectCode |
682 |
,JobLevel |
683 |
,PersonInCharge |
684 |
,RegisteredDate |
685 |
,RegisteredUser |
686 |
,ToIsDiscussion |
687 |
,ToRemarks |
688 |
,ToCreator |
689 |
,FrReviewStatus |
690 |
,FrRemarks |
691 |
,FrCreator |
692 |
,ID2StartDate |
693 |
,ID2EndDate |
694 |
,ID2Status |
695 |
,ID2Issues |
696 |
,ReplyModifications |
697 |
,ReplyRequester |
698 |
,IsConvert |
699 |
,AVEVAPersonInCharge |
700 |
,AVEVAWorker |
701 |
,AVEVAConvertDate |
702 |
,AVEVAReviewDate |
703 |
,AVEVAWorkDate |
704 |
,AVEVAStatus |
705 |
,AVEVAIssues |
706 |
,ProdReviewer |
707 |
,ProdIsResult |
708 |
,ProdRemarks |
709 |
,ClientReviewer |
710 |
,ClientIsResult |
711 |
,ClientRemarks |
712 |
,DTIsGateWay |
713 |
,DTIsImport |
714 |
,DTIsRegSystem |
715 |
,DTRemarks |
716 |
) |
717 |
output inserted.DocID into @tbdoc |
718 |
values |
719 |
( |
720 |
lower(newid()) |
721 |
,@DocumentNo |
722 |
,case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
723 |
,@System |
724 |
,@SubSystemCode |
725 |
,@RefProjectCode |
726 |
,@JobLevel |
727 |
,@PersonInCharge |
728 |
,getdate() |
729 |
,@RegisteredUser |
730 |
,@ToIsDiscussion |
731 |
,@ToRemarks |
732 |
,@ToCreator |
733 |
,@FrReviewStatus |
734 |
,@FrRemarks |
735 |
,@FrCreator |
736 |
,@ID2StartDate |
737 |
,@ID2EndDate |
738 |
,@ID2Status |
739 |
,@ID2Issues |
740 |
,@ReplyModifications |
741 |
,@ReplyRequester |
742 |
,@IsConvert |
743 |
,@AVEVAPersonInCharge |
744 |
,@AVEVAWorker |
745 |
,@AVEVAConvertDate |
746 |
,@AVEVAReviewDate |
747 |
,@AVEVAWorkDate |
748 |
,@AVEVAStatus |
749 |
,@AVEVAIssues |
750 |
,@ProdReviewer |
751 |
,@ProdIsResult |
752 |
,@ProdRemarks |
753 |
,@ClientReviewer |
754 |
,@ClientIsResult |
755 |
,@ClientRemarks |
756 |
,@DTIsGateWay |
757 |
,@DTIsImport |
758 |
,@DTIsRegSystem |
759 |
,@DTRemarks |
760 |
) |
761 |
|
762 |
if @@rowcount > 0 |
763 |
begin |
764 |
select docid from @tbdoc |
765 |
end |
766 |
else |
767 |
begin |
768 |
select '' |
769 |
end |
770 |
end"; |
771 |
#region 기존 입력 쿼리 주석 |
772 |
/* |
773 |
query = $@" |
774 |
declare @tbdoc table(docid varchar(36)) |
775 |
insert into dbo.Documents |
776 |
( |
777 |
DocID |
778 |
,DocumentNo |
779 |
,RevisonNo |
780 |
,System |
781 |
,SubSystemCode |
782 |
,RefProjectCode |
783 |
,JobLevel |
784 |
,PersonInCharge |
785 |
,RegisteredDate |
786 |
,RegisteredUser |
787 |
,ToIsDiscussion |
788 |
,ToRemarks |
789 |
,ToCreator |
790 |
,FrReviewStatus |
791 |
,FrRemarks |
792 |
,FrCreator |
793 |
,ID2StartDate |
794 |
,ID2EndDate |
795 |
,ID2Status |
796 |
,ID2Issues |
797 |
,ReplyModifications |
798 |
,ReplyRequester |
799 |
,IsConvert |
800 |
,AVEVAPersonInCharge |
801 |
,AVEVAWorker |
802 |
,AVEVAConvertDate |
803 |
,AVEVAReviewDate |
804 |
,AVEVAWorkDate |
805 |
,AVEVAStatus |
806 |
,AVEVAIssues |
807 |
,ProdReviewer |
808 |
,ProdIsResult |
809 |
,ProdRemarks |
810 |
,ClientReviewer |
811 |
,ClientIsResult |
812 |
,ClientRemarks |
813 |
,DTIsGateWay |
814 |
,DTIsImport |
815 |
,DTIsRegSystem |
816 |
,DTRemarks |
817 |
) |
818 |
output inserted.DocID into @tbdoc |
819 |
values |
820 |
( |
821 |
lower(newid()) |
822 |
,@DocumentNo |
823 |
,case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
824 |
,@System |
825 |
,@SubSystemCode |
826 |
,@RefProjectCode |
827 |
,@JobLevel |
828 |
,@PersonInCharge |
829 |
,getdate() |
830 |
,@RegisteredUser |
831 |
,@ToIsDiscussion |
832 |
,@ToRemarks |
833 |
,@ToCreator |
834 |
,@FrReviewStatus |
835 |
,@FrRemarks |
836 |
,@FrCreator |
837 |
,@ID2StartDate |
838 |
,@ID2EndDate |
839 |
,@ID2Status |
840 |
,@ID2Issues |
841 |
,@ReplyModifications |
842 |
,@ReplyRequester |
843 |
,@IsConvert |
844 |
,@AVEVAPersonInCharge |
845 |
,@AVEVAWorker |
846 |
,@AVEVAConvertDate |
847 |
,@AVEVAReviewDate |
848 |
,@AVEVAWorkDate |
849 |
,@AVEVAStatus |
850 |
,@AVEVAIssues |
851 |
,@ProdReviewer |
852 |
,@ProdIsResult |
853 |
,@ProdRemarks |
854 |
,@ClientReviewer |
855 |
,@ClientIsResult |
856 |
,@ClientRemarks |
857 |
,@DTIsGateWay |
858 |
,@DTIsImport |
859 |
,@DTIsRegSystem |
860 |
,@DTRemarks |
861 |
) |
862 |
|
863 |
if @@rowcount > 0 |
864 |
begin |
865 |
select docid from @tbdoc |
866 |
end |
867 |
else |
868 |
begin |
869 |
select '' |
870 |
end;"; |
871 |
*/ |
872 |
#endregion |
873 |
} |
874 |
else |
875 |
{ |
876 |
doc.ModifiedUser = userId; |
877 |
query = $@" |
878 |
update dbo.Documents |
879 |
set DocumentNo=@DocumentNo |
880 |
,RevisonNo=case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
881 |
,System=@System |
882 |
,SubSystemCode=@SubSystemCode |
883 |
,RefProjectCode=@RefProjectCode |
884 |
,JobLevel=@JobLevel |
885 |
,PersonInCharge=@PersonInCharge |
886 |
,ModifiedDate=getdate() |
887 |
,ModifiedUser=@ModifiedUser |
888 |
,ToIsDiscussion=@ToIsDiscussion |
889 |
,ToRemarks=@ToRemarks |
890 |
,ToCreator=@ToCreator |
891 |
,FrReviewStatus=@FrReviewStatus |
892 |
,FrRemarks=@FrRemarks |
893 |
,FrCreator=@FrCreator |
894 |
,ID2StartDate=@ID2StartDate |
895 |
,ID2EndDate=@ID2EndDate |
896 |
,ID2Status=@ID2Status |
897 |
,ID2Issues=@ID2Issues |
898 |
,ReplyModifications=@ReplyModifications |
899 |
,ReplyRequester=@ReplyRequester |
900 |
,IsConvert=@IsConvert |
901 |
,AVEVAPersonInCharge=@AVEVAPersonInCharge |
902 |
,AVEVAWorker=@AVEVAWorker |
903 |
,AVEVAConvertDate=@AVEVAConvertDate |
904 |
,AVEVAReviewDate=@AVEVAReviewDate |
905 |
,AVEVAWorkDate=@AVEVAWorkDate |
906 |
,AVEVAStatus=@AVEVAStatus |
907 |
,AVEVAIssues=@AVEVAIssues |
908 |
,ProdReviewer=@ProdReviewer |
909 |
,ProdIsResult=@ProdIsResult |
910 |
,ProdRemarks=@ProdRemarks |
911 |
,ClientReviewer=@ClientReviewer |
912 |
,ClientIsResult=@ClientIsResult |
913 |
,ClientRemarks=@ClientRemarks |
914 |
,DTIsGateWay=@DTIsGateWay |
915 |
,DTIsImport=@DTIsImport |
916 |
,DTIsRegSystem=@DTIsRegSystem |
917 |
,DTRemarks=@DTRemarks |
918 |
where DocID=@DocID |
919 |
|
920 |
if @@rowcount > 0 |
921 |
begin |
922 |
select @DocID |
923 |
end |
924 |
else |
925 |
begin |
926 |
select '' |
927 |
end;"; |
928 |
} |
929 |
string refID = base.QueryFirstOrDefault<string>(query, doc, transaction); |
930 |
|
931 |
if (doc.AttFiles != null && doc.AttFiles.Count > 0) |
932 |
{ |
933 |
string attDelIDList = string.Join("','", doc.AttFiles.Where(x => !string.IsNullOrEmpty(x.FileID)).Select(x => x.FileID).ToList()); |
934 |
|
935 |
if (!string.IsNullOrEmpty(refID) && attDelIDList.Length > 0) |
936 |
{ |
937 |
query = $@" |
938 |
delete from dbo.AttachFIles |
939 |
where RefID=@RefID and FileID in ('{attDelIDList}');"; |
940 |
base.Execute(query, new { RefID = refID }, transaction); |
941 |
} |
942 |
|
943 |
foreach (AttFileInfo attFile in doc.AttFiles) |
944 |
{ |
945 |
if (string.IsNullOrEmpty(attFile.RefID)) |
946 |
{ |
947 |
attFile.RefID = refID; |
948 |
attFile.Creator = userId; |
949 |
|
950 |
query = $@" |
951 |
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator) |
952 |
values |
953 |
( |
954 |
lower(newid()) |
955 |
,@RefID |
956 |
,@Category |
957 |
,@FileType |
958 |
,@FileName |
959 |
,@FilePath |
960 |
,@FileExtension |
961 |
,@FileData |
962 |
,@Creator |
963 |
)"; |
964 |
|
965 |
base.Execute(query, attFile, transaction); |
966 |
} |
967 |
} |
968 |
} |
969 |
} |
970 |
|
971 |
transaction.Commit(); |
972 |
isSuccess = true; |
973 |
} |
974 |
} |
975 |
catch (Exception ex) |
976 |
{ |
977 |
throw ex; |
978 |
} |
979 |
|
980 |
return isSuccess; |
981 |
} |
982 |
|
983 |
public Documents SetDocumentDataField(Documents doc, string userId) |
984 |
{ |
985 |
Documents resultData = null; |
986 |
|
987 |
try |
988 |
{ |
989 |
using (var transaction = base.BeginTransaction()) |
990 |
{ |
991 |
string query = string.Empty; |
992 |
|
993 |
if (!string.IsNullOrEmpty(doc.DocID)) |
994 |
{ |
995 |
StringBuilder sbSet = new StringBuilder(); |
996 |
var parameters = new Dictionary<string, object>(); |
997 |
|
998 |
#region Update 할 목록 |
999 |
if (doc.ID2StartDate != null) |
1000 |
{ |
1001 |
sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) "); |
1002 |
parameters.Add("ID2StartDate", doc.ID2StartDate); |
1003 |
} |
1004 |
|
1005 |
if (doc.Worker != null) |
1006 |
{ |
1007 |
sbSet.Append(" ,Worker=@Worker "); |
1008 |
parameters.Add("Worker", doc.Worker); |
1009 |
} |
1010 |
#endregion |
1011 |
|
1012 |
if (parameters.Count > 0) |
1013 |
{ |
1014 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
1015 |
parameters.Add("ModifiedUser", userId); |
1016 |
|
1017 |
parameters.Add("DocID", doc.DocID); |
1018 |
|
1019 |
query = $@" |
1020 |
declare @DateTimeNow datetime |
1021 |
set @DateTimeNow = getdate() |
1022 |
|
1023 |
update dbo.Documents |
1024 |
set ModifiedDate=@DateTimeNow {sbSet} |
1025 |
where [DocID]=@DocID |
1026 |
|
1027 |
if @@rowcount > 0 |
1028 |
begin |
1029 |
select * from dbo.Documents where DocID=@DocID |
1030 |
end |
1031 |
else |
1032 |
begin |
1033 |
select * from dbo.Documents where 1=2 |
1034 |
end;"; |
1035 |
resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction); |
1036 |
} |
1037 |
} |
1038 |
|
1039 |
transaction.Commit(); |
1040 |
} |
1041 |
} |
1042 |
catch (Exception ex) |
1043 |
{ |
1044 |
throw ex; |
1045 |
} |
1046 |
|
1047 |
return resultData; |
1048 |
} |
1049 |
|
1050 |
public bool SetDocumentDatasField(List<Documents> docs, string userId) |
1051 |
{ |
1052 |
bool isSuccess = false; |
1053 |
|
1054 |
try |
1055 |
{ |
1056 |
using (var transaction = base.BeginTransaction()) |
1057 |
{ |
1058 |
foreach (Documents doc in docs) |
1059 |
{ |
1060 |
string query = string.Empty; |
1061 |
|
1062 |
if (!string.IsNullOrEmpty(doc.DocID)) |
1063 |
{ |
1064 |
StringBuilder sbSet = new StringBuilder(); |
1065 |
var parameters = new Dictionary<string, object>(); |
1066 |
|
1067 |
#region Update 할 목록 |
1068 |
if (doc.ID2EndDate != null) |
1069 |
{ |
1070 |
sbSet.Append(" ,ID2EndDate=@ID2EndDate "); |
1071 |
parameters.Add("ID2EndDate", doc.ID2EndDate); |
1072 |
} |
1073 |
#endregion |
1074 |
|
1075 |
if (parameters.Count > 0) |
1076 |
{ |
1077 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
1078 |
parameters.Add("ModifiedUser", userId); |
1079 |
|
1080 |
parameters.Add("DocID", doc.DocID); |
1081 |
|
1082 |
query = $@" |
1083 |
update dbo.Documents |
1084 |
set ModifiedDate=getdate() {sbSet} |
1085 |
where [DocID]=@DocID;"; |
1086 |
base.Execute(query, parameters, transaction); |
1087 |
} |
1088 |
} |
1089 |
} |
1090 |
transaction.Commit(); |
1091 |
isSuccess = true; |
1092 |
} |
1093 |
} |
1094 |
catch (Exception ex) |
1095 |
{ |
1096 |
throw ex; |
1097 |
} |
1098 |
|
1099 |
return isSuccess; |
1100 |
} |
1101 |
|
1102 |
|
1103 |
//ID2 |
1104 |
public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info) |
1105 |
{ |
1106 |
try |
1107 |
{ |
1108 |
string query = $@" |
1109 |
select @Name PROJECTNAME |
1110 |
,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME |
1111 |
,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME] |
1112 |
,dw.OCCUPIED, dw.[Image] |
1113 |
from |
1114 |
( |
1115 |
select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx |
1116 |
from dbo.Drawings |
1117 |
) dw;"; |
1118 |
return Query<ID2Drawings>(query, id2Info); |
1119 |
} |
1120 |
catch (Exception ex) |
1121 |
{ |
1122 |
throw ex; |
1123 |
} |
1124 |
} |
1125 |
} |
1126 |
} |