|
|
@ -1,6 +1,8 @@ |
|
|
using BWP.B3ClientService.BO; |
|
|
using BWP.B3ClientService.BO; |
|
|
using BWP.B3ClientService.MapBO; |
|
|
|
|
|
|
|
|
using BWP.B3ClientService.RpcBO; |
|
|
using BWP.B3ClientService.Rpcs; |
|
|
using BWP.B3ClientService.Rpcs; |
|
|
|
|
|
using BWP.B3Frameworks.Utils; |
|
|
|
|
|
using Forks.EnterpriseServices.BusinessInterfaces; |
|
|
using Forks.EnterpriseServices.DomainObjects2; |
|
|
using Forks.EnterpriseServices.DomainObjects2; |
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery; |
|
|
using Forks.EnterpriseServices.DomainObjects2.DQuery; |
|
|
using System; |
|
|
using System; |
|
|
@ -15,53 +17,65 @@ namespace BWP.B3ClientService.Tasks.UpdateLoad |
|
|
{ |
|
|
{ |
|
|
public static class UpLoadWeightBill |
|
|
public static class UpLoadWeightBill |
|
|
{ |
|
|
{ |
|
|
public static void Execute() |
|
|
|
|
|
|
|
|
public static void Execute(string uri) |
|
|
{ |
|
|
{ |
|
|
//1、清理垃圾(删除且未上传的)
|
|
|
|
|
|
ClearUnUpdateLoadAndDeleteData(); |
|
|
|
|
|
|
|
|
|
|
|
//2、获取所有未上传的数据
|
|
|
|
|
|
|
|
|
//获取所有未上传的数据
|
|
|
var allBill = GetAllNeedSyncBill(); |
|
|
var allBill = GetAllNeedSyncBill(); |
|
|
|
|
|
|
|
|
//3、上传
|
|
|
|
|
|
//{
|
|
|
|
|
|
// 1、插入(全量)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 2、修改{1、全部修改,2、明细删除} 返回 信息后,明细该删的,要清理,然后改为已同步。
|
|
|
|
|
|
// 3、删除的,删除,并清理本地
|
|
|
|
|
|
|
|
|
|
|
|
// 修改删除注意单据状态。
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//4、并反馈ID
|
|
|
|
|
|
|
|
|
|
|
|
//4、改为已上传
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void ClearUnUpdateLoadAndDeleteData() |
|
|
|
|
|
{ |
|
|
|
|
|
using (var session = Dmo.NewSession()) |
|
|
|
|
|
|
|
|
foreach (var item in allBill) |
|
|
{ |
|
|
{ |
|
|
DeleteEntity<WeightBill>(session); |
|
|
|
|
|
DeleteEntity<WeightBill_Detail>(session); |
|
|
|
|
|
DeleteEntity<WeightBill_FarmerDetail>(session); |
|
|
|
|
|
DeleteEntity<WeightBill_HouseDetail>(session); |
|
|
|
|
|
DeleteEntity<WeightBill_SanctionDetail>(session); |
|
|
|
|
|
session.Commit(); |
|
|
|
|
|
|
|
|
var bwpClient = new BWPClient(uri, item.Creator); |
|
|
|
|
|
using (var context = new TransactionContext()) |
|
|
|
|
|
{ |
|
|
|
|
|
#region 删除
|
|
|
|
|
|
if (item.DeleteState) |
|
|
|
|
|
{ |
|
|
|
|
|
if (item.B3ID.HasValue) |
|
|
|
|
|
bwpClient.Call<int>("/MainSystem/B3ButcherManage/Rpcs/WeighBillRpc/Delete", item.B3ID.Value); |
|
|
|
|
|
context.Session.Delete(item); |
|
|
|
|
|
context.Commit(); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
var sync = CreateRpcWeightBill(item); |
|
|
|
|
|
var back = bwpClient.Call<BackRpcObj>("/MainSystem/B3ButcherManage/Rpcs/WeighBillRpc/UpdateOrInsert", sync); |
|
|
|
|
|
|
|
|
|
|
|
#region 同步完了要清理掉删除的明细(当前实体和数据库)
|
|
|
|
|
|
ClearDetails(item, context.Session); |
|
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
#region 反填信息
|
|
|
|
|
|
item.B3ID = back.ID; |
|
|
|
|
|
SetBillAsSynced(item.ID, item.B3ID.Value, context.Session); |
|
|
|
|
|
|
|
|
|
|
|
foreach (var bItem in back.DetailBack) |
|
|
|
|
|
{ |
|
|
|
|
|
switch (bItem.Flag) |
|
|
|
|
|
{ |
|
|
|
|
|
case "Details": |
|
|
|
|
|
ExecuteSimpleDetail<WeightBill_Detail>(bItem, context.Session); |
|
|
|
|
|
break; |
|
|
|
|
|
case "FarmerDetails": |
|
|
|
|
|
ExecuteSimpleDetail<WeightBill_FarmerDetail>(bItem, context.Session); |
|
|
|
|
|
break; |
|
|
|
|
|
case "SanctionDetails": |
|
|
|
|
|
ExecuteSimpleDetail<WeightBill_SanctionDetail>(bItem, context.Session); |
|
|
|
|
|
break; |
|
|
|
|
|
default: |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
//栋舍明细在B3系统不存在,所以无返回信息
|
|
|
|
|
|
ExecuteHouseDetial(item.ID, context.Session); |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
context.Commit(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static void DeleteEntity<T>(IDmoSession session) |
|
|
|
|
|
where T : SyncBase |
|
|
|
|
|
{ |
|
|
|
|
|
var delete = new DQDeleteDom(typeof(T)); |
|
|
|
|
|
delete.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DeleteState", true), DQCondition.IsNull(DQExpression.Field("B3ID")))); |
|
|
|
|
|
session.ExecuteNonQuery(delete); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static IEnumerable<WeightBill> GetAllNeedSyncBill() |
|
|
static IEnumerable<WeightBill> GetAllNeedSyncBill() |
|
|
{ |
|
|
{ |
|
|
var query = new DmoQuery(typeof(WeightBill)); |
|
|
var query = new DmoQuery(typeof(WeightBill)); |
|
|
@ -70,128 +84,95 @@ namespace BWP.B3ClientService.Tasks.UpdateLoad |
|
|
return query.EExecuteList().Cast<WeightBill>(); |
|
|
return query.EExecuteList().Cast<WeightBill>(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static BackRpcObj Sync(WeightBill bill, string serverUri) |
|
|
|
|
|
|
|
|
static RpcWeightBill CreateRpcWeightBill(WeightBill bill) |
|
|
{ |
|
|
{ |
|
|
var bwpClient = new BWPClient(serverUri, bill.Creator); |
|
|
|
|
|
WeighBill dmo = new WeighBill(); |
|
|
|
|
|
if (bill.B3ID.HasValue) |
|
|
|
|
|
dmo = bwpClient.Call<WeighBill>("/MainSystem/B3ButcherManage/Rpcs/WeighBillRpc/Load", bill.B3ID.Value); |
|
|
|
|
|
dmo.AccountingUnit_ID = bill.AccountingUnit_ID; |
|
|
|
|
|
dmo.Department_ID = bill.Department_ID; |
|
|
|
|
|
dmo.Zone_ID = bill.Zone_ID; |
|
|
|
|
|
dmo.Employee_ID = bill.Employee_ID; |
|
|
|
|
|
dmo.Supplier_ID = bill.Supplier_ID; |
|
|
|
|
|
dmo.WeighTime = bill.WeighTime; |
|
|
|
|
|
dmo.ShackPrice = bill.ShackPrice; |
|
|
|
|
|
dmo.ShackWeight = bill.ShackWeight; |
|
|
|
|
|
dmo.ShackMoney = bill.ShackMoney; |
|
|
|
|
|
dmo.PurchaseType = bill.PurchaseType_ID; |
|
|
|
|
|
dmo.Inspector_ID = bill.Inspector_ID; |
|
|
|
|
|
dmo.Car_ID = bill.Car_ID; |
|
|
|
|
|
dmo.AnimalTestNumber = bill.AnimalTestNumber; |
|
|
|
|
|
dmo.AnimalTestDate = bill.AnimalTestDate; |
|
|
|
|
|
dmo.AnimalTestMan = bill.AnimalTestMan; |
|
|
|
|
|
dmo.Remark = bill.Remark; |
|
|
|
|
|
dmo.CID = bill.ID; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var bF in bill.FarmerDetails) |
|
|
|
|
|
{ |
|
|
|
|
|
//未上传标识为删除的,已经在ClearUnUpdateLoadAndDeleteData里处理了
|
|
|
|
|
|
var first = dmo.FarmerDetails.FirstOrDefault(x => x.ID == bF.B3ID); |
|
|
|
|
|
if (bF.DeleteState) |
|
|
|
|
|
{ |
|
|
|
|
|
if (first != null) |
|
|
|
|
|
dmo.FarmerDetails.Remove(first); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (first == null) |
|
|
|
|
|
{ |
|
|
|
|
|
first = new Weigh_FarmerDetail(); |
|
|
|
|
|
dmo.FarmerDetails.Add(first); |
|
|
|
|
|
first.CID = bF.ID; |
|
|
|
|
|
} |
|
|
|
|
|
first.Farmer_ID = bF.Farmer_ID; |
|
|
|
|
|
first.Number = bF.Number; |
|
|
|
|
|
first.Weigh_ID = dmo.ID; |
|
|
|
|
|
first.Weight = bF.Weight; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
var result = new RpcWeightBill(); |
|
|
|
|
|
result.Bill = new SWeightBill(); |
|
|
|
|
|
DmoUtil.CopyDmoFields(bill, result.Bill); |
|
|
|
|
|
|
|
|
foreach (var bd in bill.Details) |
|
|
|
|
|
|
|
|
var d = bill.Details.Where(x => !x.DeleteState); |
|
|
|
|
|
result.Details = d.Select(x => { var y = new SWeightBill_Detail(); DmoUtil.CopyDmoFields(x, y); return y; }).ToArray(); |
|
|
|
|
|
if (result.Details.Any()) |
|
|
{ |
|
|
{ |
|
|
var first = dmo.WeighRecord.FirstOrDefault(x => x.ID == bd.B3ID); |
|
|
|
|
|
if (bd.DeleteState) |
|
|
|
|
|
{ |
|
|
|
|
|
if (first != null) |
|
|
|
|
|
dmo.WeighRecord.Remove(first); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (first == null) |
|
|
|
|
|
{ |
|
|
|
|
|
first = new Weigh_Record(); |
|
|
|
|
|
dmo.WeighRecord.Add(first); |
|
|
|
|
|
first.CID = bd.ID; |
|
|
|
|
|
} |
|
|
|
|
|
first.Weigh_ID = dmo.ID; |
|
|
|
|
|
first.LiveVarieties_ID = bill.LiveVarieties_ID; |
|
|
|
|
|
first.HogGrade_ID = bill.HogGrade_ID; |
|
|
|
|
|
first.Number = bd.Number ?? 0; |
|
|
|
|
|
first.MaoWeight = bd.MaoWeight; |
|
|
|
|
|
first.PiWeight = bd.PiWeight; |
|
|
|
|
|
first.Weight = bd.Weight; |
|
|
|
|
|
first.LiveColonyHouse_Name = string.Join(",", bill.HouseDetails.Where(x => !x.DeleteState).Select(x => x.LiveColonyHouse_Name)); |
|
|
|
|
|
|
|
|
result.Details.OrderBy(x => x.ID).First().LiveColonyHouse_Name = string.Join(",", bill.HouseDetails.Where(x => !x.DeleteState).Select(x => x.LiveColonyHouse_Name)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
foreach (var bs in bill.SanctionDetails) |
|
|
|
|
|
{ |
|
|
|
|
|
var first = dmo.WeighAbnormalRecording.FirstOrDefault(x => x.ID == bs.B3ID); |
|
|
|
|
|
if (bs.DeleteState) |
|
|
|
|
|
{ |
|
|
|
|
|
if (first != null) |
|
|
|
|
|
dmo.WeighAbnormalRecording.Remove(first); |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
if (first == null) |
|
|
|
|
|
{ |
|
|
|
|
|
first = new Weigh_AbnormalRecording(); |
|
|
|
|
|
dmo.WeighAbnormalRecording.Add(first); |
|
|
|
|
|
first.CID = bs.ID; |
|
|
|
|
|
} |
|
|
|
|
|
first.Sanction_ID = bs.Sanction_ID; |
|
|
|
|
|
first.AbnormalItem_ID = bs.AbnormalItem_ID; |
|
|
|
|
|
first.Num = bs.Number ?? 0; |
|
|
|
|
|
first.Weigh_ID = dmo.ID; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
result.D_Details = bill.Details.Where(x => x.DeleteState && x.B3ID.HasValue).Select(x => x.B3ID.Value).ToArray(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fd = bill.FarmerDetails.Where(x => !x.DeleteState); |
|
|
|
|
|
result.FarmerDetails = fd.Select(x => { var y = new SWeightBill_FarmerDetail(); DmoUtil.CopyDmoFields(x, y); return y; }).ToArray(); |
|
|
|
|
|
|
|
|
|
|
|
result.D_FarmerDetails = bill.FarmerDetails.Where(x => x.DeleteState && x.B3ID.HasValue).Select(x => x.B3ID.Value).ToArray(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var sd = bill.SanctionDetails.Where(x => !x.DeleteState); |
|
|
|
|
|
result.SanctionDetails = sd.Select(x => { var y = new SWeightBill_SanctionDetail(); DmoUtil.CopyDmoFields(x, y); return y; }).ToArray(); |
|
|
|
|
|
|
|
|
|
|
|
result.D_SanctionDetails = bill.SanctionDetails.Where(x => x.DeleteState && x.B3ID.HasValue).Select(x => x.B3ID.Value).ToArray(); |
|
|
|
|
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static void ClearDetails(WeightBill bill, IDmoSession session) |
|
|
|
|
|
{ |
|
|
|
|
|
var d = bill.Details.Where(x => x.DeleteState).ToArray(); |
|
|
|
|
|
foreach (var dd in d) |
|
|
|
|
|
bill.Details.Remove(dd); |
|
|
|
|
|
DeleteDetail<WeightBill_Detail>(bill.ID, session); |
|
|
|
|
|
|
|
|
|
|
|
var f = bill.FarmerDetails.Where(x => x.DeleteState).ToArray(); |
|
|
|
|
|
foreach (var fd in f) |
|
|
|
|
|
bill.FarmerDetails.Remove(fd); |
|
|
|
|
|
DeleteDetail<WeightBill_FarmerDetail>(bill.ID, session); |
|
|
|
|
|
|
|
|
|
|
|
var h = bill.HouseDetails.Where(x => x.DeleteState).ToArray(); |
|
|
|
|
|
foreach (var hd in h) |
|
|
|
|
|
bill.HouseDetails.Remove(hd); |
|
|
|
|
|
DeleteDetail<WeightBill_HouseDetail>(bill.ID, session); |
|
|
|
|
|
|
|
|
|
|
|
var s = bill.SanctionDetails.Where(x => x.DeleteState).ToArray(); |
|
|
|
|
|
foreach (var sd in s) |
|
|
|
|
|
bill.SanctionDetails.Remove(sd); |
|
|
|
|
|
DeleteDetail<WeightBill_SanctionDetail>(bill.ID, session); |
|
|
|
|
|
|
|
|
//var farmerDic = new Dictionary<string, object>();
|
|
|
|
|
|
//foreach (var farmerDetail in bill.FarmerDetails)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// farmerDic.Add("ID", farmerDetail.B3ID);
|
|
|
|
|
|
// farmerDic.Add("Weigh_ID", bill.ID);
|
|
|
|
|
|
// farmerDic.Add("Farmer_ID", farmerDetail.Farmer_ID);
|
|
|
|
|
|
// farmerDic.Add("Number", farmerDetail.Number);
|
|
|
|
|
|
// farmerDic.Add("Weight", farmerDetail.Weight);
|
|
|
|
|
|
// farmerDic.Add("CID", farmerDetail.ID);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//dic.Add("FarmerDetails", farmerDic);
|
|
|
|
|
|
|
|
|
static void DeleteDetail<T>(long mainID, IDmoSession session) |
|
|
|
|
|
where T : SyncBase |
|
|
|
|
|
{ |
|
|
|
|
|
var delete = new DQDeleteDom(typeof(T)); |
|
|
|
|
|
delete.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("WeightBill_ID", mainID), DQCondition.EQ("DeleteState", true))); |
|
|
|
|
|
session.ExecuteNonQuery(delete); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//var farmerDic = new Dictionary<string, object>();
|
|
|
|
|
|
//foreach (var farmerDetail in bill.FarmerDetails)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// farmerDic.Add("ID", farmerDetail.B3ID);
|
|
|
|
|
|
// farmerDic.Add("Weigh_ID", bill.ID);
|
|
|
|
|
|
// farmerDic.Add("Farmer_ID", farmerDetail.Farmer_ID);
|
|
|
|
|
|
// farmerDic.Add("Number", farmerDetail.Number);
|
|
|
|
|
|
// farmerDic.Add("Weight", farmerDetail.Weight);
|
|
|
|
|
|
// farmerDic.Add("CID", farmerDetail.ID);
|
|
|
|
|
|
//}
|
|
|
|
|
|
|
|
|
static void ExecuteHouseDetial(long mainID, IDmoSession session) |
|
|
|
|
|
{ |
|
|
|
|
|
var update = new DQUpdateDom(typeof(WeightBill_HouseDetail)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("B3ID", -1)); |
|
|
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("WeightBill_ID", mainID)); |
|
|
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
//dic.Add("FarmerDetails", farmerDic);
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
|
static void ExecuteSimpleDetail<T>(BackRpcObj details, IDmoSession session) |
|
|
|
|
|
where T : SyncBase |
|
|
|
|
|
{ |
|
|
|
|
|
foreach (var item in details.DetailBack) |
|
|
|
|
|
{ |
|
|
|
|
|
var update = new DQUpdateDom(typeof(T)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("B3ID", item.ID)); |
|
|
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", long.Parse(item.Flag))); |
|
|
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void SetBillAsSynced(long id, long B3ID, IDmoSession session) |
|
|
|
|
|
{ |
|
|
|
|
|
var update = new DQUpdateDom(typeof(WeightBill)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("Sync", true)); |
|
|
|
|
|
update.Columns.Add(new DQUpdateColumn("B3ID", B3ID)); |
|
|
|
|
|
update.Where.Conditions.Add(DQCondition.EQ("ID", id)); |
|
|
|
|
|
session.ExecuteNonQuery(update); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |