You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
4.7 KiB

using System;
using System.Threading;
using BWP.B3Frameworks;
using BWP.B3Frameworks.BO;
using BWP.B3Frameworks.Utils;
using BWP.B3QingDaoWanFu.BL;
using BWP.B3QingDaoWanFu.BO;
using BWP.B3QingDaoWanFu.BO.NamedValueTemplate;
using BWP.B3QingDaoWanFu.Utils;
using BWP.BWPTrustPayClient.TrustPayRequests;
using Forks.EnterpriseServices.BusinessInterfaces;
using Forks.EnterpriseServices.DomainObjects2;
using Forks.EnterpriseServices.DomainObjects2.DQuery;
using Forks.EnterpriseServices.SqlDoms;
using TSingSoft.WebPluginFramework;
using TSingSoft.WebPluginFramework.QueueTasks;
using TSingSoft.WebPluginFramework.TimerTasks;
namespace BWP.B3QingDaoWanFu.Tasks {
[Serializable]
public class QueryTrustPayTask : ITimerTask {
public void Execute() {
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(-3)));
query.Where.Conditions.Add(DQCondition.LessThan("ReCheckCount", 6));
query.Where.Conditions.Add(DQCondition.IsNull(DQExpression.Field("Gathering_ID")));
query.Columns.Add(DQSelectColumn.Field("ID"));
query.Range = SelectRange.Top(5);
var list = query.EExecuteList<long>();
foreach (var id in list) {
QueueTaskService.Add(new RecheckTrustPayTask(id));
}
}
public string Name {
get { return "查询未复核农行付款"; }
}
}
[Serializable]
public class RecheckTrustPayTask : ITimerTask {
private readonly long _trustPayID;
public RecheckTrustPayTask() {
}
public RecheckTrustPayTask(long id) {
_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;
TrustPay trustPay;
using (var session = Dmo.NewSession()) {
trustPay = InnerBLUtil.GetSingleDmo<TrustPay>(session, "ID", _trustPayID);
if (trustPay == null || trustPay.AccountCustomer_ID == null)
return;
trustPay.ID = _trustPayID;
if (trustPay.Gathering_ID > 0) {
return;
}
trustPay.ReCheckCount++;
if (trustPay.PayState == .) {
if (!ABCPaySuccess(trustPay)) {
InnerBLUtil.UpdateEntityProperties(session, trustPay, "ReCheckTime", "ReCheckCount" );
session.Commit();
return;
}
trustPay.PayState = .;
}
}
//创建收款单和事务和更新状态的事务分开
string msg = "";
try {
if (trustPay.PayState == .) {
using (var session = Dmo.NewSession()) {
var bl = BIFactory.Create<ITrustPayBL>(session);
long gatheringID;
var config = new WanFuOnlineConfig();
using (new SpecialDomainUserBLScope(config.DomainUserForTrustPay.Value)) {
bl.CreateGathering(trustPay, out gatheringID);
}
if (gatheringID > 0) {
trustPay.Gathering_ID = gatheringID;
}
InnerBLUtil.UpdateEntityProperties(session, trustPay, "Gathering_ID", "PayState", "ReCheckCount");
session.Commit();
}
//创建收款单成功且 状态修改了 以后 就直接返回
return;
}
} catch (Exception e) {
}
using (var session = Dmo.NewSession()) {
InnerBLUtil.UpdateEntityProperties(session, trustPay , "PayState", "ReCheckCount");
session.Commit();
}
}
private static bool ABCPaySuccess(TrustPay trustPay) {
var req = new B3QueryOrderRequest();
req.OrderNo = trustPay.ABCPay_No;
var res = req.Submit();
if (!res.IsSuccess) {
throw new Exception(res.ErrorMessage);
}
if (res.StatusIsSuccess()) {
return true;
}
if (res.Status == "01" || res.Status == "02" || res.Status == "03") {
trustPay.ReCheckTime = BLContext.Now.AddMinutes(5);
}
return false;
}
public string Name {
get {
return string.Format(string.Format("复核付款单No.{0}", _trustPayID));
}
}
}
}