1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package model
- import (
- "github.com/jaryhe/gopkgs/logger"
- "github.com/jinzhu/gorm"
- "go.uber.org/zap"
- "smart-auth/errors"
- "time"
- )
- 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) Count(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) (int64, error) {
- if len(where) > 0 || len(or) > 0 {
- cond, val, err := whereBuildAndOr(where, or)
- if err != nil {
- return 0, err
- }
- ret := int64(0)
- err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
- if err != nil {
- fields, _ := json.Marshal(where)
- logger.Error("mysql",
- zap.String("sql", "select count(1) from VSSChannelTbl"),
- zap.String("fields", string(fields)),
- zap.String("error", err.Error()))
- return 0, errors.DataBaseError
- }
- return ret, err
- }
- ret := int64(0)
- err := db.Table(p.TableName()).Count(&ret).Error
- if err != nil {
- logger.Error("mysql",
- zap.String("sql", "select count(1) from VSSChannelTbl"),
- zap.String("error", err.Error()))
- return 0, errors.DataBaseError
- }
- return ret, err
- }
- func (p *Vsschanneltbl) Find(db *gorm.DB, where map[string]interface{}) error {
- cond, val, err := whereBuild(where)
- if err != nil {
- return err
- }
- err = db.Table(p.TableName()).Where(cond, val...).First(p).Error
- if err != nil {
- fields, _ := json.Marshal(where)
- logger.Error("mysql",
- zap.String("sql", "select from t_VSSChannelTbl "),
- zap.String("fields", string(fields)),
- zap.String("error", err.Error()))
- if err == gorm.ErrRecordNotFound {
- return nil
- }
- return errors.DataBaseError
- }
- return err
- }
|