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