diff --git a/B3ClientService/RpcBO/Bill/WeightBill/SWeightBill.cs b/B3ClientService/RpcBO/Bill/WeightBill/SWeightBill.cs index a68e000..cbf9c7a 100644 --- a/B3ClientService/RpcBO/Bill/WeightBill/SWeightBill.cs +++ b/B3ClientService/RpcBO/Bill/WeightBill/SWeightBill.cs @@ -1,4 +1,5 @@ using BWP.B3ClientService.BO; +using BWP.B3Frameworks.BO; using Forks.EnterpriseServices.JsonRpc; using System; using System.Collections.Generic; @@ -10,8 +11,10 @@ using TSingSoft.WebPluginFramework; namespace BWP.B3ClientService.RpcBO { [BOClass(Exclude = true)] - public class SWeightBill : SyncBase + public class SWeightBill : Base { + public long? B3ID { get; set; } + public long? AccountingUnit_ID { get; set; } public long? Department_ID { get; set; } diff --git a/B3ClientService/Rpcs/BillRpc/HouseAndSanctionRpc.cs b/B3ClientService/Rpcs/BillRpc/HouseAndSanctionRpc.cs index 272ab77..144c8b7 100644 --- a/B3ClientService/Rpcs/BillRpc/HouseAndSanctionRpc.cs +++ b/B3ClientService/Rpcs/BillRpc/HouseAndSanctionRpc.cs @@ -170,6 +170,7 @@ namespace BWP.B3ClientService.Rpcs.BillRpc update.Columns.Add(new DQUpdateColumn("Inspector_ID", entity.Inspector_ID)); update.Columns.Add(new DQUpdateColumn("Inspector_Name", entity.Inspector_Name)); update.Columns.Add(new DQUpdateColumn("HouseNames", string.Join(",", houseNames))); + update.Columns.Add(new DQUpdateColumn("SanctionNumber", entity.SanctionDetails.Sum(x => x.Number ?? 0))); update.Columns.Add(new DQUpdateColumn("Sync", false)); update.Columns.Add(new DQUpdateColumn("ModifyTime", DateTime.Now)); update.Where.Conditions.Add(DQCondition.EQ("ID", entity.ID)); diff --git a/B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs b/B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs index b6e312b..be71524 100644 --- a/B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs +++ b/B3ClientService/Rpcs/BillRpc/WeightBillRpc.cs @@ -1,4 +1,5 @@ using BWP.B3ClientService.BO; +using BWP.B3ClientService.Tasks.UpdateLoad; using BWP.B3Frameworks.Utils; using Forks.EnterpriseServices.DomainObjects2; using Forks.EnterpriseServices.DomainObjects2.DQuery; @@ -139,8 +140,9 @@ namespace BWP.B3ClientService.Rpcs.BillRpc static void FillServerUpdateFields(IDmoSession session, WeightBill dmo) { - var min = InnerBLUtil.GetSingleDmo(session, "ID", dmo.ID, "B3ID", "Inspector_ID", "Inspector_Name", "HouseNames", "SanctionNumber"); + var min = InnerBLUtil.GetSingleDmo(session, "ID", dmo.ID, "B3ID", "DeleteState", "Inspector_ID", "Inspector_Name", "HouseNames", "SanctionNumber"); dmo.B3ID = min.B3ID; + dmo.DeleteState = min.DeleteState; dmo.Inspector_ID = min.Inspector_ID; dmo.Inspector_Name = min.Inspector_Name; dmo.HouseNames = min.HouseNames; @@ -202,20 +204,30 @@ namespace BWP.B3ClientService.Rpcs.BillRpc { using (var session = Dmo.NewSession()) { + var detailID = InnerBLUtil.GetDmoProperty(session, typeof(WeightBill_Detail), "ID", new Tuple("WeightBill_ID", id), new Tuple("DeleteState", false)); + if (detailID.HasValue) + DeleteWeightDetail(session, detailID.Value); + + var b3ID = InnerBLUtil.GetDmoPropertyByID(session, typeof(WeightBill), "B3ID", id); + if (b3ID == null) + { + UpLoadWeightBill.Delete(id, session); + session.Commit(); + return true; + } + var update = new DQUpdateDom(typeof(WeightBill)); update.Columns.Add(new DQUpdateColumn("DeleteState", true)); update.Columns.Add(new DQUpdateColumn("Sync", false)); update.Where.Conditions.Add(DQCondition.EQ("ID", id)); - - var detailID = InnerBLUtil.GetDmoProperty(session, typeof(WeightBill_Detail), "ID", new Tuple("WeightBill_ID", id), new Tuple("DeleteState", false)); - if (detailID.HasValue) - DeleteWeightDetail(session, detailID.Value); + session.ExecuteNonQuery(update); session.Commit(); } return true; } + [Rpc] public static string SyncBillB3Ids(List ids) { diff --git a/B3ClientService/Tasks/UpdateLoad/UpLoadWeightBill.cs b/B3ClientService/Tasks/UpdateLoad/UpLoadWeightBill.cs index 9d8b909..6df9144 100644 --- a/B3ClientService/Tasks/UpdateLoad/UpLoadWeightBill.cs +++ b/B3ClientService/Tasks/UpdateLoad/UpLoadWeightBill.cs @@ -18,163 +18,117 @@ namespace BWP.B3ClientService.Tasks.UpdateLoad { public static class UpLoadWeightBill { - //public static void Execute(string uri) - //{ - // var serializer = new JavaScriptSerializer(); - // //获取所有未上传的数据 - // var allBill = GetAllNeedSyncBill(); - - // foreach (var item in allBill) - // { - // var bwpClient = new BWPClient(uri, item.Creator); - // using (var context = new TransactionContext()) - // { - // #region 删除 - // if (item.DeleteState) - // { - // if (item.B3ID.HasValue) - // bwpClient.Call("/MainSystem/B3ButcherManage/Rpcs/WeighBillRpc/Delete", item.B3ID.Value); - // context.Session.Delete(item); - // context.Commit(); - // continue; - // } - // #endregion - - // var sync = serializer.Serialize(CreateRpcWeightBill(item)); - // var back = bwpClient.Call("/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(bItem, context.Session); - // break; - // case "FarmerDetails": - // ExecuteSimpleDetail(bItem, context.Session); - // break; - // case "SanctionDetails": - // ExecuteSimpleDetail(bItem, context.Session); - // break; - // default: - // break; - // } - // } - // //栋舍明细在B3系统不存在,所以无返回信息 - // ExecuteHouseDetial(item.ID, context.Session); - // #endregion - - // context.Commit(); - // } - // } - //} - - //static IEnumerable GetAllNeedSyncBill() - //{ - // var query = new DmoQuery(typeof(WeightBill)); - // query.Where.Conditions.Add(DQCondition.EQ("Sync", false)); - // query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); - // return query.EExecuteList().Cast(); - //} - - //static RpcWeightBill CreateRpcWeightBill(WeightBill bill) - //{ - // var result = new RpcWeightBill(); - // result.Bill = new SWeightBill(); - // DmoUtil.CopyDmoFields(bill, result.Bill); - - // 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()) - // { - // result.Details.OrderBy(x => x.ID).First().LiveColonyHouse_Name = string.Join(",", bill.HouseDetails.Where(x => !x.DeleteState).Select(x => x.LiveColonyHouse_Name)); - // } - - // 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(bill.ID, session); - - // var f = bill.FarmerDetails.Where(x => x.DeleteState).ToArray(); - // foreach (var fd in f) - // bill.FarmerDetails.Remove(fd); - // DeleteDetail(bill.ID, session); - - // var h = bill.HouseDetails.Where(x => x.DeleteState).ToArray(); - // foreach (var hd in h) - // bill.HouseDetails.Remove(hd); - // DeleteDetail(bill.ID, session); - - // var s = bill.SanctionDetails.Where(x => x.DeleteState).ToArray(); - // foreach (var sd in s) - // bill.SanctionDetails.Remove(sd); - // DeleteDetail(bill.ID, session); - - //} - - //static void DeleteDetail(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); - //} - - //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); - //} - - //static void ExecuteSimpleDetail(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); - //} + public static void Execute(string uri) + { + var serializer = new JavaScriptSerializer(); + //获取所有未上传的数据 + var allBill = GetAllNeedSyncBill(); + + foreach (var item in allBill) + { + var bwpClient = new BWPClient(uri, item.Creator); + using (var context = new TransactionContext()) + { + #region 删除 + if (item.DeleteState) + { + if (item.B3ID.HasValue) + bwpClient.Call("/MainSystem/B3ButcherManage/Rpcs/WeighBillRpc/Delete", item.B3ID.Value); + Delete(item.ID, context.Session); + context.Commit(); + continue; + } + #endregion + + var sync = serializer.Serialize(CreateRpcWeightBill(item)); + item.B3ID = bwpClient.Call("/MainSystem/B3ButcherManage/Rpcs/WeighBillRpc/UpdateOrInsert", sync); + + ClearDetails(item.ID, context.Session); + + SetBillAsSynced(item.ID, item.B3ID.Value, context.Session); + + context.Commit(); + } + } + } + + static IEnumerable GetAllNeedSyncBill() + { + var query = new DmoQuery(typeof(WeightBill)); + query.Where.Conditions.Add(DQCondition.EQ("Sync", false)); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID")); + return query.EExecuteList().Cast(); + } + + static RpcWeightBill CreateRpcWeightBill(WeightBill bill) + { + var result = new RpcWeightBill(); + result.Bill = new SWeightBill(); + DmoUtil.CopyDmoFields(bill, result.Bill); + + var details = GetDetails(bill.ID); + result.Details = details.Where(x => !x.DeleteState).Select(x => { var y = new SWeightBill_Detail(); DmoUtil.CopyDmoFields(x, y); return y; }).ToArray(); + foreach (var item in result.Details) + { + item.LiveColonyHouse_Name = bill.HouseNames; + } + + result.D_Details = details.Where(x => x.DeleteState).Select(x => x.ID).ToArray(); + + var farmerDetails = GetDetails(bill.ID); + result.FarmerDetails = farmerDetails.Where(x => !x.DeleteState).Select(x => { var y = new SWeightBill_FarmerDetail(); DmoUtil.CopyDmoFields(x, y); return y; }).ToArray(); + + result.D_FarmerDetails = farmerDetails.Where(x => x.DeleteState).Select(x => x.ID).ToArray(); + + var sanctionDetails = GetDetails(bill.ID); + result.SanctionDetails = sanctionDetails.Where(x => !x.DeleteState).Select(x => { var y = new SWeightBill_SanctionDetail(); DmoUtil.CopyDmoFields(x, y); return y; }).ToArray(); + + result.D_SanctionDetails = sanctionDetails.Where(x => x.DeleteState).Select(x => x.ID).ToArray(); + + return result; + } + + public static void Delete(long id, IDmoSession session) + { + Delete("ID", id, session); + Delete("WeightBill_ID", id, session); + Delete("WeightBill_ID", id, session); + Delete("WeightBill_ID", id, session); + Delete("WeightBill_ID", id, session); + } + + static void Delete(string key, long value, IDmoSession session, bool withDeleteState = false) + where T : SyncBase + { + var delete = new DQDeleteDom(typeof(T)); + delete.Where.Conditions.Add(DQCondition.EQ(key, value)); + if (withDeleteState) + delete.Where.Conditions.Add(DQCondition.EQ("DeleteState", true)); + session.ExecuteNonQuery(delete); + } + + static void ClearDetails(long mainID, IDmoSession session) + { + Delete("WeightBill_ID", mainID, session, true); + Delete("WeightBill_ID", mainID, session, true); + Delete("WeightBill_ID", mainID, session, true); + Delete("WeightBill_ID", mainID, session, true); + } + + 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); + } + + static IEnumerable GetDetails(long id) + { + var query = new DmoQuery(typeof(T)); + query.Where.Conditions.Add(DQCondition.EQ("WeightBill_ID", id)); + return query.EExecuteList().Cast(); + } } } diff --git a/B3ClientService/Tasks/UpdateLoad/UploadTest.cs b/B3ClientService/Tasks/UpdateLoad/UploadTest.cs index ac22d25..82e9010 100644 --- a/B3ClientService/Tasks/UpdateLoad/UploadTest.cs +++ b/B3ClientService/Tasks/UpdateLoad/UploadTest.cs @@ -22,7 +22,7 @@ namespace BWP.B3ClientService.Tasks var serverUri = ServerHost.GetServerUrl(); if (string.IsNullOrEmpty(serverUri)) throw new Exception("请配置服务器地址"); - //UpLoadWeightBill.Execute(serverUri); + UpLoadWeightBill.Execute(serverUri); UploadOrderDetail.Execute(serverUri); UploadSecondOrder.Execute(serverUri); }