개정판 39938acd
issue #0000
document 저장 시 log 작성 진행중
- save transaction 관리
- markus document 동기화 시 증분만 조회할 수 있도록 수정 진행중
Change-Id: I40eab56384eb367257a2b38fcb1cbf34582af3b0
ID2.Manager/ID2.Manager.Controller/Controllers/DocumentController.cs | ||
---|---|---|
248 | 248 |
|
249 | 249 |
return isSuccess; |
250 | 250 |
} |
251 |
|
|
252 |
//Transactions |
|
253 |
public int GetTranKey(string userId, string projectID) |
|
254 |
{ |
|
255 |
try |
|
256 |
{ |
|
257 |
using (DocumentRepository rep = new DocumentRepository(this._MSSQLCONNSTR)) |
|
258 |
{ |
|
259 |
return rep.GetTranKey(userId, projectID); |
|
260 |
} |
|
261 |
} |
|
262 |
catch (Exception ex) |
|
263 |
{ |
|
264 |
throw ex; |
|
265 |
} |
|
266 |
} |
|
267 |
|
|
268 |
public bool SetTran(int seq, bool isMgt, bool isStart, int itemCount, int markusItemCount) |
|
269 |
{ |
|
270 |
try |
|
271 |
{ |
|
272 |
using (DocumentRepository rep = new DocumentRepository(this._MSSQLCONNSTR)) |
|
273 |
{ |
|
274 |
return rep.SetTran(seq, isMgt, isStart, itemCount, markusItemCount); |
|
275 |
} |
|
276 |
} |
|
277 |
catch (Exception ex) |
|
278 |
{ |
|
279 |
throw ex; |
|
280 |
} |
|
281 |
} |
|
282 |
|
|
283 |
public string GetTranData(int seq) |
|
284 |
{ |
|
285 |
try |
|
286 |
{ |
|
287 |
using (DocumentRepository rep = new DocumentRepository(this._MSSQLCONNSTR)) |
|
288 |
{ |
|
289 |
return rep.GetTranData(seq); |
|
290 |
} |
|
291 |
} |
|
292 |
catch (Exception ex) |
|
293 |
{ |
|
294 |
throw ex; |
|
295 |
} |
|
296 |
} |
|
297 |
|
|
298 |
public IEnumerable<Documents> GetTrDocuments(int seq) |
|
299 |
{ |
|
300 |
try |
|
301 |
{ |
|
302 |
using (DocumentRepository rep = new DocumentRepository(this._MSSQLCONNSTR)) |
|
303 |
{ |
|
304 |
return rep.GetTrDocuments(seq); |
|
305 |
} |
|
306 |
} |
|
307 |
catch (Exception ex) |
|
308 |
{ |
|
309 |
throw ex; |
|
310 |
} |
|
311 |
} |
|
251 | 312 |
} |
252 | 313 |
} |
ID2.Manager/ID2.Manager.Dapper/Repository/DocumentRepository.cs | ||
---|---|---|
5 | 5 |
using System.Threading.Tasks; |
6 | 6 |
|
7 | 7 |
using System.Data; |
8 |
using System.ComponentModel; |
|
9 |
using System.Reflection; |
|
8 | 10 |
|
9 | 11 |
using ID2.Manager.Data.Models; |
10 | 12 |
|
11 | 13 |
using Dapper; |
12 |
using System.ComponentModel; |
|
13 |
using System.Reflection;
|
|
14 |
|
|
15 |
using Newtonsoft.Json;
|
|
14 | 16 |
|
15 | 17 |
namespace ID2.Manager.Dapper.Repository |
16 | 18 |
{ |
... | ... | |
589 | 591 |
parameters.Add("DeletedUser", userId); |
590 | 592 |
|
591 | 593 |
var limitDwgNos = delDocList.Skip(paramMaxCount * i).Take(paramMaxCount).Select(x => x.DocID).ToList(); |
592 |
sbWhere.Append($@" DocID in @limitDwgNos "); |
|
594 |
sbWhere.Append($@" and DocID in @limitDwgNos ");
|
|
593 | 595 |
parameters.Add("limitDwgNos", limitDwgNos); |
594 | 596 |
|
595 | 597 |
query = $@" |
... | ... | |
597 | 599 |
set IsDeleted=1 |
598 | 600 |
,DeletedDate=getdate() |
599 | 601 |
,DeletedUser=@DeletedUser |
600 |
where {sbWhere}"; |
|
602 |
where IsDeleted=0 {sbWhere}";
|
|
601 | 603 |
if (parameters.Count > 0) |
602 | 604 |
{ |
603 | 605 |
dynamicParameters.AddDynamicParams(parameters); |
... | ... | |
615 | 617 |
doc.ModifiedUser = userId; |
616 | 618 |
|
617 | 619 |
query = $@" |
618 |
if exists(select * from dbo.Documents where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo) |
|
620 |
if exists(select * from dbo.Documents where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo and IsDeleted=0)
|
|
619 | 621 |
begin |
620 | 622 |
--update |
621 | 623 |
update dbo.Documents |
... | ... | |
656 | 658 |
,DTIsImport=@DTIsImport |
657 | 659 |
,DTIsRegSystem=@DTIsRegSystem |
658 | 660 |
,DTRemarks=@DTRemarks |
659 |
where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo |
|
661 |
where RefProjectCode=@RefProjectCode and DocumentNo=@DocumentNo and IsDeleted=0
|
|
660 | 662 |
|
661 | 663 |
if @@rowcount > 0 |
662 | 664 |
begin |
663 |
select ''
|
|
665 |
select @DocID
|
|
664 | 666 |
end |
665 | 667 |
else |
666 | 668 |
begin |
... | ... | |
1122 | 1124 |
throw ex; |
1123 | 1125 |
} |
1124 | 1126 |
} |
1127 |
|
|
1128 |
|
|
1129 |
//Transactions |
|
1130 |
public int GetTranKey(string userId, string projectID) |
|
1131 |
{ |
|
1132 |
int result = -1; |
|
1133 |
|
|
1134 |
try |
|
1135 |
{ |
|
1136 |
var dynamicParameters = new DynamicParameters(); |
|
1137 |
|
|
1138 |
var parameters = new Dictionary<string, object>() |
|
1139 |
{ |
|
1140 |
{ "UserId", userId }, |
|
1141 |
{ "ProjectID", projectID } |
|
1142 |
}; |
|
1143 |
|
|
1144 |
dynamicParameters.AddDynamicParams(parameters); |
|
1145 |
|
|
1146 |
using (var transaction = base.BeginTransaction()) |
|
1147 |
{ |
|
1148 |
string query = $@" |
|
1149 |
--log master 입력 |
|
1150 |
insert into dbo.Transactions (UserId, ProjectID) |
|
1151 |
values (@UserId, @ProjectID); |
|
1152 |
select scope_identity();"; |
|
1153 |
|
|
1154 |
result = base.ExecuteScalar<int>(query, dynamicParameters, transaction); |
|
1155 |
|
|
1156 |
transaction.Commit(); |
|
1157 |
} |
|
1158 |
} |
|
1159 |
catch (Exception ex) |
|
1160 |
{ |
|
1161 |
throw ex; |
|
1162 |
} |
|
1163 |
|
|
1164 |
return result; |
|
1165 |
} |
|
1166 |
|
|
1167 |
public bool SetTran(int seq, bool isMgt, bool isStart, int itemCount, int markusItemCount) |
|
1168 |
{ |
|
1169 |
bool result = false; |
|
1170 |
|
|
1171 |
try |
|
1172 |
{ |
|
1173 |
var dynamicParameters = new DynamicParameters(); |
|
1174 |
var parameters = new Dictionary<string, object>() |
|
1175 |
{ |
|
1176 |
{ "Seq", seq }, |
|
1177 |
{ "ItemCount", itemCount }, |
|
1178 |
{ "MarkusItemCount", markusItemCount } |
|
1179 |
}; |
|
1180 |
dynamicParameters.AddDynamicParams(parameters); |
|
1181 |
StringBuilder sbWhere = new StringBuilder(); |
|
1182 |
if (isMgt) |
|
1183 |
{ |
|
1184 |
if (isStart) |
|
1185 |
{ |
|
1186 |
sbWhere.Append("StartDate=getdate(), ItemCount=@ItemCount"); |
|
1187 |
} |
|
1188 |
else |
|
1189 |
{ |
|
1190 |
sbWhere.Append("EndDate=getdate()"); |
|
1191 |
} |
|
1192 |
|
|
1193 |
} |
|
1194 |
else |
|
1195 |
{ |
|
1196 |
if (isStart) |
|
1197 |
{ |
|
1198 |
sbWhere.Append("MarkusStartDate=getdate(), MarkusItemCount=@MarkusItemCount"); |
|
1199 |
} |
|
1200 |
else |
|
1201 |
{ |
|
1202 |
sbWhere.Append("MarkusEndDate=getdate()"); |
|
1203 |
} |
|
1204 |
} |
|
1205 |
|
|
1206 |
using (var transaction = base.BeginTransaction()) |
|
1207 |
{ |
|
1208 |
string query = $@" |
|
1209 |
update dbo.Transactions |
|
1210 |
set {sbWhere} |
|
1211 |
where Seq=@Seq;"; |
|
1212 |
base.Execute(query, dynamicParameters, transaction); |
|
1213 |
|
|
1214 |
transaction.Commit(); |
|
1215 |
|
|
1216 |
result = true; |
|
1217 |
} |
|
1218 |
} |
|
1219 |
catch (Exception ex) |
|
1220 |
{ |
|
1221 |
throw ex; |
|
1222 |
} |
|
1223 |
|
|
1224 |
return result; |
|
1225 |
} |
|
1226 |
|
|
1227 |
public string GetTranData(int seq) |
|
1228 |
{ |
|
1229 |
try |
|
1230 |
{ |
|
1231 |
var dynamicParameters = new DynamicParameters(); |
|
1232 |
var parameters = new Dictionary<string, object>() |
|
1233 |
{ |
|
1234 |
{ "Seq", seq } |
|
1235 |
}; |
|
1236 |
dynamicParameters.AddDynamicParams(parameters); |
|
1237 |
|
|
1238 |
string query = $@" |
|
1239 |
select * |
|
1240 |
from dbo.Transactions |
|
1241 |
where Seq=@Seq"; |
|
1242 |
|
|
1243 |
IEnumerable<dynamic> rows = base.Query<dynamic>(query, dynamicParameters); |
|
1244 |
|
|
1245 |
return this.ToSerializeData(rows); |
|
1246 |
} |
|
1247 |
catch (Exception ex) |
|
1248 |
{ |
|
1249 |
throw ex; |
|
1250 |
} |
|
1251 |
} |
|
1252 |
|
|
1253 |
public string ToSerializeData(IEnumerable<dynamic> items) |
|
1254 |
{ |
|
1255 |
List<Dictionary<string, object>> list = new List<Dictionary<string, object>>(); |
|
1256 |
|
|
1257 |
if (items == null) return string.Empty; |
|
1258 |
var datas = items.ToArray(); |
|
1259 |
if (datas.Length == 0) return string.Empty; |
|
1260 |
|
|
1261 |
foreach (var data in datas) |
|
1262 |
{ |
|
1263 |
var dicItem = new Dictionary<string, object>(); |
|
1264 |
foreach (var pair in ((IDictionary<string, object>)data)) |
|
1265 |
{ |
|
1266 |
dicItem.Add(pair.Key, pair.Value); |
|
1267 |
} |
|
1268 |
list.Add(dicItem); |
|
1269 |
} |
|
1270 |
|
|
1271 |
return JsonConvert.SerializeObject(list); |
|
1272 |
} |
|
1273 |
|
|
1274 |
public IEnumerable<Documents> GetTrDocuments(int seq) |
|
1275 |
{ |
|
1276 |
var dynamicParameters = new DynamicParameters(); |
|
1277 |
StringBuilder sbWhere = new StringBuilder(); |
|
1278 |
var parameters = new Dictionary<string, object>() |
|
1279 |
{ |
|
1280 |
{ "Seq", seq } |
|
1281 |
}; |
|
1282 |
dynamicParameters.AddDynamicParams(parameters); |
|
1283 |
|
|
1284 |
try |
|
1285 |
{ |
|
1286 |
string query = $@" |
|
1287 |
declare @CreatedDate datetime |
|
1288 |
declare @EndDate datetime |
|
1289 |
declare @ProjectGroupID varchar(36) |
|
1290 |
|
|
1291 |
select top 1 @CreatedDate=CreatedDate, @EndDate=EndDate, @ProjectGroupID=ProjectID |
|
1292 |
from dbo.Transactions |
|
1293 |
where Seq=@Seq |
|
1294 |
|
|
1295 |
select RefProjectCode, DocumentNo |
|
1296 |
from dbo.Documents |
|
1297 |
where RefProjectCode in (select Code from dbo.Projects where ParentID=@ProjectGroupID) |
|
1298 |
and RegisteredDate > @CreatedDate and RegisteredDate <= @EndDate"; |
|
1299 |
|
|
1300 |
if (parameters.Count > 0) |
|
1301 |
{ |
|
1302 |
dynamicParameters.AddDynamicParams(parameters); |
|
1303 |
} |
|
1304 |
|
|
1305 |
return Query<Documents>(query, dynamicParameters); |
|
1306 |
} |
|
1307 |
catch (Exception ex) |
|
1308 |
{ |
|
1309 |
throw ex; |
|
1310 |
} |
|
1311 |
} |
|
1125 | 1312 |
} |
1126 | 1313 |
} |
내보내기 Unified diff