프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 4d2d5397

이력 | 보기 | 이력해설 | 다운로드 (16.5 KB)

1 5898479a yoush97
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
7 54977253 yoush97
using System.Data;
8
9 5898479a yoush97
using ID2.Manager.Data.Models;
10
11 8e373ccf yoush97
using Dapper;
12
13 5898479a yoush97
namespace ID2.Manager.Dapper.Repository
14
{
15
    public class DocumentRepository : BaseRepository
16
    {
17
        public DocumentRepository(string connectionStr) : base(connectionStr) { }
18
19 a4a166e2 yoush97
        public IEnumerable<Documents> GetAllDocuments(string projectGroupID)
20 5898479a yoush97
        {
21 a4a166e2 yoush97
            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 82705273 yoush97
            try
31
            {
32
                string query = $@"
33 54977253 yoush97
select   doc.*
34 7066b8a9 yoush97
from     dbo.Documents doc
35 a4a166e2 yoush97
where    doc.IsDeleted=0 {sbWhere}
36 7066b8a9 yoush97
order by doc.Seq;";
37 a4a166e2 yoush97
38
                if (parameters.Count > 0)
39
                {
40
                    dynamicParameters.AddDynamicParams(parameters);
41
                }
42
43
                return Query<Documents>(query, dynamicParameters);
44 82705273 yoush97
            }
45
            catch (Exception ex)
46
            {
47
                throw ex;
48
            }
49 7066b8a9 yoush97
        }
50
51 ee82162b yoush97
        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 7066b8a9 yoush97
        {
53
            var dynamicParameters = new DynamicParameters();
54 54977253 yoush97
            dynamicParameters.Add("Total", dbType: DbType.Int32, direction: ParameterDirection.Output);
55 7066b8a9 yoush97
56 8e373ccf yoush97
            StringBuilder sbWhere = new StringBuilder();
57 bf7d1c08 yoush97
            StringBuilder sbTotalWhere = new StringBuilder();
58 8e373ccf yoush97
            var parameters = new Dictionary<string, object>();
59 36a31d25 yoush97
            if (!string.IsNullOrEmpty(projectCode))
60 8e373ccf yoush97
            {
61 36a31d25 yoush97
                sbWhere.Append(" and doc.RefProjectCode=@RefProjectCode ");
62 bf7d1c08 yoush97
                sbTotalWhere.Append(" and doc.RefProjectCode=@RefProjectCode ");
63 36a31d25 yoush97
                parameters.Add("RefProjectCode", projectCode);
64 8e373ccf yoush97
            }
65
            if (!string.IsNullOrEmpty(personIncharge))
66
            {
67
                sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge ");
68
                parameters.Add("PersonInCharge", personIncharge);
69
            }
70 08ea0584 yoush97
            if (!string.IsNullOrEmpty(jobLevel))
71
            {
72
                sbWhere.Append(" and doc.JobLevel=@JobLevel ");
73
                parameters.Add("JobLevel", jobLevel);
74
            }
75 8e373ccf yoush97
            if (!string.IsNullOrEmpty(documentNo))
76
            {
77
                sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' ");
78
                parameters.Add("DocumentNo", documentNo);
79
            }
80
81 296ffcbd yoush97
            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 08ea0584 yoush97
            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 ee82162b yoush97
            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 08ea0584 yoush97
131 82705273 yoush97
            try
132
            {
133
                string query = $@"
134 e458a996 taeseongkim
                            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 7066b8a9 yoush97
150 3ccb1a8d yoush97
select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere}
151 7066b8a9 yoush97
select @Total;";
152 8e373ccf yoush97
153 82705273 yoush97
                if (parameters.Count > 0)
154
                {
155
                    dynamicParameters.AddDynamicParams(parameters);
156
                }
157 5898479a yoush97
158 e458a996 taeseongkim
                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 7066b8a9 yoush97
177 82705273 yoush97
                int totalCount = dynamicParameters.Get<int>("Total");
178 7066b8a9 yoush97
179 82705273 yoush97
                return (ret, totalCount);
180
            }
181
            catch (Exception ex)
182
            {
183
                throw ex;
184
            }
185 5898479a yoush97
        }
186 482f6326 yoush97
187 54977253 yoush97
        public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList, string userId)
188 482f6326 yoush97
        {
189
            bool isSuccess = false;
190
191
            try
192
            {
193 d2d4f84b yoush97
                using (var transaction = base.BeginTransaction())
194 482f6326 yoush97
                {
195 709c1971 yoush97
                    string query = string.Empty;
196
197
                    if (delDocList.Count > 0)
198 482f6326 yoush97
                    {
199 709c1971 yoush97
                        string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList());
200
201
                        if (docIDList.Length > 0)
202
                        {
203 53fde692 yoush97
                            query = $@"
204 74aa670a yoush97
update dbo.Documents
205
set    IsDeleted=1
206 54977253 yoush97
      ,DeletedDate=getdate(),
207
      ,DeletedUser=@DeletedUser
208
where  DocID in ('{docIDList}');";
209
                            base.Execute(query, new { DeletedUser = userId }, transaction);
210 709c1971 yoush97
                        }
211
                    }
212 482f6326 yoush97
213
                    foreach (Documents doc in docList)
214
                    {
215
                        if (string.IsNullOrEmpty(doc.DocID))
216
                        {
217 54977253 yoush97
                            doc.RegisteredUser = userId;
218 482f6326 yoush97
                            query = $@"
219
insert into dbo.Documents
220
(
221 54977253 yoush97
     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 482f6326 yoush97
)
266
values 
267
(
268
     lower(newid())
269
    ,@DocumentNo
270
    ,@RevisonNo
271 36a31d25 yoush97
    ,@RefProjectCode
272 482f6326 yoush97
    ,@DocFilePath
273
    ,@DocFileName
274
    ,@JobLevel
275
    ,@IsTypical
276
    ,@PersonInCharge
277 54977253 yoush97
    ,getdate()
278
    ,@RegisteredUser
279 482f6326 yoush97
    ,@ToIsDiscussion
280
    ,@ToRemarks
281
    ,@ToCreator
282 00d11333 yoush97
    ,@ToCapture
283 482f6326 yoush97
    ,@ToIsMarkup
284
    ,@FrReviewStatus
285
    ,@FrRemarks
286
    ,@FrCreator
287 00d11333 yoush97
    ,@FrCapture
288 482f6326 yoush97
    ,@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 709c1971 yoush97
);";
313 482f6326 yoush97
                        }
314
                        else
315
                        {
316 54977253 yoush97
                            doc.ModifiedUser = userId;
317 482f6326 yoush97
                            query = $@"
318
update dbo.Documents
319 54977253 yoush97
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 482f6326 yoush97
                        }
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 978488b0 yoush97
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 4b8d9ad9 yoush97
                            sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) ");
398 978488b0 yoush97
                            parameters.Add("ID2StartDate", doc.ID2StartDate);
399
                        }
400 4b8d9ad9 yoush97
401
                        if (doc.Worker != null)
402
                        {
403
                            sbSet.Append(" ,Worker=@Worker ");
404
                            parameters.Add("Worker", doc.Worker);
405
                        }
406 978488b0 yoush97
                        #endregion
407
408
                        if (parameters.Count > 0)
409
                        {
410
                            sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
411
                            parameters.Add("ModifiedUser", userId);
412
413 54977253 yoush97
                            parameters.Add("DocID", doc.DocID);
414
415 978488b0 yoush97
                            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 c0420a29 yoush97
    select *, datediff(SECOND, ID2StartDate, ID2EndDate) as ID2JobTime from dbo.Documents where DocID=@DocID
426 978488b0 yoush97
end
427
else
428
begin
429 c0420a29 yoush97
    select *, 0 as ID2JobTime from dbo.Documents where 1=2
430 978488b0 yoush97
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 fe57f64a yoush97
446 54977253 yoush97
        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 e458a996 taeseongkim
                                base.Execute(query, parameters, transaction);
483 54977253 yoush97
                            }
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 fe57f64a yoush97
499
        //ID2
500
        public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info)
501
        {
502 82705273 yoush97
            try
503
            {
504
                string query = $@"
505 fe57f64a yoush97
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 82705273 yoush97
                return Query<ID2Drawings>(query, id2Info);
515
            }
516
            catch (Exception ex)
517
            {
518
                throw ex;
519
            }
520 fe57f64a yoush97
        }
521 5898479a yoush97
    }
522 d2d4f84b yoush97
}
클립보드 이미지 추가 (최대 크기: 500 MB)