diff --git a/.gradle/5.6.4/executionHistory/executionHistory.bin b/.gradle/5.6.4/executionHistory/executionHistory.bin index 529e7ae..f379318 100644 Binary files a/.gradle/5.6.4/executionHistory/executionHistory.bin and b/.gradle/5.6.4/executionHistory/executionHistory.bin differ diff --git a/.gradle/5.6.4/executionHistory/executionHistory.lock b/.gradle/5.6.4/executionHistory/executionHistory.lock index 5c70734..4afaf1c 100644 Binary files a/.gradle/5.6.4/executionHistory/executionHistory.lock and b/.gradle/5.6.4/executionHistory/executionHistory.lock differ diff --git a/.gradle/5.6.4/fileHashes/fileHashes.bin b/.gradle/5.6.4/fileHashes/fileHashes.bin index ec8bfe6..d4d6138 100644 Binary files a/.gradle/5.6.4/fileHashes/fileHashes.bin and b/.gradle/5.6.4/fileHashes/fileHashes.bin differ diff --git a/.gradle/5.6.4/fileHashes/fileHashes.lock b/.gradle/5.6.4/fileHashes/fileHashes.lock index 7101c09..fcdb59e 100644 Binary files a/.gradle/5.6.4/fileHashes/fileHashes.lock and b/.gradle/5.6.4/fileHashes/fileHashes.lock differ diff --git a/.gradle/5.6.4/fileHashes/resourceHashesCache.bin b/.gradle/5.6.4/fileHashes/resourceHashesCache.bin index 755763f..61fef57 100644 Binary files a/.gradle/5.6.4/fileHashes/resourceHashesCache.bin and b/.gradle/5.6.4/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/5.6.4/javaCompile/classAnalysis.bin b/.gradle/5.6.4/javaCompile/classAnalysis.bin index 5b4da22..23bc3b9 100644 Binary files a/.gradle/5.6.4/javaCompile/classAnalysis.bin and b/.gradle/5.6.4/javaCompile/classAnalysis.bin differ diff --git a/.gradle/5.6.4/javaCompile/jarAnalysis.bin b/.gradle/5.6.4/javaCompile/jarAnalysis.bin index 96bc1fa..351c9ce 100644 Binary files a/.gradle/5.6.4/javaCompile/jarAnalysis.bin and b/.gradle/5.6.4/javaCompile/jarAnalysis.bin differ diff --git a/.gradle/5.6.4/javaCompile/javaCompile.lock b/.gradle/5.6.4/javaCompile/javaCompile.lock index ea283a8..d99cb8d 100644 Binary files a/.gradle/5.6.4/javaCompile/javaCompile.lock and b/.gradle/5.6.4/javaCompile/javaCompile.lock differ diff --git a/.gradle/5.6.4/javaCompile/taskHistory.bin b/.gradle/5.6.4/javaCompile/taskHistory.bin index baaa6b0..7e4bb0f 100644 Binary files a/.gradle/5.6.4/javaCompile/taskHistory.bin and b/.gradle/5.6.4/javaCompile/taskHistory.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 0382d85..cd2c6c3 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/app/src/main/java/cn/trans88/taxiappkotlin/ledok/HttpServer.kt b/app/src/main/java/cn/trans88/taxiappkotlin/ledok/HttpServer.kt index 07c6ff7..592c7fc 100644 --- a/app/src/main/java/cn/trans88/taxiappkotlin/ledok/HttpServer.kt +++ b/app/src/main/java/cn/trans88/taxiappkotlin/ledok/HttpServer.kt @@ -29,19 +29,4 @@ class HttpServer { server.listen(3389) Log.d(TAG, "run: httpServer start... listen 3389") } - - private fun getJSONFromReq(req: AsyncHttpServerRequest): JSONObject? { - var obj: JSONObject? = null - val body = req.getBody>() - if (body is JSONObjectBody) { - obj = body.get() - } else if (body is StringBody) { - try { - obj = JSONObject(body.get()) - } catch (e: JSONException) { - e.printStackTrace() - } - } - return obj - } } \ No newline at end of file diff --git a/app/src/main/java/cn/trans88/taxiappkotlin/ledok/TaskSocketServer.kt b/app/src/main/java/cn/trans88/taxiappkotlin/ledok/TaskSocketServer.kt index c2b2568..80ce093 100644 --- a/app/src/main/java/cn/trans88/taxiappkotlin/ledok/TaskSocketServer.kt +++ b/app/src/main/java/cn/trans88/taxiappkotlin/ledok/TaskSocketServer.kt @@ -73,7 +73,7 @@ class TaskSocketServer(private val context: Context, port: Int) { try { //只保持一个链接,新的进来就把老的断开 val socket = soc!!.accept() - socket.soTimeout = 5000 * 5 + socket.soTimeout = 5000 if (client != null) { client!!.close() } diff --git a/app/src/main/java/cn/trans88/taxiappkotlin/net/EasyHttpTool.kt b/app/src/main/java/cn/trans88/taxiappkotlin/net/EasyHttpTool.kt index e869ba2..d7c8d84 100644 --- a/app/src/main/java/cn/trans88/taxiappkotlin/net/EasyHttpTool.kt +++ b/app/src/main/java/cn/trans88/taxiappkotlin/net/EasyHttpTool.kt @@ -19,7 +19,6 @@ import okhttp3.RequestBody import com.zhouyou.http.callback.SimpleCallBack import com.zhouyou.http.exception.ApiException import okhttp3.Request -import java.util.concurrent.CountDownLatch /** @@ -29,49 +28,52 @@ import java.util.concurrent.CountDownLatch * @description: */ object EasyHttpTool { + val TAG = this.javaClass.simpleName /** * 提交运行时长 * @param runtimeJson String */ - lateinit var latch: CountDownLatch - var isSendSuccess = false +// lateinit var latch: CountDownLatch +// var isSendSuccess = false fun sendRunTimeToServer(runtimeJson: String) { "sendRunTimeToServer run".logd() - latch = CountDownLatch(1) +// latch = CountDownLatch(1) sendRuntimeToServerRequest(runtimeJson) - Thread { - latch.await() - var count = 10 - // 网络可用时每一分钟发一次请求 - while (!isSendSuccess && count > 0) { - latch = CountDownLatch(1) - sendRuntimeToServerRequest(runtimeJson) - Log.d("EasyHttpTool", "sendRunTimeToServer: 重发次数${count}") - latch.await() - count--; - Thread.sleep(1000 * 60) - } - // 网络不可用时监听网络状态是否发送请求 - if (!isSendSuccess) { - var isRunning = true - while (isRunning) { - val networkAvailable = NetworkChangeReceiver.isNetworkAvailable - if (networkAvailable) { - latch = CountDownLatch(1) - sendRuntimeToServerRequest(runtimeJson) - Log.d("EasyHttpTool", "sendRunTimeToServer: 重发网络${networkAvailable}") - latch.await() - if (isSendSuccess) { - isRunning = false - } - } - Thread.sleep(1000 * 60) - } - } - }.start() + +// Thread { +// latch.await() +// var count = 10 +// // 网络可用时每一分钟发一次请求 +// while (!isSendSuccess && count > 0) { +// latch = CountDownLatch(1) +// sendRuntimeToServerRequest(runtimeJson) +// Log.d("EasyHttpTool", "sendRunTimeToServer: 重发次数${count}") +// latch.await() +// count--; +// Thread.sleep(1000 * 60) +// } +// // 网络不可用时监听网络状态是否发送请求 +// if (!isSendSuccess) { +// var isRunning = true +// while (isRunning) { +// val networkAvailable = NetworkChangeReceiver.isNetworkAvailable +// if (networkAvailable) { +// latch = CountDownLatch(1) +// sendRuntimeToServerRequest(runtimeJson) +// Log.d("EasyHttpTool", "sendRunTimeToServer: 重发网络${networkAvailable}") +// latch.await() +// if (isSendSuccess) { +// isRunning = false +// } +// } +// Thread.sleep(1000 * 60) +// } +// } +// }.start() } + fun sendRuntimeToServerRequest(runtimeJson: String) { Log.d("EasyHttpTool", "sendRuntimeToServerRequest: ") val parse = ("application/json;charset=UTF-8").toMediaTypeOrNull() @@ -93,14 +95,14 @@ object EasyHttpTool { .execute(object : SimpleCallBack() { override fun onError(e: ApiException?) { "上传运行时长失败:${e?.message}".loge() - isSendSuccess = false - latch.countDown() +// isSendSuccess = false +// latch.countDown() } override fun onSuccess(t: String?) { "上传运行时长成功:${t}".loge() - isSendSuccess = true - latch.countDown() +// isSendSuccess = true +// latch.countDown() } }) } @@ -109,16 +111,51 @@ object EasyHttpTool { /** * 提交运行时长 */ + private const val retryInterval: Long = 1000 * 60 +// private const val retryInterval: Long = 1000 fun sendRunTimeToServer() { val sumTimeList = DaoUtil.getRunTimeDao().queryBuilder().where( RunTimeDataDao.Properties.IsUpload.eq(0) ).list() - "未提交的运行时长数量sumTimeList size: ${sumTimeList?.size}".logd() +// "未提交的运行时长数量sumTimeList size: ${sumTimeList?.size}".logd() + Log.d(TAG, "sendRunTimeToServer: 未提交的运行时长数量: ${sumTimeList?.size}") if (!sumTimeList.isNullOrEmpty()) { - for (runTimeData in sumTimeList) { - - sendRunLogToServer(runTimeData) + Thread { + var isSendSuccess = sendRunLogToServer(runTimeData) + var count = 10 + // 是否需要重发 + // 网络可用时每一分钟发一次请求 + while (!isSendSuccess && count > 0) { + isSendSuccess = sendRunLogToServer(runTimeData) + Log.d(TAG, "sendRunTimeToServer: 重发次数${11 - count}") + if (isSendSuccess) { + Log.d(TAG, "sendRunTimeToServer: 发送成功 重发次数${11 - count}") + } + count--; + Thread.sleep(retryInterval) + } + // 网络不可用时监听网络状态是否发送请求 + if (!isSendSuccess) { + var isRunning = true + while (isRunning) { + var available = NetworkChangeReceiver.isNetworkAvailable + Log.d(TAG, "sendRunTimeToServer: 重发网络$available") + if (available) { + isSendSuccess = sendRunLogToServer(runTimeData) + if (isSendSuccess) { + isRunning = false + Log.d(TAG, "sendRunTimeToServer: 发送成功重发网络$available") + } + } + Thread.sleep(retryInterval) + } + } + Log.d( + "EasyHttpTool", + "sendRunTimeToServer: 运行日志发送成功${runTimeData.cardId}" + ) + }.start() // val runtimeJson = RuntimeJson(runTimeData.cardId,runTimeData.sumRuntime,runTimeData.startRuntime) // val runtimeJsonStr = Gson().toJson(runtimeJson) @@ -163,7 +200,7 @@ object EasyHttpTool { /** * 上传1条运行日志 */ - fun sendRunLogToServer(runTimeData: RunTimeData) { + fun sendRunLogToServer(runTimeData: RunTimeData): Boolean { // val logJson = ProcessingCommands.gson.toJson(dbPlayerLogs) val runtimeJson = RuntimeJson(runTimeData.cardId, runTimeData.sumRuntime, runTimeData.startRuntime) @@ -191,11 +228,14 @@ object EasyHttpTool { runTimeData.isUpload = 1 DaoUtil.getRunTimeDao().update(runTimeData) "将提交的runTimeData标记成已上传".logd() + return true } else { "上传运行时长失败".loge() + return false } } catch (e: Exception) { "上传运行时长失败:${e?.message}".loge() + return false } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index cd46572..95f1ac9 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,6 +1,6 @@ - TaxiApp - + + VehiclePlayer TopLevelActivity