重构网络返回对象2.对应服务上报问题接口变更
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
package com.navinfo.omqs.http
|
||||
|
||||
class DefaultTaskResponse<T> {
|
||||
class DefaultResponse<T> {
|
||||
var success: Boolean = false
|
||||
var msg: String = ""
|
||||
var obj: T? = null
|
||||
@@ -1,7 +0,0 @@
|
||||
package com.navinfo.omqs.http
|
||||
|
||||
class DefaultUserResponse<T> {
|
||||
var success: Boolean = false
|
||||
var msg: String = ""
|
||||
var obj: T? = null
|
||||
}
|
||||
@@ -19,10 +19,10 @@ interface NetworkService {
|
||||
/**
|
||||
* 获取任务列表
|
||||
*/
|
||||
suspend fun getTaskList(evaluatorNo:String): NetResult<DefaultTaskResponse<List<TaskBean>>>
|
||||
suspend fun getTaskList(evaluatorNo:String): NetResult<DefaultResponse<List<TaskBean>>>
|
||||
|
||||
/**
|
||||
* 登录接口
|
||||
*/
|
||||
suspend fun loginUser(loginUserBean: LoginUserBean): NetResult<DefaultUserResponse<SysUserBean>>
|
||||
suspend fun loginUser(loginUserBean: LoginUserBean): NetResult<DefaultResponse<SysUserBean>>
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class NetworkServiceImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getTaskList(evaluatorNo: String): NetResult<DefaultTaskResponse<List<TaskBean>>> =
|
||||
override suspend fun getTaskList(evaluatorNo: String): NetResult<DefaultResponse<List<TaskBean>>> =
|
||||
//在IO线程中运行
|
||||
withContext(Dispatchers.IO) {
|
||||
return@withContext try {
|
||||
@@ -57,7 +57,7 @@ class NetworkServiceImpl @Inject constructor(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun loginUser(loginUserBean: LoginUserBean): NetResult<DefaultUserResponse<SysUserBean>> =
|
||||
override suspend fun loginUser(loginUserBean: LoginUserBean): NetResult<DefaultResponse<SysUserBean>> =
|
||||
//在IO线程中运行
|
||||
withContext(Dispatchers.IO) {
|
||||
return@withContext try {
|
||||
|
||||
@@ -47,7 +47,7 @@ interface RetrofitNetworkServiceAPI {
|
||||
*/
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("/devcp/loginUser")
|
||||
suspend fun retrofitLoginUser(@Body loginUserBean: LoginUserBean): Response<DefaultUserResponse<SysUserBean>>
|
||||
suspend fun retrofitLoginUser(@Body loginUserBean: LoginUserBean): Response<DefaultResponse<SysUserBean>>
|
||||
|
||||
/**
|
||||
* 下载文件
|
||||
@@ -62,11 +62,11 @@ interface RetrofitNetworkServiceAPI {
|
||||
@GET("/devcp/getEvaluationTask?evaluatType=2")
|
||||
suspend fun retrofitGetTaskList(
|
||||
@Query("evaluatorNo") evaluatorNo: String,
|
||||
): Response<DefaultTaskResponse<List<TaskBean>>>
|
||||
): Response<DefaultResponse<List<TaskBean>>>
|
||||
|
||||
@Headers("Content-Type: application/json")
|
||||
@POST("/devcp/uploadSceneProblem")
|
||||
suspend fun postRequest(@Body listEvaluationInfo: List<EvaluationInfo>?): Response<ResponseBody>
|
||||
suspend fun postRequest(@Body listEvaluationInfo: List<EvaluationInfo>?): Response<DefaultResponse<*>>
|
||||
|
||||
/**
|
||||
* @FormUrlEncoded 请求格式注解,请求实体是一个From表单,每个键值对需要使用@Field注解
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.navinfo.omqs.http.taskupload
|
||||
|
||||
import android.os.Build
|
||||
import android.util.Log
|
||||
import android.widget.Toast
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
@@ -9,6 +10,8 @@ import androidx.lifecycle.Observer
|
||||
import com.navinfo.collect.library.data.entity.QsRecordBean
|
||||
import com.navinfo.omqs.bean.EvaluationInfo
|
||||
import com.navinfo.collect.library.data.entity.TaskBean
|
||||
import com.navinfo.omqs.bean.SysUserBean
|
||||
import com.navinfo.omqs.http.DefaultResponse
|
||||
import com.navinfo.omqs.tools.FileManager.Companion.FileUploadStatus
|
||||
import io.realm.Realm
|
||||
import kotlinx.coroutines.*
|
||||
@@ -68,6 +71,7 @@ class TaskUploadScope(
|
||||
private fun change(status: Int, message: String = "") {
|
||||
if (taskBean.syncStatus != status) {
|
||||
taskBean.syncStatus = status
|
||||
taskBean.errMsg = message
|
||||
uploadData.postValue(taskBean)
|
||||
//同步中不进行状态记录,只做界面变更显示
|
||||
if(status!=FileUploadStatus.UPLOADING){
|
||||
@@ -121,15 +125,15 @@ class TaskUploadScope(
|
||||
if (objects != null&&objects.size>0) {
|
||||
val copyList = realm.copyFromRealm(objects)
|
||||
copyList.forEach {
|
||||
var problemType = "0"
|
||||
var problemType = 0
|
||||
if(it.problemType=="错误"){
|
||||
problemType = "0"
|
||||
problemType = 0
|
||||
}else if(it.problemType=="多余"){
|
||||
problemType = "1"
|
||||
problemType = 1
|
||||
}else if(it.problemType=="遗漏"){
|
||||
problemType = "2"
|
||||
problemType = 2
|
||||
}
|
||||
var evaluationWay = "2";
|
||||
var evaluationWay = 2
|
||||
/* if(it.evaluationWay=="生产测评"){
|
||||
evaluationWay = "1"
|
||||
}else if(it.evaluationWay=="现场测评"){
|
||||
@@ -170,14 +174,14 @@ class TaskUploadScope(
|
||||
trackPhotoNumber = "",
|
||||
markGeometry = "",
|
||||
featureName = "",
|
||||
problemType = "",
|
||||
problemType = 0,
|
||||
problemPhenomenon = "",
|
||||
problemDesc = "",
|
||||
problemLink = "",
|
||||
problemReason = "",
|
||||
evaluatorName = "",
|
||||
evaluationDate = "",
|
||||
evaluationWay = "",
|
||||
evaluationWay = 2,
|
||||
roadClassfcation = "",
|
||||
roadFunctionGrade = "",
|
||||
noEvaluationreason = "",
|
||||
@@ -193,10 +197,13 @@ class TaskUploadScope(
|
||||
val result = uploadManager.netApi.postRequest(bodyList)// .enqueue(object :
|
||||
// Callback<ResponseBody> {
|
||||
if (result.isSuccessful) {
|
||||
if (result.code() == 200) {
|
||||
// taskBean.syncStatus = FileUploadStatus.DONE
|
||||
// handle the response
|
||||
change(FileUploadStatus.DONE)
|
||||
if (result.code() == 200&&result.body()!=null) {
|
||||
val defaultUserResponse = result.body() as DefaultResponse<*>
|
||||
if(defaultUserResponse.success){
|
||||
change(FileUploadStatus.DONE)
|
||||
}else{
|
||||
change(FileUploadStatus.ERROR,"${defaultUserResponse.msg}")
|
||||
}
|
||||
} else {
|
||||
// handle the failure
|
||||
change(FileUploadStatus.ERROR)
|
||||
|
||||
Reference in New Issue
Block a user