feiyu02
2025-08-14 f373bbf83d9d2a7e5f96118d7dcd658c9fea8bc8
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
package cn.flightfeather.supervision.business.autooutput
 
import cn.flightfeather.supervision.business.autooutput.datasource.AopDataSource
import cn.flightfeather.supervision.domain.ds1.entity.DustDataResult
import cn.flightfeather.supervision.domain.ds1.entity.Evaluation
import cn.flightfeather.supervision.domain.ds1.entity.Itemevaluation
import cn.flightfeather.supervision.domain.ds1.mapper.DustDataResultMapper
import cn.flightfeather.supervision.domain.ds1.mapper.EvaluationMapper
import cn.flightfeather.supervision.domain.ds1.mapper.ItemevaluationMapper
import org.springframework.stereotype.Component
import org.springframework.transaction.annotation.Transactional
import tk.mybatis.mapper.entity.Example
 
/**
 * 自动评估结果输出
 */
@Component
class AopOutput(
    private val evaluationMapper: EvaluationMapper,
    private val itemevaluationMapper: ItemevaluationMapper,
    private val dustDataResultMapper: DustDataResultMapper
) {
 
    /**
     * 将评分记录输出至数据库
     */
    @Transactional
    fun toDbEvaluation(evaluationScene: AopDataSource.EvaluationScene, p: Pair<Evaluation, List<Itemevaluation>>) {
        //去除已有记录
        evaluationMapper.deleteByExample(Example(Evaluation::class.java).apply {
            createCriteria().andEqualTo("stguid", evaluationScene.subTask.value?.stguid)
        })
        itemevaluationMapper.deleteByExample(Example(Itemevaluation::class.java).apply {
            createCriteria().andEqualTo("stguid", evaluationScene.subTask.value?.stguid)
        })
 
        //写入数据库
        evaluationMapper.insert(p.first)
        p.second.forEach { il -> itemevaluationMapper.insert(il) }
    }
 
    /**
     * 将评分记录更新至数据库
     */
    @Transactional
    fun updateDbEvaluation(evaluationScene: AopDataSource.EvaluationScene, p: Pair<Evaluation, List<Itemevaluation>>) {
        evaluationMapper.updateByPrimaryKey(p.first)
        p.second.forEach { il -> itemevaluationMapper.updateByPrimaryKey(il) }
    }
 
    /**
     * 将监测数据统计结果入库
     */
    fun toDbDataResult(dustDataResult: DustDataResult) {
        val d = dustDataResultMapper.selectOne(DustDataResult().apply {
            drSceneId = dustDataResult.drSceneId
            drTime = dustDataResult.drTime
        })
        if (d == null) {
            dustDataResultMapper.insert(dustDataResult)
        } else {
            dustDataResult.drId = d.drId
            dustDataResultMapper.updateByPrimaryKey(dustDataResult)
        }
    }
}