feiyu02
2022-11-15 909fd8929d7906f1dca68acc05e36e29b0b9192c
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package cn.flightfeather.supervision.business
 
import cn.flightfeather.supervision.common.utils.DateUtil
import cn.flightfeather.supervision.domain.ds1.entity.Evaluationsubrule2
import cn.flightfeather.supervision.domain.ds1.entity.Problemlist
import cn.flightfeather.supervision.domain.ds1.mapper.ProblemlistMapper
import org.springframework.beans.factory.annotation.Autowired
import tk.mybatis.mapper.entity.Example
import kotlin.math.abs
import kotlin.properties.Delegates
 
/**
 * 自动评分条目
 */
abstract class ScoreItem() {
 
    //自动评分条目id
    abstract var id: String
    //自动评分条目名称
    abstract var name:String
    //最大分值
    var maxScore: Int = 0
    //最小分值(默认0分)
    var minScore: Int = 0
 
    lateinit var info: Info
 
    val dateUtil = DateUtil()
    // 评分项是否豁免不扣分
    var exemption = false
 
    //评分项
    private var evaluationsubrule: Evaluationsubrule2? = null
    //评分项对应选项
    private var evaluationsubruleList = listOf<Evaluationsubrule2>()
 
    @Autowired
    lateinit var problemlistMapper: ProblemlistMapper
 
    /**
     * 执行相关问题自动扣分逻辑和特殊扣分逻辑
     *
     */
    fun execute(info: Info, eList: MutableList<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>) {
        this.info = info
        if (!exemption) {
            getRule(eList)
            problemCheck()
            calScore()
        }
    }
 
    /**
     * 只执行特殊扣分逻辑
     */
    fun execute2(info: Info, eList: MutableList<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>) {
        this.info = info
        if (!exemption) {
            getRule(eList)
            calScore()
        }
    }
 
    /**
     * 获取评分规则
     */
    private fun getRule(eList: MutableList<Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>>) {
        for (e in eList) {
            if (e.first.guid == id) {
                evaluationsubrule = e.first
                evaluationsubrule?.maxscore?.let { maxScore = it }
                evaluationsubrule?.minscore?.let { minScore = it }
                evaluationsubruleList = e.second.sortedBy { it.displayid }
                break
            }
        }
    }
 
    /**
     * 检查评分项对应的问题是否存在,记录扣分
     */
    private fun problemCheck() {
        // 根据评分规则对应的具体问题,查询当前时间段下是否有记录该问题
        evaluationsubruleList.forEach {
            if (it.fatherid == id) {
                // 根据规则对应的相关问题id,查找用户在当前时间段内是否有发生该问题,有则扣除相应的分数
                val pList = problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
                    createCriteria().andEqualTo("sguid", info.sceneId)
                        .andGreaterThanOrEqualTo("time", info.sTime)
                        .andLessThan("time", info.eTime)
                }).map { p-> p.ptguid }
                it.problemlist?.split(",")?.forEach {pId ->
                    if (pList.contains(pId)) {
                        it.extension1 = (0 - (it.maxscore ?: 0)).toString()
                    }
                }
            }
        }
//        var total: Int? = null
//        subRule.forEach {
//            if (!it.extension1.isNullOrBlank()) {
//                total = (total?:0) + it.extension1!!.toInt()
//            }
//        }
//        if (total == null) {
//            rule.extension1 = "0"
//        } else {
//            val s = if (abs(total!!) > rule.maxscore!!) {
//                0 - rule.maxscore!!
//            } else {
//                total
//            }
//            rule.extension1 = s.toString()
//        }
    }
 
    /**
     * 根据系统外获取的信息,进行扣分判定。返回需要扣分的条目序号
     * @param size 传入评分条目的数量,评分条目按照一定规则进行排序
     * @return 返回需要扣分的评分条目的序号
     */
    abstract fun otherProblem(size: Int): Int?
 
    /**
     * 自动评分计算逻辑
     */
    fun calScore() {
        if (evaluationsubruleList.isEmpty()) {
            println("${name}: 评分条目为空,不做评分")
            return
        }
 
        otherProblem(evaluationsubruleList.size)?.let {i-> evaluationsubruleList[i].getScore(maxScore) }
 
        var total: Int? = null
        evaluationsubruleList.forEach {
            if (!it.extension1.isNullOrBlank()) {
                total = (total ?: 0) + it.extension1!!.toInt()
            }
        }
        if (total == null) {
            evaluationsubrule?.extension1 = "0"
        } else {
            val s = if (abs(total!!) > evaluationsubrule?.maxscore!!) {
                0 - evaluationsubrule?.maxscore!!
            } else {
                total
            }
            evaluationsubrule?.extension1 = s.toString()
        }
    }
 
    /**
     * 减分模式下,计算具体选项的得分
     */
    fun Evaluationsubrule2.getScore(maxScore: Int) {
        extension1 = (0 - (maxscore ?: 0)).toString()
    }
}