feiyu02
2024-07-08 b212ef0208cb094f63ea8a239a1361f8e859c839
src/main/kotlin/cn/flightfeather/supervision/business/bgtask/AopTaskCtrl.kt
@@ -4,7 +4,7 @@
import cn.flightfeather.supervision.business.autooutput.datasource.AopDataConfig
import cn.flightfeather.supervision.business.autooutput.score.AopCreditCode
import cn.flightfeather.supervision.business.autooutput.score.AopEvaluation
import cn.flightfeather.supervision.common.exception.ResponseErrorException
import cn.flightfeather.supervision.common.exception.BizException
import cn.flightfeather.supervision.common.executor.BackgroundTaskCtrl
import cn.flightfeather.supervision.common.executor.BgTaskStatus
import cn.flightfeather.supervision.common.executor.BgTaskType
@@ -12,6 +12,7 @@
import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import org.springframework.stereotype.Component
import java.time.LocalDateTime
/**
 * 自动评估任务管理
@@ -39,6 +40,29 @@
        dataAnalysisMap["310116"]?.put(Constant.SceneType.TYPE3.value.toInt(), jsMpDataAnalysis)
    }
    fun startAllEvaluation(time: LocalDateTime) {
        startEvaluation(getArea(time, "310106", "静安区", Constant.SceneType.TYPE1))
        startEvaluation(getArea(time, "310104", "徐汇区", Constant.SceneType.TYPE5))
        startEvaluation(getArea(time, "310116", "金山区", Constant.SceneType.TYPE1))
        startEvaluation(getArea(time, "310116", "金山区", Constant.SceneType.TYPE2))
        startEvaluation(getArea(time, "310116", "金山区", Constant.SceneType.TYPE3))
    }
    fun startEvaluation(areaVo: AreaVo) {
        val task = taskRep.findOneTask(areaVo)
        val taskId = task?.tguid
        val sceneType = areaVo.scensetypeid?.toInt() ?: throw BizException("场景类型未设置,无法评估")
        aopEvaluation.executeByTopTask(taskId, sceneType)
    }
    fun startAll(time: LocalDateTime) {
        startNewTask(getArea(time, "310106", "静安区", Constant.SceneType.TYPE1))
        startNewTask(getArea(time, "310104", "徐汇区", Constant.SceneType.TYPE5))
        startNewTask(getArea(time, "310116", "金山区", Constant.SceneType.TYPE1))
        startNewTask(getArea(time, "310116", "金山区", Constant.SceneType.TYPE2))
        startNewTask(getArea(time, "310116", "金山区", Constant.SceneType.TYPE3))
    }
    fun startNewTask(areaVo: AreaVo): BgTaskStatus {
        val task = taskRep.findOneTask(areaVo)
        val taskId = task?.tguid
@@ -46,10 +70,10 @@
            val districtCode = areaVo.districtcode
            val districtName = areaVo.districtname
//            val d = LocalDateTime.parse(areaVo.starttime, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
            val d = areaVo.starttime ?: throw ResponseErrorException("自动评估任务必须设定时间")
            val d = areaVo.starttime ?: throw BizException("自动评估任务必须设定时间")
            val year = d.year
            val month = d.monthValue
            val sceneType = areaVo.scensetypeid?.toInt() ?: throw ResponseErrorException("场景类型未设置,无法评估")
            val sceneType = areaVo.scensetypeid?.toInt() ?: throw BizException("场景类型未设置,无法评估")
            val id = "${BgTaskType.AUTO_SCORE.name}-${districtCode}-${sceneType}"
            val name = "${districtName}${Constant.SceneType.getDes(sceneType)}自动评分"
@@ -69,7 +93,7 @@
            }
            return bgTask.taskStatus
        } else {
            throw ResponseErrorException("巡查总任务不存在,无法评估")
            throw BizException("巡查总任务不存在,无法评估")
        }
    }
@@ -78,4 +102,17 @@
        aopDataAnalysis?.setResource(taskId, sceneType, year, month)
        aopDataAnalysis?.execute()
    }
    fun getArea(time: LocalDateTime, dCode: String, dName: String, sceneType: Constant.SceneType): AreaVo {
        return AreaVo().apply {
            provincecode = "31"
            provincename = "上海市"
            citycode = "3100"
            cityname = "上海市"
            starttime = time
            districtcode = dCode
            districtname = dName
            scensetypeid = sceneType.value
        }
    }
}