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
package models
 
import (
    "basic.com/valib/logger.git"
    "github.com/satori/go.uuid"
    "time"
)
 
type CameraComposePerson struct {
    Id       string `gorm:"primary_key;column:id;type:varchar(100);unique;" json:"id"`
    CameraId string `gorm:"column:cameraId" json:"cameraId"`
    PersonId int    `gorm:"column:personId" json:"personId"`
    Status   int    `gorm:"column:status" json:"status"`
    AddTime  string `gorm:"column:addTime" json:"addTime"`
}
 
func (CameraComposePerson) TableName() string {
    return "camera_compose_person"
}
 
func (
    ca *CameraComposePerson) Save() error {
    ca.Id = uuid.NewV4().String()
    ca.AddTime = time.Now().Format("2006-01-02 15:04:05")
    result := db.Table("camera_compose_person").Save(&ca)
    if result.Error != nil {
        logger.Debug("创建失败", result.Error.Error())
        return result.Error
    }
    return nil
}
 
func (ca *CameraComposePerson) Clean() (result int64, err error) {
    exeResult := db.Exec("update camera_compose_person set status = 0 where cameraId=?", ca.CameraId)
    return exeResult.RowsAffected, exeResult.Error
}
 
func (ca *CameraComposePerson) FindAll(cameraId string) (list []CameraComposePerson, err error) {
    err = db.Table(ca.TableName()).Where("cameraId", cameraId).Find(&list).Error
    if err != nil {
        return nil, err
    }
 
    return list, nil
}