package cn.flightfeather.thirdapp.repository
|
|
import cn.flightfeather.thirdapp.bean.entity.Evaluation
|
import cn.flightfeather.thirdapp.bean.entity.Evaluationrule
|
import cn.flightfeather.thirdapp.bean.entity.Itemevaluation
|
import cn.flightfeather.thirdapp.bean.vo.EvaluationsubruleVo
|
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.EvaluationService
|
import cn.flightfeather.thirdapp.repository.dao.EvaluationDao
|
import io.reactivex.Observable
|
import io.reactivex.functions.BiFunction
|
import okhttp3.ResponseBody
|
import retrofit2.Response
|
|
/**
|
* @author riku
|
* Date: 2020/7/22
|
* 评分相关数据操作
|
*/
|
class EvaluationRepository {
|
private val retrofit = RetrofitFactory.instance.retrofit
|
private val evaluationDao = EvaluationDao()
|
|
|
fun getEvaluationRule(
|
provinceCode: String, cityCode: String,
|
districtCode: String, sceneTypeId: Byte, resultCallBack: ResultCallBack<List<Evaluationrule>>) {
|
val dbService = evaluationDao.getEvaluationRule(provinceCode, cityCode, districtCode, sceneTypeId)
|
.map {
|
Response.success(it)
|
}
|
|
RetrofitFactory.executeResult(dbService, object : ResultObserver<List<Evaluationrule>>() {
|
override fun onSuccess(result: List<Evaluationrule>?) {
|
resultCallBack.onSuccess(result)
|
}
|
|
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
|
resultCallBack.onFailure()
|
}
|
})
|
}
|
|
fun getEvaluation(inspectionGuid: String, resultCallBack: ResultCallBack<List<Evaluation>>) {
|
retrofit.create(EvaluationService::class.java)
|
.findByInspectionId(inspectionGuid).enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
|
fun getRuleItem(evaluationruleGuid: String, subTaskGuid: String,resultCallBack: ResultCallBack<ArrayList<EvaluationsubruleVo>>) {
|
val dbService = evaluationDao.getEvaluationSubRule(evaluationruleGuid).map {
|
val list = it.map {
|
EvaluationsubruleVo().apply {
|
guid = it.guid
|
erguid = it.erguid
|
ertype = it.ertype
|
fatherid = it.fatherid
|
fathername = it.fathername
|
usedanalyse = it.usedanalyse
|
itemname = it.itemname
|
itemdescription = it.itemdescription
|
minscore = it.minscore
|
maxscore = it.maxscore
|
displayid = it.displayid
|
displaylevel = it.displaylevel
|
problemlist = it.problemlist
|
gitlist = it.gitlist
|
devicelist = it.devicelist
|
createdate = it.createdate
|
updatedate = it.updatedate
|
mutichoice = it.extension1
|
remark = it.remark
|
}
|
}
|
Response.success(list)
|
}
|
|
val service = retrofit.create(EvaluationService::class.java)
|
.getItemEvaluationList(subTaskGuid)
|
|
val zipService = Observable.zip(dbService, service,
|
BiFunction<Response<List<EvaluationsubruleVo>>, Response<List<Itemevaluation>>, Response<List<EvaluationsubruleVo>>> { t1, t2 ->
|
refreshRuleItem(t1, t2)
|
})
|
|
RetrofitFactory.executeResult(zipService, object : ResultObserver<List<EvaluationsubruleVo>>() {
|
override fun onSuccess(result: List<EvaluationsubruleVo>?) {
|
resultCallBack.onSuccess(ArrayList(result ?: emptyList()))
|
}
|
|
override fun onFailure(e: Throwable, isNetWorkError: Boolean) {
|
resultCallBack.onFailure()
|
}
|
})
|
}
|
|
private fun refreshRuleItem(
|
t1: Response<List<EvaluationsubruleVo>>,
|
t2: Response<List<Itemevaluation>>
|
): Response<List<EvaluationsubruleVo>> {
|
t1.body()?.forEach { r ->
|
if (t2.body()?.isNotEmpty() == true) {
|
t2.body()?.forEach t2@{ i ->
|
if (r.guid == i.esrguid) {
|
if (i.extension1.isNullOrEmpty() || i.extension1 == false.toString()) {
|
r.isSelected = false
|
} else {
|
r.grade = "0"
|
try {
|
r.grade = i.value
|
} catch (e: Throwable) {
|
e.printStackTrace()
|
}
|
r.isSelected = true
|
}
|
r.itemEvaluationVo = i
|
return@t2
|
}
|
}
|
} else {
|
// todo: 2020/7/1 目前的评分表格为单选性质,默认每一项初始都不选择
|
try {
|
if (r.defaultvalue != "0") {
|
r.isSelected = false
|
}
|
} catch (e: Exception) {
|
e.printStackTrace()
|
}
|
}
|
}
|
return t1
|
}
|
|
fun savePoint(
|
evaluationVo: Evaluation,
|
itemEvaluationVos: ArrayList<Itemevaluation>,
|
isUpdate:Boolean = false,
|
resultCallBack: ResultCallBack<ResponseBody>
|
) {
|
val totalPointService = retrofit.create(EvaluationService::class.java)
|
.let {
|
if (isUpdate) {
|
it.uploadEvaluation(evaluationVo)
|
} else {
|
it.putEvaluation(evaluationVo)
|
}
|
}
|
|
val itemPointService = retrofit.create(EvaluationService::class.java)
|
.let {
|
if (isUpdate) {
|
it.uploadItemEvaluationList(itemEvaluationVos)
|
} else {
|
it.putItemEvaluationList(itemEvaluationVos)
|
}
|
}
|
|
totalPointService.enqueue(ResponseBodyCallBack(resultCallBack))
|
itemPointService.enqueue(ResponseBodyCallBack(resultCallBack))
|
}
|
}
|