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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
package cn.flightfeather.thirdapp.module.inspection
 
import android.arch.lifecycle.MutableLiveData
import cn.flightfeather.thirdapp.bean.*
import cn.flightfeather.thirdapp.common.net.ResultCallBack
import cn.flightfeather.thirdapp.model.event.ProblemEvent
import cn.flightfeather.thirdapp.module.base.BaseViewModel
import cn.flightfeather.thirdapp.repository.ProblemRepository
import okhttp3.ResponseBody
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.toast
 
/**
 * @author riku
 * Date: 2019/8/1
 */
class MenuEvidenceViewModel : BaseViewModel() {
 
    private val problemRepository = ProblemRepository()
 
    //所有问题可能出现的位置
    val locationList = MutableLiveData<ArrayList<Domainitem>>()
 
    //所有问题的分类集合
    val problemFatherType = MutableLiveData<ArrayList<String>>()
 
    //当前所选问题分类下的详细问题集合
    val problemType = MutableLiveData<ArrayList<Problemtype>>()
 
    val suggestionList = MutableLiveData<ArrayList<String>>()
 
    val problemMap = HashMap<String, ArrayList<Problemtype>>()
 
    /**
     * 获取场景问题可选位置(目前只有工地,但所有场景都使用)
     */
    fun getLocationList() {
        problemRepository.getLocationList(object : ResultCallBack<ArrayList<Domainitem>> {
            override fun onSuccess(result: ArrayList<Domainitem>?) {
                result?.let {
                    locationList.value = it
                }
            }
 
            override fun onFailure() {
 
            }
 
        })
    }
 
    /**
     * 获取对应场景下所有问题类型
     */
    fun getProblemType(taskTypeId: Byte, cityCode: String, districtCode: String, sceneTypeId: Byte) {
        problemRepository.getProblemType(taskTypeId, cityCode, districtCode, sceneTypeId, object : ResultCallBack<ArrayList<Problemtype>> {
            override fun onSuccess(result: ArrayList<Problemtype>?) {
                result?.let {
                    if (it.isEmpty()) {
                        it.add(Problemtype().apply {
                            guid = "0"
                            typename = "无"
                            name = "无"
                        })
                    }
 
                    val typeList = ArrayList<String>()
 
                    it.forEach {p ->
                        if (problemMap.containsKey(p.typename)) {
                            problemMap[p.typename]?.add(p)
                        } else {
                            typeList.add(p.typename)
                            problemMap[p.typename] = ArrayList<Problemtype>().apply { add(p) }
                        }
                    }
 
                    problemFatherType.value = typeList
                }
            }
 
            override fun onFailure() {
            }
 
        })
    }
 
    /**
     * 获取问题对应的整改建议
     */
    fun getSuggestionList(ptGuid: String) {
        problemRepository.getSuggestion(ptGuid, object : ResultCallBack<ArrayList<ChangeAdvice>> {
            override fun onSuccess(result: ArrayList<ChangeAdvice>?) {
                result?.let {
                    val advices = ArrayList<String>()
                    it.forEach {c ->
                        advices.add(c.adName)
                    }
                    advices.add("暂无建议")
                    suggestionList.value = advices
                }
            }
 
            override fun onFailure() {
            }
 
        })
    }
 
    /**
     * 新增一个问题
     */
    fun putProblem(problem: Problemlist) {
        problemRepository.putOneProblemList(problem, object : ResultCallBack<ResponseBody> {
            override fun onSuccess(result: ResponseBody?) {
                result?.let {
                    application.toast("提交成功")
 
                    EventBus.getDefault().post(ProblemEvent(problem))
                }
            }
 
            override fun onFailure() {
                application.toast("提交失败")
            }
 
        })
    }
 
    /**
     * 新增本地多媒体文件记录
     */
    fun putMediaFile(mediaFile: Mediafile) {
        problemRepository.putMediaFileLocal(mediaFile, object : ResultCallBack<Int> {
            override fun onSuccess(result: Int?) {
 
            }
 
            override fun onFailure() {
 
            }
 
        })
    }
 
    /**
     * 下拉框选择一个问题类型时,需展示对应类别的具体问题
     */
    fun refreshProblems(problemFatherType: String?) {
        problemMap[problemFatherType]?.let {
            problemType.value = it
        }
    }
}