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
ffeca9ea
authored
Dec 03, 2019
by
patpat
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
日志拉取
parent
3ea9b03b
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
38 additions
and
25 deletions
+38
-25
app/build.gradle
+1
-0
app/src/main/java/com/bgycc/smartcanteen/AppConfig.kt
+5
-5
app/src/main/java/com/bgycc/smartcanteen/action/LogAction.kt
+16
-13
app/src/main/java/com/bgycc/smartcanteen/server/http/CommonApi.kt
+2
-1
app/src/main/java/com/bgycc/smartcanteen/server/http/MainHttpClient.kt
+7
-6
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
+7
-0
No files found.
app/build.gradle
View file @
ffeca9ea
...
@@ -73,6 +73,7 @@ dependencies {
...
@@ -73,6 +73,7 @@ dependencies {
implementation
'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation
'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation
'com.squareup.retrofit2:retrofit:2.6.2'
implementation
'com.squareup.retrofit2:retrofit:2.6.2'
implementation
'com.squareup.retrofit2:converter-gson:2.6.0'
implementation
'com.squareup.retrofit2:converter-gson:2.6.0'
implementation
'com.squareup.retrofit2:converter-scalars:2.6.0'
testImplementation
'junit:junit:4.12'
testImplementation
'junit:junit:4.12'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test:runner:1.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestImplementation
'com.android.support.test.espresso:espresso-core:3.0.2'
...
...
app/src/main/java/com/bgycc/smartcanteen/AppConfig.kt
View file @
ffeca9ea
...
@@ -13,8 +13,8 @@ object AppConfig {
...
@@ -13,8 +13,8 @@ object AppConfig {
fun
getMainWebSocketServerHost
():
String
{
fun
getMainWebSocketServerHost
():
String
{
return
when
(
SERVER
)
{
return
when
(
SERVER
)
{
Server
.
DEV
->
"10.187.43.221"
Server
.
DEV
->
"10.187.43.221
:9001
"
Server
.
TEST
->
"diningservicetest.bgy.com.cn"
Server
.
TEST
->
"diningservicetest.bgy.com.cn
:9001
"
Server
.
UAT
->
"diningserviceuat.bgy.com.cn"
Server
.
UAT
->
"diningserviceuat.bgy.com.cn"
else
->
"diningservice.bgy.com.cn"
else
->
"diningservice.bgy.com.cn"
}
}
...
@@ -22,8 +22,8 @@ object AppConfig {
...
@@ -22,8 +22,8 @@ object AppConfig {
fun
getMainWebSocketServerUrl
(
id
:
String
,
version
:
String
):
String
{
fun
getMainWebSocketServerUrl
(
id
:
String
,
version
:
String
):
String
{
return
when
(
SERVER
)
{
return
when
(
SERVER
)
{
Server
.
DEV
->
"ws://${getMainWebSocketServerHost()}
:9001
/websocket/$id/V$version"
Server
.
DEV
->
"ws://${getMainWebSocketServerHost()}/websocket/$id/V$version"
Server
.
TEST
->
"ws://${getMainWebSocketServerHost()}
:9001
/websocket/$id/V$version"
Server
.
TEST
->
"ws://${getMainWebSocketServerHost()}/websocket/$id/V$version"
Server
.
UAT
->
"wss://${getMainWebSocketServerHost()}/websocket/$id/V$version"
Server
.
UAT
->
"wss://${getMainWebSocketServerHost()}/websocket/$id/V$version"
else
->
"wss://${getMainWebSocketServerHost()}/websocket/$id/V$version"
else
->
"wss://${getMainWebSocketServerHost()}/websocket/$id/V$version"
}
}
...
@@ -32,7 +32,7 @@ object AppConfig {
...
@@ -32,7 +32,7 @@ object AppConfig {
fun
getMainHttpServerHost
():
String
{
fun
getMainHttpServerHost
():
String
{
return
when
(
SERVER
)
{
return
when
(
SERVER
)
{
Server
.
DEV
->
"http://diningbackdev.bgy.com.cn"
Server
.
DEV
->
"http://diningbackdev.bgy.com.cn"
Server
.
TEST
->
"http://diningbacktest.bgy.com.cn"
Server
.
TEST
->
"http://diningbacktest.bgy.com.cn
:9000
"
Server
.
UAT
->
"http://diningbackuat.bgy.com.cn"
Server
.
UAT
->
"http://diningbackuat.bgy.com.cn"
else
->
"http://diningback.bgy.com.cn"
else
->
"http://diningback.bgy.com.cn"
}
}
...
...
app/src/main/java/com/bgycc/smartcanteen/action/LogAction.kt
View file @
ffeca9ea
...
@@ -24,7 +24,13 @@ object LogAction : Action(ActionEnum.LOG_PULL.name) {
...
@@ -24,7 +24,13 @@ object LogAction : Action(ActionEnum.LOG_PULL.name) {
val
formatSrc
=
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
getDefault
())
val
formatSrc
=
SimpleDateFormat
(
"yyyy-MM-dd"
,
Locale
.
getDefault
())
val
type
=
data
.
getString
(
"logType"
)
val
type
=
data
.
getString
(
"logType"
)
val
startTime
=
formatSrc
.
parse
(
data
.
getString
(
"startTime"
))
val
startTime
=
formatSrc
.
parse
(
data
.
getString
(
"startTime"
))
startTime
.
hours
=
0
startTime
.
minutes
=
0
startTime
.
seconds
=
0
val
endTime
=
formatSrc
.
parse
(
data
.
getString
(
"endTime"
))
val
endTime
=
formatSrc
.
parse
(
data
.
getString
(
"endTime"
))
endTime
.
hours
=
23
endTime
.
minutes
=
59
endTime
.
seconds
=
59
if
(
startTime
>
endTime
)
return
if
(
startTime
>
endTime
)
return
val
formatDst
=
SimpleDateFormat
(
"yyyy_MM_dd"
,
Locale
.
getDefault
())
val
formatDst
=
SimpleDateFormat
(
"yyyy_MM_dd"
,
Locale
.
getDefault
())
...
@@ -44,23 +50,20 @@ object LogAction : Action(ActionEnum.LOG_PULL.name) {
...
@@ -44,23 +50,20 @@ object LogAction : Action(ActionEnum.LOG_PULL.name) {
FileUtils
.
deleteDir
(
logUploadDir
)
FileUtils
.
deleteDir
(
logUploadDir
)
logUploadDir
.
mkdirs
()
logUploadDir
.
mkdirs
()
when
(
type
)
{
val
logDir
=
when
(
type
)
{
"app"
->
{
"system"
->
File
(
PathUtils
.
getExternalStoragePath
(),
"boot_log"
)
val
logDir
=
File
(
PathUtils
.
getExternalAppCachePath
(),
"log"
)
else
->
File
(
PathUtils
.
getExternalAppCachePath
(),
"log"
)
dateList
.
forEach
{
val
f
=
File
(
logDir
,
"util_${it}_${BuildConfig.APPLICATION_ID}.txt"
)
if
(
f
.
exists
()
&&
f
.
isFile
)
{
FileUtils
.
copyFile
(
f
,
File
(
logUploadDir
,
f
.
name
))
}
}
FileUtils
.
listFilesInDir
(
logDir
).
forEach
{
val
date
=
Date
(
it
.
lastModified
())
if
(
date
>=
startTime
&&
date
<=
endTime
)
{
FileUtils
.
copyFile
(
it
,
File
(
logUploadDir
,
it
.
name
))
}
}
}
}
"system"
->
{
}
}
ZipUtils
.
zipFile
(
logUploadDir
,
logZipFile
)
ZipUtils
.
zipFile
(
logUploadDir
,
logZipFile
)
MainHttpClient
.
uploadLog
(
logZipFile
)
FileUtils
.
deleteDir
(
logUploadDir
)
MainHttpClient
.
uploadLog
(
logZipFile
,
"$type${formatSrc.format(endTime)}.zip"
)
state
=
State
.
INITED
}.
start
()
}.
start
()
}
catch
(
e
:
Exception
)
{}
}
catch
(
e
:
Exception
)
{}
}
}
...
...
app/src/main/java/com/bgycc/smartcanteen/server/http/CommonApi.kt
View file @
ffeca9ea
...
@@ -10,5 +10,5 @@ interface CommonApi {
...
@@ -10,5 +10,5 @@ interface CommonApi {
@Multipart
@Multipart
@POST
(
"upload"
)
@POST
(
"upload"
)
fun
upload
(
@Part
file
:
MultipartBody
.
Part
):
Call
<
CommonResponse
>
fun
upload
(
@Part
file
:
MultipartBody
.
Part
):
Call
<
String
>
}
}
\ No newline at end of file
app/src/main/java/com/bgycc/smartcanteen/server/http/MainHttpClient.kt
View file @
ffeca9ea
...
@@ -9,6 +9,7 @@ import retrofit2.Call
...
@@ -9,6 +9,7 @@ import retrofit2.Call
import
retrofit2.Response
import
retrofit2.Response
import
retrofit2.Retrofit
import
retrofit2.Retrofit
import
retrofit2.converter.gson.GsonConverterFactory
import
retrofit2.converter.gson.GsonConverterFactory
import
retrofit2.converter.scalars.ScalarsConverterFactory
import
java.io.File
import
java.io.File
import
java.util.concurrent.TimeUnit
import
java.util.concurrent.TimeUnit
...
@@ -35,18 +36,18 @@ object MainHttpClient {
...
@@ -35,18 +36,18 @@ object MainHttpClient {
mClient
=
Retrofit
.
Builder
()
mClient
=
Retrofit
.
Builder
()
.
client
(
httpBuilder
.
build
())
.
client
(
httpBuilder
.
build
())
.
baseUrl
(
AppConfig
.
getMainHttpServerHost
())
.
baseUrl
(
AppConfig
.
getMainHttpServerHost
())
.
addConverterFactory
(
Gson
ConverterFactory
.
create
())
.
addConverterFactory
(
Scalars
ConverterFactory
.
create
())
.
build
()
.
build
()
}
}
fun
uploadLog
(
file
:
File
)
{
fun
uploadLog
(
file
:
File
,
fileName
:
String
)
{
val
requestBody
=
RequestBody
.
create
(
MediaType
.
parse
(
"application/x-zip-compressed"
),
file
)
val
requestBody
=
RequestBody
.
create
(
MediaType
.
parse
(
"application/x-zip-compressed"
),
file
)
val
multipartBody
=
MultipartBody
.
Part
.
createFormData
(
"file"
,
file
.
n
ame
,
requestBody
)
val
multipartBody
=
MultipartBody
.
Part
.
createFormData
(
"file"
,
file
N
ame
,
requestBody
)
mClient
.
create
(
CommonApi
::
class
.
java
).
upload
(
multipartBody
).
enqueue
(
object
:
retrofit2
.
Callback
<
CommonResponse
>
{
mClient
.
create
(
CommonApi
::
class
.
java
).
upload
(
multipartBody
).
enqueue
(
object
:
retrofit2
.
Callback
<
String
>
{
override
fun
onFailure
(
call
:
Call
<
CommonResponse
>,
t
:
Throwable
)
{
override
fun
onFailure
(
call
:
Call
<
String
>,
t
:
Throwable
)
{
LogUtil
.
i
(
TAG
,
"onFailure"
)
LogUtil
.
i
(
TAG
,
"onFailure"
)
}
}
override
fun
onResponse
(
call
:
Call
<
CommonResponse
>,
response
:
Response
<
CommonResponse
>)
{
override
fun
onResponse
(
call
:
Call
<
String
>,
response
:
Response
<
String
>)
{
LogUtil
.
i
(
TAG
,
"onResponse"
)
LogUtil
.
i
(
TAG
,
"onResponse"
)
}
}
})
})
...
...
app/src/main/java/com/bgycc/smartcanteen/server/websocket/MainWebSocket.java
View file @
ffeca9ea
...
@@ -5,6 +5,7 @@ import com.bgycc.smartcanteen.App;
...
@@ -5,6 +5,7 @@ import com.bgycc.smartcanteen.App;
import
com.bgycc.smartcanteen.AppConfig
;
import
com.bgycc.smartcanteen.AppConfig
;
import
com.bgycc.smartcanteen.BuildConfig
;
import
com.bgycc.smartcanteen.BuildConfig
;
import
com.bgycc.smartcanteen.action.ActionEnum
;
import
com.bgycc.smartcanteen.action.ActionEnum
;
import
com.bgycc.smartcanteen.action.LogAction
;
import
com.bgycc.smartcanteen.action.UpdateAction
;
import
com.bgycc.smartcanteen.action.UpdateAction
;
import
com.bgycc.smartcanteen.helper.TimerHelper
;
import
com.bgycc.smartcanteen.helper.TimerHelper
;
import
com.bgycc.smartcanteen.manager.NetworkManager
;
import
com.bgycc.smartcanteen.manager.NetworkManager
;
...
@@ -207,6 +208,12 @@ public class MainWebSocket extends WebSocketClient {
...
@@ -207,6 +208,12 @@ public class MainWebSocket extends WebSocketClient {
UpdateAction
.
Companion
.
getDefault
().
exec
(
data
);
UpdateAction
.
Companion
.
getDefault
().
exec
(
data
);
return
;
return
;
}
}
// 拉取日志
else
if
(
ActionEnum
.
LOG_PULL
.
name
().
equals
(
action
))
{
JSONObject
data
=
json
.
optJSONObject
(
FieldEnum
.
data
.
name
());
LogAction
.
INSTANCE
.
exec
(
data
);
return
;
}
ArrayList
<
Response
>
list
=
mSubscribeList
.
get
(
action
);
ArrayList
<
Response
>
list
=
mSubscribeList
.
get
(
action
);
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
if
(
list
!=
null
&&
list
.
size
()
>
0
)
{
...
...
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