package cn.flightfeather.thirdapp.repository
|
|
import cn.flightfeather.thirdapp.bean.*
|
import cn.flightfeather.thirdapp.common.net.ResponseBodyCallBack
|
import cn.flightfeather.thirdapp.common.net.ResultCallBack
|
import cn.flightfeather.thirdapp.common.net.ResultObserver
|
import cn.flightfeather.thirdapp.common.net.RetrofitFactory
|
import cn.flightfeather.thirdapp.httpservice.InspectionService
|
import cn.flightfeather.thirdapp.repository.dao.DomainDao
|
import cn.flightfeather.thirdapp.repository.dao.MediaFileDao
|
import cn.flightfeather.thirdapp.repository.dao.ProblemTypeDao
|
import okhttp3.ResponseBody
|
import retrofit2.Response
|
|
/**
|
* @author riku
|
* Date: 2019/5/16
|
* 问题相关数据获取
|
*/
|
class ProblemRepository {
|
|
val retrofit = RetrofitFactory.instance.retrofit
|
private val domainDao = DomainDao()
|
private val problemTypeDao = ProblemTypeDao()
|
private val mediaFileDao = MediaFileDao()
|
|
/**
|
* 获取场景问题可选位置
|
*/
|
fun getLocationList(resultCallBack: ResultCallBack<ArrayList<Domainitem>>) {
|
val dbService = domainDao.getLocationList().map {
|
Response.success(ArrayList<Domainitem>().apply { addAll(it) })
|
}
|
|
RetrofitFactory.executeResult(dbService, object : ResultObserver<ArrayList<Domainitem>>() {
|
override fun onSuccess(result: ArrayList<Domainitem>?) {
|
resultCallBack.onSuccess(result)
|
}
|
|
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
|
resultCallBack.onFailure()
|
}
|
|
})
|
}
|
|
/**
|
* 获取对应场景下所有问题类型
|
*/
|
fun getProblemType(taskTypeId: Byte, cityCode: String, districtCode: String, sceneTypeId: Byte, resultCallBack: ResultCallBack<ArrayList<Problemtype>>) {
|
val dbService = domainDao.getProblemType(taskTypeId, cityCode, districtCode, sceneTypeId).map {
|
Response.success(ArrayList<Problemtype>().apply { addAll(it) })
|
}
|
|
RetrofitFactory.executeResult(dbService, object : ResultObserver<ArrayList<Problemtype>>() {
|
override fun onSuccess(result: ArrayList<Problemtype>?) {
|
resultCallBack.onSuccess(result)
|
}
|
|
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
|
resultCallBack.onFailure()
|
}
|
|
})
|
}
|
|
/**
|
* 获取问题对应的整改建议
|
*/
|
fun getSuggestion(ptGuid: String, resultCallBack: ResultCallBack<ArrayList<ChangeAdvice>>) {
|
val dbService = problemTypeDao.getSuggestion(ptGuid).map {
|
Response.success(ArrayList<ChangeAdvice>().apply { addAll(it) })
|
}
|
|
RetrofitFactory.executeResult(dbService, object : ResultObserver<ArrayList<ChangeAdvice>>() {
|
override fun onSuccess(result: ArrayList<ChangeAdvice>?) {
|
resultCallBack.onSuccess(result)
|
}
|
|
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
|
resultCallBack.onFailure()
|
}
|
|
})
|
}
|
|
/**
|
* 上传问题
|
*/
|
fun putOneProblemList(problem: Problemlist, resultCallBack: ResultCallBack<ResponseBody>) {
|
retrofit.create(InspectionService::class.java).putOneProblemList(problem)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
/**
|
* 图片本地缓存
|
*/
|
fun putMediaFileLocal(mediaFile: Mediafile, resultCallBack: ResultCallBack<Int>) {
|
val dbService = mediaFileDao.insert(mediaFile).map {
|
Response.success(it)
|
}
|
|
RetrofitFactory.executeResult(dbService, object : ResultObserver<Int>() {
|
override fun onSuccess(result: Int?) {
|
resultCallBack.onSuccess(result)
|
}
|
|
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
|
resultCallBack.onFailure()
|
}
|
|
})
|
}
|
}
|