package cn.flightfeather.supervision.business.autooutput.score
|
|
import cn.flightfeather.supervision.business.autooutput.datasource.AopDataConfig
|
import cn.flightfeather.supervision.common.exception.ResponseErrorException
|
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 ResponseErrorException("环信码评估时必须传递时间条件!")
|
// 找到飞羽环境中需要生成环信码的所有站点
|
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)
|
}
|
}
|