using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using FireBirdUtil.SqlUtils;
|
|
using Forks.JsonRpc.Client;
|
|
using Forks.JsonRpc.Client.Data;
|
|
using WeighBusiness.BO;
|
|
using WeighBusiness.Utils;
|
|
using WeighBusiness.Utils.SqlUtils;
|
|
|
|
namespace WeighBusiness.BL
|
|
{
|
|
public static class PoleBL
|
|
{
|
|
public static List<Pole> GetAllLocalPole()
|
|
{
|
|
return LocalQueryUtil.GetAllLocalPole();
|
|
}
|
|
|
|
public static bool Insert(Pole input)
|
|
{
|
|
string insertSql = InsertUtil.GetInsertSql(TableNames.杆,
|
|
new string[] { "ERP_ID", "Name", "Weight", "RowVersion" },
|
|
new string[] { input.ERP_ID.ToString(), input.Name, input.Weight == null ? "null" : input.Weight.ToString(), input.RowVersion.Value.ToString() });
|
|
return ExcuteSql(insertSql);
|
|
}
|
|
|
|
private static bool ExcuteSql(string sql)
|
|
{
|
|
bool success;
|
|
using (var she = new SqlHelperEx()) {
|
|
she.CreateTransaction();
|
|
she.ExecuteNonQuery(sql, out success);
|
|
if (!success)
|
|
she.Rollback();
|
|
else
|
|
she.Commit();
|
|
}
|
|
return success;
|
|
}
|
|
|
|
public static void Delete(long ID)
|
|
{
|
|
var sql2 = SqlUtil.GetDeleteSql(TableNames.杆, "where ERP_ID=" + ID.ToString());
|
|
ExcuteSql(sql2);
|
|
}
|
|
|
|
public static void Delete()
|
|
{
|
|
var sql2 = SqlUtil.GetDeleteSql(TableNames.杆);
|
|
ExcuteSql(sql2);
|
|
}
|
|
|
|
public static void SyncPole()
|
|
{
|
|
var method = "/MainSystem/B3FoodDeepProcess/Rpcs/BaseInfoRpc/GetPoleRowVersion";
|
|
var poleVersion = RpcFacade.Call<List<RpcObject>>(method);
|
|
var oldPoleVersion = PoleBL.GetAllLocalPole();
|
|
|
|
var needInsertPoleID = new List<long?>();
|
|
var needDeleteAndInsertPoleID = new List<long?>();
|
|
if (poleVersion.Count > 0) {
|
|
if (oldPoleVersion == null || oldPoleVersion.Count() <= 0) {
|
|
poleVersion.ForEach(x => needInsertPoleID.Add(x.Get<long>("field3")));
|
|
} else {
|
|
foreach (var pole in poleVersion) {
|
|
var pole_ID = pole.Get<long>("field3");
|
|
var oldPole = oldPoleVersion.Where(x => x.ERP_ID == pole_ID);
|
|
if (oldPole != null && oldPole.Count() > 0 && oldPole.FirstOrDefault().RowVersion != pole.Get<int?>("field4")) {
|
|
needDeleteAndInsertPoleID.Add(pole_ID);
|
|
} else if (oldPole == null || oldPole.Count() <= 0) {
|
|
needInsertPoleID.Add(pole_ID);
|
|
}
|
|
}
|
|
|
|
foreach (var oldVersion in oldPoleVersion) {
|
|
if (!poleVersion.Any(x => x.Get<long>("field3") == oldVersion.ERP_ID)) {
|
|
PoleBL.Delete(oldVersion.ERP_ID.Value);
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
PoleBL.Delete();
|
|
}
|
|
|
|
|
|
if (needDeleteAndInsertPoleID.Count() > 0) {
|
|
foreach (var poleID in needDeleteAndInsertPoleID) {
|
|
PoleBL.Delete(poleID.Value);
|
|
needInsertPoleID.Add(poleID);
|
|
}
|
|
}
|
|
|
|
if (needInsertPoleID.Count > 0) {
|
|
string carMethod = "/MainSystem/B3FoodDeepProcess/Rpcs/BaseInfoRpc/GetPole";
|
|
var cars = RpcFacade.Call<IList<RpcObject>>(carMethod, needInsertPoleID.ToArray());
|
|
if (cars.Count() > 0) {
|
|
foreach (var detail in cars) {
|
|
var pole = new Pole();
|
|
pole.ERP_ID = detail.Get<long?>("field3");
|
|
pole.Name = detail.Get<string>("field1");
|
|
pole.Weight = detail.Get<decimal?>("field2");
|
|
pole.RowVersion = detail.Get<int?>("field4");
|
|
PoleBL.Insert(pole);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|