修改同步逻辑
This commit is contained in:
parent
8b20da237b
commit
077d5bb32f
@ -61,7 +61,6 @@ class TaskUploadScope(
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 更新状态
|
||||
* @param status [OfflineMapCityBean.Status]
|
||||
@ -70,10 +69,13 @@ class TaskUploadScope(
|
||||
if (taskBean.syncStatus != status) {
|
||||
taskBean.syncStatus = status
|
||||
uploadData.postValue(taskBean)
|
||||
launch {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
realm.executeTransaction {
|
||||
it.copyToRealmOrUpdate(taskBean)
|
||||
//同步中不进行状态记录,只做界面变更显示
|
||||
if(status!=FileUploadStatus.UPLOADING){
|
||||
launch {
|
||||
val realm = Realm.getDefaultInstance()
|
||||
realm.executeTransaction {
|
||||
it.copyToRealmOrUpdate(taskBean)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -106,18 +108,16 @@ class TaskUploadScope(
|
||||
}
|
||||
|
||||
val realm = Realm.getDefaultInstance()
|
||||
|
||||
val bodyList: MutableList<EvaluationInfo> = ArrayList()
|
||||
|
||||
taskBean.hadLinkDvoList.forEach { hadLinkDvoBean ->
|
||||
val objects = realm.where(QsRecordBean::class.java)
|
||||
.equalTo("linkId", /*"84207223282277331"*/hadLinkDvoBean.linkPid).findAll()
|
||||
if (objects.size == 0) {
|
||||
if (taskBean.syncStatus == FileUploadStatus.WAITING)
|
||||
change(FileUploadStatus.NONE)
|
||||
return
|
||||
if (taskBean.syncStatus == FileUploadStatus.WAITING){
|
||||
change(FileUploadStatus.UPLOADING)
|
||||
}
|
||||
|
||||
val bodyList: MutableList<EvaluationInfo> = ArrayList()
|
||||
|
||||
if (objects != null) {
|
||||
if (objects != null&&objects.size>0) {
|
||||
val copyList = realm.copyFromRealm(objects)
|
||||
copyList.forEach {
|
||||
val evaluationInfo = EvaluationInfo(
|
||||
@ -139,24 +139,24 @@ class TaskUploadScope(
|
||||
|
||||
bodyList.add(evaluationInfo)
|
||||
}
|
||||
|
||||
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
|
||||
change(FileUploadStatus.ERROR)
|
||||
}
|
||||
} else {
|
||||
change(FileUploadStatus.ERROR)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
change(FileUploadStatus.ERROR)
|
||||
}
|
||||
} else {
|
||||
change(FileUploadStatus.ERROR)
|
||||
}
|
||||
|
||||
} catch (e: Throwable) {
|
||||
change(FileUploadStatus.ERROR)
|
||||
Log.e("jingo", "数据上传出错 ${e.message}")
|
||||
|
@ -27,6 +27,7 @@ class FileManager {
|
||||
const val DONE = 1 //完成
|
||||
const val ERROR = 2 //错误
|
||||
const val WAITING = 3 //等待中
|
||||
const val UPLOADING = 4 //同步中
|
||||
}
|
||||
|
||||
//初始化数据文件夹
|
||||
|
Loading…
x
Reference in New Issue
Block a user