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
84e90b01
authored
Sep 19, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化
parent
d2bceb1b
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
40 deletions
+33
-40
app/build.gradle
+8
-2
app/src/main/java/com/bgycc/smartcanteen/action/PayOfflineAction.java
+2
-2
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
+6
-6
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
+17
-29
app/src/main/java/com/bgycc/smartcanteen/task/QRCodeTask.java
+0
-1
No files found.
app/build.gradle
View file @
84e90b01
...
...
@@ -10,8 +10,8 @@ android {
applicationId
"com.bgycc.smartcanteen"
minSdkVersion
21
targetSdkVersion
22
versionCode
1
versionName
"1.0.
0
"
versionCode
2
versionName
"1.0.
2
"
testInstrumentationRunner
"android.support.test.runner.AndroidJUnitRunner"
}
buildTypes
{
...
...
@@ -25,6 +25,12 @@ android {
jniLibs
.
srcDirs
=
[
'libs'
]
}
}
lintOptions
{
checkReleaseBuilds
false
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError
false
}
}
dependencies
{
...
...
app/src/main/java/com/bgycc/smartcanteen/action/PayOfflineAction.java
View file @
84e90b01
...
...
@@ -106,12 +106,12 @@ public class PayOfflineAction extends Action {
final
MainWebSocket
.
Response
response
=
new
MainWebSocket
.
Response
()
{
@Override
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{
protected
void
onSuccess
(
long
sessionId
,
JSONObject
data
,
String
message
)
{
cancel
();
PayStorage
.
getInstance
().
clearPayList
();
}
@Override
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
code
)
{
protected
void
onFail
(
long
sessionId
,
JSONObject
data
,
String
message
,
String
code
)
{
cancel
();
}
};
...
...
app/src/main/java/com/bgycc/smartcanteen/action/PayOnlineAction.java
View file @
84e90b01
...
...
@@ -103,11 +103,11 @@ public class PayOnlineAction extends Action {
final
MainWebSocket
.
Response
response
=
new
MainWebSocket
.
Response
()
{
@Override
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{
protected
void
onSuccess
(
long
sessionId
,
JSONObject
data
,
String
message
)
{
setState
(
State
.
RESQUEST_SUCCESS
,
message
);
}
@Override
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
code
)
{
protected
void
onFail
(
long
sessionId
,
JSONObject
data
,
String
message
,
String
code
)
{
setState
(
State
.
RESQUEST_FAIL
,
message
);
}
};
...
...
@@ -133,21 +133,21 @@ public class PayOnlineAction extends Action {
MainWebSocket
.
Response
mPayResultResponse
=
new
MainWebSocket
.
Response
()
{
@Override
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{
protected
void
onSuccess
(
long
sessionId
,
JSONObject
data
,
String
message
)
{
if
(
data
==
null
)
return
;
String
payCode
=
data
.
optString
(
"payCode"
,
""
);
if
(
payCode
.
equals
(
mPayCode
))
{
setState
(
State
.
RESPONSE_SUCCESS
,
message
);
MainWebSocket
.
response
(
data
.
optInt
(
"serialNumber"
,
-
1
)
,
"0"
,
"已接收"
);
MainWebSocket
.
response
(
sessionId
,
"0"
,
"已接收"
);
}
}
@Override
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
code
)
{
protected
void
onFail
(
long
sessionId
,
JSONObject
data
,
String
message
,
String
code
)
{
if
(
data
==
null
)
return
;
String
payCode
=
data
.
optString
(
"payCode"
,
""
);
if
(
payCode
.
equals
(
mPayCode
))
{
setState
(
State
.
RESPONSE_FAIL
,
message
);
MainWebSocket
.
response
(
data
.
optInt
(
"serialNumber"
,
-
1
)
,
"0"
,
"已接收"
);
MainWebSocket
.
response
(
sessionId
,
"0"
,
"已接收"
);
}
}
};
...
...
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
View file @
84e90b01
package
com
.
bgycc
.
smartcanteen
.
server
.
websocket
;
import
android.util.LongSparseArray
;
import
android.util.SparseArray
;
import
com.bgycc.smartcanteen.App
;
import
com.bgycc.smartcanteen.AppConfig
;
...
...
@@ -110,10 +111,10 @@ public class MainWebSocket extends WebSocketClient {
return
list
.
remove
(
response
);
}
public
static
void
response
(
int
sessionId
,
String
code
,
String
message
)
{
public
static
void
response
(
long
sessionId
,
String
code
,
String
message
)
{
try
{
JSONObject
json
=
new
JSONObject
();
json
.
put
(
FieldEnum
.
equipmentId
.
name
(),
sDeviceSN
);
//
json.put(FieldEnum.equipmentId.name(), sDeviceSN);
json
.
put
(
FieldEnum
.
serialNumber
.
name
(),
sessionId
);
json
.
put
(
FieldEnum
.
code
.
name
(),
code
);
json
.
put
(
FieldEnum
.
message
.
name
(),
message
);
...
...
@@ -127,8 +128,8 @@ public class MainWebSocket extends WebSocketClient {
}
}
private
int
mSessionId
=
0
;
private
final
SparseArray
<
Request
>
mRequestList
=
new
SparseArray
<>();
private
long
mSessionId
=
0
;
private
final
LongSparseArray
<
Request
>
mRequestList
=
new
Long
SparseArray
<>();
private
final
HashMap
<
String
,
ArrayList
<
Response
>>
mSubscribeList
=
new
HashMap
<>();
private
MainWebSocket
(
URI
serverUri
)
{
...
...
@@ -137,12 +138,11 @@ public class MainWebSocket extends WebSocketClient {
private
void
send
(
String
action
,
Object
data
,
Response
callback
)
{
try
{
if
(
mSessionId
>=
Integer
.
MAX_VALUE
)
mSessionId
=
0
;
if
(
mSessionId
>=
Long
.
MAX_VALUE
)
mSessionId
=
0
;
mSessionId
++;
Request
request
=
new
Request
();
request
.
action
=
action
;
request
.
time
=
System
.
currentTimeMillis
();
request
.
response
=
callback
;
request
.
params
=
new
JSONObject
();
request
.
params
.
put
(
FieldEnum
.
equipmentId
.
name
(),
sDeviceSN
);
...
...
@@ -174,7 +174,7 @@ public class MainWebSocket extends WebSocketClient {
try
{
JSONObject
json
=
new
JSONObject
(
message
);
final
int
sessionId
=
json
.
optInt
(
FieldEnum
.
serialNumber
.
name
(),
-
1
);
final
long
sessionId
=
json
.
optLong
(
FieldEnum
.
serialNumber
.
name
(),
-
1
);
String
action
=
json
.
optString
(
FieldEnum
.
action
.
name
(),
""
);
String
code
=
json
.
optString
(
FieldEnum
.
code
.
name
(),
""
);
...
...
@@ -183,6 +183,7 @@ public class MainWebSocket extends WebSocketClient {
JSONObject
data
=
new
JSONObject
();
data
.
put
(
FieldEnum
.
equipmentId
.
name
(),
json
.
getString
(
FieldEnum
.
data
.
name
()));
JSONObject
j
=
new
JSONObject
();
j
.
put
(
FieldEnum
.
action
.
name
(),
ActionEnum
.
CHECK_DEVICE
.
name
());
j
.
put
(
FieldEnum
.
data
.
name
(),
data
);
j
.
put
(
FieldEnum
.
serialNumber
.
name
(),
sessionId
);
LogUtil
.
i
(
TAG
,
String
.
format
(
"send: %s"
,
j
.
toString
()));
...
...
@@ -221,22 +222,8 @@ public class MainWebSocket extends WebSocketClient {
public
static
class
Request
{
String
action
;
long
time
=
0
;
JSONObject
params
;
Response
response
;
void
parseResponse
(
String
code
,
JSONObject
res
)
{
if
(
res
==
null
||
response
==
null
)
return
;
response
.
parse
(
code
,
res
);
String
message
=
res
.
optString
(
FieldEnum
.
message
.
name
());
JSONObject
data
=
res
.
optJSONObject
(
FieldEnum
.
data
.
name
());
if
(
CODE_OK
.
equals
(
code
))
{
response
.
onSuccess
(
data
,
message
);
}
else
{
response
.
onFail
(
data
,
message
,
code
);
}
}
}
public
static
abstract
class
Response
{
...
...
@@ -246,12 +233,13 @@ public class MainWebSocket extends WebSocketClient {
void
parse
(
String
code
,
JSONObject
res
)
{
if
(
res
==
null
)
return
;
long
sessionId
=
res
.
optLong
(
FieldEnum
.
serialNumber
.
name
(),
-
1
);
String
message
=
res
.
optString
(
FieldEnum
.
message
.
name
());
JSONObject
data
=
res
.
optJSONObject
(
FieldEnum
.
data
.
name
());
if
(
CODE_OK
.
equals
(
code
))
{
success
(
data
,
message
);
success
(
sessionId
,
data
,
message
);
}
else
{
fail
(
data
,
message
,
code
);
fail
(
sessionId
,
data
,
message
,
code
);
}
}
...
...
@@ -262,17 +250,17 @@ public class MainWebSocket extends WebSocketClient {
this
.
cancel
=
true
;
}
public
void
success
(
JSONObject
data
,
String
message
)
{
public
void
success
(
long
sessionId
,
JSONObject
data
,
String
message
)
{
if
(
this
.
cancel
)
return
;
onSuccess
(
data
,
message
);
onSuccess
(
sessionId
,
data
,
message
);
}
public
void
fail
(
JSONObject
data
,
String
message
,
String
code
)
{
public
void
fail
(
long
sessionId
,
JSONObject
data
,
String
message
,
String
code
)
{
if
(
this
.
cancel
)
return
;
onFail
(
data
,
message
,
code
);
onFail
(
sessionId
,
data
,
message
,
code
);
}
protected
void
onSuccess
(
JSONObject
data
,
String
message
)
{}
protected
void
onFail
(
JSONObject
data
,
String
message
,
String
code
)
{}
protected
void
onSuccess
(
long
sessionId
,
JSONObject
data
,
String
message
)
{}
protected
void
onFail
(
long
sessionId
,
JSONObject
data
,
String
message
,
String
code
)
{}
}
}
app/src/main/java/com/bgycc/smartcanteen/task/QRCodeTask.java
View file @
84e90b01
...
...
@@ -7,7 +7,6 @@ import com.bgycc.smartcanteen.event.LogEvent;
import
com.bgycc.smartcanteen.helper.TimerHelper
;
import
com.bgycc.smartcanteen.server.websocket.MainWebSocket
;
import
com.bgycc.smartcanteen.util.ByteUtil
;
import
com.bgycc.smartcanteen.util.LogUtil
;
import
org.greenrobot.eventbus.EventBus
;
import
org.json.JSONObject
;
...
...
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