// Copyright 2019 github.com. All rights reserved. // Use of this source code is governed by github.com. package model import ( "fmt" "github.com/jinzhu/gorm" "time" ) type Vssdevtbl struct { Id int64 `gorm:"column:ID" json:"id" form:"id"` Devpubid string `gorm:"column:DevPubID" json:"devpubid" form:"devpubid"` Devnickname string `gorm:"column:DevNickname" json:"devnickname" form:"devnickname"` Username string `gorm:"column:UserName" json:"username" form:"username"` Passwd string `gorm:"column:Passwd" json:"passwd" form:"passwd"` Corpid string `gorm:"column:CorpID" json:"corpid" form:"corpid"` Ip string `gorm:"column:IP" json:"ip" form:"ip"` Port int64 `gorm:"column:Port" json:"port" form:"port"` Alive int64 `gorm:"column:Alive" json:"alive" form:"alive"` Subcatalogtime int64 `gorm:"column:SubCatalogTime" json:"subcatalogtime" form:"subcatalogtime"` Devmode string `gorm:"column:DevMode" json:"devmode" form:"devmode"` Mediatransport string `gorm:"column:MediaTransport" json:"mediatransport" form:"mediatransport"` Dmarker int64 `gorm:"column:DMarker" json:"dmarker" form:"dmarker"` UpdateTime time.Time `gorm:"column:updatetime" json:"updatetime" form:"updatetime"` ChannelCount int } func (Vssdevtbl) TableName() string { return "VSSDevTbl" } func (p *Vssdevtbl) Insert(db *gorm.DB) error { return db.Create(p).Error } func (p *Vssdevtbl) Del(db *gorm.DB, where map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error } func (p *Vssdevtbl) Find(db *gorm.DB, where map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).First(p).Error } func (p *Vssdevtbl) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).Updates(values).Error } func (p *Vssdevtbl) FindSort(db *gorm.DB, where map[string]interface{}, sort string) error { cond, val, err := whereBuild(where) if err != nil { return err } ps := []Vssdevtbl{} err = db.Table(p.TableName()).Where(cond, val...).Order(sort).Limit(1).Find(&ps).Error if err != nil { return err } if len(ps) > 0 { *p = ps[0] } return nil } func (p *Vssdevtbl) Save(db *gorm.DB) error { return db.Save(p).Error } func (p *Vssdevtbl) Count(db *gorm.DB, where map[string]interface{}) (int64, error) { if len(where) > 0 { cond, val, err := whereBuild(where) if err != nil { return 0, err } ret := int64(0) err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error return ret, err } ret := int64(0) err := db.Table(p.TableName()).Count(&ret).Error return ret, err } func (p *Vssdevtbl) List(db *gorm.DB, where map[string]interface{}, page int) (list []Vssdevtbl, err error) { offset := (page - 1) *PageSize if len(where) > 0 { cond, val, err := whereBuild(where) if err != nil { return list, err } result := db.Table(p.TableName()).Where(cond, val...).Limit(PageSize).Offset(offset).Find(&list) return list, result.Error } result := db.Table(p.TableName()).Limit(PageSize).Offset(offset).Find(&list) return list, result.Error } func (p *Vssdevtbl) UpdateChannelCount(db *gorm.DB, sn string, count int) error { sql := fmt.Sprintf("update VSSDevTbl set channel_count=channel_count+%d where DevPubID='%s'", count, sn) return db.Exec(sql).Error } type Vsschanneltbl struct { ID int64 `gorm:"column:ID"` Devpubid string `gorm:"column:DevPubID"` Restype int64 `gorm:"column:ResType"` Nickname string `gorm:"column:Nickname"` Chanpubid string `gorm:"column:ChanPubID"` Alive int64 `gorm:"column:Alive"` Corpid string `gorm:"column:CorpID"` Model string `gorm:"column:Model"` Owner string `gorm:"column:Owner"` Civilcode string `gorm:"column:CivilCode"` Address string `gorm:"column:Address"` Parental int64 `gorm:"column:Parental"` Parentid string `gorm:"column:ParentId"` Ip string `gorm:"column:IP"` Port int64 `gorm:"column:Port"` Longitude float64 `gorm:"column:Longitude"` Latitude float64 `gorm:"column:Latitude"` Altitude float64 `gorm:"column:Altitude"` Ptztype int64 `gorm:"column:PTZType"` Roomtype int64 `gorm:"column:RoomType"` Directiontype int64 `gorm:"column:DirectionType"` Streamtype int64 `gorm:"column:StreamType"` Chanrtspurl string `gorm:"column:ChanRtspUrl"` Realrtspurl string `gorm:"column:RealRtspUrl"` Dmarker int64 `gorm:"column:DMarker"` Updatetime time.Time `gorm:"column:UpdateTime"` } func (Vsschanneltbl) TableName() string { return "VSSChannelTbl" } func (p *Vsschanneltbl) Insert(db *gorm.DB) error { return db.Create(p).Error } func (p *Vsschanneltbl) Del(db *gorm.DB, where map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).Delete(p).Error } func (p *Vsschanneltbl) Find(db *gorm.DB, where map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).First(p).Error } func (p *Vsschanneltbl) Update(db *gorm.DB, where map[string]interface{}, values map[string]interface{}) error { cond, val, err := whereBuild(where) if err != nil { return err } return db.Table(p.TableName()).Where(cond, val...).Updates(values).Error } func (p *Vsschanneltbl) Save(db *gorm.DB) error { return db.Save(p).Error } func (p *Vsschanneltbl) Count(db *gorm.DB, where map[string]interface{}) (int64, error) { if len(where) > 0 { cond, val, err := whereBuild(where) if err != nil { return 0, err } ret := int64(0) err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error return ret, err } ret := int64(0) err := db.Table(p.TableName()).Count(&ret).Error return ret, err } func (p *Vsschanneltbl) List(db *gorm.DB, where map[string]interface{}, page int32) (list []Vsschanneltbl, err error) { offset := (int(page) - 1) *PageSize if len(where) > 0 { cond, val, err := whereBuild(where) if err != nil { return list, err } result := db.Table(p.TableName()).Where(cond, val...).Limit(PageSize).Offset(offset).Find(&list) return list, result.Error } result := db.Table(p.TableName()).Limit(PageSize).Offset(offset).Find(&list) return list, result.Error } func GetProjectIdByChannel(db *gorm.DB, id int64) (int64, error) { sql := fmt.Sprintf("select t2.project_id from VSSChannelTbl as t1 left join t_device as t2 on t1.DevPubID = t2.sn and t2.device_code=%d where t1.id=?", DeviceTypeVedio) type Result struct { ProjectId int64 } array := []Result{} err := db.Raw(sql, id).Scan(&array).Error if err != nil { return 0, err } if len(array) == 0 { return 0, nil } return array[0].ProjectId, nil }