hytos / ID2.Manager / ID2.Manager.Dapper / Repository / MarkusRepository.cs @ e1377864
이력 | 보기 | 이력해설 | 다운로드 (11.8 KB)
1 | 1a88080d | taeseongkim | using Dapper; |
---|---|---|---|
2 | using DapperParameters; |
||
3 | using ID2.Manager.Dapper.Entities; |
||
4 | 0b008ea6 | taeseongkim | using ID2.Manager.Data.Models; |
5 | 1a88080d | taeseongkim | 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 | c112c3c3 | taeseongkim | public bool Insert(string ProjectNo,string Name) |
19 | 1a88080d | taeseongkim | { |
20 | bool result = false; |
||
21 | |||
22 | d1d8c5ea | taeseongkim | var convertDocID = CreateConvertDoc(ProjectNo, Name + ".pdf", Name); |
23 | 1a88080d | taeseongkim | |
24 | if (convertDocID != null) |
||
25 | { |
||
26 | c112c3c3 | taeseongkim | var documentItemID = CreateOrUPdateDocItem( |
27 | 1a88080d | taeseongkim | 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 | d1d8c5ea | taeseongkim | if (documentItemID != null) |
39 | 1a88080d | taeseongkim | { |
40 | result = true; |
||
41 | } |
||
42 | } |
||
43 | |||
44 | return result; |
||
45 | } |
||
46 | |||
47 | 5b086e44 | taeseongkim | public bool InsertOrUpdateUsers(MEMBER member) |
48 | 7298c115 | taeseongkim | { |
49 | bool result = false; |
||
50 | |||
51 | try |
||
52 | { |
||
53 | 5b086e44 | taeseongkim | var oMember = GetMEMBER(member.ID); |
54 | 7298c115 | taeseongkim | |
55 | 5b086e44 | taeseongkim | 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 | 99c0623d | yoush97 | " WHERE ID = @ID"; |
71 | 5b086e44 | taeseongkim | |
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 | 7298c115 | taeseongkim | } |
130 | catch (Exception ex) |
||
131 | { |
||
132 | 5b086e44 | taeseongkim | throw new Exception($"userId : {member.ID}",ex); |
133 | 7298c115 | taeseongkim | } |
134 | |||
135 | return result; |
||
136 | } |
||
137 | |||
138 | 5b086e44 | taeseongkim | public IEnumerable<MEMBER> GetMEMBER(string id) |
139 | { |
||
140 | string SQL = "SELECT * FROM MEMBER WHERE ID = @ID"; |
||
141 | |||
142 | var parameters = new DynamicParameters(); |
||
143 | parameters.Add("@ID", id); |
||
144 | |||
145 | return base.Query<MEMBER>(SQL, parameters); |
||
146 | } |
||
147 | |||
148 | d1d8c5ea | taeseongkim | public IEnumerable<ConvertDoc> GetConvertDoc(int status,string ProjectNo) |
149 | { |
||
150 | string SQL = "SELECT * FROM CONVERTER_DOC WHERE STATUS = @STATUS and PROJECT_NO = @PROJECT_NO"; |
||
151 | |||
152 | var parameters = new DynamicParameters(); |
||
153 | parameters.Add("@STATUS", status); |
||
154 | parameters.Add("@PROJECT_NO", ProjectNo); |
||
155 | |||
156 | var convertItems = base.Query<ConvertDoc>(SQL, parameters); |
||
157 | |||
158 | return convertItems; |
||
159 | } |
||
160 | |||
161 | c7f3eb42 | taeseongkim | //public IEnumerable<MarkupText> GetMarkupText(IEnumerable<string> ProjectNoList, IEnumerable<string> DocumentNoList) |
162 | //{ |
||
163 | // string SQL = "GET_MARKUPDATA"; |
||
164 | 0b008ea6 | taeseongkim | |
165 | c7f3eb42 | taeseongkim | // var parameters = new DynamicParameters(); |
166 | // parameters.AddTable("@PROJECT_NOs", "VARCHAR_TABLE", ProjectNoList.Select(x=>new VARCHAR_TABLE { ITEM = x })); |
||
167 | // parameters.AddTable("@DOCUMENT_IDs", "VARCHAR_TABLE", DocumentNoList.Select(x => new VARCHAR_TABLE { ITEM = x })); |
||
168 | 0b008ea6 | taeseongkim | |
169 | c7f3eb42 | taeseongkim | // var Items = base.Query<MarkupText>(SQL, parameters,commandType:CommandType.StoredProcedure); |
170 | 0b008ea6 | taeseongkim | |
171 | c7f3eb42 | taeseongkim | // return Items; |
172 | //} |
||
173 | 0b008ea6 | taeseongkim | |
174 | 1a88080d | taeseongkim | /// <summary> |
175 | /// 완료 |
||
176 | /// </summary> |
||
177 | /// <param name="PROJECT_NO"></param> |
||
178 | /// <param name="DOCUMENT_URL"></param> |
||
179 | /// <param name="DOCUMENT_ID"></param> |
||
180 | /// <returns></returns> |
||
181 | c112c3c3 | taeseongkim | public string CreateConvertDoc(string PROJECT_NO, string DOCUMENT_URL, string DOCUMENT_ID) |
182 | 1a88080d | taeseongkim | { |
183 | string result = null; |
||
184 | try |
||
185 | { |
||
186 | var tran = BeginTransaction(); |
||
187 | |||
188 | var parameters = new DynamicParameters(); |
||
189 | parameters.Add("@project_no", value: PROJECT_NO); |
||
190 | parameters.Add("@document_url", value: DOCUMENT_URL); |
||
191 | parameters.Add("@document_id", value: DOCUMENT_ID); |
||
192 | 098748fa | taeseongkim | parameters.Add("@newid", direction: ParameterDirection.Output,size:int.MaxValue); |
193 | 1a88080d | taeseongkim | |
194 | c112c3c3 | taeseongkim | base.Execute("convert_insert_convertdoc", parameters, transaction: tran, commandType: CommandType.StoredProcedure); |
195 | 098748fa | taeseongkim | |
196 | 1a88080d | taeseongkim | tran.Commit(); |
197 | |||
198 | result = parameters.Get<string>("newid"); |
||
199 | 098748fa | taeseongkim | |
200 | |||
201 | 1a88080d | taeseongkim | } |
202 | catch (Exception ex) |
||
203 | { |
||
204 | |||
205 | throw ex; |
||
206 | } |
||
207 | return result; |
||
208 | } |
||
209 | |||
210 | 098748fa | taeseongkim | public int UpdateStatusAsync(string ServiceID, string ConvertDocID, int status, int totalPage, int currentPage, string exception) |
211 | { |
||
212 | int result = 0; |
||
213 | var tran = BeginTransaction(); |
||
214 | var parameters = new DynamicParameters(); |
||
215 | parameters.Add("@service_id", value: ServiceID); |
||
216 | parameters.Add("@id", value: ConvertDocID); |
||
217 | parameters.Add("@status", value: status); |
||
218 | parameters.Add("@total_page", value: totalPage); |
||
219 | parameters.Add("@current_page", value: currentPage); |
||
220 | parameters.Add("@exception", value: exception); |
||
221 | result = base.Execute("convert_update_status", parameters, transaction: tran, commandType: CommandType.StoredProcedure); |
||
222 | tran.Commit(); |
||
223 | |||
224 | return result; |
||
225 | } |
||
226 | |||
227 | 1a88080d | taeseongkim | /// <summary> |
228 | /// |
||
229 | /// </summary> |
||
230 | /// <param name="documentItem"></param> |
||
231 | /// <returns>Create or Update id</returns> |
||
232 | c112c3c3 | taeseongkim | public string CreateOrUPdateDocItem(DOCUMENTITEM documentItem) |
233 | 1a88080d | taeseongkim | { |
234 | string result = null; |
||
235 | |||
236 | var tran = BeginTransaction(); |
||
237 | var parameter = new DynamicParameters(); |
||
238 | |||
239 | parameter.Add("@revision", documentItem.REVISION); |
||
240 | parameter.Add("@document_no", documentItem.DOCUMENT_NO); |
||
241 | parameter.Add("@document_name", documentItem.DOCUMENT_NAME); |
||
242 | parameter.Add("@original_file", documentItem.ORIGINAL_FILE); |
||
243 | parameter.Add("@document_id", documentItem.DOCUMENT_ID); |
||
244 | parameter.Add("@project_no", documentItem.PROJECT_NO); |
||
245 | parameter.Add("@link", documentItem.Link); |
||
246 | parameter.Add("@result_file", documentItem.RESULT_FILE); |
||
247 | parameter.Add("@result", documentItem.RESULT); |
||
248 | parameter.Add("@group_no", documentItem.GROUP_NO); |
||
249 | 098748fa | taeseongkim | parameter.Add("@newid", direction: ParameterDirection.Output, size: int.MaxValue); |
250 | 1a88080d | taeseongkim | |
251 | c112c3c3 | taeseongkim | base.Execute("convert_insert_documentitem", parameter, tran, commandType: CommandType.StoredProcedure); |
252 | 1a88080d | taeseongkim | |
253 | tran.Commit(); |
||
254 | |||
255 | result = parameter.Get<string>("newid"); |
||
256 | |||
257 | |||
258 | return result; |
||
259 | } |
||
260 | |||
261 | |||
262 | /// <summary> |
||
263 | /// test 필요 transaction Commit 이후 parameter.get을 해야 commit이 된다. |
||
264 | /// </summary> |
||
265 | /// <param name="convertDocID"></param> |
||
266 | /// <param name="PageCount"></param> |
||
267 | /// <returns></returns> |
||
268 | c112c3c3 | taeseongkim | public string CreateDocInfo(string convertDocID, int PageCount) |
269 | 1a88080d | taeseongkim | { |
270 | string result = ""; |
||
271 | var tran = BeginTransaction(); |
||
272 | |||
273 | var parameters = new DynamicParameters(); |
||
274 | parameters.Add("@convert_id", convertDocID, dbType: DbType.String); |
||
275 | parameters.Add("@page_count", PageCount, dbType: DbType.Int32); |
||
276 | parameters.Add("@newid", dbType: DbType.String, direction: ParameterDirection.Output, size: 50); |
||
277 | parameters.Add("@errorcode", dbType: DbType.Int32, direction: ParameterDirection.Output); |
||
278 | parameters.Add("@error", dbType: DbType.String, direction: ParameterDirection.Output, size: 500); |
||
279 | |||
280 | c112c3c3 | taeseongkim | base.Execute("convert_insert_docinfo", parameters, tran, commandType: CommandType.StoredProcedure); |
281 | 1a88080d | taeseongkim | |
282 | var errorCode = parameters.Get<int>("errorcode"); |
||
283 | var error = parameters.Get<string>("error"); |
||
284 | |||
285 | if (errorCode > 0) |
||
286 | { |
||
287 | tran.Rollback(); |
||
288 | throw new Exception(error); |
||
289 | } |
||
290 | else |
||
291 | { |
||
292 | tran.Commit(); |
||
293 | |||
294 | result = parameters.Get<string>("newid"); |
||
295 | } |
||
296 | |||
297 | return result; |
||
298 | } |
||
299 | |||
300 | |||
301 | c112c3c3 | taeseongkim | public bool CreateDocPage(IEnumerable<DocPage> docPages) |
302 | 1a88080d | taeseongkim | { |
303 | bool result = false; |
||
304 | |||
305 | try |
||
306 | { |
||
307 | var tran = BeginTransaction(); |
||
308 | |||
309 | var parameter = new DynamicParameters(); |
||
310 | |||
311 | c7f3eb42 | taeseongkim | parameter.AddTable< DocPage>("DOCPAGES", "TYPE_INSERT_DOCPAGE", docPages.ToList()); |
312 | 1a88080d | taeseongkim | |
313 | c112c3c3 | taeseongkim | var id = base.Execute("CONVERT_INSERT_DOCPAGE", parameter, tran, commandType: CommandType.StoredProcedure); |
314 | 1a88080d | taeseongkim | |
315 | tran.Commit(); |
||
316 | |||
317 | result = true; |
||
318 | } |
||
319 | catch (Exception ex) |
||
320 | { |
||
321 | throw new Exception("DOCPAGERepository CreateAsync error.", ex); |
||
322 | } |
||
323 | |||
324 | return result; |
||
325 | } |
||
326 | } |
||
327 | 0b008ea6 | taeseongkim | |
328 | internal class VARCHAR_TABLE |
||
329 | { |
||
330 | public string ITEM { get; set; } |
||
331 | } |
||
332 | 1a88080d | taeseongkim | } |