feiyu02
2024-07-08 b212ef0208cb094f63ea8a239a1361f8e859c839
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
package cn.flightfeather.supervision.business.autooutput.score
 
import cn.flightfeather.supervision.business.Info
import cn.flightfeather.supervision.business.autooutput.datasource.AopDataSource
import cn.flightfeather.supervision.common.utils.ExcelUtil
import cn.flightfeather.supervision.common.utils.UUIDGenerator
import cn.flightfeather.supervision.domain.ds1.entity.Evaluationrule
import cn.flightfeather.supervision.domain.ds1.entity.Evaluationsubrule2
import cn.flightfeather.supervision.domain.ds1.entity.Inspection
import cn.flightfeather.supervision.domain.ds1.entity.Itemevaluation
import org.apache.poi.hssf.util.HSSFColor
import kotlin.math.abs
 
/**
 * 得分计算工具
 * 评分表格分为三个层级
 * 第一层为大分类,第二层为评估标准,第三层为标准对应的不同程度的评估结果
 */
object ScoreUtil {
 
    /**
     * 计算某一具体评分标准的得分
     * 针对减分模式
     */
    fun subRuleCal(rulePair: Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>?) {
        val rule = rulePair?.first
        val itemList = rulePair?.second
        var total: Int? = null
        itemList?.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()
        }
    }
 
    /**
     * 生成新的一条评分记录
     */
    fun newItemEvaluation(evaluationScene: AopDataSource.EvaluationScene, itemRule: Evaluationsubrule2) =
        Itemevaluation().apply {
            val rule = evaluationScene.baseRule.value
            val subTask = evaluationScene.subTask.value
            val inspection = evaluationScene.inspection.value
            ieguid = UUIDGenerator.generate16ShortUUID()
            iguid = inspection?.guid
            stguid = subTask?.stguid
            sguid = subTask?.scenseid
            sensename = subTask?.scensename
            erguid = rule?.guid
            rulename = rule?.rulename
            ruletype = rule?.ruletype?.toInt()
            ertype = itemRule.ertype
            esrguid = itemRule.guid
            name = itemRule.itemname
            value = itemRule.extension1 ?: "0"
            extension1 = (itemRule.extension1 != null).toString()
        }
 
    /**
     * 分数转换环信码
     */
    fun scoreToCredit(s: Int?): Pair<Int?, String?> {
        return when (s) {
            in 0..59 -> Pair(2, "红码")
            in 60..89 -> Pair(1, "黄码")
            in 90..100 -> Pair(0, "绿码")
            null -> Pair(null, null)
            else -> Pair(-1, "超出范围")
        }
    }
 
    /**
     * 分数转换规范等级
     */
    fun scoreToStandard() {
 
    }
}