vedio_channel.go 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package model
  4. import (
  5. "github.com/jaryhe/gopkgs/logger"
  6. "github.com/jinzhu/gorm"
  7. "go.uber.org/zap"
  8. "smart-auth/errors"
  9. "time"
  10. )
  11. type Vsschanneltbl struct {
  12. ID int64 `gorm:"column:ID"`
  13. Devpubid string `gorm:"column:DevPubID"`
  14. Restype int64 `gorm:"column:ResType"`
  15. Nickname string `gorm:"column:Nickname"`
  16. Chanpubid string `gorm:"column:ChanPubID"`
  17. Alive int64 `gorm:"column:Alive"`
  18. Corpid string `gorm:"column:CorpID"`
  19. Model string `gorm:"column:Model"`
  20. Owner string `gorm:"column:Owner"`
  21. Civilcode string `gorm:"column:CivilCode"`
  22. Address string `gorm:"column:Address"`
  23. Parental int64 `gorm:"column:Parental"`
  24. Parentid string `gorm:"column:ParentId"`
  25. Ip string `gorm:"column:IP"`
  26. Port int64 `gorm:"column:Port"`
  27. Longitude float64 `gorm:"column:Longitude"`
  28. Latitude float64 `gorm:"column:Latitude"`
  29. Altitude float64 `gorm:"column:Altitude"`
  30. Ptztype int64 `gorm:"column:PTZType"`
  31. Roomtype int64 `gorm:"column:RoomType"`
  32. Directiontype int64 `gorm:"column:DirectionType"`
  33. Streamtype int64 `gorm:"column:StreamType"`
  34. Chanrtspurl string `gorm:"column:ChanRtspUrl"`
  35. Realrtspurl string `gorm:"column:RealRtspUrl"`
  36. Dmarker int64 `gorm:"column:DMarker"`
  37. Updatetime time.Time `gorm:"column:UpdateTime"`
  38. }
  39. func (Vsschanneltbl) TableName() string {
  40. return "VSSChannelTbl"
  41. }
  42. func (p *Vsschanneltbl) Count(db *gorm.DB, where map[string]interface{}, or map[string]interface{}) (int64, error) {
  43. if len(where) > 0 || len(or) > 0 {
  44. cond, val, err := whereBuildAndOr(where, or)
  45. if err != nil {
  46. return 0, err
  47. }
  48. ret := int64(0)
  49. err = db.Table(p.TableName()).Where(cond, val...).Count(&ret).Error
  50. if err != nil {
  51. fields, _ := json.Marshal(where)
  52. logger.Error("mysql",
  53. zap.String("sql", "select count(1) from VSSChannelTbl"),
  54. zap.String("fields", string(fields)),
  55. zap.String("error", err.Error()))
  56. return 0, errors.DataBaseError
  57. }
  58. return ret, err
  59. }
  60. ret := int64(0)
  61. err := db.Table(p.TableName()).Count(&ret).Error
  62. if err != nil {
  63. logger.Error("mysql",
  64. zap.String("sql", "select count(1) from VSSChannelTbl"),
  65. zap.String("error", err.Error()))
  66. return 0, errors.DataBaseError
  67. }
  68. return ret, err
  69. }
  70. func (p *Vsschanneltbl) Find(db *gorm.DB, where map[string]interface{}) error {
  71. cond, val, err := whereBuild(where)
  72. if err != nil {
  73. return err
  74. }
  75. err = db.Table(p.TableName()).Where(cond, val...).First(p).Error
  76. if err != nil {
  77. fields, _ := json.Marshal(where)
  78. logger.Error("mysql",
  79. zap.String("sql", "select from t_VSSChannelTbl "),
  80. zap.String("fields", string(fields)),
  81. zap.String("error", err.Error()))
  82. if err == gorm.ErrRecordNotFound {
  83. return nil
  84. }
  85. return errors.DataBaseError
  86. }
  87. return err
  88. }