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.Evaluationrule
|
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 rule = dbMapper.evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
|
createCriteria().andEqualTo("scensetypeid", config.sceneType)
|
.andEqualTo("ruletype", 0)
|
}).takeIf { it.isNotEmpty() }?.get(0)
|
|
// 根据评估的提交周期(单位:月),计算对应的月份范围
|
val period = rule?.scensesubtypeid?.toInt() ?: 1
|
// 提交周期下的起止月份
|
val startM = DateUtil.getStartMonthByPeriod(config.month, period)
|
val endM = startM?.plus(period)?.minus(1)
|
|
// 查询开始时间为周期下的首个月份
|
val sTime = LocalDateTime.of(config.year, startM ?: config.month, 1, 0, 0, 0, 0)
|
// 查询结束时间为统计的月份
|
val eTime = LocalDateTime.of(config.year, config.month, 1, 0, 0, 0, 0)
|
.plusMonths(1).minusSeconds(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 {
|
totalScore = rule?.resultrange?.toInt() ?: 0
|
|
// 计算评估记录对应的周期(哪年的几月到几月)
|
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 ""
|
}
|
}
|
}
|