riku
2025-07-02 3013b813e5df6977c0be921928f73b1a3adde290
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
package cn.flightfeather.thirdappmodule.module.nightwork
 
import android.arch.lifecycle.MutableLiveData
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
import cn.flightfeather.thirdappmodule.model.bean.NightWorkFileVo
import cn.flightfeather.thirdappmodule.model.bean.NightWorkSummary
import cn.flightfeather.thirdappmodule.module.base.BaseViewModel
import cn.flightfeather.thirdappmodule.repository.NightWorkRepository
import cn.flightfeather.thirdappmodule.view.recyclerview.DataLoadModel
 
/**
 * @author riku
 * Date: 2020/12/24
 */
class NightWorkViewModel : BaseViewModel() {
 
    private val nightWorkRepository = NightWorkRepository()
 
    var summary = MutableLiveData<NightWorkSummary>()
 
    //获取最新未读文件
    val dataLoadModel1 = object : DataLoadModel<NightWorkFileVo>(application) {
        override fun loadDataByRefresh() {
            getNightWorkFile(false, 1, this)
        }
 
        override fun loadDataByLoadMore(page: Int) {
            getNightWorkFile(false, page, this)
        }
    }
 
    //获取历史已读文件
    val dataLoadModel2 = object : DataLoadModel<NightWorkFileVo>(application) {
        override fun loadDataByRefresh() {
            getNightWorkFile(true, 1, this)
        }
 
        override fun loadDataByLoadMore(page: Int) {
            getNightWorkFile(true, page, this)
        }
    }
 
    //获取全部文件
    val dataLoadModel3 = object : DataLoadModel<NightWorkFileVo>(application) {
        override fun loadDataByRefresh() {
            getRecord(application.currentUser.dguid, 1, this)
        }
 
        override fun loadDataByLoadMore(page: Int) {
            getRecord(application.currentUser.dguid, page, this)
        }
    }
 
    fun getNightWorkFile(isRead: Boolean, page: Int, callBack: ResultCallBack<List<NightWorkFileVo>>) {
        nightWorkRepository.getNightWorkFile(userId, isRead, page, callBack)
    }
 
    fun signFile(fileId: Int, fileNum: String, callBack: ResultCallBack<Int>) {
        nightWorkRepository.signFile(userId, fileNum, fileId, callBack)
    }
 
    fun getRecord(districtCode: String, page: Int, callBack: ResultCallBack<List<NightWorkFileVo>>) {
        nightWorkRepository.getRecord(districtCode, page, callBack)
    }
 
    fun getSummary() {
        nightWorkRepository.getSummary(application.currentUser.dguid, object : ResultCallBack<NightWorkSummary> {
            override fun onSuccess(result: NightWorkSummary?) {
                result?.let { summary.value = it }
            }
 
            override fun onFailure() {
//                summary.value = NightWorkSummary()
            }
        })
    }
}