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/lightshare/service/impl/EvaluationsubruleServiceImpl.kt |   58 +++++++++++++++++++++++++++++++++++++++++++++-------------
 1 files changed, 45 insertions(+), 13 deletions(-)

diff --git a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/EvaluationsubruleServiceImpl.kt b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/EvaluationsubruleServiceImpl.kt
index d104301..e972031 100644
--- a/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/EvaluationsubruleServiceImpl.kt
+++ b/src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/EvaluationsubruleServiceImpl.kt
@@ -1,18 +1,27 @@
 package cn.flightfeather.supervision.lightshare.service.impl
 
+import cn.flightfeather.supervision.common.exception.BizException
 import cn.flightfeather.supervision.domain.ds1.entity.Evaluationrule
 import cn.flightfeather.supervision.domain.ds1.entity.Evaluationsubrule
+import cn.flightfeather.supervision.domain.ds1.entity.Evaluationsubrule2
 import cn.flightfeather.supervision.domain.ds1.mapper.EvaluationruleMapper
 import cn.flightfeather.supervision.domain.ds1.mapper.EvaluationsubruleMapper
+import cn.flightfeather.supervision.domain.ds1.repository.EvaluationRep
+import cn.flightfeather.supervision.domain.ds1.repository.EvaluationRuleRep
+import cn.flightfeather.supervision.domain.ds1.repository.SceneRep
 import cn.flightfeather.supervision.lightshare.service.EvaluationsubruleService
+import cn.flightfeather.supervision.lightshare.vo.ScoreDetail
 import org.springframework.stereotype.Service
 import tk.mybatis.mapper.entity.Example
 
 @Service
-class EvaluationsubruleServiceImpl (
-        val evaluationsubruleMapper: EvaluationsubruleMapper,
-        val evaluationruleMapper: EvaluationruleMapper
-):EvaluationsubruleService {
+class EvaluationsubruleServiceImpl(
+    val evaluationsubruleMapper: EvaluationsubruleMapper,
+    val evaluationruleMapper: EvaluationruleMapper,
+    private val evaluationRep: EvaluationRep,
+    private val evaluationRuleRep: EvaluationRuleRep,
+    private val sceneRep: SceneRep,
+) : EvaluationsubruleService {
 
     override fun findOne(id: String): Evaluationsubrule = evaluationsubruleMapper.selectByPrimaryKey(id)
 
@@ -20,24 +29,21 @@
 
     override fun save(evaluationsubrule: Evaluationsubrule): Int = evaluationsubruleMapper.insert(evaluationsubrule)
 
-    override fun update(evaluationsubrule: Evaluationsubrule): Int = evaluationsubruleMapper.updateByPrimaryKey(evaluationsubrule)
+    override fun update(evaluationsubrule: Evaluationsubrule): Int =
+        evaluationsubruleMapper.updateByPrimaryKey(evaluationsubrule)
 
     override fun delete(id: String): Int = evaluationsubruleMapper.deleteByPrimaryKey(id)
 
-    override fun findByRuleId(erguid: String): List<Evaluationsubrule> {
-        val example = Example(Evaluationsubrule::class.java)
-        val criteria = example.createCriteria()
-        criteria.andEqualTo("erguid", erguid)
-        example.orderBy("extension1").desc()
-        return evaluationsubruleMapper.selectByExample(example)
+    override fun findByRuleId(erguid: String): List<Evaluationsubrule2> {
+        return evaluationRuleRep.findSubRule(erguid)
     }
 
     override fun search(districtCode: String, sceneTypeId: String, version: String?): List<Evaluationsubrule> {
         val result = mutableListOf<Evaluationsubrule>()
         evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
             createCriteria().andEqualTo("districtcode", districtCode)
-                    .andEqualTo("scensetypeid", sceneTypeId)
-        }).takeIf { it.isNotEmpty() }?.get(0)?.let {rule ->
+                .andEqualTo("scensetypeid", sceneTypeId)
+        }).takeIf { it.isNotEmpty() }?.get(0)?.let { rule ->
             evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply {
                 createCriteria().andEqualTo("erguid", rule.guid)
             })
@@ -47,4 +53,30 @@
 
         return result
     }
+
+    override fun getAutoScore(subTaskId: String): ScoreDetail {
+        //鍦烘櫙淇℃伅
+        val scene = sceneRep.findBySubTask(subTaskId)
+        //鎬诲垎
+        val evaluation = evaluationRep.findBySubtask(subTaskId)
+        //瀛愯鍒欓�愭潯寰楀垎
+        val subRuleScores = evaluationRep.findItemEvaluation(subTaskId)
+        if (subRuleScores.isEmpty()) throw BizException("鏃犺瘎浼拌褰�")
+        //璇勫垎鎬昏鍒�
+        val rule = evaluationRuleRep.findAutoEvaluationRule(subTaskId) ?: throw BizException("鏈壘鍒扮浉鍏宠嚜鍔ㄨ瘎浼拌鍒�")
+        //鎬昏鍒欏搴旂殑璇勫垎瀛愯鍒�
+        val subRules = evaluationRuleRep.findSubRule(rule.guid)
+        //鏌ヨ缁撴灉
+        val result = ScoreDetail()
+        result.status = if (scene?.extension1.equals("1")) "鍦ㄥ缓" else "瀹屽伐"
+
+        result.updateTime = evaluation?.updatedate
+        subRules.forEach {
+            it.ertype ?: return@forEach
+            result.addDetail(result.details, it, it.ertype!! - 1, subRuleScores, false)
+        }
+        result.calScore()
+
+        return result
+    }
 }
\ No newline at end of file

--
Gitblit v1.9.3