|
|
@ -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<SOrderDetail>(); |
|
|
|
|
|
var delete = new List<long>(); |
|
|
|
|
|
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<List<CTuple<long, long, long>>>("/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<long> 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<OrderDetail> 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<OrderDetail>(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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<long, long, long> 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); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |