hytos / ID2.Manager / ID2.Manager.Dapper / Repository / MarkusRepository.cs @ 81d15568
이력 | 보기 | 이력해설 | 다운로드 (7.32 KB)
1 |
using Dapper; |
---|---|
2 |
using DapperParameters; |
3 |
using ID2.Manager.Dapper.Entities; |
4 |
using System; |
5 |
using System.Collections.Generic; |
6 |
using System.Data; |
7 |
using System.Linq; |
8 |
using System.Text; |
9 |
using System.Threading.Tasks; |
10 |
|
11 |
namespace ID2.Manager.Dapper.Repository |
12 |
{ |
13 |
public class MarkusRepository : BaseRepository |
14 |
{ |
15 |
public MarkusRepository(string connectionStr) : base(connectionStr) { } |
16 |
|
17 |
public bool Insert(string ProjectNo,string Name) |
18 |
{ |
19 |
bool result = false; |
20 |
|
21 |
var convertDocID = CreateConvertDoc(ProjectNo, Name, Name); |
22 |
|
23 |
if (convertDocID != null) |
24 |
{ |
25 |
var serviceId = this.QueryFirst<string>("SELECT ID FROM SERVICE_PROPERTIES WHERE SERVICE_TYPE = 3"); |
26 |
|
27 |
var statusResult = UpdateStatusAsync(serviceId, convertDocID, 4, 1, 1, null); |
28 |
|
29 |
var docInfoID = CreateDocInfo(convertDocID, 1); |
30 |
|
31 |
var docPageResult = CreateDocPage(new[]{ |
32 |
new DocPage { |
33 |
docinfo_id = docInfoID, |
34 |
page_angle = 0, |
35 |
page_width = "9600", |
36 |
page_height = "6787", |
37 |
page_number = 1 |
38 |
|
39 |
} }); |
40 |
|
41 |
var documentItemID = CreateOrUPdateDocItem( |
42 |
new DOCUMENTITEM |
43 |
{ |
44 |
REVISION = "0", |
45 |
PROJECT_NO = ProjectNo, |
46 |
DOCUMENT_NO = Name, |
47 |
GROUP_NO = Name, |
48 |
DOCUMENT_NAME = Name, |
49 |
ORIGINAL_FILE = Name, |
50 |
DOCUMENT_ID = Name |
51 |
}); |
52 |
|
53 |
if(statusResult == 1 && docInfoID != null && docPageResult && documentItemID != null) |
54 |
{ |
55 |
result = true; |
56 |
} |
57 |
} |
58 |
|
59 |
return result; |
60 |
} |
61 |
|
62 |
/// <summary> |
63 |
/// 완료 |
64 |
/// </summary> |
65 |
/// <param name="PROJECT_NO"></param> |
66 |
/// <param name="DOCUMENT_URL"></param> |
67 |
/// <param name="DOCUMENT_ID"></param> |
68 |
/// <returns></returns> |
69 |
public string CreateConvertDoc(string PROJECT_NO, string DOCUMENT_URL, string DOCUMENT_ID) |
70 |
{ |
71 |
string result = null; |
72 |
try |
73 |
{ |
74 |
var tran = BeginTransaction(); |
75 |
|
76 |
var parameters = new DynamicParameters(); |
77 |
parameters.Add("@project_no", value: PROJECT_NO); |
78 |
parameters.Add("@document_url", value: DOCUMENT_URL); |
79 |
parameters.Add("@document_id", value: DOCUMENT_ID); |
80 |
parameters.Add("@newid", direction: ParameterDirection.Output,size:int.MaxValue); |
81 |
|
82 |
base.Execute("convert_insert_convertdoc", parameters, transaction: tran, commandType: CommandType.StoredProcedure); |
83 |
|
84 |
tran.Commit(); |
85 |
|
86 |
result = parameters.Get<string>("newid"); |
87 |
|
88 |
|
89 |
} |
90 |
catch (Exception ex) |
91 |
{ |
92 |
|
93 |
throw ex; |
94 |
} |
95 |
return result; |
96 |
} |
97 |
|
98 |
public int UpdateStatusAsync(string ServiceID, string ConvertDocID, int status, int totalPage, int currentPage, string exception) |
99 |
{ |
100 |
int result = 0; |
101 |
var tran = BeginTransaction(); |
102 |
var parameters = new DynamicParameters(); |
103 |
parameters.Add("@service_id", value: ServiceID); |
104 |
parameters.Add("@id", value: ConvertDocID); |
105 |
parameters.Add("@status", value: status); |
106 |
parameters.Add("@total_page", value: totalPage); |
107 |
parameters.Add("@current_page", value: currentPage); |
108 |
parameters.Add("@exception", value: exception); |
109 |
result = base.Execute("convert_update_status", parameters, transaction: tran, commandType: CommandType.StoredProcedure); |
110 |
tran.Commit(); |
111 |
|
112 |
return result; |
113 |
} |
114 |
|
115 |
/// <summary> |
116 |
/// |
117 |
/// </summary> |
118 |
/// <param name="documentItem"></param> |
119 |
/// <returns>Create or Update id</returns> |
120 |
public string CreateOrUPdateDocItem(DOCUMENTITEM documentItem) |
121 |
{ |
122 |
string result = null; |
123 |
|
124 |
var tran = BeginTransaction(); |
125 |
var parameter = new DynamicParameters(); |
126 |
|
127 |
parameter.Add("@revision", documentItem.REVISION); |
128 |
parameter.Add("@document_no", documentItem.DOCUMENT_NO); |
129 |
parameter.Add("@document_name", documentItem.DOCUMENT_NAME); |
130 |
parameter.Add("@original_file", documentItem.ORIGINAL_FILE); |
131 |
parameter.Add("@document_id", documentItem.DOCUMENT_ID); |
132 |
parameter.Add("@project_no", documentItem.PROJECT_NO); |
133 |
parameter.Add("@link", documentItem.Link); |
134 |
parameter.Add("@result_file", documentItem.RESULT_FILE); |
135 |
parameter.Add("@result", documentItem.RESULT); |
136 |
parameter.Add("@group_no", documentItem.GROUP_NO); |
137 |
parameter.Add("@newid", direction: ParameterDirection.Output, size: int.MaxValue); |
138 |
|
139 |
base.Execute("convert_insert_documentitem", parameter, tran, commandType: CommandType.StoredProcedure); |
140 |
|
141 |
tran.Commit(); |
142 |
|
143 |
result = parameter.Get<string>("newid"); |
144 |
|
145 |
|
146 |
return result; |
147 |
} |
148 |
|
149 |
|
150 |
/// <summary> |
151 |
/// test 필요 transaction Commit 이후 parameter.get을 해야 commit이 된다. |
152 |
/// </summary> |
153 |
/// <param name="convertDocID"></param> |
154 |
/// <param name="PageCount"></param> |
155 |
/// <returns></returns> |
156 |
public string CreateDocInfo(string convertDocID, int PageCount) |
157 |
{ |
158 |
string result = ""; |
159 |
var tran = BeginTransaction(); |
160 |
|
161 |
var parameters = new DynamicParameters(); |
162 |
parameters.Add("@convert_id", convertDocID, dbType: DbType.String); |
163 |
parameters.Add("@page_count", PageCount, dbType: DbType.Int32); |
164 |
parameters.Add("@newid", dbType: DbType.String, direction: ParameterDirection.Output, size: 50); |
165 |
parameters.Add("@errorcode", dbType: DbType.Int32, direction: ParameterDirection.Output); |
166 |
parameters.Add("@error", dbType: DbType.String, direction: ParameterDirection.Output, size: 500); |
167 |
|
168 |
base.Execute("convert_insert_docinfo", parameters, tran, commandType: CommandType.StoredProcedure); |
169 |
|
170 |
var errorCode = parameters.Get<int>("errorcode"); |
171 |
var error = parameters.Get<string>("error"); |
172 |
|
173 |
if (errorCode > 0) |
174 |
{ |
175 |
tran.Rollback(); |
176 |
throw new Exception(error); |
177 |
} |
178 |
else |
179 |
{ |
180 |
tran.Commit(); |
181 |
|
182 |
result = parameters.Get<string>("newid"); |
183 |
} |
184 |
|
185 |
return result; |
186 |
} |
187 |
|
188 |
|
189 |
public bool CreateDocPage(IEnumerable<DocPage> docPages) |
190 |
{ |
191 |
bool result = false; |
192 |
|
193 |
try |
194 |
{ |
195 |
var tran = BeginTransaction(); |
196 |
|
197 |
var parameter = new DynamicParameters(); |
198 |
|
199 |
parameter.AddTable("DOCPAGES", "TYPE_INSERT_DOCPAGE", docPages); |
200 |
|
201 |
var id = base.Execute("CONVERT_INSERT_DOCPAGE", parameter, tran, commandType: CommandType.StoredProcedure); |
202 |
|
203 |
tran.Commit(); |
204 |
|
205 |
result = true; |
206 |
} |
207 |
catch (Exception ex) |
208 |
{ |
209 |
throw new Exception("DOCPAGERepository CreateAsync error.", ex); |
210 |
} |
211 |
|
212 |
return result; |
213 |
} |
214 |
} |
215 |
} |