feiyu02
2024-07-08 b212ef0208cb094f63ea8a239a1361f8e859c839
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
package cn.flightfeather.supervision.domain.ds1.repository
 
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.domain.ds1.entity.Evaluationrule
import cn.flightfeather.supervision.domain.ds1.entity.Evaluationsubrule2
import cn.flightfeather.supervision.domain.ds1.mapper.EvaluationruleMapper
import cn.flightfeather.supervision.domain.ds1.mapper.EvaluationsubruleMapper2
import cn.flightfeather.supervision.lightshare.vo.AreaEvaVo
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
 
/**
 * 评估规则数据库相关操作
 */
@Repository
class EvaluationRuleRep(
    private val evaluationruleMapper: EvaluationruleMapper,
    private val evaluationsubruleMapper2: EvaluationsubruleMapper2,
    private val sceneRep: SceneRep,
) {
 
    /**
     * 根据参数查询总规则
     * @param areaEvaVo 查询参数
     * @return
     */
    fun findBaseRule(areaEvaVo: AreaEvaVo): List<Evaluationrule?> {
        return evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
            createCriteria().andEqualTo("tasktypeid", areaEvaVo.taskTypeId)
                .andEqualTo("scensetypeid", areaEvaVo.scensetypeid)
                .andEqualTo("isuse", true)
            and(createCriteria().orEqualTo("provincecode", areaEvaVo.provincecode).orIsNull("provincecode"))
            and(createCriteria().orEqualTo("citycode", areaEvaVo.citycode).orIsNull("citycode"))
            and(createCriteria().orEqualTo("districtcode", areaEvaVo.districtcode).orIsNull("districtcode"))
            and(createCriteria().orEqualTo("towncode", areaEvaVo.towncode).orIsNull("towncode"))
        })
    }
 
    /**
     * 根据巡查任务id找到对应自动评估规则
     * @param subTaskId
     * @return
     */
    fun findAutoEvaluationRule(subTaskId:String): Evaluationrule? {
        val scene = sceneRep.findBySubTask(subTaskId)
        return findAutoEvaluationRule(Constant.SceneType.getByValue(scene?.typeid.toString()))
    }
 
    /**
     * 根据场景类型找到自动评估规则
     * 自动评估规则参数[Evaluationrule.tasktypeid] = 99
     * @param sceneType
     * @return
     */
    fun findAutoEvaluationRule(sceneType: Constant.SceneType): Evaluationrule? {
        return evaluationruleMapper.selectOne(Evaluationrule().apply {
            scensetypeid = sceneType.value.toByteOrNull()
            tasktypeid = 99
        })
    }
 
    /**
     * 根据总规则id找到子规则
     * @param ruleId
     * @return
     */
    fun findSubRule(ruleId: String?): List<Evaluationsubrule2> {
        return evaluationsubruleMapper2.selectByExample(Example(Evaluationsubrule2::class.java).apply {
            createCriteria().andEqualTo("erguid", ruleId)
            orderBy("ertype").orderBy("displayid")
        })
    }
 
}