Commit ffeca9ea by patpat

日志拉取

parent 3ea9b03b
......@@ -73,6 +73,7 @@ dependencies {
implementation 'com.squareup.okhttp3:logging-interceptor:3.10.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
implementation 'com.squareup.retrofit2:converter-gson:2.6.0'
implementation 'com.squareup.retrofit2:converter-scalars:2.6.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
......
......@@ -13,8 +13,8 @@ object AppConfig {
fun getMainWebSocketServerHost(): String {
return when (SERVER) {
Server.DEV -> "10.187.43.221"
Server.TEST -> "diningservicetest.bgy.com.cn"
Server.DEV -> "10.187.43.221:9001"
Server.TEST -> "diningservicetest.bgy.com.cn:9001"
Server.UAT -> "diningserviceuat.bgy.com.cn"
else -> "diningservice.bgy.com.cn"
}
......@@ -22,8 +22,8 @@ object AppConfig {
fun getMainWebSocketServerUrl(id: String, version: String): String {
return when (SERVER) {
Server.DEV -> "ws://${getMainWebSocketServerHost()}:9001/websocket/$id/V$version"
Server.TEST -> "ws://${getMainWebSocketServerHost()}:9001/websocket/$id/V$version"
Server.DEV -> "ws://${getMainWebSocketServerHost()}/websocket/$id/V$version"
Server.TEST -> "ws://${getMainWebSocketServerHost()}/websocket/$id/V$version"
Server.UAT -> "wss://${getMainWebSocketServerHost()}/websocket/$id/V$version"
else -> "wss://${getMainWebSocketServerHost()}/websocket/$id/V$version"
}
......@@ -32,7 +32,7 @@ object AppConfig {
fun getMainHttpServerHost(): String {
return when (SERVER) {
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"
else -> "http://diningback.bgy.com.cn"
}
......
......@@ -24,7 +24,13 @@ object LogAction : Action(ActionEnum.LOG_PULL.name) {
val formatSrc = SimpleDateFormat("yyyy-MM-dd", Locale.getDefault())
val type = data.getString("logType")
val startTime = formatSrc.parse(data.getString("startTime"))
startTime.hours = 0
startTime.minutes = 0
startTime.seconds = 0
val endTime = formatSrc.parse(data.getString("endTime"))
endTime.hours = 23
endTime.minutes = 59
endTime.seconds = 59
if (startTime > endTime) return
val formatDst = SimpleDateFormat("yyyy_MM_dd", Locale.getDefault())
......@@ -44,23 +50,20 @@ object LogAction : Action(ActionEnum.LOG_PULL.name) {
FileUtils.deleteDir(logUploadDir)
logUploadDir.mkdirs()
when (type) {
"app" -> {
val logDir = 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))
}
}
}
"system" -> {
val logDir = when (type) {
"system" -> File(PathUtils.getExternalStoragePath(), "boot_log")
else -> File(PathUtils.getExternalAppCachePath(), "log")
}
FileUtils.listFilesInDir(logDir).forEach {
val date = Date(it.lastModified())
if (date >= startTime && date <= endTime) {
FileUtils.copyFile(it, File(logUploadDir, it.name))
}
}
ZipUtils.zipFile(logUploadDir, logZipFile)
MainHttpClient.uploadLog(logZipFile)
FileUtils.deleteDir(logUploadDir)
MainHttpClient.uploadLog(logZipFile, "$type${formatSrc.format(endTime)}.zip")
state = State.INITED
}.start()
} catch (e: Exception) {}
}
......
......@@ -10,5 +10,5 @@ interface CommonApi {
@Multipart
@POST("upload")
fun upload(@Part file: MultipartBody.Part): Call<CommonResponse>
fun upload(@Part file: MultipartBody.Part): Call<String>
}
\ No newline at end of file
......@@ -9,6 +9,7 @@ import retrofit2.Call
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import retrofit2.converter.scalars.ScalarsConverterFactory
import java.io.File
import java.util.concurrent.TimeUnit
......@@ -35,18 +36,18 @@ object MainHttpClient {
mClient = Retrofit.Builder()
.client(httpBuilder.build())
.baseUrl(AppConfig.getMainHttpServerHost())
.addConverterFactory(GsonConverterFactory.create())
.addConverterFactory(ScalarsConverterFactory.create())
.build()
}
fun uploadLog(file: File) {
fun uploadLog(file: File, fileName: String) {
val requestBody = RequestBody.create(MediaType.parse("application/x-zip-compressed"), file)
val multipartBody = MultipartBody.Part.createFormData("file", file.name, requestBody)
mClient.create(CommonApi::class.java).upload(multipartBody).enqueue(object : retrofit2.Callback<CommonResponse> {
override fun onFailure(call: Call<CommonResponse>, t: Throwable) {
val multipartBody = MultipartBody.Part.createFormData("file", fileName, requestBody)
mClient.create(CommonApi::class.java).upload(multipartBody).enqueue(object : retrofit2.Callback<String> {
override fun onFailure(call: Call<String>, t: Throwable) {
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")
}
})
......
......@@ -5,6 +5,7 @@ import com.bgycc.smartcanteen.App;
import com.bgycc.smartcanteen.AppConfig;
import com.bgycc.smartcanteen.BuildConfig;
import com.bgycc.smartcanteen.action.ActionEnum;
import com.bgycc.smartcanteen.action.LogAction;
import com.bgycc.smartcanteen.action.UpdateAction;
import com.bgycc.smartcanteen.helper.TimerHelper;
import com.bgycc.smartcanteen.manager.NetworkManager;
......@@ -207,6 +208,12 @@ public class MainWebSocket extends WebSocketClient {
UpdateAction.Companion.getDefault().exec(data);
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);
if (list != null && list.size() > 0) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment