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 |   67 +++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 1 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
index 1c81e5c..165d72c 100644
--- a/app/src/main/java/cn/flightfeather/thirdappmodule/databinding/SceneHistoryViewModel.kt
+++ b/app/src/main/java/cn/flightfeather/thirdappmodule/databinding/SceneHistoryViewModel.kt
@@ -1,7 +1,9 @@
 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
@@ -9,6 +11,7 @@
 import cn.flightfeather.thirdappmodule.util.DateUtil
 import org.jetbrains.anko.toast
 import java.util.*
+import kotlin.math.round
 
 /**
  * 鍦烘櫙鍘嗗彶鎯呭喌
@@ -16,16 +19,40 @@
  * Date: 2025/10/30
  */
 class SceneHistoryViewModel : BaseViewModel() {
+
+    companion object {
+        const val CHANGE_PER = 0.8
+    }
+
     private val dataProdSingleSceneRepository = DataProdSingleSceneRepository.instance
 
     // 涓婁釜鏈堟暣鏀圭巼鏈�宸殑鎯呭喌
     var worstChangeInfo = MutableLiveData<DPChangeInfo>()
 
-    fun getChangeInfoList(sceneId: String) {
+    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]
                 }
             }
@@ -36,6 +63,44 @@
         })
     }
 
+    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>()
 

--
Gitblit v1.9.3