feiyu02
2025-07-31 6688232eaa889eeb6c58d0d804b587699db55ec2
src/main/kotlin/cn/flightfeather/supervision/lightshare/service/impl/ItemevaluationServiceImpl.kt
@@ -1,22 +1,39 @@
package cn.flightfeather.supervision.lightshare.service.impl
import cn.flightfeather.supervision.business.autooutput.AopOutput
import cn.flightfeather.supervision.business.autooutput.datasource.AopDataSource
import cn.flightfeather.supervision.business.autooutput.datasource.AopDbMapper
import cn.flightfeather.supervision.business.autooutput.datasource.AopSceneTypeCheck
import cn.flightfeather.supervision.business.autooutput.score.ScoreUtil
import cn.flightfeather.supervision.common.exception.BizException
import cn.flightfeather.supervision.domain.ds1.entity.Itemevaluation
import cn.flightfeather.supervision.domain.ds1.mapper.ItemevaluationMapper
import cn.flightfeather.supervision.domain.ds1.repository.SubTaskRep
import cn.flightfeather.supervision.domain.ds1.repository.TaskRep
import cn.flightfeather.supervision.lightshare.service.ItemevaluationService
import cn.flightfeather.supervision.lightshare.vo.ItemevaluationVo
import cn.flightfeather.supervision.lightshare.vo.AreaVo
import cn.flightfeather.supervision.lightshare.vo.EvaluationUpdateVo
import cn.flightfeather.supervision.lightshare.vo.ItemEvaluationVo
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Service
import org.springframework.transaction.annotation.Transactional
@Service
class ItemevaluationServiceImpl(val itemevaluationMapper: ItemevaluationMapper) : ItemevaluationService {
class ItemevaluationServiceImpl(
    private val itemevaluationMapper: ItemevaluationMapper,
    private val aopDbMapper: AopDbMapper,
    private val aopOutput: AopOutput,
    private val aopSceneTypeCheck: AopSceneTypeCheck,
    private val subTaskRep: SubTaskRep,
    private val taskRep: TaskRep,
) : ItemevaluationService {
    //批量修改单项评估
    @Transactional
    override fun updatelist(itemevaluationlist: List<Itemevaluation>): Int {
        //循环修改
        itemevaluationlist.forEach {
            itemevaluationMapper.updateByPrimaryKey(it)
            itemevaluationMapper.updateByPrimaryKeySelective(it)
        }
        return itemevaluationlist.size
    }
@@ -32,13 +49,13 @@
    }
    //根据子任务ID获取单项评估列表
    override fun findBySubTaskID(subTaskID: String): List<ItemevaluationVo> {
        val itemvaluationVoList = mutableListOf<ItemevaluationVo>()
    override fun findBySubTaskID(subTaskID: String): List<ItemEvaluationVo> {
        val itemvaluationVoList = mutableListOf<ItemEvaluationVo>()
        val itemvaluation = Itemevaluation()
        itemvaluation.stguid = subTaskID
        val itemvaluationList = itemevaluationMapper.select(itemvaluation)
        itemvaluationList.forEach {
            val itemvaluationVo = ItemevaluationVo()
            val itemvaluationVo = ItemEvaluationVo()
            BeanUtils.copyProperties(it, itemvaluationVo)
            itemvaluationVoList.add(itemvaluationVo)
        }
@@ -51,7 +68,70 @@
    override fun save(itemevaluation: Itemevaluation): Int = itemevaluationMapper.insert(itemevaluation)
    override fun update(itemevaluation: Itemevaluation): Int = itemevaluationMapper.updateByPrimaryKey(itemevaluation)
    override fun update(itemevaluation: Itemevaluation): Int =
        itemevaluationMapper.updateByPrimaryKeySelective(itemevaluation)
    override fun delete(id: String): Int = itemevaluationMapper.deleteByPrimaryKey(id)
    @Transactional
    override fun createItemEvaluation(subTaskId: String, ruleId: String?, itemList: List<String>): Boolean {
        val source = AopDataSource(aopDbMapper, aopSceneTypeCheck)
        val subTask = subTaskRep.findOne(subTaskId) ?: throw BizException("巡查任务不存在")
        source.setResource(subTask)
        try {
            source.runBySubTask { _, evaluationScene ->
                if (evaluationScene.noRecord()) throw BizException("巡查任务不存在")
                // 将分数赋值到对应的评估规则下,并且自动计算其余规则的得分
                ScoreUtil.scoreAssign(evaluationScene, itemList)
                // 获取总分和子项得分数据库表结构体,并入库
                ScoreUtil.genEvaRecord(evaluationScene)?.let { aopOutput.toDbEvaluation(evaluationScene, it) }
            }
            return true
        } catch (e: Exception) {
            throw BizException("出现系统内部错误")
        }
    }
    @Transactional
    override fun updateItemEvaluation(subTaskId: String, ruleId: String?, itemList: List<String>): Boolean {
        val source = AopDataSource(aopDbMapper, aopSceneTypeCheck)
        val subTask = subTaskRep.findOne(subTaskId) ?: throw BizException("巡查任务不存在")
        source.setResource(subTask)
        try {
            source.runBySubTask { _, evaluationScene ->
                if (evaluationScene.noRecord()) throw BizException("巡查任务不存在")
                // 将分数赋值到对应的评估规则下,并且自动计算其余规则的得分
                ScoreUtil.scoreAssign(evaluationScene, itemList)
                // 获取总分和子项得分数据库表结构体,并入库
                ScoreUtil.updateEvaRecord(evaluationScene)?.let { aopOutput.updateDbEvaluation(evaluationScene, it) }
            }
            return true
        } catch (e: Exception) {
            throw BizException("出现系统内部错误")
        }
    }
    override fun updateMonitorDataEva(evaVo: EvaluationUpdateVo): Boolean {
        val task = taskRep.findOneTask(evaVo)
        val taskId = task?.tguid
        val sceneType = evaVo.scensetypeid?.toInt() ?: throw BizException("场景类型未设置,无法更新分数")
        val source = AopDataSource(aopDbMapper, aopSceneTypeCheck)
        source.setResource(taskId, sceneType, null, null)
        try {
            source.loop() { _, evaluationScene ->
                if (evaluationScene.noRecord()) throw BizException("巡查任务不存在")
                evaVo.subTaskEvaList?.find {
                    it.subTaskId == evaluationScene.subTask.value?.stguid
                }?.let {stEva ->
                    // 将分数赋值到对应的评估规则下,并且自动计算其余规则的得分
                    ScoreUtil.scoreAssignSelected(evaluationScene, stEva.subRule)
                    // 获取总分和子项得分数据库表结构体,并入库
                    ScoreUtil.updateEvaRecord(evaluationScene)?.let { aopOutput.updateDbEvaluation(evaluationScene, it) }
                }
            }
            return true
        } catch (e: Exception) {
            throw BizException("出现系统内部错误")
        }
    }
}