From 1a677d2b4a4bc615602f8c2a22bc07ec1356e5be Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 16 十月 2025 17:39:06 +0800
Subject: [PATCH] 2025.10.16 1. 根据全局响应增强器GlobalResponseAdvice,将原先的BaseResPack接口包装函数统一去除; 2. 新增三种类型的数据产品数据库实体 3. 新增典型问题场景清单中间数据产品接口

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdMiddleServiceImpl.kt |   72 ++++++++++++++++++++++++++++++-----
 1 files changed, 61 insertions(+), 11 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdMiddleServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdMiddleServiceImpl.kt
index b6e4029..6d46bc9 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdMiddleServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/DataProdMiddleServiceImpl.kt
@@ -3,13 +3,12 @@
 import cn.flightfeather.supervision.common.utils.Constant
 import cn.flightfeather.supervision.common.utils.QueryByCache
 import cn.flightfeather.supervision.domain.ds1.entity.SceneConstructionSite
+import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
 import cn.flightfeather.supervision.lightshare.service.DataProdBaseService
 import cn.flightfeather.supervision.lightshare.service.DataProdMiddleService
 import cn.flightfeather.supervision.lightshare.vo.dataprod.QueryOpt
-import cn.flightfeather.supervision.lightshare.vo.dataprod.middle.DPEvaluationByArea
-import cn.flightfeather.supervision.lightshare.vo.dataprod.middle.DPInspectionSummary
-import cn.flightfeather.supervision.lightshare.vo.dataprod.middle.DPProblemCountByArea
-import cn.flightfeather.supervision.lightshare.vo.dataprod.middle.DPProblemTypeCount
+import cn.flightfeather.supervision.lightshare.vo.dataprod.middle.*
+import org.springframework.beans.BeanUtils
 import org.springframework.stereotype.Service
 
 /**
@@ -18,7 +17,10 @@
  * @author feiyu02
  */
 @Service
-class DataProdMiddleServiceImpl(private val dataProdBaseService: DataProdBaseService) : DataProdMiddleService {
+class DataProdMiddleServiceImpl(
+    private val dataProdBaseService: DataProdBaseService, private val taskRep: TaskRep,
+) : DataProdMiddleService {
+
 
     override fun getInspectionSummary(queryOpt: QueryOpt): DPInspectionSummary {
         return QueryByCache.queryCache(
@@ -34,7 +36,7 @@
                     when (it.scene?.typeid.toString()) {
                         // 瀵逛簬寤虹瓚宸ュ湴绫诲瀷锛屾牴鎹叾csStatus鍒ゆ柇鏄惁鍋滃伐鎴栧畬宸�
                         Constant.SceneType.TYPE1.value -> {
-                            when ((it.subScene as SceneConstructionSite).csStatus) {
+                            when ((it.subScene as SceneConstructionSite?)?.csStatus) {
                                 "鍋滃伐" -> {
                                     res.stopSceneCount++
                                 }
@@ -54,7 +56,6 @@
                 }
                 return@queryCache res
             },
-            save = {}
         )
     }
 
@@ -62,6 +63,16 @@
         return QueryByCache.queryCache(
             cache = { return@queryCache null },
             calculate = {
+                // 鏌ヨ涓婁竴涓懆鏈熺殑鎬讳换鍔$粺璁℃儏鍐�
+                val lastTopTask = taskRep.findLastTopTask(queryOpt.topTaskId)
+                val lastQueryOpt = QueryOpt()
+                BeanUtils.copyProperties(queryOpt, lastQueryOpt)
+                lastQueryOpt.topTaskId = lastTopTask?.tguid
+                val lastInspectionInfo = dataProdBaseService.getInspectionInfo(lastQueryOpt)
+                val lastAllProblemList = lastInspectionInfo.flatMap { it.problems ?: emptyList() }
+                val lastAllProblemMap = lastAllProblemList.groupBy { it.typeid }
+
+                // 鏌ヨ褰撳墠鍛ㄦ湡鐨勬�讳换鍔$粺璁℃儏鍐�
                 val res = mutableListOf<DPProblemTypeCount>()
                 val inspectionInfo = dataProdBaseService.getInspectionInfo(queryOpt)
                 val allProblemList = inspectionInfo.flatMap { it.problems ?: emptyList() }
@@ -71,11 +82,16 @@
                         this.typeName = problemList.firstOrNull()?.typename
                         this.count = problemList.size
                         this.ratio = problemList.size.toDouble() / allProblemList.size
+                        this.ratioDiff =
+                            if (lastAllProblemMap[typeid] == null) {
+                                this.ratio
+                            } else {
+                                this.ratio - lastAllProblemMap[typeid]!!.size.toDouble() / lastAllProblemList.size
+                            }
                     })
                 }
                 return@queryCache res
             },
-            save = {}
         )
     }
 
@@ -101,13 +117,12 @@
                             this.townName = firstSubtask?.townname
                             this.sceneCount = ins.distinctBy { it.subTask?.scenseid }.size
                             this.problemCount = allProblemList.size
-                            this.ratio = problemCount.toDouble() / sceneCount
+                            this.proAvg = problemCount.toDouble() / sceneCount
                         })
                     }
 
                 return@queryCache res
             },
-            save = {}
         )
     }
 
@@ -147,7 +162,42 @@
 
                 return@queryCache res
             },
-            save = {}
+        )
+    }
+
+    override fun getTypicalProblems(queryOpt: QueryOpt, rateTotal: Double): List<DPTypicalProblemScene> {
+        return QueryByCache.queryCache(
+            cache = { return@queryCache null },
+            calculate = {
+                val res = mutableListOf<DPTypicalProblemScene>()
+                val inspectionInfo = dataProdBaseService.getInspectionInfo(queryOpt)
+                inspectionInfo.groupBy { it.subTask?.scenseid }.forEach { (sceneId, ins) ->
+                    val problems = ins.flatMap { it.problems ?: emptyList() }
+                    if (problems.isEmpty()) return@forEach
+
+                    val unChangePros = problems.filter { it.ischanged != true }
+                    val changeRatio = if (problems.isNotEmpty()) {
+                        (problems.size - unChangePros.size.toDouble()) / problems.size
+                    } else {
+                        0.0
+                    }
+                    if (changeRatio < rateTotal) {
+                        res.add(DPTypicalProblemScene().apply {
+                            val firstSubtask = ins.first().subTask
+                            this.sceneId = sceneId
+                            this.sceneName = firstSubtask?.scensename
+                            this.townCode = firstSubtask?.towncode
+                            this.townName = firstSubtask?.townname
+                            this.problemCount = problems.size
+                            this.changeCount = problems.size - unChangePros.size
+                            this.changeRatio = changeRatio
+                            this.typicalProblems = unChangePros
+                                .distinctBy { it.ptguid }
+                        })
+                    }
+                }
+                return@queryCache res
+            },
         )
     }
 }
\ No newline at end of file

--
Gitblit v1.9.3