package cn.flightfeather.supervision.business.autooutput.score.construction
|
|
import cn.flightfeather.supervision.business.Info
|
import cn.flightfeather.supervision.domain.ds1.entity.Evaluation
|
import cn.flightfeather.supervision.domain.ds1.entity.Score
|
import cn.flightfeather.supervision.domain.ds1.mapper.ScoreMapper
|
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.stereotype.Component
|
import tk.mybatis.mapper.entity.Example
|
import java.time.LocalDateTime
|
import java.time.ZoneId
|
|
/**
|
* 上海市静安区单独的50分制评分结果,
|
* 根据自动评分结果进行转换得出
|
*/
|
@Component
|
class JAScore {
|
|
@Autowired
|
lateinit var scoreMapper: ScoreMapper
|
|
fun toDb(e: Evaluation, info: Info) {
|
val time = LocalDateTime.ofInstant(e.evaluatetime?.toInstant(), ZoneId.systemDefault())
|
val scoreVo = Score().apply {
|
sceneId = e.sguid
|
sceneName = e.scensename
|
year = time.year
|
month = time.monthValue
|
districtCode = e.districtcode
|
districtName = e.districtname
|
score = transform(e.resultscorebef?.toIntOrNull() ?: 0)
|
completion = !info.online
|
}
|
|
val res = scoreMapper.selectByExample(Example(Score::class.java).apply {
|
createCriteria().andEqualTo("sceneId", e.sguid)
|
.andEqualTo("year", time.year)
|
.andEqualTo("month", time.monthValue)
|
})
|
if (res.isNotEmpty()) {
|
scoreVo.id = res[0].id
|
scoreMapper.updateByPrimaryKeySelective(scoreVo)
|
} else {
|
scoreMapper.insert(scoreVo)
|
}
|
}
|
|
/**
|
* 分数转换
|
*/
|
private fun transform(oldS: Int): Int {
|
return when {
|
// 基本规范
|
oldS >= 90 -> 50
|
// 不规范
|
oldS >= 50 -> 30
|
// 严重不规范
|
else -> 10
|
}
|
}
|
}
|