feiyu02
2024-08-15 196bb14112448857a885e32dc4149e308e00b01a
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
package cn.flightfeather.supervision.common.risk
 
import cn.flightfeather.supervision.common.score.EvaluationUtil
import cn.flightfeather.supervision.domain.entity.Evaluation
import cn.flightfeather.supervision.domain.entity.Userinfo
import cn.flightfeather.supervision.infrastructure.utils.DateUtil
import com.github.pagehelper.PageHelper
import tk.mybatis.mapper.entity.Example
import java.time.LocalDateTime
 
/**
 * 获取自评完成情况
 */
class RiskAssessment {
 
    private val summary = listOf(
        "未开展自评,\n",
        "自评结果与线上管理规范性偏差较大,\n",
        "自评得分较高,\n",
        "自评满分,\n"
    )
 
    private var finished = false
    private var score: Int? = null
    private var totalScore = 0
 
    private fun reset() {
        finished = false
        score = 0
        totalScore = 0
    }
 
    fun getResult(user: Userinfo, config: DataSource.Config, dbMapper: DbMapper): Triple<Boolean, Int?, String> {
        reset()
 
        val sTime = LocalDateTime.of(config.year, config.month, 1, 0, 0, 0, 0)
        val eTime = sTime.plusMonths(1)
        PageHelper.startPage<Evaluation>(1, 1)
        val result = dbMapper.evaluationMapper.selectByExample((Example(Evaluation::class.java).apply {
            createCriteria().andEqualTo("evaluatorguid", user.guid)
                .andEqualTo("ertype", 0)
//                .andBetween("createdate", sTime, eTime)
            orderBy("createdate").desc()
        }))
        if (result.isEmpty()) {
            return Triple(false, null, "/")
        } else {
            val rule = dbMapper.evaluationruleMapper.selectByPrimaryKey(result[0].stguid)
            totalScore = rule.resultrange?.toInt() ?: 0
            // 根据评估的提交周期(单位:月),计算对应的月份范围
            val period = rule.scensesubtypeid?.toInt() ?: 1
            val startM = DateUtil.getStartMonthByPeriod(config.month, period)
            val endM = startM?.plus(period)?.minus(1)
 
            // 计算评估记录对应的周期(哪年的几月到几月)
            val list1 = result[0].scensename?.split("/") ?: return Triple(false, null, "/")
            val year = list1[0]
            val list2 = list1[1].split("-")
            val sMonth = list2[0].toInt()
            val eMonth = list2[1].toInt()
 
            finished = if (startM != null && endM != null) {
                year == config.year.toString() && sMonth >= startM && eMonth <= endM
            } else {
                year == config.year.toString()
                        && config.month >= sMonth
                        && config.month <= eMonth
            }
            score = result[0].resultscorebef?.toIntOrNull() ?: 0
            val eRes = EvaluationUtil.getEvaluationLevel(score!!, rule)
            return if (finished)
                Triple(finished, score, eRes.evaluateLevel)
            else
                Triple(false, null, "/")
        }
    }
 
    /**
     * 根据是否完成,返回总结
     * @param riskLevel 综合风险等级
     */
    fun getSummary(riskLevel: Int): String {
        return when {
            !finished -> summary[0]
            riskLevel == 2 -> summary[1]
            riskLevel == 0 && score == totalScore -> summary[3]
            else -> if (riskLevel == 0) summary[2] else ""
        }
    }
}