| | |
| | | package db |
| | | |
| | | import ( |
| | | "encoding/json" |
| | | "fmt" |
| | | "gorm.io/gorm" |
| | | "strings" |
| | | "time" |
| | | |
| | | "gorm.io/gorm" |
| | | ) |
| | | |
| | | type ( |
| | | ModelTask struct { |
| | | BaseModel |
| | | Name string `gorm:"type:varchar(255)" json:"name"` //任务名称 |
| | | ModelID string `gorm:"type:varchar(255)" json:"modelID"` //模型ID |
| | | BeginTime time.Time //工作时间开始 |
| | | EndTime time.Time //公祖时间结束 |
| | | DomainUnitIds []string `gorm:"-" json:"domainUnitIds"` //区域id列表 |
| | | DomainIds string `gorm:"type:varchar(1000)" json:"-"` |
| | | Building string `gorm:"type:varchar(255)" json:"building"` //楼栋 |
| | | Floor string `gorm:"type:varchar(255)" json:"floor"` //楼层 |
| | | AlarmType AlarmType `gorm:"type:varchar(255);" json:"alarmType"` //预警方式 |
| | | PersonType string `gorm:"type:varchar(255);" json:"personType"` //人员类型 |
| | | GatherPersons int `gorm:"type:int;" json:"gatherPersons"` //聚集人数 |
| | | AppearInterval int `gorm:"type:int;" json:"appearInterval"` //出现间隔,单位为秒 |
| | | DaysWindow int `gorm:"type:int;" json:"daysWindow" ` //近几天内 |
| | | Threshold int `gorm:"type:int;" json:"threshold" ` //达几次 |
| | | Enabled bool `json:"enabled"` //是否开启 |
| | | Name string `gorm:"type:varchar(255)" json:"name"` // 任务名称 |
| | | ModelID string `gorm:"type:varchar(255)" json:"modelID"` // 模型ID |
| | | BeginTime time.Time `json:"beginTime"` // 工作时间开始 |
| | | EndTime time.Time `json:"endTime"` // 工作时间结束 |
| | | DomainUnitIds []string `gorm:"-" json:"domainUnitIds"` // 区域id列表 |
| | | DomainIds string `gorm:"type:varchar(1000)" json:"-"` |
| | | Building string `gorm:"type:varchar(255)" json:"building"` // 楼栋 |
| | | Floor string `gorm:"type:varchar(255)" json:"floor"` // 楼层 |
| | | AlarmType AlarmType `gorm:"type:varchar(255);" json:"alarmType"` // 预警方式 |
| | | PersonType string `gorm:"type:varchar(255);" json:"personType"` // 人员类型 |
| | | PersonLabel string `gorm:"type:varchar(255);" json:"personLabel"` // 人员标签 |
| | | IdentityType string `gorm:"type:varchar(255);" json:"identityType"` // 身份标签, 陌生人, 访客, 住户 |
| | | AlarmLevel string `gorm:"type:varchar(255);" json:"alarmLevel"` // 预警级别 |
| | | GatherPersons int `gorm:"type:int;" json:"gatherPersons"` // 聚集人数 |
| | | AppearInterval int `gorm:"type:int;" json:"appearInterval"` // 出现间隔,单位为秒 |
| | | DaysWindow int `gorm:"type:int;" json:"daysWindow" ` // 近几天内 |
| | | Threshold int `gorm:"type:int;" json:"threshold" ` // 达几次 |
| | | Enabled bool `json:"enabled"` // 是否开启 |
| | | RuleSet string `gorm:"type:text" json:"-"` // 存储模型任务设置的规则参数 |
| | | Rules []ModelRuleSet `gorm:"-" json:"rules"` // 规则配置 |
| | | } |
| | | |
| | | ModelTaskSearch struct { |
| | | ModelTask |
| | | Orm *gorm.DB |
| | | ModelIDs []string |
| | | Unexpired bool |
| | | PageNum int |
| | | PageSize int |
| | | Keyword string |
| | | ModelIDs []string |
| | | Unexpired bool |
| | | } |
| | | ) |
| | | |
| | | type AlarmType string |
| | | |
| | | const ( |
| | | AlarmTypeSave AlarmType = "save" //仅保存 |
| | | AlarmTypeSendMessage AlarmType = "message" //发消息 |
| | | AlarmTypeSave AlarmType = "save" // 仅保存 |
| | | AlarmTypeSendMessage AlarmType = "message" // 发消息 |
| | | ) |
| | | |
| | | func (slf *ModelTask) TableName() string { |
| | |
| | | if slf.DomainIds != "" { |
| | | slf.DomainUnitIds = strings.Split(slf.DomainIds, ",") |
| | | } |
| | | if slf.DomainIds != "" { |
| | | slf.DomainUnitIds = strings.Split(slf.DomainIds, ",") |
| | | } |
| | | |
| | | if slf.RuleSet != "" { |
| | | _ = json.Unmarshal([]byte(slf.RuleSet), &slf.Rules) |
| | | } |
| | | return nil |
| | | } |
| | | |