From 2302c9f0336f7ae4acae0583412ddc396645a0ed Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期一, 22 十二月 2025 17:22:31 +0800
Subject: [PATCH] 2025.12.22 巡查任务统计相关功能修改

---
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/TaskService.kt                 |    2 
 src/main/kotlin/cn/flightfeather/supervision/lightshare/web/TaskController.kt                  |    5 +-
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/TaskServiceImpl.kt        |   44 ++++++++++++++--------
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ProblemlistService.kt          |    2 
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt     |    2 
 src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt |   38 +++++++++++-------
 6 files changed, 57 insertions(+), 36 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ProblemlistService.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ProblemlistService.kt
index cdf3f43..f61a1bd 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ProblemlistService.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/ProblemlistService.kt
@@ -37,7 +37,7 @@
 
     fun getProblemByScene(sceneId: String, date: String):List<ProblemListVo>
 
-    fun getBySceneMonth(sceneId: String, year: Int?, month: Int?):List<ProblemListVo>
+    fun getBySceneMonth(sceneId: String, year: Int?, month: Int?):Pair<List<SubtaskVo>, List<ProblemListVo>>
 
     fun findMonthProblemById(taskId:String, sceneId:Int?):List<MonthProblemVo>
 
diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/TaskService.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/TaskService.kt
index 6046e69..07a4260 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/TaskService.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/TaskService.kt
@@ -30,7 +30,7 @@
 
     fun getDayTaskList(taskVoList: List<TaskVo>, date: String, guid: String, userType: String): List<TaskVo>
 
-    fun getDayTask(taskId: String, userId: String?, userType: String): List<DayTaskProgressVo>
+    fun getDayTask(taskId: String, userId: String?, userType: String, sceneTypeId: String?): List<DayTaskProgressVo>
 
     fun findByName(name: String): TaskVo
 
diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt
index 264e239..add0297 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ProblemlistServiceImpl.kt
@@ -40,6 +40,8 @@
     val problemlistMapper: ProblemlistMapper,
     val inspectionMapper: InspectionMapper,
     val mediafileMapper: MediafileMapper,
+    private val subtaskService: SubtaskService,
+    private val subtaskMapper: SubtaskMapper,
     private val taskRep: TaskRep,
     private val subTaskRep: SubTaskRep,
     private val problemRep: ProblemRep,
@@ -106,34 +108,40 @@
         return problemListVolistTemp1
     }
 
-    override fun getBySceneMonth(sceneId: String, year: Int?, month: Int?): List<ProblemListVo> {
+    override fun getBySceneMonth(sceneId: String, year: Int?, month: Int?): Pair<List<SubtaskVo>, List<ProblemListVo>> {
         var _year = year
         var _month = month
+        var lastSubTasks = listOf<SubtaskVo>()
         if (year == null) {
-            PageHelper.startPage<Problemlist>(1, 1)
-            val lastProblem = problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
-                createCriteria().andEqualTo("sguid", sceneId)
-                orderBy("time").desc()
-            }).takeIf { it.isNotEmpty() }?.get(0)
-            if (lastProblem == null) {
-                return emptyList()
+            lastSubTasks = subtaskService.findByDate(sceneId = sceneId)
+//            PageHelper.startPage<Problemlist>(1, 1)
+//            val lastProblem = problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
+//                createCriteria().andEqualTo("sguid", sceneId)
+//                orderBy("time").desc()
+//            }).takeIf { it.isNotEmpty() }?.get(0)
+            if (lastSubTasks.isEmpty()) {
+                return lastSubTasks to emptyList()
             } else {
-                val lt = LocalDateTime.ofInstant(lastProblem.time?.toInstant(), ZoneId.systemDefault())
+                val lt = LocalDateTime.ofInstant(lastSubTasks[0].planstarttime?.toInstant(), ZoneId.systemDefault())
                 _year = lt.year
                 _month = lt.monthValue
             }
         }
         val sT = LocalDateTime.of(_year!!, _month!!, 1, 0, 0, 0, 0)
         val eT = sT.plusMonths(1).minusSeconds(1)
-        return problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
+        if (lastSubTasks.isEmpty()) {
+            lastSubTasks = subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
+                createCriteria().andBetween("planstarttime", sT, eT)
+            }).map {
+                SubtaskVo().apply { BeanUtils.copyProperties(it, this) }
+            }
+        }
+        val problemList = problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
             createCriteria().andBetween("time", sT,eT)
                 .andEqualTo("sguid", sceneId)
             orderBy("time").desc()
-        }).map {
-            val problemVo = ProblemListVo();
-            BeanUtils.copyProperties(it, problemVo)
-            problemVo
-        }
+        }).map { ProblemListVo().apply { BeanUtils.copyProperties(it, this) } }
+        return lastSubTasks to problemList
     }
 
     //鑾峰彇鏌愰《灞備换鍔′笅锛屾煇涓満鏅笅鐨勯棶棰樻暣鏀规儏鍐�
diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt
index d264f3c..d3c51fd 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/SubtaskServiceImpl.kt
@@ -950,7 +950,7 @@
                     .apply { sceneId?.let { andEqualTo("scenseid", it) } }
             })
         } else {
-            // 鑾峰彇鏈�杩戜竴涓湀鍐呯殑锛堟煇涓満鏅殑锛夋墍鏈夊贰鏌ヤ换鍔�
+            // 鑾峰彇鏈�杩戜竴娆℃�讳换鍔″唴鐨勶紙鏌愪釜鍦烘櫙鐨勶級鎵�鏈夊贰鏌ヤ换鍔�
             PageHelper.startPage<Subtask>(1, 1)
             val lastOne = subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
                 createCriteria().apply {
diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/TaskServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/TaskServiceImpl.kt
index 61140aa..7fd361b 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/TaskServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/TaskServiceImpl.kt
@@ -10,6 +10,8 @@
 import cn.flightfeather.supervision.common.utils.Constant
 import cn.flightfeather.supervision.common.utils.DateUtil
 import cn.flightfeather.supervision.common.utils.UUIDGenerator
+import cn.flightfeather.supervision.domain.ds1.entity.Scense
+import cn.flightfeather.supervision.domain.ds1.mapper.ScenseMapper
 import cn.flightfeather.supervision.domain.ds1.repository.SceneRep
 import cn.flightfeather.supervision.domain.ds1.repository.SubTaskRep
 import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
@@ -28,6 +30,7 @@
     private val taskRep: TaskRep,
     private val subTaskRep: SubTaskRep,
     private val sceneRep: SceneRep,
+    private val scenseMapper: ScenseMapper,
 ) : TaskService {
 
     @Autowired
@@ -320,7 +323,7 @@
         return taskVoList
     }
 
-    override fun getDayTask(taskId: String, userId: String?, userType: String): List<DayTaskProgressVo> {
+    override fun getDayTask(taskId: String, userId: String?, userType: String, sceneTypeId: String?): List<DayTaskProgressVo> {
         val resultList = ArrayList<DayTaskProgressVo>()
 
         // 鑾峰彇鎬讳换鍔′笅鎵�鏈夋棩浠诲姟
@@ -332,29 +335,37 @@
 
         // 鑾峰彇鎬讳换鍔′笅鎵�鏈夌殑瀛愪换鍔�
         val subTasks = subTaskRep.findAll(Subtask().apply { tguid = taskId })
+        if (subTasks.isEmpty()) return emptyList()
+        // 鑾峰彇鎵�鏈夊瓙浠诲姟娑夊強鐨勫贰鏌ュ満鏅俊鎭�
+        val sceneList = scenseMapper.selectByExample(Example(Scense::class.java).apply {
+            createCriteria().andIn("guid", subTasks.map { it?.scenseid })
+        })
 
         //鏍规嵁sql鏉′欢鏌ヨ
-        dayTasks.forEach {t->
+        dayTasks.forEach { t ->
             // 绛涢�夊綋鍓嶆棩浠诲姟涓嬬殑瀛愪换鍔�
-            val filterSubTasks = subTasks.filter {s->
-                s?.tsguid == t?.tguid
+            val filterSubTasks = subTasks.filter { s ->
+                val scene = sceneList.find { it?.guid == s?.scenseid }
+                s?.tsguid == t?.tguid && (sceneTypeId.isNullOrBlank() || scene?.typeid.toString() == sceneTypeId)
             }
             // 鑾峰彇褰撴棩鎵�鏈夌殑闂
-            val subTaskIds = filterSubTasks.map { fs-> fs?.stguid }
+            val subTaskIds = filterSubTasks.map { fs -> fs?.stguid }
             val problemList = if (subTaskIds.isNotEmpty()) {
                 problemListMapper.selectByExample(Example(Problemlist::class.java).apply {
                     createCriteria().andIn("stguid", subTaskIds)
                 })
-            } else{
+            } else {
                 emptyList()
             }
+
             /** 鎬诲贰鏌ラ噺缁熻 **/
             // 瀛愪换鍔℃�绘暟
             val total = filterSubTasks.size
             // 瀛愪换鍔″畬鎴愭暟
-            val complete = filterSubTasks.count {fs->
+            val complete = filterSubTasks.count { fs ->
                 fs?.status == Constant.TaskProgress.RUNINGSTATUS3.text
             }
+
             /** 鎬婚棶棰樻暣鏀圭巼缁熻 **/
             // 鎬婚棶棰樻暟鍜屾�绘暣鏀规暟
             val totalProblemNum = problemList.size
@@ -362,7 +373,7 @@
 
             /** 姣忎釜浜虹殑宸℃煡閲忛棶棰樻暣鏀圭巼 **/
             val userProgressMap = mutableMapOf<String, ProgressPerUserPerDay>()
-            filterSubTasks.forEach fst@ { fst->
+            filterSubTasks.forEach fst@{ fst ->
                 fst ?: return@fst
                 // fixme 2025.11.30 鐢变簬鐩戠APP鐨刡ug锛屽鑷寸敤鎴峰彲浠ヤ笉閫夋嫨鎵ц浜哄憳鐩存帴鍒涘缓浠诲姟锛屾墍浠ユ殏鏃跺皢娌℃湁鎵ц浜哄憳鐨勪换鍔″畾涔変负鍖垮悕鐢ㄦ埛
                 if (fst.executorguids.isNullOrBlank()) {
@@ -373,7 +384,7 @@
                 val ids = fst.executorguids?.split("#") ?: return@fst
                 val names = fst.executorrealtimes?.split("#") ?: return@fst
                 // 绛涢�夋瘡涓瓙浠诲姟涓嬬殑闂
-                val proList = problemList.filter { p-> p?.stguid == fst.stguid }
+                val proList = problemList.filter { p -> p?.stguid == fst.stguid }
                 for (i in ids.indices) {
                     val key = ids[i]
                     if (!userProgressMap.containsKey(key)) {
@@ -386,8 +397,9 @@
                         // 鍗曚汉宸℃煡閲忕疮璁�
                         // 褰撳涓汉涓�璧锋墽琛屽悓涓�浠诲姟鏃讹紝骞冲垎宸℃煡閲�
                         this.totalTaskNum += 1.0 / ids.size
-                        if (fst.status== Constant.TaskProgress.RUNINGSTATUS3.text)
-                            this.completeTaskNum += 1.0 / ids.size
+                        if (fst.status == Constant.TaskProgress.RUNINGSTATUS3.text) {
+                        }
+                        this.completeTaskNum += 1.0 / ids.size
 
                         // 鍗曚汉鏁存敼鐜囩疮璁★紙璇勫垎锛�
                         this.totalProblemNum += proList.size.toDouble() / ids.size
@@ -395,7 +407,7 @@
                         this.changedProblemNumOnTime += proList.filter {
                             // 鏁存敼鑰楁椂锛堝ぉ锛�
                             val day = ((it.changedtime?.time ?: 0L) - (it?.time?.time ?: 0L)).div(1000 * 60 * 60 * 24)
-                            it.ischanged == true &&  day <= 1
+                            it.ischanged == true && day <= 1
                         }.size.toDouble() / ids.size
                         // 姝ゅ鍏堢疮璁″贰鏌ユ椂闀匡紝鏈�鍚庡啀鏍规嵁浠诲姟鏁伴噺骞冲潎
                         this.avgInspectionTime +=
@@ -414,9 +426,9 @@
             var changed = 0
             //瀹℃牳鏄惁瀹屾垚
             var check = true
-            filterSubTasks.forEach {fs ->
+            filterSubTasks.forEach { fs ->
                 // 绛涢�夋瘡涓瓙浠诲姟涓嬬殑闂鏈暣鏀规暟
-                problemList.filter { p-> p?.stguid == fs?.stguid }.onEach { pro ->
+                problemList.filter { p -> p?.stguid == fs?.stguid }.onEach { pro ->
                     // 褰撳瓨鍦ㄨ嚦灏戜竴涓棶棰樻病鏈夊鏍告椂锛屽綋鏃ュ鏍哥姸鎬佷负鏈鏍�
                     if (pro.extension3 == Constant.PROBLEM_UNCHECKED || pro.extension3 == Constant.CHANGE_UNCHECKED) {
                         check = false
@@ -430,8 +442,8 @@
             }
 
             resultList.add(DayTaskProgressVo().apply {
-                this.guid =t?.tguid
-                this.date =t?.starttime
+                this.guid = t?.tguid
+                this.date = t?.starttime
                 this.tsGuid = taskId
                 this.totalTaskNum = total
                 this.completeTaskNum = complete
diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/TaskController.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/TaskController.kt
index 5951258..bffd429 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/TaskController.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/web/TaskController.kt
@@ -63,8 +63,9 @@
     fun getDayTask(
             @PathVariable("taskId") taskId: String,
             @RequestParam("userId", required = false) userId: String?,
-            @RequestParam("userType") userType: String
-    ) = taskService.getDayTask(taskId, userId, userType)
+            @RequestParam("userType") userType: String,
+            @RequestParam(required = false) sceneTypeId: String?,
+    ) = taskService.getDayTask(taskId, userId, userType, sceneTypeId)
 
     @IgnoreResponseAdvice
     @GetMapping("/taskprogress/{userid}")

--
Gitblit v1.9.3