zmc
2023-11-02 6f28997aa8d9f62e0c54838490a473041f709742
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
package com.flightfeather.monitor.domain.ds1.repository
 
import com.flightfeather.monitor.domain.ds1.entity.DustExceptionData
import com.flightfeather.monitor.domain.ds1.mapper.DustExceptionDataMapper
import com.github.pagehelper.PageHelper
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
import java.time.LocalDate
 
@Repository
class DustExceptionDataRep(private val dustExceptionDataMapper: DustExceptionDataMapper) {
 
    /**
     * 获取最新一条记录
     */
    fun findLatestData(): DustExceptionData? {
        val p = PageHelper.startPage<DustExceptionData>(1, 1)
        dustExceptionDataMapper.selectByExample(Example(DustExceptionData::class.java).apply {
            orderBy("endTime").desc()
        })
        return if (p.isNotEmpty()) {
            p[0]
        } else {
            null
        }
    }
 
    /**
     * 判断某天的异常分析数据是否存在
     */
    fun findDataExist(date: LocalDate): Boolean {
        val s = date.atStartOfDay()
        val e = s.plusDays(1).minusSeconds(1)
        val res = dustExceptionDataMapper.selectOneByExample(Example(DustExceptionData::class.java).apply {
            createCriteria().andBetween("endTime", s, e)
        })
        return res != null
    }
 
    /**
     * 存储异常分析结果
     */
    fun insert(list: List<DustExceptionData>): Int {
        return dustExceptionDataMapper.insertList(list)
    }
}