|
@ -8,17 +8,16 @@ using CK.SCP.Utils; |
|
|
using Newtonsoft.Json; |
|
|
using Newtonsoft.Json; |
|
|
using System; |
|
|
using System; |
|
|
using System.Collections.Generic; |
|
|
using System.Collections.Generic; |
|
|
using System.ComponentModel; |
|
|
|
|
|
using System.Data.Entity.Migrations; |
|
|
using System.Data.Entity.Migrations; |
|
|
using System.Linq; |
|
|
using System.Linq; |
|
|
using System.Text; |
|
|
using System.Text; |
|
|
using System.Threading; |
|
|
using System.Threading; |
|
|
using System.Threading.Tasks; |
|
|
|
|
|
using System.Transactions; |
|
|
using System.Transactions; |
|
|
using System.Data.Entity.Core; |
|
|
using System.Data.Entity.Core; |
|
|
using System.Security.Cryptography; |
|
|
using System.Data; |
|
|
using System.Data.Entity; |
|
|
using CK.SCP.Controller.WebReference; |
|
|
using System.Collections.ObjectModel; |
|
|
using CK.SCP.Models.UniApiEntity; |
|
|
|
|
|
using System.Threading.Tasks; |
|
|
//using WebSrvAPITest;
|
|
|
//using WebSrvAPITest;
|
|
|
|
|
|
|
|
|
namespace CK.SCP.Controller |
|
|
namespace CK.SCP.Controller |
|
@ -194,28 +193,29 @@ namespace CK.SCP.Controller |
|
|
// return list;
|
|
|
// return list;
|
|
|
//}
|
|
|
//}
|
|
|
|
|
|
|
|
|
public static ResultObject<List<TEA_TASK_SUB>> Get_TEA_TASK_SUB_List(TEA_TASK_SUB p_entity) |
|
|
public static List<TEA_TASK_SUB> Get_TEA_TASK_SUB_List(TEA_TASK_SUB p_entity) |
|
|
{ |
|
|
|
|
|
ResultObject<List<TEA_TASK_SUB>> _ret = new ResultObject<List<TEA_TASK_SUB>>(); |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
{ |
|
|
|
|
|
//ResultObject<List<TEA_TASK_SUB>> _ret = new ResultObject<List<TEA_TASK_SUB>>();
|
|
|
|
|
|
//try
|
|
|
|
|
|
//{
|
|
|
|
|
|
List<TEA_TASK_SUB> _ret = new List<TEA_TASK_SUB>(); |
|
|
using (var db = EntitiesFactory.CreateExchangeCenterInstance()) |
|
|
using (var db = EntitiesFactory.CreateExchangeCenterInstance()) |
|
|
{ |
|
|
{ |
|
|
string _sql = "select * from TEA_TASK_SUB with(nolock) where TaskState = '{0}' and Subscriber = '{1}'"; |
|
|
string _sql = "select * from TEA_TASK_SUB with(nolock) where TaskState = '{0}' and Subscriber = '{1}'"; |
|
|
_sql = string.Format(_sql, (int)p_entity.TaskState, p_entity.Subscriber); |
|
|
_sql = string.Format(_sql, (int)p_entity.TaskState, p_entity.Subscriber); |
|
|
|
|
|
|
|
|
var q = db.Database.SqlQuery<TEA_TASK_SUB>(_sql).OrderBy(p=>p.CreateTime).ToList(); |
|
|
var q = db.Database.SqlQuery<TEA_TASK_SUB>(_sql).OrderBy(p=>p.CreateTime).ToList(); |
|
|
_ret.State = ReturnStatus.Succeed; |
|
|
//_ret.State = ReturnStatus.Succeed;
|
|
|
_ret.Result = q; |
|
|
_ret = q; |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception e) |
|
|
|
|
|
{ |
|
|
|
|
|
_ret.State = ReturnStatus.Failed; |
|
|
|
|
|
_ret.ErrorList.Add(e); |
|
|
|
|
|
LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_DC_UNI_CONTROLLER), "Get_TEA_TASK_SUB_List", e.Message); |
|
|
|
|
|
throw e; |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
//}
|
|
|
|
|
|
//catch (Exception e)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// _ret.State = ReturnStatus.Failed;
|
|
|
|
|
|
// _ret.ErrorList.Add(e);
|
|
|
|
|
|
// LogHelper.Writlog(LogHelper.LogType.Error, typeof(SCP_DC_UNI_CONTROLLER), "Get_TEA_TASK_SUB_List", e.Message);
|
|
|
|
|
|
// throw e;
|
|
|
|
|
|
//}
|
|
|
return _ret; |
|
|
return _ret; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -360,12 +360,12 @@ namespace CK.SCP.Controller |
|
|
// ResultObject<List<LogModel>> result = new ResultObject<List<LogModel>>();
|
|
|
// ResultObject<List<LogModel>> result = new ResultObject<List<LogModel>>();
|
|
|
var _result = Get_TEA_TASK_SUB_List(new TEA_TASK_SUB() { TaskState = EnumTaskState.Unread, Subscriber = "SCP"}); |
|
|
var _result = Get_TEA_TASK_SUB_List(new TEA_TASK_SUB() { TaskState = EnumTaskState.Unread, Subscriber = "SCP"}); |
|
|
//List<TEA_TASK_SUB> tasklist = Get_TEA_TASK_SUB_List(new TEA_TASK_SUB() { TaskState = EnumTaskState.Unread, Subscriber = "SCP" });
|
|
|
//List<TEA_TASK_SUB> tasklist = Get_TEA_TASK_SUB_List(new TEA_TASK_SUB() { TaskState = EnumTaskState.Unread, Subscriber = "SCP" });
|
|
|
//if (tasklist.Count() > 0)
|
|
|
if (_result.Count() > 0) |
|
|
if (_result.State == ReturnStatus.Succeed) |
|
|
//if (_result.State == ReturnStatus.Succeed)
|
|
|
{ |
|
|
{ |
|
|
|
|
|
|
|
|
//foreach (var _task in tasklist)
|
|
|
foreach (var _task in _result) |
|
|
foreach (var _task in _result.Result) |
|
|
//foreach (var _task in _result.Result)
|
|
|
{ |
|
|
{ |
|
|
ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); |
|
|
ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); |
|
|
DataCenterContext dc = EntitiesFactory.CreateDataCenterInstance(); |
|
|
DataCenterContext dc = EntitiesFactory.CreateDataCenterInstance(); |
|
@ -418,32 +418,34 @@ namespace CK.SCP.Controller |
|
|
EntitiesFactory.SaveDb(dc); |
|
|
EntitiesFactory.SaveDb(dc); |
|
|
scope.Complete(); |
|
|
scope.Complete(); |
|
|
break; |
|
|
break; |
|
|
case "TES_SUPPLIER": |
|
|
#region 单独读取 供应商和零件
|
|
|
var _supplierlist = db.TES_SUPPLIER.Where(p => p.TaskID == _task.TaskID).ToList(); |
|
|
//case "TES_SUPPLIER":
|
|
|
result = UpdateSupplier(_supplierlist, scpdb, authdb, _task); |
|
|
// var _supplierlist = db.TES_SUPPLIER.Where(p => p.TaskID == _task.TaskID).ToList();
|
|
|
result.Message = _task.TaskID.ToString(); |
|
|
// result = UpdateSupplier(_supplierlist, scpdb, authdb, _task);
|
|
|
Update_TEA_TASK_SUB(db, _task); |
|
|
// result.Message = _task.TaskID.ToString();
|
|
|
scpdb.BulkSaveChanges(); |
|
|
// Update_TEA_TASK_SUB(db, _task);
|
|
|
db.BulkSaveChanges(); |
|
|
// scpdb.BulkSaveChanges();
|
|
|
authdb.BulkSaveChanges(); |
|
|
// db.BulkSaveChanges();
|
|
|
dc.BulkSaveChanges(); |
|
|
// //authdb.BulkSaveChanges();
|
|
|
//EntitiesFactory.SaveDb(scpdb);
|
|
|
// dc.BulkSaveChanges();
|
|
|
//EntitiesFactory.SaveDb(db);
|
|
|
// //EntitiesFactory.SaveDb(scpdb);
|
|
|
//EntitiesFactory.SaveDb(dc);
|
|
|
// //EntitiesFactory.SaveDb(db);
|
|
|
//EntitiesFactory.SaveDb(authdb);
|
|
|
// //EntitiesFactory.SaveDb(dc);
|
|
|
//取消自动创建
|
|
|
// //EntitiesFactory.SaveDb(authdb);
|
|
|
//UpdateSupplierExtend(_supplierlist);
|
|
|
// //取消自动创建
|
|
|
scope.Complete(); |
|
|
// //UpdateSupplierExtend(_supplierlist);
|
|
|
break; |
|
|
// scope.Complete();
|
|
|
case "TES_PART_MSTR": |
|
|
// break;
|
|
|
result = UpdatePart(db, scpdb, _task); |
|
|
//case "TES_PART_MSTR":
|
|
|
result.Message = _task.TaskID.ToString(); |
|
|
// result = UpdatePart(db, scpdb, _task);
|
|
|
Update_TEA_TASK_SUB(db, _task); |
|
|
// result.Message = _task.TaskID.ToString();
|
|
|
EntitiesFactory.SaveDb(scpdb); |
|
|
// Update_TEA_TASK_SUB(db, _task);
|
|
|
EntitiesFactory.SaveDb(db); |
|
|
// EntitiesFactory.SaveDb(scpdb);
|
|
|
EntitiesFactory.SaveDb(dc); |
|
|
// EntitiesFactory.SaveDb(db);
|
|
|
scope.Complete(); |
|
|
// EntitiesFactory.SaveDb(dc);
|
|
|
break; |
|
|
// scope.Complete();
|
|
|
|
|
|
// break;
|
|
|
|
|
|
#endregion
|
|
|
case "TED_PPOD_DET": |
|
|
case "TED_PPOD_DET": |
|
|
result = UpdatePPod(db, scpdb, _task); |
|
|
result = UpdatePPod(db, scpdb, _task); |
|
|
result.Message = _task.TaskID.ToString(); |
|
|
result.Message = _task.TaskID.ToString(); |
|
@ -513,6 +515,103 @@ namespace CK.SCP.Controller |
|
|
p_action(result); |
|
|
p_action(result); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 基础数据
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="p_action"></param>
|
|
|
|
|
|
public static void BaseReadService(Action<ResultObject<bool>> p_action) |
|
|
|
|
|
{ |
|
|
|
|
|
ResultObject<bool> result = new ResultObject<bool>(); |
|
|
|
|
|
ExchangeCenterService service = new ExchangeCenterService(); |
|
|
|
|
|
var jsonResult = service.GetSessionId("SCP", "5C2DE907DB859810", ""); |
|
|
|
|
|
var serviceResultEntityList = JsonConvert.DeserializeObject< List<ServiceResult>>(jsonResult); |
|
|
|
|
|
string SessionId = ""; |
|
|
|
|
|
SessionId = serviceResultEntityList.First().Data; |
|
|
|
|
|
var _result = Get_TEA_TASK_SUB_List(new TEA_TASK_SUB() { TaskState = EnumTaskState.Unread, Subscriber = "SCP" }); |
|
|
|
|
|
if (_result.Count() > 0) |
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
foreach (var _task in _result) |
|
|
|
|
|
//foreach (var _task in _result.Result)
|
|
|
|
|
|
{ |
|
|
|
|
|
ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); |
|
|
|
|
|
DataCenterContext dc = EntitiesFactory.CreateDataCenterInstance(); |
|
|
|
|
|
AppBoxContext authdb = EntitiesFactory.CreateAppBoxInstance(); |
|
|
|
|
|
ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); |
|
|
|
|
|
|
|
|
|
|
|
using (var scope = |
|
|
|
|
|
new TransactionScope(TransactionScopeOption.Suppress, new TransactionOptions() |
|
|
|
|
|
{ |
|
|
|
|
|
IsolationLevel = System.Transactions.IsolationLevel.RepeatableRead, |
|
|
|
|
|
Timeout = new TimeSpan(0, 20, 0) |
|
|
|
|
|
})) |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
switch (_task.TableName) |
|
|
|
|
|
{ |
|
|
|
|
|
case "TES_SUPPLIER": |
|
|
|
|
|
var _supplierlist = db.TES_SUPPLIER.Where(p => p.TaskID == _task.TaskID).ToList(); |
|
|
|
|
|
result = UpdateSupplier(_supplierlist, scpdb, authdb, _task); |
|
|
|
|
|
result.Message = _task.TaskID.ToString(); |
|
|
|
|
|
service.UpdateTaskState(SessionId, _task.TaskID.ToString(), 2,0,""); |
|
|
|
|
|
//Update_TEA_TASK_SUB(db, _task);
|
|
|
|
|
|
scpdb.BulkSaveChanges(); |
|
|
|
|
|
scope.Complete(); |
|
|
|
|
|
break; |
|
|
|
|
|
case "TES_PART_MSTR": |
|
|
|
|
|
result = UpdatePart(db, scpdb, _task); |
|
|
|
|
|
result.Message = _task.TaskID.ToString(); |
|
|
|
|
|
service.UpdateTaskState(SessionId, _task.TaskID.ToString(), 2, 0, ""); |
|
|
|
|
|
//Update_TEA_TASK_SUB(db, _task);
|
|
|
|
|
|
EntitiesFactory.SaveDb(scpdb); |
|
|
|
|
|
scope.Complete(); |
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
result.State = ReturnStatus.Succeed; |
|
|
|
|
|
result.Result = true; |
|
|
|
|
|
} |
|
|
|
|
|
catch (System.Data.Entity.Validation.DbEntityValidationException dbEx)//捕获实体验证异常
|
|
|
|
|
|
{ |
|
|
|
|
|
var sb = new StringBuilder(); |
|
|
|
|
|
foreach (var error in dbEx.EntityValidationErrors.ToList()) |
|
|
|
|
|
{ |
|
|
|
|
|
error.ValidationErrors.ToList().ForEach(i => |
|
|
|
|
|
{ |
|
|
|
|
|
sb.AppendFormat("表:{0},字段:{1},信息:{2}\r\n", error.Entry.Entity.GetType().Name, i.PropertyName, i.ErrorMessage); |
|
|
|
|
|
}); |
|
|
|
|
|
} |
|
|
|
|
|
scope.Dispose(); |
|
|
|
|
|
result.State = ReturnStatus.Failed; |
|
|
|
|
|
result.ErrorList.Add(dbEx); |
|
|
|
|
|
} |
|
|
|
|
|
catch (OptimisticConcurrencyException ex)//并发冲突异常
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
scope.Dispose(); |
|
|
|
|
|
result.State = ReturnStatus.Failed; |
|
|
|
|
|
result.ErrorList.Add(ex); |
|
|
|
|
|
} |
|
|
|
|
|
catch (Exception ex) |
|
|
|
|
|
{ |
|
|
|
|
|
scope.Dispose(); |
|
|
|
|
|
result.State = ReturnStatus.Failed; |
|
|
|
|
|
result.ErrorList.Add(ex); |
|
|
|
|
|
result.Message = ex.Message; //_task.TaskID.ToString();
|
|
|
|
|
|
if (ex.InnerException != null) |
|
|
|
|
|
{ |
|
|
|
|
|
result.Message = ex.InnerException.Message; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
p_action(result); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
p_action(result); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static void WriteService(Action<ResultObject<List<LogModel>>> p_action) |
|
|
public static void WriteService(Action<ResultObject<List<LogModel>>> p_action) |
|
|
{ |
|
|
{ |
|
|
ResultObject<List<LogModel>> result = new ResultObject<List<LogModel>>(); |
|
|
ResultObject<List<LogModel>> result = new ResultObject<List<LogModel>>(); |
|
@ -528,8 +627,8 @@ namespace CK.SCP.Controller |
|
|
{ |
|
|
{ |
|
|
ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); |
|
|
ScpEntities scpdb = EntitiesFactory.CreateScpInstance(); |
|
|
ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); |
|
|
ExchangeCenterContext db = EntitiesFactory.CreateExchangeCenterInstance(); |
|
|
var _list = scpdb.TS_UNI_API.Where(p => p.State == (int)DataState.Enabled && p.Domain == "BJBMPT").OrderBy(p => p.UID).ToList(); |
|
|
var _list = scpdb.TS_UNI_API.Where(p => p.State == (int)DataState.Enabled && p.Domain == "CDBMPT").OrderBy(p => p.UID).ToList(); |
|
|
var _list1 = scpdb.TS_UNI_API.Where(p => p.State == (int)DataState.Enabled && p.Domain == "BJBMPT" && p.InterfaceType == "Price").OrderBy(p => p.UID).ToList(); |
|
|
var _list1 = scpdb.TS_UNI_API.Where(p => p.State == (int)DataState.Enabled && p.Domain == "CDBMPT" && p.InterfaceType == "Price").OrderBy(p => p.UID).ToList(); |
|
|
|
|
|
|
|
|
var apiii = _list1.Count(); |
|
|
var apiii = _list1.Count(); |
|
|
if (apiii > 0) |
|
|
if (apiii > 0) |
|
@ -2053,12 +2152,14 @@ namespace CK.SCP.Controller |
|
|
ResultObject<bool> _ret = new ResultObject<bool>(); |
|
|
ResultObject<bool> _ret = new ResultObject<bool>(); |
|
|
try |
|
|
try |
|
|
{ |
|
|
{ |
|
|
var _venderlist = new List<TA_VENDER>(); |
|
|
var _tavenderlist = scpdb.TA_VENDER.ToList(); |
|
|
|
|
|
var addlist = new List<TA_VENDER>(); |
|
|
|
|
|
var uplist = new List<TA_VENDER>(); |
|
|
foreach (var supplier in p_list) |
|
|
foreach (var supplier in p_list) |
|
|
{ |
|
|
{ |
|
|
foreach (var item in _dic) |
|
|
foreach (var item in _dic) |
|
|
{ |
|
|
{ |
|
|
var _supplier = scpdb.TA_VENDER.FirstOrDefault(p => p.VendId == supplier.SupplierCode && p.Site == item.Key); |
|
|
var _supplier = _tavenderlist.FirstOrDefault(p => p.VendId == supplier.SupplierCode && p.Site == item.Key); |
|
|
if (_supplier == null) |
|
|
if (_supplier == null) |
|
|
{ |
|
|
{ |
|
|
_supplier = new TA_VENDER |
|
|
_supplier = new TA_VENDER |
|
@ -2067,15 +2168,25 @@ namespace CK.SCP.Controller |
|
|
VendAbbCode = "0", |
|
|
VendAbbCode = "0", |
|
|
State = 1, |
|
|
State = 1, |
|
|
}; |
|
|
}; |
|
|
} |
|
|
|
|
|
_supplier.VendName = string.IsNullOrEmpty(supplier.SupplierName) ? supplier.SupplierName : supplier.SupplierName; |
|
|
_supplier.VendName = string.IsNullOrEmpty(supplier.SupplierName) ? supplier.SupplierName : supplier.SupplierName; |
|
|
|
|
|
|
|
|
_supplier.SubSite = item.Value;//地点
|
|
|
_supplier.SubSite = item.Value;//地点
|
|
|
_supplier.Site = item.Key;//域
|
|
|
_supplier.Site = item.Key;//域
|
|
|
_supplier.Remark = supplier.TaskID.ToString();//任务ID
|
|
|
_supplier.Remark = supplier.TaskID.ToString();//任务ID
|
|
|
|
|
|
addlist.Add(_supplier); |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
_supplier.VendName = string.IsNullOrEmpty(supplier.SupplierName) ? supplier.SupplierName : supplier.SupplierName; |
|
|
|
|
|
|
|
|
var vendname = string.Format("{0}@{1}", _supplier.VendId.ToUpper(), _supplier.Site.ToUpper()); |
|
|
_supplier.SubSite = item.Value;//地点
|
|
|
// 取消自动创建
|
|
|
_supplier.Site = item.Key;//域
|
|
|
|
|
|
_supplier.Remark = supplier.TaskID.ToString();//任务ID
|
|
|
|
|
|
uplist.Add(_supplier); |
|
|
|
|
|
} |
|
|
|
|
|
# region 取消自动创建
|
|
|
|
|
|
//var vendname = string.Format("{0}@{1}", _supplier.VendId.ToUpper(), _supplier.Site.ToUpper());
|
|
|
|
|
|
//
|
|
|
//var _first = authdb.Users.Where(p => p.Name == vendname).FirstOrDefault();
|
|
|
//var _first = authdb.Users.Where(p => p.Name == vendname).FirstOrDefault();
|
|
|
//var _vend = authdb.Roles.Where(p => p.Name == "供应商").FirstOrDefault();
|
|
|
//var _vend = authdb.Roles.Where(p => p.Name == "供应商").FirstOrDefault();
|
|
|
//var _factory = authdb.TA_FACTORY.Where(p => p.ErpDomain == _supplier.Site.ToUpper()).FirstOrDefault();
|
|
|
//var _factory = authdb.TA_FACTORY.Where(p => p.ErpDomain == _supplier.Site.ToUpper()).FirstOrDefault();
|
|
@ -2108,10 +2219,13 @@ namespace CK.SCP.Controller |
|
|
// _entity.TA_FACTORY.Add(f);
|
|
|
// _entity.TA_FACTORY.Add(f);
|
|
|
// authdb.Users.Add(_entity);
|
|
|
// authdb.Users.Add(_entity);
|
|
|
//}
|
|
|
//}
|
|
|
_venderlist.Add(_supplier); |
|
|
//_venderlist.Add(_supplier);
|
|
|
|
|
|
#endregion
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
scpdb.TA_VENDER.AddOrUpdate(q => q.UID, _venderlist.ToArray()); |
|
|
scpdb.BulkInsert(addlist); |
|
|
|
|
|
scpdb.BulkUpdate(uplist); |
|
|
|
|
|
//scpdb.TA_VENDER.AddOrUpdate(q => q.UID, _venderlist.ToArray());
|
|
|
_ret.State = ReturnStatus.Succeed; |
|
|
_ret.State = ReturnStatus.Succeed; |
|
|
_ret.MessageList.Add(string.Format("更新表{0}任务ID{1}成功!", "TES_SUPPLIER", p_entity.TaskID)); |
|
|
_ret.MessageList.Add(string.Format("更新表{0}任务ID{1}成功!", "TES_SUPPLIER", p_entity.TaskID)); |
|
|
} |
|
|
} |
|
|