From 1897c4ad5fa73b3f0a36e1aa0e1e9000302a6ace Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 31 十月 2025 17:35:09 +0800
Subject: [PATCH] 2025.10.31 1. 新增巡查场景历史详情相关数据逻辑(待完成);

---
 app/src/main/java/cn/flightfeather/thirdappmodule/databinding/SceneHistoryViewModel.kt |  133 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 133 insertions(+), 0 deletions(-)

diff --git a/app/src/main/java/cn/flightfeather/thirdappmodule/databinding/SceneHistoryViewModel.kt b/app/src/main/java/cn/flightfeather/thirdappmodule/databinding/SceneHistoryViewModel.kt
new file mode 100644
index 0000000..165d72c
--- /dev/null
+++ b/app/src/main/java/cn/flightfeather/thirdappmodule/databinding/SceneHistoryViewModel.kt
@@ -0,0 +1,133 @@
+package cn.flightfeather.thirdappmodule.databinding
+
+import android.arch.lifecycle.MutableLiveData
+import android.view.View
+import cn.flightfeather.thirdappmodule.bean.vo.DPChangeInfo
+import cn.flightfeather.thirdappmodule.bean.vo.DPProblemRecurrence
+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.*
+import kotlin.math.round
+
+/**
+ * 鍦烘櫙鍘嗗彶鎯呭喌
+ * @author riku
+ * Date: 2025/10/30
+ */
+class SceneHistoryViewModel : BaseViewModel() {
+
+    companion object {
+        const val CHANGE_PER = 0.8
+    }
+
+    private val dataProdSingleSceneRepository = DataProdSingleSceneRepository.instance
+
+    // 涓婁釜鏈堟暣鏀圭巼鏈�宸殑鎯呭喌
+    var worstChangeInfo = MutableLiveData<DPChangeInfo>()
+
+    var changeInfoTxt = MutableLiveData<String>()
+    var changeEfficiencyTxt = MutableLiveData<String>()
+
+    // 闂澶嶅彂鎯呭喌
+//    var problemRecurrenceList = MutableLiveData<List<DPProblemRecurrence>>()
+    var worstProblemRecurrence = MutableLiveData<DPProblemRecurrence>()
+
+    //
+    fun fetchChangeInfoList(sceneId: String) {
+        val queryOpts = getQueryOptSingleList(sceneId)
+        dataProdSingleSceneRepository.getChangeInfoList(queryOpts, object : ResultCallBack<List<DPChangeInfo>> {
+            override fun onSuccess(result: List<DPChangeInfo>?) {
+                if (!result.isNullOrEmpty()) {
+                    changeInfoTxt.value = result.mapIndexed { i, info ->
+                        // 绛涢�夊瓨鍦ㄩ棶棰橈紝骞朵笖鏁存敼鐜囧皬浜�80%鐨勬湀浠�
+                        if (info.subTasks.isNullOrEmpty() && info.changePer >= CHANGE_PER) {
+                            ""
+                        } else {
+                            val time = DateUtil.parseYearMonth(queryOpts[i].startTime) ?: return@mapIndexed ""
+                            val cal = Calendar.getInstance().apply { setTime(time) }
+                            "${cal.get(Calendar.MONTH) + 1}鏈堟暣鏀圭巼涓�${round(info.changePer * 100)}%"
+                        }
+                    }.filter { it.isNotBlank() }.joinToString("锛�") + "锛屾暣鏀圭巼杈冧綆锛岄渶鍔犲己鐩戠銆�"
+
+                    worstChangeInfo.value = result[0]
+                }
+            }
+
+            override fun onFailure() {
+                application.toast("鑾峰彇鏁存敼鐜囨儏鍐靛け璐�")
+            }
+        })
+    }
+
+    fun fetchProblemRecurrence(sceneId:String) {
+        // 鑾峰彇鍓嶄笁涓湀鐨勫唴鐨勮褰�
+        val queryOpt = QueryOptSingle().apply {
+            this.sceneId = sceneId
+            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)
+            }
+            // 寰楀埌涓婃湀鏈�鍚庝竴澶�
+            now.add(Calendar.SECOND, -1)
+            endTime = DateUtil.getDateStr(now.time)
+            // 寰楀埌鍓�4涓湀绗竴澶�
+            now.apply {
+                set(Calendar.DAY_OF_MONTH, 1)
+                set(Calendar.HOUR_OF_DAY, 0)
+                set(Calendar.MINUTE, 0)
+                set(Calendar.SECOND, 0)
+            }
+            now.add(Calendar.MONTH, 2)
+            startTime = DateUtil.getDateStr(now.time)
+        }
+        dataProdSingleSceneRepository.getProblemRecurrence(queryOpt, object : ResultCallBack<List<DPProblemRecurrence>> {
+            override fun onSuccess(result: List<DPProblemRecurrence>?) {
+                if (!result.isNullOrEmpty()) {
+                    worstProblemRecurrence.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
+    }
+}
\ No newline at end of file

--
Gitblit v1.9.3