using ButcherFactory.BO.Utils;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.JsonRpc.Client;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ButcherFactory.BO.Rpcs
|
|
{
|
|
public static class BaseInfoSyncRpc
|
|
{
|
|
const string baseInfoRpcPath = @"/MainSystem/B3ClientService/Rpcs/SyncBaseInfoRpc/";
|
|
|
|
static void TruncateTable(Type type, IDmoSession session)
|
|
{
|
|
var table = DmoInfo.Get(type).MappedDBObject;
|
|
var sql = string.Format("truncate table [{0}]", table);
|
|
session.ExecuteSqlNonQuery(sql);
|
|
}
|
|
|
|
public static void SyncBaseInfo<T>(string methodName = null)
|
|
where T : BaseInfo
|
|
{
|
|
var type = typeof(T);
|
|
if (string.IsNullOrEmpty(methodName))
|
|
methodName = "Sync" + type.Name;
|
|
var json = RpcFacade.Call<string>(baseInfoRpcPath + methodName);
|
|
var list = JsonConvert.DeserializeObject<List<T>>(json);
|
|
using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
|
|
{
|
|
TruncateTable(type, session);
|
|
foreach (var item in list)
|
|
session.Insert(item);
|
|
session.Commit();
|
|
}
|
|
}
|
|
|
|
public static void SyncGoodsByTag(string tag)
|
|
{
|
|
//var json = RpcFacade.Call<string>(baseInfoRpcPath + "SyncGoods");
|
|
//var list = JsonConvert.DeserializeObject<List<Goods>>(json);
|
|
//using (var session = Dmo.NewSession(AppContext.ConnectInfo.SqlConnection))
|
|
//{
|
|
// TruncateTable(typeof(Goods), session);
|
|
// foreach (var item in list)
|
|
// session.Insert(item);
|
|
// session.Commit();
|
|
//}
|
|
}
|
|
}
|
|
}
|