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