riku
2025-10-30 e9aa93f381afcf9f9cf0c39f2b9e32375ed49528
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
package cn.flightfeather.thirdappmodule.databinding
 
import android.arch.lifecycle.MutableLiveData
import cn.flightfeather.thirdappmodule.bean.vo.DPChangeInfo
import cn.flightfeather.thirdappmodule.bean.vo.QueryOptSingle
import cn.flightfeather.thirdappmodule.common.net.ResultCallBack
import cn.flightfeather.thirdappmodule.module.base.BaseViewModel
import cn.flightfeather.thirdappmodule.repository.DataProdSingleSceneRepository
import cn.flightfeather.thirdappmodule.util.DateUtil
import org.jetbrains.anko.toast
import java.util.*
 
/**
 * 场景历史情况
 * @author riku
 * Date: 2025/10/30
 */
class SceneHistoryViewModel : BaseViewModel() {
    private val dataProdSingleSceneRepository = DataProdSingleSceneRepository.instance
 
    // 上个月整改率最差的情况
    var worstChangeInfo = MutableLiveData<DPChangeInfo>()
 
    fun getChangeInfoList(sceneId: String) {
        val queryOpts = getQueryOptSingleList(sceneId)
        dataProdSingleSceneRepository.getChangeInfoList(queryOpts, object : ResultCallBack<List<DPChangeInfo>> {
            override fun onSuccess(result: List<DPChangeInfo>?) {
                if (!result.isNullOrEmpty()) {
                    worstChangeInfo.value = result[0]
                }
            }
 
            override fun onFailure() {
                application.toast("获取整改率情况失败")
            }
        })
    }
 
    private fun getQueryOptSingleList(sceneId: String): List<QueryOptSingle> {
        val queryOpts = mutableListOf<QueryOptSingle>()
 
        // 获取前三个月的月头和月末时间
        val now = Calendar.getInstance().apply {
            set(Calendar.DAY_OF_MONTH, 1)
            set(Calendar.HOUR_OF_DAY, 0)
            set(Calendar.MINUTE, 0)
            set(Calendar.SECOND, 0)
        }
        repeat(3) {
            val queryOptSingle = QueryOptSingle().apply { this.sceneId = sceneId }
            // 得到上月最后一天
            now.add(Calendar.SECOND, -1)
            queryOptSingle.endTime = DateUtil.getDateStr(now.time)
            // 得到上月第一天
            now.apply {
                set(Calendar.DAY_OF_MONTH, 1)
                set(Calendar.HOUR_OF_DAY, 0)
                set(Calendar.MINUTE, 0)
                set(Calendar.SECOND, 0)
            }
            queryOptSingle.startTime = DateUtil.getDateStr(now.time)
 
            queryOpts.add(queryOptSingle)
        }
 
        return queryOpts
    }
}