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
60
61
62
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
        }
    }
}