实现了双屏摄像头显示,添加了部分代码
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
package com.sw.dualscreen.repository
|
||||
|
||||
import com.google.gson.JsonParseException
|
||||
import com.sw.dualscreen.model.response.ApiResponse
|
||||
import retrofit2.HttpException
|
||||
import timber.log.Timber
|
||||
import java.io.IOException
|
||||
import java.net.ConnectException
|
||||
import java.net.SocketTimeoutException
|
||||
import javax.net.ssl.SSLHandshakeException
|
||||
|
||||
abstract class BaseRepository {
|
||||
suspend fun <T> safeApiCall(apiCall: suspend () -> ApiResponse<T>): ApiResponse<T> {
|
||||
return try {
|
||||
apiCall()
|
||||
} catch (e: Exception) {
|
||||
Timber.e("safeApiCall Exception: ${e.stackTraceToString()}")
|
||||
|
||||
when (e) {
|
||||
is HttpException -> {
|
||||
ApiResponse(code = e.code(), message = e.message())
|
||||
}
|
||||
|
||||
is SocketTimeoutException -> {
|
||||
ApiResponse(code = -2, message = "请求超时: ${e.message}")
|
||||
}
|
||||
|
||||
is ConnectException -> {
|
||||
ApiResponse(code = -3, message = "连接失败: ${e.message}")
|
||||
}
|
||||
|
||||
is SSLHandshakeException -> {
|
||||
ApiResponse(code = -4, message = "SSL握手失败: ${e.message}")
|
||||
}
|
||||
|
||||
is JsonParseException -> {
|
||||
ApiResponse(code = -5, message = "JSON解析错误: ${e.message}")
|
||||
}
|
||||
|
||||
is IOException -> {
|
||||
ApiResponse(code = -6, message = "网络IO错误: ${e.message}")
|
||||
}
|
||||
|
||||
else -> {
|
||||
ApiResponse(code = -1, message = "未知错误: ${e.message ?: "无错误信息"}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package com.sw.dualscreen.repository
|
||||
|
||||
import com.sw.dualscreen.GlobalData
|
||||
import com.sw.dualscreen.model.request.UserNutritionParam
|
||||
import com.sw.dualscreen.model.response.ApiResponse
|
||||
import com.sw.dualscreen.model.response.EquipmentInfo
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
import com.sw.dualscreen.model.response.NutritionData
|
||||
import com.sw.dualscreen.model.response.UserFaceInfo
|
||||
import com.sw.dualscreen.network.api.ApiService
|
||||
|
||||
/**
|
||||
* 远程数据处理
|
||||
*/
|
||||
class RemoteRepository constructor(
|
||||
private val apiService: ApiService
|
||||
) : BaseRepository() {
|
||||
/**
|
||||
* 生成token
|
||||
*/
|
||||
suspend fun getDeviceToken(qrcodeId: String): ApiResponse<String> {
|
||||
return safeApiCall {
|
||||
apiService.getDeviceToken(
|
||||
qrcodeId
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取设备信息
|
||||
*/
|
||||
suspend fun getDeviceInfo(equipmentCode: String, token: String): ApiResponse<EquipmentInfo> {
|
||||
return safeApiCall {
|
||||
apiService.getDeviceInfo(
|
||||
equipmentCode,
|
||||
token = token
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取业务服务器token
|
||||
*/
|
||||
suspend fun getEquipmentToken(qrcodeId: String): ApiResponse<String> {
|
||||
return safeApiCall {
|
||||
apiService.getEquipmentToken(qrcodeId = qrcodeId)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取人脸数据
|
||||
*/
|
||||
suspend fun getUserFaceCache(
|
||||
pageIndex: Int
|
||||
): ApiResponse<UserFaceInfo> {
|
||||
return safeApiCall {
|
||||
apiService.getUserFaceCache(pageIndex = pageIndex)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取档口菜品信息
|
||||
* @param restId 从device服务获取的canteenId字段
|
||||
* @param type 0全部 1餐次
|
||||
*/
|
||||
suspend fun getRestInfoFoodsByType(
|
||||
restId: String = GlobalData.restId,
|
||||
type: Int = 1,
|
||||
foodName: String,
|
||||
): ApiResponse<List<FoodInfo>> {
|
||||
return safeApiCall {
|
||||
apiService.getRestInfoFoodsByType(restId = restId, type = type, foodName = foodName)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过用户信息获取就餐数据
|
||||
*/
|
||||
suspend fun getUserNutritionData(
|
||||
restId: String = GlobalData.restId,
|
||||
userId: String,
|
||||
foodId: String,
|
||||
): ApiResponse<NutritionData> {
|
||||
return safeApiCall {
|
||||
apiService.getUserNutritionData(restId = restId, userId = userId, foodId = foodId)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 提交就餐数据
|
||||
*/
|
||||
suspend fun postUserNutritionData(
|
||||
param: UserNutritionParam
|
||||
): ApiResponse<String> {
|
||||
return safeApiCall { apiService.postUserNutritionData(param = param) }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user