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,查找用户在当前时间段内是否有发生该问题,有则扣除相应的分数
|
it.problemlist?.let {pId ->
|
problemlistMapper.selectByExample(Example(Problemlist::class.java).apply {
|
createCriteria().andEqualTo("sguid", info.sceneId)
|
.andEqualTo("ptguid", pId)
|
.andGreaterThanOrEqualTo("time", info.sTime)
|
.andLessThan("time", info.eTime)
|
})?.takeIf { p-> p.isNotEmpty() }?.run {
|
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()
|
}
|
}
|