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
|
}
|