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)
|
}
|
}
|