프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 54977253

이력 | 보기 | 이력해설 | 다운로드 (13.1 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()
20
        {
21
            string query = $@"
22
select   doc.*
23
from     dbo.Documents doc
24
where    doc.IsDeleted=0
25
order by doc.Seq;";
26
            return Query<Documents>(query);
27
        }
28

    
29
        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)
30
        {
31
            var dynamicParameters = new DynamicParameters();
32
            dynamicParameters.Add("Total", dbType: DbType.Int32, direction: ParameterDirection.Output);
33

    
34
            StringBuilder sbWhere = new StringBuilder();
35
            var parameters = new Dictionary<string, object>();
36
            if (!string.IsNullOrEmpty(projectCode))
37
            {
38
                sbWhere.Append(" and doc.RefProjectCode=@RefProjectCode ");
39
                parameters.Add("RefProjectCode", projectCode);
40
            }
41
            if (!string.IsNullOrEmpty(personIncharge))
42
            {
43
                sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge ");
44
                parameters.Add("PersonInCharge", personIncharge);
45
            }
46
            if (!string.IsNullOrEmpty(jobLevel))
47
            {
48
                sbWhere.Append(" and doc.JobLevel=@JobLevel ");
49
                parameters.Add("JobLevel", jobLevel);
50
            }
51
            if (!string.IsNullOrEmpty(documentNo))
52
            {
53
                sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' ");
54
                parameters.Add("DocumentNo", documentNo);
55
            }
56

    
57
            if (!string.IsNullOrEmpty(isToIsDiscussion))
58
            {
59
                sbWhere.Append(" and doc.ToIsDiscussion=@ToIsDiscussion ");
60
                parameters.Add("ToIsDiscussion", isToIsDiscussion);
61
            }
62

    
63
            if (!string.IsNullOrEmpty(isFrReviewStatus))
64
            {
65
                sbWhere.Append(" and doc.FrReviewStatus=@FrReviewStatus ");
66
                parameters.Add("FrReviewStatus", isFrReviewStatus);
67
            }
68

    
69
            if (!string.IsNullOrEmpty(isID2Work))
70
            {
71
                sbWhere.Append(" and doc.IsID2Work=@IsID2Work ");
72
                parameters.Add("IsID2Work", isID2Work);
73
            }
74

    
75
            if (!string.IsNullOrEmpty(id2Status))
76
            {
77
                sbWhere.Append(" and doc.ID2Status=@ID2Status ");
78
                parameters.Add("ID2Status", id2Status);
79
            }
80
            if (!string.IsNullOrEmpty(avevaStatus))
81
            {
82
                sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus ");
83
                parameters.Add("AVEVAStatus", avevaStatus);
84
            }
85

    
86
            if (!string.IsNullOrEmpty(prodIsResult))
87
            {
88
                sbWhere.Append(" and doc.ProdIsResult=@ProdIsResult ");
89
                parameters.Add("ProdIsResult", prodIsResult);
90
            }
91
            if (!string.IsNullOrEmpty(clientIsResult))
92
            {
93
                sbWhere.Append(" and doc.ClientIsResult=@ClientIsResult ");
94
                parameters.Add("ClientIsResult", clientIsResult);
95
            }
96

    
97
            string query = $@"
98
select   doc.*, datediff(SECOND, doc.ID2StartDate, doc.ID2EndDate) as ID2JobTime,
99

    
100
  (
101
    select markus.*
102
	from [markus_SEC].[dbo].[ViewMarkupData] markus where doc.DocumentNo = markus.DOCUMENT_ID
103
	FOR JSON PATH
104
  ) as MarkupText
105
from     dbo.Documents doc
106
where    doc.IsDeleted=0 {sbWhere}
107
order by doc.Seq
108

    
109
select @Total=count(*) from dbo.Documents
110
select @Total;";
111

    
112
            if (parameters.Count > 0)
113
            {
114
                dynamicParameters.AddDynamicParams(parameters);
115
            }
116

    
117
            var ret = Query<Documents>(query, dynamicParameters);
118

    
119
            int totalCount = dynamicParameters.Get<int>("Total");
120

    
121
            return (ret, totalCount);
122
        }
123

    
124
        public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList, string userId)
125
        {
126
            bool isSuccess = false;
127

    
128
            try
129
            {
130
                using (var transaction = base.BeginTransaction())
131
                {
132
                    string query = string.Empty;
133

    
134
                    if (delDocList.Count > 0)
135
                    {
136
                        string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList());
137

    
138
                        if (docIDList.Length > 0)
139
                        {
140
                            query = $@"
141
update dbo.Documents
142
set    IsDeleted=1
143
      ,DeletedDate=getdate(),
144
      ,DeletedUser=@DeletedUser
145
where  DocID in ('{docIDList}');";
146
                            base.Execute(query, new { DeletedUser = userId }, transaction);
147
                        }
148
                    }
149

    
150
                    foreach (Documents doc in docList)
151
                    {
152
                        if (string.IsNullOrEmpty(doc.DocID))
153
                        {
154
                            doc.RegisteredUser = userId;
155
                            query = $@"
156
insert into dbo.Documents
157
(
158
     DocID
159
    ,DocumentNo
160
    ,RevisonNo
161
    ,RefProjectCode
162
    ,DocFilePath
163
    ,DocFileName
164
    ,JobLevel
165
    ,IsTypical
166
    ,PersonInCharge
167
    ,RegisteredDate
168
    ,RegisteredUser
169
    ,ToIsDiscussion
170
    ,ToRemarks
171
    ,ToCreator
172
    ,ToCapture
173
    ,ToIsMarkup
174
    ,FrReviewStatus
175
    ,FrRemarks
176
    ,FrCreator
177
    ,FrCapture
178
    ,FrIsMarkup
179
    ,IsID2Work
180
    ,ID2Connection
181
    ,ID2StartDate
182
    ,ID2EndDate
183
    ,ID2JobTime
184
    ,ID2Status
185
    ,ID2Issues
186
    ,AVEVAConnection
187
    ,AVEVAConvertDate
188
    ,AVEVAReviewDate
189
    ,AVEVAStatus
190
    ,AVEVAIssues
191
    ,ReviewFilePath
192
    ,ReviewFileName
193
    ,ProdReviewer
194
    ,ProdIsResult
195
    ,ProdRemarks
196
    ,ClientReviewer
197
    ,ClientIsResult
198
    ,ClientRemarks
199
    ,DTIsGateWay
200
    ,DTIsImport
201
    ,DTIsRegSystem
202
    ,DTRemarks
203
)
204
values 
205
(
206
     lower(newid())
207
    ,@DocumentNo
208
    ,@RevisonNo
209
    ,@RefProjectCode
210
    ,@DocFilePath
211
    ,@DocFileName
212
    ,@JobLevel
213
    ,@IsTypical
214
    ,@PersonInCharge
215
    ,getdate()
216
    ,@RegisteredUser
217
    ,@ToIsDiscussion
218
    ,@ToRemarks
219
    ,@ToCreator
220
    ,@ToCapture
221
    ,@ToIsMarkup
222
    ,@FrReviewStatus
223
    ,@FrRemarks
224
    ,@FrCreator
225
    ,@FrCapture
226
    ,@FrIsMarkup
227
    ,@IsID2Work
228
    ,@ID2Connection
229
    ,@ID2StartDate
230
    ,@ID2EndDate
231
    ,@ID2JobTime
232
    ,@ID2Status
233
    ,@ID2Issues
234
    ,@AVEVAConnection
235
    ,@AVEVAConvertDate
236
    ,@AVEVAReviewDate
237
    ,@AVEVAStatus
238
    ,@AVEVAIssues
239
    ,@ReviewFilePath
240
    ,@ReviewFileName
241
    ,@ProdReviewer
242
    ,@ProdIsResult
243
    ,@ProdRemarks
244
    ,@ClientReviewer
245
    ,@ClientIsResult
246
    ,@ClientRemarks
247
    ,@DTIsGateWay
248
    ,@DTIsImport
249
    ,@DTIsRegSystem
250
    ,@DTRemarks
251
);";
252
                        }
253
                        else
254
                        {
255
                            doc.ModifiedUser = userId;
256
                            query = $@"
257
update dbo.Documents
258
set    DocumentNo=@DocumentNo
259
      ,RevisonNo=@RevisonNo
260
      ,RefProjectCode=@RefProjectCode
261
      ,DocFilePath=@DocFilePath
262
      ,DocFileName=@DocFileName
263
      ,JobLevel=@JobLevel
264
      ,IsTypical=@IsTypical
265
      ,PersonInCharge=@PersonInCharge
266
      ,ModifiedDate=getdate()
267
      ,ModifiedUser=@ModifiedUser
268
      ,ToIsDiscussion=@ToIsDiscussion
269
      ,ToRemarks=@ToRemarks
270
      ,ToCreator=@ToCreator
271
      ,ToCapture=@ToCapture
272
      ,ToIsMarkup=@ToIsMarkup
273
      ,FrReviewStatus=@FrReviewStatus
274
      ,FrRemarks=@FrRemarks
275
      ,FrCreator=@FrCreator
276
      ,FrCapture=@FrCapture
277
      ,FrIsMarkup=@FrIsMarkup
278
      ,IsID2Work=@IsID2Work
279
      ,ID2Connection=@ID2Connection
280
      ,ID2StartDate=@ID2StartDate
281
      ,ID2EndDate=@ID2EndDate
282
      ,ID2JobTime=@ID2JobTime
283
      ,ID2Status=@ID2Status
284
      ,ID2Issues=@ID2Issues
285
      ,AVEVAConnection=@AVEVAConnection
286
      ,AVEVAConvertDate=@AVEVAConvertDate
287
      ,AVEVAReviewDate=@AVEVAReviewDate
288
      ,AVEVAStatus=@AVEVAStatus
289
      ,AVEVAIssues=@AVEVAIssues
290
      ,ReviewFilePath=@ReviewFilePath
291
      ,ReviewFileName=@ReviewFileName
292
      ,ProdReviewer=@ProdReviewer
293
      ,ProdIsResult=@ProdIsResult
294
      ,ProdRemarks=@ProdRemarks
295
      ,ClientReviewer=@ClientReviewer
296
      ,ClientIsResult=@ClientIsResult
297
      ,ClientRemarks=@ClientRemarks
298
      ,DTIsGateWay=@DTIsGateWay
299
      ,DTIsImport=@DTIsImport
300
      ,DTIsRegSystem=@DTIsRegSystem
301
      ,DTRemarks=@DTRemarks
302
where  DocID=@DocID;";
303
                        }
304
                        base.Execute(query, doc, transaction);
305
                    }
306

    
307
                    transaction.Commit();
308
                    isSuccess = true;
309
                }
310
            }
311
            catch (Exception ex)
312
            {
313
                throw ex;
314
            }
315

    
316
            return isSuccess;
317
        }
318

    
319
        public Documents SetDocumentDataField(Documents doc, string userId)
320
        {
321
            Documents resultData = null;
322

    
323
            try
324
            {
325
                using (var transaction = base.BeginTransaction())
326
                {
327
                    string query = string.Empty;
328

    
329
                    if (!string.IsNullOrEmpty(doc.DocID))
330
                    {
331
                        StringBuilder sbSet = new StringBuilder();
332
                        var parameters = new Dictionary<string, object>();
333

    
334
                        #region Update 할 목록
335
                        if (doc.ID2StartDate != null)
336
                        {
337
                            sbSet.Append(" ,ID2StartDate=@DateTimeNow ");
338
                            parameters.Add("ID2StartDate", doc.ID2StartDate);
339
                        }
340
                        #endregion
341

    
342
                        if (parameters.Count > 0)
343
                        {
344
                            sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
345
                            parameters.Add("ModifiedUser", userId);
346

    
347
                            parameters.Add("DocID", doc.DocID);
348

    
349
                            query = $@"
350
declare @DateTimeNow datetime
351
set @DateTimeNow = getdate()
352

    
353
update dbo.Documents
354
set    ModifiedDate=@DateTimeNow {sbSet}
355
where  [DocID]=@DocID
356

    
357
if @@rowcount > 0
358
begin
359
    select * from dbo.Documents where DocID=@DocID
360
end
361
else
362
begin
363
    select * from dbo.Documents where 1=2
364
end;";
365
                            resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction);
366
                        }
367
                    }
368

    
369
                    transaction.Commit();
370
                }
371
            }
372
            catch (Exception ex)
373
            {
374
                throw ex;
375
            }
376

    
377
            return resultData;
378
        }
379

    
380
        public bool SetDocumentDatasField(List<Documents> docs, string userId)
381
        {
382
            bool isSuccess = false;
383

    
384
            try
385
            {
386
                using (var transaction = base.BeginTransaction())
387
                {
388
                    foreach (Documents doc in docs)
389
                    {
390
                        string query = string.Empty;
391

    
392
                        if (!string.IsNullOrEmpty(doc.DocID))
393
                        {
394
                            StringBuilder sbSet = new StringBuilder();
395
                            var parameters = new Dictionary<string, object>();
396

    
397
                            #region Update 할 목록
398
                            if (doc.ID2EndDate != null)
399
                            {
400
                                sbSet.Append(" ,ID2EndDate=@ID2EndDate ");
401
                                parameters.Add("ID2EndDate", doc.ID2EndDate);
402
                            }
403
                            #endregion
404

    
405
                            if (parameters.Count > 0)
406
                            {
407
                                sbSet.Append(" ,ModifiedUser=@ModifiedUser ");
408
                                parameters.Add("ModifiedUser", userId);
409

    
410
                                parameters.Add("DocID", doc.DocID);
411

    
412
                                query = $@"
413
update dbo.Documents
414
set    ModifiedDate=getdate() {sbSet}
415
where  [DocID]=@DocID;";
416
                                 base.Execute(query, parameters, transaction);
417
                            }
418
                        }
419
                    }
420
                    transaction.Commit();
421
                    isSuccess = true;
422
                }
423
            }
424
            catch (Exception ex)
425
            {
426
                throw ex;
427
            }
428

    
429
            return isSuccess;
430
        }
431

    
432

    
433
        //ID2
434
        public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info)
435
        {
436
            string query = $@"
437
select @Name PROJECTNAME
438
      ,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME
439
      ,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME]
440
      ,dw.OCCUPIED, dw.[Image]
441
from
442
(
443
    select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx
444
    from   dbo.Drawings
445
) dw;";
446
            return Query<ID2Drawings>(query, id2Info);
447
        }
448
    }
449
}
클립보드 이미지 추가 (최대 크기: 500 MB)