| | |
| | | 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 |
| | | import cn.flightfeather.supervision.lightshare.service.* |
| | |
| | | import org.springframework.beans.factory.annotation.Autowired |
| | | import org.springframework.stereotype.Service |
| | | import tk.mybatis.mapper.entity.Example |
| | | import java.time.LocalDateTime |
| | | import java.time.ZoneId |
| | | import java.util.* |
| | | import kotlin.collections.ArrayList |
| | | |
| | |
| | | val taskMapper: TaskMapper, |
| | | private val taskRep: TaskRep, |
| | | private val subTaskRep: SubTaskRep, |
| | | private val sceneRep: SceneRep, |
| | | private val scenseMapper: ScenseMapper, |
| | | ) : TaskService { |
| | | |
| | | @Autowired |
| | |
| | | return taskVoList |
| | | } |
| | | |
| | | override fun getDayTask(taskId: String, userId: String, userType: String): List<DayTaskProgressVo> { |
| | | val example = Example(Task::class.java) |
| | | val criteria = example.createCriteria() |
| | | //构造查询条件 |
| | | criteria.andEqualTo("tsguid", taskId) |
| | | if (userType == "1") { |
| | | criteria.andLike("executorguids", "%$userId%") |
| | | } |
| | | |
| | | override fun getDayTask(taskId: String, userId: String?, userType: String, sceneTypeId: String?): List<DayTaskProgressVo> { |
| | | val resultList = ArrayList<DayTaskProgressVo>() |
| | | |
| | | // 获取总任务下所有日任务 |
| | | val dayTasks = if (userType == "1") { |
| | | taskRep.findDayTasks(taskId, userId) |
| | | } else { |
| | | taskRep.findDayTasks(taskId) |
| | | } |
| | | |
| | | // 获取总任务下所有的子任务 |
| | | 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条件查询 |
| | | taskMapper.selectByExample(example).forEach { |
| | | val exampleTotal = Example(Subtask::class.java).apply { |
| | | createCriteria().andEqualTo("tsguid", it.tguid) |
| | | dayTasks.forEach { t -> |
| | | // 筛选当前日任务下的子任务 |
| | | 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 problemList = if (subTaskIds.isNotEmpty()) { |
| | | problemListMapper.selectByExample(Example(Problemlist::class.java).apply { |
| | | createCriteria().andIn("stguid", subTaskIds) |
| | | }) |
| | | } else { |
| | | emptyList() |
| | | } |
| | | |
| | | val total = subtaskMapper.selectCountByExample(exampleTotal) |
| | | |
| | | val exampleComplete = exampleTotal.apply { |
| | | and().andEqualTo("status", Constant.TaskProgress.RUNINGSTATUS3.text) |
| | | /** 总巡查量统计 **/ |
| | | // 子任务总数 |
| | | val total = filterSubTasks.size |
| | | // 子任务完成数 |
| | | val complete = filterSubTasks.count { fs -> |
| | | fs?.status == Constant.TaskProgress.RUNINGSTATUS3.text |
| | | } |
| | | val complete = subtaskMapper.selectCountByExample(exampleComplete) |
| | | |
| | | var changed = 0 |
| | | problemListMapper.findUnchangedCount(it.tguid ?: "").forEach { i -> |
| | | //结果表示该子任务未整改问题数 |
| | | if (i == 0) { |
| | | changed++ |
| | | /** 总问题整改率统计 **/ |
| | | // 总问题数和总整改数 |
| | | 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 _changedDate = it.changedtime?.let { c-> |
| | | LocalDateTime.ofInstant(c.toInstant(), ZoneId.systemDefault()).toLocalDate() |
| | | } |
| | | val _proDate = it.time?.let { t-> |
| | | LocalDateTime.ofInstant(t.toInstant(), ZoneId.systemDefault()).toLocalDate() |
| | | } |
| | | val isSameDay = _changedDate?.equals(_proDate) |
| | | it.ischanged == true && (isSameDay ?: false) |
| | | }.size.toDouble() / ids.size |
| | | this.efficientChangedProNum += proList.filter { |
| | | // 整改耗时(天) |
| | | val day = ((it.changedtime?.time ?: 0L) - (it?.time?.time ?: 0L)).div(1000 * 60 * 60 * 24) |
| | | it.ischanged == true && day <= 2 |
| | | }.size.toDouble() / ids.size |
| | | // 此处先累计巡查时长,最后再根据任务数量平均 |
| | | this.avgInspectionTime += if (fst.executionendtime == null || fst.executionstarttime == null) { |
| | | 0 |
| | | } else { |
| | | (fst.executionendtime!!.time - fst.executionstarttime!!.time).div(1000).div(ids.size) |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | // 统一计算平均巡查时长(秒) |
| | | userProgressMap.forEach { (t, u) -> |
| | | u.avgInspectionTime = if (u.completeTaskNum == .0 ) 0 else (u.avgInspectionTime / u.completeTaskNum).toLong() |
| | | u.formatParam() |
| | | } |
| | | |
| | | /** 任务整改完成情况和审核情况统计 **/ |
| | | var changed = 0 |
| | | //审核是否完成 |
| | | var check = false |
| | | with(subtaskMapper.selectByExample(exampleTotal)) breaking@{ |
| | | forEach { |
| | | problemListMapper.selectByExample(Example(Problemlist::class.java).apply { |
| | | createCriteria().andEqualTo("stguid", it.stguid) |
| | | }).forEach { problem -> |
| | | if (problem.extension3 == Constant.PROBLEM_UNCHECKED) { |
| | | check = true |
| | | return@breaking |
| | | } |
| | | var check = true |
| | | filterSubTasks.forEach { fs -> |
| | | // 筛选每个子任务下的问题未整改数 |
| | | problemList.filter { p -> p?.stguid == fs?.stguid }.onEach { pro -> |
| | | // 当存在至少一个问题没有审核时,当日审核状态为未审核 |
| | | if (pro.extension3 == Constant.PROBLEM_UNCHECKED || pro.extension3 == Constant.CHANGE_UNCHECKED) { |
| | | check = false |
| | | } |
| | | }.count { i -> i?.ischanged != true }.let { c -> |
| | | // 没有未整改问题时,则表示该子任务已经整改完成 |
| | | if (c == 0) { |
| | | changed++ |
| | | } |
| | | } |
| | | } |
| | | |
| | | resultList.add(DayTaskProgressVo( |
| | | it.tguid, it.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 |
| | |
| | | districtName = t.districtname |
| | | townCode = t.towncode |
| | | townName = t.townname |
| | | |
| | | var count = 0 |
| | | val countByScene = mutableMapOf<String?, Int>() |
| | | val allScenes = sceneRep.findSceneList(t.tguid!!, areaVo.scensetypeid?.toInt(), areaVo.towncode) |
| | | taskRep.findMonitorList(t.tguid!!, areaVo.scensetypeid).forEach { |
| | | val c = if (it.extension1 != null) it.extension1!!.toInt() else 1 |
| | | val c = it.monitornum ?: 1 |
| | | count += c |
| | | |
| | | allScenes.find { s-> s?.guid == it.sguid }?.let { s-> |
| | | // if (!countByScene.containsKey(s.type)) { |
| | | // countByScene[s.type] = 0 |
| | | // } |
| | | countByScene[s.type] = (countByScene[s.type] ?: 0) + c |
| | | } |
| | | } |
| | | totaltask = count |
| | | subTaskSummary = subTaskRep.findSummary(areaVo) |
| | | totaltaskByScene = countByScene |
| | | |
| | | subTaskSummary = subTaskRep.findSummary(AreaVo().apply { |
| | | topTaskId = t.tguid |
| | | }) |
| | | val completeByScene = mutableMapOf<String?, Int>() |
| | | subTaskSummary?.forEach { |
| | | completeByScene[it.sceneType] = (completeByScene[it.sceneType] ?: 0) + 1 |
| | | } |
| | | completetask = this.subTaskSummary?.size |
| | | completetaskByScene = completeByScene |
| | | } |
| | | res.add(pro) |
| | | } |