riku
2020-06-02 9a5f9bfc4f4b153dd0175c63f563d8047e1e2515
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
package com.flightfeather.uav.repository.impl
 
import com.flightfeather.uav.domain.entity.ThresholdValue
import com.flightfeather.uav.domain.mapper.ThresholdValueMapper
import com.flightfeather.uav.lightshare.bean.ThresholdValueVo
import com.flightfeather.uav.repository.ObdThresholdValueRepository
import org.springframework.beans.BeanUtils
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
 
/**
 * @author riku
 * Date: 2019/9/5
 */
@Repository
class ObdThresholdValueDaoImpl(val obdThresholdValueMapper: ThresholdValueMapper) : ObdThresholdValueRepository {
 
    override fun save(userId: String, thresholdValueVo: ThresholdValueVo): Boolean {
        val thresholdValue = ThresholdValue()
        BeanUtils.copyProperties(thresholdValueVo, thresholdValue)
        val example = Example(ThresholdValue::class.java).apply {
            createCriteria().andEqualTo("obdVin", thresholdValueVo.obdVin)
        }
        val tempResult = obdThresholdValueMapper.selectByExample(example)
        return if (tempResult.isNotEmpty())
            false
        else
            obdThresholdValueMapper.insert(thresholdValue) == 1
    }
 
    override fun update(userId: String, thresholdValueVo: ThresholdValueVo): Boolean {
        val thresholdValue = ThresholdValue()
        BeanUtils.copyProperties(thresholdValueVo, thresholdValue)
        val example = Example(ThresholdValue::class.java).apply {
            createCriteria().andEqualTo("obdVin", thresholdValue.obdVin)
        }
        return obdThresholdValueMapper.updateByExample(thresholdValue, example) == 1
    }
 
    override fun getByVinCode(vinCode: String): ThresholdValueVo? {
        val example = Example(ThresholdValue::class.java).apply {
            createCriteria().andEqualTo("obdVin", vinCode)
        }
 
        val result = obdThresholdValueMapper.selectByExample(example)
 
        if (result.isNotEmpty()) {
            val vo = ThresholdValueVo()
            BeanUtils.copyProperties(result[0], vo)
            return vo
        }
 
        return null
    }
 
}