| | |
| | | package models |
| | | |
| | | type LocalConfig struct { |
| | | Id string `gorm:"primary_key;column:id" json:"id"` |
| | | AlarmIp string `gorm:"column:alarm_ip" json:"alarm_ip" example:"192.168.1.182"` |
| | | AlarmPort int `gorm:"column:alarm_port" json:"alarm_port" example:"22122"` |
| | | AlarmThresholdType int `gorm:"column:alarm_threshold_type" json:"alarm_threshold_type"` //报警阈值类型设置:1:按最高分,2:按阈值以上 |
| | | AlarmThreshold int `gorm:"column:alarm_threshold" json:"alarm_threshold"` //报警阈值 |
| | | WebPicIp string `gorm:"column:web_pic_ip" json:"web_pic_ip" example:""` |
| | | WebPicPort int `gorm:"column:web_pic_port" json:"web_pic_port" example:"22122"` |
| | | EsPicIp string `gorm:"column:es_pic_ip" json:"es_pic_ip" example:""` |
| | | EsPicPort int `gorm:"column:es_pic_port" json:"es_pic_port" example:"22122"` |
| | | |
| | | CutMaxDuration int `gorm:"column:cut_max_duration" json:"cut_max_duration" example:"20"` |
| | | CutMinDuration int `gorm:"column:cut_min_duration" json:"cut_min_duration" example:"5"` |
| | | ServerId string `gorm:"column:server_id" json:"server_id" example:"分析设备id"` |
| | | ServerName string `gorm:"column:server_name" json:"server_name" example:"分析设备名称"` |
| | | ServerType int `gorm:"column:server_type" json:"server_type" example:"1"` |
| | | Reserved string `gorm:"column:reserved" json:"reserved" example:"1"` |
| | | RealMax int `gorm:"column:real_max" json:"real_max"` //实时处理的最大路数 |
| | | NeedAuthPwd int `gorm:"column:need_auth_pwd;default:0;" json:"need_auth_pwd"` //设备授权管理方式 0:不用密码 1:通过密码 |
| | | AuthPwd string `gorm:"column:auth_pwd" json:"auth_pwd"` //设备授权密码 |
| | | } |
| | | |
| | | // 设置表名为`profiles` |
| | | func (LocalConfig) TableName() string { |
| | | return "local_configs" |
| | | } |
| | | |
| | | func (loCon *LocalConfig) FindAreaSliece() (config []LocalConfig, err error) { |
| | | if err := db.Table(loCon.TableName()).Find(&config).Error; err != nil { |
| | | return nil, err |
| | | } |
| | | return config, nil |
| | | } |
| | | |
| | | func (loCon *LocalConfig) Insert() (err error) { |
| | | tx := db.Table(loCon.TableName()).Begin() |
| | | if tx.Error != nil { |
| | | return err |
| | | } |
| | | if err := tx.Create(&loCon).Error; err != nil { |
| | | tx.Rollback() |
| | | return err |
| | | } |
| | | return tx.Commit().Error |
| | | } |
| | | |
| | | func (loCon *LocalConfig) Select() (err error) { |
| | | if err = db.Table(loCon.TableName()).First(&loCon).Error; err != nil { |
| | | if err.Error() == "record not found" { |
| | | loCon = nil |
| | | return nil |
| | | } |
| | | return err |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func (loCon *LocalConfig) SelectByDeviceId(deviceId string) (err error) { |
| | | if err = db.Table(loCon.TableName()).Where("server_id=?", deviceId).First(&loCon).Error; err != nil { |
| | | if err.Error() == "record not found" { |
| | | loCon = nil |
| | | return nil |
| | | } |
| | | return err |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func (loCon *LocalConfig) Update() error { |
| | | if err := db.Save(&loCon).Error; err != nil { |
| | | return err |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func (loCon *LocalConfig) UpdateAuth() error { |
| | | // 根据id查找记录,修改密码和授权方式两个字段,传空值也会修改,只要与原来值发生变化 |
| | | if err := db.Model(&loCon).Updates(map[string]interface{}{"auth_pwd": loCon.AuthPwd, "need_auth_pwd": loCon.NeedAuthPwd}).Error; err != nil { |
| | | return err |
| | | } |
| | | return nil |
| | | } |
| | | package models
|
| | |
|
| | | type LocalConfig struct {
|
| | | Id string `gorm:"primary_key;column:id" json:"id"`
|
| | | AlarmIp string `gorm:"column:alarm_ip" json:"alarm_ip" example:"192.168.1.182"`
|
| | | AlarmPort int `gorm:"column:alarm_port" json:"alarm_port" example:"22122"`
|
| | | AlarmThresholdType int `gorm:"column:alarm_threshold_type" json:"alarm_threshold_type"` //报警阈值类型设置:1:按最高分,2:按阈值以上
|
| | | AlarmThreshold int `gorm:"column:alarm_threshold" json:"alarm_threshold"` //报警阈值
|
| | | WebPicIp string `gorm:"column:web_pic_ip" json:"web_pic_ip" example:""`
|
| | | WebPicPort int `gorm:"column:web_pic_port" json:"web_pic_port" example:"22122"`
|
| | | EsPicIp string `gorm:"column:es_pic_ip" json:"es_pic_ip" example:""`
|
| | | EsPicPort int `gorm:"column:es_pic_port" json:"es_pic_port" example:"22122"`
|
| | |
|
| | | CutMaxDuration int `gorm:"column:cut_max_duration" json:"cut_max_duration" example:"20"`
|
| | | CutMinDuration int `gorm:"column:cut_min_duration" json:"cut_min_duration" example:"5"`
|
| | | ServerId string `gorm:"column:server_id" json:"server_id" example:"分析设备id"`
|
| | | ServerName string `gorm:"column:server_name" json:"server_name" example:"分析设备名称"`
|
| | | ServerType int `gorm:"column:server_type" json:"server_type" example:"1"`
|
| | | Reserved string `gorm:"column:reserved" json:"reserved" example:"1"`
|
| | | RealMax int `gorm:"column:real_max" json:"real_max"` //实时处理的最大路数
|
| | | NeedAuthPwd int `gorm:"column:need_auth_pwd;default:0;" json:"need_auth_pwd"` //设备授权管理方式 0:不用密码 1:通过密码
|
| | | AuthPwd string `gorm:"column:auth_pwd" json:"auth_pwd"` //设备授权密码
|
| | | }
|
| | |
|
| | | // 设置表名为`profiles`
|
| | | func (LocalConfig) TableName() string {
|
| | | return "local_configs"
|
| | | }
|
| | |
|
| | | func (loCon *LocalConfig) FindAreaSliece() (config []LocalConfig, err error) {
|
| | | if err := db.Table(loCon.TableName()).Find(&config).Error; err != nil {
|
| | | return nil, err
|
| | | }
|
| | | return config, nil
|
| | | }
|
| | |
|
| | | func (loCon *LocalConfig) Insert() (err error) {
|
| | | tx := db.Table(loCon.TableName()).Begin()
|
| | | if tx.Error != nil {
|
| | | return err
|
| | | }
|
| | | if err := tx.Create(&loCon).Error; err != nil {
|
| | | tx.Rollback()
|
| | | return err
|
| | | }
|
| | | return tx.Commit().Error
|
| | | }
|
| | |
|
| | | func (loCon *LocalConfig) Select() (err error) {
|
| | | if err = db.Table(loCon.TableName()).First(&loCon).Error; err != nil {
|
| | | if err.Error() == "record not found" {
|
| | | loCon = nil
|
| | | return nil
|
| | | }
|
| | | return err
|
| | | }
|
| | | return nil
|
| | | }
|
| | |
|
| | | func (loCon *LocalConfig) SelectByDeviceId(deviceId string) (err error) {
|
| | | if err = db.Table(loCon.TableName()).Where("server_id=?", deviceId).First(&loCon).Error; err != nil {
|
| | | if err.Error() == "record not found" {
|
| | | loCon = nil
|
| | | return nil
|
| | | }
|
| | | return err
|
| | | }
|
| | | return nil
|
| | | }
|
| | |
|
| | | func (loCon *LocalConfig) Update() error {
|
| | | if err := db.Save(&loCon).Error; err != nil {
|
| | | return err
|
| | | }
|
| | | return nil
|
| | | }
|
| | |
|
| | | func (loCon *LocalConfig) UpdateAuth() error {
|
| | | // 根据id查找记录,修改密码和授权方式两个字段,传空值也会修改,只要与原来值发生变化
|
| | | if err := db.Model(&loCon).Updates(map[string]interface{}{"auth_pwd": loCon.AuthPwd, "need_auth_pwd": loCon.NeedAuthPwd}).Error; err != nil {
|
| | | return err
|
| | | }
|
| | | return nil
|
| | | }
|