hytos / ID2.Manager / ID2.Manager.Dapper / Repository / MarkusRepository.cs @ 45322477
이력 | 보기 | 이력해설 | 다운로드 (13.6 KB)
1 |
using Dapper; |
---|---|
2 |
using DapperParameters; |
3 |
using ID2.Manager.Dapper.Entities; |
4 |
using ID2.Manager.Data.Models; |
5 |
using System; |
6 |
using System.Collections.Generic; |
7 |
using System.Data; |
8 |
using System.Linq; |
9 |
using System.Text; |
10 |
using System.Threading.Tasks; |
11 |
|
12 |
namespace ID2.Manager.Dapper.Repository |
13 |
{ |
14 |
public class MarkusRepository : BaseRepository |
15 |
{ |
16 |
public MarkusRepository(string connectionStr) : base(connectionStr) { } |
17 |
|
18 |
public bool Insert(string ProjectNo,string Name) |
19 |
{ |
20 |
bool result = false; |
21 |
|
22 |
var convertDocID = CreateConvertDoc(ProjectNo, Name + ".pdf", Name); |
23 |
|
24 |
if (convertDocID != null) |
25 |
{ |
26 |
var documentItemID = CreateOrUPdateDocItem( |
27 |
new DOCUMENTITEM |
28 |
{ |
29 |
REVISION = "0", |
30 |
PROJECT_NO = ProjectNo, |
31 |
DOCUMENT_NO = Name, |
32 |
GROUP_NO = Name, |
33 |
DOCUMENT_NAME = Name, |
34 |
ORIGINAL_FILE = Name, |
35 |
DOCUMENT_ID = Name |
36 |
}); |
37 |
|
38 |
if (documentItemID != null) |
39 |
{ |
40 |
result = true; |
41 |
} |
42 |
} |
43 |
|
44 |
return result; |
45 |
} |
46 |
|
47 |
public bool InsertOrUpdateUsers(MEMBER member) |
48 |
{ |
49 |
bool result = false; |
50 |
|
51 |
try |
52 |
{ |
53 |
var oMember = GetMEMBER(member.ID); |
54 |
|
55 |
if(oMember?.Count() > 0) |
56 |
{ |
57 |
var tran = BeginTransaction(); |
58 |
|
59 |
string SQL = "UPDATE MEMBER" + |
60 |
" SET " + |
61 |
"DEPARTMENT = @DEPARTMENT" + |
62 |
",NAME = @NAME" + |
63 |
",POSITION = @POSITION" + |
64 |
",EMAIL_ADDRESS = @EMAIL_ADDRESS" + |
65 |
",PASSWORD = @PASSWORD" + |
66 |
",COMPANY = @COMPANY" + |
67 |
",CREATE_DATETIME = @CREATE_DATETIME" + |
68 |
",MODIFIED_DATETIME = @MODIFIED_DATETIME" + |
69 |
",ISLICENSE = @ISLICENSE" + |
70 |
" WHERE ID = @ID"; |
71 |
|
72 |
|
73 |
var parameters = new DynamicParameters(); |
74 |
parameters.Add("@ID", member.ID); |
75 |
parameters.Add("@DEPARTMENT", member.DEPARTMENT); |
76 |
parameters.Add("@NAME", member.NAME); |
77 |
parameters.Add("@POSITION", member.POSITION); |
78 |
parameters.Add("@EMAIL_ADDRESS", member.EMAIL_ADDRESS); |
79 |
parameters.Add("@PASSWORD", member.PASSWORD); |
80 |
parameters.Add("@COMPANY", member.COMPANY); |
81 |
parameters.Add("@CREATE_DATETIME", member.CREATE_DATETIME); |
82 |
parameters.Add("@MODIFIED_DATETIME", member.MODIFIED_DATETIME); |
83 |
parameters.Add("@ISLICENSE", member.ISLICENSE); |
84 |
|
85 |
var rowsAffected = base.Execute(SQL, parameters, tran); |
86 |
|
87 |
|
88 |
if (rowsAffected < 0) |
89 |
{ |
90 |
result = false; |
91 |
} |
92 |
else |
93 |
{ |
94 |
tran.Commit(); |
95 |
} |
96 |
} |
97 |
else |
98 |
{ |
99 |
var tran = BeginTransaction(); |
100 |
|
101 |
string SQL = "INSERT INTO MEMBER (ID,DEPARTMENT,NAME,POSITION,EMAIL_ADDRESS,PASSWORD,COMPANY,CREATE_DATETIME,MODIFIED_DATETIME,ISLICENSE) " + |
102 |
"VALUES (@ID,@DEPARTMENT,@NAME,@POSITION,@EMAIL_ADDRESS,@PASSWORD,@COMPANY,@CREATE_DATETIME,@MODIFIED_DATETIME,@ISLICENSE)"; |
103 |
|
104 |
|
105 |
var parameters = new DynamicParameters(); |
106 |
parameters.Add("@ID", member.ID); |
107 |
parameters.Add("@DEPARTMENT", member.DEPARTMENT); |
108 |
parameters.Add("@NAME", member.NAME); |
109 |
parameters.Add("@POSITION", member.POSITION); |
110 |
parameters.Add("@EMAIL_ADDRESS", member.EMAIL_ADDRESS); |
111 |
parameters.Add("@PASSWORD", member.PASSWORD); |
112 |
parameters.Add("@COMPANY", member.COMPANY); |
113 |
parameters.Add("@CREATE_DATETIME", member.CREATE_DATETIME); |
114 |
parameters.Add("@MODIFIED_DATETIME", member.MODIFIED_DATETIME); |
115 |
parameters.Add("@ISLICENSE", member.ISLICENSE); |
116 |
|
117 |
var rowsAffected = base.Execute(SQL, parameters, tran); |
118 |
|
119 |
|
120 |
if(rowsAffected < 0) |
121 |
{ |
122 |
result = false; |
123 |
} |
124 |
else |
125 |
{ |
126 |
tran.Commit(); |
127 |
} |
128 |
} |
129 |
} |
130 |
catch (Exception ex) |
131 |
{ |
132 |
throw new Exception($"userId : {member.ID}",ex); |
133 |
} |
134 |
|
135 |
return result; |
136 |
} |
137 |
|
138 |
public bool InsertProperties(string ProjectNo) |
139 |
{ |
140 |
bool result = false; |
141 |
|
142 |
try |
143 |
{ |
144 |
var properties = new[] { "TileSorceStorage", "TileSorcePath" }; |
145 |
|
146 |
foreach (var property in properties) |
147 |
{ |
148 |
var tran = BeginTransaction(); |
149 |
|
150 |
string SQL = "INSERT INTO [dbo].[PROPERTIES] ([TYPE], [PROPERTY], [VALUE])" + |
151 |
" SELECT @TYPE,@ProjectNo, [VALUE]" + |
152 |
" FROM [dbo].[PROPERTIES]" + |
153 |
" WHERE [TYPE] = @TYPE AND [PROPERTY] = 'APAO'" + |
154 |
" AND NOT EXISTS (" + |
155 |
" SELECT 1" + |
156 |
" FROM [dbo].[PROPERTIES]" + |
157 |
" WHERE [TYPE] = @TYPE AND [PROPERTY] = @ProjectNo)"; |
158 |
|
159 |
var parameters = new DynamicParameters(); |
160 |
parameters.Add("@TYPE", property); |
161 |
parameters.Add("@ProjectNo", ProjectNo); |
162 |
|
163 |
var rowsAffected = base.Execute(SQL, parameters, tran); |
164 |
|
165 |
tran.Commit(); |
166 |
} |
167 |
} |
168 |
catch (Exception ex) |
169 |
{ |
170 |
throw new Exception($"InsertProperties : {ProjectNo}", ex); |
171 |
} |
172 |
|
173 |
return result; |
174 |
} |
175 |
|
176 |
public IEnumerable<MEMBER> GetMEMBER(string id) |
177 |
{ |
178 |
string SQL = "SELECT * FROM MEMBER WHERE ID = @ID"; |
179 |
|
180 |
var parameters = new DynamicParameters(); |
181 |
parameters.Add("@ID", id); |
182 |
|
183 |
return base.Query<MEMBER>(SQL, parameters); |
184 |
} |
185 |
|
186 |
public IEnumerable<ConvertDoc> GetConvertDoc(int status,string ProjectNo) |
187 |
{ |
188 |
string SQL = "SELECT * FROM CONVERTER_DOC WHERE STATUS = @STATUS and PROJECT_NO = @PROJECT_NO"; |
189 |
|
190 |
var parameters = new DynamicParameters(); |
191 |
parameters.Add("@STATUS", status); |
192 |
parameters.Add("@PROJECT_NO", ProjectNo); |
193 |
|
194 |
var convertItems = base.Query<ConvertDoc>(SQL, parameters); |
195 |
|
196 |
return convertItems; |
197 |
} |
198 |
|
199 |
public int GetConvertDoc(string ProjectNo,string DOCUMENT_ID) |
200 |
{ |
201 |
string SQL = "SELECT STATUS FROM CONVERTER_DOC WHERE PROJECT_NO = @PROJECT_NO and DOCUMENT_ID = @DOCUMENT_ID"; |
202 |
|
203 |
var parameters = new DynamicParameters(); |
204 |
parameters.Add("@PROJECT_NO", ProjectNo); |
205 |
parameters.Add("@DOCUMENT_ID", DOCUMENT_ID); |
206 |
|
207 |
return base.ExecuteScalar<int>(SQL, parameters); |
208 |
} |
209 |
|
210 |
//public IEnumerable<MarkupText> GetMarkupText(IEnumerable<string> ProjectNoList, IEnumerable<string> DocumentNoList) |
211 |
//{ |
212 |
// string SQL = "GET_MARKUPDATA"; |
213 |
|
214 |
// var parameters = new DynamicParameters(); |
215 |
// parameters.AddTable("@PROJECT_NOs", "VARCHAR_TABLE", ProjectNoList.Select(x=>new VARCHAR_TABLE { ITEM = x })); |
216 |
// parameters.AddTable("@DOCUMENT_IDs", "VARCHAR_TABLE", DocumentNoList.Select(x => new VARCHAR_TABLE { ITEM = x })); |
217 |
|
218 |
// var Items = base.Query<MarkupText>(SQL, parameters,commandType:CommandType.StoredProcedure); |
219 |
|
220 |
// return Items; |
221 |
//} |
222 |
|
223 |
/// <summary> |
224 |
/// 완료 |
225 |
/// </summary> |
226 |
/// <param name="PROJECT_NO"></param> |
227 |
/// <param name="DOCUMENT_URL"></param> |
228 |
/// <param name="DOCUMENT_ID"></param> |
229 |
/// <returns></returns> |
230 |
public string CreateConvertDoc(string PROJECT_NO, string DOCUMENT_URL, string DOCUMENT_ID) |
231 |
{ |
232 |
string result = null; |
233 |
try |
234 |
{ |
235 |
var tran = BeginTransaction(); |
236 |
|
237 |
var parameters = new DynamicParameters(); |
238 |
parameters.Add("@project_no", value: PROJECT_NO); |
239 |
parameters.Add("@document_url", value: DOCUMENT_URL); |
240 |
parameters.Add("@document_id", value: DOCUMENT_ID); |
241 |
parameters.Add("@newid", direction: ParameterDirection.Output,size:int.MaxValue); |
242 |
|
243 |
base.Execute("convert_insert_convertdoc", parameters, transaction: tran, commandType: CommandType.StoredProcedure); |
244 |
|
245 |
tran.Commit(); |
246 |
|
247 |
result = parameters.Get<string>("newid"); |
248 |
|
249 |
|
250 |
} |
251 |
catch (Exception ex) |
252 |
{ |
253 |
throw ex; |
254 |
} |
255 |
return result; |
256 |
} |
257 |
|
258 |
public int UpdateStatusAsync(string ServiceID, string ConvertDocID, int status, int totalPage, int currentPage, string exception) |
259 |
{ |
260 |
int result = 0; |
261 |
var tran = BeginTransaction(); |
262 |
var parameters = new DynamicParameters(); |
263 |
parameters.Add("@service_id", value: ServiceID); |
264 |
parameters.Add("@id", value: ConvertDocID); |
265 |
parameters.Add("@status", value: status); |
266 |
parameters.Add("@total_page", value: totalPage); |
267 |
parameters.Add("@current_page", value: currentPage); |
268 |
parameters.Add("@exception", value: exception); |
269 |
result = base.Execute("convert_update_status", parameters, transaction: tran, commandType: CommandType.StoredProcedure); |
270 |
tran.Commit(); |
271 |
|
272 |
return result; |
273 |
} |
274 |
|
275 |
/// <summary> |
276 |
/// |
277 |
/// </summary> |
278 |
/// <param name="documentItem"></param> |
279 |
/// <returns>Create or Update id</returns> |
280 |
public string CreateOrUPdateDocItem(DOCUMENTITEM documentItem) |
281 |
{ |
282 |
string result = null; |
283 |
|
284 |
var tran = BeginTransaction(); |
285 |
var parameter = new DynamicParameters(); |
286 |
|
287 |
parameter.Add("@revision", documentItem.REVISION); |
288 |
parameter.Add("@document_no", documentItem.DOCUMENT_NO); |
289 |
parameter.Add("@document_name", documentItem.DOCUMENT_NAME); |
290 |
parameter.Add("@original_file", documentItem.ORIGINAL_FILE); |
291 |
parameter.Add("@document_id", documentItem.DOCUMENT_ID); |
292 |
parameter.Add("@project_no", documentItem.PROJECT_NO); |
293 |
parameter.Add("@link", documentItem.Link); |
294 |
parameter.Add("@result_file", documentItem.RESULT_FILE); |
295 |
parameter.Add("@result", documentItem.RESULT); |
296 |
parameter.Add("@group_no", documentItem.GROUP_NO); |
297 |
parameter.Add("@newid", direction: ParameterDirection.Output, size: int.MaxValue); |
298 |
|
299 |
base.Execute("convert_insert_documentitem", parameter, tran, commandType: CommandType.StoredProcedure); |
300 |
|
301 |
tran.Commit(); |
302 |
|
303 |
result = parameter.Get<string>("newid"); |
304 |
|
305 |
|
306 |
return result; |
307 |
} |
308 |
|
309 |
|
310 |
/// <summary> |
311 |
/// test 필요 transaction Commit 이후 parameter.get을 해야 commit이 된다. |
312 |
/// </summary> |
313 |
/// <param name="convertDocID"></param> |
314 |
/// <param name="PageCount"></param> |
315 |
/// <returns></returns> |
316 |
public string CreateDocInfo(string convertDocID, int PageCount) |
317 |
{ |
318 |
string result = ""; |
319 |
var tran = BeginTransaction(); |
320 |
|
321 |
var parameters = new DynamicParameters(); |
322 |
parameters.Add("@convert_id", convertDocID, dbType: DbType.String); |
323 |
parameters.Add("@page_count", PageCount, dbType: DbType.Int32); |
324 |
parameters.Add("@newid", dbType: DbType.String, direction: ParameterDirection.Output, size: 50); |
325 |
parameters.Add("@errorcode", dbType: DbType.Int32, direction: ParameterDirection.Output); |
326 |
parameters.Add("@error", dbType: DbType.String, direction: ParameterDirection.Output, size: 500); |
327 |
|
328 |
base.Execute("convert_insert_docinfo", parameters, tran, commandType: CommandType.StoredProcedure); |
329 |
|
330 |
var errorCode = parameters.Get<int>("errorcode"); |
331 |
var error = parameters.Get<string>("error"); |
332 |
|
333 |
if (errorCode > 0) |
334 |
{ |
335 |
tran.Rollback(); |
336 |
throw new Exception(error); |
337 |
} |
338 |
else |
339 |
{ |
340 |
tran.Commit(); |
341 |
|
342 |
result = parameters.Get<string>("newid"); |
343 |
} |
344 |
|
345 |
return result; |
346 |
} |
347 |
|
348 |
|
349 |
public bool CreateDocPage(IEnumerable<DocPage> docPages) |
350 |
{ |
351 |
bool result = false; |
352 |
|
353 |
try |
354 |
{ |
355 |
var tran = BeginTransaction(); |
356 |
|
357 |
var parameter = new DynamicParameters(); |
358 |
|
359 |
parameter.AddTable< DocPage>("DOCPAGES", "TYPE_INSERT_DOCPAGE", docPages.ToList()); |
360 |
|
361 |
var id = base.Execute("CONVERT_INSERT_DOCPAGE", parameter, tran, commandType: CommandType.StoredProcedure); |
362 |
|
363 |
tran.Commit(); |
364 |
|
365 |
result = true; |
366 |
} |
367 |
catch (Exception ex) |
368 |
{ |
369 |
throw new Exception("DOCPAGERepository CreateAsync error.", ex); |
370 |
} |
371 |
|
372 |
return result; |
373 |
} |
374 |
} |
375 |
|
376 |
internal class VARCHAR_TABLE |
377 |
{ |
378 |
public string ITEM { get; set; } |
379 |
} |
380 |
} |