From 378ed89b9b57f6bdbaf8ea7a6cfc2113624ccc02 Mon Sep 17 00:00:00 2001 From: yibo <361071264@qq.com> Date: Tue, 10 Apr 2018 19:31:55 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=80=E5=94=AE=E5=87=BA=E5=BA=93=E5=85=B3?= =?UTF-8?q?=E8=81=94=E6=89=AB=E7=A0=81=E9=94=80=E5=94=AE=E7=9A=84=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- B3QingDaoWanFu.Web/PluginClass.cs | 1 + B3QingDaoWanFu/B3QingDaoWanFu.csproj | 10 ++ .../BO/SaleOutStoreBarCodeToMESLog.cs | 17 +++ .../Tasks/SyncSaleOutStoreInfoToMES.cs | 121 ++++++++++++++++++ .../TypeIOCs/SaleOutStoreBLTypeIoc.cs | 57 ++++++--- 5 files changed, 191 insertions(+), 15 deletions(-) create mode 100644 B3QingDaoWanFu/BO/SaleOutStoreBarCodeToMESLog.cs create mode 100644 B3QingDaoWanFu/Tasks/SyncSaleOutStoreInfoToMES.cs diff --git a/B3QingDaoWanFu.Web/PluginClass.cs b/B3QingDaoWanFu.Web/PluginClass.cs index d63beba..0ff7a9d 100644 --- a/B3QingDaoWanFu.Web/PluginClass.cs +++ b/B3QingDaoWanFu.Web/PluginClass.cs @@ -25,6 +25,7 @@ namespace BWP.B3QingDaoWanFu GlobalFlags.On(B3SaleConsts.Flags.SendOutStoreNoAvailableStorage); GlobalFlags.On(B3SaleConsts.Flags.CustAcceptAnalyseHasFactoryPrice); GlobalFlags.On(B3ButcherManageConsts.GlobalFlags.预付款单不关联过磅单); + GlobalFlags.On(B3SaleConsts.Flags.SaleOutStoreEnableScan); } } } diff --git a/B3QingDaoWanFu/B3QingDaoWanFu.csproj b/B3QingDaoWanFu/B3QingDaoWanFu.csproj index 7fe71e2..bc49aa5 100644 --- a/B3QingDaoWanFu/B3QingDaoWanFu.csproj +++ b/B3QingDaoWanFu/B3QingDaoWanFu.csproj @@ -86,11 +86,19 @@ D:\BwpB3Project\tsref\Debug\Forks.EnterpriseServices.dll False + + False + ..\..\..\tsref\Debug\Forks.JsonRpc.Client.dll + False D:\BwpB3Project\tsref\Debug\Forks.Utils.dll False + + False + ..\..\..\tsref\Debug\Newtonsoft.Json.dll + False @@ -141,9 +149,11 @@ + + diff --git a/B3QingDaoWanFu/BO/SaleOutStoreBarCodeToMESLog.cs b/B3QingDaoWanFu/BO/SaleOutStoreBarCodeToMESLog.cs new file mode 100644 index 0000000..bcf71e2 --- /dev/null +++ b/B3QingDaoWanFu/BO/SaleOutStoreBarCodeToMESLog.cs @@ -0,0 +1,17 @@ +using Forks.EnterpriseServices.DomainObjects2; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TSingSoft.WebPluginFramework; + +namespace BWP.B3QingDaoWanFu.BO +{ + + [BOClass] + [KeyField("ScanBar_ID", KeyGenType.assigned)] + public class SaleOutStoreBarCodeToMESLog + { + public long ScanBar_ID { get; set; } + } +} diff --git a/B3QingDaoWanFu/Tasks/SyncSaleOutStoreInfoToMES.cs b/B3QingDaoWanFu/Tasks/SyncSaleOutStoreInfoToMES.cs new file mode 100644 index 0000000..d991e8a --- /dev/null +++ b/B3QingDaoWanFu/Tasks/SyncSaleOutStoreInfoToMES.cs @@ -0,0 +1,121 @@ +using BWP.B3ProcurementInterface.Utils; +using BWP.B3QingDaoWanFu.BO; +using BWP.B3Sale.BO; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.SqlDoms; +using Forks.Utils; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading; +using TSingSoft.WebPluginFramework.TimerTasks; +using TSingSoft.WebPluginFramework; +using Forks.JsonRpc.Client; +using Newtonsoft.Json; +using BWP.B3Frameworks.BO.NamedValueTemplate; + +namespace BWP.B3QingDaoWanFu.Tasks +{ + public class SyncSaleOutStoreInfoToMES : ITimerTask + { + volatile static object _lockObj = new object(); + public void Execute() + { + if (!Monitor.TryEnter(_lockObj)) + { + throw new SameTaskNotFinishException(this); + } + try + { + DoExecute(); + } + finally + { + Monitor.Exit(_lockObj); + } + } + + private void DoExecute() + { + if (!ClientServerFacedRpcFacadeUtil.InitRpcFacade()) + return; + var main = new JoinAlias(typeof(SaleOutStore)); + var detail = new JoinAlias(typeof(SaleOutStore_Detail)); + var weight = new JoinAlias(typeof(WeightingInfor)); + var scan = new JoinAlias(typeof(WeightingInfo_ScanDetail)); + var relate = new JoinAlias(typeof(SaleOutStoreBarCodeToMESLog)); + var query = new DQueryDom(main); + query.From.AddJoin(JoinType.Left, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "SaleOutStore_ID")); + query.From.AddJoin(JoinType.Left, new DQDmoSource(weight), DQCondition.And(DQCondition.EQ(detail, "ID", weight, "DetailID"), DQCondition.EQ("BillType", DmoTypeIDAttribute.GetID(typeof(SaleOutStore))))); + query.From.AddJoin(JoinType.Left, new DQDmoSource(scan), DQCondition.And(DQCondition.EQ(detail, "ID", scan, "Detail_ID"), DQCondition.EQ(weight, "ID", scan, "WeightingInfo_ID"))); + query.From.AddJoin(JoinType.Left, new DQDmoSource(relate), DQCondition.EQ(scan, "ID", relate, "ScanBar_ID")); + + query.Columns.Add(DQSelectColumn.Field("ID", scan)); + query.Columns.Add(DQSelectColumn.Field("BarCode", scan)); + query.Columns.Add(DQSelectColumn.Field("NetWeight", weight)); + query.Columns.Add(DQSelectColumn.Field("LoadTime", main)); + query.Columns.Add(DQSelectColumn.Field("ID", weight)); + query.Columns.Add(DQSelectColumn.Field("Goods_Code", detail)); + + + query.Where.Conditions.Add(DQCondition.And(DQCondition.GreaterThanOrEqual("BillState", 单据状态.已审核), DQCondition.IsNull(DQExpression.Field(relate, "ScanBar_ID")), DQCondition.IsNotNull(DQExpression.Field(scan, "ID")))); + + using (var session = Dmo.NewSession()) + { + var list = new List(); + var ids = new List(); + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var entity = new CarcassSaleOutStoreObj(); + entity.BarCode = (string)reader[1]; + entity.Weight = ((Money?)reader[2]).EToDecimal(); + entity.Time = (DateTime?)reader[3]; + entity.GroupID = (long)reader[4]; + entity.SaleGoods_Code = (string)reader[5]; + list.Add(entity); + ids.Add((long)reader[0]); + } + } + if (list.Count == 0) + return; + + foreach (var g in list.GroupBy(x => x.GroupID)) + { + var first = true; + foreach (var item in g) + { + if (first) + first = false; + else + item.Weight = 0; + } + } + var par = JsonConvert.SerializeObject(list); + + var json = RpcFacade.Call("/MainSystem/B3ClientService/Rpcs/CarcassSaleOutStoreRpc/UploadCarcassInfo", par); + foreach (var item in ids) + session.Insert(new SaleOutStoreBarCodeToMESLog { ScanBar_ID = item }); + + session.Commit(); + } + } + + public string Name + { + get { return "上传审核的销售出库扫码信息到MES"; } + } + } + + 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; } + } +} diff --git a/B3QingDaoWanFu/TypeIOCs/SaleOutStoreBLTypeIoc.cs b/B3QingDaoWanFu/TypeIOCs/SaleOutStoreBLTypeIoc.cs index b902bcc..e8ac7dd 100644 --- a/B3QingDaoWanFu/TypeIOCs/SaleOutStoreBLTypeIoc.cs +++ b/B3QingDaoWanFu/TypeIOCs/SaleOutStoreBLTypeIoc.cs @@ -12,13 +12,12 @@ using Forks.EnterpriseServices.DomainObjects2.DQuery; using Forks.EnterpriseServices.SqlDoms; using Forks.Utils; using TSingSoft.WebPluginFramework; +using BWP.B3ButcherManage.BO; namespace BWP.B3QingDaoWanFu.TypeIOCs { - - [TypeIOC(typeof(SaleOutStoreBL), typeof(SaleOutStoreBL.BaseBLIOCs.BeforeSave))] - public class SaleOutStoreBLTypeIoc:SaleOutStoreBL.BaseBLIOCs.BeforeSave + public class SaleOutStoreBLTypeIoc : SaleOutStoreBL.BaseBLIOCs.BeforeSave { public void Invoke(IDmoContext context, SaleOutStore dmo) { @@ -30,29 +29,57 @@ namespace BWP.B3QingDaoWanFu.TypeIOCs private Money? GetFactoryPrice(IDmoContext context, SaleOutStore dmo, long detailSaleGoodsId) { - var detail=new JoinAlias(typeof(DynamicPrice_Detail)); - var query=new DQueryDom(detail); + var detail = new JoinAlias(typeof(DynamicPrice_Detail)); + var query = new DQueryDom(detail); query.Where.Conditions.Add(DQCondition.EQ("SaleGoods_ID", detailSaleGoodsId)); - query.Where.Conditions.Add(DQCondition.InSubQuery(DQExpression.Field("DynamicPrice_ID"),GetSubQueryDom(dmo))); + query.Where.Conditions.Add(DQCondition.InSubQuery(DQExpression.Field("DynamicPrice_ID"), GetSubQueryDom(dmo))); query.Columns.Add(DQSelectColumn.Field("Price")); return query.EExecuteScalar?>(context.Session); } - private DQueryDom GetSubQueryDom( SaleOutStore dmo) + private DQueryDom GetSubQueryDom(SaleOutStore dmo) { - var bill=new JoinAlias("bill",typeof(DynamicPrice)); - var detail=new JoinAlias("detail",typeof(DynamicPrice_AccountingUnitDetail)); - var query=new DQueryDom(bill); - query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail),DQCondition.EQ(bill,"ID",detail, "DynamicPrice_ID") ); + var bill = new JoinAlias("bill", typeof(DynamicPrice)); + var detail = new JoinAlias("detail", typeof(DynamicPrice_AccountingUnitDetail)); + var query = new DQueryDom(bill); + query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(bill, "ID", detail, "DynamicPrice_ID")); query.AddBillStateCondition(bill); - query.Where.Conditions.Add(DQCondition.EQ(detail, "AccountingUnit_ID",dmo.AccountingUnit_ID)); + query.Where.Conditions.Add(DQCondition.EQ(detail, "AccountingUnit_ID", dmo.AccountingUnit_ID)); query.Where.Conditions.Add(DQCondition.LessThanOrEqual(bill, "StartPriceDate", dmo.LoadTime)); - query.OrderBy.Expressions.Add(DQOrderByExpression.Create(bill,"ID",true)); - query.Columns.Add(DQSelectColumn.Field("ID",bill)); - query.Range=SelectRange.Top(1); + query.OrderBy.Expressions.Add(DQOrderByExpression.Create(bill, "ID", true)); + query.Columns.Add(DQSelectColumn.Field("ID", bill)); + query.Range = SelectRange.Top(1); return query; } } + + [TypeIOC(typeof(SaleOutStoreBL), typeof(SaleOutStoreBL.BillBLIOCs.AfterCheck))] + public class SaleOutStoreCheckBLTypeIoc : SaleOutStoreBL.BillBLIOCs.AfterCheck + { + public void Invoke(IDmoContext context, SaleOutStore dmo) + { + var config = new B3ButcherManageOnlineConfiguration(); + if (string.IsNullOrEmpty(config.TraceBackServerUrl)) + return; + var detail = new JoinAlias(typeof(SaleOutStore_Detail)); + var weight = new JoinAlias(typeof(WeightingInfor)); + var scan = new JoinAlias(typeof(WeightingInfo_ScanDetail)); + var query = new DQueryDom(detail); + query.From.AddJoin(JoinType.Left, new DQDmoSource(weight), DQCondition.And(DQCondition.EQ(detail, "ID", weight, "DetailID"), DQCondition.EQ("BillType", DmoTypeIDAttribute.GetID(typeof(SaleOutStore))))); + query.From.AddJoin(JoinType.Left, new DQDmoSource(scan), DQCondition.And(DQCondition.EQ(detail, "ID", scan, "Detail_ID"), DQCondition.EQ(weight, "ID", scan, "WeightingInfo_ID"))); + + query.Columns.Add(DQSelectColumn.Field("BarCode", scan)); + + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ(detail, "SaleOutStore_ID", dmo.ID), DQCondition.IsNotNull(DQExpression.Field(scan, "ID")))); + + var list = query.EExecuteList(context.Session); + if (!list.Any()) + return; + + var letList = list.Select(x => new TraceBackInfo { Code = x, SendCustomer = dmo.Customer_Name, CarNo = dmo.Car_Name, SendDate = dmo.LoadTime.Value.ToString("yyyyMMdd") }); + TraceBackInfoUtil.Insert(config.TraceBackServerUrl, letList.ToList()); + } + } }