diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj index 694674c..2f5c9ad 100644 --- a/B3ClientService/B3ClientService.csproj +++ b/B3ClientService/B3ClientService.csproj @@ -91,6 +91,8 @@ + + @@ -104,6 +106,7 @@ + diff --git a/B3ClientService/RpcBO/Bill/OrderDetail/RpcOrderBill.cs b/B3ClientService/RpcBO/Bill/OrderDetail/RpcOrderBill.cs new file mode 100644 index 0000000..86b85e8 --- /dev/null +++ b/B3ClientService/RpcBO/Bill/OrderDetail/RpcOrderBill.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BWP.B3ClientService.RpcBO +{ + public class RpcOrderBill + { + public long? AccountingUnit_ID { get; set; } + + public DateTime? Date { get; set; } + + public SOrderDetail[] Details { get; set; } + + public long[] DeleteIDs { get; set; } + } +} diff --git a/B3ClientService/RpcBO/Bill/OrderDetail/SOrderDetail.cs b/B3ClientService/RpcBO/Bill/OrderDetail/SOrderDetail.cs new file mode 100644 index 0000000..55deee6 --- /dev/null +++ b/B3ClientService/RpcBO/Bill/OrderDetail/SOrderDetail.cs @@ -0,0 +1,25 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace BWP.B3ClientService.RpcBO +{ + public class SOrderDetail + { + public long ID { get; set; } + + public long? B3ID { get; set; } + + public long B3WeighBill_ID { get; set; } + + public int Order { get; set; } + + public int PlanNumber { get; set; } + + public string LiveColonyHouse_Name { get; set; } + + public bool IsHurryButcher { get; set; } + } +} diff --git a/B3ClientService/Tasks/UpdateLoad/UploadOrderDetail.cs b/B3ClientService/Tasks/UpdateLoad/UploadOrderDetail.cs new file mode 100644 index 0000000..77947cc --- /dev/null +++ b/B3ClientService/Tasks/UpdateLoad/UploadOrderDetail.cs @@ -0,0 +1,104 @@ +using BWP.B3ClientService.BO; +using BWP.B3ClientService.RpcBO; +using BWP.B3Frameworks.Utils; +using Forks.EnterpriseServices.BusinessInterfaces; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Web.Script.Serialization; +using TSingSoft.WebPluginFramework; +using TSingSoft.WebPluginFramework.BWPClients; + + +namespace BWP.B3ClientService.Tasks.UpdateLoad +{ + public static class UploadOrderDetail + { + public static void Execute(string uri) + { + var serializer = new JavaScriptSerializer(); + //获取所有未上传的数据 + var allBill = GetAllNeedSyncBill(); + foreach (var group in allBill.GroupBy(x => new { x.Date, x.AccountingUnit_ID }).OrderBy(x => x.Key.Date)) + { + var creator = group.First().Creator; + + var bwpClient = new BWPClient(uri, creator); + using (var context = new TransactionContext()) + { + #region 删除 + DeleteUnSyncDeleteData(context.Session); + #endregion + var entity = new RpcOrderBill(); + entity.AccountingUnit_ID = group.Key.AccountingUnit_ID; + entity.Date = group.Key.Date; + var details = new List(); + var delete = new List(); + foreach (var item in group) + { + if (item.DeleteState) + delete.Add(item.B3ID.Value); + else + { + var detail = new SOrderDetail(); + DmoUtil.CopyDmoFields(item, detail); + details.Add(detail); + } + } + + var sync = serializer.Serialize(entity); + var back = bwpClient.Call>>("/MainSystem/B3ButcherManage/Rpcs/ButcherOrderRpc/UpdateOrInsert", sync); + + #region 同步完了要清理掉删除的记录 + if (delete.Any()) + ClearDetails(delete, context.Session); + + #endregion + + #region 反填信息 + foreach (var item in back) + { + Update(item, context.Session); + } + #endregion + + context.Commit(); + } + } + } + + private static void ClearDetails(List b3IDs, IDmoSession session) + { + var delete = new DQDeleteDom(typeof(OrderDetail)); + delete.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("B3ID"), b3IDs.Select(x => DQExpression.Value(x)).ToArray())); + } + + private static IEnumerable GetAllNeedSyncBill() + { + var query = new DmoQuery(typeof(OrderDetail)); + query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("B3WeighBill_ID")), DQCondition.EQ("Sync", false))); + return query.EExecuteList().Cast(); + } + + static void DeleteUnSyncDeleteData(IDmoSession session) + { + var delete = new DQDeleteDom(typeof(OrderDetail)); + delete.Where.Conditions.Add(DQCondition.And(DQCondition.IsNull(DQExpression.Field("B3ID")), DQCondition.EQ("DeleteState", true))); + session.ExecuteNonQuery(delete); + } + + static void Update(CTuple item, IDmoSession session) + { + var update = new DQUpdateDom(typeof(OrderDetail)); + update.Columns.Add(new DQUpdateColumn("B3ID", item.Item2)); + update.Columns.Add(new DQUpdateColumn("B3MainID", item.Item3)); + update.Columns.Add(new DQUpdateColumn("Sync", true)); + update.Where.Conditions.Add(DQCondition.EQ("ID", item.Item1)); + session.ExecuteNonQuery(update); + } + } +}