feiyu02
2025-09-18 baf2cc2ce3dfd1235c012a3750132769fcd9ad2f
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/EvaluationsubruleServiceImpl.kt
@@ -1,51 +1,52 @@
package cn.flightfeather.supervision.lightshare.service.impl
import cn.flightfeather.supervision.domain.ds1.entity.*
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.mapper.EvaluationsubruleMapper2
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.EvaluationVo
import cn.flightfeather.supervision.lightshare.vo.SubEvaluationVo
import cn.flightfeather.supervision.lightshare.vo.ThirdEvaluationVo
import cn.flightfeather.supervision.lightshare.vo.ScoreDetail
import org.springframework.stereotype.Service
import tk.mybatis.mapper.entity.Example
@Service
class EvaluationsubruleServiceImpl(
    val evaluationsubruleMapper2: EvaluationsubruleMapper2,
    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 findOne(id: String): Evaluationsubrule2 = evaluationsubruleMapper2.selectByPrimaryKey(id)
    override fun findAll(): MutableList<Evaluationsubrule> = evaluationsubruleMapper.selectAll()
    override fun save(evaluationsubrule: Evaluationsubrule): Int = evaluationsubruleMapper.insert(evaluationsubrule)
    override fun save(evaluationsubrule: Evaluationsubrule2): Int = evaluationsubruleMapper2.insert(evaluationsubrule)
    override fun update(evaluationsubrule: Evaluationsubrule): Int =
        evaluationsubruleMapper.updateByPrimaryKey(evaluationsubrule)
    override fun update(evaluationsubrule: Evaluationsubrule2): Int =
        evaluationsubruleMapper2.updateByPrimaryKey(evaluationsubrule)
    override fun delete(id: String): Int = evaluationsubruleMapper.deleteByPrimaryKey(id)
    override fun delete(id: String): Int = evaluationsubruleMapper2.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>()
    override fun search(districtCode: String, sceneTypeId: String, version: String?): List<Evaluationsubrule2> {
        val result = mutableListOf<Evaluationsubrule2>()
        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 {
            evaluationsubruleMapper2.selectByExample(Example(Evaluationsubrule2::class.java).apply {
                createCriteria().andEqualTo("erguid", rule.guid)
            })
        }?.also {
@@ -55,127 +56,29 @@
        return result
    }
    override fun getAutoScore(subTaskId: String): List<EvaluationVo> {
    override fun getAutoScore(subTaskId: String): ScoreDetail {
        //场景信息
        val scene = sceneRep.findBySubTask(subTaskId)
        //总分
        val evaluation = evaluationRep.findBySubtask(subTaskId)
        //子规则逐条得分
        val subRuleScores = evaluationRep.findItemEvaluation(subTaskId)
        //总规则id
        val ruleId = mutableListOf<Evaluation>()
        if (subRuleScores.isEmpty()) throw BizException("无评估记录")
        //评分总规则
        val rule = evaluationRuleRep.findAutoEvaluationRule(subTaskId)
        val rule = evaluationRuleRep.findAutoEvaluationRule(subTaskId) ?: throw BizException("未找到相关自动评估规则")
        //总规则对应的评分子规则
        val subRules = mutableListOf<Evaluationsubrule2>()
        val subRules = evaluationRuleRep.findSubRule(rule.guid)
        //查询结果
        val resultList = mutableListOf<EvaluationVo>()
        val result = ScoreDetail()
        result.status = if (scene?.extension1.equals("1")) "在建" else "完工"
        var _group = 0
        result.updateTime = evaluation?.updatedate
        subRules.forEach {
            when (it.ertype) {
                2 -> resultList.add(EvaluationVo().apply {
                    id = it.guid
                    title1 = it.itemname
                    scoreMode = it.extension1
                    gradeMode = it.extension2
                    score = when (gradeMode) {
                        "minus_mode" -> it.minscore?.minus(it.maxscore ?: 0) ?: 0
                        "add_mode" -> it.maxscore ?: 0
                        else -> it.minscore?.minus(it.maxscore ?: 0) ?: 0
                    }
                    selectMode = it.extension3
                    //如果有得分记录,则改变状态为选中
                    for (s in subRuleScores) {
                        if (it.guid == s.esrguid) {
                            select = s.extension1 == "true"
                            break
                        }
                    }
                })
                3 -> {
                    for (r in resultList) {
                        if (it.fatherid == r.id) {
                            r.sub1.add(SubEvaluationVo().apply {
                                id = it.guid
                                title2 = it.itemname
                                gradeMode = it.extension2
                                selectMode = it.extension3
                                score = when (gradeMode) {
                                    "minus_mode" -> it.minscore?.minus(it.maxscore ?: 0) ?: 0
                                    "add_mode" -> it.maxscore ?: 0
                                    else -> it.minscore?.minus(it.maxscore ?: 0) ?: 0
                                }
                                group = _group++
                                //如果有得分记录,则改变状态为选中
                                for (s in subRuleScores) {
                                    if (it.guid == s.esrguid) {
                                        select = s.extension1 == "true"
                                        break
                                    }
                                }
                            })
                            break
                        }
                    }
                }
                4 -> {
                    resultList.forEach{ r ->
                        //4级的评估项直接附属于2级评估项
                        if (r.id == it.fatherid) {
                            if (r.sub1.isEmpty()) {
                                r.sub1.add(SubEvaluationVo().apply {
                                    placeholder = true
                                    id = it.guid
                                    title2 = r.title1
                                    score = r.score
                                    gradeMode = r.gradeMode
                                    selectMode = r.selectMode
                                    group = _group++
                                })
                            }
                            r.sub1[0].sub2.add(ThirdEvaluationVo().apply {
                                id = it.guid
                                content = it.itemname
                                score = when (r.sub1[0].gradeMode) {
                                    "minus_mode" -> r.score.plus(it.maxscore ?: 0)
                                    "add_mode" -> it.maxscore ?: 0
                                    else -> r.score.plus(it.maxscore ?: 0)
                                }
                                //如果有得分记录,则改变状态为选中
                                for (s in subRuleScores) {
                                    if (it.guid == s.esrguid) {
                                        select = s.extension1 == "true"
                                        break
                                    }
                                }
                            })
                        } else {
                            r.sub1.forEach { sr ->
                                if (sr.id == it.fatherid){
                                    sr.sub2.add(ThirdEvaluationVo().apply {
                                        id = it.guid
                                        content = it.itemname
                                        score = when (sr.gradeMode) {
                                            "minus_mode" -> sr.score.plus(it.maxscore ?: 0)
                                            "add_mode" -> it.maxscore ?: 0
                                            else -> sr.score.plus(it.maxscore ?: 0)
                                        }
                                        //如果有得分记录,则改变状态为选中
                                        for (s in subRuleScores) {
                                            if (it.guid == s.esrguid) {
                                                select = s.extension1 == "true"
                                                break
                                            }
                                        }
                                    })
                                }
                            }
                        }
                    }
                }
            }
            it.ertype ?: return@forEach
            result.addDetail(result.details, it, it.ertype!! - 1, subRuleScores, false)
        }
        result.calScore()
        return resultList
        return result
    }
}