hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 4d2d5397
이력 | 보기 | 이력해설 | 다운로드 (16.5 KB)
1 |
using System; |
---|---|
2 |
using System.Collections.Generic; |
3 |
using System.Linq; |
4 |
using System.Text; |
5 |
using System.Threading.Tasks; |
6 |
|
7 |
using System.Data; |
8 |
|
9 |
using ID2.Manager.Data.Models; |
10 |
|
11 |
using Dapper; |
12 |
|
13 |
namespace ID2.Manager.Dapper.Repository |
14 |
{ |
15 |
public class DocumentRepository : BaseRepository |
16 |
{ |
17 |
public DocumentRepository(string connectionStr) : base(connectionStr) { } |
18 |
|
19 |
public IEnumerable<Documents> GetAllDocuments(string projectGroupID) |
20 |
{ |
21 |
var dynamicParameters = new DynamicParameters(); |
22 |
StringBuilder sbWhere = new StringBuilder(); |
23 |
var parameters = new Dictionary<string, object>(); |
24 |
if (!string.IsNullOrEmpty(projectGroupID)) |
25 |
{ |
26 |
sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) "); |
27 |
parameters.Add("RefGroupID", projectGroupID); |
28 |
} |
29 |
|
30 |
try |
31 |
{ |
32 |
string query = $@" |
33 |
select doc.* |
34 |
from dbo.Documents doc |
35 |
where doc.IsDeleted=0 {sbWhere} |
36 |
order by doc.Seq;"; |
37 |
|
38 |
if (parameters.Count > 0) |
39 |
{ |
40 |
dynamicParameters.AddDynamicParams(parameters); |
41 |
} |
42 |
|
43 |
return Query<Documents>(query, dynamicParameters); |
44 |
} |
45 |
catch (Exception ex) |
46 |
{ |
47 |
throw ex; |
48 |
} |
49 |
} |
50 |
|
51 |
public (IEnumerable<Documents> dwgs, int totalCnt) GetDocuments(string projectCode, string personIncharge, string jobLevel, string documentNo, string isToIsDiscussion, string isFrReviewStatus, string isID2Work, string id2Status, string avevaStatus, string prodIsResult, string clientIsResult, string isGateWay, string isRegSystem) |
52 |
{ |
53 |
var dynamicParameters = new DynamicParameters(); |
54 |
dynamicParameters.Add("Total", dbType: DbType.Int32, direction: ParameterDirection.Output); |
55 |
|
56 |
StringBuilder sbWhere = new StringBuilder(); |
57 |
StringBuilder sbTotalWhere = new StringBuilder(); |
58 |
var parameters = new Dictionary<string, object>(); |
59 |
if (!string.IsNullOrEmpty(projectCode)) |
60 |
{ |
61 |
sbWhere.Append(" and doc.RefProjectCode=@RefProjectCode "); |
62 |
sbTotalWhere.Append(" and doc.RefProjectCode=@RefProjectCode "); |
63 |
parameters.Add("RefProjectCode", projectCode); |
64 |
} |
65 |
if (!string.IsNullOrEmpty(personIncharge)) |
66 |
{ |
67 |
sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge "); |
68 |
parameters.Add("PersonInCharge", personIncharge); |
69 |
} |
70 |
if (!string.IsNullOrEmpty(jobLevel)) |
71 |
{ |
72 |
sbWhere.Append(" and doc.JobLevel=@JobLevel "); |
73 |
parameters.Add("JobLevel", jobLevel); |
74 |
} |
75 |
if (!string.IsNullOrEmpty(documentNo)) |
76 |
{ |
77 |
sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' "); |
78 |
parameters.Add("DocumentNo", documentNo); |
79 |
} |
80 |
|
81 |
if (!string.IsNullOrEmpty(isToIsDiscussion)) |
82 |
{ |
83 |
sbWhere.Append(" and doc.ToIsDiscussion=@ToIsDiscussion "); |
84 |
parameters.Add("ToIsDiscussion", isToIsDiscussion); |
85 |
} |
86 |
|
87 |
if (!string.IsNullOrEmpty(isFrReviewStatus)) |
88 |
{ |
89 |
sbWhere.Append(" and doc.FrReviewStatus=@FrReviewStatus "); |
90 |
parameters.Add("FrReviewStatus", isFrReviewStatus); |
91 |
} |
92 |
|
93 |
if (!string.IsNullOrEmpty(isID2Work)) |
94 |
{ |
95 |
sbWhere.Append(" and doc.IsID2Work=@IsID2Work "); |
96 |
parameters.Add("IsID2Work", isID2Work); |
97 |
} |
98 |
|
99 |
if (!string.IsNullOrEmpty(id2Status)) |
100 |
{ |
101 |
sbWhere.Append(" and doc.ID2Status=@ID2Status "); |
102 |
parameters.Add("ID2Status", id2Status); |
103 |
} |
104 |
if (!string.IsNullOrEmpty(avevaStatus)) |
105 |
{ |
106 |
sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus "); |
107 |
parameters.Add("AVEVAStatus", avevaStatus); |
108 |
} |
109 |
|
110 |
if (!string.IsNullOrEmpty(prodIsResult)) |
111 |
{ |
112 |
sbWhere.Append(" and doc.ProdIsResult=@ProdIsResult "); |
113 |
parameters.Add("ProdIsResult", prodIsResult); |
114 |
} |
115 |
if (!string.IsNullOrEmpty(clientIsResult)) |
116 |
{ |
117 |
sbWhere.Append(" and doc.ClientIsResult=@ClientIsResult "); |
118 |
parameters.Add("ClientIsResult", clientIsResult); |
119 |
} |
120 |
if (!string.IsNullOrEmpty(isGateWay)) |
121 |
{ |
122 |
sbWhere.Append(" and doc.DTIsGateWay=@DTIsGateWay "); |
123 |
parameters.Add("DTIsGateWay", isGateWay); |
124 |
} |
125 |
if (!string.IsNullOrEmpty(isRegSystem)) |
126 |
{ |
127 |
sbWhere.Append(" and doc.DTIsRegSystem=@DTIsRegSystem "); |
128 |
parameters.Add("DTIsRegSystem", isRegSystem); |
129 |
} |
130 |
|
131 |
try |
132 |
{ |
133 |
string query = $@" |
134 |
select doc.*, datediff(SECOND, doc.ID2StartDate, doc.ID2EndDate) as ID2JobTime, |
135 |
markus.* |
136 |
from dbo.Documents doc |
137 |
LEFT OUTER JOIN |
138 |
(SELECT [PROJECT_NO] as PROJECT_NO |
139 |
,[DOCUMENT_ID] as DocumentNo |
140 |
,[MARKUP_DATA_ID] |
141 |
,[PAGENUMBER] |
142 |
,[Text] as TEXT |
143 |
,[CREATE_DATE] as CREATE_DATE |
144 |
,[NAME] as CREATE_USER |
145 |
FROM [markus_SEC].dbo.[ViewMarkupData]) markus |
146 |
ON doc.DocumentNo = markus.DocumentNo |
147 |
where doc.IsDeleted=0 {sbWhere} |
148 |
order by doc.Seq |
149 |
|
150 |
select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere} |
151 |
select @Total;"; |
152 |
|
153 |
if (parameters.Count > 0) |
154 |
{ |
155 |
dynamicParameters.AddDynamicParams(parameters); |
156 |
} |
157 |
|
158 |
var docDictionary = new Dictionary<string, Documents>(); |
159 |
|
160 |
var ret = MultiQuery<Documents, MarkupText, Documents>(query, |
161 |
(document, markusText) => |
162 |
{ |
163 |
Documents doc; |
164 |
|
165 |
if (!docDictionary.TryGetValue(document.DocumentNo, out doc)) |
166 |
{ |
167 |
doc = document; |
168 |
doc.Markups = doc.Markups ?? new List<MarkupText>(); |
169 |
docDictionary.Add(doc.DocumentNo, doc); |
170 |
} |
171 |
|
172 |
doc.Markups.Add(markusText); |
173 |
return doc; |
174 |
|
175 |
}, dynamicParameters, splitOn: "DocumentNo").Distinct(); |
176 |
|
177 |
int totalCount = dynamicParameters.Get<int>("Total"); |
178 |
|
179 |
return (ret, totalCount); |
180 |
} |
181 |
catch (Exception ex) |
182 |
{ |
183 |
throw ex; |
184 |
} |
185 |
} |
186 |
|
187 |
public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList, string userId) |
188 |
{ |
189 |
bool isSuccess = false; |
190 |
|
191 |
try |
192 |
{ |
193 |
using (var transaction = base.BeginTransaction()) |
194 |
{ |
195 |
string query = string.Empty; |
196 |
|
197 |
if (delDocList.Count > 0) |
198 |
{ |
199 |
string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList()); |
200 |
|
201 |
if (docIDList.Length > 0) |
202 |
{ |
203 |
query = $@" |
204 |
update dbo.Documents |
205 |
set IsDeleted=1 |
206 |
,DeletedDate=getdate(), |
207 |
,DeletedUser=@DeletedUser |
208 |
where DocID in ('{docIDList}');"; |
209 |
base.Execute(query, new { DeletedUser = userId }, transaction); |
210 |
} |
211 |
} |
212 |
|
213 |
foreach (Documents doc in docList) |
214 |
{ |
215 |
if (string.IsNullOrEmpty(doc.DocID)) |
216 |
{ |
217 |
doc.RegisteredUser = userId; |
218 |
query = $@" |
219 |
insert into dbo.Documents |
220 |
( |
221 |
DocID |
222 |
,DocumentNo |
223 |
,RevisonNo |
224 |
,RefProjectCode |
225 |
,DocFilePath |
226 |
,DocFileName |
227 |
,JobLevel |
228 |
,IsTypical |
229 |
,PersonInCharge |
230 |
,RegisteredDate |
231 |
,RegisteredUser |
232 |
,ToIsDiscussion |
233 |
,ToRemarks |
234 |
,ToCreator |
235 |
,ToCapture |
236 |
,ToIsMarkup |
237 |
,FrReviewStatus |
238 |
,FrRemarks |
239 |
,FrCreator |
240 |
,FrCapture |
241 |
,FrIsMarkup |
242 |
,IsID2Work |
243 |
,ID2Connection |
244 |
,ID2StartDate |
245 |
,ID2EndDate |
246 |
,ID2Status |
247 |
,ID2Issues |
248 |
,AVEVAConnection |
249 |
,AVEVAConvertDate |
250 |
,AVEVAReviewDate |
251 |
,AVEVAStatus |
252 |
,AVEVAIssues |
253 |
,ReviewFilePath |
254 |
,ReviewFileName |
255 |
,ProdReviewer |
256 |
,ProdIsResult |
257 |
,ProdRemarks |
258 |
,ClientReviewer |
259 |
,ClientIsResult |
260 |
,ClientRemarks |
261 |
,DTIsGateWay |
262 |
,DTIsImport |
263 |
,DTIsRegSystem |
264 |
,DTRemarks |
265 |
) |
266 |
values |
267 |
( |
268 |
lower(newid()) |
269 |
,@DocumentNo |
270 |
,@RevisonNo |
271 |
,@RefProjectCode |
272 |
,@DocFilePath |
273 |
,@DocFileName |
274 |
,@JobLevel |
275 |
,@IsTypical |
276 |
,@PersonInCharge |
277 |
,getdate() |
278 |
,@RegisteredUser |
279 |
,@ToIsDiscussion |
280 |
,@ToRemarks |
281 |
,@ToCreator |
282 |
,@ToCapture |
283 |
,@ToIsMarkup |
284 |
,@FrReviewStatus |
285 |
,@FrRemarks |
286 |
,@FrCreator |
287 |
,@FrCapture |
288 |
,@FrIsMarkup |
289 |
,@IsID2Work |
290 |
,@ID2Connection |
291 |
,@ID2StartDate |
292 |
,@ID2EndDate |
293 |
,@ID2Status |
294 |
,@ID2Issues |
295 |
,@AVEVAConnection |
296 |
,@AVEVAConvertDate |
297 |
,@AVEVAReviewDate |
298 |
,@AVEVAStatus |
299 |
,@AVEVAIssues |
300 |
,@ReviewFilePath |
301 |
,@ReviewFileName |
302 |
,@ProdReviewer |
303 |
,@ProdIsResult |
304 |
,@ProdRemarks |
305 |
,@ClientReviewer |
306 |
,@ClientIsResult |
307 |
,@ClientRemarks |
308 |
,@DTIsGateWay |
309 |
,@DTIsImport |
310 |
,@DTIsRegSystem |
311 |
,@DTRemarks |
312 |
);"; |
313 |
} |
314 |
else |
315 |
{ |
316 |
doc.ModifiedUser = userId; |
317 |
query = $@" |
318 |
update dbo.Documents |
319 |
set DocumentNo=@DocumentNo |
320 |
,RevisonNo=@RevisonNo |
321 |
,RefProjectCode=@RefProjectCode |
322 |
,DocFilePath=@DocFilePath |
323 |
,DocFileName=@DocFileName |
324 |
,JobLevel=@JobLevel |
325 |
,IsTypical=@IsTypical |
326 |
,PersonInCharge=@PersonInCharge |
327 |
,ModifiedDate=getdate() |
328 |
,ModifiedUser=@ModifiedUser |
329 |
,ToIsDiscussion=@ToIsDiscussion |
330 |
,ToRemarks=@ToRemarks |
331 |
,ToCreator=@ToCreator |
332 |
,ToCapture=@ToCapture |
333 |
,ToIsMarkup=@ToIsMarkup |
334 |
,FrReviewStatus=@FrReviewStatus |
335 |
,FrRemarks=@FrRemarks |
336 |
,FrCreator=@FrCreator |
337 |
,FrCapture=@FrCapture |
338 |
,FrIsMarkup=@FrIsMarkup |
339 |
,IsID2Work=@IsID2Work |
340 |
,ID2Connection=@ID2Connection |
341 |
,ID2StartDate=@ID2StartDate |
342 |
,ID2EndDate=@ID2EndDate |
343 |
,ID2Status=@ID2Status |
344 |
,ID2Issues=@ID2Issues |
345 |
,AVEVAConnection=@AVEVAConnection |
346 |
,AVEVAConvertDate=@AVEVAConvertDate |
347 |
,AVEVAReviewDate=@AVEVAReviewDate |
348 |
,AVEVAStatus=@AVEVAStatus |
349 |
,AVEVAIssues=@AVEVAIssues |
350 |
,ReviewFilePath=@ReviewFilePath |
351 |
,ReviewFileName=@ReviewFileName |
352 |
,ProdReviewer=@ProdReviewer |
353 |
,ProdIsResult=@ProdIsResult |
354 |
,ProdRemarks=@ProdRemarks |
355 |
,ClientReviewer=@ClientReviewer |
356 |
,ClientIsResult=@ClientIsResult |
357 |
,ClientRemarks=@ClientRemarks |
358 |
,DTIsGateWay=@DTIsGateWay |
359 |
,DTIsImport=@DTIsImport |
360 |
,DTIsRegSystem=@DTIsRegSystem |
361 |
,DTRemarks=@DTRemarks |
362 |
where DocID=@DocID;"; |
363 |
} |
364 |
base.Execute(query, doc, transaction); |
365 |
} |
366 |
|
367 |
transaction.Commit(); |
368 |
isSuccess = true; |
369 |
} |
370 |
} |
371 |
catch (Exception ex) |
372 |
{ |
373 |
throw ex; |
374 |
} |
375 |
|
376 |
return isSuccess; |
377 |
} |
378 |
|
379 |
public Documents SetDocumentDataField(Documents doc, string userId) |
380 |
{ |
381 |
Documents resultData = null; |
382 |
|
383 |
try |
384 |
{ |
385 |
using (var transaction = base.BeginTransaction()) |
386 |
{ |
387 |
string query = string.Empty; |
388 |
|
389 |
if (!string.IsNullOrEmpty(doc.DocID)) |
390 |
{ |
391 |
StringBuilder sbSet = new StringBuilder(); |
392 |
var parameters = new Dictionary<string, object>(); |
393 |
|
394 |
#region Update 할 목록 |
395 |
if (doc.ID2StartDate != null) |
396 |
{ |
397 |
sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) "); |
398 |
parameters.Add("ID2StartDate", doc.ID2StartDate); |
399 |
} |
400 |
|
401 |
if (doc.Worker != null) |
402 |
{ |
403 |
sbSet.Append(" ,Worker=@Worker "); |
404 |
parameters.Add("Worker", doc.Worker); |
405 |
} |
406 |
#endregion |
407 |
|
408 |
if (parameters.Count > 0) |
409 |
{ |
410 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
411 |
parameters.Add("ModifiedUser", userId); |
412 |
|
413 |
parameters.Add("DocID", doc.DocID); |
414 |
|
415 |
query = $@" |
416 |
declare @DateTimeNow datetime |
417 |
set @DateTimeNow = getdate() |
418 |
|
419 |
update dbo.Documents |
420 |
set ModifiedDate=@DateTimeNow {sbSet} |
421 |
where [DocID]=@DocID |
422 |
|
423 |
if @@rowcount > 0 |
424 |
begin |
425 |
select *, datediff(SECOND, ID2StartDate, ID2EndDate) as ID2JobTime from dbo.Documents where DocID=@DocID |
426 |
end |
427 |
else |
428 |
begin |
429 |
select *, 0 as ID2JobTime from dbo.Documents where 1=2 |
430 |
end;"; |
431 |
resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction); |
432 |
} |
433 |
} |
434 |
|
435 |
transaction.Commit(); |
436 |
} |
437 |
} |
438 |
catch (Exception ex) |
439 |
{ |
440 |
throw ex; |
441 |
} |
442 |
|
443 |
return resultData; |
444 |
} |
445 |
|
446 |
public bool SetDocumentDatasField(List<Documents> docs, string userId) |
447 |
{ |
448 |
bool isSuccess = false; |
449 |
|
450 |
try |
451 |
{ |
452 |
using (var transaction = base.BeginTransaction()) |
453 |
{ |
454 |
foreach (Documents doc in docs) |
455 |
{ |
456 |
string query = string.Empty; |
457 |
|
458 |
if (!string.IsNullOrEmpty(doc.DocID)) |
459 |
{ |
460 |
StringBuilder sbSet = new StringBuilder(); |
461 |
var parameters = new Dictionary<string, object>(); |
462 |
|
463 |
#region Update 할 목록 |
464 |
if (doc.ID2EndDate != null) |
465 |
{ |
466 |
sbSet.Append(" ,ID2EndDate=@ID2EndDate "); |
467 |
parameters.Add("ID2EndDate", doc.ID2EndDate); |
468 |
} |
469 |
#endregion |
470 |
|
471 |
if (parameters.Count > 0) |
472 |
{ |
473 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
474 |
parameters.Add("ModifiedUser", userId); |
475 |
|
476 |
parameters.Add("DocID", doc.DocID); |
477 |
|
478 |
query = $@" |
479 |
update dbo.Documents |
480 |
set ModifiedDate=getdate() {sbSet} |
481 |
where [DocID]=@DocID;"; |
482 |
base.Execute(query, parameters, transaction); |
483 |
} |
484 |
} |
485 |
} |
486 |
transaction.Commit(); |
487 |
isSuccess = true; |
488 |
} |
489 |
} |
490 |
catch (Exception ex) |
491 |
{ |
492 |
throw ex; |
493 |
} |
494 |
|
495 |
return isSuccess; |
496 |
} |
497 |
|
498 |
|
499 |
//ID2 |
500 |
public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info) |
501 |
{ |
502 |
try |
503 |
{ |
504 |
string query = $@" |
505 |
select @Name PROJECTNAME |
506 |
,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME |
507 |
,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME] |
508 |
,dw.OCCUPIED, dw.[Image] |
509 |
from |
510 |
( |
511 |
select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx |
512 |
from dbo.Drawings |
513 |
) dw;"; |
514 |
return Query<ID2Drawings>(query, id2Info); |
515 |
} |
516 |
catch (Exception ex) |
517 |
{ |
518 |
throw ex; |
519 |
} |
520 |
} |
521 |
} |
522 |
} |