feiyu02
2023-11-14 8f069a80ed15dd431450f58304513aa3985e62ba
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
package com.flightfeather.monitor.domain.ds1.repository
 
import com.flightfeather.monitor.domain.ds1.entity.RiskValue
import com.flightfeather.monitor.domain.ds1.mapper.RiskValueMapper
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
import java.time.LocalDate
 
@Repository
class RiskValueRep(private val riskValueMapper: RiskValueMapper) {
 
    /**
     * 获取最新一条记录
     */
    fun findLatestData(type: String): RiskValue? {
        val p = PageHelper.startPage<RiskValue>(1, 1)
        riskValueMapper.selectByExample(Example(RiskValue::class.java).apply {
            createCriteria().andEqualTo("type", type)
            orderBy("lst").desc()
        })
        return if (p.isNotEmpty()) {
            p[0]
        } else {
            null
        }
    }
 
    /**
     * 插入列表
     * @param list
     */
    fun insert(list: List<RiskValue>): Int {
        return riskValueMapper.insertList(list)
    }
 
    /**
     * 查询
     * @param mnCode
     * @param date
     * @param type
     */
    fun select(mnCode: String, date: LocalDate, type: String): List<RiskValue?> {
        val s = date.withDayOfMonth(1).atStartOfDay()
        val e = s.plusMonths(1).minusSeconds(1)
        return riskValueMapper.selectByExample(Example(RiskValue::class.java).apply {
            createCriteria().andEqualTo("mnCode", mnCode)
                .andBetween("lst", s, e)
                .andEqualTo("type", type)
        })
    }
}