feiyu02
2024-08-15 196bb14112448857a885e32dc4149e308e00b01a
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
package cn.flightfeather.supervision.domain.repository
 
import cn.flightfeather.supervision.domain.entity.Evaluation
import cn.flightfeather.supervision.domain.entity.Evaluationrule
import cn.flightfeather.supervision.domain.enumeration.AssessmentRuleType
import cn.flightfeather.supervision.domain.enumeration.SceneType
import cn.flightfeather.supervision.domain.mapper.EvaluationMapper
import cn.flightfeather.supervision.domain.mapper.EvaluationruleMapper
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
import java.time.LocalDateTime
 
/**
 * 评估相关数据库操作
 */
@Repository
class EvaluationRep(
    private val evaluationruleMapper: EvaluationruleMapper,
    private val evaluationMapper: EvaluationMapper,
) {
 
    /**
     * 获取评估基本规则(非自评)
     */
    fun findRule(sceneType: SceneType, ruleType: AssessmentRuleType = AssessmentRuleType.Total): Evaluationrule? {
        val list = evaluationruleMapper.selectByExample(Example(Evaluationrule::class.java).apply {
            createCriteria().andEqualTo("scensetypeid", sceneType.value)
                .andEqualTo("ruletype", ruleType.value)
            and(createCriteria().orIsNull("tasktypeid").orNotEqualTo("tasktypeid", 1))
        })
        return if (list.isNotEmpty()) {
            list[0]
        } else {
            null
        }
    }
 
    /**
     * 获取用户评估周期内最新一期评估总分
     */
    fun findLatest(ruleId: String?, userId: String, period: String, st: LocalDateTime, et: LocalDateTime): Evaluation? {
        val r = evaluationMapper.selectByExample(Example(Evaluation::class.java).apply {
            createCriteria().andEqualTo("iguid", userId)
                .andEqualTo("stguid", ruleId)
            and(
                createCriteria().orEqualTo("scensename", period)
                    .orBetween("createdate", st, et)
            )
            orderBy("createdate").desc()
        })
        return if (r.isNotEmpty()) {
            r[0]
        } else {
            null
        }
    }
}