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.obd.repository.impl
 
import com.flightfeather.obd.domain.entity.ObdData
import com.flightfeather.obd.domain.mapper.ObdDataMapper
import com.flightfeather.obd.lightshare.bean.ObdDataVo
import com.flightfeather.obd.repository.ObdDataRepository
import com.github.pagehelper.PageHelper
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
 
/**
 * obd数据相关数据库操作实现
 * @author riku
 * Date: 2019/8/27
 */
@Repository
class ObdDataDaoImpl(val obdDataMapper: ObdDataMapper) : ObdDataRepository {
 
    override fun saveObdData(data: ObdDataVo) {
        val obdData = ObdData()
        BeanUtils.copyProperties(data, obdData)
        obdDataMapper.insert(obdData)
    }
 
    override fun getDataByVinCode(vinCode: String, pageNum: Int?, pageSize: Int?): MutableList<ObdDataVo> {
        val example = Example(ObdData::class.java).apply {
            createCriteria().andEqualTo("obdVin", vinCode)
            orderBy("obdTime").desc()
        }
 
        //分页
        val offset = (pageSize?.times(pageNum?.minus(1) ?: 0)) ?: 0
        val a = PageHelper.offsetPage<ObdData>(offset, pageSize ?: 10)
        val result = obdDataMapper.selectByExample(example)
 
        val resultList = mutableListOf<ObdDataVo>()
        result.forEach {
            val vo = ObdDataVo()
            BeanUtils.copyProperties(it, vo)
            resultList.add(vo)
        }
 
        return resultList
    }
}