diff --git a/B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/TrustPay_/TrustPayEdit.cs b/B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/TrustPay_/TrustPayEdit.cs index 3d8b7e0..6d21893 100644 --- a/B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/TrustPay_/TrustPayEdit.cs +++ b/B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/TrustPay_/TrustPayEdit.cs @@ -1,6 +1,7 @@ using System; using System.Web.UI; using System.Web.UI.WebControls; +using BWP.B3Frameworks.Utils; using BWP.B3QingDaoWanFu.BL; using BWP.B3QingDaoWanFu.BO; using BWP.B3QingDaoWanFu.BO.NamedValueTemplate; @@ -9,8 +10,10 @@ using BWP.BWPTrustPayClient.TrustPayRequests; using BWP.Web.CustomPageLayout; using BWP.Web.Layout; using BWP.Web.WebControls; +using Forks.EnterpriseServices.BusinessInterfaces; using TSingSoft.WebControls2; using TSingSoft.WebPluginFramework.QueueTasks; +using Forks.EnterpriseServices.DomainObjects2; namespace BWP.Web.Pages.B3QingDaoWanFu.TrustPay_ { class TrustPayEdit : BaseDmoEditPage { @@ -120,8 +123,15 @@ namespace BWP.Web.Pages.B3QingDaoWanFu.TrustPay_ { } if (MinDmo.PayState == 付款状态.付款成功) { vPanel.Add(new TSButton("创建收款单", delegate { - long gatheringID; - mBL.CreateGathering(Dmo, out gatheringID); + long gatheringID; + using (var session = Forks.EnterpriseServices.DomainObjects2.Dmo.NewSession()) { + var bl = BIFactory.Create(session); + + bl.CreateGathering(Dmo, out gatheringID); + Dmo.Gathering_ID = gatheringID; + InnerBLUtil.UpdateEntityProperties(session, Dmo, "Gathering_ID"); + session.Commit(); + } if (gatheringID > 0) AspUtil.RedirectAndAlert(this, Request.RawUrl, "成功创建收款单No." + gatheringID); diff --git a/B3QingDaoWanFu/Tasks/CreatGatheringTask.cs b/B3QingDaoWanFu/Tasks/CreatGatheringTask.cs index ab0195c..50ab535 100644 --- a/B3QingDaoWanFu/Tasks/CreatGatheringTask.cs +++ b/B3QingDaoWanFu/Tasks/CreatGatheringTask.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using BWP.B3Frameworks; using BWP.B3Frameworks.Utils; using BWP.B3QingDaoWanFu.BL; @@ -44,7 +45,20 @@ namespace BWP.B3QingDaoWanFu.Tasks { _trustPayID = id; } + volatile static object _lockObj = new object(); + public void Execute() { + if (!Monitor.TryEnter(_lockObj)) { + throw new SameTaskNotFinishException(this); + } + try { + DoExecute(); + } finally { + Monitor.Exit(_lockObj); + } + } + + void DoExecute() { using (var session = Dmo.NewSession()) { var config = new WanFuOnlineConfig(); diff --git a/B3QingDaoWanFu/Tasks/RecheckTrustPayTask.cs b/B3QingDaoWanFu/Tasks/RecheckTrustPayTask.cs index 7fee310..ee0f797 100644 --- a/B3QingDaoWanFu/Tasks/RecheckTrustPayTask.cs +++ b/B3QingDaoWanFu/Tasks/RecheckTrustPayTask.cs @@ -1,4 +1,5 @@ using System; +using System.Threading; using BWP.B3Frameworks; using BWP.B3Frameworks.BO; using BWP.B3Frameworks.Utils; @@ -22,8 +23,7 @@ namespace BWP.B3QingDaoWanFu.Tasks { var query = new DQueryDom(new JoinAlias(typeof(TrustPay))); query.Where.Conditions.Add(DQCondition.GreaterThanOrEqual("PayState", 付款状态.请求支付)); query.Where.Conditions.Add(DQCondition.LessThanOrEqual("ReCheckTime", BLContext.Now)); - query.Where.Conditions.Add(DQCondition.GreaterThan("CreateTime", BLContext.Now.AddHours(-5))); - query.Where.Conditions.Add(DQCondition.EQ("ReChecked", false)); + query.Where.Conditions.Add(DQCondition.GreaterThan("CreateTime", BLContext.Now.AddHours(-3))); query.Where.Conditions.Add(DQCondition.LessThan("ReCheckCount", 6)); query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field("Gathering_ID"))); @@ -53,7 +53,20 @@ namespace BWP.B3QingDaoWanFu.Tasks { _trustPayID = id; } + volatile static object _lockObj = new object(); + public void Execute() { + if (!Monitor.TryEnter(_lockObj)) { + throw new SameTaskNotFinishException(this); + } + try { + DoExecute(); + } finally { + Monitor.Exit(_lockObj); + } + } + + void DoExecute() { if (_trustPayID == 0) return; @@ -62,19 +75,17 @@ namespace BWP.B3QingDaoWanFu.Tasks { trustPay = InnerBLUtil.GetSingleDmo(session, "ID", _trustPayID); if (trustPay == null || trustPay.AccountCustomer_ID == null) return; - trustPay.ID = _trustPayID; - trustPay.ReCheckCount++; - if (trustPay.Gathering_ID > 0) { - if (!trustPay.ReChecked) { - trustPay.ReChecked = true; - InnerBLUtil.UpdateEntityProperties(session, trustPay, "ReChecked", "ReCheckCount"); - session.Commit(); - } + trustPay.ID = _trustPayID; + if (trustPay.Gathering_ID > 0) { return; } + trustPay.ReCheckCount++; if (trustPay.PayState == 付款状态.请求支付) { - if (!ABCPaySuccess(session, trustPay)) + if (!ABCPaySuccess(trustPay)) { + InnerBLUtil.UpdateEntityProperties(session, trustPay, "ReCheckTime", "ReCheckCount" ); + session.Commit(); return; + } trustPay.PayState = 付款状态.付款成功; } } @@ -92,25 +103,22 @@ namespace BWP.B3QingDaoWanFu.Tasks { } if (gatheringID > 0) { trustPay.Gathering_ID = gatheringID; - } + } + InnerBLUtil.UpdateEntityProperties(session, trustPay, "Gathering_ID", "PayState", "ReCheckCount"); session.Commit(); } + //创建收款单成功且 状态修改了 以后 就直接返回 + return; } - } catch (Exception e) { - msg = e.Message; - } - - using (var session = Dmo.NewSession()) { - trustPay.ReChecked = trustPay.Gathering_ID > 0; - - InnerBLUtil.UpdateEntityProperties(session, trustPay, "Gathering_ID", "PayState", "ReChecked", "ReCheckCount"); + } catch (Exception e) { + } + using (var session = Dmo.NewSession()) { + InnerBLUtil.UpdateEntityProperties(session, trustPay , "PayState", "ReCheckCount"); session.Commit(); - } - if (!string.IsNullOrEmpty(msg)) - throw new ApplicationException(msg); + } } - private static bool ABCPaySuccess(IDmoSessionWithTransaction session, TrustPay trustPay) { + private static bool ABCPaySuccess(TrustPay trustPay) { var req = new B3QueryOrderRequest(); req.OrderNo = trustPay.ABCPay_No; var res = req.Submit(); @@ -119,17 +127,10 @@ namespace BWP.B3QingDaoWanFu.Tasks { } if (res.StatusIsSuccess()) { return true; - } - + } if (res.Status == "01" || res.Status == "02" || res.Status == "03") { - trustPay.ReCheckTime = BLContext.Now.AddMinutes(5); - InnerBLUtil.UpdateEntityProperties(session, trustPay, "ReCheckTime", "ReCheckCount"); - session.Commit(); - return false; - } - trustPay.ReChecked = true; - InnerBLUtil.UpdateEntityProperties(session, trustPay, "ReChecked", "ReCheckCount"); - session.Commit(); + trustPay.ReCheckTime = BLContext.Now.AddMinutes(5); + } return false; }