Browse Source

定时任务增加lock

master
robin 7 years ago
parent
commit
1435a5f0b9
3 changed files with 61 additions and 36 deletions
  1. +12
    -2
      B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/TrustPay_/TrustPayEdit.cs
  2. +14
    -0
      B3QingDaoWanFu/Tasks/CreatGatheringTask.cs
  3. +35
    -34
      B3QingDaoWanFu/Tasks/RecheckTrustPayTask.cs

+ 12
- 2
B3QingDaoWanFu.Web/Pages/B3QingDaoWanFu/TrustPay_/TrustPayEdit.cs View File

@ -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<TrustPay, ITrustPayBL> {
@ -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<ITrustPayBL>(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);


+ 14
- 0
B3QingDaoWanFu/Tasks/CreatGatheringTask.cs View File

@ -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();


+ 35
- 34
B3QingDaoWanFu/Tasks/RecheckTrustPayTask.cs View File

@ -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<TrustPay>(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;
}


Loading…
Cancel
Save