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
5b7c39f9
authored
May 29, 2020
by
pye52
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop'
parents
87beb945
38d5b2be
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
27 additions
and
38 deletions
+27
-38
app/build.gradle
+1
-1
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
+4
-0
app/src/main/java/com/bgycc/smartcanteen/viewModel/PayOfflineViewModel.java
+21
-36
daemon/build.gradle
+1
-1
智慧食堂开发文档.docx
+0
-0
No files found.
app/build.gradle
View file @
5b7c39f9
...
...
@@ -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.2
8.4
'
implementation
'com.blankj:utilcodex:1.2
9.0
'
def
okhttp_version
=
"4.6.0"
implementation
"com.squareup.okhttp3:okhttp:$okhttp_version"
implementation
"com.squareup.okhttp3:logging-interceptor:$okhttp_version"
...
...
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
View file @
5b7c39f9
...
...
@@ -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
);
...
...
app/src/main/java/com/bgycc/smartcanteen/viewModel/PayOfflineViewModel.java
View file @
5b7c39f9
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
);
}
};
...
...
daemon/build.gradle
View file @
5b7c39f9
...
...
@@ -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.2
8.4
'
implementation
'com.blankj:utilcodex:1.2
9.0
'
}
智慧食堂开发文档.docx
View file @
5b7c39f9
No preview for this file type
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