| @ -0,0 +1,122 @@ | |||||
| using BWP.B3ClientService.BO; | |||||
| using BWP.B3ClientService.NamedValueTemplate; | |||||
| 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 SegmentPickUpRpc | |||||
| { | |||||
| [Rpc(RpcFlags.SkipAuth)] | |||||
| public static string GetScanInfo(string barCode) | |||||
| { | |||||
| var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo))); | |||||
| query.Columns.Add(DQSelectColumn.Field("Goods_ID")); | |||||
| query.Columns.Add(DQSelectColumn.Field("Goods_Name")); | |||||
| query.Columns.Add(DQSelectColumn.Field("Weight")); | |||||
| query.Where.Conditions.Add(DQCondition.EQ("BarCode", barCode)); | |||||
| var r = query.EExecuteScalar<long, string, decimal>(); | |||||
| if (r == null) | |||||
| return null; | |||||
| return JsonConvert.SerializeObject(new ExtensionObj { LongExt1 = r.Item1, StringExt1 = r.Item2, DecimalExt1 = r.Item3 }); | |||||
| } | |||||
| [Rpc(RpcFlags.SkipAuth)] | |||||
| public static string GetBeforeInfo(List<string> codeList) | |||||
| { | |||||
| var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo))); | |||||
| query.Columns.Add(DQSelectColumn.Field("BarCode")); | |||||
| query.Columns.Add(DQSelectColumn.Field("Weight")); | |||||
| query.Columns.Add(DQSelectColumn.Field("Goods_ID")); | |||||
| query.Columns.Add(DQSelectColumn.Field("Goods_Name")); | |||||
| query.Where.Conditions.Add(DQCondition.And(DQCondition.IsNotNull(DQExpression.Field("Goods_ID")), DQCondition.InList(DQExpression.Field("BarCode"), codeList.Select(x => DQExpression.Value(x)).ToArray()))); | |||||
| var result = query.EExecuteList<string, decimal, long, string>(); | |||||
| var back = result.Select(x => new ExtensionObj { StringExt1 = x.Item1, DecimalExt1 = x.Item2, LongExt1 = x.Item3, StringExt2 = x.Item4 }); | |||||
| return JsonConvert.SerializeObject(back); | |||||
| } | |||||
| [Rpc(RpcFlags.SkipAuth)] | |||||
| public static int UploadSegmentInfo(string jsonArr) | |||||
| { | |||||
| var list = JsonConvert.DeserializeObject<List<SegmentPickUpObj>>(jsonArr); | |||||
| 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) | |||||
| { | |||||
| if (string.IsNullOrEmpty(code)) | |||||
| return null; | |||||
| var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo))); | |||||
| query.Columns.Add(DQSelectColumn.Field("ID")); | |||||
| query.Where.Conditions.Add(DQCondition.EQ("BarCode", code)); | |||||
| return query.EExecuteScalar<long?>(session); | |||||
| } | |||||
| static void Update(long id, SegmentPickUpObj obj, IDmoSession session) | |||||
| { | |||||
| var update = new DQUpdateDom(typeof(SegmentProductionInfo)); | |||||
| update.Columns.Add(new DQUpdateColumn("PickWorker_ID", obj.TakeOutWorker_ID)); | |||||
| update.Columns.Add(new DQUpdateColumn("PickWorkUnit_ID", obj.WorkUnit_ID)); | |||||
| update.Columns.Add(new DQUpdateColumn("PickTime", obj.Time)); | |||||
| update.Columns.Add(new DQUpdateColumn("PickNumber", 1)); | |||||
| update.Columns.Add(new DQUpdateColumn("PickType", 领用类型.分割领用)); | |||||
| update.Where.Conditions.Add(DQCondition.EQ("ID", id)); | |||||
| session.ExecuteNonQuery(update); | |||||
| } | |||||
| static void Insert(SegmentPickUpObj obj, IDmoSession session) | |||||
| { | |||||
| var entity = new SegmentProductionInfo(); | |||||
| entity.BarCode = obj.BarCode; | |||||
| entity.Goods_ID = obj.Goods_ID; | |||||
| entity.PickWorker_ID = obj.TakeOutWorker_ID; | |||||
| entity.PickWorkUnit_ID = obj.WorkUnit_ID; | |||||
| entity.Weight = obj.Weight; | |||||
| entity.PickTime = obj.Time; | |||||
| entity.PickNumber = obj.Number; | |||||
| entity.PickType = 领用类型.分割领用; | |||||
| if (string.IsNullOrEmpty(entity.BarCode)) | |||||
| entity.ProductBatch_ID = obj.ProductBatch_ID; | |||||
| session.Insert(entity); | |||||
| } | |||||
| } | |||||
| class SegmentPickUpObj | |||||
| { | |||||
| public string BarCode { get; set; } | |||||
| public long TakeOutWorker_ID { get; set; } | |||||
| public long? WorkUnit_ID { get; set; } | |||||
| public long? ProductBatch_ID { get; set; } | |||||
| public long? Goods_ID { get; set; } | |||||
| public decimal? Weight { get; set; } | |||||
| public DateTime? Time { get; set; } | |||||
| public int Number { get; set; } | |||||
| } | |||||
| } | |||||