riku
2025-10-17 fbae5f3ea74727ccadc48314a864a1ea0099a945
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
package cn.flightfeather.thirdappmodule.module.inspection
 
import android.arch.lifecycle.MutableLiveData
import cn.flightfeather.thirdappmodule.bean.vo.LastSubtaskPack
import cn.flightfeather.thirdappmodule.bean.entity.Subtask
import cn.flightfeather.thirdappmodule.bean.vo.ProblemlistVo
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack2
import cn.flightfeather.thirdappmodule.model.event.ProblemEvent
import cn.flightfeather.thirdappmodule.module.base.BaseViewModel
import cn.flightfeather.thirdappmodule.repository.InspectionRepository
import cn.flightfeather.thirdappmodule.repository.ProblemRepository
import cn.flightfeather.thirdappmodule.util.DateFormatter
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.toast
 
/**
 * @author riku
 * Date: 2019/8/1
 */
class BaseProblemListViewModel : BaseViewModel() {
 
    private val inspectionRepository = InspectionRepository()
    private val problemRepository = ProblemRepository()
 
    var problemList = MutableLiveData<ArrayList<ProblemlistVo>>().apply { value = ArrayList() }
 
    var subTaskPack = MutableLiveData<LastSubtaskPack>()
 
    /**
     * 获取问题列表
     */
    fun getProblems(inspectionId: String?) {
        inspectionId?.let {
            inspectionRepository.getProblemList(it, object : ResultCallBack<List<ProblemlistVo>> {
                override fun onSuccess(result: List<ProblemlistVo>?) {
                    result?.let {
                        problemList.value?.clear()
 
                        problemList.value?.addAll(ArrayList<ProblemlistVo>().apply {
                            addAll(it)
                        })
 
                        problemList.value = problemList.value
                    }
                }
 
                override fun onFailure() {
 
                }
 
            })
        }
 
    }
 
    /**
     * 获取上次任务的问题列表
     */
    fun getLastProblems(subTask: Subtask?) {
        subTask?.let { subtask ->
            val dateStr = DateFormatter.dateTimeFormat2.format(subtask.executionstarttime)
            inspectionRepository.getLastProblemList(subtask.scenseid, dateStr, object : ResultCallBack<LastSubtaskPack> {
                override fun onSuccess(result: LastSubtaskPack?) {
                    result?.let {
                        subTaskPack.value = it
                    }
                }
 
                override fun onFailure() {
                }
 
            })
        }
    }
 
    /**
     * 删除问题
     */
    fun deleteProblem(position: Int, s: () -> Unit) {
        problemList.value?.get(position)?.let {
            problemRepository.deleteProblem(it.guid ?: "", object : ResultCallBack2<Int> {
                override fun onSuccess(result: Int?, message: String) {
                    if (result != null) {
                        EventBus.getDefault().post(ProblemEvent(it.voToEntity(), InspectionDetailActivity.PROBLEM_DELETE))
                        s()
                    }
                }
 
                override fun onFailure(message: String) {
                    application.toast(message)
                }
            })
        }
    }
}