diff --git a/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchEdit.cs b/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchEdit.cs index eb2edeb..c6967a8 100644 --- a/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchEdit.cs +++ b/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchEdit.cs @@ -16,6 +16,7 @@ namespace BWP.Web.Pages.B3ClientService.BaseInfos.ProductBatch_ var config = new AutoLayoutConfig() { Cols = 8 }; config.Add("Name"); config.Add("Date"); + config.Add("BatchType"); config.Add("Remark"); layoutManager.Config = config; parent.Controls.Add(layoutManager.CreateLayout()); diff --git a/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchList.cs b/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchList.cs index a3cc214..4432cf1 100644 --- a/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchList.cs +++ b/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchList.cs @@ -15,6 +15,7 @@ namespace BWP.Web.Pages.B3ClientService.BaseInfos.ProductBatch_ vPanel.Add(CreateDefaultBaseInfoQueryControls((panel, config) => { config.AddAfter("Date", "Name"); + config.AddAfter("BatchType", "Date"); })); } @@ -22,7 +23,10 @@ namespace BWP.Web.Pages.B3ClientService.BaseInfos.ProductBatch_ { base.AddDFBrowseGridColumn(grid, field); if (field == "Name") + { AddDFBrowseGridColumn(grid, "Date"); + AddDFBrowseGridColumn(grid, "BatchType"); + } } } } diff --git a/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchList.xml b/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchList.xml index cf6e01a..06ef057 100644 --- a/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchList.xml +++ b/B3ClientService.Web/Pages/B3ClientService/BaseInfos/ProductBatch_/ProductBatchList.xml @@ -25,6 +25,10 @@ + + + + diff --git a/B3ClientService/B3ClientService.csproj b/B3ClientService/B3ClientService.csproj index 221af3d..cd3a090 100644 --- a/B3ClientService/B3ClientService.csproj +++ b/B3ClientService/B3ClientService.csproj @@ -258,6 +258,7 @@ + diff --git a/B3ClientService/B3ClientServiceOnLineConfig.cs b/B3ClientService/B3ClientServiceOnLineConfig.cs index e2281d5..20643ce 100644 --- a/B3ClientService/B3ClientServiceOnLineConfig.cs +++ b/B3ClientService/B3ClientServiceOnLineConfig.cs @@ -31,7 +31,7 @@ namespace BWP.B3ClientService [LogicName("自动生成批次模板")] [ConfigurationItemGroup("MES系统")] - [ConfigurationItemDescription("自动生成批次 日期追加部分用英文半角逗号分开")] + [ConfigurationItemDescription("自动生成批次 日期追加部分用英文半角逗号分开,内部再用|把类型和附加部分加上。例如0|A,0|B,1|")] public StringConfigRef ProductBatchRole { get { return _productBatchRole; } diff --git a/B3ClientService/BO/BaseInfo/ProductBatch.cs b/B3ClientService/BO/BaseInfo/ProductBatch.cs index 256a1f9..03ffb62 100644 --- a/B3ClientService/BO/BaseInfo/ProductBatch.cs +++ b/B3ClientService/BO/BaseInfo/ProductBatch.cs @@ -6,6 +6,8 @@ using Forks.EnterpriseServices.DomainObjects2; using TSingSoft.WebPluginFramework; using Forks.EnterpriseServices.DataForm; using Forks.EnterpriseServices; +using BWP.B3ClientService.NamedValueTemplate; +using Forks.Utils; namespace BWP.B3ClientService.BO { @@ -16,5 +18,11 @@ namespace BWP.B3ClientService.BO { [LogicName("日期")] public DateTime? Date { get; set; } + + private NamedValue<批次类型> mBatchType = 批次类型.屠宰; + + [LogicName("批次类型")] + [DbColumn(DefaultValue = 0)] + public NamedValue<批次类型> BatchType { get { return mBatchType; } set { mBatchType = value; } } } } diff --git a/B3ClientService/BO/Bill/SegmentProductionInfo.cs b/B3ClientService/BO/Bill/SegmentProductionInfo.cs index 820528a..f597489 100644 --- a/B3ClientService/BO/Bill/SegmentProductionInfo.cs +++ b/B3ClientService/BO/Bill/SegmentProductionInfo.cs @@ -104,8 +104,23 @@ namespace BWP.B3ClientService.BO public long? DetailID { get; set; } + [DbColumn(DefaultValue = false)] + public bool CreateOutput { get; set; } + [ReferenceTo(typeof(Goods), "Name")] [Join("Goods_ID", "ID")] public string Goods_Name { get; set; } + + [ReferenceTo(typeof(Goods), "Code")] + [Join("Goods_ID", "ID")] + public string Goods_Code { get; set; } + + [ReferenceTo(typeof(Worker), "Name")] + [Join("Worker_ID", "ID")] + public string Worker_Name { get; set; } + + [ReferenceTo(typeof(ProductBatch), "Name")] + [Join("ProductBatch_ID", "ID")] + public string ProductBatch_Name { get; set; } } } diff --git a/B3ClientService/NamedValueTemplate.cs b/B3ClientService/NamedValueTemplate.cs index 2742a41..9d788b4 100644 --- a/B3ClientService/NamedValueTemplate.cs +++ b/B3ClientService/NamedValueTemplate.cs @@ -44,4 +44,10 @@ namespace BWP.B3ClientService.NamedValueTemplate public static readonly NamedValue<领用类型> 白条销售 = new NamedValue<领用类型>(1); public static readonly NamedValue<领用类型> 条转段 = new NamedValue<领用类型>(2); } + + public sealed class 批次类型 + { + public static readonly NamedValue<批次类型> 屠宰 = new NamedValue<批次类型>(0); + public static readonly NamedValue<批次类型> 分割 = new NamedValue<批次类型>(1); + } } diff --git a/B3ClientService/OfflinRpc/BaseInfoRpc.cs b/B3ClientService/OfflinRpc/BaseInfoRpc.cs index ed1560a..e863289 100644 --- a/B3ClientService/OfflinRpc/BaseInfoRpc.cs +++ b/B3ClientService/OfflinRpc/BaseInfoRpc.cs @@ -23,12 +23,18 @@ namespace BWP.B3ClientService.Rpcs [Rpc(RpcFlags.SkipAuth)] public static string SyncProductBatch() + { + return SyncProductBatchByType(0); + } + + [Rpc(RpcFlags.SkipAuth)] + public static string SyncProductBatchByType(int type) { var query = new DQueryDom(new JoinAlias(typeof(ProductBatch))); query.Columns.Add(DQSelectColumn.Field("ID")); query.Columns.Add(DQSelectColumn.Field("Name")); query.Columns.Add(DQSelectColumn.Field("Date")); - query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("IsLocked", false), DQCondition.EQ("Stopped", false))); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BatchType", type), DQCondition.EQ("IsLocked", false), DQCondition.EQ("Stopped", false))); var list = query.EExecuteList().Select(x => new MinProductBatch { ID = x.Item1, Name = x.Item2, Date = x.Item3 }); return JsonConvert.SerializeObject(list); } @@ -119,18 +125,25 @@ namespace BWP.B3ClientService.Rpcs [Rpc(RpcFlags.SkipAuth)] public static string GetProductBatch(int range) + { + return GetProductBatchByType(range, 0); + } + + [Rpc(RpcFlags.SkipAuth)] + public static string GetProductBatchByType(int range, int type) { var query = new DQueryDom(new JoinAlias(typeof(ProductBatch))); query.Columns.Add(DQSelectColumn.Field("ID")); query.Columns.Add(DQSelectColumn.Field("Name")); query.Columns.Add(DQSelectColumn.Field("Date")); - query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("IsLocked", false), DQCondition.EQ("Stopped", false))); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("BatchType", type), DQCondition.EQ("IsLocked", false), DQCondition.EQ("Stopped", false))); query.OrderBy.Expressions.Add(DQOrderByExpression.Create("ID", true)); query.Range = SelectRange.Top(range); var list = query.EExecuteList().Select(x => new MinProductBatch { ID = x.Item1, Name = x.Item2, Date = x.Item3 }); return JsonConvert.SerializeObject(list); } + [Rpc(RpcFlags.SkipAuth)] public static string SyncStore() { diff --git a/B3ClientService/Tasks/AutoCreateProductBatchTask.cs b/B3ClientService/Tasks/AutoCreateProductBatchTask.cs index dab949c..4cbedcb 100644 --- a/B3ClientService/Tasks/AutoCreateProductBatchTask.cs +++ b/B3ClientService/Tasks/AutoCreateProductBatchTask.cs @@ -25,11 +25,21 @@ namespace BWP.B3ClientService.Tasks var bl = BIFactory.Create(session); foreach (var item in arr) { - var name = DateTime.Today.ToString("yyyyMMdd") + item; + var append = item; + short type = 0; + var inner = item.Split(new char[] { '|' }); + if (inner.Length == 2) + { + type = short.Parse(inner[0]); + append = inner[1]; + } + + var name = DateTime.Today.ToString("yyyyMMdd") + append; if (Exist(session, name)) continue; var entity = new ProductBatch(); bl.InitNewDmo(entity); + entity.BatchType = type; entity.Name = name; entity.Date = DateTime.Today; bl.Insert(entity); diff --git a/B3ClientService/Tasks/CreateB3OutputTask.cs b/B3ClientService/Tasks/CreateB3OutputTask.cs new file mode 100644 index 0000000..ddd3ba2 --- /dev/null +++ b/B3ClientService/Tasks/CreateB3OutputTask.cs @@ -0,0 +1,132 @@ +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 CreateB3OutputTask : 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/OutputRpc/CreateOutput"; + private void DoExecute() + { + using (var context = new TransactionContext()) + { + var list = GetUnSyncdList(context.Session); + if (list.Count == 0) + return; + TransferToB3(list); + SetAsSyncd(context.Session, list.Select(x => x.ID)); + context.Commit(); + } + } + + void TransferToB3(List list) + { + var arr = list.GroupBy(x => new { x.Date, x.UserName, x.ProductBatch, x.Goods_Code }).Select(x => new + { + Date = x.Key.Date, + UserName = x.Key.UserName, + ProductBatch = x.Key.ProductBatch, + Goods_Code = x.Key.Goods_Code, + Weight = x.Sum(y => y.Weight), + Number = x.Count() + }); + RpcFacade.Call(method, JsonConvert.SerializeObject(arr)); + } + + private void SetAsSyncd(IDmoSession session, IEnumerable ids) + { + var update = new DQUpdateDom(typeof(SegmentProductionInfo)); + update.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray())); + update.Columns.Add(new DQUpdateColumn("CreateOutput", true)); + session.ExecuteNonQuery(update); + } + + private List GetUnSyncdList(IDmoSession session) + { + var query = new DQueryDom(new JoinAlias(typeof(SegmentProductionInfo))); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Columns.Add(DQSelectColumn.Field("ProductTime")); + query.Columns.Add(DQSelectColumn.Field("Goods_Code")); + query.Columns.Add(DQSelectColumn.Field("Worker_Name")); + query.Columns.Add(DQSelectColumn.Field("ProductBatch_Name")); + query.Columns.Add(DQSelectColumn.Field("Weight")); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("CreateOutput", false), DQCondition.IsNotNull(DQExpression.Field("Worker_ID")), DQCondition.IsNotNull(DQExpression.Field("ProductTime")))); + query.Range = SelectRange.Top(100); + var list = new List(); + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var entity = new Temp(); + entity.ID = (long)reader[0]; + entity.Date = ((DateTime)reader[1]).Date; + entity.Goods_Code = (string)reader[2]; + entity.UserName = (string)reader[3]; + entity.ProductBatch = (string)reader[4]; + entity.Weight = (decimal)reader[5]; + list.Add(entity); + } + } + return list; + } + } + + class Temp + { + public long ID { get; set; } + public DateTime Date { get; set; } + + public string Goods_Code { get; set; } + + public string UserName { get; set; } + + public string ProductBatch { get; set; } + + public decimal Weight { get; set; } + } +} diff --git a/WebFolder/config/NamedValue/B3ClientService.xml b/WebFolder/config/NamedValue/B3ClientService.xml index 08e10d3..44682e0 100644 --- a/WebFolder/config/NamedValue/B3ClientService.xml +++ b/WebFolder/config/NamedValue/B3ClientService.xml @@ -29,4 +29,8 @@ + + + + \ No newline at end of file