From c03e1d823eb86c856ecbe40d8d2180ffce7c7b0f Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期五, 14 十一月 2025 17:45:39 +0800
Subject: [PATCH] 2025.11.14 新增值域的增删改接口

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdSingleSceneServiceImpl.kt |   79 ++++++++++++++++++++++++++-------------
 1 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdSingleSceneServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdSingleSceneServiceImpl.kt
index ce3eb0b..00ba68c 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdSingleSceneServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdSingleSceneServiceImpl.kt
@@ -10,7 +10,6 @@
 import cn.flightfeather.supervision.lightshare.vo.dataprod.DPChangeInfo
 import cn.flightfeather.supervision.lightshare.vo.dataprod.DPProblemRecurrence
 import cn.flightfeather.supervision.lightshare.vo.dataprod.QueryOptSingle
-import cn.flightfeather.supervision.lightshare.vo.dataprod.base.DPInspectionInfo
 import org.springframework.beans.BeanUtils
 import org.springframework.stereotype.Service
 import tk.mybatis.mapper.entity.Example
@@ -24,7 +23,7 @@
 class DataProdSingleSceneServiceImpl(private val aopDbMapper: AopDbMapper) : DataProdSingleSceneService {
 
     // 鏁存敼瑕佹眰鏈�澶ц�楁椂锛堝ぉ锛�
-    private val maxChangeTime = 3
+    private val MAX_CHANGE_TIME = 3
 
     override fun getChangeInfo(option: QueryOptSingle): DPChangeInfo {
         return QueryByCache.queryCache(
@@ -41,21 +40,44 @@
                 })
                 return@queryCache DPChangeInfo().apply {
                     subTasks = subtaskList
-                    problems = problemList.map {problem ->
+                    problems = problemList.map { problem ->
                         val problemListVo = ProblemListVo()
                         BeanUtils.copyProperties(problem, problemListVo)
                         problemListVo
                     }
                     proCount = problemList.size
-                    changeCount = problemList.count { it.ischanged == true }
-                    changePer = if (proCount == 0) 0.0 else changeCount.toDouble() / proCount
-                    changeTime = problemList
-                        .filter { it.ischanged == true }
-                        .maxOf { (it.changedtime?.time?:0L) - (it?.time?.time?:0L) }.toInt()
-                        .div(1000 * 60 * 60 * 24)
 
-                    val eff = if (changeTime == 0) 1.0 else maxChangeTime.toDouble() / changeTime
-                    changeEfficiency = if (eff > 1.0) 1.0 else eff
+                    val changeTimeList = mutableListOf<Long>()
+                    problemList.forEach { p ->
+                        if (p.ischanged != true) return@forEach
+                        // 鏁存敼鑰楁椂锛堝ぉ锛�
+                        val day = ((p.changedtime?.time ?: 0L) - (p?.time?.time ?: 0L)).div(1000 * 60 * 60 * 24)
+                        changeTimeList.add(day)
+
+                        // 鍙婃椂鐜板満鏁存敼
+                        if (day <= 1) {
+                            immeChangeCount++
+                        }
+                        // 甯告��/瑙勮寖鏁存敼锛�48灏忔椂鍐呮暣鏀癸級
+                        else if (day < MAX_CHANGE_TIME) {
+                            normalChangeCount++
+                        }
+                        // 鏈�缁堟暣鏀�
+                        changeCount++
+                    }
+                    immeChangePer = if (proCount == 0) 0.0 else immeChangeCount.toDouble() / proCount
+                    normalChangePer = if (proCount == 0) 0.0 else normalChangeCount.toDouble() / proCount
+                    changePer = if (proCount == 0) 0.0 else changeCount.toDouble() / proCount
+
+                    if (changeTimeList.isNotEmpty()) {
+                        changeTime = changeTimeList.maxOrNull()?.toInt() ?: 0
+                        val eff = if (changeTime == 0) 1.0 else MAX_CHANGE_TIME.toDouble() / changeTime
+                        changeEfficiency = if (eff > 1.0) 1.0 else eff
+
+                        avgChangeTime = changeTimeList.average().toInt()
+                        val effAvg = if (avgChangeTime == 0) 1.0 else MAX_CHANGE_TIME.toDouble() / avgChangeTime
+                        avgChangeEfficiency = if (effAvg > 1.0) 1.0 else effAvg
+                    }
                 }
             }
         )
@@ -70,35 +92,38 @@
             cache = { return@queryCache null },
             calculate = {
                 val problemList = aopDbMapper.problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
-                    createCriteria().andEqualTo("scenseid", option.sceneId)
-                        .andBetween("planstarttime", option.startTime, option.endTime)
-                    orderBy("planstarttime").desc()
+                    createCriteria().andEqualTo("sguid", option.sceneId)
+                        .andBetween("time", option.startTime, option.endTime)
+                    orderBy("time").desc()
                 })
                 if (problemList.isEmpty()) return@queryCache emptyList()
-                val problemTypeList = aopDbMapper.problemtypeMapper.selectByExample(Example(Problemtype::class.java)
-                    .apply { createCriteria().andIn("guid", problemList.map { it.ptguid }) })
+                val problemTypeList = aopDbMapper.problemtypeMapper.selectByExample(
+                    Example(Problemtype::class.java)
+                        .apply { createCriteria().andIn("guid", problemList.map { it.ptguid }) })
 
                 val problemMap = problemList
                     .filter {
-                        val type = problemTypeList.find { type-> type.guid == it.ptguid }
+                        val type = problemTypeList.find { type -> type.guid == it.ptguid }
                         type?.typename != "閬撹矾鎵皹" || type.description == "宸ュ湴鍐呭鏉¢亾璺槑鏄炬偿鐥�/娉ユ碁/绉皹/閬楁拻"
                     }.groupBy { problem ->
-                    val type = problemTypeList.find { type-> type.guid == problem.ptguid } ?: return@groupBy null
-                    /**
-                     * 2025.10.30 鐩墠鏍规嵁涓氬姟瑕佹眰锛屽湪宸ュ湴绫诲瀷涓紝鈥滈亾璺壃灏樷�濋棶棰樺嚭鐜版鐜囬潪甯搁珮锛�
-                     * 鍥犳璇ラ棶棰樺湪鍋氶噸澶嶆�х粺璁℃椂锛� 鍙粺璁$敤鍏跺瓙绫诲瀷"宸ュ湴鍐呭鏉¢亾璺槑鏄炬偿鐥�/娉ユ碁/绉皹/閬楁拻"涓哄垎绫荤被鍨�
-                     */
-                    if (type.typename == "閬撹矾鎵皹") {
+                        val type = problemTypeList.find { type -> type.guid == problem.ptguid } ?: return@groupBy null
+//                    /**
+//                     * 2025.10.30 鐩墠鏍规嵁涓氬姟瑕佹眰锛屽湪宸ュ湴绫诲瀷涓紝鈥滈亾璺壃灏樷�濋棶棰樺嚭鐜版鐜囬潪甯搁珮锛�
+//                     * 鍥犳璇ラ棶棰樺湪鍋氶噸澶嶆�х粺璁℃椂锛� 鍙粺璁$敤鍏跺瓙绫诲瀷"宸ュ湴鍐呭鏉¢亾璺槑鏄炬偿鐥�/娉ユ碁/绉皹/閬楁拻"涓哄垎绫荤被鍨�
+//                     */
+//                    if (type.typename == "閬撹矾鎵皹") {
+//                        type.description
+//                    } else {
+//                        type.typename
+//                    }
                         type.description
-                    } else {
-                        type.typename
                     }
-                }
                 return@queryCache problemMap.map { (key, value) ->
-                    val type = problemTypeList.find { type-> type.guid == value.first().ptguid }
+                    val type = problemTypeList.find { type -> type.guid == value.first().ptguid }
                     DPProblemRecurrence().apply {
                         problemTag = key
                         problemType = type
+                        this.problemList = value
                         count = value.size
                         changeCount = value.count { it.ischanged == true }
                         changePer = if (count == 0) 0.0 else changeCount.toDouble() / count

--
Gitblit v1.9.3