修改数据上传

This commit is contained in:
squallzhjch
2023-05-05 14:33:54 +08:00
parent b98e8b1614
commit 4d4549557d
15 changed files with 157 additions and 82 deletions

View File

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

View File

@@ -91,7 +91,6 @@ class TaskDownloadScope(
* @param status [OfflineMapCityBean.Status]
*/
private suspend fun change(status: Int, message: String = "") {
Log.e("jingo", "我被挂起 S")
if (taskBean.status != status || status == FileDownloadStatus.LOADING || status == FileDownloadStatus.IMPORTING) {
taskBean.status = status
taskBean.message = message
@@ -103,7 +102,6 @@ class TaskDownloadScope(
}
}
}
Log.e("jingo", "我被挂起 E")
}
/**

View File

@@ -10,7 +10,7 @@ import com.navinfo.collect.library.data.entity.QsRecordBean
import com.navinfo.omqs.bean.EvaluationInfo
import com.navinfo.omqs.bean.TaskBean
import com.navinfo.omqs.tools.FileManager
import com.navinfo.omqs.tools.FileManager.Companion.FileDownloadStatus
import com.navinfo.omqs.tools.FileManager.Companion.FileUploadStatus
import io.realm.Realm
import kotlinx.coroutines.*
import okhttp3.ResponseBody
@@ -48,7 +48,7 @@ class TaskUploadScope(
//改进的代码
fun start() {
change(FileDownloadStatus.WAITING)
change(FileUploadStatus.WAITING)
uploadManager.launchScope(this@TaskUploadScope)
}
@@ -59,7 +59,9 @@ class TaskUploadScope(
*/
fun launch() {
uploadJob = launch() {
upload()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
upload()
}
uploadManager.launchNext(taskBean.id)
}
}
@@ -86,7 +88,7 @@ class TaskUploadScope(
* 是否未上传
*/
fun isWaiting(): Boolean {
return taskBean.syncStatus == FileManager.Companion.FileUploadStatus.WAITING
return taskBean.syncStatus == FileUploadStatus.WAITING
}
/**
@@ -104,70 +106,62 @@ class TaskUploadScope(
private suspend fun upload() {
try {
//如果已上传则返回
if (taskBean.syncStatus == FileManager.Companion.FileUploadStatus.DONE) {
if (taskBean.syncStatus == FileUploadStatus.DONE) {
return
}
val realm = Realm.getDefaultInstance()
taskBean.hadLinkDvoList.forEach {
val hadLinkDvoBean = it
val liveDataQSList = MutableLiveData<List<QsRecordBean>>()
taskBean.hadLinkDvoList.forEach { hadLinkDvoBean ->
val objects = realm.where(QsRecordBean::class.java)
.equalTo("linkId", /*"84207223282277331"*/hadLinkDvoBean.linkPid).findAll()
val bodyList: MutableList<EvaluationInfo> = ArrayList()
if (objects != null) {
objects.forEach{
val evaluationInfo = EvaluationInfo(
taskBean.id.toString(),
hadLinkDvoBean.linkPid,//"84207223282277331"
"已测评",
hadLinkDvoBean.mesh,//"20065597"
"",
it.geometry,
it.classType,
it.problemType,
it.phenomenon,
it.description,
it.problemLink,
it.cause,
it.checkUserId,
it.checkTime
)
liveDataQSList.postValue(realm.copyFromRealm(objects))
bodyList.add(evaluationInfo)
}
if (liveDataQSList.value!!.isNotEmpty()) {
liveDataQSList.value?.forEach {
val evaluationInfo = EvaluationInfo(
taskBean.id.toString(),
hadLinkDvoBean.linkPid,//"84207223282277331"
"已测评",
hadLinkDvoBean.mesh,//"20065597"
"",
it.geometry,
it.classType,
it.problemType,
it.phenomenon,
it.description,
it.problemLink,
it.cause,
it.checkUserId,
it.checkTime
)
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)
}
}
uploadManager.netApi.postRequest(bodyList).enqueue(object :
Callback<ResponseBody> {
override fun onResponse(
call: Call<ResponseBody>,
response: Response<ResponseBody>
) {
if(response.code()==200){
taskBean.syncStatus = FileManager.Companion.FileUploadStatus.DONE
// handle the response
Log.e("qj", "")
change(FileManager.Companion.FileUploadStatus.DONE)
}
}
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
// handle the failure
Log.e("qj", "")
change(FileManager.Companion.FileUploadStatus.ERROR)
}
})
}
override fun onFailure(call: Call<ResponseBody>, t: Throwable) {
// handle the failure
Log.e("qj", "")
change(FileUploadStatus.ERROR)
}
})
}
}
} catch (e: Throwable) {
change(FileManager.Companion.FileUploadStatus.ERROR)
change(FileUploadStatus.ERROR)
Log.e("jingo", "数据上传出错 ${e.message}")
} finally {