package cn.flightfeather.supervision.business
|
|
import cn.flightfeather.supervision.domain.ds1.entity.*
|
import cn.flightfeather.supervision.common.utils.UUIDGenerator
|
import cn.flightfeather.supervision.lightshare.service.*
|
import cn.flightfeather.supervision.lightshare.vo.InspectionVo
|
import cn.flightfeather.supervision.lightshare.vo.ProblemlistVo
|
import cn.flightfeather.supervision.lightshare.vo.ScenseVo
|
import org.springframework.beans.factory.annotation.Autowired
|
import org.springframework.stereotype.Component
|
import java.util.*
|
import javax.annotation.PostConstruct
|
import kotlin.collections.ArrayList
|
|
/**
|
* @author riku
|
* Date: 2020/8/7
|
*/
|
|
@Component
|
class AutoScore2 {
|
|
companion object {
|
private lateinit var autoScore: AutoScore2
|
|
}
|
|
@Autowired
|
lateinit var problemlistService: ProblemlistService
|
@Autowired
|
lateinit var evaluationruleService: EvaluationruleService
|
@Autowired
|
lateinit var evaluationsubruleService: EvaluationsubruleService
|
@Autowired
|
lateinit var scenseService: ScenseService
|
@Autowired
|
lateinit var inspectionService: InspectionService
|
@Autowired
|
lateinit var evaluationService: EvaluationService
|
@Autowired
|
lateinit var itemevaluationService: ItemevaluationService
|
|
private var problems: ArrayList<ProblemlistVo> = ArrayList()
|
|
private var allRules: ArrayList<Evaluationsubrule> = ArrayList()
|
|
private var inspection = InspectionVo()
|
|
private var evaluationrule: Evaluationrule? = null
|
|
private var scense: ScenseVo? = null
|
|
private var totalPoint = 0
|
|
//子评分项得分列表
|
val childScorelist = ArrayList<Itemevaluation>()
|
//总得分
|
val totalScore = Evaluation()
|
|
var subtask = Subtask()
|
|
@PostConstruct
|
fun init() {
|
autoScore = this
|
autoScore.problemlistService = this.problemlistService
|
autoScore.evaluationruleService = this.evaluationruleService
|
autoScore.evaluationsubruleService = this.evaluationsubruleService
|
autoScore.scenseService = this.scenseService
|
autoScore.inspectionService = this.inspectionService
|
autoScore.evaluationService = this.evaluationService
|
autoScore.itemevaluationService = this.itemevaluationService
|
}
|
|
fun calculateScore() {
|
//获取子任务对应的问题列表
|
this.problems.addAll(autoScore.problemlistService.findBySubtaskId(subtask.stguid!!))
|
//获取子任务对应的场景信息
|
scense = autoScore.scenseService.findOne(subtask.scenseid!!)
|
//获取对应任务类型、场景类型、区县的评分表名称
|
val evaluationrule = autoScore.evaluationruleService.findBySpecificRule(subtask.typeno, scense!!.typeid, subtask.districtcode)
|
if (evaluationrule === null) return
|
this.evaluationrule = evaluationrule
|
//获取对应的具体评分细则
|
allRules = autoScore.evaluationsubruleService.findByRuleId(evaluationrule.guid!!) as ArrayList<Evaluationsubrule>
|
//获取巡查信息
|
inspection = autoScore.inspectionService.findBySubTaskID(subtask.stguid!!)
|
|
|
val titleRule = Evaluationsubrule()
|
val titleOptionRange = ArrayList<Int>()
|
val titleIsGood = true
|
|
//满分
|
totalPoint = getTotalPoint(allRules, titleRule.guid)
|
|
|
//得到的point是扣分分数
|
val point = autoGeneration(titleRule, totalPoint)
|
createTotalScore(point)
|
update()
|
}
|
|
|
/**
|
* 自动打分
|
* @param rule 当前评分项
|
* @param maxScore 父项的最大分
|
*/
|
fun autoGeneration(rule: Evaluationsubrule, maxScore: Int): Int? {
|
|
val nextSubRules = getSubRulesByFatherId(allRules, rule.guid)
|
//无子项的最小评分项,给出得分
|
if (nextSubRules.isEmpty()) {
|
val totalScore = writeScore4th(rule, maxScore)
|
createNewChildScore(rule, totalScore.first, totalScore.second)
|
return totalScore.first
|
}
|
//有子项的评分项,以每项子项为父项继续递归,获取总分
|
else {
|
var totalScore = 0//有子项的评分项一定会有分数,不会出现null的情况
|
|
var nextTmpTotalScore = 0//所有子项的总得分
|
nextSubRules.forEach {
|
val nextFatherRule = it
|
val score = autoGeneration(nextFatherRule, nextFatherRule.maxscore?:0)
|
if (score != null) {
|
nextTmpTotalScore += score
|
}
|
}
|
|
totalScore += nextTmpTotalScore
|
//取得总分后,生成对应的评分信息并存入列表
|
if (!rule.guid.isNullOrBlank()) {
|
createNewChildScore(rule, totalScore, true)
|
}
|
|
return totalScore
|
}
|
}
|
|
//填写详细评分项的分数
|
fun writeScore4th(rule: Evaluationsubrule, maxScore: Int): Pair<Int, Boolean> {
|
|
problems.forEach {
|
if (it.guid != null) {
|
if (rule.problemlist?.contains(it.guid!!) == true) {
|
return Pair(rule.maxscore?.minus(maxScore) ?: 0, true)
|
}
|
}
|
}
|
//若不需要评分,此处将其设置为空
|
return Pair(0, false)
|
}
|
|
//按照父id查找子评分项
|
fun getSubRulesByFatherId(rules: ArrayList<Evaluationsubrule>, fatherId: String?): List<Evaluationsubrule> {
|
val subRules = mutableListOf<Evaluationsubrule>()
|
rules.forEach {
|
if (it.fatherid == fatherId
|
|| (fatherId.isNullOrBlank() && it.fatherid.isNullOrBlank())) {
|
subRules.add(it)
|
// rules.remove(it)
|
}
|
}
|
return subRules
|
}
|
|
//创建单项评分对象
|
fun createNewChildScore(subRule: Evaluationsubrule, score: Int, isSelected: Boolean): Int? {
|
val itemevaluation = Itemevaluation()
|
itemevaluation.ieguid = UUIDGenerator.generate16ShortUUID()
|
itemevaluation.iguid = inspection.guid
|
itemevaluation.stguid = subtask.stguid
|
itemevaluation.sguid = subtask.scenseid
|
itemevaluation.sensename = subtask.scensename
|
itemevaluation.erguid = evaluationrule!!.guid
|
itemevaluation.rulename = evaluationrule!!.rulename
|
itemevaluation.ruletype = 2
|
// itemevaluation.ertype = subRule.ertype?.toInt()
|
itemevaluation.esrguid = subRule.guid
|
itemevaluation.name = subRule.itemname
|
|
itemevaluation.value = score.toString()
|
itemevaluation.extension1 = isSelected.toString()
|
|
childScorelist.add(itemevaluation)
|
|
return itemevaluation.value?.toInt()
|
}
|
|
//创建总分对象
|
fun createTotalScore(point: Int?) {
|
totalScore.guid = UUIDGenerator.generate16ShortUUID()
|
totalScore.iguid = inspection.guid
|
totalScore.stguid = subtask.stguid
|
totalScore.sguid = scense?.guid
|
totalScore.scensetypeid = scense?.typeid
|
totalScore.scensetype =scense?.type
|
totalScore.subscensetypeid = scense?.scensesubtypeid
|
totalScore.subscensetype = scense?.scensesubtype
|
totalScore.ertype = evaluationrule?.ruletype?.toByte()
|
totalScore.provincecode = scense?.provincecode
|
totalScore.provincename = scense?.provincename
|
totalScore.citycode = scense?.citycode
|
totalScore.cityname = scense?.cityname
|
totalScore.districtcode = scense?.districtcode
|
totalScore.districtname = scense?.districtname
|
totalScore.towncode = scense?.towncode
|
totalScore.townname = scense?.townname
|
totalScore.scensename = scense?.name
|
totalScore.scenseaddress = scense?.location
|
totalScore.evaluatetime = Date()
|
totalScore.evaluatorguid = "admin"
|
totalScore.evaluatorusername = "admin"
|
totalScore.evaluatorrealname = "admin"
|
totalScore.createdate = Date()
|
totalScore.resultscorebef = (totalPoint - Math.abs(point!!)).toInt().toString()
|
}
|
|
//获取总分
|
fun getTotalPoint(rules: ArrayList<Evaluationsubrule>, fatherId: String?): Int {
|
val rules1 = getSubRulesByFatherId(rules, fatherId)
|
var point = 0
|
rules1.forEach {
|
point += it.maxscore?: 0
|
}
|
return point
|
}
|
|
//数据库更新
|
fun update() {
|
// println(totalScore)
|
autoScore.evaluationService.save(totalScore)
|
childScorelist.forEach {
|
autoScore.itemevaluationService.save(it)
|
// println(it)
|
}
|
}
|
|
}
|