feiyu02
2025-08-14 f373bbf83d9d2a7e5f96118d7dcd658c9fea8bc8
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
package cn.flightfeather.supervision.business.autooutput.score
 
import cn.flightfeather.supervision.business.autooutput.datasource.AopDataConfig
import cn.flightfeather.supervision.common.exception.BizException
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.domain.ds1.repository.EvaluationRep
import cn.flightfeather.supervision.domain.ds2.entity.UserinfoTZ
import cn.flightfeather.supervision.domain.ds2.repository.OverallEvaluationRep
import cn.flightfeather.supervision.domain.ds2.repository.UserInfoTZRep
import cn.flightfeather.supervision.domain.ds2.repository.UserMapRep
import org.springframework.stereotype.Component
import java.time.LocalDate
import java.time.ZoneId
import java.util.*
 
/**
 * 根据自动评估[AopEvaluation]结果生成环信码
 */
@Component
class AopCreditCode(
    private val userInfoTZRep: UserInfoTZRep,
    private val userMapRep: UserMapRep,
    private val evaluationRep: EvaluationRep,
    private val overallEvaluationRep: OverallEvaluationRep,
) {
 
    fun execute(config: AopDataConfig) {
        if (config.year == null || config.month == null) throw BizException("环信码评估时必须传递时间条件!")
        // 找到飞羽环境中需要生成环信码的所有站点
        val sceneType = Constant.SceneType.getByValue(config.sceneType.toString())
        val userList = findUsers(config.districtName, sceneType)
        val date = LocalDate.of(config.year, config.month, 1)
        val endDate = date.plusMonths(config.period.toLong() - 1)
        userList.forEach {
            userMapRep.findFromSupervision(it)?.let { s ->
                // 从飞羽监管系统中查找评分
                val e = evaluationRep.findByScene(s.guid, date)
                if (e.isNotEmpty()) {
                    // 根据评分生成对应的环信码
                    var score = 0
                    e.forEach {eva ->
                        val s = eva?.resultscorebef?.toInt() ?: 0
                        if (s > score) score = s
                    }
                    overallEvaluationRep.insertOrUpdateOne(it?.guid, score, sceneType, date, endDate)
                } else {
                    // TODO: 2024/12/6 当没有找到自动评分记录时,采用历史最新的环信码记录作为本期记录
                    overallEvaluationRep.selectLatest(it?.guid)?.let {o ->
                        overallEvaluationRep.insertOrUpdateOne(o.biGuid, o.oeScore, sceneType, date, endDate)
                    }
                }
            }
        }
    }
 
    private fun findUsers(districtName: String?, type: Constant.SceneType): List<UserinfoTZ?> {
        return userInfoTZRep.findEnterpriseUser(districtName, type)
    }
}