package cn.flightfeather.thirdapp.repository
|
|
import cn.flightfeather.thirdapp.bean.entity.Inspection
|
import cn.flightfeather.thirdapp.bean.entity.Mediafile
|
import cn.flightfeather.thirdapp.bean.entity.Scense
|
import cn.flightfeather.thirdapp.bean.entity.Subtask
|
import cn.flightfeather.thirdapp.bean.vo.*
|
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.httpservice.SubTaskService
|
import cn.flightfeather.thirdapp.httpservice.TaskService
|
import cn.flightfeather.thirdapp.repository.dao.MediaFileDao
|
import cn.flightfeather.thirdapp.repository.dao.SceneDao
|
import io.reactivex.Observable
|
import io.reactivex.functions.BiFunction
|
import okhttp3.ResponseBody
|
import retrofit2.Call
|
import retrofit2.Callback
|
import retrofit2.Response
|
|
/**
|
* @author riku
|
* Date: 2019/7/29
|
* 巡查相关数据获取
|
*/
|
class InspectionRepository {
|
|
val retrofit = RetrofitFactory.instance.retrofit
|
private val mediaFileDao = MediaFileDao()
|
private val sceneDao = SceneDao()
|
|
/**
|
* 根据用户及用户类型获取月任务信息;
|
* 普通用户只能获取自己执行的任务
|
* 管理员可获取所有任务
|
*/
|
fun getMonthDayTask(date: String, executorID: String, userType: String, resultCallBack: ResultCallBack<ArrayList<TaskVo>>) {
|
retrofit.create(TaskService::class.java).getMonthTask(executorID, date, userType)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
/**
|
* 根据总任务id获取日任务
|
*/
|
fun getDayTask(taskId: String, executorID: String, userType: String, resultCallBack: ResultCallBack<ArrayList<DayTaskProgressVo>>) {
|
retrofit.create(TaskService::class.java).getDayTaskList(taskId, executorID, userType)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
/**
|
* 根据日任务获取子任务
|
*/
|
fun getSubTask(dayTaskId: String, executorID: String, userType: String, resultCallBack: ResultCallBack<ArrayList<Subtask>>) {
|
retrofit.create(SubTaskService::class.java).findByDayTaskID(dayTaskId, executorID, userType)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
/**
|
* 查询本地是否有图片未上传
|
*/
|
fun checkUnUploadImage(resultCallBack: ResultCallBack<Boolean>) {
|
val dbService = mediaFileDao.checkUnUploadImage().map {
|
Response.success(it)
|
}
|
|
RetrofitFactory.executeResult(dbService, object : ResultObserver<Boolean>() {
|
override fun onSuccess(result: Boolean?) {
|
resultCallBack.onSuccess(result)
|
}
|
|
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
|
resultCallBack.onFailure()
|
}
|
|
})
|
}
|
|
/**
|
* 获取巡查信息
|
*/
|
fun getInspectionData(subTaskId: String, resultCallBack: ResultCallBack<InspectionVo>) {
|
retrofit.create(InspectionService::class.java).loadInspectionData(subTaskId)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
/**
|
* 根据巡查id获取问题列表
|
*/
|
fun getProblemList(inspectionId: String, resultCallBack: ResultCallBack<List<ProblemlistVo>>) {
|
retrofit.create(InspectionService::class.java).loadProblemList(inspectionId)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
/**
|
* 根据场景id和对应本次子任务id,查询该场景上一次子任务的所有问题
|
* @param dateStr 格式为"yyyy-MM-dd HH:mm"
|
*/
|
fun getLastProblemList(sceneId: String, dateStr: String, resultCallBack: ResultCallBack<LastSubtaskPack>) {
|
retrofit.create(InspectionService::class.java).loadLastProblemList(sceneId, dateStr)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
/**
|
* 更新子任务
|
*/
|
fun updateSubTask(subTask: Subtask, resultCallBack: ResultCallBack<String>) {
|
retrofit.create(InspectionService::class.java).updateSubTask(subTask)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
/**
|
* 更新巡查信息
|
*/
|
fun updateInspection(inspection: Inspection, resultCallBack: ResultCallBack<ResponseBody>) {
|
retrofit.create(InspectionService::class.java).updateInspection(inspection)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
/**
|
* 更新场景信息
|
*/
|
fun updateScene(scene: Scense, resultCallBack: ResultCallBack<ResponseBody>) {
|
retrofit.create(InspectionService::class.java).updateScense(scene)
|
.enqueue(object : Callback<ResponseBody> {
|
override fun onFailure(p0: Call<ResponseBody>, p1: Throwable) {
|
resultCallBack?.onFailure()
|
}
|
|
override fun onResponse(p0: Call<ResponseBody>, p1: Response<ResponseBody>) {
|
if (p1.isSuccessful) {
|
sceneDao.update(scene)
|
resultCallBack?.onSuccess(p1.body())
|
} else {
|
resultCallBack?.onFailure()
|
}
|
}
|
})
|
}
|
|
/**
|
* 根据类型获取巡查中的图片
|
*/
|
fun getMediaFile(inspectionId: String, businessType: Int,resultCallBack: ResultCallBack<ArrayList<Mediafile>>) {
|
val dbService = mediaFileDao.getMediaFile(inspectionId, businessType)
|
|
val mediaService = retrofit.create(InspectionService::class.java).getMediaFileList(inspectionId, businessType)
|
|
val zipService = Observable.zip(dbService, mediaService,
|
BiFunction<List<Mediafile>, Response<List<Mediafile>>, Response<ArrayList<Mediafile>>> { t1, t2 ->
|
Response.success(ArrayList<Mediafile>().apply {
|
addAll(t1)
|
t2.body()?.let { addAll(it) }
|
})
|
})
|
|
RetrofitFactory.executeResult(zipService, object : ResultObserver<ArrayList<Mediafile>>() {
|
override fun onSuccess(result: ArrayList<Mediafile>?) {
|
resultCallBack.onSuccess(result)
|
}
|
|
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
|
resultCallBack.onFailure()
|
}
|
})
|
}
|
|
/**
|
* 获取技防措施
|
*/
|
fun getGitList(inspectionId: String, resultCallBack: ResultCallBack<List<GitlistVo>>) {
|
retrofit.create(InspectionService::class.java).loadGitList(inspectionId)
|
.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
}
|