优化运行日志上传

This commit is contained in:
刘金华 2024-06-29 16:35:58 +08:00
parent 37924fa2b5
commit 421517c248
19 changed files with 78 additions and 33 deletions

View File

@ -1,2 +1,2 @@
#Mon Mar 04 15:33:52 GMT+08:00 2024
#Tue Jun 25 17:25:11 GMT+08:00 2024
gradle.version=5.6.4

View File

@ -21,8 +21,8 @@ android {
applicationId "net.sysolution.taxiapp"
minSdkVersion 21
targetSdkVersion 29
versionCode 256
versionName "3.3.3-beta26.4.1.5-release"
versionCode 257
versionName "3.3.3-beta26.4.1.4-release"
//alphaxx - ,bug
//Betaxx -

View File

@ -256,11 +256,13 @@ object ProcessingCommands {
// val endRuntime = Configurations.config(TaxiApp.instance()).endRunTime()
val todaySumRunTime = Configurations.config(TaxiApp.instance()).todaySumRunTime()
"getTodayRuntime-->当天taxiApp运行时间$todaySumRunTime".logd()
// val sumTimeList = DaoUtil.getRunTimeDao().queryBuilder().where(
// RunTimeDataDao.Properties.IsUpload.eq(0)).list()
sanleResponse.type = type
sanleResponse.id = baseResponse.id
sanleResponse.task_id = baseResponse.task_id
sanleResponse.runtime = todaySumRunTime
// sanleResponse.runtime = sumTimeList.size.toLong()
val response = gson.toJson(sanleResponse)
send(response)
}

View File

@ -69,32 +69,36 @@ object EasyHttpTool {
if (!sumTimeList.isNullOrEmpty()){
for (runTimeData in sumTimeList) {
val runtimeJson = RuntimeJson(runTimeData.cardId,runTimeData.sumRuntime,runTimeData.startRuntime)
val runtimeJsonStr = Gson().toJson(runtimeJson)
"提交运行时长sendRunTimeToServer$runtimeJsonStr".logd()
val parse = ("application/json;charset=UTF-8").toMediaTypeOrNull()
val body = RequestBody.create(parse, runtimeJsonStr)
EasyHttp.post(Configurations.config(TaxiApp.instance()).logServiceUrl() + "postRunningTimeLog")
.readTimeOut(80*1000)
.writeTimeOut(80*1000)
.connectTimeout(80*1000)
.headers("Authorization", "Bearer ${Configurations.config(TaxiApp.instance()).appToken()}")
.headers("Accept-Encoding", "gzip")
.requestBody(body)
.retryCount(1)//本次请求重试次数
.retryDelay(1000)//本次请求重试延迟时间1000ms
.execute(object :SimpleCallBack<String>(){
override fun onError(e: ApiException?) {
"上传运行时长失败:${e?.message}".loge()
}
override fun onSuccess(t: String?) {
"上传运行时长成功:${t}".loge()
runTimeData.isUpload = 1
DaoUtil.getRunTimeDao().update(runTimeData)
"将提交的runTimeData标记成已上传".logd()
}
})
sendRunLogToServer(runTimeData)
// val runtimeJson = RuntimeJson(runTimeData.cardId,runTimeData.sumRuntime,runTimeData.startRuntime)
// val runtimeJsonStr = Gson().toJson(runtimeJson)
// "提交运行时长sendRunTimeToServer$runtimeJsonStr".logd()
// val parse = ("application/json;charset=UTF-8").toMediaTypeOrNull()
// val body = RequestBody.create(parse, runtimeJsonStr)
// EasyHttp.post(Configurations.config(TaxiApp.instance()).logServiceUrl() + "postRunningTimeLog")
// .readTimeOut(80*1000)
// .writeTimeOut(80*1000)
// .connectTimeout(80*1000)
// .headers("Authorization", "Bearer ${Configurations.config(TaxiApp.instance()).appToken()}")
// .headers("Accept-Encoding", "gzip")
// .requestBody(body)
// .retryCount(1)//本次请求重试次数
// .retryDelay(1000)//本次请求重试延迟时间1000ms
// .execute(object :SimpleCallBack<String>(){
// override fun onError(e: ApiException?) {
// "上传运行时长失败:${e?.message}".loge()
// }
//
// override fun onSuccess(t: String?) {
// "上传运行时长成功:${t}".loge()
// runTimeData.isUpload = 1
// DaoUtil.getRunTimeDao().update(runTimeData)
// "将提交的runTimeData标记成已上传".logd()
// }
// })
}
// val lists:List<RuntimeJson> = sumTimeList.map {
@ -108,6 +112,42 @@ object EasyHttpTool {
}
/**
* 上传1条运行日志
*/
fun sendRunLogToServer(runTimeData:RunTimeData){
// val logJson = ProcessingCommands.gson.toJson(dbPlayerLogs)
val runtimeJson = RuntimeJson(runTimeData.cardId,runTimeData.sumRuntime,runTimeData.startRuntime)
val runtimeJsonStr = Gson().toJson(runtimeJson)
"提交运行时长sendRunTimeToServer$runtimeJsonStr".logd()
val parse = ("application/json;charset=UTF-8").toMediaTypeOrNull()
val body = RequestBody.create(parse, runtimeJsonStr)
val url = Configurations.config(TaxiApp.instance()).logServiceUrl() + "postRunningTimeLog"
try {
val request = Request.Builder()
.url(url)
.addHeader("Authorization","Bearer ${Configurations.config(TaxiApp.instance()).appToken()}")
.addHeader("Accept-Encoding","gzip")
.post(body)
.build()
val response = OkHttpTool.getInstance().client.newCall(request).execute()
"response code:${response?.code}".logd()
"response body:${response?.body?.string().toString()}".logd()
if (response.isSuccessful){
"上传运行时长成功".loge()
runTimeData.isUpload = 1
DaoUtil.getRunTimeDao().update(runTimeData)
"将提交的runTimeData标记成已上传".logd()
} else {
"上传运行时长失败".loge()
}
} catch (e: Exception) {
"上传运行时长失败:${e?.message}".loge()
}
}
/**
* 提交日志摘要
@ -229,4 +269,5 @@ object EasyHttpTool {
// })
}
}

View File

@ -236,14 +236,16 @@ class PlayActivity : AppCompatActivity(), NetworkCallback, BusCallback, OnScreen
DaoUtil.getRunTimeDao().insert(runTimeData)
}
//提交未上传的运行时长数据
EasyHttpTool.sendRunTimeToServer()
//重新初始化startRunTime为当前启动时间,sumRuntime为0
configurations.startRunTimeSave(currentTime)
configurations.sumRunTimeSave(0)
//开启定时器让sumRunTime累加
startSaveSumTimer()
//提交未上传的运行时长数据
EasyHttpTool.sendRunTimeToServer()
//跳出循环
break
} else {

View File

@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Tue May 21 14:20:34 GMT+08:00 2024
#Tue Jun 25 17:11:45 GMT+08:00 2024
sdk.dir=D\:\\Android\\sdk

View File

@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":256,"versionName":"3.3.3-beta26.4.1.5-release","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.4.1.5-release{256}.apk","fullName":"release","baseName":"release","dirName":""},"path":"TaxiApp_v3.3.3-beta26.4.1.5-release{256}.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":257,"versionName":"3.3.3-beta26.4.1.4-release","enabled":true,"outputFile":"TaxiApp_v3.3.3-beta26.4.1.4-release{257}.apk","fullName":"release","baseName":"release","dirName":""},"path":"TaxiApp_v3.3.3-beta26.4.1.4-release{257}.apk","properties":{}}]