diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj index cd3a090..5716ca9 100644 --- a/B3ClientService/B3ClientService.csproj +++ b/B3ClientService/B3ClientService.csproj @@ -181,6 +181,7 @@ + @@ -209,6 +210,7 @@ + @@ -259,6 +261,7 @@ + diff --git a/B3ClientService/BO/Bill/SegmentProductionInfo.cs b/B3ClientService/BO/Bill/SegmentProductionInfo.cs index 1c4006d..00ce861 100644 --- a/B3ClientService/BO/Bill/SegmentProductionInfo.cs +++ b/B3ClientService/BO/Bill/SegmentProductionInfo.cs @@ -102,6 +102,9 @@ namespace BWP.B3ClientService.BO #endregion + [LogicName("入库合并ID")] + public long? InStoreCombine_ID { get; set; } + public bool IsSync { get; set; } [DbColumn(DefaultValue = false)] @@ -128,6 +131,10 @@ namespace BWP.B3ClientService.BO [Join("Goods_ID", "ID")] public string Goods_Code { get; set; } + [ReferenceTo(typeof(Goods), "Spec")] + [Join("Goods_ID", "ID")] + public string Goods_Spec { get; set; } + [ReferenceTo(typeof(Worker), "Name")] [Join("Worker_ID", "ID")] public string Worker_Name { get; set; } @@ -139,7 +146,7 @@ namespace BWP.B3ClientService.BO [ReferenceTo(typeof(ProductBatch), "Name")] [Join("ProductBatch_ID", "ID")] public string ProductBatch_Name { get; set; } - + [ReferenceTo(typeof(Worker), "Name")] [Join("InStoreWorker_ID", "ID")] public string InStoreWorker_Name { get; set; } diff --git a/B3ClientService/BO/ProductInStoreCombine_/ProductInStoreCombine.cs b/B3ClientService/BO/ProductInStoreCombine_/ProductInStoreCombine.cs new file mode 100644 index 0000000..e221b6a --- /dev/null +++ b/B3ClientService/BO/ProductInStoreCombine_/ProductInStoreCombine.cs @@ -0,0 +1,36 @@ +using BWP.B3Frameworks.BO; +using Forks.EnterpriseServices.DataForm; +using Forks.EnterpriseServices.DomainObjects2; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BWP.B3ClientService.BO +{ + [DFClass, Serializable] + public class ProductInStoreCombine : Base + { + public string CombineCode { get; set; } + + public long OutStore_ID { get; set; } + + [ReferenceTo(typeof(Store), "Code")] + [Join("OutStore_ID", "ID")] + public string OutStore_Code { get; set; } + + public long InStore_ID { get; set; } + + [ReferenceTo(typeof(Store), "Code")] + [Join("InStore_ID", "ID")] + public string InStore_Code { get; set; } + + public DateTime CombineTime { get; set; } + + public bool IsCreated { get; set; } + + private readonly List mBarCodes = new List(); + [NonDmoProperty] + public List BarCodes { get { return mBarCodes; } } + } +} diff --git a/B3ClientService/NamedValueTemplate.cs b/B3ClientService/NamedValueTemplate.cs index 0b6be95..9a7b841 100644 --- a/B3ClientService/NamedValueTemplate.cs +++ b/B3ClientService/NamedValueTemplate.cs @@ -22,6 +22,7 @@ namespace BWP.B3ClientService.NamedValueTemplate public static readonly NamedValue<终端> 分割生产 = new NamedValue<终端>(2); public static readonly NamedValue<终端> 扫码入库 = new NamedValue<终端>(3); public static readonly NamedValue<终端> 分割领用 = new NamedValue<终端>(4); + public static readonly NamedValue<终端> 成品入库 = new NamedValue<终端>(5); //51-100供B3用 public static readonly NamedValue<终端> 赶猪确认 = new NamedValue<终端>(103); public static readonly NamedValue<终端> 上线确认 = new NamedValue<终端>(104); diff --git a/B3ClientService/OfflinRpc/ProductInStoreCombineRpc.cs b/B3ClientService/OfflinRpc/ProductInStoreCombineRpc.cs new file mode 100644 index 0000000..82990b2 --- /dev/null +++ b/B3ClientService/OfflinRpc/ProductInStoreCombineRpc.cs @@ -0,0 +1,82 @@ +using BWP.B3ClientService.BO; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.JsonRpc; +using Forks.EnterpriseServices.SqlDoms; +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 ProductInStoreCombineRpc + { + [Rpc(RpcFlags.SkipAuth)] + public static string ScanBarCode(string barCode) + { + var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo))); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BarCode", barCode), DQCondition.EQ("Delete", false), DQCondition.IsNotNull(DQExpression.Field("Weight")))); + query.Columns.Add(DQSelectColumn.Field("Goods_Name")); + query.Columns.Add(DQSelectColumn.Field("Goods_Spec")); + query.Columns.Add(DQSelectColumn.Field("Weight")); + query.Columns.Add(DQSelectColumn.Field("InStoreTime")); + query.Range = SelectRange.Top(1); + using (var session = Dmo.NewSession()) + { + using (var reader = session.ExecuteReader(query)) + { + if (reader.Read()) + { + var obj = new + { + Goods_Name = (string)reader[0], + Goods_Spec = (string)reader[1], + Weight = (decimal)reader[2], + InStoreTime = (DateTime?)reader[3] + }; + return JsonConvert.SerializeObject(obj); + } + } + } + return JsonConvert.SerializeObject(new { }); + + } + + [Rpc(RpcFlags.SkipAuth)] + public static int InsertCombine(string json) + { + var list = JsonConvert.DeserializeObject>(json); + using (var session = Dmo.NewSession()) + { + foreach (var item in list) + { + if ((Exist(session, item.CombineCode))) + continue; + session.Insert(item); + UpdateProductInfo(session, item); + } + session.Commit(); + } + return 1; + } + + static bool Exist(IDmoSession session, string code) + { + var query = new DQueryDom(new JoinAlias(typeof(ProductInStoreCombine))); + query.Where.Conditions.Add(DQCondition.EQ("CombineCode", code)); + return query.EExists(session); + } + + static void UpdateProductInfo(IDmoSession session, ProductInStoreCombine item) + { + var update = new DQUpdateDom(typeof(SegmentProductionInfo)); + update.Columns.Add(new DQUpdateColumn("InStoreCombine_ID", item.ID)); + update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("BarCode"), item.BarCodes.Select(x => DQExpression.Value(x)).ToArray())); + session.ExecuteNonQuery(update); + } + } +} diff --git a/B3ClientService/Tasks/InStoreCombineCreateB3Bills.cs b/B3ClientService/Tasks/InStoreCombineCreateB3Bills.cs new file mode 100644 index 0000000..6c38f68 --- /dev/null +++ b/B3ClientService/Tasks/InStoreCombineCreateB3Bills.cs @@ -0,0 +1,123 @@ +using BWP.B3ClientService.BO; +using Forks.EnterpriseServices.BusinessInterfaces; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.SqlDoms; +using Forks.JsonRpc.Client; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using TSingSoft.WebPluginFramework.TimerTasks; + +namespace BWP.B3ClientService.Tasks +{ + public class InStoreCombineCreateB3Bills : ITimerTask + { + private static volatile object _lockObj = new object(); + public void Execute() + { + if (!Monitor.TryEnter(_lockObj)) + { + throw new SameTaskNotFinishException(this); + } + var serverUri = ServerHost.GetServerUrl(); + if (string.IsNullOrEmpty(serverUri)) + throw new Exception("请配置服务器地址"); + try + { + RpcFacade.Init(serverUri, "B3ClientServer"); + } + catch (Exception ex) + { + if (ex.Message != "Can only start once") + throw; + } + + try + { + DoExecute(); + } + catch (Exception e) + { + throw new ApplicationException(e.ToString()); + } + finally + { + Monitor.Exit(_lockObj); + } + } + + string method = "/MainSystem/B3ButcherManage/Rpcs/InStoreCombineRpc/CreateInOutStore"; + private void DoExecute() + { + using (var context = new TransactionContext()) + { + List ids; + var list = GetUnSyncdList(context.Session, out ids); + if (list.Count == 0) + return; + + RpcFacade.Call(method, JsonConvert.SerializeObject(list)); + SetAsSyncd(context.Session, ids); + context.Commit(); + } + } + + private void SetAsSyncd(IDmoSession session, List ids) + { + var update = new DQUpdateDom(typeof(ProductInStoreCombine)); + update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray())); + update.Columns.Add(new DQUpdateColumn("IsCreated", true)); + session.ExecuteNonQuery(update); + } + + private List GetUnSyncdList(IDmoSession session, out List ids) + { + var main = new JoinAlias(typeof(ProductInStoreCombine)); + var detail = new JoinAlias(typeof(SegmentProductionInfo)); + var query = new DQueryDom(main); + query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "InStoreCombine_ID")); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Columns.Add(DQSelectColumn.Field("CombineTime")); + query.Columns.Add(DQSelectColumn.Field("OutStore_Code")); + query.Columns.Add(DQSelectColumn.Field("InStore_Code")); + query.Columns.Add(DQSelectColumn.Field("Goods_Code", detail)); + foreach (var c in query.Columns) + query.GroupBy.Expressions.Add(c.Expression); + query.Columns.Add(DQSelectColumn.Sum("Weight")); + query.Columns.Add(DQSelectColumn.Count("C")); + query.Where.Conditions.Add(DQCondition.EQ("IsCreated", false)); + query.Range = SelectRange.Top(100); + var list = new List(); + ids = new List(); + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var id = (long)reader[0]; + ids.Add(id); + + list.Add(new + { + ID = id, + CombineTime = (DateTime)reader[1], + OutStore_Code = (string)reader[2], + InStore_Code = (string)reader[3], + Goods_Code = (string)reader[4], + Weight = (decimal)reader[5], + Count = Convert.ToInt32(reader[6]) + }); + } + } + return list; + } + + public string Name + { + get { return "成品入库创建产出入库单"; } + } + } +} diff --git a/WebFolder/config/NamedValue/B3ClientService.xml b/WebFolder/config/NamedValue/B3ClientService.xml index e2df829..77f0436 100644 --- a/WebFolder/config/NamedValue/B3ClientService.xml +++ b/WebFolder/config/NamedValue/B3ClientService.xml @@ -13,6 +13,7 @@ +