diff --git a/B3CowButcherManageToSale/B3CowButcherManageToSale.csproj b/B3CowButcherManageToSale/B3CowButcherManageToSale.csproj index a894c0b..3036cef 100644 --- a/B3CowButcherManageToSale/B3CowButcherManageToSale.csproj +++ b/B3CowButcherManageToSale/B3CowButcherManageToSale.csproj @@ -54,6 +54,10 @@ False ..\..\..\..\..\..\..\BwpB3Project\tsref\Debug\Forks.Utils.dll + + False + ..\..\..\tsref\Debug\Newtonsoft.Json.dll + @@ -76,6 +80,7 @@ + diff --git a/B3CowButcherManageToSale/TypeIOCs/SaleOutStoreBLTypeIoc.cs b/B3CowButcherManageToSale/TypeIOCs/SaleOutStoreBLTypeIoc.cs new file mode 100644 index 0000000..aa5c40a --- /dev/null +++ b/B3CowButcherManageToSale/TypeIOCs/SaleOutStoreBLTypeIoc.cs @@ -0,0 +1,111 @@ +using BWP.B3CowButcherManage.Rpcs; +using BWP.B3Frameworks; +using BWP.B3Sale.BL; +using BWP.B3Sale.BO; +using Forks.EnterpriseServices.BusinessInterfaces; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.SqlDoms; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using TSingSoft.WebPluginFramework; +using TSingSoft.WebPluginFramework.QueueTasks; + +namespace BWP.B3CowButcherManageToSale.TypeIOCs +{ + [TypeIOC(typeof(SaleOutStoreBL), typeof(SaleOutStoreBL.BillBLIOCs.AfterCheck))] + public class SaleOutStoreCheckBLTypeIoc : SaleOutStoreBL.BillBLIOCs.AfterCheck + { + public void Invoke(IDmoContext context, SaleOutStore dmo) + { + var task = new SaleInfoToButcherTask(dmo.ID); + task.AddTaskUser_ID = BLContext.User.ID; + task.DomainUser_ID = DomainContext.Current.DomainUser.ID; + QueueTaskService.Add(task); + } + } + + [Serializable] + class SaleInfoToButcherTask : QueueTaskBase + { + public long BillID { get; set; } + public long DomainUser_ID { get; set; } + + public SaleInfoToButcherTask(long id) + { + BillID = id; + } + + public override bool PersistTask + { + get + { + return true; + } + } + + protected override bool SingleTaskInQueue + { + get + { + return true; + } + } + + public override void Execute(QueueTaskContext context) + { + using (var scope = new SpecialDomainUserBLScope(DomainUser_ID)) + { + using (var session = Dmo.NewSession()) + { + var infos = GetBarCodeInfos(session, BillID); + if(infos.Count==0) + return; + var json = JsonConvert.SerializeObject(infos); + BarCodeProductRpc.UploadSaleOutInfo(json); + } + } + } + + List GetBarCodeInfos(IDmoSession session, long id) + { + var detail = new JoinAlias(typeof(SaleOutStore_Detail)); + var bill = new JoinAlias(typeof(SaleOutStore)); + var scan = new JoinAlias(typeof(WeightingInfo_ScanDetail)); + var query = new DQueryDom(detail); + query.From.AddJoin(JoinType.Left, new DQDmoSource(bill), DQCondition.EQ(detail, "SaleOutStore_ID", bill, "ID")); + query.From.AddJoin(JoinType.Left, new DQDmoSource(scan), DQCondition.EQ(detail, "ID", scan, "Detail_ID")); + query.Columns.Add(DQSelectColumn.Field("LoadTime", bill)); + query.Columns.Add(DQSelectColumn.Field("Weight", scan)); + query.Columns.Add(DQSelectColumn.Field("Detail_ID", scan)); + query.Columns.Add(DQSelectColumn.Field("BarCode", scan)); + + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ(detail, "SaleOutStore_ID", id), DQCondition.IsNotNull(DQExpression.Field(scan, "ID")))); + query.Where.Conditions.Add(DQCondition.InEQ(scan, "BarCode", "")); + var list = new List(); + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var entity = new + { + SaleTime = (DateTime)reader[0], + SaleWeight = (decimal)reader[1], + SaleDetailID = (long)reader[2], + BarCode = (string)reader[3] + }; + list.Add(entity); + } + } + return list; + } + + public override string Name + { + get { return string.Format("销售出库单No.{0}扫码信息到屠宰系统", BillID); } + } + } +}