| @ -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<List<CarcassSaleOutStoreObj>>(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<long?>(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<string, long?> GoodsCodeToID = new Dictionary<string, long?>(); | |||
| 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<long?>(session, typeof(Goods), "ID", new Tuple<string, object>("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; } | |||
| } | |||
| } | |||