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