Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
60e01ee8
authored
Mar 07, 2020
by
pye52
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'new_master' into new_for_phone
parents
5523ffdc
0e901650
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
71 additions
and
59 deletions
+71
-59
app/libs/telpo_api.jar
+0
-0
app/src/main/java/com/bgycc/smartcanteen/MainActivity.java
+41
-32
app/src/main/java/com/bgycc/smartcanteen/qrcode/BaseQRCodeScan.java
+1
-1
app/src/main/java/com/bgycc/smartcanteen/qrcode/QRCodeScanFactory.java
+2
-2
app/src/main/java/com/bgycc/smartcanteen/state/PayOfflineState.java
+2
-1
app/src/main/java/com/bgycc/smartcanteen/viewModel/PayOfflineViewModel.java
+14
-8
app/src/main/java/com/bgycc/smartcanteen/viewModel/PayOnlineViewModel.java
+1
-0
app/src/main/java/com/bgycc/smartcanteen/viewModel/QRCodeViewModel.java
+10
-15
No files found.
app/libs/telpo_api.jar
View file @
60e01ee8
No preview for this file type
app/src/main/java/com/bgycc/smartcanteen/MainActivity.java
View file @
60e01ee8
...
...
@@ -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
();
...
...
app/src/main/java/com/bgycc/smartcanteen/qrcode/BaseQRCodeScan.java
View file @
60e01ee8
...
...
@@ -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
;
...
...
app/src/main/java/com/bgycc/smartcanteen/qrcode/QRCodeScanFactory.java
View file @
60e01ee8
...
...
@@ -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
);
}
}
}
app/src/main/java/com/bgycc/smartcanteen/state/PayOfflineState.java
View file @
60e01ee8
...
...
@@ -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
{
}
...
...
app/src/main/java/com/bgycc/smartcanteen/viewModel/PayOfflineViewModel.java
View file @
60e01ee8
...
...
@@ -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
();
...
...
app/src/main/java/com/bgycc/smartcanteen/viewModel/PayOnlineViewModel.java
View file @
60e01ee8
...
...
@@ -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
);
...
...
app/src/main/java/com/bgycc/smartcanteen/viewModel/QRCodeViewModel.java
View file @
60e01ee8
...
...
@@ -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
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment