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