개정판 1a88080d
issue #000000 ID2의 데이터를 Markus DB에 추가하는 코드
ID2.Manager/ID2.Manager.Dapper/Entities/DOCUMENTITEM.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.ComponentModel.DataAnnotations; |
|
3 |
/* |
|
4 |
This class requires the System.ComponentModel.Annotations package and you can download it from https://www.nuget.org/packages/System.ComponentModel.Annotations |
|
5 |
*/ |
|
6 |
namespace ID2.Manager.Dapper.Entities |
|
7 |
{ |
|
8 |
public class DOCUMENTITEM |
|
9 |
{ |
|
10 |
[Key] |
|
11 |
[MaxLength(50)] |
|
12 |
public string ID {get; set;} |
|
13 |
[Required] |
|
14 |
[MaxLength(50)] |
|
15 |
public string REVISION {get; set;} |
|
16 |
[Required] |
|
17 |
[MaxLength(50)] |
|
18 |
public string DOCUMENT_NO {get; set;} |
|
19 |
[Required] |
|
20 |
[MaxLength(500)] |
|
21 |
public string DOCUMENT_NAME {get; set;} |
|
22 |
[Required] |
|
23 |
[MaxLength(500)] |
|
24 |
public string ORIGINAL_FILE {get; set;} |
|
25 |
[Required] |
|
26 |
[MaxLength(50)] |
|
27 |
public string DOCUMENT_ID {get; set;} |
|
28 |
[Required] |
|
29 |
[MaxLength(10)] |
|
30 |
public string PROJECT_NO {get; set;} |
|
31 |
[MaxLength(500)] |
|
32 |
public string Link {get; set;} |
|
33 |
public DateTime CreateDate {get; set;} |
|
34 |
[MaxLength(500)] |
|
35 |
public string RESULT_FILE {get; set;} |
|
36 |
[MaxLength(50)] |
|
37 |
public string RESULT {get; set;} |
|
38 |
[MaxLength(50)] |
|
39 |
public string GROUP_NO {get; set;} |
|
40 |
} |
|
41 |
} |
|
42 |
|
ID2.Manager/ID2.Manager.Dapper/Entities/DocPage.cs | ||
---|---|---|
1 |
using System; |
|
2 |
using System.Collections.Generic; |
|
3 |
using System.Linq; |
|
4 |
using System.Text; |
|
5 |
using System.Threading.Tasks; |
|
6 |
|
|
7 |
namespace ID2.Manager.Dapper.Entities |
|
8 |
{ |
|
9 |
public class DocPage |
|
10 |
{ |
|
11 |
public string docinfo_id { get; set; } |
|
12 |
public int page_number { get; set; } |
|
13 |
public string page_width { get; set; } |
|
14 |
public string page_height { get; set; } |
|
15 |
public int page_angle { get; set; } |
|
16 |
|
|
17 |
} |
|
18 |
} |
ID2.Manager/ID2.Manager.Dapper/ID2.Manager.Dapper.csproj | ||
---|---|---|
43 | 43 |
<Reference Include="System.Xml" /> |
44 | 44 |
</ItemGroup> |
45 | 45 |
<ItemGroup> |
46 |
<Compile Include="Entities\DocPage.cs" /> |
|
47 |
<Compile Include="Entities\DOCUMENTITEM.cs" /> |
|
46 | 48 |
<Compile Include="IBaseRepository.cs" /> |
47 | 49 |
<Compile Include="Properties\AssemblyInfo.cs" /> |
48 | 50 |
<Compile Include="Repository\BaseRepository.cs" /> |
49 | 51 |
<Compile Include="Repository\DocumentRepository.cs" /> |
52 |
<Compile Include="Repository\MarkusRepository.cs" /> |
|
50 | 53 |
<Compile Include="Repository\UserRepository.cs" /> |
51 | 54 |
</ItemGroup> |
52 | 55 |
<ItemGroup /> |
... | ... | |
54 | 57 |
<PackageReference Include="Dapper"> |
55 | 58 |
<Version>2.0.90</Version> |
56 | 59 |
</PackageReference> |
60 |
<PackageReference Include="Dapper.ParameterExtensions"> |
|
61 |
<Version>2022.7.7.1</Version> |
|
62 |
</PackageReference> |
|
57 | 63 |
<PackageReference Include="Newtonsoft.Json"> |
58 | 64 |
<Version>13.0.3</Version> |
59 | 65 |
</PackageReference> |
ID2.Manager/ID2.Manager.Dapper/Repository/BaseRepository.cs | ||
---|---|---|
135 | 135 |
|
136 | 136 |
return await this._DbConnection.ExecuteAsync(query, param, dbTran); |
137 | 137 |
} |
138 |
|
|
139 |
|
|
140 |
public async Task<int> ExecuteAsync(string SQL, SqlMapper.IDynamicParameters parameters, IDbTransaction transaction, CommandType commandType) |
|
141 |
{ |
|
142 |
if (_DbConnection.State != System.Data.ConnectionState.Open) |
|
143 |
{ |
|
144 |
_DbConnection.Open(); |
|
145 |
} |
|
146 |
|
|
147 |
|
|
148 |
return await _DbConnection.ExecuteAsync(SQL, parameters, transaction, commandType: commandType); |
|
149 |
} |
|
138 | 150 |
} |
139 | 151 |
} |
ID2.Manager/ID2.Manager.Dapper/Repository/MarkusRepository.cs | ||
---|---|---|
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 async Task<bool> InsertAsync(string ProjectNo,string Name) |
|
18 |
{ |
|
19 |
bool result = false; |
|
20 |
|
|
21 |
var convertDocID = await CreateConvertDocAsync(ProjectNo, Name, Name); |
|
22 |
|
|
23 |
if (convertDocID != null) |
|
24 |
{ |
|
25 |
|
|
26 |
var docInfoID = await CreateDocInfoAsync(convertDocID, 1); |
|
27 |
|
|
28 |
var docPageResult = await CreateDocPageAsync(new[]{ |
|
29 |
new DocPage { |
|
30 |
page_angle = 0, |
|
31 |
page_height = "1", |
|
32 |
page_width = "1", |
|
33 |
page_number = 1 |
|
34 |
|
|
35 |
} }); |
|
36 |
|
|
37 |
var documentItemID = await CreateOrUPdateDocItemAsync( |
|
38 |
new DOCUMENTITEM |
|
39 |
{ |
|
40 |
REVISION = "0", |
|
41 |
PROJECT_NO = ProjectNo, |
|
42 |
DOCUMENT_NO = Name, |
|
43 |
GROUP_NO = Name, |
|
44 |
DOCUMENT_NAME = Name, |
|
45 |
ORIGINAL_FILE = Name, |
|
46 |
DOCUMENT_ID = Name |
|
47 |
}); |
|
48 |
|
|
49 |
if(docInfoID != null && docPageResult && documentItemID != null) |
|
50 |
{ |
|
51 |
result = true; |
|
52 |
} |
|
53 |
} |
|
54 |
|
|
55 |
return result; |
|
56 |
} |
|
57 |
|
|
58 |
/// <summary> |
|
59 |
/// 완료 |
|
60 |
/// </summary> |
|
61 |
/// <param name="PROJECT_NO"></param> |
|
62 |
/// <param name="DOCUMENT_URL"></param> |
|
63 |
/// <param name="DOCUMENT_ID"></param> |
|
64 |
/// <returns></returns> |
|
65 |
public async Task<string> CreateConvertDocAsync(string PROJECT_NO, string DOCUMENT_URL, string DOCUMENT_ID) |
|
66 |
{ |
|
67 |
string result = null; |
|
68 |
try |
|
69 |
{ |
|
70 |
var tran = BeginTransaction(); |
|
71 |
|
|
72 |
var parameters = new DynamicParameters(); |
|
73 |
parameters.Add("@project_no", value: PROJECT_NO); |
|
74 |
parameters.Add("@document_url", value: DOCUMENT_URL); |
|
75 |
parameters.Add("@document_id", value: DOCUMENT_ID); |
|
76 |
parameters.Add("@newid", direction: ParameterDirection.Output); |
|
77 |
|
|
78 |
await base.ExecuteAsync("convert_insert_convertdoc", parameters, transaction: tran, commandType: CommandType.StoredProcedure); |
|
79 |
|
|
80 |
tran.Commit(); |
|
81 |
|
|
82 |
result = parameters.Get<string>("newid"); |
|
83 |
} |
|
84 |
catch (Exception ex) |
|
85 |
{ |
|
86 |
|
|
87 |
throw ex; |
|
88 |
} |
|
89 |
return result; |
|
90 |
} |
|
91 |
|
|
92 |
/// <summary> |
|
93 |
/// |
|
94 |
/// </summary> |
|
95 |
/// <param name="documentItem"></param> |
|
96 |
/// <returns>Create or Update id</returns> |
|
97 |
public async Task<string> CreateOrUPdateDocItemAsync(DOCUMENTITEM documentItem) |
|
98 |
{ |
|
99 |
string result = null; |
|
100 |
|
|
101 |
var tran = BeginTransaction(); |
|
102 |
var parameter = new DynamicParameters(); |
|
103 |
|
|
104 |
parameter.Add("@revision", documentItem.REVISION); |
|
105 |
parameter.Add("@document_no", documentItem.DOCUMENT_NO); |
|
106 |
parameter.Add("@document_name", documentItem.DOCUMENT_NAME); |
|
107 |
parameter.Add("@original_file", documentItem.ORIGINAL_FILE); |
|
108 |
parameter.Add("@document_id", documentItem.DOCUMENT_ID); |
|
109 |
parameter.Add("@project_no", documentItem.PROJECT_NO); |
|
110 |
parameter.Add("@link", documentItem.Link); |
|
111 |
parameter.Add("@result_file", documentItem.RESULT_FILE); |
|
112 |
parameter.Add("@result", documentItem.RESULT); |
|
113 |
parameter.Add("@group_no", documentItem.GROUP_NO); |
|
114 |
parameter.Add("@newid", direction: ParameterDirection.Output); |
|
115 |
|
|
116 |
await base.ExecuteAsync("convert_insert_documentitem", parameter, tran, commandType: CommandType.StoredProcedure); |
|
117 |
|
|
118 |
tran.Commit(); |
|
119 |
|
|
120 |
result = parameter.Get<string>("newid"); |
|
121 |
|
|
122 |
|
|
123 |
return result; |
|
124 |
} |
|
125 |
|
|
126 |
|
|
127 |
/// <summary> |
|
128 |
/// test 필요 transaction Commit 이후 parameter.get을 해야 commit이 된다. |
|
129 |
/// </summary> |
|
130 |
/// <param name="convertDocID"></param> |
|
131 |
/// <param name="PageCount"></param> |
|
132 |
/// <returns></returns> |
|
133 |
public async Task<string> CreateDocInfoAsync(string convertDocID, int PageCount) |
|
134 |
{ |
|
135 |
string result = ""; |
|
136 |
var tran = BeginTransaction(); |
|
137 |
|
|
138 |
var parameters = new DynamicParameters(); |
|
139 |
parameters.Add("@convert_id", convertDocID, dbType: DbType.String); |
|
140 |
parameters.Add("@page_count", PageCount, dbType: DbType.Int32); |
|
141 |
parameters.Add("@newid", dbType: DbType.String, direction: ParameterDirection.Output, size: 50); |
|
142 |
parameters.Add("@errorcode", dbType: DbType.Int32, direction: ParameterDirection.Output); |
|
143 |
parameters.Add("@error", dbType: DbType.String, direction: ParameterDirection.Output, size: 500); |
|
144 |
|
|
145 |
await base.ExecuteAsync("convert_insert_docinfo", parameters, tran, commandType: CommandType.StoredProcedure); |
|
146 |
|
|
147 |
var errorCode = parameters.Get<int>("errorcode"); |
|
148 |
var error = parameters.Get<string>("error"); |
|
149 |
|
|
150 |
if (errorCode > 0) |
|
151 |
{ |
|
152 |
tran.Rollback(); |
|
153 |
throw new Exception(error); |
|
154 |
} |
|
155 |
else |
|
156 |
{ |
|
157 |
tran.Commit(); |
|
158 |
|
|
159 |
result = parameters.Get<string>("newid"); |
|
160 |
} |
|
161 |
|
|
162 |
return result; |
|
163 |
} |
|
164 |
|
|
165 |
|
|
166 |
public async Task<bool> CreateDocPageAsync(IEnumerable<DocPage> docPages) |
|
167 |
{ |
|
168 |
bool result = false; |
|
169 |
|
|
170 |
try |
|
171 |
{ |
|
172 |
var tran = BeginTransaction(); |
|
173 |
|
|
174 |
var parameter = new DynamicParameters(); |
|
175 |
|
|
176 |
parameter.AddTable("DOCPAGES", "TYPE_INSERT_DOCPAGE", docPages); |
|
177 |
|
|
178 |
var id = await base.ExecuteAsync("CONVERT_INSERT_DOCPAGE", parameter, tran, commandType: CommandType.StoredProcedure); |
|
179 |
|
|
180 |
tran.Commit(); |
|
181 |
|
|
182 |
result = true; |
|
183 |
} |
|
184 |
catch (Exception ex) |
|
185 |
{ |
|
186 |
throw new Exception("DOCPAGERepository CreateAsync error.", ex); |
|
187 |
} |
|
188 |
|
|
189 |
return result; |
|
190 |
} |
|
191 |
} |
|
192 |
} |
내보내기 Unified diff