Riku
2024-09-28 bda3bf8923acb5216f6f46b5d903cac24c842143
src/main/kotlin/cn/flightfeather/supervision/business/autooutput/datasource/AopDataSource.kt
@@ -1,12 +1,15 @@
package cn.flightfeather.supervision.business.autooutput.datasource
import cn.flightfeather.supervision.common.exception.ResponseErrorException
import cn.flightfeather.supervision.common.exception.BizException
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.domain.ds1.entity.*
import cn.flightfeather.supervision.domain.ds2.entity.LedgerRecord
import cn.flightfeather.supervision.domain.ds2.entity.LedgerSubType
import cn.flightfeather.supervision.domain.ds2.entity.UserMap
import cn.flightfeather.supervision.domain.ds2.entity.UserinfoTZ
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import cn.flightfeather.supervision.lightshare.vo.EvaluationSubRuleVo
import org.springframework.beans.BeanUtils
import tk.mybatis.mapper.entity.Example
import java.time.LocalDateTime
import java.time.ZoneId
@@ -36,6 +39,12 @@
            initUserSource(config)
        }
    }
//    fun setResource(areaVo: AreaVo) {
//        val task = taskRep.findOneTask(areaVo)
//        val taskId = task?.tguid
//        val sceneType = areaVo.scensetypeid?.toInt() ?: throw BizException("场景类型未设置,无法评估")
//    }
    fun setResource(config: AopDataConfig) {
        config.sceneType ?: return
@@ -70,6 +79,33 @@
                    evaluationScene.clear()
                    evaluationScene.index = i
                    evaluationScene.setDefaultScene(scene)
                    do {
                        callback(i, evaluationScene)
                    } while (evaluationScene.gotoNextSubTask())
                }
            }
            1 -> {
                userSourceList.forEachIndexed { i, user ->
                    evaluationScene.clear()
                    evaluationScene.index = i
                    evaluationScene.setDefaultUserTZ(user)
                    callback(i, evaluationScene)
                }
            }
        }
    }
    /**
     * 根据子任务只轮询一次
     * 当数据源是通过[setResource]传入[Subtask]时决定时
     */
    fun runBySubTask(callback: (index: Int, evaluationScene: EvaluationScene) -> Unit) {
        when (mode) {
            0 -> {
                sceneSourceList.forEachIndexed { i, scene ->
                    evaluationScene.clear()
                    evaluationScene.index = i
                    evaluationScene.setDefaultScene(scene)
                    callback(i, evaluationScene)
                }
            }
@@ -86,12 +122,15 @@
    // 从监管系统获取场景
    private fun initSceneSource(config: AopDataConfig) {
        config.topTaskGuid ?: throw ResponseErrorException("顶层任务id不能为null")
        config.topTaskGuid ?: throw BizException("顶层任务id不能为null")
        this.config = config
        this.mode = 0
        sceneSourceList.clear()
        val taskSceneIdList =
            aopDbMapper.scenseMapper.getSceneByType(config.topTaskGuid, config.sceneType, config.townCode)
        taskSceneIdList.forEach {
            println(it.name)
        }
        sceneSourceList.addAll(taskSceneIdList)
    }
@@ -150,12 +189,21 @@
            })
        }
        //巡查任务信息
        var subTaskIndex = 0
        val subTask = InfoProxy<Subtask> {_,_ ->
            return@InfoProxy if (subTaskList.value?.isNotEmpty() == true) {
                subTaskList.value?.get(subTaskIndex)
            } else {
                null
            }
        }
        val subTaskList = InfoProxy<List<Subtask>> {_,_ ->
            return@InfoProxy aopDbMapper.subtaskMapper.selectByExample(Example(Subtask::class.java).apply {
                createCriteria().andEqualTo("scenseid", scene.value?.guid)
//                    .andBetween("planstarttime", config?.startTime, config?.endTime)
                    .andEqualTo("tguid", config?.topTaskGuid)
            })?.takeIf { it.isNotEmpty() }?.get(0)
            })
        }
        //现场巡查信息
@@ -234,9 +282,9 @@
        val totalScore = InfoProxy<Int>()
        //自动评分规则一级分类
        val topItems = InfoProxy<MutableList<Evaluationsubrule2>>(config?.sceneType.toString()) { _, cacheMap ->
            val _topItems = mutableListOf<Evaluationsubrule2>()
            val _rules = mutableListOf<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>()
        val topRules = InfoProxy<MutableList<EvaluationSubRuleVo>>(config?.sceneType.toString()) { _, cacheMap ->
            val _topItems = mutableListOf<EvaluationSubRuleVo>()
            val _rules = mutableListOf<Pair<EvaluationSubRuleVo, MutableList<EvaluationSubRuleVo>>>()
            val rule = aopDbMapper.evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
                createCriteria()
                    .andEqualTo("tasktypeid", 99)
@@ -250,7 +298,11 @@
                val rules =
                    aopDbMapper.evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule2::class.java).apply {
                        createCriteria().andEqualTo("erguid", ruleId)
                    })
                    }).map {
                        val vo = EvaluationSubRuleVo()
                        BeanUtils.copyProperties(it, vo)
                        vo
                    }
                rules.forEach {
                    if (it.ertype == 2) {
                        _topItems.add(it)
@@ -261,7 +313,7 @@
                var t = 0
                _topItems.forEach {
                    t += it.maxscore ?: 0
                    val tempRules = mutableListOf<Evaluationsubrule2>()
                    val tempRules = mutableListOf<EvaluationSubRuleVo>()
                    for (i in rules) {
                        if (i.fatherid == it.guid && i.ertype == 3) {
                            tempRules.add(i)
@@ -273,7 +325,7 @@
                    }
                    tempRules.sortBy { t -> t.displayid }
                    tempRules.forEach { temp ->
                        val tempSubRules = mutableListOf<Evaluationsubrule2>()
                        val tempSubRules = mutableListOf<EvaluationSubRuleVo>()
                        for (i in rules) {
                            if (i.fatherid == temp.guid && i.ertype == 4) {
                                tempSubRules.add(i)
@@ -294,7 +346,7 @@
        // FIXME: 2023/8/9 子规则的获取必须在[topItems]调用之后,否则为空
        //自动评分规则二级和三级分类
        val rules = InfoProxy<MutableList<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>>()
        val rules = InfoProxy<MutableList<Pair<EvaluationSubRuleVo, MutableList<EvaluationSubRuleVo>>>>()
        //必填台账数量
        val ledgerCount = InfoProxy<Int>(config?.sceneType.toString()) {_, cacheMap ->
@@ -341,21 +393,43 @@
         */
        fun clear() {
            scene.clear()
            subTaskIndex = 0
            subTaskList.clear()
            userInfo.clear()
            userInfoTZ.clear()
            baseScene.clear()
            problemTypes.clear()
            ledgerCount.clear()
            ledgerRecords.clear()
            clearSubtask()
        }
        fun clearSubtask() {
            subTask.clear()
            inspection.clear()
            baseScene.clear()
            problems.clear()
            evaluation.clear()
            itemevaluationList.clear()
            problemTypes.clear()
            baseRule.clear()
            totalScore.clear()
            topItems.clear()
            topRules.clear()
            baseRule.clear()
            rules.clear()
            ledgerCount.clear()
            ledgerRecords.clear()
        }
        /**
         * 切换至下一个巡查任务
         * 一个场景可能同时存在多个巡查任务[subTaskList],需要对每个巡查任务分别进行评分
         * @return 是否有下一个巡查任务
         */
        fun gotoNextSubTask(): Boolean {
            return if (subTaskIndex + 1 < (subTaskList.value?.size ?: 0)) {
                clearSubtask()
                subTaskIndex++
                true
            } else {
                false
            }
        }
        /**