qixiaoning
2025-07-24 343a89f9fa20d2d142469b2a4531e16ce03d3525
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
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
}