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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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.lightshare.service.ItemevaluationService
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(
    private val itemevaluationMapper: ItemevaluationMapper,
    private val aopDbMapper: AopDbMapper,
    private val aopOutput: AopOutput,
    private val aopSceneTypeCheck: AopSceneTypeCheck,
    private val subTaskRep: SubTaskRep,
) : ItemevaluationService {
 
    //批量修改单项评估
    @Transactional
    override fun updatelist(itemevaluationlist: List<Itemevaluation>): Int {
        //循环修改
        itemevaluationlist.forEach {
            itemevaluationMapper.updateByPrimaryKeySelective(it)
        }
        return itemevaluationlist.size
    }
 
    //批量保存单项评估
    @Transactional
    override fun savelist(itemevaluationlist: List<Itemevaluation>): Int {
        //循环新增
        itemevaluationlist.forEach {
            itemevaluationMapper.insert(it)
        }
        return itemevaluationlist.size
    }
 
    //根据子任务ID获取单项评估列表
    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()
            BeanUtils.copyProperties(it, itemvaluationVo)
            itemvaluationVoList.add(itemvaluationVo)
        }
        return itemvaluationVoList
    }
 
    override fun findOne(id: String): Itemevaluation = itemevaluationMapper.selectByPrimaryKey(id)
 
    override fun findAll(): MutableList<Itemevaluation> = itemevaluationMapper.selectAll()
 
    override fun save(itemevaluation: Itemevaluation): Int = itemevaluationMapper.insert(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("出现系统内部错误")
        }
    }
}