修改数据上传

This commit is contained in:
squallzhjch
2023-05-05 16:52:07 +08:00
parent 5826922bb9
commit 3a1e1bc9d6
9 changed files with 48 additions and 31 deletions

View File

@@ -58,7 +58,7 @@ interface RetrofitNetworkServiceAPI {
@Headers("Content-Type: application/json")
@POST("/devcp/upload")
suspend fun postRequest(@Body listEvaluationInfo: List<EvaluationInfo>?): Call<ResponseBody>
suspend fun postRequest(@Body listEvaluationInfo: List<EvaluationInfo>?): Response<ResponseBody>
/**
* @FormUrlEncoded 请求格式注解请求实体是一个From表单每个键值对需要使用@Field注解

View File

@@ -9,6 +9,7 @@ import androidx.lifecycle.Observer
import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.omqs.bean.EvaluationInfo
import com.navinfo.omqs.bean.TaskBean
import com.navinfo.omqs.http.NetResult
import com.navinfo.omqs.tools.FileManager
import com.navinfo.omqs.tools.FileManager.Companion.FileUploadStatus
import io.realm.Realm
@@ -114,9 +115,16 @@ class TaskUploadScope(
taskBean.hadLinkDvoList.forEach { hadLinkDvoBean ->
val objects = realm.where(QsRecordBean::class.java)
.equalTo("linkId", /*"84207223282277331"*/hadLinkDvoBean.linkPid).findAll()
if(objects.size == 0){
// change(FileUploadStatus.NONE)
return
}
val bodyList: MutableList<EvaluationInfo> = ArrayList()
if (objects != null) {
objects.forEach{
val copyList =realm.copyFromRealm(objects)
copyList.forEach {
val evaluationInfo = EvaluationInfo(
taskBean.id.toString(),
hadLinkDvoBean.linkPid,//"84207223282277331"
@@ -137,26 +145,20 @@ class TaskUploadScope(
bodyList.add(evaluationInfo)
}
uploadManager.netApi.postRequest(bodyList).enqueue(object :
Callback<ResponseBody> {
override fun onResponse(
call: Call<ResponseBody>,
response: Response<ResponseBody>
) {
if (response.code() == 200) {
taskBean.syncStatus = FileUploadStatus.DONE
// handle the response
Log.e("qj", "")
change(FileUploadStatus.DONE)
}
}
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
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)
} else {
// handle the failure
Log.e("qj", "")
change(FileUploadStatus.ERROR)
}
})
} else {
change(FileUploadStatus.ERROR)
}
}
}