프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / ID2.Manager / ID2.Manager.Dapper / Repository / MarkusRepository.cs @ 00d11333

이력 | 보기 | 이력해설 | 다운로드 (8.58 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 serviceId = this.QueryFirst<string>("SELECT ID FROM SERVICE_PROPERTIES WHERE SERVICE_TYPE = 3");
27

    
28
                //var statusResult = UpdateStatusAsync(serviceId, convertDocID, 4, 1, 1, null);
29

    
30
                //var docInfoID =  CreateDocInfo(convertDocID, 1);
31

    
32
                //var docPageResult = CreateDocPage(new[]{
33
                //new DocPage {
34
                //    docinfo_id = docInfoID,
35
                //    page_angle = 0,
36
                //    page_width  = "9600",
37
                //    page_height = "6787",
38
                //    page_number = 1
39

    
40
                //} });
41

    
42
                var documentItemID = CreateOrUPdateDocItem(
43
                    new DOCUMENTITEM
44
                    {
45
                        REVISION = "0",
46
                        PROJECT_NO = ProjectNo,
47
                        DOCUMENT_NO = Name,
48
                        GROUP_NO = Name,
49
                        DOCUMENT_NAME = Name,
50
                        ORIGINAL_FILE = Name,
51
                        DOCUMENT_ID = Name
52
                    });
53

    
54
                //if (statusResult == 1 && docInfoID != null && docPageResult && documentItemID != null)
55
                if (documentItemID != null)
56
                {
57
                    result = true;
58
                }
59
            }
60

    
61
            return result;
62
        }
63

    
64
        public IEnumerable<ConvertDoc> GetConvertDoc(int status,string ProjectNo)
65
        {
66
            string SQL = "SELECT * FROM CONVERTER_DOC WHERE STATUS = @STATUS and PROJECT_NO = @PROJECT_NO";
67

    
68
            var parameters = new DynamicParameters();
69
            parameters.Add("@STATUS", status);
70
            parameters.Add("@PROJECT_NO", ProjectNo);
71

    
72
            var convertItems = base.Query<ConvertDoc>(SQL, parameters);
73

    
74
            return convertItems;
75
        }
76

    
77
        public IEnumerable<MarkupText> GetMarkupText(IEnumerable<string> ProjectNoList, IEnumerable<string> DocumentNoList)
78
        {
79
            string SQL = "GET_MARKUPDATA";
80

    
81
            var parameters = new DynamicParameters();
82
            parameters.AddTable("@PROJECT_NOs", "VARCHAR_TABLE", ProjectNoList.Select(x=>new VARCHAR_TABLE { ITEM = x }));
83
            parameters.AddTable("@DOCUMENT_IDs", "VARCHAR_TABLE", DocumentNoList.Select(x => new VARCHAR_TABLE { ITEM = x }));
84

    
85
            var Items = base.Query<MarkupText>(SQL, parameters,commandType:CommandType.StoredProcedure);
86

    
87
            return Items;
88
        }
89

    
90
        /// <summary>
91
        /// 완료
92
        /// </summary>
93
        /// <param name="PROJECT_NO"></param>
94
        /// <param name="DOCUMENT_URL"></param>
95
        /// <param name="DOCUMENT_ID"></param>
96
        /// <returns></returns>
97
        public string CreateConvertDoc(string PROJECT_NO, string DOCUMENT_URL, string DOCUMENT_ID)
98
        {
99
            string result = null;
100
            try
101
            {
102
                var tran = BeginTransaction();
103

    
104
                var parameters = new DynamicParameters();
105
                parameters.Add("@project_no", value: PROJECT_NO);
106
                parameters.Add("@document_url", value: DOCUMENT_URL);
107
                parameters.Add("@document_id", value: DOCUMENT_ID);
108
                parameters.Add("@newid", direction: ParameterDirection.Output,size:int.MaxValue);
109

    
110
                base.Execute("convert_insert_convertdoc", parameters, transaction: tran, commandType: CommandType.StoredProcedure);
111
                
112
                tran.Commit();
113

    
114
                result = parameters.Get<string>("newid");
115

    
116

    
117
            }
118
            catch (Exception ex)
119
            {
120

    
121
                throw ex;
122
            }
123
            return result;
124
        }
125

    
126
        public int UpdateStatusAsync(string ServiceID, string ConvertDocID, int status, int totalPage, int currentPage, string exception)
127
        {
128
            int result = 0;
129
            var tran = BeginTransaction();
130
            var parameters = new DynamicParameters();
131
            parameters.Add("@service_id", value: ServiceID);
132
            parameters.Add("@id", value: ConvertDocID);
133
            parameters.Add("@status", value: status);
134
            parameters.Add("@total_page", value: totalPage);
135
            parameters.Add("@current_page", value: currentPage);
136
            parameters.Add("@exception", value: exception);
137
            result = base.Execute("convert_update_status", parameters, transaction: tran, commandType: CommandType.StoredProcedure);
138
            tran.Commit();
139

    
140
            return result;
141
        }
142

    
143
        /// <summary>
144
        /// 
145
        /// </summary>
146
        /// <param name="documentItem"></param>
147
        /// <returns>Create or Update id</returns>
148
        public string CreateOrUPdateDocItem(DOCUMENTITEM documentItem)
149
        {
150
            string result = null;
151

    
152
            var tran = BeginTransaction();
153
            var parameter = new DynamicParameters();
154

    
155
            parameter.Add("@revision", documentItem.REVISION);
156
            parameter.Add("@document_no", documentItem.DOCUMENT_NO);
157
            parameter.Add("@document_name", documentItem.DOCUMENT_NAME);
158
            parameter.Add("@original_file", documentItem.ORIGINAL_FILE);
159
            parameter.Add("@document_id", documentItem.DOCUMENT_ID);
160
            parameter.Add("@project_no", documentItem.PROJECT_NO);
161
            parameter.Add("@link", documentItem.Link);
162
            parameter.Add("@result_file", documentItem.RESULT_FILE);
163
            parameter.Add("@result", documentItem.RESULT);
164
            parameter.Add("@group_no", documentItem.GROUP_NO);
165
            parameter.Add("@newid", direction: ParameterDirection.Output, size: int.MaxValue);
166

    
167
            base.Execute("convert_insert_documentitem", parameter, tran, commandType: CommandType.StoredProcedure);
168

    
169
            tran.Commit();
170

    
171
            result = parameter.Get<string>("newid");
172

    
173

    
174
            return result;
175
        }
176

    
177

    
178
        /// <summary>
179
        /// test 필요 transaction Commit 이후 parameter.get을 해야 commit이 된다.
180
        /// </summary>
181
        /// <param name="convertDocID"></param>
182
        /// <param name="PageCount"></param>
183
        /// <returns></returns>
184
        public string CreateDocInfo(string convertDocID, int PageCount)
185
        {
186
            string result = "";
187
            var tran = BeginTransaction();
188

    
189
            var parameters = new DynamicParameters();
190
            parameters.Add("@convert_id", convertDocID, dbType: DbType.String);
191
            parameters.Add("@page_count", PageCount, dbType: DbType.Int32);
192
            parameters.Add("@newid", dbType: DbType.String, direction: ParameterDirection.Output, size: 50);
193
            parameters.Add("@errorcode", dbType: DbType.Int32, direction: ParameterDirection.Output);
194
            parameters.Add("@error", dbType: DbType.String, direction: ParameterDirection.Output, size: 500);
195

    
196
            base.Execute("convert_insert_docinfo", parameters, tran, commandType: CommandType.StoredProcedure);
197

    
198
            var errorCode = parameters.Get<int>("errorcode");
199
            var error = parameters.Get<string>("error");
200

    
201
            if (errorCode > 0)
202
            {
203
                tran.Rollback();
204
                throw new Exception(error);
205
            }
206
            else
207
            {
208
                tran.Commit();
209

    
210
                result = parameters.Get<string>("newid");
211
            }
212

    
213
            return result;
214
        }
215

    
216

    
217
        public bool CreateDocPage(IEnumerable<DocPage> docPages)
218
        {
219
            bool result = false;
220

    
221
            try
222
            {
223
                var tran = BeginTransaction();
224

    
225
                var parameter = new DynamicParameters();
226

    
227
                parameter.AddTable("DOCPAGES", "TYPE_INSERT_DOCPAGE", docPages);
228

    
229
                var id = base.Execute("CONVERT_INSERT_DOCPAGE", parameter, tran, commandType: CommandType.StoredProcedure);
230

    
231
                tran.Commit();
232

    
233
                result = true;
234
            }
235
            catch (Exception ex)
236
            {
237
                throw new Exception("DOCPAGERepository CreateAsync error.", ex);
238
            }
239

    
240
            return result;
241
        }
242
    }
243

    
244
    internal class VARCHAR_TABLE
245
    {
246
        public string ITEM { get; set; }
247
    }
248
}
클립보드 이미지 추가 (최대 크기: 500 MB)