package models
|
|
type CameraRuleGroup struct {
|
Id string `gorm:"primary_key;column:id" json:"id"`
|
GroupText string `gorm:"column:group_text" json:"group_text"`
|
AlarmLevel int `gorm:"column:alarm_level;default:1" json:"alarm_level"`
|
SetType string `gorm:"column:set_type" json:"set_type"`
|
|
TemplateId string `gorm:"column:template_id" json:"template_id"` //场景模板id
|
TemplateRule string `gorm:"column:template_rule" json:"template_rule"` //场景模板的配置
|
TimeRuleId string `gorm:"column:time_rule_id" json:"time_rule_id"` //时间段
|
SceneName string `gorm:"column:scene_name" json:"scene_name"` //场景名称,从模板来,修改即自定义
|
Desc string `gorm:"column:desc" json:"desc"` //场景描述
|
Enable bool `gorm:"column:enable;default:1" json:"enable"` //开关,默认开启
|
|
VoiceId string `gorm:"column:voiceId" json:"voiceId"` //事件声音
|
}
|
|
const (
|
Type_SetType_Batch = "batchTask"
|
Type_SetType_Link = "linkTask"
|
RecordNotFound = "record not found"
|
)
|
|
func (CameraRuleGroup) TableName() string {
|
return "camera_rule_group"
|
}
|
|
func (crg *CameraRuleGroup) SelectById(id string) (rows int64, err error) {
|
result := db.Table(crg.TableName()).Where("id = ?", id).First(&crg)
|
if result.Error != nil && result.Error.Error() != RecordNotFound {
|
return 0, result.Error
|
}
|
return result.RowsAffected, nil
|
}
|
|
func (crg *CameraRuleGroup) FindAll() (list []CameraRuleGroup) {
|
if err := db.Table(crg.TableName()).Scan(&list).Error; err != nil {
|
return nil
|
}
|
return list
|
}
|
func (crg *CameraRuleGroup) Insert() (bool, error) {
|
if err := db.Table(crg.TableName()).Create(&crg).Error; err != nil {
|
return false, err
|
}
|
return true, nil
|
}
|
|
func (crg *CameraRuleGroup) FindByCameraId(cameraId string, setType string) (arr []CameraRuleGroup, err error) {
|
sql := "select * from " + crg.TableName() + " where id in (select distinct group_id from " + CameraRuleGroupArg{}.TableName() + " where camera_id='" + cameraId + "')"
|
if setType != "" {
|
sql += " and set_type='batchTask'"
|
}
|
if err := db.Raw(sql).Scan(&arr).Error; err != nil {
|
return nil, err
|
}
|
return arr, nil
|
}
|
|
func (crg *CameraRuleGroup) FindGroupByPolygonId(polygonId string) (list []CameraRuleGroup) {
|
var rga CameraRuleGroupArg
|
err := db.Raw("select * from "+crg.TableName()+" where id in (select distinct group_id from "+rga.TableName()+" where polygon_id=?)", polygonId).Find(&list).Error
|
if err != nil {
|
return nil
|
}
|
return list
|
}
|
|
func (crg *CameraRuleGroup) UpdateText(id string, text string) bool {
|
execResult := db.Exec("update "+crg.TableName()+" set group_text=? where id=?", text, id)
|
if execResult.Error != nil {
|
return false
|
}
|
return execResult.RowsAffected > 0
|
}
|
|
func (crg *CameraRuleGroup) UpdateAlarmLevel(groupId string, alarmLevel int) bool {
|
execResult := db.Exec("update "+crg.TableName()+" set alarm_level=? where id=?", alarmLevel, groupId)
|
if execResult.Error != nil {
|
return false
|
}
|
return execResult.RowsAffected > 0
|
}
|
|
func (crg *CameraRuleGroup) FindByTimeRuleId(timeRuleId string) (list []CameraRuleGroup, e error) {
|
if err := db.Table(crg.TableName()).Where("time_rule_id=?", timeRuleId).Scan(&list).Error; err != nil {
|
return nil, err
|
}
|
return list, nil
|
}
|