From 0516cba27e632f20efac2752787f38f0c87baafa Mon Sep 17 00:00:00 2001 From: feiyu02 <risaku@163.com> Date: 星期三, 25 九月 2024 09:24:05 +0800 Subject: [PATCH] 1. 新增自动评估添加和更新接口 --- src/main/kotlin/cn/flightfeather/supervision/business/autooutput/score/ScoreUtil.kt | 168 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 143 insertions(+), 25 deletions(-) diff --git a/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/score/ScoreUtil.kt b/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/score/ScoreUtil.kt index 05d102d..12df325 100644 --- a/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/score/ScoreUtil.kt +++ b/src/main/kotlin/cn/flightfeather/supervision/business/autooutput/score/ScoreUtil.kt @@ -1,52 +1,170 @@ 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.Evaluation +import cn.flightfeather.supervision.lightshare.vo.EvaluationSubRuleVo import cn.flightfeather.supervision.domain.ds1.entity.Itemevaluation -import org.apache.poi.hssf.util.HSSFColor -import kotlin.math.abs +import cn.flightfeather.supervision.lightshare.vo.EvaluationVo +import cn.flightfeather.supervision.lightshare.vo.ItemEvaluationVo +import java.util.* /** * 寰楀垎璁$畻宸ュ叿 * 璇勫垎琛ㄦ牸鍒嗕负涓変釜灞傜骇 * 绗竴灞備负澶у垎绫伙紝绗簩灞備负璇勪及鏍囧噯锛岀涓夊眰涓烘爣鍑嗗搴旂殑涓嶅悓绋嬪害鐨勮瘎浼扮粨鏋� */ +// FIXME: 2024/9/23 鐩墠鏆傛寜鐓т笁灞傝瘎浼拌鍒欒繘琛岃瘎浼帮紝鍚庣画搴旇浼樺寲涓轰笉闄愬眰鏁� object ScoreUtil { /** - * 璁$畻鏌愪竴鍏蜂綋璇勫垎鏍囧噯鐨勫緱鍒� - * 閽堝鍑忓垎妯″紡 + * 鏍规嵁鎵�閫夋渶娣卞眰璇勪及閫夐」锛岀粰瑙勫垯璧嬪�煎搴斿垎鏁板強鑷姩璁$畻鍏朵綑鎵�鏈夋潯鐩緱鍒� + * @param evaluationScene 闇�瑕佽瘎浼扮殑瀵硅薄 + * @param selected 璇勪及琛ㄤ腑閫変腑鐨勮瘎浼版潯鐩富閿甶d闆嗗悎锛堝繀椤绘槸鏈�娣变竴灞傜殑璇勪及鏉$洰锛� */ - fun subRuleCal(rulePair: Pair<Evaluationsubrule2, MutableList<Evaluationsubrule2>>?) { + fun scoreAssign(evaluationScene: AopDataSource.EvaluationScene, selected: List<String>) { + val topRules = evaluationScene.topRules.value + val subRules = evaluationScene.rules.value + subRules?.forEach { r -> + // 鏍规嵁浼犲叆鐨勯�変腑璇勪及鏉$洰涓婚敭id锛屼慨鏀瑰叾寰楀垎 + r.second.forEach { e -> + if (selected.contains(e.guid)) { + e.setMaxScore() + } + } + // 鏍规嵁瀛愰」鐨勯�夋嫨鎯呭喌锛岃嚜鍔ㄨ绠楄鏉¤瘎浼扮殑鎬诲緱鍒� + subRuleCal(r) + + // 琛ュ厖鍚勬渶涓婄骇璇勫垎椤圭殑璁″垎 + val fatherId = r.first.fatherid + for (t in (evaluationScene.topRules.value ?: emptyList())) { + if (t.guid == fatherId) { + t.score += r.first.score + break + } + } + } + } + + /** + * 璁$畻鏌愪竴鍏蜂綋璇勫垎鏍囧噯鐨勫緱鍒嗭紝骞朵笖鏍规嵁閫夐」鍜屽垎鏁颁笂闄愯绠楁渶缁堝緱鍒� + * @param rulePair 浜岀骇鍜屼笁绾ц瘎鍒嗚鍒欑殑瀵瑰簲缁撴瀯 + */ + fun subRuleCal(rulePair: Pair<EvaluationSubRuleVo, MutableList<EvaluationSubRuleVo>>?) { val rule = rulePair?.first val itemList = rulePair?.second - var total: Int? = null + var total = 0 itemList?.forEach { - if (!it.extension1.isNullOrBlank()) { - total = (total ?: 0) + it.extension1!!.toInt() + total += it.score + } +// val s = if (abs(total) > rule?.maxscore!!) { +// when (rule.extension2) { +// // 鍑忓垎妯″紡锛岃褰曚负鎵e垎锛堣礋鏁帮級 +// Constant.EvaGradeMode.MINUS_MODE.value -> { +// 0 - rule.maxscore!! +// } +// // 鍔犲垎妯″紡锛岃褰曚负寰楀垎锛堟鏁帮級 +// Constant.EvaGradeMode.ADD_MODE.value -> { +// rule.maxscore!! +// } +// // 榛樿鍑忓垎妯″紡 +// else -> { +// 0 - rule.maxscore!! +// } +// } +// } else { +// total +// } +// rule.score = s + rule?.score = total + } + + /** + * 鐢熸垚璇勪及璁板綍缁撴灉 + * @param evaluationScene 闇�瑕佽瘎浼扮殑瀵硅薄 + * @return 璇勪及鎬诲垎鍜屽搴旂粏鍒欏緱鍒嗙殑鏁版嵁搴撶粨鏋� + */ + fun genEvaRecord(evaluationScene: AopDataSource.EvaluationScene): Pair<Evaluation, List<Itemevaluation>>? { + val scene = evaluationScene.scene.value ?: return null + val topRules = evaluationScene.topRules.value ?: return null + val baseRule = evaluationScene.baseRule.value + val rules = evaluationScene.rules.value ?: return null + val subTask = evaluationScene.subTask.value + val inspection = evaluationScene.inspection.value + + var total = 0 //鎬诲緱鍒� + topRules.forEach top@{ top -> + total += top.getFinalScore() + } + val evaluation = EvaluationVo.newAutoEvaluation(inspection, subTask, scene, baseRule, total) + //瀛愰」鍏蜂綋寰楀垎 + val itemList = mutableListOf<Itemevaluation>() + topRules.forEach { subRule -> + val item = ItemEvaluationVo.newItemEvaluation(baseRule, subTask, inspection, subRule) + itemList.add(item) + } + rules.forEach { p -> + if (p.first.ertype != 2) { + val item = ItemEvaluationVo.newItemEvaluation(baseRule, subTask, inspection, p.first) + itemList.add(item) + } + p.second.forEach { r -> + val item1 = ItemEvaluationVo.newItemEvaluation(baseRule, subTask, inspection, r) + itemList.add(item1) } } - if (total == null) { - rule?.extension1 = "0" - } else { - val s = if (abs(total!!) > rule?.maxscore!!) { - 0 - rule.maxscore!! - } else { - total - } - rule.extension1 = s.toString() + return Pair(evaluation, itemList) + } + + /** + * 鏇存柊璇勪及璁板綍缁撴灉 + * @param evaluationScene 闇�瑕佽瘎浼扮殑瀵硅薄 + * @return 璇勪及鎬诲垎鍜屽搴旂粏鍒欏緱鍒嗙殑鏁版嵁搴撶粨鏋� + */ + fun updateEvaRecord(evaluationScene: AopDataSource.EvaluationScene): Pair<Evaluation, List<Itemevaluation>>? { + val topRules = evaluationScene.topRules.value ?: return null + val rules = evaluationScene.rules.value ?: return null + + val evaluation = evaluationScene.evaluation.value ?: return null + val itemevaluationList = evaluationScene.itemevaluationList.value ?: return null + + var total = 0 //鎬诲緱鍒� + topRules.forEach top@{ top -> + total += top.getFinalScore() } + evaluation.apply { + resultscorebef = total.toString() + updatedate = Date() + } + //瀛愰」鍏蜂綋寰楀垎 + topRules.forEach { subRule -> + itemevaluationList.find { it.esrguid == subRule.guid }?.let { + it.value = subRule.score.toString() + it.extension1 = subRule.selected.toString() + } + } + rules.forEach { p -> + // 鍙兘瀛樺湪绗竴灞傜骇涓嬪睘鐩存帴涓虹涓夊眰绾х殑鎯呭喌 + if (p.first.ertype != 2) { + itemevaluationList.find { it.esrguid == p.first.guid }?.let { + it.value = p.first.score.toString() + it.extension1 = p.first.selected.toString() + } + } + p.second.forEach { r -> + itemevaluationList.find { it.esrguid == r.guid }?.let { + it.value = r.score.toString() + it.extension1 = r.selected.toString() + } + } + } + return Pair(evaluation, itemevaluationList) } /** * 鐢熸垚鏂扮殑涓�鏉¤瘎鍒嗚褰� */ - fun newItemEvaluation(evaluationScene: AopDataSource.EvaluationScene, itemRule: Evaluationsubrule2) = + fun newItemEvaluation(evaluationScene: AopDataSource.EvaluationScene, itemRule: EvaluationSubRuleVo) = Itemevaluation().apply { val rule = evaluationScene.baseRule.value val subTask = evaluationScene.subTask.value @@ -62,8 +180,8 @@ ertype = itemRule.ertype esrguid = itemRule.guid name = itemRule.itemname - value = itemRule.extension1 ?: "0" - extension1 = (itemRule.extension1 != null).toString() + value = itemRule.score.toString() + extension1 = itemRule.selected.toString() } /** -- Gitblit v1.9.3