From 16905e5c83a486c9d8cc3d07235af21129a5e9ab Mon Sep 17 00:00:00 2001 From: wugang <425674808@qq.com> Date: Sat, 3 Nov 2018 15:16:41 +0800 Subject: [PATCH] =?UTF-8?q?=E9=94=80=E5=94=AE=E5=8F=91=E8=B4=A7=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E8=B0=83=E6=95=B4=E4=B8=BA=E5=8F=AF=E4=BB=A5?= =?UTF-8?q?=E6=8C=89=E7=AE=B1=E5=8F=91=E8=B4=A7=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../B3CowButcherManageToSale.csproj | 2 +- .../Properties/AssemblyInfo.cs | 2 + .../Rpcs/SaleOutStoreRpc.cs | 271 ++++++++++++++++++ 3 files changed, 274 insertions(+), 1 deletion(-) create mode 100644 B3CowButcherManageToSale/Rpcs/SaleOutStoreRpc.cs diff --git a/B3CowButcherManageToSale/B3CowButcherManageToSale.csproj b/B3CowButcherManageToSale/B3CowButcherManageToSale.csproj index 442d117..8a9810d 100644 --- a/B3CowButcherManageToSale/B3CowButcherManageToSale.csproj +++ b/B3CowButcherManageToSale/B3CowButcherManageToSale.csproj @@ -80,11 +80,11 @@ + - diff --git a/B3CowButcherManageToSale/Properties/AssemblyInfo.cs b/B3CowButcherManageToSale/Properties/AssemblyInfo.cs index 108ad45..3147127 100644 --- a/B3CowButcherManageToSale/Properties/AssemblyInfo.cs +++ b/B3CowButcherManageToSale/Properties/AssemblyInfo.cs @@ -2,6 +2,7 @@ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using Forks.EnterpriseServices.Ert; // 有关程序集的常规信息通过以下 // 特性集控制。更改这些特性值可修改 @@ -35,3 +36,4 @@ using System.Runtime.InteropServices; // [assembly: AssemblyVersion("1.0.*")] [assembly: AssemblyVersion("1.0.0.0")] [assembly: AssemblyMapToTablePrefix("B3CowButcherManageToSale_")] +[assembly: ErtAbbr("B3CowButcherManageToSale", "BWP.B3CowButcherManageToSale")] diff --git a/B3CowButcherManageToSale/Rpcs/SaleOutStoreRpc.cs b/B3CowButcherManageToSale/Rpcs/SaleOutStoreRpc.cs new file mode 100644 index 0000000..090afb6 --- /dev/null +++ b/B3CowButcherManageToSale/Rpcs/SaleOutStoreRpc.cs @@ -0,0 +1,271 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using BWP.B3CowButcherManage.BO; +using BWP.B3Frameworks.Utils; +using BWP.B3Sale.BO; +using Forks.EnterpriseServices.DomainObjects2; +using Forks.EnterpriseServices.DomainObjects2.DQuery; +using Forks.EnterpriseServices.JsonRpc; +using Forks.EnterpriseServices.SqlDoms; +using Forks.Utils; +using Newtonsoft.Json; +using TSingSoft.WebPluginFramework; + +namespace BWP.B3CowButcherManageToSale.Rpcs +{ + [Rpc] + public static class SaleOutStoreRpc + { + class WeightRecord + { + public long ID { get; set; } + public string BarCode { get; set; } + public DateTime WeightTime { get; set; } + public decimal? MainUnitNum { get; set; } + public decimal? SecondNumber { get; set; } + + public bool? IsPackage { get; set; } + + public bool? HasPWeight { get; set; } + + public string Product_Batch { get; set; } + + } + + static Tuple GetSaleOutInfo(IDmoSession session, long detailID) + { + var main = new JoinAlias(typeof(SaleOutStore)); + var detail = new JoinAlias(typeof(SaleOutStore_Detail)); + var query = new DQueryDom(main); + query.From.AddJoin(JoinType.Inner, new DQDmoSource(detail), DQCondition.EQ(main, "ID", detail, "SaleOutStore_ID")); + query.Columns.Add(DQSelectColumn.Field("ID", main)); + query.Columns.Add(DQSelectColumn.Field("Customer_ID", main)); + query.Columns.Add(DQSelectColumn.Field("SaleGoods_ID", detail)); + query.Columns.Add(DQSelectColumn.Field("Unit", detail)); + query.Where.Conditions.Add(DQCondition.EQ(detail, "ID", detailID)); + var result = query.EExecuteList(session); + if (result == null) + throw new Exception("销售出库单不存在"); + return result.FirstOrDefault(); + } + + private class ExtObj + { + public long? LongExt1 { get; set; } + + public List LongListExt1 { get; set; } + + public List LongListExt2 { get; set; } + + } + + [Rpc] + public static string SaveWeightRecord(string json, long detailID) + { + var weightRecord = JsonConvert.DeserializeObject(json); + var result = new List(); + Tuple?, Money?> assignInfo; + var longListExt1 = new List(); + var longListExt2 = new List(); + using (var session = Dmo.NewSession()) + { + var saleInfo = GetSaleOutInfo(session, detailID); + var billType = DmoTypeIDAttribute.GetID(typeof(SaleOutStore)); + if (weightRecord.IsPackage == true) + { + if (weightRecord.HasPWeight == true) + { + var record = CreateWeightingInfo(detailID, saleInfo, billType, weightRecord.MainUnitNum, weightRecord.SecondNumber, weightRecord.WeightTime, weightRecord.Product_Batch, weightRecord.ID); + session.Insert(record); + longListExt1.Add(record.ID); + var barCodes = GetBarCodeInfo(weightRecord.BarCode); + foreach (var code in barCodes) + { + var scan = CreateSanDetail(detailID, saleInfo, code.Weight, 1m, weightRecord.ID, record.ID, code.BarCode); + session.Insert(scan); + longListExt2.Add(scan.ID); + } + } + else + { + var barCodes = GetBarCodeInfo(weightRecord.BarCode); + foreach (var code in barCodes) + { + var wInfo = CreateWeightingInfo(detailID, saleInfo, billType, code.Weight, 1m, weightRecord.WeightTime, code.Product_Batch, weightRecord.ID); + session.Insert(wInfo); + longListExt1.Add(wInfo.ID); + var scan = CreateSanDetail(detailID, saleInfo, code.Weight, 1m, weightRecord.ID, wInfo.ID, code.BarCode); + session.Insert(scan); + longListExt2.Add(scan.ID); + } + } + } + else + { + var record = CreateWeightingInfo(detailID, saleInfo, billType, weightRecord.MainUnitNum, weightRecord.SecondNumber, weightRecord.WeightTime, weightRecord.Product_Batch, weightRecord.ID); + session.Insert(record); + longListExt1.Add(record.ID); + var scan = CreateSanDetail(detailID, saleInfo, weightRecord.MainUnitNum, weightRecord.SecondNumber.Value, weightRecord.ID, record.ID, weightRecord.BarCode); + session.Insert(scan); + longListExt2.Add(scan.ID); + } + result.Add(new ExtObj { LongExt1 = weightRecord.ID, LongListExt1 = longListExt1, LongListExt2 = longListExt2 }); + assignInfo = UpdateAssignNumber(session, saleInfo.Item1, detailID); + session.Commit(); + } + return JsonConvert.SerializeObject(new Tuple>(assignInfo.Item1.EToDecimal(), assignInfo.Item2.EToDecimal(), result)); + } + + + [Rpc] + public static int DeleteAndUpdate(long clientId, long detailId) + { + using (var session = Dmo.NewSession()) + { + var weightIDs = GetWeightingInforID(session, detailId, clientId); + if(weightIDs.Count > 0) + DeleteByID(session, weightIDs); + var scanIds = GetScanDetailID(session, detailId, clientId); + if (scanIds.Count > 0) + DeleteByID(session, scanIds); + var billID = InnerBLUtil.GetDmoPropertyByID(session, typeof(SaleOutStore_Detail), "SaleOutStore_ID", detailId); + UpdateAssignNumber(session, billID, detailId, false); + session.Commit(); + } + return 1; + } + + + + static List GetWeightingInforID(IDmoSession session, long detailID, long clientId) + { + var query = new DQueryDom(new JoinAlias(typeof(WeightingInfor))); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ClientID", clientId), DQCondition.EQ("DetailID", detailID), DQCondition.EQ("BillType", DmoTypeIDAttribute.GetID(typeof(SaleOutStore))))); + return query.EExecuteList(session); + } + + static List GetScanDetailID(IDmoSession session, long detailID, long clientId) + { + var query = new DQueryDom(new JoinAlias(typeof(WeightingInfo_ScanDetail))); + query.Columns.Add(DQSelectColumn.Field("ID")); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("ClientID", clientId), DQCondition.EQ("Detail_ID", detailID))); + return query.EExecuteList(session); + } + + static void DeleteByID(IDmoSession session, IEnumerable ids) + { + var delete = new DQDeleteDom(typeof(T)); + delete.Where.Conditions.Add(DQCondition.InList(DQExpression.Field("ID"), ids.Select(x => DQExpression.Value(x)).ToArray())); + session.ExecuteNonQuery(delete); + } + + private static Tuple?, Money?> UpdateAssignNumber(IDmoSession session, long billID, long detailID, bool isAdd = true) + { + var weightingInfo = GetWeightingInfor(session, detailID); + + var update = new DQUpdateDom(typeof(SaleOutStore_Detail)); + update.Columns.Add(new DQUpdateColumn("AssignUnitNum", DQExpression.Value(weightingInfo.Item1))); + update.Columns.Add(new DQUpdateColumn("AssignMainUnitNum", DQExpression.Value(weightingInfo.Item1))); + update.Columns.Add(new DQUpdateColumn("AssignSecondaryUnit1Num", DQExpression.Value(weightingInfo.Item2))); + if (isAdd) + update.Columns.Add(new DQUpdateColumn("PackageNum", DQExpression.Add(DQExpression.IfNull(DQExpression.Field("PackageNum"), DQExpression.Value(0)), DQExpression.Value(1)))); + else + update.Columns.Add(new DQUpdateColumn("PackageNum", DQExpression.Add(DQExpression.IfNull(DQExpression.Field("PackageNum"), DQExpression.Value(0)), DQExpression.Value(-1)))); + update.Where.Conditions.Add(DQCondition.EQ("ID", detailID)); + session.ExecuteNonQuery(update); + + var update2 = new DQUpdateDom(typeof(SaleOutStore)); + update2.Columns.Add(new DQUpdateColumn("RowVersion", DQExpression.Add(DQExpression.Field("RowVersion"), DQExpression.Value(1)))); + update2.Where.Conditions.Add(DQCondition.EQ("ID", billID)); + session.ExecuteNonQuery(update2); + + return weightingInfo; + } + + static Tuple?, Money?> GetWeightingInfor(IDmoSession session, long detailID) + { + var query = new DQueryDom(new JoinAlias(typeof(WeightingInfor))); + query.Columns.Add(DQSelectColumn.Sum("MainUnitNum")); + query.Columns.Add(DQSelectColumn.Sum("SecondNumber")); + query.Where.Conditions.Add(DQCondition.And(DQCondition.EQ("DetailID", detailID), DQCondition.EQ("BillType", DmoTypeIDAttribute.GetID(typeof(SaleOutStore))))); + return query.EExecuteScalar?, Money?>(session); + } + + private static WeightingInfo_ScanDetail CreateSanDetail(long detailID, Tuple saleInfo, decimal? mainUnitNum, decimal secondNumber, long? clientID, long? weightRecordID, string code) + { + var scan = new WeightingInfo_ScanDetail(); + scan.BarCode = code; + scan.BillID = saleInfo.Item1; + scan.Detail_ID = detailID; + scan.Goods_ID = saleInfo.Item3; + scan.Weight = mainUnitNum; + scan.Number = secondNumber; + scan.ClientID = clientID; + scan.WeightRecordID = weightRecordID; + return scan; + } + + private static WeightingInfor CreateWeightingInfo(long detailID, Tuple saleInfo, short billType, decimal? mainUnitNum, decimal? secondNumber, DateTime? weightTime, string product_Batch, long clientID) + { + var record = new WeightingInfor(); + record.BillID = saleInfo.Item1; + record.BillType = billType; + record.Customer_ID = saleInfo.Item2; + record.DetailID = detailID; + record.Goods_ID = saleInfo.Item3; + record.MainUnitNum = mainUnitNum; + record.SecondNumber = secondNumber; + record.NetWeight = mainUnitNum; + record.Weight = mainUnitNum; + record.WeightTime = weightTime; + record.Unit = saleInfo.Item4; + record.Type = "客户端"; + record.Product_Batch = product_Batch; + record.ClientID = clientID; + return record; + } + + static List GetBarCodeInfo(string barCode) + { + var left = new JoinAlias("_l", typeof(BarCodeProductionInfo)); + var right = new JoinAlias("_r", typeof(BarCodeProductionInfo)); + var query = new DQueryDom(left); + query.From.AddJoin(JoinType.Inner, new DQDmoSource(right), DQCondition.EQ(left, "ID", right, "PackageID")); + query.Where.Conditions.Add(DQCondition.EQ(left, "BarCode", barCode)); + var arr = new string[] { "Product_Batch", "BarCode", "Goods_ID", "Weight" }; + var list = new List(); + foreach (var f in arr) + query.Columns.Add(DQSelectColumn.Create(DQExpression.Field(right, f), f)); + using (var session = Dmo.NewSession()) + { + using (var reader = session.ExecuteReader(query)) + { + while (reader.Read()) + { + var obj = new MinBarCode() + { + Product_Batch = Convert.ToString(reader[0]), + BarCode = Convert.ToString(reader[1]), + Goods_ID = (long?)reader[2], + Weight = (decimal?)reader[3] + }; + list.Add(obj); + } + } + } + return list; + } + + class MinBarCode + { + public string Product_Batch { get; set; } + public string BarCode { get; set; } + public long? Goods_ID { get; set; } + public decimal? Weight { get; set; } + } +} + } +