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
bbd70a5f
authored
Mar 07, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修复离线支付runnable的执行体写在构造函数导致无法执行的问题。
同时离线支付增加"标记失败"状态,则订单在数据库状态更新失败时会发送该状态通知。
parent
396214ba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
9 deletions
+16
-9
app/src/main/java/com/bgycc/smartcanteen/state/PayOfflineState.java
+2
-1
app/src/main/java/com/bgycc/smartcanteen/viewModel/PayOfflineViewModel.java
+14
-8
No files found.
app/src/main/java/com/bgycc/smartcanteen/state/PayOfflineState.java
View file @
bbd70a5f
...
...
@@ -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 @
bbd70a5f
...
...
@@ -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
();
...
...
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