feiyu02
2024-08-13 b8cc591541b88dd2bb93f111f8e8075842dce7ca
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package cn.flightfeather.supervision.domain.ds1.repository
 
import cn.flightfeather.supervision.common.utils.Constant
import cn.flightfeather.supervision.domain.ds1.entity.*
import cn.flightfeather.supervision.domain.ds1.mapper.DeviceStatusMapper
import cn.flightfeather.supervision.domain.ds1.mapper.MonitorDeviceInfoMapper
import cn.flightfeather.supervision.domain.ds1.mapper.TreatmentDeviceInfoMapper
import cn.flightfeather.supervision.domain.ds1.mapper.ProductionDeviceInfoMapper
import org.springframework.stereotype.Repository
 
/**
 *
 * @date 2024/7/24
 * @author feiyu02
 */
@Repository
class DeviceRep(
    private val monitorDeviceInfoMapper: MonitorDeviceInfoMapper,
    private val treatmentDeviceInfoMapper: TreatmentDeviceInfoMapper,
    private val productionDeviceInfoMapper: ProductionDeviceInfoMapper,
    private val deviceStatusMapper: DeviceStatusMapper,
) {
    /***--DeviceInfo--***/
 
    /**
     * 查询设备信息
     * @param deviceId 设备主键id
     * @param type 设备类型
     * @return 设备信息
     */
    fun findDevice(deviceId: Int, type: Constant.DeviceType): BaseDevice? {
        return when (type) {
            Constant.DeviceType.MONITOR_DEVICE -> monitorDeviceInfoMapper.selectByPrimaryKey(deviceId)
            Constant.DeviceType.TREATMENT_DEVICE -> treatmentDeviceInfoMapper.selectByPrimaryKey(deviceId)
            Constant.DeviceType.PRODUCTION_DEVICE -> productionDeviceInfoMapper.selectByPrimaryKey(deviceId)
        }
    }
 
    /**
     * 查询设备信息
     * @param sceneId 场景主键id
     * @param type 设备类型
     * @return 设备信息
     */
    fun findDeviceList(sceneId: String, type: Constant.DeviceType): List<BaseDevice> {
        return when (type) {
            Constant.DeviceType.MONITOR_DEVICE -> findDeviceList(MonitorDeviceInfo().apply { diSceneGuid = sceneId })
            Constant.DeviceType.TREATMENT_DEVICE -> findDeviceList(TreatmentDeviceInfo()
                .apply { piSceneGuid = sceneId })
            Constant.DeviceType.PRODUCTION_DEVICE -> findDeviceList(ProductionDeviceInfo()
                .apply { wiSceneGuid = sceneId })
        }
    }
    fun findDeviceList(monitorDeviceInfo: MonitorDeviceInfo): List<MonitorDeviceInfo> {
        return monitorDeviceInfoMapper.select(monitorDeviceInfo)
    }
    fun findDeviceList(treatmentDeviceInfo: TreatmentDeviceInfo): List<TreatmentDeviceInfo> {
        return treatmentDeviceInfoMapper.select(treatmentDeviceInfo)
    }
    fun findDeviceList(productionDeviceInfo: ProductionDeviceInfo): List<ProductionDeviceInfo> {
        return productionDeviceInfoMapper.select(productionDeviceInfo)
    }
 
    /**
     * 插入设备信息
     */
    fun insertDevice(monitorDeviceInfo: MonitorDeviceInfo): Int {
        return monitorDeviceInfoMapper.insert(monitorDeviceInfo)
    }
    fun insertDevice(treatmentDeviceInfo: TreatmentDeviceInfo): Int {
        return treatmentDeviceInfoMapper.insert(treatmentDeviceInfo)
    }
    fun insertDevice(productionDeviceInfo: ProductionDeviceInfo): Int {
        return productionDeviceInfoMapper.insert(productionDeviceInfo)
    }
 
    /**
     * 更新设备信息
     */
    fun updateDevice(monitorDeviceInfo: MonitorDeviceInfo): Int {
        return monitorDeviceInfoMapper.updateByPrimaryKey(monitorDeviceInfo)
    }
    fun updateDevice(treatmentDeviceInfo: TreatmentDeviceInfo): Int {
        return treatmentDeviceInfoMapper.updateByPrimaryKey(treatmentDeviceInfo)
    }
    fun updateDevice(productionDeviceInfo: ProductionDeviceInfo): Int {
        return productionDeviceInfoMapper.updateByPrimaryKey(productionDeviceInfo)
    }
 
    /***--DeviceStatus--***/
    fun findStatus(id: Int): DeviceStatus? {
        return deviceStatusMapper.selectByPrimaryKey(id)
    }
 
    fun findStatuses(deviceId: Int): List<DeviceStatus> {
        return findStatuses(DeviceStatus()
            .apply { dlDeviceId = deviceId })
    }
 
    fun findStatuses(location: DeviceStatus): List<DeviceStatus> {
        return deviceStatusMapper.select(location)
    }
 
    fun insertStatus(location: DeviceStatus): Int {
        return deviceStatusMapper.insert(location)
    }
 
    fun updateStatus(location: DeviceStatus): Int {
        return deviceStatusMapper.updateByPrimaryKey(location)
    }
}