| | |
| | | package cn.flightfeather.supervision.lightshare.service.impl |
| | | |
| | | import cn.flightfeather.supervision.common.exception.BizException |
| | | import cn.flightfeather.supervision.domain.ds1.entity.Problemlist |
| | | import cn.flightfeather.supervision.domain.ds1.entity.Subtask |
| | | import cn.flightfeather.supervision.domain.ds1.entity.Task |
| | |
| | | import cn.flightfeather.supervision.domain.ds1.mapper.TaskMapper |
| | | 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 |
| | |
| | | townRank.standardRate = it.get("standardRate").toString().toFloat() |
| | | } catch (e: Exception) { |
| | | } |
| | | val s =it.get("hasScoredNum").toString() |
| | | val s = it.get("hasScoredNum").toString() |
| | | try { |
| | | townRank.hasScoredNum = it.get("hasScoredNum").toString().toInt() |
| | | } catch (e: Exception) { |
| | |
| | | if (type == 0) |
| | | return getAllTop() |
| | | //获取未完成顶层任务及对应日任务列表 |
| | | else if (type == 1){ |
| | | else if (type == 1) { |
| | | val tmp = getAllTop() |
| | | tmp.forEach { |
| | | if (it.runingstatus != Constant.TaskProgress.RUNINGSTATUS3.text) { |
| | |
| | | } |
| | | |
| | | //根据日期获取日任务 |
| | | override fun findByDate(date: String): TaskVo { |
| | | override fun findByDate(topTaskId: String, date: String): TaskVo { |
| | | val taskVo = TaskVo() |
| | | val example = Example(Task::class.java) |
| | | val criteria = example.createCriteria() |
| | | //gsguid不为空为日任务,日任务开始时间和结束时间在同一天,过滤开始时间就ok |
| | | criteria.andEqualTo("starttime", DateUtil.StringToDate(date.substring(0, 10))) |
| | | criteria.andIsNotNull("tsguid") |
| | | criteria.andEqualTo("tsguid", topTaskId) |
| | | val tasklist = taskMapper.selectByExample(example) |
| | | if (tasklist.isNotEmpty()) { |
| | | BeanUtils.copyProperties(tasklist[0], taskVo) |
| | |
| | | // .andEqualTo("districtcode", districtCode) |
| | | // .andLessThanOrEqualTo("endtime", date) |
| | | // example.or( |
| | | example.createCriteria().andIsNull("tsguid") |
| | | .andEqualTo("districtcode", districtCode) |
| | | .andLessThanOrEqualTo("starttime", date) |
| | | .andGreaterThanOrEqualTo("endtime", date) |
| | | example.createCriteria().andIsNull("tsguid") |
| | | .andEqualTo("districtcode", districtCode) |
| | | .andLessThanOrEqualTo("starttime", date) |
| | | .andGreaterThanOrEqualTo("endtime", date) |
| | | // ) |
| | | example.orderBy("starttime").desc() |
| | | val tasklist = taskMapper.selectByExample(example) |
| | |
| | | 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 }) |
| | | // 获取所有子任务涉及的巡查场景信息 |
| | | val sceneList = if (subTasks.isEmpty()) { |
| | | emptyList() |
| | | } else { |
| | | 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 |
| | | // 2026.2.2 将没有执行人员的任务定义为匿名用户 |
| | | 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 |
| | |
| | | |
| | | val criteria2 = example.createCriteria() |
| | | criteria2.orBetween( |
| | | "endtime", |
| | | startDate, |
| | | endDate |
| | | "endtime", |
| | | startDate, |
| | | endDate |
| | | ).andIsNull("tsguid"); |
| | | if (userType == "1") { |
| | | criteria2.andLike("executorguids", "%$guid%") |
| | | } else if (userType == "2"){ |
| | | } else if (userType == "2") { |
| | | criteria2.andEqualTo("districtcode", districtCode) |
| | | } |
| | | example.or(criteria2) |
| | | |
| | | val criteria3 = example.createCriteria() |
| | | criteria3.orLessThan("starttime", startDate).andGreaterThan( |
| | | "endtime", |
| | | endDate |
| | | "endtime", |
| | | endDate |
| | | ).andIsNull("tsguid"); |
| | | if (userType == "1") { |
| | | criteria3.andLike("executorguids", "%$guid%") |
| | | } else if (userType == "2"){ |
| | | } else if (userType == "2") { |
| | | criteria3.andEqualTo("districtcode", districtCode) |
| | | } |
| | | example.or(criteria3) |
| | |
| | | } |
| | | return taskVoList |
| | | } |
| | | |
| | | |
| | | override fun save(task: Task): Int { |
| | | // FIXME: 2021/10/9 按照当前的逻辑,此函数主要用于新建顶层任务以及日任务,但是日任务内容的生成逻辑目前由前端app完成,因此会出现一个bug: |
| | | // FIXME: 2021/10/9 当前端多个用户同时在同一个顶层任务下的新的一天创建任务时,会出现同一天有多个日任务,此时前端后续查看只能看到其中一个日任务下的子任务 |
| | |
| | | // FIXME: 2021/10/9 另外对于顶层任务也添加类似逻辑,由于顶层任务的任务名称默认系统自动生成,因此暂时只判断同名的顶层任务,当存在同名顶层任务时,不做保存操作 |
| | | |
| | | var result = 0 |
| | | if (task.tguid == null) task.tguid = UUIDGenerator.generate16ShortUUID() |
| | | // 1、首先判断是顶层任务还是日任务 |
| | | if (task.levelnum == 2) { |
| | | //2.1、 是顶层任务时,判断是否已有同名任务 |
| | |
| | | } |
| | | } else { |
| | | //3.1、 当是日任务时,判断在同一个顶层任务下,是否有同名的日任务 |
| | | val r =taskMapper.selectByExample(Example(Task::class.java).apply { |
| | | val r = taskMapper.selectByExample(Example(Task::class.java).apply { |
| | | createCriteria().andEqualTo("tsguid", task.tsguid) |
| | | .andEqualTo("name", task.name) |
| | | }) |
| | |
| | | return result |
| | | } |
| | | |
| | | override fun create(task: Task): Task { |
| | | val res = save(task) |
| | | if (res < 1) |
| | | throw BizException("总任务或当日任务创建失败") |
| | | else |
| | | return task |
| | | } |
| | | |
| | | //修改日任务信息,若有子任务,子任务也修改 |
| | | override fun update(task: Task): Int { |
| | | var re = 1 |
| | |
| | | BeanUtils.copyProperties(it, subtask) |
| | | subtask.planstarttime = task.starttime |
| | | subtask.planendtime = task.endtime |
| | | subtaskService.update(subtask) |
| | | subtaskService.changeStatus(subtask) |
| | | } |
| | | } |
| | | return re |
| | |
| | | criteria.andIsNull("tsguid") |
| | | example.orderBy("starttime").asc() |
| | | val result = taskMapper.selectByExample(example) |
| | | if (result.isNotEmpty()){ |
| | | if (result.isNotEmpty()) { |
| | | result.forEach { |
| | | var mytotalcount = 0 |
| | | var mycompletecount = 0 |
| | |
| | | taskProgressVo.mycompletetask = mycompletecount |
| | | val daytaskVolist = getDayTaskByTaskID(it.tguid!!) |
| | | val daytasklist = mutableListOf<TaskVo>() |
| | | if (daytaskVolist.isNotEmpty()){ |
| | | if (daytaskVolist.isNotEmpty()) { |
| | | daytaskVolist.forEach { |
| | | var mytotalcount1 = 0 |
| | | var mycompletecount1 = 0 |
| | |
| | | if (Objects.equals(it.status!!, Constant.TaskProgress.RUNINGSTATUS3.text)) |
| | | mycompletecount1++ |
| | | } |
| | | if(Objects.equals(it.status, Constant.TaskProgress.RUNINGSTATUS3.text)) |
| | | if (Objects.equals(it.status, Constant.TaskProgress.RUNINGSTATUS3.text)) |
| | | completecount1++ |
| | | } |
| | | val daytaskProgressVo = TaskVo() |
| | |
| | | |
| | | override fun findTaskProgress(areaVo: AreaVo): List<TaskProgressVo?> { |
| | | val res = mutableListOf<TaskProgressVo?>() |
| | | taskRep.findTasks(areaVo).forEach {t-> |
| | | taskRep.findTasks(areaVo).forEach { t -> |
| | | if (t?.tguid == null) return@forEach |
| | | val pro = TaskProgressVo().apply { |
| | | tguid = t.tguid |
| | |
| | | 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) |
| | | } |