hytos / ID2.Manager / ID2.Manager.Dapper / Repository / DocumentRepository.cs @ 0a6036cb
이력 | 보기 | 이력해설 | 다운로드 (33.1 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 | 39938acd | yoush97 | using System.ComponentModel; |
9 | using System.Reflection; |
||
10 | 54977253 | yoush97 | |
11 | 5898479a | yoush97 | using ID2.Manager.Data.Models; |
12 | |||
13 | 8e373ccf | yoush97 | using Dapper; |
14 | 39938acd | yoush97 | |
15 | using Newtonsoft.Json; |
||
16 | 8e373ccf | yoush97 | |
17 | 5898479a | yoush97 | namespace ID2.Manager.Dapper.Repository |
18 | { |
||
19 | public class DocumentRepository : BaseRepository |
||
20 | { |
||
21 | public DocumentRepository(string connectionStr) : base(connectionStr) { } |
||
22 | |||
23 | a4a166e2 | yoush97 | public IEnumerable<Documents> GetAllDocuments(string projectGroupID) |
24 | 5898479a | yoush97 | { |
25 | a4a166e2 | yoush97 | var dynamicParameters = new DynamicParameters(); |
26 | StringBuilder sbWhere = new StringBuilder(); |
||
27 | var parameters = new Dictionary<string, object>(); |
||
28 | if (!string.IsNullOrEmpty(projectGroupID)) |
||
29 | { |
||
30 | sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) "); |
||
31 | parameters.Add("RefGroupID", projectGroupID); |
||
32 | } |
||
33 | |||
34 | 82705273 | yoush97 | try |
35 | { |
||
36 | string query = $@" |
||
37 | 54977253 | yoush97 | select doc.* |
38 | 7066b8a9 | yoush97 | from dbo.Documents doc |
39 | a4a166e2 | yoush97 | where doc.IsDeleted=0 {sbWhere} |
40 | 7066b8a9 | yoush97 | order by doc.Seq;"; |
41 | a4a166e2 | yoush97 | |
42 | if (parameters.Count > 0) |
||
43 | { |
||
44 | dynamicParameters.AddDynamicParams(parameters); |
||
45 | } |
||
46 | |||
47 | return Query<Documents>(query, dynamicParameters); |
||
48 | 82705273 | yoush97 | } |
49 | catch (Exception ex) |
||
50 | { |
||
51 | throw ex; |
||
52 | } |
||
53 | 7066b8a9 | yoush97 | } |
54 | 08499f5f | taeseongkim | static string GetDescriptionFromAttribute(MemberInfo member) |
55 | { |
||
56 | if (member == null) return null; |
||
57 | |||
58 | var attrib = (DescriptionAttribute)Attribute.GetCustomAttribute(member, typeof(DescriptionAttribute), false); |
||
59 | return (attrib?.Description ?? member.Name).ToLower(); |
||
60 | } |
||
61 | |||
62 | 7066b8a9 | yoush97 | |
63 | 2aa2a446 | yoush97 | public (IEnumerable<Documents> dwgs, int totalCnt) GetDocuments(string projectGroupID, List<string> dateTypes, DateTime? frDate, DateTime? toDate, string projectCode, string personIncharge, string jobLevel, string documentNo, string isToIsDiscussion, string isFrReviewStatus, string id2Status, string id2Issues, string avevaStatus, string avevaIssues, string prodIsResult, string clientIsResult, string isGateWay, string isRegSystem) |
64 | 7066b8a9 | yoush97 | { |
65 | 08499f5f | taeseongkim | var map = new CustomPropertyTypeMap(typeof(AttFileInfo), (type, columnName) |
66 | => type.GetProperties().FirstOrDefault(prop => GetDescriptionFromAttribute(prop) == columnName.ToLower())); |
||
67 | SqlMapper.SetTypeMap(typeof(AttFileInfo), map); |
||
68 | |||
69 | |||
70 | 7066b8a9 | yoush97 | var dynamicParameters = new DynamicParameters(); |
71 | 54977253 | yoush97 | dynamicParameters.Add("Total", dbType: DbType.Int32, direction: ParameterDirection.Output); |
72 | 7066b8a9 | yoush97 | |
73 | 8e373ccf | yoush97 | StringBuilder sbWhere = new StringBuilder(); |
74 | bf7d1c08 | yoush97 | StringBuilder sbTotalWhere = new StringBuilder(); |
75 | 8e373ccf | yoush97 | var parameters = new Dictionary<string, object>(); |
76 | b2ff5ff4 | yoush97 | if (dateTypes.Count > 0 && (frDate != null || toDate != null)) |
77 | { |
||
78 | List<string> subWheres = new List<string>(); |
||
79 | foreach (string dateType in dateTypes) |
||
80 | { |
||
81 | StringBuilder sbSubWhere = new StringBuilder(); |
||
82 | if (frDate != null) |
||
83 | { |
||
84 | sbSubWhere.Insert(0, $@"convert(datetime, '{Convert.ToDateTime(frDate).AddDays(-1):yyyy-MM-dd 23:59:59.997}') < doc.{dateType}"); |
||
85 | } |
||
86 | if (toDate != null) |
||
87 | { |
||
88 | if (frDate != null) |
||
89 | sbSubWhere.Append($@" and "); |
||
90 | sbSubWhere.Append($@"doc.{dateType} < convert(datetime, '{Convert.ToDateTime(toDate).AddDays(1):yyyy-MM-dd 00:00:00.000}')"); |
||
91 | } |
||
92 | |||
93 | if (sbSubWhere.Length > 0) |
||
94 | { |
||
95 | subWheres.Add("(" + sbSubWhere.ToString() + ")"); |
||
96 | } |
||
97 | } |
||
98 | |||
99 | if (subWheres.Count > 0) |
||
100 | { |
||
101 | sbWhere.Append(" and (" + string.Join(" or ", subWheres) + ") "); |
||
102 | } |
||
103 | } |
||
104 | ea97eee6 | yoush97 | if (string.IsNullOrEmpty(projectCode)) |
105 | { |
||
106 | sbWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') "); |
||
107 | e8a86b9b | yoush97 | sbTotalWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') "); |
108 | ea97eee6 | yoush97 | parameters.Add("RefGroupID", projectGroupID); |
109 | } |
||
110 | else |
||
111 | 8e373ccf | yoush97 | { |
112 | e8a86b9b | yoush97 | sbTotalWhere.Append(" and isnull(doc.RefProjectCode,'') in (select Code from dbo.Projects where ParentID=@RefGroupID union all select '') "); |
113 | parameters.Add("RefGroupID", projectGroupID); |
||
114 | |||
115 | 36a31d25 | yoush97 | sbWhere.Append(" and doc.RefProjectCode=@RefProjectCode "); |
116 | parameters.Add("RefProjectCode", projectCode); |
||
117 | 8e373ccf | yoush97 | } |
118 | if (!string.IsNullOrEmpty(personIncharge)) |
||
119 | { |
||
120 | sbWhere.Append(" and doc.PersonInCharge=@PersonInCharge "); |
||
121 | parameters.Add("PersonInCharge", personIncharge); |
||
122 | } |
||
123 | 08ea0584 | yoush97 | if (!string.IsNullOrEmpty(jobLevel)) |
124 | { |
||
125 | sbWhere.Append(" and doc.JobLevel=@JobLevel "); |
||
126 | parameters.Add("JobLevel", jobLevel); |
||
127 | } |
||
128 | 8e373ccf | yoush97 | if (!string.IsNullOrEmpty(documentNo)) |
129 | { |
||
130 | sbWhere.Append(" and doc.DocumentNo like '%' + @DocumentNo +'%' "); |
||
131 | parameters.Add("DocumentNo", documentNo); |
||
132 | } |
||
133 | |||
134 | 296ffcbd | yoush97 | if (!string.IsNullOrEmpty(isToIsDiscussion)) |
135 | { |
||
136 | sbWhere.Append(" and doc.ToIsDiscussion=@ToIsDiscussion "); |
||
137 | parameters.Add("ToIsDiscussion", isToIsDiscussion); |
||
138 | } |
||
139 | |||
140 | if (!string.IsNullOrEmpty(isFrReviewStatus)) |
||
141 | { |
||
142 | sbWhere.Append(" and doc.FrReviewStatus=@FrReviewStatus "); |
||
143 | parameters.Add("FrReviewStatus", isFrReviewStatus); |
||
144 | } |
||
145 | |||
146 | 08ea0584 | yoush97 | if (!string.IsNullOrEmpty(id2Status)) |
147 | { |
||
148 | sbWhere.Append(" and doc.ID2Status=@ID2Status "); |
||
149 | parameters.Add("ID2Status", id2Status); |
||
150 | } |
||
151 | 3cc84cb6 | yoush97 | |
152 | if (!string.IsNullOrEmpty(id2Issues)) |
||
153 | { |
||
154 | sbWhere.Append(" and (case when isnull(ltrim(rtrim(doc.ID2Issues)),'') = '' then 'No' else 'Yes' end)=@ID2Issues "); |
||
155 | parameters.Add("ID2Issues", id2Issues); |
||
156 | } |
||
157 | |||
158 | 08ea0584 | yoush97 | if (!string.IsNullOrEmpty(avevaStatus)) |
159 | { |
||
160 | sbWhere.Append(" and doc.AVEVAStatus=@AVEVAStatus "); |
||
161 | parameters.Add("AVEVAStatus", avevaStatus); |
||
162 | } |
||
163 | |||
164 | 3cc84cb6 | yoush97 | if (!string.IsNullOrEmpty(avevaIssues)) |
165 | { |
||
166 | sbWhere.Append(" and (case when isnull(ltrim(rtrim(doc.AVEVAIssues)),'') = '' then 'No' else 'Yes' end)=@AVEVAIssues "); |
||
167 | parameters.Add("AVEVAIssues", avevaIssues); |
||
168 | } |
||
169 | |||
170 | 08ea0584 | yoush97 | if (!string.IsNullOrEmpty(prodIsResult)) |
171 | { |
||
172 | sbWhere.Append(" and doc.ProdIsResult=@ProdIsResult "); |
||
173 | parameters.Add("ProdIsResult", prodIsResult); |
||
174 | } |
||
175 | if (!string.IsNullOrEmpty(clientIsResult)) |
||
176 | { |
||
177 | sbWhere.Append(" and doc.ClientIsResult=@ClientIsResult "); |
||
178 | parameters.Add("ClientIsResult", clientIsResult); |
||
179 | } |
||
180 | ee82162b | yoush97 | if (!string.IsNullOrEmpty(isGateWay)) |
181 | { |
||
182 | sbWhere.Append(" and doc.DTIsGateWay=@DTIsGateWay "); |
||
183 | parameters.Add("DTIsGateWay", isGateWay); |
||
184 | } |
||
185 | if (!string.IsNullOrEmpty(isRegSystem)) |
||
186 | { |
||
187 | sbWhere.Append(" and doc.DTIsRegSystem=@DTIsRegSystem "); |
||
188 | parameters.Add("DTIsRegSystem", isRegSystem); |
||
189 | } |
||
190 | 08ea0584 | yoush97 | |
191 | 82705273 | yoush97 | try |
192 | { |
||
193 | 08499f5f | taeseongkim | |
194 | //files.[FileID],files.[FileID] as AttFileID, files.RefID, files.Category, files.FileType, files.FileName, files.FilePath, files.FileExtension, files.FileData, files.Remark, files.CreatedDate, files.Creator, |
||
195 | fe310cac | yoush97 | string query = $@" |
196 | select doc.*, |
||
197 | files.[FileID] as FileID, files.*, |
||
198 | markus.PROJECT_NO as PROJECT_NO, markus.* |
||
199 | from dbo.Documents doc |
||
200 | LEFT OUTER JOIN AttachFIles files ON doc.DocID = fIles.RefID |
||
201 | LEFT OUTER JOIN |
||
202 | (SELECT [PROJECT_NO] as PROJECT_NO |
||
203 | ,[DOCUMENT_ID] as DocumentNo |
||
204 | ,[PAGENUMBER] |
||
205 | ,[Text] as TEXT |
||
206 | ,[CREATE_DATE] as CREATE_DATE |
||
207 | ,[NAME] as CREATE_USER |
||
208 | FROM ViewMarkupData) markus |
||
209 | 9096bc6d | taeseongkim | ON doc.RefProjectCode = markus.Project_NO AND doc.DocumentNo = markus.DocumentNo |
210 | fe310cac | yoush97 | where doc.IsDeleted=0 {sbWhere} |
211 | order by doc.Seq |
||
212 | 7066b8a9 | yoush97 | |
213 | 3ccb1a8d | yoush97 | select @Total=count(*) from dbo.Documents doc where doc.IsDeleted=0 {sbTotalWhere} |
214 | 7066b8a9 | yoush97 | select @Total;"; |
215 | 8e373ccf | yoush97 | |
216 | 82705273 | yoush97 | if (parameters.Count > 0) |
217 | { |
||
218 | dynamicParameters.AddDynamicParams(parameters); |
||
219 | } |
||
220 | 5898479a | yoush97 | |
221 | e458a996 | taeseongkim | var docDictionary = new Dictionary<string, Documents>(); |
222 | |||
223 | 08499f5f | taeseongkim | var ret = MultiQuery<Documents, AttFileInfo, MarkupText, Documents>(query, |
224 | (document, attfile, markusText) => |
||
225 | e458a996 | taeseongkim | { |
226 | Documents doc; |
||
227 | |||
228 | 08499f5f | taeseongkim | if (!docDictionary.TryGetValue(document.DocID, out doc)) |
229 | e458a996 | taeseongkim | { |
230 | doc = document; |
||
231 | 08499f5f | taeseongkim | docDictionary.Add(doc.DocID, doc); |
232 | } |
||
233 | |||
234 | if (markusText != null) |
||
235 | { |
||
236 | 9096bc6d | taeseongkim | doc.ConvertStatus = 4; |
237 | 08499f5f | taeseongkim | |
238 | 9096bc6d | taeseongkim | if (markusText.TEXT != null && markusText.CREATE_DATE != null && markusText.CREATE_USER != null) |
239 | 08499f5f | taeseongkim | { |
240 | 9096bc6d | taeseongkim | doc.Markups = doc.Markups ?? new List<MarkupText>(); |
241 | |||
242 | if (!doc.Markups.Any(x => x.Equals(markusText))) |
||
243 | { |
||
244 | doc.Markups.Add(markusText); |
||
245 | } |
||
246 | 08499f5f | taeseongkim | } |
247 | } |
||
248 | |||
249 | if (attfile != null) |
||
250 | { |
||
251 | doc.AttFiles = doc.AttFiles ?? new List<AttFileInfo>(); |
||
252 | System.Diagnostics.Debug.WriteLine(attfile.FileName); |
||
253 | if (!doc.AttFiles.Any(x => x.FileID == attfile.FileID)) |
||
254 | { |
||
255 | e8a86b9b | yoush97 | switch (attfile.Category) |
256 | { |
||
257 | case "toreview": |
||
258 | doc.ToCapture++; |
||
259 | break; |
||
260 | case "frreview": |
||
261 | doc.FrCapture++; |
||
262 | break; |
||
263 | f4230b40 | yoush97 | //case "prodvalidation": |
264 | // doc.ProdCapture++; |
||
265 | // break; |
||
266 | //case "clientvalidation": |
||
267 | // doc.ClientCapture++; |
||
268 | // break; |
||
269 | case "id2work": |
||
270 | doc.ID2Capture++; |
||
271 | e8a86b9b | yoush97 | break; |
272 | } |
||
273 | |||
274 | 08499f5f | taeseongkim | doc.AttFiles.Add(attfile); |
275 | } |
||
276 | e458a996 | taeseongkim | } |
277 | |||
278 | return doc; |
||
279 | |||
280 | a37dc9a7 | taeseongkim | }, dynamicParameters, splitOn: "DocID,FileID,PROJECT_NO").Distinct(); |
281 | 7066b8a9 | yoush97 | |
282 | 82705273 | yoush97 | int totalCount = dynamicParameters.Get<int>("Total"); |
283 | 7066b8a9 | yoush97 | |
284 | 82705273 | yoush97 | return (ret, totalCount); |
285 | } |
||
286 | catch (Exception ex) |
||
287 | { |
||
288 | throw ex; |
||
289 | } |
||
290 | 5898479a | yoush97 | } |
291 | 482f6326 | yoush97 | |
292 | ff990784 | yoush97 | public int ExistsDocument(string projectGroupID, List<string> newDwgNos) |
293 | { |
||
294 | 9107c43b | yoush97 | int existCount = 0; |
295 | ff990784 | yoush97 | |
296 | 9107c43b | yoush97 | int paramMaxCount = 2000; |
297 | int execCount = (newDwgNos.Count / paramMaxCount) + 1; |
||
298 | ff990784 | yoush97 | |
299 | 9107c43b | yoush97 | for (int i = 0; i < execCount; i++) |
300 | { |
||
301 | var dynamicParameters = new DynamicParameters(); |
||
302 | StringBuilder sbWhere = new StringBuilder(); |
||
303 | var parameters = new Dictionary<string, object>(); |
||
304 | if (!string.IsNullOrEmpty(projectGroupID)) |
||
305 | ff990784 | yoush97 | { |
306 | 9107c43b | yoush97 | sbWhere.Append(" and doc.RefProjectCode in (select Code from dbo.Projects where ParentID=@RefGroupID) "); |
307 | parameters.Add("RefGroupID", projectGroupID); |
||
308 | ff990784 | yoush97 | } |
309 | |||
310 | 9107c43b | yoush97 | var limitDwgNos = newDwgNos.Skip(paramMaxCount * i).Take(paramMaxCount).ToList(); |
311 | sbWhere.Append($@" and doc.DocumentNo in @limitDwgNos "); |
||
312 | parameters.Add("limitDwgNos", limitDwgNos); |
||
313 | |||
314 | try |
||
315 | { |
||
316 | string query = $@" |
||
317 | ff990784 | yoush97 | select count(*) cnt |
318 | from dbo.Documents doc |
||
319 | where doc.IsDeleted=0 {sbWhere}"; |
||
320 | |||
321 | 9107c43b | yoush97 | if (parameters.Count > 0) |
322 | { |
||
323 | dynamicParameters.AddDynamicParams(parameters); |
||
324 | } |
||
325 | |||
326 | existCount += ExecuteScalar<int>(query, dynamicParameters); |
||
327 | } |
||
328 | catch (Exception ex) |
||
329 | ff990784 | yoush97 | { |
330 | 9107c43b | yoush97 | throw ex; |
331 | ff990784 | yoush97 | } |
332 | } |
||
333 | 9107c43b | yoush97 | |
334 | return existCount; |
||
335 | ff990784 | yoush97 | } |
336 | |||
337 | f074a104 | yoush97 | public bool SetDocumentData(string projectGroupID, List<Documents> docList, List<string> delDocList, string userId) |
338 | 482f6326 | yoush97 | { |
339 | bool isSuccess = false; |
||
340 | |||
341 | try |
||
342 | { |
||
343 | d2d4f84b | yoush97 | using (var transaction = base.BeginTransaction()) |
344 | 482f6326 | yoush97 | { |
345 | 709c1971 | yoush97 | string query = string.Empty; |
346 | |||
347 | if (delDocList.Count > 0) |
||
348 | 482f6326 | yoush97 | { |
349 | 993feace | yoush97 | int paramMaxCount = 2000; |
350 | int execCount = (delDocList.Count / paramMaxCount) + 1; |
||
351 | 709c1971 | yoush97 | |
352 | 993feace | yoush97 | for (int i = 0; i < execCount; i++) |
353 | 709c1971 | yoush97 | { |
354 | 993feace | yoush97 | var dynamicParameters = new DynamicParameters(); |
355 | StringBuilder sbWhere = new StringBuilder(); |
||
356 | var parameters = new Dictionary<string, object>(); |
||
357 | |||
358 | parameters.Add("DeletedUser", userId); |
||
359 | |||
360 | f074a104 | yoush97 | var limitDwgNos = delDocList.Skip(paramMaxCount * i).Take(paramMaxCount).ToList(); |
361 | 39938acd | yoush97 | sbWhere.Append($@" and DocID in @limitDwgNos "); |
362 | 993feace | yoush97 | parameters.Add("limitDwgNos", limitDwgNos); |
363 | |||
364 | 53fde692 | yoush97 | query = $@" |
365 | 74aa670a | yoush97 | update dbo.Documents |
366 | set IsDeleted=1 |
||
367 | 993feace | yoush97 | ,DeletedDate=getdate() |
368 | 54977253 | yoush97 | ,DeletedUser=@DeletedUser |
369 | 39938acd | yoush97 | where IsDeleted=0 {sbWhere}"; |
370 | 993feace | yoush97 | if (parameters.Count > 0) |
371 | { |
||
372 | dynamicParameters.AddDynamicParams(parameters); |
||
373 | } |
||
374 | |||
375 | base.Execute(query, dynamicParameters, transaction); |
||
376 | 709c1971 | yoush97 | } |
377 | } |
||
378 | 482f6326 | yoush97 | |
379 | foreach (Documents doc in docList) |
||
380 | { |
||
381 | if (string.IsNullOrEmpty(doc.DocID)) |
||
382 | { |
||
383 | 54977253 | yoush97 | doc.RegisteredUser = userId; |
384 | 993feace | yoush97 | doc.ModifiedUser = userId; |
385 | |||
386 | query = $@" |
||
387 | 39938acd | yoush97 | if exists(select * from dbo.Documents where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo and IsDeleted=0) |
388 | 993feace | yoush97 | begin |
389 | --update |
||
390 | update dbo.Documents |
||
391 | set RevisonNo=case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
||
392 | ,System=@System |
||
393 | ,SubSystemCode=@SubSystemCode |
||
394 | ,JobLevel=@JobLevel |
||
395 | ,PersonInCharge=@PersonInCharge |
||
396 | ,ModifiedDate=getdate() |
||
397 | ,ModifiedUser=@ModifiedUser |
||
398 | ,ToIsDiscussion=@ToIsDiscussion |
||
399 | ,ToRemarks=@ToRemarks |
||
400 | ,ToCreator=@ToCreator |
||
401 | ,FrReviewStatus=@FrReviewStatus |
||
402 | ,FrRemarks=@FrRemarks |
||
403 | ,FrCreator=@FrCreator |
||
404 | ,ID2StartDate=@ID2StartDate |
||
405 | ,ID2EndDate=@ID2EndDate |
||
406 | ,ID2Status=@ID2Status |
||
407 | ,ID2Issues=@ID2Issues |
||
408 | ,ReplyModifications=@ReplyModifications |
||
409 | ,ReplyRequester=@ReplyRequester |
||
410 | ,IsConvert=@IsConvert |
||
411 | ,AVEVAPersonInCharge=@AVEVAPersonInCharge |
||
412 | ,AVEVAWorker=@AVEVAWorker |
||
413 | ,AVEVAConvertDate=@AVEVAConvertDate |
||
414 | ,AVEVAReviewDate=@AVEVAReviewDate |
||
415 | ,AVEVAWorkDate=@AVEVAWorkDate |
||
416 | ,AVEVAStatus=@AVEVAStatus |
||
417 | ,AVEVAIssues=@AVEVAIssues |
||
418 | ,ProdReviewer=@ProdReviewer |
||
419 | ,ProdIsResult=@ProdIsResult |
||
420 | ,ProdRemarks=@ProdRemarks |
||
421 | ,ClientReviewer=@ClientReviewer |
||
422 | ,ClientIsResult=@ClientIsResult |
||
423 | ,ClientRemarks=@ClientRemarks |
||
424 | ,DTIsGateWay=@DTIsGateWay |
||
425 | ,DTIsImport=@DTIsImport |
||
426 | ,DTIsRegSystem=@DTIsRegSystem |
||
427 | ,DTRemarks=@DTRemarks |
||
428 | 39938acd | yoush97 | where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo and IsDeleted=0 |
429 | 993feace | yoush97 | |
430 | if @@rowcount > 0 |
||
431 | begin |
||
432 | 39938acd | yoush97 | select @DocID |
433 | 993feace | yoush97 | end |
434 | else |
||
435 | begin |
||
436 | select '' |
||
437 | end |
||
438 | end |
||
439 | else |
||
440 | begin |
||
441 | --insert |
||
442 | declare @tbdoc table(docid varchar(36)) |
||
443 | insert into dbo.Documents |
||
444 | ( |
||
445 | DocID |
||
446 | ,DocumentNo |
||
447 | ,RevisonNo |
||
448 | ,System |
||
449 | ,SubSystemCode |
||
450 | ,RefProjectCode |
||
451 | ,JobLevel |
||
452 | ,PersonInCharge |
||
453 | ,RegisteredDate |
||
454 | ,RegisteredUser |
||
455 | ,ToIsDiscussion |
||
456 | ,ToRemarks |
||
457 | ,ToCreator |
||
458 | ,FrReviewStatus |
||
459 | ,FrRemarks |
||
460 | ,FrCreator |
||
461 | ,ID2StartDate |
||
462 | ,ID2EndDate |
||
463 | ,ID2Status |
||
464 | ,ID2Issues |
||
465 | ,ReplyModifications |
||
466 | ,ReplyRequester |
||
467 | ,IsConvert |
||
468 | ,AVEVAPersonInCharge |
||
469 | ,AVEVAWorker |
||
470 | ,AVEVAConvertDate |
||
471 | ,AVEVAReviewDate |
||
472 | ,AVEVAWorkDate |
||
473 | ,AVEVAStatus |
||
474 | ,AVEVAIssues |
||
475 | ,ProdReviewer |
||
476 | ,ProdIsResult |
||
477 | ,ProdRemarks |
||
478 | ,ClientReviewer |
||
479 | ,ClientIsResult |
||
480 | ,ClientRemarks |
||
481 | ,DTIsGateWay |
||
482 | ,DTIsImport |
||
483 | ,DTIsRegSystem |
||
484 | ,DTRemarks |
||
485 | ) |
||
486 | output inserted.DocID into @tbdoc |
||
487 | values |
||
488 | ( |
||
489 | lower(newid()) |
||
490 | ,@DocumentNo |
||
491 | ,case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
||
492 | ,@System |
||
493 | ,@SubSystemCode |
||
494 | ,@RefProjectCode |
||
495 | ,@JobLevel |
||
496 | ,@PersonInCharge |
||
497 | ,getdate() |
||
498 | ,@RegisteredUser |
||
499 | ,@ToIsDiscussion |
||
500 | ,@ToRemarks |
||
501 | ,@ToCreator |
||
502 | ,@FrReviewStatus |
||
503 | ,@FrRemarks |
||
504 | ,@FrCreator |
||
505 | ,@ID2StartDate |
||
506 | ,@ID2EndDate |
||
507 | ,@ID2Status |
||
508 | ,@ID2Issues |
||
509 | ,@ReplyModifications |
||
510 | ,@ReplyRequester |
||
511 | ,@IsConvert |
||
512 | ,@AVEVAPersonInCharge |
||
513 | ,@AVEVAWorker |
||
514 | ,@AVEVAConvertDate |
||
515 | ,@AVEVAReviewDate |
||
516 | ,@AVEVAWorkDate |
||
517 | ,@AVEVAStatus |
||
518 | ,@AVEVAIssues |
||
519 | ,@ProdReviewer |
||
520 | ,@ProdIsResult |
||
521 | ,@ProdRemarks |
||
522 | ,@ClientReviewer |
||
523 | ,@ClientIsResult |
||
524 | ,@ClientRemarks |
||
525 | ,@DTIsGateWay |
||
526 | ,@DTIsImport |
||
527 | ,@DTIsRegSystem |
||
528 | ,@DTRemarks |
||
529 | ) |
||
530 | |||
531 | if @@rowcount > 0 |
||
532 | begin |
||
533 | select docid from @tbdoc |
||
534 | end |
||
535 | else |
||
536 | begin |
||
537 | select '' |
||
538 | end |
||
539 | end"; |
||
540 | 482f6326 | yoush97 | } |
541 | else |
||
542 | { |
||
543 | 54977253 | yoush97 | doc.ModifiedUser = userId; |
544 | 482f6326 | yoush97 | query = $@" |
545 | update dbo.Documents |
||
546 | 0a6036cb | yoush97 | set RevisonNo=case when isnull(@RevisonNo,'')='' then '0' else @RevisonNo end |
547 | 79d7836e | yoush97 | ,System=@System |
548 | ,SubSystemCode=@SubSystemCode |
||
549 | 54977253 | yoush97 | ,JobLevel=@JobLevel |
550 | ,PersonInCharge=@PersonInCharge |
||
551 | ,ModifiedDate=getdate() |
||
552 | ,ModifiedUser=@ModifiedUser |
||
553 | ,ToIsDiscussion=@ToIsDiscussion |
||
554 | ,ToRemarks=@ToRemarks |
||
555 | ,ToCreator=@ToCreator |
||
556 | ,FrReviewStatus=@FrReviewStatus |
||
557 | ,FrRemarks=@FrRemarks |
||
558 | ,FrCreator=@FrCreator |
||
559 | ,ID2StartDate=@ID2StartDate |
||
560 | ,ID2EndDate=@ID2EndDate |
||
561 | ,ID2Status=@ID2Status |
||
562 | ,ID2Issues=@ID2Issues |
||
563 | cb2e1138 | yoush97 | ,ReplyModifications=@ReplyModifications |
564 | ,ReplyRequester=@ReplyRequester |
||
565 | ,IsConvert=@IsConvert |
||
566 | ,AVEVAPersonInCharge=@AVEVAPersonInCharge |
||
567 | ,AVEVAWorker=@AVEVAWorker |
||
568 | 54977253 | yoush97 | ,AVEVAConvertDate=@AVEVAConvertDate |
569 | ,AVEVAReviewDate=@AVEVAReviewDate |
||
570 | ab3c1c74 | yoush97 | ,AVEVAWorkDate=@AVEVAWorkDate |
571 | 54977253 | yoush97 | ,AVEVAStatus=@AVEVAStatus |
572 | ,AVEVAIssues=@AVEVAIssues |
||
573 | ,ProdReviewer=@ProdReviewer |
||
574 | ,ProdIsResult=@ProdIsResult |
||
575 | ,ProdRemarks=@ProdRemarks |
||
576 | ,ClientReviewer=@ClientReviewer |
||
577 | ,ClientIsResult=@ClientIsResult |
||
578 | ,ClientRemarks=@ClientRemarks |
||
579 | ,DTIsGateWay=@DTIsGateWay |
||
580 | ,DTIsImport=@DTIsImport |
||
581 | ,DTIsRegSystem=@DTIsRegSystem |
||
582 | ,DTRemarks=@DTRemarks |
||
583 | b1591ae6 | yoush97 | where DocID=@DocID |
584 | |||
585 | if @@rowcount > 0 |
||
586 | begin |
||
587 | select @DocID |
||
588 | end |
||
589 | else |
||
590 | begin |
||
591 | select '' |
||
592 | end;"; |
||
593 | } |
||
594 | string refID = base.QueryFirstOrDefault<string>(query, doc, transaction); |
||
595 | |||
596 | if (doc.AttFiles != null && doc.AttFiles.Count > 0) |
||
597 | { |
||
598 | string attDelIDList = string.Join("','", doc.AttFiles.Where(x => !string.IsNullOrEmpty(x.FileID)).Select(x => x.FileID).ToList()); |
||
599 | |||
600 | if (!string.IsNullOrEmpty(refID) && attDelIDList.Length > 0) |
||
601 | { |
||
602 | query = $@" |
||
603 | delete from dbo.AttachFIles |
||
604 | where RefID=@RefID and FileID in ('{attDelIDList}');"; |
||
605 | base.Execute(query, new { RefID = refID }, transaction); |
||
606 | } |
||
607 | |||
608 | foreach (AttFileInfo attFile in doc.AttFiles) |
||
609 | { |
||
610 | e5ade387 | yoush97 | if (string.IsNullOrEmpty(attFile.RefID)) |
611 | { |
||
612 | attFile.RefID = refID; |
||
613 | attFile.Creator = userId; |
||
614 | b1591ae6 | yoush97 | |
615 | e5ade387 | yoush97 | query = $@" |
616 | b1591ae6 | yoush97 | insert into dbo.AttachFIles (FileID,RefID,Category,FileType,FileName,FilePath,FileExtension,FileData,Creator) |
617 | values |
||
618 | ( |
||
619 | lower(newid()) |
||
620 | ,@RefID |
||
621 | ,@Category |
||
622 | ,@FileType |
||
623 | ,@FileName |
||
624 | ,@FilePath |
||
625 | ,@FileExtension |
||
626 | ,@FileData |
||
627 | ,@Creator |
||
628 | )"; |
||
629 | |||
630 | e5ade387 | yoush97 | base.Execute(query, attFile, transaction); |
631 | } |
||
632 | b1591ae6 | yoush97 | } |
633 | 482f6326 | yoush97 | } |
634 | } |
||
635 | |||
636 | transaction.Commit(); |
||
637 | isSuccess = true; |
||
638 | } |
||
639 | } |
||
640 | catch (Exception ex) |
||
641 | { |
||
642 | throw ex; |
||
643 | } |
||
644 | |||
645 | return isSuccess; |
||
646 | } |
||
647 | 978488b0 | yoush97 | |
648 | public Documents SetDocumentDataField(Documents doc, string userId) |
||
649 | { |
||
650 | Documents resultData = null; |
||
651 | |||
652 | try |
||
653 | { |
||
654 | using (var transaction = base.BeginTransaction()) |
||
655 | { |
||
656 | string query = string.Empty; |
||
657 | |||
658 | if (!string.IsNullOrEmpty(doc.DocID)) |
||
659 | { |
||
660 | StringBuilder sbSet = new StringBuilder(); |
||
661 | var parameters = new Dictionary<string, object>(); |
||
662 | |||
663 | #region Update 할 목록 |
||
664 | if (doc.ID2StartDate != null) |
||
665 | { |
||
666 | 4b8d9ad9 | yoush97 | sbSet.Append(" ,ID2StartDate=(case when ID2StartDate is null then @DateTimeNow else ID2StartDate end) "); |
667 | 978488b0 | yoush97 | parameters.Add("ID2StartDate", doc.ID2StartDate); |
668 | } |
||
669 | 4b8d9ad9 | yoush97 | |
670 | if (doc.Worker != null) |
||
671 | { |
||
672 | sbSet.Append(" ,Worker=@Worker "); |
||
673 | parameters.Add("Worker", doc.Worker); |
||
674 | } |
||
675 | 978488b0 | yoush97 | #endregion |
676 | |||
677 | if (parameters.Count > 0) |
||
678 | { |
||
679 | sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
||
680 | parameters.Add("ModifiedUser", userId); |
||
681 | |||
682 | 54977253 | yoush97 | parameters.Add("DocID", doc.DocID); |
683 | |||
684 | 978488b0 | yoush97 | query = $@" |
685 | declare @DateTimeNow datetime |
||
686 | set @DateTimeNow = getdate() |
||
687 | |||
688 | update dbo.Documents |
||
689 | set ModifiedDate=@DateTimeNow {sbSet} |
||
690 | where [DocID]=@DocID |
||
691 | |||
692 | if @@rowcount > 0 |
||
693 | begin |
||
694 | fe310cac | yoush97 | select * from dbo.Documents where DocID=@DocID |
695 | 978488b0 | yoush97 | end |
696 | else |
||
697 | begin |
||
698 | fe310cac | yoush97 | select * from dbo.Documents where 1=2 |
699 | 978488b0 | yoush97 | end;"; |
700 | resultData = base.QueryFirstOrDefault<Documents>(query, parameters, transaction); |
||
701 | } |
||
702 | } |
||
703 | |||
704 | transaction.Commit(); |
||
705 | } |
||
706 | } |
||
707 | catch (Exception ex) |
||
708 | { |
||
709 | throw ex; |
||
710 | } |
||
711 | |||
712 | return resultData; |
||
713 | } |
||
714 | fe57f64a | yoush97 | |
715 | 54977253 | yoush97 | public bool SetDocumentDatasField(List<Documents> docs, string userId) |
716 | { |
||
717 | bool isSuccess = false; |
||
718 | |||
719 | try |
||
720 | { |
||
721 | using (var transaction = base.BeginTransaction()) |
||
722 | { |
||
723 | foreach (Documents doc in docs) |
||
724 | { |
||
725 | string query = string.Empty; |
||
726 | |||
727 | if (!string.IsNullOrEmpty(doc.DocID)) |
||
728 | { |
||
729 | StringBuilder sbSet = new StringBuilder(); |
||
730 | var parameters = new Dictionary<string, object>(); |
||
731 | |||
732 | #region Update 할 목록 |
||
733 | if (doc.ID2EndDate != null) |
||
734 | { |
||
735 | sbSet.Append(" ,ID2EndDate=@ID2EndDate "); |
||
736 | parameters.Add("ID2EndDate", doc.ID2EndDate); |
||
737 | } |
||
738 | #endregion |
||
739 | |||
740 | if (parameters.Count > 0) |
||
741 | { |
||
742 | sbSet.Append(" ,ModifiedUser=@ModifiedUser "); |
||
743 | parameters.Add("ModifiedUser", userId); |
||
744 | |||
745 | parameters.Add("DocID", doc.DocID); |
||
746 | |||
747 | query = $@" |
||
748 | update dbo.Documents |
||
749 | set ModifiedDate=getdate() {sbSet} |
||
750 | where [DocID]=@DocID;"; |
||
751 | e458a996 | taeseongkim | base.Execute(query, parameters, transaction); |
752 | 54977253 | yoush97 | } |
753 | } |
||
754 | } |
||
755 | transaction.Commit(); |
||
756 | isSuccess = true; |
||
757 | } |
||
758 | } |
||
759 | catch (Exception ex) |
||
760 | { |
||
761 | throw ex; |
||
762 | } |
||
763 | |||
764 | return isSuccess; |
||
765 | } |
||
766 | |||
767 | fe57f64a | yoush97 | |
768 | //ID2 |
||
769 | public IEnumerable<ID2Drawings> GetID2DrawingsByProject(ID2ProjectInfo id2Info) |
||
770 | { |
||
771 | 82705273 | yoush97 | try |
772 | { |
||
773 | string query = $@" |
||
774 | fe57f64a | yoush97 | select @Name PROJECTNAME |
775 | ,dw.[UID], dw.[NAME], left(dw.[NAME], len(dw.[NAME]) - dw.lastidx) DOCNAME |
||
776 | ,case when rtrim(ltrim(isnull(convert(varchar, dw.[DATETIME]),''))) = '' then null else convert(datetime, convert(varchar, dw.[DATETIME])) end [DATETIME] |
||
777 | ,dw.OCCUPIED, dw.[Image] |
||
778 | from |
||
779 | ( |
||
780 | select [UID], [NAME], [DATETIME], OCCUPIED, [Image], charindex('.', reverse([NAME])) lastidx |
||
781 | from dbo.Drawings |
||
782 | ) dw;"; |
||
783 | 82705273 | yoush97 | return Query<ID2Drawings>(query, id2Info); |
784 | } |
||
785 | catch (Exception ex) |
||
786 | { |
||
787 | throw ex; |
||
788 | } |
||
789 | fe57f64a | yoush97 | } |
790 | 39938acd | yoush97 | |
791 | |||
792 | //Transactions |
||
793 | public int GetTranKey(string userId, string projectID) |
||
794 | { |
||
795 | int result = -1; |
||
796 | |||
797 | try |
||
798 | { |
||
799 | var dynamicParameters = new DynamicParameters(); |
||
800 | |||
801 | var parameters = new Dictionary<string, object>() |
||
802 | { |
||
803 | { "UserId", userId }, |
||
804 | { "ProjectID", projectID } |
||
805 | }; |
||
806 | |||
807 | dynamicParameters.AddDynamicParams(parameters); |
||
808 | |||
809 | using (var transaction = base.BeginTransaction()) |
||
810 | { |
||
811 | string query = $@" |
||
812 | --log master 입력 |
||
813 | insert into dbo.Transactions (UserId, ProjectID) |
||
814 | values (@UserId, @ProjectID); |
||
815 | select scope_identity();"; |
||
816 | |||
817 | result = base.ExecuteScalar<int>(query, dynamicParameters, transaction); |
||
818 | |||
819 | transaction.Commit(); |
||
820 | } |
||
821 | } |
||
822 | catch (Exception ex) |
||
823 | { |
||
824 | throw ex; |
||
825 | } |
||
826 | |||
827 | return result; |
||
828 | } |
||
829 | |||
830 | public bool SetTran(int seq, bool isMgt, bool isStart, int itemCount, int markusItemCount) |
||
831 | { |
||
832 | bool result = false; |
||
833 | |||
834 | try |
||
835 | { |
||
836 | var dynamicParameters = new DynamicParameters(); |
||
837 | var parameters = new Dictionary<string, object>() |
||
838 | { |
||
839 | { "Seq", seq }, |
||
840 | { "ItemCount", itemCount }, |
||
841 | { "MarkusItemCount", markusItemCount } |
||
842 | }; |
||
843 | dynamicParameters.AddDynamicParams(parameters); |
||
844 | StringBuilder sbWhere = new StringBuilder(); |
||
845 | if (isMgt) |
||
846 | { |
||
847 | if (isStart) |
||
848 | { |
||
849 | sbWhere.Append("StartDate=getdate(), ItemCount=@ItemCount"); |
||
850 | } |
||
851 | else |
||
852 | { |
||
853 | sbWhere.Append("EndDate=getdate()"); |
||
854 | } |
||
855 | |||
856 | } |
||
857 | else |
||
858 | { |
||
859 | if (isStart) |
||
860 | { |
||
861 | sbWhere.Append("MarkusStartDate=getdate(), MarkusItemCount=@MarkusItemCount"); |
||
862 | } |
||
863 | else |
||
864 | { |
||
865 | sbWhere.Append("MarkusEndDate=getdate()"); |
||
866 | } |
||
867 | } |
||
868 | |||
869 | using (var transaction = base.BeginTransaction()) |
||
870 | { |
||
871 | string query = $@" |
||
872 | update dbo.Transactions |
||
873 | set {sbWhere} |
||
874 | where Seq=@Seq;"; |
||
875 | base.Execute(query, dynamicParameters, transaction); |
||
876 | |||
877 | transaction.Commit(); |
||
878 | |||
879 | result = true; |
||
880 | } |
||
881 | } |
||
882 | catch (Exception ex) |
||
883 | { |
||
884 | throw ex; |
||
885 | } |
||
886 | |||
887 | return result; |
||
888 | } |
||
889 | |||
890 | public string GetTranData(int seq) |
||
891 | { |
||
892 | try |
||
893 | { |
||
894 | var dynamicParameters = new DynamicParameters(); |
||
895 | var parameters = new Dictionary<string, object>() |
||
896 | { |
||
897 | { "Seq", seq } |
||
898 | }; |
||
899 | dynamicParameters.AddDynamicParams(parameters); |
||
900 | |||
901 | string query = $@" |
||
902 | select * |
||
903 | from dbo.Transactions |
||
904 | where Seq=@Seq"; |
||
905 | |||
906 | IEnumerable<dynamic> rows = base.Query<dynamic>(query, dynamicParameters); |
||
907 | |||
908 | return this.ToSerializeData(rows); |
||
909 | } |
||
910 | catch (Exception ex) |
||
911 | { |
||
912 | throw ex; |
||
913 | } |
||
914 | } |
||
915 | |||
916 | public string ToSerializeData(IEnumerable<dynamic> items) |
||
917 | { |
||
918 | List<Dictionary<string, object>> list = new List<Dictionary<string, object>>(); |
||
919 | |||
920 | if (items == null) return string.Empty; |
||
921 | var datas = items.ToArray(); |
||
922 | if (datas.Length == 0) return string.Empty; |
||
923 | |||
924 | foreach (var data in datas) |
||
925 | { |
||
926 | var dicItem = new Dictionary<string, object>(); |
||
927 | foreach (var pair in ((IDictionary<string, object>)data)) |
||
928 | { |
||
929 | dicItem.Add(pair.Key, pair.Value); |
||
930 | } |
||
931 | list.Add(dicItem); |
||
932 | } |
||
933 | |||
934 | return JsonConvert.SerializeObject(list); |
||
935 | } |
||
936 | |||
937 | public IEnumerable<Documents> GetTrDocuments(int seq) |
||
938 | { |
||
939 | var dynamicParameters = new DynamicParameters(); |
||
940 | StringBuilder sbWhere = new StringBuilder(); |
||
941 | var parameters = new Dictionary<string, object>() |
||
942 | { |
||
943 | { "Seq", seq } |
||
944 | }; |
||
945 | dynamicParameters.AddDynamicParams(parameters); |
||
946 | |||
947 | try |
||
948 | { |
||
949 | string query = $@" |
||
950 | declare @CreatedDate datetime |
||
951 | declare @EndDate datetime |
||
952 | declare @ProjectGroupID varchar(36) |
||
953 | |||
954 | select top 1 @CreatedDate=CreatedDate, @EndDate=EndDate, @ProjectGroupID=ProjectID |
||
955 | from dbo.Transactions |
||
956 | where Seq=@Seq |
||
957 | |||
958 | select RefProjectCode, DocumentNo |
||
959 | from dbo.Documents |
||
960 | where RefProjectCode in (select Code from dbo.Projects where ParentID=@ProjectGroupID) |
||
961 | 8c7fbec1 | yoush97 | and RegisteredDate between @CreatedDate and @EndDate"; |
962 | 39938acd | yoush97 | |
963 | if (parameters.Count > 0) |
||
964 | { |
||
965 | dynamicParameters.AddDynamicParams(parameters); |
||
966 | } |
||
967 | |||
968 | return Query<Documents>(query, dynamicParameters); |
||
969 | } |
||
970 | catch (Exception ex) |
||
971 | { |
||
972 | throw ex; |
||
973 | } |
||
974 | } |
||
975 | 9096bc6d | taeseongkim | |
976 | public class MarkusConvert |
||
977 | { |
||
978 | public string PROJECT_NO { get; set; } |
||
979 | public string DOCUMENT_ID { get; set; } |
||
980 | public int STATUS { get; set; } |
||
981 | } |
||
982 | |||
983 | 5898479a | yoush97 | } |
984 | d2d4f84b | yoush97 | } |