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