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