hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 3fbf99d3
이력 | 보기 | 이력해설 | 다운로드 (32.7 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 "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<string> delDocList, string userId) |
332 |
{ |
333 |
bool isSuccess = false; |
334 |
|
335 |
try |
336 |
{ |
337 |
using (var transaction = base.BeginTransaction()) |
338 |
{ |
339 |
string query = string.Empty; |
340 |
|
341 |
if (delDocList.Count > 0) |
342 |
{ |
343 |
int paramMaxCount = 2000; |
344 |
int execCount = (delDocList.Count / paramMaxCount) + 1; |
345 |
|
346 |
for (int i = 0; i < execCount; i++) |
347 |
{ |
348 |
var dynamicParameters = new DynamicParameters(); |
349 |
StringBuilder sbWhere = new StringBuilder(); |
350 |
var parameters = new Dictionary<string, object>(); |
351 |
|
352 |
parameters.Add("DeletedUser", userId); |
353 |
|
354 |
var limitDwgNos = delDocList.Skip(paramMaxCount * i).Take(paramMaxCount).ToList(); |
355 |
sbWhere.Append($@" and DocID in @limitDwgNos "); |
356 |
parameters.Add("limitDwgNos", limitDwgNos); |
357 |
|
358 |
query = $@" |
359 |
update dbo.Documents |
360 |
set IsDeleted=1 |
361 |
,DeletedDate=getdate() |
362 |
,DeletedUser=@DeletedUser |
363 |
where IsDeleted=0 {sbWhere}"; |
364 |
if (parameters.Count > 0) |
365 |
{ |
366 |
dynamicParameters.AddDynamicParams(parameters); |
367 |
} |
368 |
|
369 |
base.Execute(query, dynamicParameters, transaction); |
370 |
} |
371 |
} |
372 |
|
373 |
foreach (Documents doc in docList) |
374 |
{ |
375 |
if (string.IsNullOrEmpty(doc.DocID)) |
376 |
{ |
377 |
doc.RegisteredUser = userId; |
378 |
doc.ModifiedUser = userId; |
379 |
|
380 |
query = $@" |
381 |
if exists(select * from dbo.Documents where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo and IsDeleted=0) |
382 |
begin |
383 |
--update |
384 |
update dbo.Documents |
385 |
set RevisonNo=case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
386 |
,System=@System |
387 |
,SubSystemCode=@SubSystemCode |
388 |
,JobLevel=@JobLevel |
389 |
,PersonInCharge=@PersonInCharge |
390 |
,Worker=@Worker |
391 |
,ModifiedDate=getdate() |
392 |
,ModifiedUser=@ModifiedUser |
393 |
,ToIsDiscussion=@ToIsDiscussion |
394 |
,ToRemarks=@ToRemarks |
395 |
,ToCreator=@ToCreator |
396 |
,FrReviewStatus=@FrReviewStatus |
397 |
,FrRemarks=@FrRemarks |
398 |
,FrCreator=@FrCreator |
399 |
,ID2StartDate=@ID2StartDate |
400 |
,ID2EndDate=@ID2EndDate |
401 |
,ID2Status=@ID2Status |
402 |
,ID2Issues=@ID2Issues |
403 |
,ReplyModifications=@ReplyModifications |
404 |
,ReplyRequester=@ReplyRequester |
405 |
,IsConvert=@IsConvert |
406 |
,AVEVAPersonInCharge=@AVEVAPersonInCharge |
407 |
,AVEVAWorker=@AVEVAWorker |
408 |
,AVEVAConvertDate=@AVEVAConvertDate |
409 |
,AVEVAReviewDate=@AVEVAReviewDate |
410 |
,AVEVAWorkDate=@AVEVAWorkDate |
411 |
,AVEVAStatus=@AVEVAStatus |
412 |
,AVEVAIssues=@AVEVAIssues |
413 |
,ProdReviewer=@ProdReviewer |
414 |
,ProdIsResult=@ProdIsResult |
415 |
,ProdRemarks=@ProdRemarks |
416 |
,ClientReviewer=@ClientReviewer |
417 |
,ClientIsResult=@ClientIsResult |
418 |
,ClientRemarks=@ClientRemarks |
419 |
,DTIsGateWay=@DTIsGateWay |
420 |
,DTIsImport=@DTIsImport |
421 |
,DTIsRegSystem=@DTIsRegSystem |
422 |
,DTRemarks=@DTRemarks |
423 |
where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo and IsDeleted=0 |
424 |
|
425 |
if @@rowcount > 0 |
426 |
begin |
427 |
select @DocID |
428 |
end |
429 |
else |
430 |
begin |
431 |
select '' |
432 |
end |
433 |
end |
434 |
else |
435 |
begin |
436 |
--insert |
437 |
declare @tbdoc table(docid varchar(36)) |
438 |
insert into dbo.Documents |
439 |
( |
440 |
DocID |
441 |
,DocumentNo |
442 |
,RevisonNo |
443 |
,System |
444 |
,SubSystemCode |
445 |
,RefProjectCode |
446 |
,JobLevel |
447 |
,PersonInCharge |
448 |
,Worker |
449 |
,RegisteredDate |
450 |
,RegisteredUser |
451 |
,ToIsDiscussion |
452 |
,ToRemarks |
453 |
,ToCreator |
454 |
,FrReviewStatus |
455 |
,FrRemarks |
456 |
,FrCreator |
457 |
,ID2StartDate |
458 |
,ID2EndDate |
459 |
,ID2Status |
460 |
,ID2Issues |
461 |
,ReplyModifications |
462 |
,ReplyRequester |
463 |
,IsConvert |
464 |
,AVEVAPersonInCharge |
465 |
,AVEVAWorker |
466 |
,AVEVAConvertDate |
467 |
,AVEVAReviewDate |
468 |
,AVEVAWorkDate |
469 |
,AVEVAStatus |
470 |
,AVEVAIssues |
471 |
,ProdReviewer |
472 |
,ProdIsResult |
473 |
,ProdRemarks |
474 |
,ClientReviewer |
475 |
,ClientIsResult |
476 |
,ClientRemarks |
477 |
,DTIsGateWay |
478 |
,DTIsImport |
479 |
,DTIsRegSystem |
480 |
,DTRemarks |
481 |
) |
482 |
output inserted.DocID into @tbdoc |
483 |
values |
484 |
( |
485 |
lower(newid()) |
486 |
,@DocumentNo |
487 |
,case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
488 |
,@System |
489 |
,@SubSystemCode |
490 |
,@RefProjectCode |
491 |
,@JobLevel |
492 |
,@PersonInCharge |
493 |
,@Worker |
494 |
,getdate() |
495 |
,@RegisteredUser |
496 |
,@ToIsDiscussion |
497 |
,@ToRemarks |
498 |
,@ToCreator |
499 |
,@FrReviewStatus |
500 |
,@FrRemarks |
501 |
,@FrCreator |
502 |
,@ID2StartDate |
503 |
,@ID2EndDate |
504 |
,@ID2Status |
505 |
,@ID2Issues |
506 |
,@ReplyModifications |
507 |
,@ReplyRequester |
508 |
,@IsConvert |
509 |
,@AVEVAPersonInCharge |
510 |
,@AVEVAWorker |
511 |
,@AVEVAConvertDate |
512 |
,@AVEVAReviewDate |
513 |
,@AVEVAWorkDate |
514 |
,@AVEVAStatus |
515 |
,@AVEVAIssues |
516 |
,@ProdReviewer |
517 |
,@ProdIsResult |
518 |
,@ProdRemarks |
519 |
,@ClientReviewer |
520 |
,@ClientIsResult |
521 |
,@ClientRemarks |
522 |
,@DTIsGateWay |
523 |
,@DTIsImport |
524 |
,@DTIsRegSystem |
525 |
,@DTRemarks |
526 |
) |
527 |
|
528 |
if @@rowcount > 0 |
529 |
begin |
530 |
select docid from @tbdoc |
531 |
end |
532 |
else |
533 |
begin |
534 |
select '' |
535 |
end |
536 |
end"; |
537 |
} |
538 |
else |
539 |
{ |
540 |
doc.ModifiedUser = userId; |
541 |
query = $@" |
542 |
update dbo.Documents |
543 |
set RevisonNo=case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
544 |
,System=@System |
545 |
,SubSystemCode=@SubSystemCode |
546 |
,JobLevel=@JobLevel |
547 |
,PersonInCharge=@PersonInCharge |
548 |
,Worker=@Worker |
549 |
,ModifiedDate=getdate() |
550 |
,ModifiedUser=@ModifiedUser |
551 |
,ToIsDiscussion=@ToIsDiscussion |
552 |
,ToRemarks=@ToRemarks |
553 |
,ToCreator=@ToCreator |
554 |
,FrReviewStatus=@FrReviewStatus |
555 |
,FrRemarks=@FrRemarks |
556 |
,FrCreator=@FrCreator |
557 |
,ID2StartDate=@ID2StartDate |
558 |
,ID2EndDate=@ID2EndDate |
559 |
,ID2Status=@ID2Status |
560 |
,ID2Issues=@ID2Issues |
561 |
,ReplyModifications=@ReplyModifications |
562 |
,ReplyRequester=@ReplyRequester |
563 |
,IsConvert=@IsConvert |
564 |
,AVEVAPersonInCharge=@AVEVAPersonInCharge |
565 |
,AVEVAWorker=@AVEVAWorker |
566 |
,AVEVAConvertDate=@AVEVAConvertDate |
567 |
,AVEVAReviewDate=@AVEVAReviewDate |
568 |
,AVEVAWorkDate=@AVEVAWorkDate |
569 |
,AVEVAStatus=@AVEVAStatus |
570 |
,AVEVAIssues=@AVEVAIssues |
571 |
,ProdReviewer=@ProdReviewer |
572 |
,ProdIsResult=@ProdIsResult |
573 |
,ProdRemarks=@ProdRemarks |
574 |
,ClientReviewer=@ClientReviewer |
575 |
,ClientIsResult=@ClientIsResult |
576 |
,ClientRemarks=@ClientRemarks |
577 |
,DTIsGateWay=@DTIsGateWay |
578 |
,DTIsImport=@DTIsImport |
579 |
,DTIsRegSystem=@DTIsRegSystem |
580 |
,DTRemarks=@DTRemarks |
581 |
where DocID=@DocID |
582 |
|
583 |
if @@rowcount > 0 |
584 |
begin |
585 |
select @DocID |
586 |
end |
587 |
else |
588 |
begin |
589 |
select '' |
590 |
end;"; |
591 |
} |
592 |
string refID = base.QueryFirstOrDefault<string>(query, doc, transaction); |
593 |
|
594 |
if (doc.AttFiles != null && doc.AttFiles.Count > 0) |
595 |
{ |
596 |
string attDelIDList = string.Join("','", doc.AttFiles.Where(x => !string.IsNullOrEmpty(x.FileID)).Select(x => x.FileID).ToList()); |
597 |
|
598 |
if (!string.IsNullOrEmpty(refID) && attDelIDList.Length > 0) |
599 |
{ |
600 |
query = $@" |
601 |
delete from dbo.AttachFIles |
602 |
where RefID=@RefID and FileID in ('{attDelIDList}');"; |
603 |
base.Execute(query, new { RefID = refID }, transaction); |
604 |
} |
605 |
|
606 |
foreach (AttFileInfo attFile in doc.AttFiles) |
607 |
{ |
608 |
if (string.IsNullOrEmpty(attFile.RefID)) |
609 |
{ |
610 |
attFile.RefID = refID; |
611 |
attFile.Creator = userId; |
612 |
|
613 |
query = $@" |
614 |
insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator) |
615 |
values |
616 |
( |
617 |
lower(newid()) |
618 |
,@RefID |
619 |
,@Category |
620 |
,@FileType |
621 |
,@FileName |
622 |
,@FilePath |
623 |
,@FileExtension |
624 |
,@FileData |
625 |
,@Creator |
626 |
)"; |
627 |
|
628 |
base.Execute(query, attFile, transaction); |
629 |
} |
630 |
} |
631 |
} |
632 |
} |
633 |
|
634 |
transaction.Commit(); |
635 |
isSuccess = true; |
636 |
} |
637 |
} |
638 |
catch (Exception ex) |
639 |
{ |
640 |
throw ex; |
641 |
} |
642 |
|
643 |
return isSuccess; |
644 |
} |
645 |
|
646 |
public Documents SetDocumentDataField(Documents doc, string userId) |
647 |
{ |
648 |
Documents resultData = null; |
649 |
|
650 |
try |
651 |
{ |
652 |
using (var transaction = base.BeginTransaction()) |
653 |
{ |
654 |
string query = string.Empty; |
655 |
|
656 |
if (!string.IsNullOrEmpty(doc.DocID)) |
657 |
{ |
658 |
StringBuilder sbSet = new StringBuilder(); |
659 |
var parameters = new Dictionary<string, object>(); |
660 |
|
661 |
#region Update 할 목록 |
662 |
if (doc.ID2StartDate != null) |
663 |
{ |
664 |
sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) "); |
665 |
parameters.Add("ID2StartDate", doc.ID2StartDate); |
666 |
} |
667 |
|
668 |
if (!string.IsNullOrEmpty(doc.Worker)) |
669 |
{ |
670 |
sbSet.Append(" ,Worker=@Worker "); |
671 |
parameters.Add("Worker", doc.Worker); |
672 |
} |
673 |
#endregion |
674 |
|
675 |
if (parameters.Count > 0) |
676 |
{ |
677 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
678 |
parameters.Add("ModifiedUser", userId); |
679 |
|
680 |
parameters.Add("DocID", doc.DocID); |
681 |
|
682 |
query = $@" |
683 |
declare @DateTimeNow datetime |
684 |
set @DateTimeNow = getdate() |
685 |
|
686 |
update dbo.Documents |
687 |
set ModifiedDate=@DateTimeNow {sbSet} |
688 |
where [DocID]=@DocID |
689 |
|
690 |
if @@rowcount > 0 |
691 |
begin |
692 |
select * from dbo.Documents where DocID=@DocID |
693 |
end |
694 |
else |
695 |
begin |
696 |
select * from dbo.Documents where 1=2 |
697 |
end;"; |
698 |
resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction); |
699 |
} |
700 |
} |
701 |
|
702 |
transaction.Commit(); |
703 |
} |
704 |
} |
705 |
catch (Exception ex) |
706 |
{ |
707 |
throw ex; |
708 |
} |
709 |
|
710 |
return resultData; |
711 |
} |
712 |
|
713 |
public bool SetDocumentDatasField(List<Documents> docs, string userId) |
714 |
{ |
715 |
bool isSuccess = false; |
716 |
|
717 |
try |
718 |
{ |
719 |
using (var transaction = base.BeginTransaction()) |
720 |
{ |
721 |
foreach (Documents doc in docs) |
722 |
{ |
723 |
string query = string.Empty; |
724 |
|
725 |
if (!string.IsNullOrEmpty(doc.DocID)) |
726 |
{ |
727 |
StringBuilder sbSet = new StringBuilder(); |
728 |
var parameters = new Dictionary<string, object>(); |
729 |
|
730 |
#region Update 할 목록 |
731 |
if (doc.ID2EndDate != null) |
732 |
{ |
733 |
sbSet.Append(" ,ID2EndDate=@ID2EndDate "); |
734 |
parameters.Add("ID2EndDate", doc.ID2EndDate); |
735 |
} |
736 |
#endregion |
737 |
|
738 |
if (parameters.Count > 0) |
739 |
{ |
740 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
741 |
parameters.Add("ModifiedUser", userId); |
742 |
|
743 |
parameters.Add("DocID", doc.DocID); |
744 |
|
745 |
query = $@" |
746 |
update dbo.Documents |
747 |
set ModifiedDate=getdate() {sbSet} |
748 |
where [DocID]=@DocID;"; |
749 |
base.Execute(query, parameters, transaction); |
750 |
} |
751 |
} |
752 |
} |
753 |
transaction.Commit(); |
754 |
isSuccess = true; |
755 |
} |
756 |
} |
757 |
catch (Exception ex) |
758 |
{ |
759 |
throw ex; |
760 |
} |
761 |
|
762 |
return isSuccess; |
763 |
} |
764 |
|
765 |
|
766 |
//ID2 |
767 |
public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info) |
768 |
{ |
769 |
try |
770 |
{ |
771 |
string query = $@" |
772 |
select @Name PROJECTNAME |
773 |
,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME |
774 |
,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME] |
775 |
,dw.OCCUPIED, dw.[Image] |
776 |
from |
777 |
( |
778 |
select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx |
779 |
from dbo.Drawings |
780 |
) dw;"; |
781 |
return Query<ID2Drawings>(query, id2Info); |
782 |
} |
783 |
catch (Exception ex) |
784 |
{ |
785 |
throw ex; |
786 |
} |
787 |
} |
788 |
|
789 |
|
790 |
//Transactions |
791 |
public int GetTranKey(string userId, string projectID) |
792 |
{ |
793 |
int result = -1; |
794 |
|
795 |
try |
796 |
{ |
797 |
var dynamicParameters = new DynamicParameters(); |
798 |
|
799 |
var parameters = new Dictionary<string, object>() |
800 |
{ |
801 |
{ "UserId", userId }, |
802 |
{ "ProjectID", projectID } |
803 |
}; |
804 |
|
805 |
dynamicParameters.AddDynamicParams(parameters); |
806 |
|
807 |
using (var transaction = base.BeginTransaction()) |
808 |
{ |
809 |
string query = $@" |
810 |
--log master 입력 |
811 |
insert into dbo.Transactions (UserId, ProjectID) |
812 |
values (@UserId, @ProjectID); |
813 |
select scope_identity();"; |
814 |
|
815 |
result = base.ExecuteScalar<int>(query, dynamicParameters, transaction); |
816 |
|
817 |
transaction.Commit(); |
818 |
} |
819 |
} |
820 |
catch (Exception ex) |
821 |
{ |
822 |
throw ex; |
823 |
} |
824 |
|
825 |
return result; |
826 |
} |
827 |
|
828 |
public bool SetTran(int seq, bool isMgt, bool isStart, int itemCount, int markusItemCount) |
829 |
{ |
830 |
bool result = false; |
831 |
|
832 |
try |
833 |
{ |
834 |
var dynamicParameters = new DynamicParameters(); |
835 |
var parameters = new Dictionary<string, object>() |
836 |
{ |
837 |
{ "Seq", seq }, |
838 |
{ "ItemCount", itemCount }, |
839 |
{ "MarkusItemCount", markusItemCount } |
840 |
}; |
841 |
dynamicParameters.AddDynamicParams(parameters); |
842 |
StringBuilder sbWhere = new StringBuilder(); |
843 |
if (isMgt) |
844 |
{ |
845 |
if (isStart) |
846 |
{ |
847 |
sbWhere.Append("StartDate=getdate(), ItemCount=@ItemCount"); |
848 |
} |
849 |
else |
850 |
{ |
851 |
sbWhere.Append("EndDate=getdate()"); |
852 |
} |
853 |
|
854 |
} |
855 |
else |
856 |
{ |
857 |
if (isStart) |
858 |
{ |
859 |
sbWhere.Append("MarkusStartDate=getdate(), MarkusItemCount=@MarkusItemCount"); |
860 |
} |
861 |
else |
862 |
{ |
863 |
sbWhere.Append("MarkusEndDate=getdate()"); |
864 |
} |
865 |
} |
866 |
|
867 |
using (var transaction = base.BeginTransaction()) |
868 |
{ |
869 |
string query = $@" |
870 |
update dbo.Transactions |
871 |
set {sbWhere} |
872 |
where Seq=@Seq;"; |
873 |
base.Execute(query, dynamicParameters, transaction); |
874 |
|
875 |
transaction.Commit(); |
876 |
|
877 |
result = true; |
878 |
} |
879 |
} |
880 |
catch (Exception ex) |
881 |
{ |
882 |
throw ex; |
883 |
} |
884 |
|
885 |
return result; |
886 |
} |
887 |
|
888 |
public string GetTranData(int seq) |
889 |
{ |
890 |
try |
891 |
{ |
892 |
var dynamicParameters = new DynamicParameters(); |
893 |
var parameters = new Dictionary<string, object>() |
894 |
{ |
895 |
{ "Seq", seq } |
896 |
}; |
897 |
dynamicParameters.AddDynamicParams(parameters); |
898 |
|
899 |
string query = $@" |
900 |
select * |
901 |
from dbo.Transactions |
902 |
where Seq=@Seq"; |
903 |
|
904 |
IEnumerable<dynamic> rows = base.Query<dynamic>(query, dynamicParameters); |
905 |
|
906 |
return this.ToSerializeData(rows); |
907 |
} |
908 |
catch (Exception ex) |
909 |
{ |
910 |
throw ex; |
911 |
} |
912 |
} |
913 |
|
914 |
public string ToSerializeData(IEnumerable<dynamic> items) |
915 |
{ |
916 |
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>(); |
917 |
|
918 |
if (items == null) return string.Empty; |
919 |
var datas = items.ToArray(); |
920 |
if (datas.Length == 0) return string.Empty; |
921 |
|
922 |
foreach (var data in datas) |
923 |
{ |
924 |
var dicItem = new Dictionary<string, object>(); |
925 |
foreach (var pair in ((IDictionary<string, object>)data)) |
926 |
{ |
927 |
dicItem.Add(pair.Key, pair.Value); |
928 |
} |
929 |
list.Add(dicItem); |
930 |
} |
931 |
|
932 |
return JsonConvert.SerializeObject(list); |
933 |
} |
934 |
|
935 |
public IEnumerable<Documents> GetTrDocuments(int seq) |
936 |
{ |
937 |
var dynamicParameters = new DynamicParameters(); |
938 |
StringBuilder sbWhere = new StringBuilder(); |
939 |
var parameters = new Dictionary<string, object>() |
940 |
{ |
941 |
{ "Seq", seq } |
942 |
}; |
943 |
dynamicParameters.AddDynamicParams(parameters); |
944 |
|
945 |
try |
946 |
{ |
947 |
string query = $@" |
948 |
declare @CreatedDate datetime |
949 |
declare @EndDate datetime |
950 |
declare @ProjectGroupID varchar(36) |
951 |
|
952 |
select top 1 @CreatedDate=CreatedDate, @EndDate=EndDate, @ProjectGroupID=ProjectID |
953 |
from dbo.Transactions |
954 |
where Seq=@Seq |
955 |
|
956 |
select RefProjectCode, DocumentNo |
957 |
from dbo.Documents |
958 |
where RefProjectCode in (select Code from dbo.Projects where ParentID=@ProjectGroupID) |
959 |
and RegisteredDate between @CreatedDate and @EndDate"; |
960 |
|
961 |
if (parameters.Count > 0) |
962 |
{ |
963 |
dynamicParameters.AddDynamicParams(parameters); |
964 |
} |
965 |
|
966 |
return Query<Documents>(query, dynamicParameters); |
967 |
} |
968 |
catch (Exception ex) |
969 |
{ |
970 |
throw ex; |
971 |
} |
972 |
} |
973 |
|
974 |
public class MarkusConvert |
975 |
{ |
976 |
public string PROJECT_NO { get; set; } |
977 |
public string DOCUMENT_ID { get; set; } |
978 |
public int STATUS { get; set; } |
979 |
} |
980 |
|
981 |
} |
982 |
} |