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
|
}
|
}
|