Commit bbd70a5f by pye52

修复离线支付runnable的执行体写在构造函数导致无法执行的问题。

同时离线支付增加"标记失败"状态,则订单在数据库状态更新失败时会发送该状态通知。
parent 396214ba
......@@ -11,8 +11,9 @@ public class PayOfflineState {
public static final int SEND = 2;
public static final int SUCCESS = 3;
public static final int FAILED = 4;
public static final int MARK_FAILED = 5;
@IntDef(value = {MARK, IDLE, SEND, SUCCESS, FAILED})
@IntDef(value = {MARK, IDLE, SEND, SUCCESS, FAILED, MARK_FAILED})
public @interface PAY_OFFLINE_STATE {
}
......
......@@ -70,7 +70,6 @@ public class PayOfflineViewModel extends ViewModel {
public void exec(PayData payData) {
MarkRunnable runnable = new MarkRunnable(payData);
SCTaskExecutor.getInstance().executeOnDiskIO(runnable);
LogUtils.w(TAG, "WebSocket未链接: " + payData.toString());
}
private void cancelTimeout() {
......@@ -113,10 +112,20 @@ public class PayOfflineViewModel extends ViewModel {
private PayData payData;
MarkRunnable(PayData payData) {
this.payData = payData;
}
@Override
public void run() {
payData.payOffline();
payDataRepository.updatePayData(payData);
int result = payDataRepository.updatePayData(payData);
if (result <= 0) {
payOfflineState.postValue(new PayOfflineState(PayOfflineState.MARK_FAILED));
LogUtils.w(TAG, "WebSocket未链接, 订单标记失败: " + payData.toString());
return;
}
payOfflineState.postValue(new PayOfflineState(PayOfflineState.MARK));
LogUtils.w(TAG, "WebSocket未链接, 订单已标记为离线支付: " + payData.toString());
try {
Thread.sleep(DEFAULT_DELAY);
} catch (Exception ignored) {
......@@ -124,11 +133,6 @@ public class PayOfflineViewModel extends ViewModel {
payOfflineState.postValue(new PayOfflineState(PayOfflineState.IDLE));
}
}
@Override
public void run() {
}
}
private class RequestRunnable implements Runnable {
......@@ -160,6 +164,7 @@ public class PayOfflineViewModel extends ViewModel {
public void run() {
if (payRequest == null || payRequest.getData().isEmpty()) {
LogUtils.w(TAG, "后台返回离线支付结果,但没有待处理任务");
payOfflineState.postValue(new PayOfflineState(PayOfflineState.IDLE));
return;
}
......@@ -200,6 +205,7 @@ public class PayOfflineViewModel extends ViewModel {
payOfflineState.postValue(new PayOfflineState(PayOfflineState.FAILED, "支付超时"));
if (payRequest == null || payRequest.getData().isEmpty()) {
LogUtils.w(TAG, "离线支付超时: 待处理任务为空");
payOfflineState.postValue(new PayOfflineState(PayOfflineState.IDLE));
return;
}
List<PayData> payDataList = payRequest.getData();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment