feiyu02
2024-01-09 c1becf4cbd2e99601ce011c14b8742427249cfb4
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
package cn.flightfeather.supervision.business.autooutput.score
 
import cn.flightfeather.supervision.business.autooutput.datasource.AopDataConfig
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
 
/**
 * 根据自动评估[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 IllegalStateException("环信码评估时必须传递时间条件!")
        // 找到飞羽环境中需要生成环信码的所有站点
        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)
                e?.resultscorebef?.toInt()?.let {score ->
                    // 根据评分生成对应的环信码
                    overallEvaluationRep.insertOrUpdateOne(it?.guid, score, sceneType, date, endDate)
                }
            }
        }
    }
 
    private fun findUsers(districtName: String?, type: Constant.SceneType): List<UserinfoTZ?> {
        return userInfoTZRep.findEnterpriseUser(districtName, type)
    }
}