package models
|
|
type Dictionary struct {
|
Id string `gorm:"primary_key;column:id;" json:"id"`
|
Value string `gorm:"column:value" json:"value"` //值
|
Name string `gorm:"column:name" json:"name"` //名称
|
Type string `gorm:"column:type" json:"type"` //类型
|
Description string `gorm:"column:description" json:"description"` //描述
|
Sort int `gorm:"column:sort;default:1" json:"sort"`
|
ParentId string `gorm:"column:parent_id;default:0" json:"parent_id"`
|
}
|
|
const (
|
TYPE_RULECOMPUTEBETWEEN = "RULECOMPUTEBETWEEN"
|
TYPE_RULECOMPUTE = "RULECOMPUTE"
|
TYPE_TYPECOMPUTE = "TYPECOMPUTE"
|
TYPE_ALARMLEVEL = "ALARMLEVEL"
|
TYPE_EVENTRULETOPIC = "EVENTRULETOPIC" //事件推送一级主题
|
TYPE_MONITORLEVEL = "MONITORLEVEL"
|
TYPE_PERSONSEX = "PERSONSEX"
|
TYPE_AGEDESC = "AGEDESC"
|
TYPE_PERSONRACE = "PERSONRACE"
|
TYPE_EVENTTYPECOMPUTE = "EVENTTYPECOMPUTE"
|
)
|
|
const (
|
EVENTRULETOPIC_CAMERA = "camera" //摄像机
|
EVENTRULETOPIC_CAMERA_NAME = "name"
|
EVENTRULETOPIC_CAMERA_ADDR = "addr"
|
|
EVENTRULETOPIC_DBTABLE = "dbtable" //底库
|
EVENTRULETOPIC_TASK = "task" //任务
|
|
EVENTRULETOPIC_PERSON = "person" //人员
|
EVENTRULETOPIC_PERSON_MONITORLEVEL = "monitorLevel" //等级
|
EVENTRULETOPIC_PERSON_AGE = "age" //年龄
|
EVENTRULETOPIC_PERSON_SEX = "sex" //性别
|
EVENTRULETOPIC_PERSON_RACE = "race" //种族
|
EVENTRULETOPIC_PERSON_OTHREINFO = "otherInfo" //其他信息
|
|
EVENTRULETOPIC_ALARMLEVEL = "alarmLevel" //报警等级
|
)
|
|
func (Dictionary) TableName() string {
|
return "dictionary"
|
}
|
|
func (dic *Dictionary) FindAll() (dics []Dictionary, err error) {
|
if err := db.Table("dictionary").Find(&dics).Error; err != nil {
|
return nil, err
|
}
|
return dics, nil
|
}
|
|
func (dic *Dictionary) FindByType(dicType string) (dics []Dictionary, err error) {
|
if err := db.Table("dictionary").Where("type=?", dicType).Scan(&dics).Error; err != nil {
|
return nil, err
|
}
|
return dics, nil
|
}
|
|
func (dic *Dictionary) FindByParentId(parentId string) (dics []Dictionary, err error) {
|
if err := db.Table("dictionary").Where("parent_id=?", parentId).Scan(&dics).Error; err != nil {
|
return nil, err
|
}
|
return dics, nil
|
}
|
|
func (dic *Dictionary) Insert() (bool, error) {
|
if err := db.Table("dictionary").Create(&dic).Error; err != nil {
|
return false, err
|
}
|
return true, nil
|
}
|
|
func (dic *Dictionary) Update() (bool, error) {
|
if err := db.Table("dictionary").Update(&dic).Error; err != nil {
|
return false, err
|
}
|
return true, nil
|
}
|
|
func (dic *Dictionary) SelectById(id string) (bool, error) {
|
result := db.Table("dictionary").Where("id=?", id).First(&dic)
|
if result.Error != nil {
|
return false, err
|
}
|
return result.RecordNotFound(), nil
|
}
|