riku
2020-08-21 0328eab9276e57487eb2cfff31a945a01dd8c73a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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()
            }
 
        })
    }
}