desc:请求网络崩溃问题

main
xiaowusky 1 year ago
parent ff1c62092d
commit 5294403b34

@ -43,17 +43,32 @@ class DevicesApi : BaseObserve<DevicesApi.Api>(Api::class.java) {
suspend fun uploadGasData( suspend fun uploadGasData(
gasList: List<GasReqBean> = emptyList() gasList: List<GasReqBean> = emptyList()
): BaseResponse { ): BaseResponse? {
val gasReq = GasRequest(detections = gasList) try {
return api.uploadGasData(gasReq) val gasReq = GasRequest(detections = gasList)
return api.uploadGasData(gasReq)
} catch (e: Exception) {
e.printStackTrace()
}
return null
} }
suspend fun getDetectionLastTime() : LastTimeResponse{ suspend fun getDetectionLastTime(): LastTimeResponse? {
return api.getDetectionLastTime(LztekUtil.getSn()) try {
return api.getDetectionLastTime(LztekUtil.getSn())
} catch (e: Exception) {
e.printStackTrace()
}
return null
} }
suspend fun getVideoLastTime(): LastTimeResponse { suspend fun getVideoLastTime(): LastTimeResponse? {
return api.getVideoLastTime(LztekUtil.getSn()) try {
return api.getVideoLastTime(LztekUtil.getSn())
} catch (e: Exception) {
e.printStackTrace()
}
return null
} }
interface Api { interface Api {

@ -93,13 +93,13 @@ class CloudActivity : NoOptionsActivity() {
uploadingVideo.set(true) uploadingVideo.set(true)
// 1.拿到云端最新数据时间 // 1.拿到云端最新数据时间
val timeResponse = devicesApi.getVideoLastTime() val timeResponse = devicesApi.getVideoLastTime()
if (timeResponse.isOk()) { if (timeResponse?.isOk() == true) {
val cloudTime = timeResponse.data val cloudTime = timeResponse.data
// 2. 拿到待上传文件列表 上传 // 2. 拿到待上传文件列表 上传
getFileListAndUpload(cloudTime) getFileListAndUpload(cloudTime)
LogUtils.v("uploadVideo ok") LogUtils.v("uploadVideo ok")
} else { } else {
LogUtils.e("getVideoLastTime error code = ${timeResponse.code}") LogUtils.e("getVideoLastTime error code = ${timeResponse?.code}")
} }
uploadingVideo.set(false) uploadingVideo.set(false)
} }
@ -110,14 +110,14 @@ class CloudActivity : NoOptionsActivity() {
uploadingGas.set(true) uploadingGas.set(true)
// 1.拿到云端最新数据时间 // 1.拿到云端最新数据时间
val lastTimeResponse = devicesApi.getDetectionLastTime() val lastTimeResponse = devicesApi.getDetectionLastTime()
if (lastTimeResponse.isOk()) { if (lastTimeResponse?.isOk() == true) {
val cloudTime = lastTimeResponse.data val cloudTime = lastTimeResponse.data
// 2. 查询本地数据库中该时间之后的数据 // 2. 查询本地数据库中该时间之后的数据
// 3. 上传数据给服务器 // 3. 上传数据给服务器
getSensorDataUpload(cloudTime) getSensorDataUpload(cloudTime)
LogUtils.v("uploadSensorData ok") LogUtils.v("uploadSensorData ok")
} else { } else {
LogUtils.e("getVideoLastTime error code = ${lastTimeResponse.code}") LogUtils.e("getVideoLastTime error code = ${lastTimeResponse?.code}")
} }
uploadingGas.set(false) uploadingGas.set(false)
} }
@ -132,7 +132,7 @@ class CloudActivity : NoOptionsActivity() {
tempReqList.add(GasReqBean(it)) tempReqList.add(GasReqBean(it))
if (tempList.size == GAS_CLOUD_UPLOAD_SIZE_ONCE) { if (tempList.size == GAS_CLOUD_UPLOAD_SIZE_ONCE) {
val response = devicesApi.uploadGasData(tempReqList) val response = devicesApi.uploadGasData(tempReqList)
if (response.isOk()) { if (response?.isOk() == true) {
val gasDao = DBUtils.gasDao() val gasDao = DBUtils.gasDao()
tempList.forEach { gas -> tempList.forEach { gas ->
gas.syncFlag = true gas.syncFlag = true
@ -145,7 +145,7 @@ class CloudActivity : NoOptionsActivity() {
} }
if (tempList.isNotEmpty()) { if (tempList.isNotEmpty()) {
val response = devicesApi.uploadGasData(tempReqList) val response = devicesApi.uploadGasData(tempReqList)
if (response.isOk()) { if (response?.isOk() == true) {
val gasDao = DBUtils.gasDao() val gasDao = DBUtils.gasDao()
tempList.forEach { tempList.forEach {
it.syncFlag = true it.syncFlag = true

Loading…
Cancel
Save