using ButcherFactory.BO.Utils;
|
|
using Forks.EnterpriseServices.DomainObjects2;
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery;
|
|
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 = DmoSession.New())
|
|
{
|
|
TruncateTable(type, session);
|
|
foreach (var item in list)
|
|
session.Insert(item);
|
|
session.Commit();
|
|
}
|
|
}
|
|
|
|
public static void SyncGoodsByTag(ApplyClient applyClient)
|
|
{
|
|
var json = RpcFacade.Call<string>(baseInfoRpcPath + "SyncClientGoodsSetByClient", (short)applyClient);
|
|
var list = JsonConvert.DeserializeObject<List<ClientGoodsSet>>(json);
|
|
using (var session = DmoSession.New())
|
|
{
|
|
foreach (var item in list)
|
|
{
|
|
DeleteOld(item.ID, session);
|
|
if (!item.Stopped)
|
|
Insert(item, session);
|
|
}
|
|
session.Commit();
|
|
}
|
|
}
|
|
|
|
static void DeleteOld(long id, IDmoSession session)
|
|
{
|
|
var detail = new DQDeleteDom(typeof(ClientGoodsSet_Detail));
|
|
detail.Where.Conditions.Add(DQCondition.EQ("ClientGoodsSet_ID", id));
|
|
session.ExecuteNonQuery(detail);
|
|
|
|
var main = new DQDeleteDom(typeof(ClientGoodsSet));
|
|
main.Where.Conditions.Add(DQCondition.EQ("ID", id));
|
|
session.ExecuteNonQuery(main);
|
|
}
|
|
|
|
static void Insert(ClientGoodsSet entity, IDmoSession session)
|
|
{
|
|
session.Insert(entity);
|
|
foreach (var detail in entity.Details)
|
|
session.Insert(detail);
|
|
foreach (var goods in entity.Goods)
|
|
session.AddUpdateOrInsert(goods);
|
|
}
|
|
}
|
|
}
|