feiyu02
2024-09-25 0516cba27e632f20efac2752787f38f0c87baafa
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
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,
    private val evaluationRep: EvaluationRep,
    private val evaluationRuleRep: EvaluationRuleRep,
    private val sceneRep: SceneRep,
) : EvaluationsubruleService {
 
    override fun findOne(id: String): Evaluationsubrule = evaluationsubruleMapper.selectByPrimaryKey(id)
 
    override fun findAll(): MutableList<Evaluationsubrule> = evaluationsubruleMapper.selectAll()
 
    override fun save(evaluationsubrule: Evaluationsubrule): Int = evaluationsubruleMapper.insert(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<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 ->
            evaluationsubruleMapper.selectByExample(Example(Evaluationsubrule::class.java).apply {
                createCriteria().andEqualTo("erguid", rule.guid)
            })
        }?.also {
            result.addAll(it)
        }
 
        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
    }
}