diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj index a3fb7eb..0f0129d 100644 --- a/B3ClientService/B3ClientService.csproj +++ b/B3ClientService/B3ClientService.csproj @@ -149,6 +149,7 @@ + diff --git a/B3ClientService/OfflinRpc/CarcassSaleOutStoreRpc.cs b/B3ClientService/OfflinRpc/CarcassSaleOutStoreRpc.cs new file mode 100644 index 0000000..348dab2 --- /dev/null +++ b/B3ClientService/OfflinRpc/CarcassSaleOutStoreRpc.cs @@ -0,0 +1,94 @@ +using BWP.B3ClientService.BO; +using BWP.B3ClientService.NamedValueTemplate; +using BWP.B3Frameworks.Utils; +using Forks.EnterpriseServices; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.JsonRpc; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TSingSoft.WebPluginFramework; + +namespace BWP.B3ClientService.Rpcs +{ + [Rpc] + public static class CarcassSaleOutStoreRpc + { + [Rpc(RpcFlags.SkipAuth)] + public static int UploadCarcassInfo(string json) + { + var list = JsonConvert.DeserializeObject>(json); + using (var session = Dmo.NewSession()) + { + foreach (var item in list) + { + var id = GetID(item.BarCode, session); + if (id.HasValue) + Update(id.Value, item, session); + else + Insert(item, session); + } + session.Commit(); + } + return 1; + } + + static long? GetID(string code, IDmoSession session) + { + var query = new DQueryDom(new JoinAlias(typeof(CarcassFullInfo))); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Where.Conditions.Add(DQCondition.EQ("BarCode", code)); + return query.EExecuteScalar(session); + } + + static void Update(long id, CarcassSaleOutStoreObj obj, IDmoSession session) + { + var goodsID = GetGoodsID(obj.SaleGoods_Code, session); + var update = new DQUpdateDom(typeof(CarcassFullInfo)); + update.Columns.Add(new DQUpdateColumn("PickGroupID", obj.GroupID)); + update.Columns.Add(new DQUpdateColumn("SaleGoods_ID", goodsID)); + update.Columns.Add(new DQUpdateColumn("PickWeight", obj.Weight)); + update.Columns.Add(new DQUpdateColumn("PickTime", obj.Time)); + update.Columns.Add(new DQUpdateColumn("PickType", 领用类型.白条销售)); + update.Where.Conditions.Add(DQCondition.EQ("ID", id)); + session.ExecuteNonQuery(update); + } + + static Dictionary GoodsCodeToID = new Dictionary(); + + static void Insert(CarcassSaleOutStoreObj obj, IDmoSession session) + { + var entity = new CarcassFullInfo(); + entity.BarCode = obj.BarCode; + entity.PickWeight = obj.Weight; + entity.PickGroupID = obj.GroupID; + entity.PickTime = obj.Time; + entity.SaleGoods_ID = GetGoodsID(obj.SaleGoods_Code, session); + entity.PickType = 领用类型.白条销售; + session.Insert(entity); + } + + static long? GetGoodsID(string code, IDmoSession session) + { + if (!GoodsCodeToID.ContainsKey(code)) + { + var id = InnerBLUtil.GetDmoProperty(session, typeof(Goods), "ID", new Tuple("Code", code)); + GoodsCodeToID.Add(code, id); + } + return GoodsCodeToID[code]; + } + + } + + class CarcassSaleOutStoreObj + { + public string BarCode { get; set; } + public decimal? Weight { get; set; } + public DateTime? Time { get; set; } + public long? GroupID { get; set; } + public string SaleGoods_Code { get; set; } + } +}