프로젝트

일반

사용자정보

통계
| 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / MarkusRepository.cs @ 81d15568

이력 | 보기 | 이력해설 | 다운로드 (7.32 KB)

1 1a88080d taeseongkim
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 c112c3c3 taeseongkim
        public bool Insert(string ProjectNo,string Name)
18 1a88080d taeseongkim
        {
19
            bool result = false;
20
21 c112c3c3 taeseongkim
            var convertDocID = CreateConvertDoc(ProjectNo, Name, Name);
22 1a88080d taeseongkim
23
            if (convertDocID != null)
24
            {
25 098748fa taeseongkim
                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 1a88080d taeseongkim
29 c112c3c3 taeseongkim
                var docInfoID =  CreateDocInfo(convertDocID, 1);
30 1a88080d taeseongkim
31 c112c3c3 taeseongkim
                var docPageResult = CreateDocPage(new[]{
32 1a88080d taeseongkim
                new DocPage {
33 098748fa taeseongkim
                    docinfo_id = docInfoID,
34 1a88080d taeseongkim
                    page_angle = 0,
35 9a1bb06b taeseongkim
                    page_width  = "9600",
36
                    page_height = "6787",
37 1a88080d taeseongkim
                    page_number = 1
38
39
                } });
40
41 c112c3c3 taeseongkim
                var documentItemID = CreateOrUPdateDocItem(
42 1a88080d taeseongkim
                    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 098748fa taeseongkim
                if(statusResult == 1 && docInfoID != null && docPageResult && documentItemID != null)
54 1a88080d taeseongkim
                {
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 c112c3c3 taeseongkim
        public string CreateConvertDoc(string PROJECT_NO, string DOCUMENT_URL, string DOCUMENT_ID)
70 1a88080d taeseongkim
        {
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 098748fa taeseongkim
                parameters.Add("@newid", direction: ParameterDirection.Output,size:int.MaxValue);
81 1a88080d taeseongkim
82 c112c3c3 taeseongkim
                base.Execute("convert_insert_convertdoc", parameters, transaction: tran, commandType: CommandType.StoredProcedure);
83 098748fa taeseongkim
                
84 1a88080d taeseongkim
                tran.Commit();
85
86
                result = parameters.Get<string>("newid");
87 098748fa taeseongkim
88
89 1a88080d taeseongkim
            }
90
            catch (Exception ex)
91
            {
92
93
                throw ex;
94
            }
95
            return result;
96
        }
97
98 098748fa taeseongkim
        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 1a88080d taeseongkim
        /// <summary>
116
        /// 
117
        /// </summary>
118
        /// <param name="documentItem"></param>
119
        /// <returns>Create or Update id</returns>
120 c112c3c3 taeseongkim
        public string CreateOrUPdateDocItem(DOCUMENTITEM documentItem)
121 1a88080d taeseongkim
        {
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 098748fa taeseongkim
            parameter.Add("@newid", direction: ParameterDirection.Output, size: int.MaxValue);
138 1a88080d taeseongkim
139 c112c3c3 taeseongkim
            base.Execute("convert_insert_documentitem", parameter, tran, commandType: CommandType.StoredProcedure);
140 1a88080d taeseongkim
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 c112c3c3 taeseongkim
        public string CreateDocInfo(string convertDocID, int PageCount)
157 1a88080d taeseongkim
        {
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 c112c3c3 taeseongkim
            base.Execute("convert_insert_docinfo", parameters, tran, commandType: CommandType.StoredProcedure);
169 1a88080d taeseongkim
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 c112c3c3 taeseongkim
        public bool CreateDocPage(IEnumerable<DocPage> docPages)
190 1a88080d taeseongkim
        {
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 c112c3c3 taeseongkim
                var id = base.Execute("CONVERT_INSERT_DOCPAGE", parameter, tran, commandType: CommandType.StoredProcedure);
202 1a88080d taeseongkim
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
}
클립보드 이미지 추가 (최대 크기: 500 MB)