1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package cn.flightfeather.supervision.business.bgtask
 
import cn.flightfeather.supervision.business.autooutput.dataanalysis.*
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.BizException
import cn.flightfeather.supervision.common.executor.BackgroundTaskCtrl
import cn.flightfeather.supervision.common.executor.BgTaskStatus
import cn.flightfeather.supervision.common.executor.BgTaskType
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import org.springframework.stereotype.Component
 
/**
 * 自动评估任务管理
 */
@Component
class AopTaskCtrl(
    private val aopEvaluation: AopEvaluation,
    private val aopCreditCode: AopCreditCode,
    private val jaCsDataAnalysis: JACsDataAnalysis,
    private val xhFuDataAnalysis: XHFuDataAnalysis,
    private val jsCsDataAnalysis: JSCsDataAnalysis,
    private val jsMpDataAnalysis: JSMpDataAnalysis,
    private val jsWhDataAnalysis: JSWhDataAnalysis,
    private val backgroundTaskCtrl: BackgroundTaskCtrl,
    private val taskRep: TaskRep,
) {
    private val dataAnalysisMap = mutableMapOf<String, MutableMap<Int, AopDataAnalysis<*>>>()
 
    init {
        listOf("310106", "310104", "310116").forEach { dataAnalysisMap[it] = mutableMapOf() }
        dataAnalysisMap["310106"]?.put(Constant.SceneType.TYPE1.value.toInt(), jaCsDataAnalysis)
        dataAnalysisMap["310104"]?.put(Constant.SceneType.TYPE5.value.toInt(), xhFuDataAnalysis)
        dataAnalysisMap["310116"]?.put(Constant.SceneType.TYPE1.value.toInt(), jsCsDataAnalysis)
        dataAnalysisMap["310116"]?.put(Constant.SceneType.TYPE2.value.toInt(), jsWhDataAnalysis)
        dataAnalysisMap["310116"]?.put(Constant.SceneType.TYPE3.value.toInt(), jsMpDataAnalysis)
    }
 
    fun startNewTask(areaVo: AreaVo): BgTaskStatus {
        val task = taskRep.findOneTask(areaVo)
        val taskId = task?.tguid
        if (taskId != null) {
            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 BizException("自动评估任务必须设定时间")
            val year = d.year
            val month = d.monthValue
            val sceneType = areaVo.scensetypeid?.toInt() ?: throw BizException("场景类型未设置,无法评估")
 
            val id = "${BgTaskType.AUTO_SCORE.name}-${districtCode}-${sceneType}"
            val name = "${districtName}${Constant.SceneType.getDes(sceneType)}自动评分"
            val bgTask = backgroundTaskCtrl.startNewTask(BgTaskType.AUTO_SCORE, id, name) {
                dataAnalysis(districtCode, sceneType, taskId, year, month)
 
                aopEvaluation.executeByTopTask(taskId, sceneType)
 
                aopCreditCode.execute(AopDataConfig(
                    year = year,
                    month = month,
                    districtName = districtName,
                    sceneType = sceneType,
                    period = 1
                ))
                true
            }
            return bgTask.taskStatus
        } else {
            throw BizException("巡查总任务不存在,无法评估")
        }
    }
 
    private fun dataAnalysis(districtCode: String?, sceneType: Int, taskId: String, year: Int, month: Int) {
        val aopDataAnalysis = dataAnalysisMap[districtCode]?.get(sceneType)
        aopDataAnalysis?.setResource(taskId, sceneType, year, month)
        aopDataAnalysis?.execute()
    }
}