feiyu02
2025-12-20 5a003a42d2b34e8362910ac1d3e5a8866768e5fe
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/TaskServiceImpl.kt
@@ -339,14 +339,6 @@
            val filterSubTasks = subTasks.filter {s->
                s?.tsguid == t?.tguid
            }
            // 子任务总数
            val total = filterSubTasks.size
            // 子任务完成数
            val complete = filterSubTasks.count {fs->
                fs?.status == Constant.TaskProgress.RUNINGSTATUS3.text
            }
            // 获取当日所有的问题
            val subTaskIds = filterSubTasks.map { fs-> fs?.stguid }
            val problemList = if (subTaskIds.isNotEmpty()) {
@@ -356,8 +348,69 @@
            } else{
                emptyList()
            }
            /** 总巡查量统计 **/
            // 子任务总数
            val total = filterSubTasks.size
            // 子任务完成数
            val complete = filterSubTasks.count {fs->
                fs?.status == Constant.TaskProgress.RUNINGSTATUS3.text
            }
            /** 总问题整改率统计 **/
            // 总问题数和总整改数
            val totalProblemNum = problemList.size
            val changedProblemNum = problemList.filter { it.ischanged == true }.size
            /** 每个人的巡查量问题整改率 **/
            val userProgressMap = mutableMapOf<String, ProgressPerUserPerDay>()
            filterSubTasks.forEach fst@ { fst->
                fst ?: return@fst
                // fixme 2025.11.30 由于监管APP的bug,导致用户可以不选择执行人员直接创建任务,所以暂时将没有执行人员的任务定义为匿名用户
                if (fst.executorguids.isNullOrBlank()) {
                    fst.executorguids = "niming"
                    fst.executorusernames = "niming"
                    fst.executorrealtimes = "匿名用户"
                }
                val ids = fst.executorguids?.split("#") ?: return@fst
                val names = fst.executorrealtimes?.split("#") ?: return@fst
                // 筛选每个子任务下的问题
                val proList = problemList.filter { p-> p?.stguid == fst.stguid }
                for (i in ids.indices) {
                    val key = ids[i]
                    if (!userProgressMap.containsKey(key)) {
                        userProgressMap[key] = ProgressPerUserPerDay().apply {
                            this.userId = key
                            this.userName = names[i]
                        }
                    }
                    userProgressMap[key]?.apply {
                        // 单人巡查量累计
                        // 当多个人一起执行同一任务时,平分巡查量
                        this.totalTaskNum += 1.0 / ids.size
                        if (fst.status== Constant.TaskProgress.RUNINGSTATUS3.text)
                            this.completeTaskNum += 1.0 / ids.size
                        // 单人整改率累计(评分)
                        this.totalProblemNum += proList.size.toDouble() / ids.size
                        this.changedProblemNum += proList.filter { it.ischanged == true }.size.toDouble() / ids.size
                        this.changedProblemNumOnTime += proList.filter {
                            // 整改耗时(天)
                            val day = ((it.changedtime?.time ?: 0L) - (it?.time?.time ?: 0L)).div(1000 * 60 * 60 * 24)
                            it.ischanged == true &&  day <= 1
                        }.size.toDouble() / ids.size
                        // 此处先累计巡查时长,最后再根据任务数量平均
                        this.avgInspectionTime +=
                            ((fst.executionendtime?.time ?: 0L) - (fst.executionstarttime?.time ?: 0L)).div(1000).div(ids.size)
                    }
                }
            }
            // 统一计算平均巡查时长(秒)
            userProgressMap.forEach { (t, u) ->
                u.avgInspectionTime = (u.avgInspectionTime / u.completeTaskNum).toLong()
                u.formatParam()
            }
            /** 任务整改完成情况和审核情况统计 **/
            var changed = 0
            //审核是否完成
            var check = true
@@ -376,9 +429,18 @@
                }
            }
            resultList.add(DayTaskProgressVo(
                t?.tguid, t?.starttime, taskId, complete, changed, total, check
            ))
            resultList.add(DayTaskProgressVo().apply {
                this.guid =t?.tguid
                this.date =t?.starttime
                this.tsGuid = taskId
                this.totalTaskNum = total
                this.completeTaskNum = complete
                this.changedTaskNum = changed
                this.check = check
                this.totalProblemNum = totalProblemNum
                this.changedProblemNum = changedProblemNum
                this.progressPerUser = userProgressMap.entries.map { it.value }
            })
        }
        return resultList