From 5294403b3438b4efd2bc07fc9ec0364546f94286 Mon Sep 17 00:00:00 2001 From: xiaowusky Date: Wed, 6 Dec 2023 15:32:44 +0800 Subject: [PATCH] =?UTF-8?q?desc:=E8=AF=B7=E6=B1=82=E7=BD=91=E7=BB=9C?= =?UTF-8?q?=E5=B4=A9=E6=BA=83=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../safetywatcher/watcher/net/DevicesApi.kt | 29 ++++++++++++++----- .../safetywatcher/watcher/ui/CloudActivity.kt | 12 ++++---- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/net/DevicesApi.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/net/DevicesApi.kt index ec896d3..956a034 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/net/DevicesApi.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/net/DevicesApi.kt @@ -43,17 +43,32 @@ class DevicesApi : BaseObserve(Api::class.java) { suspend fun uploadGasData( gasList: List = emptyList() - ): BaseResponse { - val gasReq = GasRequest(detections = gasList) - return api.uploadGasData(gasReq) + ): BaseResponse? { + try { + val gasReq = GasRequest(detections = gasList) + return api.uploadGasData(gasReq) + } catch (e: Exception) { + e.printStackTrace() + } + return null } - suspend fun getDetectionLastTime() : LastTimeResponse{ - return api.getDetectionLastTime(LztekUtil.getSn()) + suspend fun getDetectionLastTime(): LastTimeResponse? { + try { + return api.getDetectionLastTime(LztekUtil.getSn()) + } catch (e: Exception) { + e.printStackTrace() + } + return null } - suspend fun getVideoLastTime(): LastTimeResponse { - return api.getVideoLastTime(LztekUtil.getSn()) + suspend fun getVideoLastTime(): LastTimeResponse? { + try { + return api.getVideoLastTime(LztekUtil.getSn()) + } catch (e: Exception) { + e.printStackTrace() + } + return null } interface Api { diff --git a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt index 74da8e3..b5cf38a 100644 --- a/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt +++ b/app/src/main/java/com/yinuo/safetywatcher/watcher/ui/CloudActivity.kt @@ -93,13 +93,13 @@ class CloudActivity : NoOptionsActivity() { uploadingVideo.set(true) // 1.拿到云端最新数据时间 val timeResponse = devicesApi.getVideoLastTime() - if (timeResponse.isOk()) { + if (timeResponse?.isOk() == true) { val cloudTime = timeResponse.data // 2. 拿到待上传文件列表 上传 getFileListAndUpload(cloudTime) LogUtils.v("uploadVideo ok") } else { - LogUtils.e("getVideoLastTime error code = ${timeResponse.code}") + LogUtils.e("getVideoLastTime error code = ${timeResponse?.code}") } uploadingVideo.set(false) } @@ -110,14 +110,14 @@ class CloudActivity : NoOptionsActivity() { uploadingGas.set(true) // 1.拿到云端最新数据时间 val lastTimeResponse = devicesApi.getDetectionLastTime() - if (lastTimeResponse.isOk()) { + if (lastTimeResponse?.isOk() == true) { val cloudTime = lastTimeResponse.data // 2. 查询本地数据库中该时间之后的数据 // 3. 上传数据给服务器 getSensorDataUpload(cloudTime) LogUtils.v("uploadSensorData ok") } else { - LogUtils.e("getVideoLastTime error code = ${lastTimeResponse.code}") + LogUtils.e("getVideoLastTime error code = ${lastTimeResponse?.code}") } uploadingGas.set(false) } @@ -132,7 +132,7 @@ class CloudActivity : NoOptionsActivity() { tempReqList.add(GasReqBean(it)) if (tempList.size == GAS_CLOUD_UPLOAD_SIZE_ONCE) { val response = devicesApi.uploadGasData(tempReqList) - if (response.isOk()) { + if (response?.isOk() == true) { val gasDao = DBUtils.gasDao() tempList.forEach { gas -> gas.syncFlag = true @@ -145,7 +145,7 @@ class CloudActivity : NoOptionsActivity() { } if (tempList.isNotEmpty()) { val response = devicesApi.uploadGasData(tempReqList) - if (response.isOk()) { + if (response?.isOk() == true) { val gasDao = DBUtils.gasDao() tempList.forEach { it.syncFlag = true