feiyu02
2025-09-30 a3cc1d220f8a1de11874bebceba0130d32157ff1
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/TaskServiceImpl.kt
@@ -1,5 +1,6 @@
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
@@ -8,6 +9,8 @@
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.repository.SceneRep
import cn.flightfeather.supervision.domain.ds1.repository.SubTaskRep
import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
import cn.flightfeather.supervision.lightshare.service.*
@@ -24,6 +27,7 @@
    val taskMapper: TaskMapper,
    private val taskRep: TaskRep,
    private val subTaskRep: SubTaskRep,
    private val sceneRep: SceneRep,
) : TaskService {
    @Autowired
@@ -104,7 +108,7 @@
                    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) {
@@ -164,7 +168,7 @@
        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) {
@@ -178,13 +182,13 @@
    }
    //根据日期获取日任务
    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)
@@ -223,10 +227,10 @@
//                .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)
@@ -316,55 +320,64 @@
        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): 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 })
        //根据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->
                s?.tsguid == t?.tguid
            }
            // 子任务总数
            val total = filterSubTasks.size
            // 子任务完成数
            val complete = filterSubTasks.count {fs->
                fs?.status == Constant.TaskProgress.RUNINGSTATUS3.text
            }
            val total = subtaskMapper.selectCountByExample(exampleTotal)
            val exampleComplete = exampleTotal.apply {
                and().andEqualTo("status", Constant.TaskProgress.RUNINGSTATUS3.text)
            // 获取当日所有的问题
            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 complete = subtaskMapper.selectCountByExample(exampleComplete)
            var changed = 0
            problemListMapper.findUnchangedCount(it.tguid ?: "").forEach {i ->
                //结果表示该子任务未整改问题数
                if (i == 0) {
                    changed++
                }
            }
            //审核是否完成
            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(
                t?.tguid, t?.starttime, taskId, complete, changed, total, check
            ))
        }
@@ -522,25 +535,25 @@
        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)
@@ -587,7 +600,7 @@
        }
        return taskVoList
    }
    override fun save(task: Task): Int {
        // FIXME: 2021/10/9 按照当前的逻辑,此函数主要用于新建顶层任务以及日任务,但是日任务内容的生成逻辑目前由前端app完成,因此会出现一个bug:
        // FIXME: 2021/10/9 当前端多个用户同时在同一个顶层任务下的新的一天创建任务时,会出现同一天有多个日任务,此时前端后续查看只能看到其中一个日任务下的子任务
@@ -595,6 +608,7 @@
        // FIXME: 2021/10/9 另外对于顶层任务也添加类似逻辑,由于顶层任务的任务名称默认系统自动生成,因此暂时只判断同名的顶层任务,当存在同名顶层任务时,不做保存操作
        var result = 0
        if (task.tguid == null) task.tguid = UUIDGenerator.generate16ShortUUID()
        // 1、首先判断是顶层任务还是日任务
        if (task.levelnum == 2) {
            //2.1、 是顶层任务时,判断是否已有同名任务
@@ -608,7 +622,7 @@
            }
        } 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)
            })
@@ -634,6 +648,14 @@
        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
@@ -646,7 +668,7 @@
                BeanUtils.copyProperties(it, subtask)
                subtask.planstarttime = task.starttime
                subtask.planendtime = task.endtime
                subtaskService.update(subtask)
                subtaskService.changeStatus(subtask)
            }
        }
        return re
@@ -665,7 +687,7 @@
        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
@@ -692,7 +714,7 @@
                    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
@@ -704,7 +726,7 @@
                                    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()
@@ -732,7 +754,7 @@
    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
@@ -746,14 +768,33 @@
                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)
        }