Riku
2025-07-13 37d47c6a7ab0f454b948b68c987146b261117993
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
package com.flightfeather.uav.domain.repository
 
import com.flightfeather.uav.domain.entity.DeviceInfo
import com.flightfeather.uav.domain.entity.Mission
import com.flightfeather.uav.domain.mapper.DeviceInfoMapper
import com.flightfeather.uav.domain.mapper.MissionMapper
import com.flightfeather.uav.socket.eunm.UWDeviceType
import org.springframework.stereotype.Repository
import tk.mybatis.mapper.entity.Example
 
@Repository
class DeviceRep(private val deviceInfoMapper: DeviceInfoMapper) {
 
    fun find(deviceInfo: DeviceInfo): List<DeviceInfo> {
        return deviceInfoMapper.select(deviceInfo)
    }
 
    /**
     * 按字段条件相等查询
     */
    fun find(deviceType: UWDeviceType?, asc: Boolean = true): List<DeviceInfo> {
        return deviceInfoMapper.selectByExample(Example(DeviceInfo::class.java).apply {
            createCriteria().andEqualTo("deviceType", deviceType?.value)
            orderBy("displayIndex").apply {
                if (asc) asc() else desc()
            }
        })
    }
 
    /**
     * 插入一台新设备
     */
    fun insert(deviceInfo: DeviceInfo): Int {
        return deviceInfoMapper.insert(deviceInfo)
    }
 
    fun delete(deviceCode: String): Int {
        return deviceInfoMapper.deleteByPrimaryKey(deviceCode)
    }
}