hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 7066b8a9
이력 | 보기 | 이력해설 | 다운로드 (11.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 ID2.Manager.Data.Models; |
8 |
|
9 |
using Dapper; |
10 |
|
11 |
namespace ID2.Manager.Dapper.Repository |
12 |
{ |
13 |
public class DocumentRepository : BaseRepository |
14 |
{ |
15 |
public DocumentRepository(string connectionStr) : base(connectionStr) { } |
16 |
|
17 |
public IEnumerable<Documents> GetAllDocuments() |
18 |
{ |
19 |
string query = $@" |
20 |
select doc.*, |
21 |
|
22 |
( |
23 |
select markus.* |
24 |
from [markus_SEC].[dbo].[ViewMarkupData] markus where doc.DocumentNo = markus.DOCUMENT_ID |
25 |
FOR JSON PATH |
26 |
) as MarkupText |
27 |
from dbo.Documents doc |
28 |
where doc.IsDeleted=0 |
29 |
order by doc.Seq;"; |
30 |
|
31 |
return Query<Documents>(query); |
32 |
} |
33 |
|
34 |
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) |
35 |
{ |
36 |
var dynamicParameters = new DynamicParameters(); |
37 |
dynamicParameters.Add("Total", dbType: System.Data.DbType.Int32, direction: System.Data.ParameterDirection.Output); |
38 |
|
39 |
StringBuilder sbWhere = new StringBuilder(); |
40 |
var parameters = new Dictionary<string, object>(); |
41 |
if (!string.IsNullOrEmpty(projectCode)) |
42 |
{ |
43 |
sbWhere.Append(" and doc.RefProjectCode=@RefProjectCode "); |
44 |
parameters.Add("RefProjectCode", projectCode); |
45 |
} |
46 |
if (!string.IsNullOrEmpty(personIncharge)) |
47 |
{ |
48 |
sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge "); |
49 |
parameters.Add("PersonInCharge", personIncharge); |
50 |
} |
51 |
if (!string.IsNullOrEmpty(jobLevel)) |
52 |
{ |
53 |
sbWhere.Append(" and doc.JobLevel=@JobLevel "); |
54 |
parameters.Add("JobLevel", jobLevel); |
55 |
} |
56 |
if (!string.IsNullOrEmpty(documentNo)) |
57 |
{ |
58 |
sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' "); |
59 |
parameters.Add("DocumentNo", documentNo); |
60 |
} |
61 |
|
62 |
if (!string.IsNullOrEmpty(isToIsDiscussion)) |
63 |
{ |
64 |
sbWhere.Append(" and doc.ToIsDiscussion=@ToIsDiscussion "); |
65 |
parameters.Add("ToIsDiscussion", isToIsDiscussion); |
66 |
} |
67 |
|
68 |
if (!string.IsNullOrEmpty(isFrReviewStatus)) |
69 |
{ |
70 |
sbWhere.Append(" and doc.FrReviewStatus=@FrReviewStatus "); |
71 |
parameters.Add("FrReviewStatus", isFrReviewStatus); |
72 |
} |
73 |
|
74 |
if (!string.IsNullOrEmpty(isID2Work)) |
75 |
{ |
76 |
sbWhere.Append(" and doc.IsID2Work=@IsID2Work "); |
77 |
parameters.Add("IsID2Work", isID2Work); |
78 |
} |
79 |
|
80 |
if (!string.IsNullOrEmpty(id2Status)) |
81 |
{ |
82 |
sbWhere.Append(" and doc.ID2Status=@ID2Status "); |
83 |
parameters.Add("ID2Status", id2Status); |
84 |
} |
85 |
if (!string.IsNullOrEmpty(avevaStatus)) |
86 |
{ |
87 |
sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus "); |
88 |
parameters.Add("AVEVAStatus", avevaStatus); |
89 |
} |
90 |
|
91 |
if (!string.IsNullOrEmpty(prodIsResult)) |
92 |
{ |
93 |
sbWhere.Append(" and doc.ProdIsResult=@ProdIsResult "); |
94 |
parameters.Add("ProdIsResult", prodIsResult); |
95 |
} |
96 |
if (!string.IsNullOrEmpty(clientIsResult)) |
97 |
{ |
98 |
sbWhere.Append(" and doc.ClientIsResult=@ClientIsResult "); |
99 |
parameters.Add("ClientIsResult", clientIsResult); |
100 |
} |
101 |
|
102 |
string query = $@" |
103 |
select doc.*, |
104 |
|
105 |
( |
106 |
select markus.* |
107 |
from [markus_SEC].[dbo].[ViewMarkupData] markus where doc.DocumentNo = markus.DOCUMENT_ID |
108 |
FOR JSON PATH |
109 |
) as MarkupText |
110 |
from dbo.Documents doc |
111 |
where doc.IsDeleted=0 {sbWhere} |
112 |
order by doc.Seq |
113 |
|
114 |
select @Total=count(*) from dbo.Documents |
115 |
select @Total;"; |
116 |
|
117 |
if (parameters.Count > 0) |
118 |
{ |
119 |
dynamicParameters.AddDynamicParams(parameters); |
120 |
} |
121 |
|
122 |
var ret = Query<Documents>(query, dynamicParameters); |
123 |
|
124 |
int totalCount = dynamicParameters.Get<int>("Total"); |
125 |
|
126 |
return (ret, totalCount); |
127 |
} |
128 |
|
129 |
public bool SetDocumentData(List<Documents> docList, List<Documents> delDocList) |
130 |
{ |
131 |
bool isSuccess = false; |
132 |
|
133 |
try |
134 |
{ |
135 |
using (var transaction = base.BeginTransaction()) |
136 |
{ |
137 |
string query = string.Empty; |
138 |
|
139 |
if (delDocList.Count > 0) |
140 |
{ |
141 |
string docIDList = string.Join("','", delDocList.Where(x => !string.IsNullOrEmpty(x.DocID)).Select(x => x.DocID).ToList()); |
142 |
|
143 |
if (docIDList.Length > 0) |
144 |
{ |
145 |
query = $@" |
146 |
update dbo.Documents |
147 |
set IsDeleted=1 |
148 |
,DeletedDate=getdate() |
149 |
where [DocID] in ('{docIDList}');"; |
150 |
base.Execute(query, transaction); |
151 |
} |
152 |
} |
153 |
|
154 |
foreach (Documents doc in docList) |
155 |
{ |
156 |
if (string.IsNullOrEmpty(doc.DocID)) |
157 |
{ |
158 |
query = $@" |
159 |
insert into dbo.Documents |
160 |
( |
161 |
[DocID] |
162 |
,[DocumentNo] |
163 |
,[RevisonNo] |
164 |
,[RefProjectCode] |
165 |
,[DocFilePath] |
166 |
,[DocFileName] |
167 |
,[JobLevel] |
168 |
,[IsTypical] |
169 |
,[PersonInCharge] |
170 |
,[ToIsDiscussion] |
171 |
,[ToRemarks] |
172 |
,[ToCreator] |
173 |
,[ToCapture] |
174 |
,[ToIsMarkup] |
175 |
,[FrReviewStatus] |
176 |
,[FrRemarks] |
177 |
,[FrCreator] |
178 |
,[FrCapture] |
179 |
,[FrIsMarkup] |
180 |
,[IsID2Work] |
181 |
,[ID2Connection] |
182 |
,[ID2StartDate] |
183 |
,[ID2EndDate] |
184 |
,[ID2JobTime] |
185 |
,[ID2Status] |
186 |
,[ID2Issues] |
187 |
,[AVEVAConnection] |
188 |
,[AVEVAConvertDate] |
189 |
,[AVEVAReviewDate] |
190 |
,[AVEVAStatus] |
191 |
,[AVEVAIssues] |
192 |
,[ReviewFilePath] |
193 |
,[ReviewFileName] |
194 |
,[ProdReviewer] |
195 |
,[ProdIsResult] |
196 |
,[ProdRemarks] |
197 |
,[ClientReviewer] |
198 |
,[ClientIsResult] |
199 |
,[ClientRemarks] |
200 |
,[DTIsGateWay] |
201 |
,[DTIsImport] |
202 |
,[DTIsRegSystem] |
203 |
,[DTRemarks] |
204 |
) |
205 |
values |
206 |
( |
207 |
lower(newid()) |
208 |
,@DocumentNo |
209 |
,@RevisonNo |
210 |
,@RefProjectCode |
211 |
,@DocFilePath |
212 |
,@DocFileName |
213 |
,@JobLevel |
214 |
,@IsTypical |
215 |
,@PersonInCharge |
216 |
,@ToIsDiscussion |
217 |
,@ToRemarks |
218 |
,@ToCreator |
219 |
,@ToCapture |
220 |
,@ToIsMarkup |
221 |
,@FrReviewStatus |
222 |
,@FrRemarks |
223 |
,@FrCreator |
224 |
,@FrCapture |
225 |
,@FrIsMarkup |
226 |
,@IsID2Work |
227 |
,@ID2Connection |
228 |
,@ID2StartDate |
229 |
,@ID2EndDate |
230 |
,@ID2JobTime |
231 |
,@ID2Status |
232 |
,@ID2Issues |
233 |
,@AVEVAConnection |
234 |
,@AVEVAConvertDate |
235 |
,@AVEVAReviewDate |
236 |
,@AVEVAStatus |
237 |
,@AVEVAIssues |
238 |
,@ReviewFilePath |
239 |
,@ReviewFileName |
240 |
,@ProdReviewer |
241 |
,@ProdIsResult |
242 |
,@ProdRemarks |
243 |
,@ClientReviewer |
244 |
,@ClientIsResult |
245 |
,@ClientRemarks |
246 |
,@DTIsGateWay |
247 |
,@DTIsImport |
248 |
,@DTIsRegSystem |
249 |
,@DTRemarks |
250 |
);"; |
251 |
} |
252 |
else |
253 |
{ |
254 |
query = $@" |
255 |
update dbo.Documents |
256 |
set [DocumentNo]=@DocumentNo |
257 |
,[RevisonNo]=@RevisonNo |
258 |
,[RefProjectCode]=@RefProjectCode |
259 |
,[DocFilePath]=@DocFilePath |
260 |
,[DocFileName]=@DocFileName |
261 |
,[JobLevel]=@JobLevel |
262 |
,[IsTypical]=@IsTypical |
263 |
,[PersonInCharge]=@PersonInCharge |
264 |
,[ModifiedDate]=getdate() |
265 |
,[ToIsDiscussion]=@ToIsDiscussion |
266 |
,[ToRemarks]=@ToRemarks |
267 |
,[ToCreator]=@ToCreator |
268 |
,[ToCapture]=@ToCapture |
269 |
,[ToIsMarkup]=@ToIsMarkup |
270 |
,[FrReviewStatus]=@FrReviewStatus |
271 |
,[FrRemarks]=@FrRemarks |
272 |
,[FrCreator]=@FrCreator |
273 |
,[FrCapture]=@FrCapture |
274 |
,[FrIsMarkup]=@FrIsMarkup |
275 |
,[IsID2Work]=@IsID2Work |
276 |
,[ID2Connection]=@ID2Connection |
277 |
,[ID2StartDate]=@ID2StartDate |
278 |
,[ID2EndDate]=@ID2EndDate |
279 |
,[ID2JobTime]=@ID2JobTime |
280 |
,[ID2Status]=@ID2Status |
281 |
,[ID2Issues]=@ID2Issues |
282 |
,[AVEVAConnection]=@AVEVAConnection |
283 |
,[AVEVAConvertDate]=@AVEVAConvertDate |
284 |
,[AVEVAReviewDate]=@AVEVAReviewDate |
285 |
,[AVEVAStatus]=@AVEVAStatus |
286 |
,[AVEVAIssues]=@AVEVAIssues |
287 |
,[ReviewFilePath]=@ReviewFilePath |
288 |
,[ReviewFileName]=@ReviewFileName |
289 |
,[ProdReviewer]=@ProdReviewer |
290 |
,[ProdIsResult]=@ProdIsResult |
291 |
,[ProdRemarks]=@ProdRemarks |
292 |
,[ClientReviewer]=@ClientReviewer |
293 |
,[ClientIsResult]=@ClientIsResult |
294 |
,[ClientRemarks]=@ClientRemarks |
295 |
,[DTIsGateWay]=@DTIsGateWay |
296 |
,[DTIsImport]=@DTIsImport |
297 |
,[DTIsRegSystem]=@DTIsRegSystem |
298 |
,[DTRemarks]=@DTRemarks |
299 |
where [DocID]=@DocID;"; |
300 |
} |
301 |
base.Execute(query, doc, transaction); |
302 |
} |
303 |
|
304 |
transaction.Commit(); |
305 |
isSuccess = true; |
306 |
} |
307 |
} |
308 |
catch (Exception ex) |
309 |
{ |
310 |
throw ex; |
311 |
} |
312 |
|
313 |
return isSuccess; |
314 |
} |
315 |
|
316 |
public Documents SetDocumentDataField(Documents doc, string userId) |
317 |
{ |
318 |
Documents resultData = null; |
319 |
|
320 |
try |
321 |
{ |
322 |
using (var transaction = base.BeginTransaction()) |
323 |
{ |
324 |
string query = string.Empty; |
325 |
|
326 |
if (!string.IsNullOrEmpty(doc.DocID)) |
327 |
{ |
328 |
StringBuilder sbSet = new StringBuilder(); |
329 |
var parameters = new Dictionary<string, object>(); |
330 |
|
331 |
#region Update 할 목록 |
332 |
if (doc.ID2StartDate != null) |
333 |
{ |
334 |
sbSet.Append(" ,ID2StartDate=@DateTimeNow "); |
335 |
parameters.Add("ID2StartDate", doc.ID2StartDate); |
336 |
} |
337 |
#endregion |
338 |
|
339 |
if (parameters.Count > 0) |
340 |
{ |
341 |
sbSet.Append(" ,DocID=@DocID "); |
342 |
parameters.Add("DocID", doc.DocID); |
343 |
|
344 |
sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
345 |
parameters.Add("ModifiedUser", userId); |
346 |
|
347 |
query = $@" |
348 |
declare @DateTimeNow datetime |
349 |
set @DateTimeNow = getdate() |
350 |
|
351 |
update dbo.Documents |
352 |
set ModifiedDate=@DateTimeNow {sbSet} |
353 |
where [DocID]=@DocID |
354 |
|
355 |
if @@rowcount > 0 |
356 |
begin |
357 |
select * from dbo.Documents where DocID=@DocID |
358 |
end |
359 |
else |
360 |
begin |
361 |
select * from dbo.Documents where 1=2 |
362 |
end;"; |
363 |
resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction); |
364 |
} |
365 |
} |
366 |
|
367 |
transaction.Commit(); |
368 |
} |
369 |
} |
370 |
catch (Exception ex) |
371 |
{ |
372 |
throw ex; |
373 |
} |
374 |
|
375 |
return resultData; |
376 |
} |
377 |
|
378 |
|
379 |
//ID2 |
380 |
public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info) |
381 |
{ |
382 |
string query = $@" |
383 |
select @Name PROJECTNAME |
384 |
,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME |
385 |
,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME] |
386 |
,dw.OCCUPIED, dw.[Image] |
387 |
from |
388 |
( |
389 |
select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx |
390 |
from dbo.Drawings |
391 |
) dw;"; |
392 |
return Query<ID2Drawings>(query, id2Info); |
393 |
} |
394 |
} |
395 |
} |