Commit 5b7c39f9 by pye52

Merge branch 'develop'

parents 87beb945 38d5b2be
......@@ -116,7 +116,7 @@ dependencies {
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation "org.java-websocket:Java-WebSocket:1.5.1"
implementation 'com.blankj:utilcodex:1.28.4'
implementation 'com.blankj:utilcodex:1.29.0'
def okhttp_version = "4.6.0"
implementation "com.squareup.okhttp3:okhttp:$okhttp_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
......
......@@ -161,6 +161,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
payOnlineViewModel.getPayOnlineStateEvent().observe(this, event -> {
switch (event.getState()) {
case PayOnlineState.IDLE:
message.setTextColor(getResources().getColor(R.color.qrcode_normal));
message.setText(R.string.pay_idle);
break;
case PayOnlineState.SEND:
message.setTextColor(getResources().getColor(R.color.pay_idle));
message.setText(R.string.pay_wait);
......
package com.bgycc.smartcanteen.viewModel;
import android.text.TextUtils;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.ViewModel;
......@@ -97,27 +95,16 @@ public class PayOfflineViewModel extends ViewModel {
}
private SCWebSocketListener listener = new SCWebSocketListenerAdapter() {
private static final String RESPONSE_MESSAGE = "message";
private static final String RESPONSE_OFFLINE_RESULT = "操作完成";
private static final String RESPONSE_PAY_OFFLINE_UPLOAD = "PAY_OFFLINE_UPLOAD";
private static final String RESPONSE_PAY_OFFLINE_RESULT = "PAY_OFFLINE_RESULT";
private static final String RESPONSE_SUCCESS = "0";
// 每心跳多少次后进行一次离线订单检测
private static final int PAY_OFFLINE_CHECK = 30;
// 当链接频繁断开时,给予离线订单检测一定缓冲时间
private static final long PAY_OFFLINE_INTERVAL = 30 * 60 * 1000;
private long lastPayTime = -1;
private int heartbeatCount = 0;
@Override
public void onOpen(ServerHandshake data) {
heartbeatCount = 0;
long currentTime = System.currentTimeMillis();
if ((currentTime - lastPayTime) < PAY_OFFLINE_INTERVAL) {
LogUtils.w(TAG, "离线检测过于频繁,可能是链接频繁断开导致");
return;
}
lastPayTime = currentTime;
traversalPayOfflineData();
}
......@@ -133,30 +120,28 @@ public class PayOfflineViewModel extends ViewModel {
@Override
public void onMessage(String action, JsonObject obj, String original) {
if (action.equals(RESPONSE_PAY_OFFLINE_RESULT)) {
String code = null;
// 这里为了兼容新的消息体需要单独对code作判断
if (obj.has("code")) {
code = obj.get("code").getAsString();
}
if (code != null && code.equals(RESPONSE_SUCCESS)) {
// 离线订单已写入到服务器数据库,可以标记为支付成功
LogUtils.d(TAG, "离线支付结果响应: " + original);
ResponseRunnable runnable = new ResponseRunnable(original);
SCTaskExecutor.getInstance().executeOnDiskIO(runnable);
}
return;
String code = null;
if (obj.has("code")) {
code = obj.get("code").getAsString();
}
String message = "";
if (obj.has(RESPONSE_MESSAGE)) {
message = obj.get(RESPONSE_MESSAGE).getAsString();
switch (action) {
case RESPONSE_PAY_OFFLINE_UPLOAD:
if (code != null && code.equals(RESPONSE_SUCCESS)) {
// 离线订单只上传到服务器,未写入到服务器数据库
// 此时只需要更改其uploadTime(保证一定时间内不会频繁发送到服务器)
UpdateUploadTimeRunnable runnable = new UpdateUploadTimeRunnable();
SCTaskExecutor.getInstance().executeOnDiskIO(runnable);
}
break;
case RESPONSE_PAY_OFFLINE_RESULT:
if (code != null && code.equals(RESPONSE_SUCCESS)) {
// 离线订单已写入到服务器数据库,可以标记为支付成功
LogUtils.d(TAG, "离线支付结果响应: " + original);
ResponseRunnable runnable = new ResponseRunnable(original);
SCTaskExecutor.getInstance().executeOnDiskIO(runnable);
}
break;
}
if (!TextUtils.isEmpty(action) || !message.equals(RESPONSE_OFFLINE_RESULT)) return;
// 离线订单只上传到服务器,未写入到服务器数据库
// 此时只需要更改其uploadTime(保证一定时间内不会频繁发送到服务器)
UpdateUploadTimeRunnable runnable = new UpdateUploadTimeRunnable();
SCTaskExecutor.getInstance().executeOnDiskIO(runnable);
}
};
......
......@@ -100,5 +100,5 @@ dependencies {
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'com.blankj:utilcodex:1.28.4'
implementation 'com.blankj:utilcodex:1.29.0'
}
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