qixiaoning
2025-07-08 84d2ef9760af0a4a4aa933937294400b3caa291d
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
package models
 
type CameraSensor struct {
    CameraId string `json:"camera_id"`
    SensorId string `json:"sensor_id"`
}
 
func (CameraSensor) TableName() string {
    return "camera_sensor"
}
 
func (cs *CameraSensor) Exist(cameraId string, sensorId string) bool {
    result := db.Table(cs.TableName()).Where("camera_id=? and sensor_id=?", cameraId, sensorId).First(&cs)
    if result.Error != nil || result.RowsAffected == 0 {
        return false
    }
    return true
}
 
func (cs *CameraSensor) Add() bool {
    result := db.Table(cs.TableName()).Create(&cs)
    if result.Error == nil && result.RowsAffected > 0 {
        return true
    }
    return false
}
 
func (cs *CameraSensor) Delete(cameraId string, sensorId string) bool {
    result := db.Exec("delete from camera_sensor where camera_id='" + cameraId + "' and sensor_id='" + sensorId + "'")
    if result.Error == nil {
        return true
    }
 
    return false
}
 
func (cs *CameraSensor) DeleteByCamId(cameraId string) bool {
    result := db.Exec("delete from camera_sensor where camera_id='" + cameraId + "'")
    if result.Error == nil {
        return true
    }
 
    return false
}
 
func (ca *CameraSensor) FindAll() (cams []CameraSensor, err error) {
    dberr := db.Table(ca.TableName()).Find(&cams)
    if dberr.Error != nil {
        return nil, err
    }
    return cams, nil
}