Commit 60e01ee8 by pye52

Merge branch 'new_master' into new_for_phone

parents 5523ffdc 0e901650
No preview for this file type
......@@ -174,40 +174,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
sendText.setText(log);
break;
case PayOnlineState.SUCCESS:
message.setTextColor(getResources().getColor(R.color.pay_success));
String successText = event.getMessage();
if (TextUtils.isEmpty(successText)) {
message.setText(R.string.pay_success);
TTSHelper.speak(getString(R.string.pay_success));
} else {
message.setText(successText);
TTSHelper.speak(successText);
}
qrCodeViewModel.scan();
String successTime = payDateFormat.format(new Date());
String successLog = "支付成功: " + successTime + " - " + event.getMessage();
LogUtils.file(TAG, successLog);
if (debugVs != null) return;
recText.setText(successLog);
paidSuccess(event.getMessage());
break;
case PayOnlineState.FAILED:
message.setTextColor(getResources().getColor(R.color.pay_failed));
String failedText = event.getMessage();
if (TextUtils.isEmpty(failedText)) {
message.setText(R.string.pay_failed);
TTSHelper.speak(getString(R.string.pay_failed));
} else {
message.setText(failedText);
TTSHelper.speak(failedText);
}
qrCodeViewModel.scan();
String failedTime = payDateFormat.format(new Date());
String failedLog = "支付失败: " + failedTime + " - " + event.getMessage();
LogUtils.file(TAG, failedLog);
if (debugVs != null) return;
recText.setText(failedLog);
paidFailed(event.getMessage());
break;
}
});
......@@ -226,6 +196,9 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
qrCodeViewModel.scan();
break;
case PayOfflineState.MARK_FAILED:
paidFailed(event.getMessage());
break;
}
});
......@@ -292,6 +265,42 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCWebSocketClient.getInstance().tryConnect();
}
private void paidSuccess(String successMessage) {
message.setTextColor(getResources().getColor(R.color.pay_success));
if (TextUtils.isEmpty(successMessage)) {
message.setText(R.string.pay_success);
TTSHelper.speak(getString(R.string.pay_success));
} else {
message.setText(successMessage);
TTSHelper.speak(successMessage);
}
qrCodeViewModel.scan();
String successTime = payDateFormat.format(new Date());
String successLog = "支付成功: " + successTime + " - " + successMessage;
LogUtils.file(TAG, successLog);
if (debugVs != null) return;
recText.setText(successLog);
}
private void paidFailed(String failedMessage) {
message.setTextColor(getResources().getColor(R.color.pay_failed));
if (TextUtils.isEmpty(failedMessage)) {
message.setText(R.string.pay_failed);
TTSHelper.speak(getString(R.string.pay_failed));
} else {
message.setText(failedMessage);
TTSHelper.speak(failedMessage);
}
qrCodeViewModel.scan();
String failedTime = payDateFormat.format(new Date());
String failedLog = "支付失败: " + failedTime + " - " + failedMessage;
LogUtils.file(TAG, failedLog);
if (debugVs != null) return;
recText.setText(failedLog);
}
@Override
protected void onResume() {
super.onResume();
......
......@@ -34,7 +34,7 @@ public abstract class BaseQRCodeScan implements IQRCodeScan {
}
byte[] buf = null;
int len = 0;
while (buf == null || end(buf)) {
while (buf == null || !end(buf)) {
byte[] b = new byte[64];
int l = serialPortIS.read(b);
if (l == 0) break;
......
......@@ -4,7 +4,7 @@ import android.os.Build;
public class QRCodeScanFactory {
private static final String TPS = "TPS";
private static final String T3 = "T3";
private static final String T3 = "56iqDS";
private static final String TPS_PORT = "/dev/ttyS0";
private static final String T3_PORT = "/dev/ttyS6";
......@@ -14,7 +14,7 @@ public class QRCodeScanFactory {
} else if (Build.DEVICE.contains(T3)) {
return new T3(T3_PORT);
} else {
throw new RuntimeException("不明设备型号");
throw new RuntimeException("不明设备型号: " + Build.DEVICE);
}
}
}
......@@ -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();
......
......@@ -103,6 +103,7 @@ public class PayOnlineViewModel extends ViewModel {
// 1、action为"PAY_RESULT"
if (payRequest == null || payRequest.getData().isEmpty()) {
LogUtils.w(TAG, "后台返回在线支付结果,但没有待处理任务");
payOnlineState.postValue(new PayOnlineState(PayOnlineState.IDLE));
return;
}
LogUtils.d(TAG, "在线支付结果响应: " + original);
......
......@@ -77,25 +77,20 @@ public class QRCodeViewModel extends ViewModel {
private Runnable scanRunnable = () -> {
qrCodeState.postValue(new QRCodeState(QRCodeState.IDLE));
LogUtils.i(TAG, "开始扫描二维码");
// 等待串口数据
// noinspection LoopStatementThatDoesntLoop
while (!scan.available()) {
qrCodeState.postValue(new QRCodeState(QRCodeState.SCANNING));
break;
}
while (!scan.available()) {}
qrCodeState.postValue(new QRCodeState(QRCodeState.SCANNING));
// 读取串口扫描的二维码数据
String scanData;
// 若存在测试数据,则直接读取测试数据
try {
scanData = scan.scan();
} catch (Exception e) {
LogUtils.e(TAG, "读取串口数据失败: " + e.getMessage(), e);
qrCodeState.postValue(new QRCodeState(QRCodeState.FAILED));
return;
}
// 若存在测试数据,则使用测试数据覆盖
if (!TextUtils.isEmpty(SmartCanteenUtils.testQRCode)) {
scanData = SmartCanteenUtils.testQRCode;
} else {
try {
scanData = scan.scan();
} catch (Exception e) {
LogUtils.e(TAG, "读取串口数据失败: " + e.getMessage(), e);
qrCodeState.postValue(new QRCodeState(QRCodeState.FAILED));
return;
}
}
// 需要识别二维码的类型
String terminalType = PayData.matchTerminalType(scanData);
......
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